]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Removed non-SDL codepaths.
[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 int newnetmessages;
80 extern char netmessages[256];
81 extern bool keyboardfrozen;
82 extern int netdatanew;
83 extern bool loadingstuff;
84 extern char mapname[256];
85 extern XYZ windvector;
86 extern bool buttons[3];
87 extern bool debugmode;
88 static int music1;
89 extern int mainmenu;
90 extern int oldmainmenu;
91 extern bool visibleloading;
92 extern int loadscreencolor;
93 extern float flashamount,flashr,flashg,flashb;
94 extern int flashdelay;
95 extern XYZ envsound[30];
96 extern float envsoundvol[30];
97 extern int numenvsounds;
98 extern float envsoundlife[30];
99 extern float usermousesensitivity;
100 extern bool ismotionblur;
101 extern bool foliage;
102 extern bool trilinear;
103 extern bool damageeffects;
104 extern bool showpoints;
105 extern bool texttoggle;
106 extern bool alwaysblur;
107 extern float gamespeed;
108 extern bool decals;
109 extern bool vblsync;
110 extern bool immediate;
111 extern bool velocityblur;
112 extern int bonus;
113 extern int oldbonus;
114 extern float bonusvalue;
115 extern float bonustotal;
116 extern float bonustime;
117 extern float startbonustotal;
118 extern float tintr,tintg,tintb;
119 extern float bonusnum[100];
120 extern bool skyboxtexture;
121 extern float skyboxr;
122 extern float skyboxg;
123 extern float skyboxb;
124 extern float skyboxlightr;
125 extern float skyboxlightg;
126 extern float skyboxlightb;
127 extern float fadestart;
128 extern float slomospeed;
129 extern float slomofreq;
130 extern int tutoriallevel;
131 extern float smoketex;
132 extern float tutorialstagetime;
133 extern int tutorialstage;
134 extern float tutorialmaxtime;
135 extern float tutorialsuccess;
136 extern bool againbonus;
137 extern bool reversaltrain;
138 extern bool canattack;
139 extern bool cananger;
140 extern float damagedealt;
141 extern float damagetaken;
142 extern int maptype;
143 extern int editoractive;
144 extern int editorpathtype;
145 extern bool oldbuttons[3];
146
147 extern float hostiletime;
148
149 extern bool gamestarted;
150
151 extern int numhotspots;
152 extern int winhotspot;
153 extern int windialogue;
154 extern int killhotspot;
155 extern XYZ hotspot[40];
156 extern int hotspottype[40];
157 extern float hotspotsize[40];
158 extern char hotspottext[40][256];
159 extern int currenthotspot;
160
161 extern int kBitsPerPixel;
162 extern int hostile;
163
164 extern int numaccounts;
165 extern int accountactive;
166 extern int accountdifficulty[10];
167 extern int accountprogress[10];
168 extern float accountpoints[10];
169 extern float accounthighscore[10][50];
170 extern float accountfasttime[10][50];
171 extern bool accountunlocked[10][60];
172 extern char accountname[10][256];
173
174 extern bool stillloading;
175 extern bool winfreeze;
176
177 extern int numfalls;
178 extern int numflipfail;
179 extern int numseen;
180 extern int numstaffattack;
181 extern int numswordattack;
182 extern int numknifeattack;
183 extern int numunarmedattack;
184 extern int numescaped;
185 extern int numflipped;
186 extern int numwallflipped;
187 extern int numthrowkill;
188 extern int numafterkill;
189 extern int numreversals;
190 extern int numattacks;
191 extern int maxalarmed;
192 extern int numresponded;
193
194 extern int numdialogues;
195 extern int numdialogueboxes[max_dialogues];
196 extern int dialoguetype[max_dialogues];
197 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
198 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
199 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
200 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
201 extern char dialoguename[max_dialogues][max_dialoguelength][64];
202 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
203 extern XYZ participantlocation[max_dialogues][10];
204 extern int participantfocus[max_dialogues][max_dialoguelength];
205 extern int participantaction[max_dialogues][max_dialoguelength];
206 extern float participantrotation[max_dialogues][10];
207 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
208 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
209 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
210 extern int indialogue;
211 extern int whichdialogue;
212 extern int directing;
213 extern float dialoguetime;
214 extern int dialoguegonethrough[20];
215
216 extern bool campaign;
217
218 extern float oldgamespeed;
219
220 extern float accountcampaignhighscore[10];
221 extern float accountcampaignfasttime[10];
222 extern float accountcampaignscore[10];
223 extern float accountcampaigntime[10];
224
225 extern int accountcampaignchoicesmade[10];
226 extern int accountcampaignchoices[10][5000];
227 /********************> Tick() <*****/
228 extern OPENAL_STREAM * strm[20];
229 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
230 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
231
232 extern void ScreenShot(const char * fname);
233 void Screenshot (void)
234 {
235         char temp[1024];
236         time_t  t = time(NULL);
237         struct  tm *tme = localtime(&t);
238         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);
239
240         #if defined(_WIN32)
241         mkdir("Screenshots");
242         #else
243         mkdir("Screenshots", S_IRWXU);
244         #endif
245
246         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
247
248         /*FSSpec                                MAC_file;
249         GraphicsExportComponent QT_exporter;
250         OSErr                           MAC_error_code;
251         CGrafPtr                        MAC_currentPort;
252         GDHandle                        MAC_currentDevice;
253         unsigned char*          MAC_pixels;
254         Rect                            MAC_picture_rectangle;
255         GWorldPtr                       MAC_offscreen_graphics_port;
256
257         static int numscreenshots=0;
258
259         // Make an FSSpec
260         static char buf[256];
261         if(numscreenshots==0){
262         buf[0]=26;
263         buf[1]=':';
264         buf[2]='S';
265         buf[3]='c';
266         buf[4]='r';
267         buf[5]='e';
268         buf[6]='e';
269         buf[7]='n';
270         buf[8]='s';
271         buf[9]='h';
272         buf[10]='o';
273         buf[11]='t';
274         buf[12]='s';
275         buf[13]=':';
276         buf[14]='S';
277         buf[15]='c';
278         buf[16]='r';
279         buf[17]='e';
280         buf[18]='e';
281         buf[19]='n';
282         buf[20]='s';
283         buf[21]='h';
284         buf[22]='o';
285         buf[23]='t';
286         buf[24]='0';
287         buf[25]='0';
288         buf[26]='0';
289         }
290
291         FInfo *fndrInfo;
292         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
293         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
294         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
295         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
296         numscreenshots++;
297         buf[26]++;
298         if(buf[26]==':'){
299         buf[26]='0';
300         buf[25]++;
301         if(buf[25]==':'){
302         buf[25]='0';
303         buf[24]++;
304         if(buf[24]==':'){
305         buf[24]='9';
306         buf[25]='9';
307         buf[26]='9';
308         }
309         }
310         }
311         }
312         }
313
314
315         // Get the GWorld
316         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
317         //assert(MAC_gWorld != NULL);
318
319         // Allocate memory for loading image
320         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
321         if (MAC_pixels == NULL) {
322         //UTIL_Error("Could not create Texture data.");
323         return;
324         }
325
326         // Get GWorld
327         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
328
329         // Make a picture Rectangle
330         MAC_picture_rectangle.left = 0;
331         MAC_picture_rectangle.right = screenwidth;
332         MAC_picture_rectangle.top = 0;
333         MAC_picture_rectangle.bottom = screenheight;
334
335         // Create new offscreen GWorld
336         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
337         if (MAC_error_code)     {
338         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
339         delete MAC_pixels;
340         //UTIL_Error("Could not create offscreen GWorld. ");
341         return;
342
343         }
344
345         // Copy OpenGL Context to new GWorld
346         glReadBuffer(GL_FRONT);
347         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
348
349         // Swizzle texture
350         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
351         unsigned char temp = MAC_pixels[byte+0];
352         MAC_pixels[byte+0] = MAC_pixels[byte+3];
353         MAC_pixels[byte+3] = MAC_pixels[byte+2];
354         MAC_pixels[byte+2] = MAC_pixels[byte+1];
355         MAC_pixels[byte+1] = temp;
356         }
357
358         // Flip the image  :(   This could probably be optimized
359         int vert;
360         int src_index;
361         int dst_index;
362         unsigned char temp;
363         for (int horz = 0; horz < screenwidth; ++horz)
364         for (vert = 0; vert < screenheight / 2; ++vert) {
365         src_index = (screenwidth * vert + horz) * 4;
366         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
367
368         temp=MAC_pixels[src_index+0];
369         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
370         MAC_pixels[dst_index+0]=temp;
371
372         temp=MAC_pixels[src_index+1];
373         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
374         MAC_pixels[dst_index+1]=temp;
375
376         temp=MAC_pixels[src_index+2];
377         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
378         MAC_pixels[dst_index+2]=temp;
379
380         temp=MAC_pixels[src_index+3];
381         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
382         MAC_pixels[dst_index+3]=temp;
383         }
384
385
386
387         // Export the Gworld
388         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
389         if (MAC_error_code) {
390         //UTIL_Warning("Unable to export screenshot.");
391         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
392         ::DisposeGWorld(MAC_offscreen_graphics_port);
393         delete MAC_pixels;
394         return;
395         }
396
397         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
398         if (MAC_error_code) {
399         ::CloseComponent(QT_exporter);
400         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
401         ::DisposeGWorld(MAC_offscreen_graphics_port);
402         delete MAC_pixels;
403         //UTIL_Warning("Unable to export screenshot.");
404         return;
405         }
406
407         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
408         if (MAC_error_code) {
409         ::CloseComponent(QT_exporter);
410         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
411         ::DisposeGWorld(MAC_offscreen_graphics_port);
412         delete MAC_pixels;
413         //UTIL_Warning("Unable to export screenshot.");
414         return;
415         }
416
417         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
418         if (MAC_error_code) {
419         ::CloseComponent(QT_exporter);
420         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
421         ::DisposeGWorld(MAC_offscreen_graphics_port);
422         delete MAC_pixels;
423         //UTIL_Warning("Unable to export screenshot.");
424         return;
425         }
426
427         ::CloseComponent(QT_exporter);
428         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
429         ::DisposeGWorld(MAC_offscreen_graphics_port);
430
431         delete MAC_pixels;*/
432 }
433
434
435
436 void    Game::SetUpLighting(){
437         if(environment==snowyenvironment){
438                 light.color[0]=.65;
439                 light.color[1]=.65;
440                 light.color[2]=.7;
441                 light.ambient[0]=.4;
442                 light.ambient[1]=.4;
443                 light.ambient[2]=.44;
444         }
445         if(environment==desertenvironment){
446                 light.color[0]=.95;
447                 light.color[1]=.95;
448                 light.color[2]=.95;
449                 light.ambient[0]=.4;
450                 light.ambient[1]=.35;
451                 light.ambient[2]=.3;
452         }
453
454         if(environment==grassyenvironment){
455                 light.color[0]=.95;
456                 light.color[1]=.95;
457                 light.color[2]=1;
458                 light.ambient[0]=.4;
459                 light.ambient[1]=.4;
460                 light.ambient[2]=.44;
461         }
462         if(!skyboxtexture){
463                 light.color[0]=1;
464                 light.color[1]=1;
465                 light.color[2]=1;
466                 light.ambient[0]=.4;
467                 light.ambient[1]=.4;
468                 light.ambient[2]=.4;
469         }
470         float average;
471         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
472         light.color[0]*=(skyboxlightr+average)/2;
473         light.color[1]*=(skyboxlightg+average)/2;
474         light.color[2]*=(skyboxlightb+average)/2;
475         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
476         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
477         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
478         /*
479         light.ambient[0]=0;
480         light.ambient[1]=0;
481         light.ambient[2]=0;     */
482 }
483
484 int Game::findPathDist(int start,int end){
485         int i,j,k,smallestcount,count,connected;
486         int last,last2,last3,last4;
487         int closest;
488
489         smallestcount=1000;
490         for(i=0;i<50;i++){
491                 count=0;
492                 last=start;
493                 last2=-1;
494                 last3=-1;
495                 last4=-1;
496                 while(last!=end&&count<30){
497                         closest=-1;
498                         for(j=0;j<numpathpoints;j++){
499                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
500                                 {
501                                         connected=0;
502                                         if(numpathpointconnect[j])
503                                                 for(k=0;k<numpathpointconnect[j];k++){
504                                                         if(pathpointconnect[j][k]==last)connected=1;
505                                                 }
506                                                 if(!connected)
507                                                         if(numpathpointconnect[last])
508                                                                 for(k=0;k<numpathpointconnect[last];k++){
509                                                                         if(pathpointconnect[last][k]==j)connected=1;
510                                                                 }
511                                                                 if(connected)
512                                                                         if(closest==-1||Random()%2==0){
513                                                                                 closest=j;
514                                                                         }
515                                 }
516                         }
517                         last4=last3;
518                         last3=last2;
519                         last2=last;
520                         last=closest;
521                         count++;
522                 }
523                 if(count<smallestcount)smallestcount=count;
524         }
525         return smallestcount;
526 }
527
528 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
529         static XYZ colpoint,colviewer,coltarget;
530         static float minx,minz,maxx,maxz,miny,maxy;
531         static int i;
532
533         //startpoint.y+=.7;
534         //endpoint.y+=.7;
535         //startpoint.y-=.1;
536         //endpoint.y-=.1;
537
538         minx=startpoint.x;
539         if(minx>endpoint.x)minx=endpoint.x;
540         miny=startpoint.y;
541         if(miny>endpoint.y)miny=endpoint.y;
542         minz=startpoint.z;
543         if(minz>endpoint.z)minz=endpoint.z;
544
545         maxx=startpoint.x;
546         if(maxx<endpoint.x)maxx=endpoint.x;
547         maxy=startpoint.y;
548         if(maxy<endpoint.y)maxy=endpoint.y;
549         maxz=startpoint.z;
550         if(maxz<endpoint.z)maxz=endpoint.z;
551
552         minx-=1;
553         miny-=1;
554         minz-=1;
555         maxx+=1;
556         maxy+=1;
557         maxz+=1;
558
559         for(i=0;i<objects.numobjects;i++){
560                 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){
561                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
562                                 colviewer=startpoint;
563                                 coltarget=endpoint;
564                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
565                         }
566                 }
567         }
568
569         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
570
571         return -1;
572 }
573
574 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
575         static XYZ colpoint,colviewer,coltarget;
576         static float minx,minz,maxx,maxz,miny,maxy;
577         static int i;
578
579         //startpoint.y+=.7;
580         //endpoint.y+=.7;
581         //startpoint.y-=.1;
582         //endpoint.y-=.1;
583
584         minx=startpoint.x;
585         if(minx>endpoint.x)minx=endpoint.x;
586         miny=startpoint.y;
587         if(miny>endpoint.y)miny=endpoint.y;
588         minz=startpoint.z;
589         if(minz>endpoint.z)minz=endpoint.z;
590
591         maxx=startpoint.x;
592         if(maxx<endpoint.x)maxx=endpoint.x;
593         maxy=startpoint.y;
594         if(maxy<endpoint.y)maxy=endpoint.y;
595         maxz=startpoint.z;
596         if(maxz<endpoint.z)maxz=endpoint.z;
597
598         minx-=1;
599         miny-=1;
600         minz-=1;
601         maxx+=1;
602         maxy+=1;
603         maxz+=1;
604
605         if(what!=1000){
606                 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){
607                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
608                                 colviewer=startpoint;
609                                 coltarget=endpoint;
610                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
611                         }
612                 }
613         }
614
615         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
616
617         return -1;
618 }
619
620 void    Game::Setenvironment(int which)
621 {
622         LOGFUNC;
623
624         LOG(" Setting environment...");
625
626         float temptexdetail;
627         environment=which;
628 /*
629         OPENAL_SetPaused(channels[music1snow], true);
630         OPENAL_SetPaused(channels[music1grass], true);
631         OPENAL_SetPaused(channels[music1desert], true);
632         OPENAL_SetPaused(channels[wind], true);
633         OPENAL_SetPaused(channels[desertambient], true);
634 */
635         OPENAL_SetPaused(channels[stream_music1snow], true);
636         OPENAL_SetPaused(channels[stream_music1grass], true);
637         OPENAL_SetPaused(channels[stream_music1desert], true);
638         OPENAL_SetPaused(channels[stream_wind], true);
639         OPENAL_SetPaused(channels[stream_desertambient], true);
640
641
642         if(environment==snowyenvironment){
643                 windvector=0;
644                 windvector.z=3;
645                 if(ambientsound){
646                         //PlaySoundEx( wind, samp[wind], NULL, true);
647                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
648                         OPENAL_SetPaused(channels[stream_wind], false);
649                         OPENAL_SetVolume(channels[stream_wind], 256);
650                 }
651
652                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
653                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
654                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
655                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
656
657                 OPENAL_Sample_Free(samp[footstepsound]);
658                 OPENAL_Sample_Free(samp[footstepsound2]);
659                 OPENAL_Sample_Free(samp[footstepsound3]);
660                 OPENAL_Sample_Free(samp[footstepsound4]);
661                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
662                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
663                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
664                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
665                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
666                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
667                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
668                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
669
670                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
671
672                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
673
674                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
675
676
677
678
679                 temptexdetail=texdetail;
680                 if(texdetail>1)texdetail=4;
681                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
682                         ":Data:Textures:Skybox(snow):Left.jpg",
683                         ":Data:Textures:Skybox(snow):Back.jpg",
684                         ":Data:Textures:Skybox(snow):Right.jpg",
685                         ":Data:Textures:Skybox(snow):Up.jpg",
686                         ":Data:Textures:Skybox(snow):Down.jpg",
687                         ":Data:Textures:Skybox(snow):Cloud.jpg",
688                         ":Data:Textures:Skybox(snow):Reflect.jpg");
689
690
691
692
693                 texdetail=temptexdetail;
694         }
695         if(environment==desertenvironment){
696                 windvector=0;
697                 windvector.z=2;
698                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
699                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
700                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
701                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
702
703
704                 if(ambientsound){
705                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
706                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
707                         OPENAL_SetPaused(channels[stream_desertambient], false);
708                         OPENAL_SetVolume(channels[stream_desertambient], 256);
709                 }
710
711                 OPENAL_Sample_Free(samp[footstepsound]);
712                 OPENAL_Sample_Free(samp[footstepsound2]);
713                 OPENAL_Sample_Free(samp[footstepsound3]);
714                 OPENAL_Sample_Free(samp[footstepsound4]);
715                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
716                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
717                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
718                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
719                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
720                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
721                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
722                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
723
724                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
725
726                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
727
728                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
729
730
731
732                 temptexdetail=texdetail;
733                 if(texdetail>1)texdetail=4;
734                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
735                         ":Data:Textures:Skybox(sand):Left.jpg",
736                         ":Data:Textures:Skybox(sand):Back.jpg",
737                         ":Data:Textures:Skybox(sand):Right.jpg",
738                         ":Data:Textures:Skybox(sand):Up.jpg",
739                         ":Data:Textures:Skybox(sand):Down.jpg",
740                         ":Data:Textures:Skybox(sand):Cloud.jpg",
741                         ":Data:Textures:Skybox(sand):Reflect.jpg");
742
743
744
745
746                 texdetail=temptexdetail;
747         }
748         if(environment==grassyenvironment){
749                 windvector=0;
750                 windvector.z=2;
751                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
752                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
753                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
754                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
755
756                 if(ambientsound){
757                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
758                         OPENAL_SetPaused(channels[stream_wind], false);
759                         OPENAL_SetVolume(channels[stream_wind], 100);
760                 }
761
762                 OPENAL_Sample_Free(samp[footstepsound]);
763                 OPENAL_Sample_Free(samp[footstepsound2]);
764                 OPENAL_Sample_Free(samp[footstepsound3]);
765                 OPENAL_Sample_Free(samp[footstepsound4]);
766                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass1.ogg", OPENAL_HW3D, 0, 0);
767                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass2.ogg", OPENAL_HW3D, 0, 0);
768                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
769                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
770                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
771                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
772                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
773                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
774
775                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
776
777                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
778
779                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
780
781
782
783                 temptexdetail=texdetail;
784                 if(texdetail>1)texdetail=4;
785                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
786                         ":Data:Textures:Skybox(grass):Left.jpg",
787                         ":Data:Textures:Skybox(grass):Back.jpg",
788                         ":Data:Textures:Skybox(grass):Right.jpg",
789                         ":Data:Textures:Skybox(grass):Up.jpg",
790                         ":Data:Textures:Skybox(grass):Down.jpg",
791                         ":Data:Textures:Skybox(grass):Cloud.jpg",
792                         ":Data:Textures:Skybox(grass):Reflect.jpg");
793
794
795
796                 texdetail=temptexdetail;
797         }
798         temptexdetail=texdetail;
799         texdetail=1;
800         terrain.load(":Data:Textures:heightmap.png");
801
802         texdetail=temptexdetail;
803 }
804
805
806 void    Game::Loadlevel(int which){
807         stealthloading=0;
808
809         if(which==0)Loadlevel((char *)":Data:Maps:map1");
810         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
811         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
812         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
813         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
814         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
815         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
816         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
817         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
818         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
819         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
820         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
821         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
822         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
823         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
824         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
825         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
826         else Loadlevel((char *)":Data:Maps:mapsave");
827
828         whichlevel=which;
829 }
830
831 /*char * Game::MD5_string (unsigned char *string){
832 char temp[50];
833 char temp2[100];
834
835 strcpy(temp2,(const char *)string);
836 strcat((char *)temp2,(const char *)"Lugaru");
837 sprintf (temp, "%d",strlen((char *)temp2));
838 strcat((char *)temp2,temp);
839
840 MD5 context;
841 unsigned int len = strlen ( (char *)temp2);
842
843 context.update   ((unsigned char *)temp2, len);
844 context.finalize ();
845
846 return context.hex_digest();
847 }*/
848
849
850
851 void    Game::Loadlevel(char *name){
852         int i,j,k,l,m;
853         static int oldlevel;
854         int templength;
855         float lamefloat;
856         int lameint;
857
858         float headprop,legprop,armprop,bodyprop;
859
860         LOGFUNC;
861
862         LOG(std::string("Loading level...") + name);
863
864         if(!gameon)visibleloading=1;
865
866         if(stealthloading)visibleloading=0;
867
868         if(!stillloading)loadtime=0;
869         gamestarted=1;
870
871         numenvsounds=0;
872         //visibleloading=1;
873         if(tutoriallevel!=-1)tutoriallevel=0;
874         else tutoriallevel=1;
875
876         if(tutoriallevel==1)tutorialstage=0;
877         if(tutorialstage==0){
878                 tutorialstagetime=0;
879                 tutorialmaxtime=1;
880         }
881         loadingstuff=1;
882         if(!firstload){
883                 oldlevel=50;
884         }
885         OPENAL_SetPaused(channels[whooshsound], true);
886         OPENAL_SetPaused(channels[stream_firesound], true);
887
888         int mapvers;
889         FILE                    *tfile;
890         tfile=fopen( name, "rb" );
891         if(tfile)
892         {
893                 OPENAL_SetPaused(channels[stream_firesound], true);
894
895
896                 scoreadded=0;
897                 windialogue=0;
898
899                 hostiletime=0;
900
901                 won=0;
902
903                 //campaign=0;
904                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
905
906                 numdialogues=0;
907
908                 for(i=0;i<20;i++)
909                 {
910                         dialoguegonethrough[i]=0;
911                 }
912
913                 indialogue=-1;
914                 cameramode=0;
915
916                 damagedealt=0;
917                 damagetaken=0;
918
919                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
920
921                 if(difficulty!=2)minimap=1;
922                 else minimap=0;
923
924                 numhotspots=0;
925                 currenthotspot=-1;
926                 bonustime=1;
927
928                 skyboxtexture=1;
929                 skyboxr=1;
930                 skyboxg=1;
931                 skyboxb=1;
932
933                 freeze=0;
934                 winfreeze=0;
935
936                 for(i=0;i<100;i++)
937                 {
938                         bonusnum[i]=0;
939                 }
940
941                 numfalls=0;
942                 numflipfail=0;
943                 numseen=0;
944                 numstaffattack=0;
945                 numswordattack=0;
946                 numknifeattack=0;
947                 numunarmedattack=0;
948                 numescaped=0;
949                 numflipped=0;
950                 numwallflipped=0;
951                 numthrowkill=0;
952                 numafterkill=0;
953                 numreversals=0;
954                 numattacks=0;
955                 maxalarmed=0;
956                 numresponded=0;
957
958                 bonustotal=startbonustotal;
959                 bonus=0;
960                 gameon=1;
961                 changedelay=0;
962                 if(console)
963                 {
964                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
965                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
966                         OPENAL_SetPaused(channels[consolesuccesssound], false);
967                         freeze=0;
968                         console=0;
969                 }
970
971                 if(!stealthloading)
972                 {
973                         terrain.numdecals=0;
974                         sprites.numsprites=0;
975                         for(i=0;i<objects.numobjects;i++)
976                         {
977                                 objects.model[i].numdecals=0;
978                         }
979
980                         j=objects.numobjects;
981                         for(i=0;i<j;i++)
982                         {
983                                 objects.DeleteObject(0);
984                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
985                         }
986
987                         for(i=0;i<subdivision;i++)
988                         {
989                                 for(j=0;j<subdivision;j++)
990                                 {
991                                         terrain.patchobjectnum[i][j]=0;
992                                 }
993                         }
994                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
995                 }
996
997                 weapons.numweapons=0;
998
999                 funpackf(tfile, "Bi", &mapvers);
1000                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1001                 else indemo=0;
1002                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1003                 else maptype=mapkilleveryone;
1004                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1005                 else hostile=1;
1006                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1007                 else
1008                 {
1009                         viewdistance=100;
1010                         fadestart=.6;
1011                 }
1012                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1013                 else
1014                 {
1015                         skyboxtexture=1;
1016                         skyboxr=1;
1017                         skyboxg=1;
1018                         skyboxb=1;
1019                 }
1020                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1021                 else
1022                 {
1023                         skyboxlightr=skyboxr;
1024                         skyboxlightg=skyboxg;
1025                         skyboxlightb=skyboxb;
1026                 }
1027                 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);
1028                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1029                 player[0].originalcoords=player[0].coords;
1030                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1031                 {
1032                         for(j=0;j<player[0].num_weapons;j++)
1033                         {
1034                                 player[0].weaponids[j]=weapons.numweapons;
1035                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1036                                 weapons.owner[weapons.numweapons]=0;
1037                                 weapons.numweapons++;
1038                         }
1039                 }
1040
1041                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1042
1043                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1044                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1045                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1046                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1047
1048                 funpackf(tfile, "Bi", &player[0].numclothes);
1049
1050                 if(mapvers>=9)
1051                 {
1052                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1053                 }
1054                 else
1055                 {
1056                         player[0].whichskin=0;
1057                         player[0].creature=rabbittype;
1058                 }
1059
1060                 for(i=0;i<max_dialogues;i++)
1061                 {
1062                         for(j=0;j<max_dialoguelength;j++)
1063                         {
1064                                 for(k=0;k<128;k++)
1065                                 {
1066                                         dialoguetext[i][j][k]='\0';
1067                                 }
1068                                 for(k=0;k<64;k++)
1069                                 {
1070                                         dialoguename[i][j][k]='\0';
1071                                 }
1072                         }
1073                 }
1074
1075                 player[0].lastattack=-1;
1076                 player[0].lastattack2=-1;
1077                 player[0].lastattack3=-1;
1078
1079                 if(mapvers>=8)
1080                 {
1081                         funpackf(tfile, "Bi", &numdialogues);
1082                         if(numdialogues)
1083                         {
1084                                 for(k=0;k<numdialogues;k++)
1085                                 {
1086                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1087                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1088                                         for(l=0;l<10;l++)
1089                                         {
1090                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1091                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1092                                         }
1093                                         if(numdialogueboxes)
1094                                         {
1095                                                 for(l=0;l<numdialogueboxes[k];l++)
1096                                                 {
1097                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1098                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1099                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1100                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1101                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1102
1103                                                         bool doneread;
1104
1105                                                         funpackf(tfile, "Bi",&templength);
1106                                                         if(templength>128||templength<=0)templength=128;
1107                                                         for(m=0;m<templength;m++){
1108                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1109                                                                 if(dialoguetext[k][l][m]=='\0')break;
1110                                                         }
1111
1112                                                         funpackf(tfile, "Bi",&templength);
1113                                                         if(templength>64||templength<=0)templength=64;
1114                                                         for(m=0;m<templength;m++){
1115                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1116                                                                 if(dialoguename[k][l][m]=='\0'){
1117                                                                         break;
1118                                                                 }
1119                                                         }
1120                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1121                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1122                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1123
1124                                                         for(m=0;m<10;m++)
1125                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1126
1127                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1128                                                 }
1129                                         }
1130                                 }
1131                         }
1132                 }
1133                 else numdialogues=0;
1134
1135                 if(player[0].numclothes)
1136                 {
1137                         for(k=0;k<player[0].numclothes;k++)
1138                         {
1139                                 funpackf(tfile, "Bi", &templength);
1140                                 for(l=0;l<templength;l++)
1141                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1142                                 player[0].clothes[k][templength]='\0';
1143                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1144                         }
1145                 }
1146
1147                 funpackf(tfile, "Bi", &environment);
1148
1149                 funpackf(tfile, "Bi", &objects.numobjects);
1150                 if(objects.numobjects)
1151                 {
1152                         for(i=0;i<objects.numobjects;i++)
1153                         {
1154                                 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]);
1155                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1156                         }
1157                 }
1158
1159                 if(mapvers>=7)
1160                 {
1161                         funpackf(tfile, "Bi", &numhotspots);
1162                         if(numhotspots)
1163                         {
1164                                 for(i=0;i<numhotspots;i++)
1165                                 {
1166                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1167                                         funpackf(tfile, "Bi", &templength);
1168                                         if(templength)
1169                                                 for(l=0;l<templength;l++)
1170                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1171                                         hotspottext[i][templength]='\0';
1172                                         if(hotspottype[i]==-111)indemo=1;
1173                                 }
1174                         }
1175                 }
1176                 else numhotspots=0;
1177
1178                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1179
1180                 if(!stealthloading)
1181                 {
1182                         objects.center=0;
1183                         for(i=0;i<objects.numobjects;i++)
1184                         {
1185                                 objects.center+=objects.position[i];
1186                         }
1187                         objects.center/=objects.numobjects;
1188
1189
1190                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1191
1192                         float maxdistance=0;
1193                         float tempdist;
1194                         int whichclosest;
1195                         for(i=0;i<objects.numobjects;i++)
1196                         {
1197                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1198                                 if(tempdist>maxdistance)
1199                                 {
1200                                         whichclosest=i;
1201                                         maxdistance=tempdist;
1202                                 }
1203                         }
1204                         objects.radius=fast_sqrt(maxdistance);
1205                 }
1206
1207                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1208                 //mapcenter=objects.center;
1209                 //mapradius=objects.radius;
1210
1211                 funpackf(tfile, "Bi", &numplayers);
1212                 int howmanyremoved=0;
1213                 bool removeanother=0;
1214                 if(numplayers>1&&numplayers<maxplayers)
1215                 {
1216                         for(i=1;i<numplayers;i++)
1217                         {
1218                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1219                                 removeanother=0;
1220
1221                                 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);
1222                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1223                                 else player[i-howmanyremoved].howactive=typeactive;
1224                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1225                                 else player[i-howmanyremoved].scale=-1;
1226                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1227                                 else player[i-howmanyremoved].immobile=0;
1228                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1229                                 else player[i-howmanyremoved].rotation=0;
1230                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1231                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1232                                         removeanother=1;
1233                                         howmanyremoved++;
1234                                 }
1235                                 if(!removeanother)
1236                                 {
1237                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1238                                         {
1239                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1240                                                 {
1241                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1242                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1243                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1244                                                         weapons.numweapons++;
1245                                                 }
1246                                         }
1247                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1248                                         //player[i-howmanyremoved].numwaypoints=10;
1249                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1250                                         {
1251                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1252                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1253                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1254                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1255                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1256                                         }
1257
1258                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1259                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1260
1261                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1262                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1263                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1264                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1265
1266                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1267                                         else
1268                                         {
1269                                                 headprop=1;
1270                                                 bodyprop=1;
1271                                                 armprop=1;
1272                                                 legprop=1;
1273                                         }
1274                                         if(player[i-howmanyremoved].creature==wolftype)
1275                                         {
1276                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1277                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1278                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1279                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1280                                         }
1281
1282                                         if(player[i-howmanyremoved].creature==rabbittype)
1283                                         {
1284                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1285                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1286                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1287                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1288                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1289                                         }
1290
1291                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1292                                         if(player[i-howmanyremoved].numclothes)
1293                                         {
1294                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1295                                                 {
1296                                                         int templength;
1297                                                         funpackf(tfile, "Bi", &templength);
1298                                                         for(l=0;l<templength;l++)
1299                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1300                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1301                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1302                                                 }
1303                                         }
1304                                 }
1305                         }
1306                 }
1307                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1308
1309                 numplayers-=howmanyremoved;
1310                 funpackf(tfile, "Bi", &numpathpoints);
1311                 if(numpathpoints>30||numpathpoints<0)
1312                         numpathpoints=0;
1313                 if(numpathpoints)
1314                 {
1315                         for(j=0;j<numpathpoints;j++)
1316                         {
1317                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1318                                 for(k=0;k<numpathpointconnect[j];k++){
1319                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1320                                 }
1321                         }
1322                 }
1323                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1324
1325                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1326
1327                 SetUpLighting();
1328                 if(environment!=oldenvironment)Setenvironment(environment);
1329                 oldenvironment=environment;
1330
1331                 if(!stealthloading)
1332                 {
1333                         j=objects.numobjects;
1334                         objects.numobjects=0;
1335                         for(i=0;i<j;i++)
1336                         {
1337                                 //if(objects.type[i]!=spiketype)
1338                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1339                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1340                         }
1341
1342                         //if(skyboxtexture){
1343                         terrain.DoShadows();
1344                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1345                         objects.DoShadows();
1346                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1347                         /*}
1348                         else terrain.DoLighting();
1349                         */
1350                 }
1351
1352                 fclose(tfile);
1353
1354                 oldlevel=whichlevel;
1355
1356
1357                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1358                 for(i=0;i<numplayers;i++)
1359                 {
1360                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1361                         player[i].burnt=0;
1362                         player[i].bled=0;
1363                         player[i].onfire=0;
1364                         if(i==0||player[i].scale<0)player[i].scale=.2;
1365                         player[i].skeleton.free=0;
1366                         player[i].skeleton.id=i;
1367                         //if(Random()%2==0)player[i].creature=wolftype;
1368                         //else player[i].creature=rabbittype;
1369                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1370                         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);
1371                         else
1372                         {
1373                                 if(player[i].creature!=wolftype){
1374                                         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);
1375                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1376                                 }
1377                                 if(player[i].creature==wolftype){
1378                                         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);
1379                                 }
1380                         }
1381
1382
1383                         int texsize;
1384                         texsize=512*512*3/texdetail/texdetail;
1385                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1386                         //player[i].skeleton.skinText.resize(texsize);
1387
1388                         if(player[i].creature==rabbittype)
1389                         {
1390                                 if(player[i].whichskin==0){
1391                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                                 else if(player[i].whichskin==1){
1394                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1395                                 }
1396                                 else if(player[i].whichskin==2){
1397                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1398                                 }
1399                                 else if(player[i].whichskin==3){
1400                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1401                                 }
1402                                 else if(player[i].whichskin==4){
1403                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1404                                 }
1405                                 else if(player[i].whichskin==5){
1406                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1407                                 }
1408                                 else if(player[i].whichskin==6){
1409                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1410                                 }
1411                                 else if(player[i].whichskin==7){
1412                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1413                                 }
1414                                 else if(player[i].whichskin==8){
1415                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416                                 }
1417                                 else if(player[i].whichskin==9){
1418                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1419                                 }
1420                         }
1421                         if(player[i].creature==wolftype)
1422                         {
1423                                 //k=abs(Random()%3);
1424                                 if(player[i].whichskin==0){
1425                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1426                                 }
1427                                 else if(player[i].whichskin==1){
1428                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1429                                 }
1430                                 else if(player[i].whichskin==2){
1431                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1432                                 }
1433                         }
1434
1435                         if(player[i].numclothes)
1436                         {
1437                                 for(j=0;j<player[i].numclothes;j++)
1438                                 {
1439                                         tintr=player[i].clothestintr[j];
1440                                         tintg=player[i].clothestintg[j];
1441                                         tintb=player[i].clothestintb[j];
1442                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1443                                 }
1444                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1445                         }
1446
1447                         player[i].currentanimation=bounceidleanim;
1448                         player[i].targetanimation=bounceidleanim;
1449                         player[i].currentframe=0;
1450                         player[i].targetframe=1;
1451                         player[i].target=0;
1452                         player[i].speed=1+(float)(Random()%100)/1000;
1453                         if(difficulty==0)player[i].speed-=.2;
1454                         if(difficulty==1)player[i].speed-=.1;
1455
1456                         player[i].velocity=0;
1457                         player[i].oldcoords=player[i].coords;
1458                         player[i].realoldcoords=player[i].coords;
1459
1460                         player[i].id=i;
1461                         player[i].skeleton.id=i;
1462                         player[i].updatedelay=0;
1463                         player[i].normalsupdatedelay=0;
1464
1465                         player[i].aitype=passivetype;
1466                         player[i].aitarget=0;
1467                         player[i].madskills=0;
1468
1469                         if(i==0)
1470                         {
1471                                 player[i].proportionhead=1.2;
1472                                 player[i].proportionbody=1.05;
1473                                 player[i].proportionarms=1.00;
1474                                 player[i].proportionlegs=1.1;
1475                                 player[i].proportionlegs.y=1.05;
1476                         }
1477                         player[i].headless=0;
1478                         player[i].currentoffset=0;
1479                         player[i].targetoffset=0;
1480                         /*player[i].armorhead=1;
1481                         player[i].armorhigh=1;
1482                         player[i].armorlow=1;
1483                         player[i].protectionhead=1;
1484                         player[i].protectionhigh=1;
1485                         player[i].protectionlow=1;
1486                         player[i].metalhead=1;
1487                         player[i].metalhigh=1;
1488                         player[i].metallow=1;
1489                         player[i].power=1;
1490                         player[i].speedmult=1;*/
1491
1492                         player[i].damagetolerance=200;
1493
1494                         if(player[i].creature==wolftype)
1495                         {
1496                                 /*player[i].proportionhead=1.1;
1497                                 player[i].proportionbody=1.1;
1498                                 player[i].proportionarms=1.1;
1499                                 player[i].proportionlegs=1.1;
1500                                 player[i].proportionlegs.y=1.1;*/
1501                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1502
1503                                 player[i].damagetolerance=300;
1504                         }
1505
1506                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1507                         if(cellophane)
1508                         {
1509                                 player[i].proportionhead.z=0;
1510                                 player[i].proportionbody.z=0;
1511                                 player[i].proportionarms.z=0;
1512                                 player[i].proportionlegs.z=0;
1513                         }
1514
1515                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1516
1517                         player[i].headmorphness=0;
1518                         player[i].targetheadmorphness=1;
1519                         player[i].headmorphstart=0;
1520                         player[i].headmorphend=0;
1521
1522                         player[i].pausetime=0;
1523
1524                         player[i].dead=0;
1525                         player[i].jumppower=5;
1526                         player[i].damage=0;
1527                         player[i].permanentdamage=0;
1528                         player[i].superpermanentdamage=0;
1529
1530                         player[i].forwardkeydown=0;
1531                         player[i].leftkeydown=0;
1532                         player[i].backkeydown=0;
1533                         player[i].rightkeydown=0;
1534                         player[i].jumpkeydown=0;
1535                         player[i].crouchkeydown=0;
1536                         player[i].throwkeydown=0;
1537
1538                         player[i].collided=-10;
1539                         player[i].loaded=1;
1540                         player[i].bloodloss=0;
1541                         player[i].weaponactive=-1;
1542                         player[i].weaponstuck=-1;
1543                         player[i].bleeding=0;
1544                         player[i].deathbleeding=0;
1545                         player[i].stunned=0;
1546                         player[i].hasvictim=0;
1547                         player[i].wentforweapon=0;
1548                 }
1549
1550                 player[0].aitype=playercontrolled;
1551                 player[0].weaponactive=-1;
1552
1553                 if(difficulty==1)
1554                 {
1555                         //player[0].speedmult=1/.9;
1556                         player[0].power=1/.9;
1557                 }
1558
1559                 if(difficulty==0)
1560                 {
1561                         //player[0].speedmult=1/.8;
1562                         player[0].power=1/.8;
1563                 }
1564
1565                 //player[0].weaponstuck=1;
1566
1567                 if(difficulty==1)player[0].damagetolerance=250;
1568                 if(difficulty==0)player[0].damagetolerance=300;
1569                 if(difficulty==0)player[0].armorhead*=1.5;
1570                 if(difficulty==0)player[0].armorhigh*=1.5;
1571                 if(difficulty==0)player[0].armorlow*=1.5;
1572                 cameraloc=player[0].coords;
1573                 cameraloc.y+=5;
1574                 rotation=player[0].rotation;
1575
1576                 hawkcoords=player[0].coords;
1577                 hawkcoords.y+=30;
1578
1579                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1580                 //weapons.numweapons=numplayers;
1581                 for(i=0;i<weapons.numweapons;i++)
1582                 {
1583                         weapons.bloody[i]=0;
1584                         weapons.blooddrip[i]=0;
1585                         weapons.blooddripdelay[i]=0;
1586                         weapons.onfire[i]=0;
1587                         weapons.flamedelay[i]=0;
1588                         weapons.damage[i]=0;
1589                         //weapons.type[i]=sword;
1590                         if(weapons.type[i]==sword){
1591                                 weapons.mass[i]=1.5;
1592                                 weapons.tipmass[i]=1;
1593                                 weapons.length[i]=.8;
1594                         }
1595                         if(weapons.type[i]==staff){
1596                                 weapons.mass[i]=2;
1597                                 weapons.tipmass[i]=1;
1598                                 weapons.length[i]=1.5;
1599                         }
1600                         if(weapons.type[i]==knife){
1601                                 weapons.mass[i]=1;
1602                                 weapons.tipmass[i]=1.2;
1603                                 weapons.length[i]=.25;
1604                         }
1605                         weapons.position[i]=-1000;
1606                         weapons.tippoint[i]=-1000;
1607                 }
1608
1609 /*              for(i=0;i<32;i++){
1610                         //if(i<16||i>20)
1611                         OPENAL_StopSound(i);
1612                 }
1613 */
1614                 LOG("Starting background music...");
1615
1616                 OPENAL_StopSound(OPENAL_ALL);
1617                 if(environment==snowyenvironment)
1618                 {
1619                         if(ambientsound)
1620                         {
1621                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1622                                 OPENAL_SetPaused(channels[stream_wind], false);
1623                                 OPENAL_SetVolume(channels[stream_wind], 256);
1624                         }
1625                 }
1626                 else if(environment==desertenvironment)
1627                 {
1628                         if(ambientsound)
1629                         {
1630                                 //PlaySoundEx(desertambient,
1631                                 //      samp[desertambient], NULL, true);
1632                                 PlayStreamEx(stream_desertambient,
1633                                         strm[stream_desertambient], NULL, true);
1634                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1635                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1636                         }
1637                 }
1638                 else if(environment==grassyenvironment)
1639                 {
1640                         if(ambientsound)
1641                         {
1642                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1643                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1644                                 OPENAL_SetPaused(channels[stream_wind], false);
1645                                 OPENAL_SetVolume(channels[stream_wind], 100);
1646                         }
1647                 }
1648                 oldmusicvolume[0]=0;
1649                 oldmusicvolume[1]=0;
1650                 oldmusicvolume[2]=0;
1651                 oldmusicvolume[3]=0;
1652
1653
1654                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1655                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1656                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1657                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1658                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1659                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1660                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1661                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1662                 */
1663
1664                 if(!firstload)
1665                 {
1666                         firstload=1;
1667                 }
1668         }
1669         leveltime=0;
1670         loadingstuff=0;
1671         visibleloading=0;
1672 }
1673
1674 void    Game::Tick()
1675 {
1676         static int i,k,j,l,m;
1677         static XYZ facing,flatfacing,absflatfacing;
1678         static XYZ rotatetarget;
1679         static bool oldkey;
1680         static float oldtargetrotation;
1681         static int target, numgood;
1682         static XYZ tempcoords1,tempcoords2;
1683         static XYZ test;
1684         static XYZ test2;
1685         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1686         static int whichhit;
1687         static bool donesomething;
1688         static bool oldjumpkeydown;
1689
1690         int templength;
1691
1692         float headprop,bodyprop,armprop,legprop;
1693
1694         if(newnetmessages){
1695                 newnetmessages=0;
1696                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1697                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1698                 OPENAL_SetPaused(channels[consolesuccesssound], false);
1699
1700                 for(k=14;k>=2;k--){
1701                         for(j=0;j<255;j++){
1702                                 consoletext[k][j]=consoletext[k-1][j];
1703                         }
1704                         consolechars[k]=consolechars[k-1];
1705                 }
1706                 for(k=14;k>=2;k--){
1707                         for(j=0;j<255;j++){
1708                                 displaytext[k][j]=displaytext[k-1][j];
1709                         }
1710                         displaychars[k]=displaychars[k-1];
1711                         displaytime[k]=displaytime[k-1];
1712                 }
1713                 for(j=0;j<255;j++){
1714                         consoletext[1][j]=' ';
1715                         displaytext[1][j]=' ';
1716                 }
1717                 sprintf (consoletext[1], netmessages);
1718                 sprintf (displaytext[1], netmessages);
1719                 consolechars[1]=255;
1720                 displaychars[1]=255;
1721                 displaytime[1]=0;
1722         }
1723
1724         for(i=0;i<15;i++){
1725                 displaytime[i]+=multiplier;
1726         }
1727
1728         static unsigned char    theKeyMap[16];
1729         GetKeys( theKeyMap );
1730
1731         keyboardfrozen=0;
1732
1733
1734         static bool mainmenutogglekeydown;
1735         if(!console){
1736                 if(mainmenu&&endgame==1)mainmenu=10;
1737                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1738                         for(j=0;j<255;j++){
1739                                 displaytext[0][j]=' ';
1740                         }
1741                         displaychars[0]=0;
1742                         displayselected=0;
1743                         entername=0;
1744                         mainmenutogglekeydown=1;
1745                 }
1746                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||(mainmenu==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
1747                         selected=-1;
1748                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1749                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1750                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1751                                 else if(mainmenu==0&&winfreeze){
1752                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1753                                         stealthloading=1;
1754                                         else stealthloading=0;
1755
1756                                         if(!stealthloading){
1757                                         float gLoc[3]={0,0,0};
1758                                         float vel[3]={0,0,0};
1759                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1760                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1761                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1762                                         OPENAL_SetVolume(channels[firestartsound], 256);
1763                                         OPENAL_SetPaused(channels[firestartsound], false);
1764                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1765
1766                                         flashr=1;
1767                                         flashg=0;
1768                                         flashb=0;
1769                                         flashamount=1;
1770                                         flashdelay=1;
1771                                         }
1772
1773                                         startbonustotal=0;
1774
1775                                         for(i=0;i<campaignnumlevels;i++){
1776                                         levelvisible[i]=0;
1777                                         levelhighlight[i]=0;
1778                                         }
1779
1780                                         levelorder[0]=0;
1781                                         levelvisible[0]=1;
1782                                         if(accountcampaignchoicesmade[accountactive])
1783                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1784                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1785                                         levelvisible[levelorder[i+1]]=1;
1786                                         }
1787                                         int whichlevelstart;
1788                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1789                                         if(whichlevelstart<0){
1790                                         campaignchoicenum=1;
1791                                         campaignchoicewhich[0]=0;
1792                                         }
1793                                         else
1794                                         {
1795                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1796                                         if(campaignchoicenum)
1797                                         for(i=0;i<campaignchoicenum;i++){
1798                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1799                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1800                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1801                                         }
1802                                         }
1803
1804                                         loading=2;
1805                                         loadtime=0;
1806                                         targetlevel=7;
1807                                         if(firstload)TickOnceAfter();
1808                                         if(!firstload)LoadStuff();
1809                                         //else {
1810                                         for(i=0;i<255;i++){
1811                                         mapname[i]='\0';
1812                                         }
1813                                         mapname[0]=':';
1814                                         mapname[1]='D';
1815                                         mapname[2]='a';
1816                                         mapname[3]='t';
1817                                         mapname[4]='a';
1818                                         mapname[5]=':';
1819                                         mapname[6]='M';
1820                                         mapname[7]='a';
1821                                         mapname[8]='p';
1822                                         mapname[9]='s';
1823                                         mapname[10]=':';
1824
1825                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1826                                         //accountcampaignchoicesmade[accountactive]++;
1827
1828
1829                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1830                                         whichchoice=0;
1831                                         visibleloading=1;
1832                                         stillloading=1;
1833                                         Loadlevel(mapname);
1834                                         campaign=1;
1835                                         mainmenu=0;
1836                                         gameon=1;
1837                                         OPENAL_SetPaused(channels[music3], true);
1838
1839                                         stealthloading=0;*/
1840                                 }
1841                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1842                                 if(mainmenu&&musictoggle){
1843                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1844                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1845                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1846                                                 OPENAL_SetPaused(channels[stream_music3], false);
1847                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1848                                                 OPENAL_SetPaused(channels[music1], true);
1849                                         }
1850                                 }
1851                                 if(!mainmenu){
1852                                         OPENAL_SetPaused(channels[stream_music3], true);
1853                                         OPENAL_SetPaused(channels[music1], false);
1854                                 }
1855                         }
1856                         if(mainmenu==3){
1857                                 float gLoc[3]={0,0,0};
1858                                 float vel[3]={0,0,0};
1859                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1860                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1861                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1862                                 OPENAL_SetVolume(channels[fireendsound], 256);
1863                                 OPENAL_SetPaused(channels[fireendsound], false);
1864                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1865
1866                                 flashr=1;
1867                                 flashg=0;
1868                                 flashb=0;
1869                                 flashamount=1;
1870                                 flashdelay=1;
1871
1872                                 if(newdetail>2)newdetail=detail;
1873                                 if(newdetail<0)newdetail=detail;
1874                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1875                                 if(newscreenheight<0)newscreenheight=screenheight;
1876
1877                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1878                                 opstream << "Screenwidth:\n";
1879                                 opstream << newscreenwidth;
1880                                 opstream << "\nScreenheight:\n";
1881                                 opstream << newscreenheight;
1882                                 opstream << "\nMouse sensitivity:\n";
1883                                 opstream << usermousesensitivity;
1884                                 opstream << "\nBlur(0,1):\n";
1885                                 opstream << ismotionblur;
1886                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1887                                 opstream << newdetail;
1888                                 opstream << "\nFloating jump:\n";
1889                                 opstream << floatjump;
1890                                 opstream << "\nMouse jump:\n";
1891                                 opstream << mousejump;
1892                                 opstream << "\nAmbient sound:\n";
1893                                 opstream << ambientsound;
1894                                 opstream << "\nBlood (0,1,2):\n";
1895                                 opstream << bloodtoggle;
1896                                 opstream << "\nAuto slomo:\n";
1897                                 opstream << autoslomo;
1898                                 opstream << "\nFoliage:\n";
1899                                 opstream << foliage;
1900                                 opstream << "\nMusic:\n";
1901                                 opstream << musictoggle;
1902                                 opstream << "\nTrilinear:\n";
1903                                 opstream << trilinear;
1904                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1905                                 opstream << decals;
1906                                 opstream << "\nInvert mouse:\n";
1907                                 opstream << invertmouse;
1908                                 opstream << "\nGamespeed:\n";
1909                                 if(oldgamespeed==0)oldgamespeed=1;
1910                                 opstream << oldgamespeed;
1911                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1912                                 opstream << difficulty;
1913                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1914                                 opstream << damageeffects;
1915                                 opstream << "\nText:\n";
1916                                 opstream << texttoggle;
1917                                 opstream << "\nDebug:\n";
1918                                 opstream << debugmode;
1919                                 opstream << "\nVBL Sync:\n";
1920                                 opstream << vblsync;
1921                                 opstream << "\nShow Points:\n";
1922                                 opstream << showpoints;
1923                                 opstream << "\nAlways Blur:\n";
1924                                 opstream << alwaysblur;
1925                                 opstream << "\nImmediate mode (turn on on G5):\n";
1926                                 opstream << immediate;
1927                                 opstream << "\nVelocity blur:\n";
1928                                 opstream << velocityblur;
1929                             opstream << "\nVolume:\n";
1930                         opstream << volume;
1931                                 opstream << "\nForward key:\n";
1932                                 opstream << KeyToChar(forwardkey);
1933                                 opstream << "\nBack key:\n";
1934                                 opstream << KeyToChar(backkey);
1935                                 opstream << "\nLeft key:\n";
1936                                 opstream << KeyToChar(leftkey);
1937                                 opstream << "\nRight key:\n";
1938                                 opstream << KeyToChar(rightkey);
1939                                 opstream << "\nJump key:\n";
1940                                 opstream << KeyToChar(jumpkey);
1941                                 opstream << "\nCrouch key:\n";
1942                                 opstream << KeyToChar(crouchkey);
1943                                 opstream << "\nDraw key:\n";
1944                                 opstream << KeyToChar(drawkey);
1945                                 opstream << "\nThrow key:\n";
1946                                 opstream << KeyToChar(throwkey);
1947                                 opstream << "\nAttack key:\n";
1948                                 opstream << KeyToChar(attackkey);
1949                                 opstream << "\nChat key:\n";
1950                                 opstream << KeyToChar(chatkey);
1951                                 opstream.close();
1952                         }
1953                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1954                                 float gLoc[3]={0,0,0};
1955                                 float vel[3]={0,0,0};
1956                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1957                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1958                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1959                                 OPENAL_SetVolume(channels[fireendsound], 256);
1960                                 OPENAL_SetPaused(channels[fireendsound], false);
1961                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1962
1963                                 flashr=1;
1964                                 flashg=0;
1965                                 flashb=0;
1966                                 flashamount=1;
1967                                 flashdelay=1;
1968                         }
1969                         if(mainmenu==3&&gameon)mainmenu=2;
1970                         if(mainmenu==3&&!gameon)mainmenu=1;
1971                         if(mainmenu==5&&gameon)mainmenu=2;
1972                         if(mainmenu==5&&!gameon)mainmenu=1;
1973                         if(mainmenu==4)mainmenu=3;
1974                         if(mainmenu==6)mainmenu=5;
1975                         if(mainmenu==7)mainmenu=1;
1976                         if(mainmenu==9)mainmenu=5;
1977                         if(mainmenu==11)mainmenu=5;
1978                         if(mainmenu==12)mainmenu=5;
1979                         if(mainmenu==13)mainmenu=12;
1980                         if(mainmenu==14)mainmenu=13;
1981                         if(mainmenu==10)mainmenu=5;
1982                         if(mainmenu==100){
1983                                 mainmenu=5;
1984                                 gameon=0;
1985                                 winfreeze=0;
1986                         }
1987                         mainmenutogglekeydown=1;
1988                 }
1989                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1990                         mainmenutogglekeydown=0;
1991                 }
1992         }
1993
1994         /*static bool minimaptogglekeydown;
1995         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1996         minimap=1-minimap;
1997         minimaptogglekeydown=1;
1998         }
1999         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2000         minimaptogglekeydown=0;
2001         }
2002         */
2003
2004         static bool minimaptogglekeydown;
2005         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
2006                 if(tutorialstage!=51)
2007                         tutorialstagetime=tutorialmaxtime;
2008                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
2009                 OPENAL_SetVolume(channels[consolefailsound], 128);
2010                 OPENAL_SetPaused(channels[consolefailsound], false);
2011                 minimaptogglekeydown=1;
2012         }
2013         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2014                 minimaptogglekeydown=0;
2015         }
2016
2017         if(mainmenu){
2018                 //menu buttons
2019                 if(mainmenu==1||mainmenu==2){
2020                         if(Button()&&!oldbutton&&selected==1){
2021                                 if(!gameon){
2022                                         float gLoc[3]={0,0,0};
2023                                         float vel[3]={0,0,0};
2024                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2025                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2026                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2027                                         OPENAL_SetVolume(channels[firestartsound], 256);
2028                                         OPENAL_SetPaused(channels[firestartsound], false);
2029                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2030
2031                                         flashr=1;
2032                                         flashg=0;
2033                                         flashb=0;
2034                                         flashamount=1;
2035                                         flashdelay=1;
2036
2037                                         //new game
2038                                         if(accountactive!=-1)mainmenu=5;
2039                                         else mainmenu=7;
2040                                         /*
2041                                         startbonustotal=0;
2042
2043                                         loading=2;
2044                                         loadtime=0;
2045                                         if(firstload)TickOnceAfter();
2046                                         if(!firstload)LoadStuff();
2047                                         else {
2048                                         Loadlevel(0);
2049                                         }
2050                                         mainmenu=0;
2051                                         gameon=1;
2052                                         OPENAL_SetPaused(channels[music3], true);       */
2053                                 }
2054                                 else
2055                                 {
2056                                         //resume
2057                                         mainmenu=0;
2058                                         OPENAL_SetPaused(channels[stream_music3], true);
2059                                         OPENAL_SetPaused(channels[music1], false);
2060                                 }
2061                         }
2062
2063                         if(Button()&&!oldbutton&&selected==2){
2064                                 float gLoc[3]={0,0,0};
2065                                 float vel[3]={0,0,0};
2066                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2067                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2068                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2069                                 OPENAL_SetVolume(channels[firestartsound], 256);
2070                                 OPENAL_SetPaused(channels[firestartsound], false);
2071                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2072
2073                                 flashr=1;
2074                                 flashg=0;
2075                                 flashb=0;
2076                                 flashamount=1;
2077                                 flashdelay=1;
2078
2079                                 //options
2080
2081                                 mainmenu=3;
2082
2083                                 if(newdetail>2)newdetail=detail;
2084                                 if(newdetail<0)newdetail=detail;
2085                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2086                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2087                                 if(newscreenheight>3000)newscreenheight=screenheight;
2088                                 if(newscreenheight<0)newscreenheight=screenheight;
2089                         }
2090
2091                         if(Button()&&!oldbutton&&selected==3){
2092                                 float gLoc[3]={0,0,0};
2093                                 float vel[3]={0,0,0};
2094                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2095                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2096                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2097                                 OPENAL_SetVolume(channels[fireendsound], 256);
2098                                 OPENAL_SetPaused(channels[fireendsound], false);
2099                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2100
2101                                 flashr=1;
2102                                 flashg=0;
2103                                 flashb=0;
2104                                 flashamount=1;
2105                                 flashdelay=1;
2106
2107                                 if(!gameon){
2108                                         //quit
2109                                         tryquit=1;
2110                                         if(registered)OPENAL_SetPaused(channels[stream_music3], true);
2111                                 }
2112                                 else{
2113                                         //end game
2114                                         gameon=0;
2115                                         mainmenu=1;
2116                                 }
2117                         }
2118                         if(Button())oldbutton=1;
2119                         else oldbutton=0;
2120                 }
2121
2122                 if(mainmenu==3){
2123                         if(Button()&&!oldbutton&&selected!=-1){
2124                                 float gLoc[3]={0,0,0};
2125                                 float vel[3]={0,0,0};
2126                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2127                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2128                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2129                                 OPENAL_SetVolume(channels[firestartsound], 256);
2130                                 OPENAL_SetPaused(channels[firestartsound], false);
2131                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2132                         }
2133                         if(Button()&&!oldbutton&&selected==0){
2134                         
2135                                 extern SDL_Rect **resolutions;
2136                                 bool isCustomResolution = true;
2137                                 bool found = false;
2138                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2139                                 {
2140                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2141                                                 isCustomResolution = false;
2142
2143                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2144                                         {
2145                                                 i++;
2146                                                 if (resolutions[i] != NULL)
2147                                                 {
2148                                                         newscreenwidth = (int) resolutions[i]->w;
2149                                                         newscreenheight = (int) resolutions[i]->h;
2150                                                 }
2151                                                 else if (isCustomResolution)
2152                                                 {
2153                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2154                                                         {
2155                                                                 newscreenwidth = (int) resolutions[0]->w;
2156                                                                 newscreenheight = (int) resolutions[0]->h;
2157                                                         }
2158                                                         else
2159                                                         {
2160                                                                 newscreenwidth = screenwidth;
2161                                                                 newscreenheight = screenheight;
2162                                                         }
2163                                                 }
2164                                                 else
2165                                                 {
2166                                                         newscreenwidth = (int) resolutions[0]->w;
2167                                                         newscreenheight = (int) resolutions[0]->h;
2168                                                 }
2169                                                 found = true;
2170                                         }
2171                                 }
2172
2173                                 if (!found)
2174                                 {
2175                                         newscreenwidth = (int) resolutions[0]->w;
2176                                         newscreenheight = (int) resolutions[0]->h;
2177                                 }
2178
2179                                 
2180                         }
2181                         if(Button()&&!oldbutton&&selected==1){
2182                                 newdetail++;
2183                                 if(newdetail>2)newdetail=0;
2184                         }
2185                         if(Button()&&!oldbutton&&selected==2){
2186                                 bloodtoggle++;
2187                                 if(bloodtoggle>2)bloodtoggle=0;
2188                         }
2189                         if(Button()&&!oldbutton&&selected==3){
2190                                 difficulty++;
2191                                 if(difficulty>2)difficulty=0;
2192                         }
2193                         if(Button()&&!oldbutton&&selected==4){
2194                                 ismotionblur=1-ismotionblur;
2195                         }
2196                         if(Button()&&!oldbutton&&selected==5){
2197                                 decals=1-decals;
2198                         }
2199                         if(Button()&&!oldbutton&&selected==6){
2200                                 musictoggle=1-musictoggle;
2201
2202                                 if(!musictoggle){
2203                                         OPENAL_SetPaused(channels[music1], true);
2204                                         OPENAL_SetPaused(channels[stream_music2], true);
2205                                         OPENAL_SetPaused(channels[stream_music3], true);
2206
2207                                         for(i=0;i<4;i++){
2208                                                 oldmusicvolume[i]=0;
2209                                                 musicvolume[i]=0;
2210                                         }
2211                                 }
2212
2213                                 if(musictoggle){
2214                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2215                                         OPENAL_SetPaused(channels[stream_music3], false);
2216                                         OPENAL_SetVolume(channels[stream_music3], 256);
2217                                 }
2218                         }
2219                         if(Button()&&!oldbutton&&selected==9){
2220                                 invertmouse=1-invertmouse;
2221                         }
2222                         if(Button()&&!oldbutton&&selected==10){
2223                                 usermousesensitivity+=.2;
2224                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2225                         }
2226                         if(Button()&&!oldbutton&&selected==11){
2227                                 volume+=.1f;
2228                                 if(volume>1.0001f)volume=0;
2229                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2230                         }
2231                         if(Button()&&!oldbutton&&selected==7){
2232                                 /*float gLoc[3]={0,0,0};
2233                                 float vel[3]={0,0,0};
2234                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2235                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2236                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2237                                 OPENAL_SetVolume(channels[firestartsound], 256);
2238                                 OPENAL_SetPaused(channels[firestartsound], false);
2239                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2240                                 */
2241                                 flashr=1;
2242                                 flashg=0;
2243                                 flashb=0;
2244                                 flashamount=1;
2245                                 flashdelay=1;
2246
2247                                 //options
2248
2249                                 mainmenu=4;
2250                                 keyselect=-1;
2251                         }
2252                         if(Button()&&!oldbutton&&selected==8){
2253                                 float gLoc[3]={0,0,0};
2254                                 float vel[3]={0,0,0};
2255                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2256                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2257                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2258                                 OPENAL_SetVolume(channels[fireendsound], 256);
2259                                 OPENAL_SetPaused(channels[fireendsound], false);
2260                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2261
2262                                 flashr=1;
2263                                 flashg=0;
2264                                 flashb=0;
2265                                 flashamount=1;
2266                                 flashdelay=1;
2267
2268                                 if(newdetail>2)newdetail=detail;
2269                                 if(newdetail<0)newdetail=detail;
2270                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2271                                 if(newscreenheight<0)newscreenheight=screenheight;
2272
2273
2274                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2275                                 opstream << "Screenwidth:\n";
2276                                 opstream << newscreenwidth;
2277                                 opstream << "\nScreenheight:\n";
2278                                 opstream << newscreenheight;
2279                                 opstream << "\nMouse sensitivity:\n";
2280                                 opstream << usermousesensitivity;
2281                                 opstream << "\nBlur(0,1):\n";
2282                                 opstream << ismotionblur;
2283                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2284                                 opstream << newdetail;
2285                                 opstream << "\nFloating jump:\n";
2286                                 opstream << floatjump;
2287                                 opstream << "\nMouse jump:\n";
2288                                 opstream << mousejump;
2289                                 opstream << "\nAmbient sound:\n";
2290                                 opstream << ambientsound;
2291                                 opstream << "\nBlood (0,1,2):\n";
2292                                 opstream << bloodtoggle;
2293                                 opstream << "\nAuto slomo:\n";
2294                                 opstream << autoslomo;
2295                                 opstream << "\nFoliage:\n";
2296                                 opstream << foliage;
2297                                 opstream << "\nMusic:\n";
2298                                 opstream << musictoggle;
2299                                 opstream << "\nTrilinear:\n";
2300                                 opstream << trilinear;
2301                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2302                                 opstream << decals;
2303                                 opstream << "\nInvert mouse:\n";
2304                                 opstream << invertmouse;
2305                                 opstream << "\nGamespeed:\n";
2306                                 if(oldgamespeed==0)oldgamespeed=1;
2307                                 opstream << oldgamespeed;
2308                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2309                                 opstream << difficulty;
2310                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2311                                 opstream << damageeffects;
2312                                 opstream << "\nText:\n";
2313                                 opstream << texttoggle;
2314                                 opstream << "\nDebug:\n";
2315                                 opstream << debugmode;
2316                                 opstream << "\nVBL Sync:\n";
2317                                 opstream << vblsync;
2318                                 opstream << "\nShow Points:\n";
2319                                 opstream << showpoints;
2320                                 opstream << "\nAlways Blur:\n";
2321                                 opstream << alwaysblur;
2322                                 opstream << "\nImmediate mode (turn on on G5):\n";
2323                                 opstream << immediate;
2324                                 opstream << "\nVelocity blur:\n";
2325                                 opstream << velocityblur;
2326                             opstream << "\nVolume:\n";
2327                         opstream << volume;
2328                                 opstream << "\nForward key:\n";
2329                                 opstream << KeyToChar(forwardkey);
2330                                 opstream << "\nBack key:\n";
2331                                 opstream << KeyToChar(backkey);
2332                                 opstream << "\nLeft key:\n";
2333                                 opstream << KeyToChar(leftkey);
2334                                 opstream << "\nRight key:\n";
2335                                 opstream << KeyToChar(rightkey);
2336                                 opstream << "\nJump key:\n";
2337                                 opstream << KeyToChar(jumpkey);
2338                                 opstream << "\nCrouch key:\n";
2339                                 opstream << KeyToChar(crouchkey);
2340                                 opstream << "\nDraw key:\n";
2341                                 opstream << KeyToChar(drawkey);
2342                                 opstream << "\nThrow key:\n";
2343                                 opstream << KeyToChar(throwkey);
2344                                 opstream << "\nAttack key:\n";
2345                                 opstream << KeyToChar(attackkey);
2346                                 opstream << "\nChat key:\n";
2347                                 opstream << KeyToChar(chatkey);
2348                                 opstream.close();
2349
2350                                 if(mainmenu==3&&gameon)mainmenu=2;
2351                                 if(mainmenu==3&&!gameon)mainmenu=1;
2352                         }
2353                         if(Button())oldbutton=1;
2354                         else oldbutton=0;
2355                 }
2356                 if(mainmenu==4){
2357                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2358                                 float gLoc[3]={0,0,0};
2359                                 float vel[3]={0,0,0};
2360                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2361                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2362                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2363                                 OPENAL_SetVolume(channels[firestartsound], 256);
2364                                 OPENAL_SetPaused(channels[firestartsound], false);
2365                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2366                         }
2367                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2368                                 keyselect=selected;
2369                                 oldbuttons[0]=1;
2370                                 oldbuttons[1]=1;
2371                                 oldbuttons[2]=1;
2372                         }
2373                         if(keyselect!=-1){
2374                                 for(i=0;i<3;i++)
2375                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2376                                 for(i=0;i<140;i++){
2377                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2378                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2379                                                         float gLoc[3]={0,0,0};
2380                                                         float vel[3]={0,0,0};
2381                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2382                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2383                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2384                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2385                                                         OPENAL_SetPaused(channels[fireendsound], false);
2386                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2387
2388                                                         int keynum;
2389                                                         keynum=i;
2390                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2391                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2392
2393
2394
2395                                                         if(keyselect==0)forwardkey=keynum;
2396                                                         if(keyselect==1)backkey=keynum;
2397                                                         if(keyselect==2)leftkey=keynum;
2398                                                         if(keyselect==3)rightkey=keynum;
2399                                                         if(keyselect==4)crouchkey=keynum;
2400                                                         if(keyselect==5)jumpkey=keynum;
2401                                                         if(keyselect==6)drawkey=keynum;
2402                                                         if(keyselect==7)throwkey=keynum;
2403                                                         if(keyselect==8)attackkey=keynum;
2404                                                         keyselect=-1;
2405                                                 }
2406                                         }
2407                                 }}
2408                         if(Button()&&!oldbutton&&selected==9){
2409                                 float gLoc[3]={0,0,0};
2410                                 float vel[3]={0,0,0};
2411                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2412                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2413                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2414                                 OPENAL_SetVolume(channels[fireendsound], 256);
2415                                 OPENAL_SetPaused(channels[fireendsound], false);
2416                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2417
2418                                 flashr=1;
2419                                 flashg=0;
2420                                 flashb=0;
2421                                 flashamount=1;
2422                                 flashdelay=1;
2423
2424                                 mainmenu=3;
2425
2426                                 if(newdetail>2)newdetail=detail;
2427                                 if(newdetail<0)newdetail=detail;
2428                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2429                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2430                                 if(newscreenheight>3000)newscreenheight=screenheight;
2431                                 if(newscreenheight<0)newscreenheight=screenheight;
2432                         }
2433                 }
2434
2435                 if(mainmenu==5){
2436                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2437                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2438                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2439                                 OPENAL_SetPaused(channels[stream_music3], false);
2440                                 OPENAL_SetVolume(channels[stream_music3], 256);
2441
2442                                 gameon=0;
2443                                 mainmenu=12;
2444                                 accountcampaignchoicesmade[accountactive]=0;
2445                                 accountcampaignscore[accountactive]=0;
2446                                 accountcampaigntime[accountactive]=0;
2447
2448                                 float gLoc[3]={0,0,0};
2449                                 float vel[3]={0,0,0};
2450                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2451                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2452                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2453                                 OPENAL_SetVolume(channels[fireendsound], 256);
2454                                 OPENAL_SetPaused(channels[fireendsound], false);
2455                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2456
2457                                 flashr=1;
2458                                 flashg=0;
2459                                 flashb=0;
2460                                 flashamount=1;
2461                                 flashdelay=1;
2462                         }
2463
2464                         if(endgame==2){
2465                                 accountcampaignchoicesmade[accountactive]=0;
2466                                 accountcampaignscore[accountactive]=0;
2467                                 accountcampaigntime[accountactive]=0;
2468                                 endgame=0;
2469                         }
2470
2471                         if(Button()&&!oldbutton&&selected==1){
2472                                 float gLoc[3]={0,0,0};
2473                                 float vel[3]={0,0,0};
2474                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2475                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2476                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2477                                 OPENAL_SetVolume(channels[firestartsound], 256);
2478                                 OPENAL_SetPaused(channels[firestartsound], false);
2479                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2480
2481                                 flashr=1;
2482                                 flashg=0;
2483                                 flashb=0;
2484                                 flashamount=1;
2485                                 flashdelay=1;
2486
2487                                 startbonustotal=0;
2488
2489                                 loading=2;
2490                                 loadtime=0;
2491                                 targetlevel=-1;
2492                                 if(firstload)TickOnceAfter();
2493                                 if(!firstload)LoadStuff();
2494                                 else {
2495                                         Loadlevel(-1);
2496                                 }
2497
2498                                 mainmenu=0;
2499                                 gameon=1;
2500                                 OPENAL_SetPaused(channels[stream_music3], true);
2501                         }
2502                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2503                                 float gLoc[3]={0,0,0};
2504                                 float vel[3]={0,0,0};
2505                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2506                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2507                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2508                                 OPENAL_SetVolume(channels[firestartsound], 256);
2509                                 OPENAL_SetPaused(channels[firestartsound], false);
2510                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2511
2512                                 flashr=1;
2513                                 flashg=0;
2514                                 flashb=0;
2515                                 flashamount=1;
2516                                 flashdelay=1;
2517
2518                                 startbonustotal=0;
2519
2520                                 loading=2;
2521                                 loadtime=0;
2522                                 targetlevel=7;
2523                                 if(firstload)TickOnceAfter();
2524                                 if(!firstload)LoadStuff();
2525                                 //else {
2526                                 for(i=0;i<255;i++){
2527                                         mapname[i]='\0';
2528                                 }
2529                                 mapname[0]=':';
2530                                 mapname[1]='D';
2531                                 mapname[2]='a';
2532                                 mapname[3]='t';
2533                                 mapname[4]='a';
2534                                 mapname[5]=':';
2535                                 mapname[6]='M';
2536                                 mapname[7]='a';
2537                                 mapname[8]='p';
2538                                 mapname[9]='s';
2539                                 mapname[10]=':';
2540                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2541                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2542                                 visibleloading=1;
2543                                 stillloading=1;
2544                                 Loadlevel(mapname);
2545                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2546                                 //}
2547                                 campaign=1;
2548                                 mainmenu=0;
2549                                 gameon=1;
2550                                 OPENAL_SetPaused(channels[stream_music3], true);
2551                         }
2552                         if(Button()&&!oldbutton&&selected==4){
2553                                 float gLoc[3]={0,0,0};
2554                                 float vel[3]={0,0,0};
2555                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2556                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2557                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2558                                 OPENAL_SetVolume(channels[fireendsound], 256);
2559                                 OPENAL_SetPaused(channels[fireendsound], false);
2560                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2561
2562                                 flashr=1;
2563                                 flashg=0;
2564                                 flashb=0;
2565                                 flashamount=1;
2566                                 flashdelay=1;
2567
2568                                 if(mainmenu==5&&gameon)mainmenu=2;
2569                                 if(mainmenu==5&&!gameon)mainmenu=1;
2570                         }
2571                         if(Button()&&!oldbutton&&selected==5){
2572                                 float gLoc[3]={0,0,0};
2573                                 float vel[3]={0,0,0};
2574                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2575                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2576                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2577                                 OPENAL_SetVolume(channels[fireendsound], 256);
2578                                 OPENAL_SetPaused(channels[fireendsound], false);
2579                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2580
2581                                 flashr=1;
2582                                 flashg=0;
2583                                 flashb=0;
2584                                 flashamount=1;
2585                                 flashdelay=1;
2586
2587                                 mainmenu=7;
2588                         }
2589                         if(Button()&&!oldbutton&&selected==3){
2590                                 float gLoc[3]={0,0,0};
2591                                 float vel[3]={0,0,0};
2592                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2593                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2594                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2595                                 OPENAL_SetVolume(channels[firestartsound], 256);
2596                                 OPENAL_SetPaused(channels[firestartsound], false);
2597                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2598
2599                                 flashr=1;
2600                                 flashg=0;
2601                                 flashb=0;
2602                                 flashamount=1;
2603                                 flashdelay=1;
2604
2605                                 mainmenu=6;
2606                         }
2607                         if(Button()&&!oldbutton&&selected==2){
2608                                 float gLoc[3]={0,0,0};
2609                                 float vel[3]={0,0,0};
2610                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2611                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2612                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2613                                 OPENAL_SetVolume(channels[firestartsound], 256);
2614                                 OPENAL_SetPaused(channels[firestartsound], false);
2615                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2616
2617                                 flashr=1;
2618                                 flashg=0;
2619                                 flashb=0;
2620                                 flashamount=1;
2621                                 flashdelay=1;
2622
2623                                 mainmenu=9;
2624                         }
2625                         if(Button())oldbutton=1;
2626                         else oldbutton=0;
2627                 }
2628                 if(mainmenu==9){
2629                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2630                                 float gLoc[3]={0,0,0};
2631                                 float vel[3]={0,0,0};
2632                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2633                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2634                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2635                                 OPENAL_SetVolume(channels[firestartsound], 256);
2636                                 OPENAL_SetPaused(channels[firestartsound], false);
2637                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2638
2639                                 flashr=1;
2640                                 flashg=0;
2641                                 flashb=0;
2642                                 flashamount=1;
2643                                 flashdelay=1;
2644
2645                                 startbonustotal=0;
2646
2647                                 loading=2;
2648                                 loadtime=0;
2649                                 targetlevel=selected;
2650                                 if(firstload)TickOnceAfter();
2651                                 if(!firstload)LoadStuff();
2652                                 else {
2653                                         Loadlevel(selected);
2654                                 }
2655                                 campaign=0;
2656
2657                                 mainmenu=0;
2658                                 gameon=1;
2659                                 OPENAL_SetPaused(channels[stream_music3], true);
2660                         }
2661                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2662                                 float gLoc[3]={0,0,0};
2663                                 float vel[3]={0,0,0};
2664                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2665                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2666                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2667                                 OPENAL_SetVolume(channels[fireendsound], 256);
2668                                 OPENAL_SetPaused(channels[fireendsound], false);
2669                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2670
2671                                 flashr=1;
2672                                 flashg=0;
2673                                 flashb=0;
2674                                 flashamount=1;
2675                                 flashdelay=1;
2676
2677                                 mainmenu=5;
2678                         }
2679                         if(Button())oldbutton=1;
2680                         else oldbutton=0;
2681                 }
2682                 if(mainmenu==11){
2683                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2684                                 float gLoc[3]={0,0,0};
2685                                 float vel[3]={0,0,0};
2686                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2687                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2688                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2689                                 OPENAL_SetVolume(channels[firestartsound], 256);
2690                                 OPENAL_SetPaused(channels[firestartsound], false);
2691                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2692
2693                                 flashr=1;
2694                                 flashg=0;
2695                                 flashb=0;
2696                                 flashamount=1;
2697                                 flashdelay=1;
2698
2699                                 startbonustotal=0;
2700
2701                                 loading=2;
2702                                 loadtime=0;
2703                                 targetlevel=selected;
2704                                 if(firstload)TickOnceAfter();
2705                                 if(!firstload)LoadStuff();
2706                                 else {
2707                                         Loadlevel(selected);
2708                                 }
2709                                 campaign=0;
2710
2711                                 mainmenu=0;
2712                                 gameon=1;
2713                                 OPENAL_SetPaused(channels[stream_music3], true);
2714                         }
2715                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2716                                 float gLoc[3]={0,0,0};
2717                                 float vel[3]={0,0,0};
2718                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2719                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2720                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2721                                 OPENAL_SetVolume(channels[fireendsound], 256);
2722                                 OPENAL_SetPaused(channels[fireendsound], false);
2723                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2724
2725                                 flashr=1;
2726                                 flashg=0;
2727                                 flashb=0;
2728                                 flashamount=1;
2729                                 flashdelay=1;
2730
2731                                 mainmenu=5;
2732                         }
2733                         if(Button())oldbutton=1;
2734                         else oldbutton=0;
2735                 }
2736                 if(mainmenu==10){
2737                         endgame=2;
2738                         if(Button()&&!oldbutton&&selected==3){
2739                                 float gLoc[3]={0,0,0};
2740                                 float vel[3]={0,0,0};
2741                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2742                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2743                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2744                                 OPENAL_SetVolume(channels[fireendsound], 256);
2745                                 OPENAL_SetPaused(channels[fireendsound], false);
2746                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2747
2748                                 flashr=1;
2749                                 flashg=0;
2750                                 flashb=0;
2751                                 flashamount=1;
2752                                 flashdelay=1;
2753
2754                                 mainmenu=5;
2755                         }
2756                         if(Button())oldbutton=1;
2757                         else oldbutton=0;
2758                 }
2759
2760                 if(mainmenu==15||mainmenu==16){
2761                         if(Button()&&!oldbutton&&selected==1){
2762                                 float gLoc[3]={0,0,0};
2763                                 float vel[3]={0,0,0};
2764                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2765                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2766                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2767                                 OPENAL_SetVolume(channels[fireendsound], 256);
2768                                 OPENAL_SetPaused(channels[fireendsound], false);
2769                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2770
2771                                 flashr=1;
2772                                 flashg=0;
2773                                 flashb=0;
2774                                 flashamount=1;
2775                                 flashdelay=1;
2776
2777                                 if(mainmenu==15)mainmenu=5;
2778                                 else mainmenu=12;
2779                         }
2780                         if(Button())oldbutton=1;
2781                         else oldbutton=0;
2782                 }
2783
2784                 if(mainmenu==12){
2785                         endgame=2;
2786                         if(Button()&&!oldbutton&&selected==3){
2787                                 if(tryquit)quit=1;
2788                                 float gLoc[3]={0,0,0};
2789                                 float vel[3]={0,0,0};
2790                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2791                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2792                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2793                                 OPENAL_SetVolume(channels[fireendsound], 256);
2794                                 OPENAL_SetPaused(channels[fireendsound], false);
2795                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2796
2797                                 flashr=1;
2798                                 flashg=0;
2799                                 flashb=0;
2800                                 flashamount=1;
2801                                 flashdelay=1;
2802
2803                                 mainmenu=5;
2804                         }
2805
2806                         if(Button()&&!oldbutton&&selected==4){
2807                                 registernow=1;
2808                                 quit=1;
2809                                 float gLoc[3]={0,0,0};
2810                                 float vel[3]={0,0,0};
2811                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2812                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2813                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2814                                 OPENAL_SetVolume(channels[fireendsound], 256);
2815                                 OPENAL_SetPaused(channels[fireendsound], false);
2816                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2817
2818                                 flashr=1;
2819                                 flashg=0;
2820                                 flashb=0;
2821                                 flashamount=1;
2822                                 flashdelay=1;
2823                         }
2824
2825
2826                         if(Button()&&!oldbutton&&selected==5){
2827                                 tryquit=0;
2828                                 float gLoc[3]={0,0,0};
2829                                 float vel[3]={0,0,0};
2830                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2831                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2832                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2833                                 OPENAL_SetVolume(channels[fireendsound], 256);
2834                                 OPENAL_SetPaused(channels[fireendsound], false);
2835                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2836
2837                                 flashr=1;
2838                                 flashg=0;
2839                                 flashb=0;
2840                                 flashamount=1;
2841                                 flashdelay=1;
2842
2843                                 mainmenu=13;
2844                         }
2845                         if(Button())oldbutton=1;
2846                         else oldbutton=0;
2847                 }
2848                 if(mainmenu==6){
2849                         if(Button()&&!oldbutton&&selected!=-1){
2850                                 float gLoc[3]={0,0,0};
2851                                 float vel[3]={0,0,0};
2852                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2853                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2854                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2855                                 OPENAL_SetVolume(channels[firestartsound], 256);
2856                                 OPENAL_SetPaused(channels[firestartsound], false);
2857                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2858                         }
2859                         if(Button()&&!oldbutton&&selected==1){
2860                                 float gLoc[3]={0,0,0};
2861                                 float vel[3]={0,0,0};
2862                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2863                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2864                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2865                                 OPENAL_SetVolume(channels[fireendsound], 256);
2866                                 OPENAL_SetPaused(channels[fireendsound], false);
2867                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2868
2869                                 flashr=1;
2870                                 flashg=0;
2871                                 flashb=0;
2872                                 flashamount=1;
2873                                 flashdelay=1;
2874
2875                                 for(i=accountactive;i<numaccounts-1;i++){
2876                                         accountdifficulty[i]=accountdifficulty[i+1];
2877                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2878                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2879                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2880                                         }
2881                                         accountpoints[i]=accountpoints[i+1];
2882                                         for(j=0;j<50;j++){
2883                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2884                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2885                                         }
2886                                         for(j=0;j<60;j++){
2887                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2888                                         }
2889                                         for(j=0;j<256;j++){
2890                                                 accountname[i][j]=accountname[i+1][j];
2891                                         }
2892                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2893                                         accountprogress[i]=accountprogress[i+1];
2894                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2895                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2896                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2897                                 }
2898
2899                                 numaccounts--;
2900                                 accountactive=-1;
2901
2902
2903                                 mainmenu=7;
2904                         }
2905                         if(Button()&&!oldbutton&&selected==2){
2906                                 float gLoc[3]={0,0,0};
2907                                 float vel[3]={0,0,0};
2908                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2909                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2910                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2911                                 OPENAL_SetVolume(channels[fireendsound], 256);
2912                                 OPENAL_SetPaused(channels[fireendsound], false);
2913                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2914
2915                                 flashr=1;
2916                                 flashg=0;
2917                                 flashb=0;
2918                                 flashamount=1;
2919                                 flashdelay=1;
2920
2921                                 mainmenu=5;
2922                         }
2923                         if(Button())oldbutton=1;
2924                         else oldbutton=0;
2925                 }
2926                 if(mainmenu==7){
2927                         if(Button()&&!oldbutton&&selected!=-1){
2928                                 float gLoc[3]={0,0,0};
2929                                 float vel[3]={0,0,0};
2930                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2931                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2932                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2933                                 OPENAL_SetVolume(channels[firestartsound], 256);
2934                                 OPENAL_SetPaused(channels[firestartsound], false);
2935                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2936                         }
2937                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2938                                 entername=1;
2939                         }
2940                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2941                                 accountactive=selected-1;
2942                                 mainmenu=5;
2943                                 flashr=1;
2944                                 flashg=0;
2945                                 flashb=0;
2946                                 flashamount=1;
2947                                 flashdelay=1;
2948                         }
2949                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2950                                 float gLoc[3]={0,0,0};
2951                                 float vel[3]={0,0,0};
2952                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2953                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2954                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2955                                 OPENAL_SetVolume(channels[fireendsound], 256);
2956                                 OPENAL_SetPaused(channels[fireendsound], false);
2957                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2958
2959                                 flashr=1;
2960                                 flashg=0;
2961                                 flashb=0;
2962                                 flashamount=1;
2963                                 flashdelay=1;
2964
2965                                 mainmenu=1;
2966
2967                                 for(j=0;j<255;j++){
2968                                         displaytext[0][j]=' ';
2969                                 }
2970                                 displaychars[0]=0;
2971                                 displayselected=0;
2972                                 entername=0;
2973                         }
2974                         if(Button())oldbutton=1;
2975                         else oldbutton=0;
2976                 }
2977                 if(mainmenu==8){
2978                         if(Button()&&!oldbutton&&selected!=-1){
2979                                 float gLoc[3]={0,0,0};
2980                                 float vel[3]={0,0,0};
2981                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2982                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2983                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2984                                 OPENAL_SetVolume(channels[firestartsound], 256);
2985                                 OPENAL_SetPaused(channels[firestartsound], false);
2986                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2987
2988                                 if(selected==0)accountdifficulty[accountactive]=0;
2989                                 if(selected==1)accountdifficulty[accountactive]=1;
2990                                 if(selected==2)accountdifficulty[accountactive]=2;
2991
2992                                 mainmenu=5;
2993
2994                                 flashr=1;
2995                                 flashg=0;
2996                                 flashb=0;
2997                                 flashamount=1;
2998                                 flashdelay=1;
2999
3000                         }
3001                         if(Button())oldbutton=1;
3002                         else oldbutton=0;
3003                 }
3004
3005
3006                 if(Button())oldbutton=1;
3007                 else oldbutton=0;
3008
3009                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
3010                         tryquit=1;
3011                         if(mainmenu==3){
3012                                 if(newdetail>2)newdetail=detail;
3013                                 if(newdetail<0)newdetail=detail;
3014                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
3015                                 if(newscreenheight<0)newscreenheight=screenheight;
3016
3017                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
3018                                 opstream << "Screenwidth:\n";
3019                                 opstream << newscreenwidth;
3020                                 opstream << "\nScreenheight:\n";
3021                                 opstream << newscreenheight;
3022                                 opstream << "\nMouse sensitivity:\n";
3023                                 opstream << usermousesensitivity;
3024                                 opstream << "\nBlur(0,1):\n";
3025                                 opstream << ismotionblur;
3026                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3027                                 opstream << newdetail;
3028                                 opstream << "\nFloating jump:\n";
3029                                 opstream << floatjump;
3030                                 opstream << "\nMouse jump:\n";
3031                                 opstream << mousejump;
3032                                 opstream << "\nAmbient sound:\n";
3033                                 opstream << ambientsound;
3034                                 opstream << "\nBlood (0,1,2):\n";
3035                                 opstream << bloodtoggle;
3036                                 opstream << "\nAuto slomo:\n";
3037                                 opstream << autoslomo;
3038                                 opstream << "\nFoliage:\n";
3039                                 opstream << foliage;
3040                                 opstream << "\nMusic:\n";
3041                                 opstream << musictoggle;
3042                                 opstream << "\nTrilinear:\n";
3043                                 opstream << trilinear;
3044                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3045                                 opstream << decals;
3046                                 opstream << "\nInvert mouse:\n";
3047                                 opstream << invertmouse;
3048                                 opstream << "\nGamespeed:\n";
3049                                 if(oldgamespeed==0)oldgamespeed=1;
3050                                 opstream << oldgamespeed;
3051                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3052                                 opstream << difficulty;
3053                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3054                                 opstream << damageeffects;
3055                                 opstream << "\nText:\n";
3056                                 opstream << texttoggle;
3057                                 opstream << "\nDebug:\n";
3058                                 opstream << debugmode;
3059                                 opstream << "\nVBL Sync:\n";
3060                                 opstream << vblsync;
3061                                 opstream << "\nShow Points:\n";
3062                                 opstream << showpoints;
3063                                 opstream << "\nAlways Blur:\n";
3064                                 opstream << alwaysblur;
3065                                 opstream << "\nImmediate mode (turn on on G5):\n";
3066                                 opstream << immediate;
3067                                 opstream << "\nVelocity blur:\n";
3068                                 opstream << velocityblur;
3069                             opstream << "\nVolume:\n";
3070                         opstream << volume;
3071                                 opstream << "\nForward key:\n";
3072                                 opstream << KeyToChar(forwardkey);
3073                                 opstream << "\nBack key:\n";
3074                                 opstream << KeyToChar(backkey);
3075                                 opstream << "\nLeft key:\n";
3076                                 opstream << KeyToChar(leftkey);
3077                                 opstream << "\nRight key:\n";
3078                                 opstream << KeyToChar(rightkey);
3079                                 opstream << "\nJump key:\n";
3080                                 opstream << KeyToChar(jumpkey);
3081                                 opstream << "\nCrouch key:\n";
3082                                 opstream << KeyToChar(crouchkey);
3083                                 opstream << "\nDraw key:\n";
3084                                 opstream << KeyToChar(drawkey);
3085                                 opstream << "\nThrow key:\n";
3086                                 opstream << KeyToChar(throwkey);
3087                                 opstream << "\nAttack key:\n";
3088                                 opstream << KeyToChar(attackkey);
3089                                 opstream << "\nChat key:\n";
3090                                 opstream << KeyToChar(chatkey);
3091                                 opstream.close();
3092                         }
3093                 }
3094
3095                 if(mainmenu==1||mainmenu==2){
3096                         if(loaddistrib>4)transition+=multiplier/8;
3097                         if(transition>1){
3098                                 transition=0;
3099                                 anim++;
3100                                 if(anim>4)anim=0;
3101                                 loaddistrib=0;
3102                         }
3103                 }
3104                 OPENAL_SetFrequency(channels[stream_music3], 22050);
3105
3106                 if(entername||mainmenu==13||mainmenu==14){
3107                         for(i=0;i<140;i++){
3108                                 if(IsKeyDown(theKeyMap, i)){
3109                                         togglekeydelay[i]+=multiplier;
3110                                         if(togglekeydelay[i]>.4){
3111                                                 togglekey[i]=0;
3112                                                 togglekeydelay[i]=.36;
3113                                         }
3114                                         if(!togglekey[i]){
3115                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3116                                                         for(j=255;j>=displayselected+1;j--){
3117                                                                 displaytext[0][j]=displaytext[0][j-1];
3118                                                         }
3119                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3120                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3121                                                         displayselected++;
3122                                                         displaychars[0]++;
3123                                                 }
3124                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3125                                                         for(j=displayselected-1;j<255;j++){
3126                                                                 displaytext[0][j]=displaytext[0][j+1];
3127                                                         }
3128                                                         displaytext[0][255]=' ';
3129                                                         displayselected--;
3130                                                         displaychars[0]--;
3131                                                 }
3132                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3133                                                         displayselected--;
3134                                                 }
3135                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3136                                                         displayselected++;
3137                                                 }
3138                                                 if(i==MAC_RETURN_KEY&&entername){
3139                                                         if(displaychars[0]){
3140                                                                 numaccounts++;
3141                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3142                                                                 accountactive=numaccounts-1;
3143                                                                 accountdifficulty[accountactive]=1;
3144                                                                 accountprogress[accountactive]=0;
3145                                                                 accountpoints[accountactive]=0;
3146                                                                 accountcampaigntime[accountactive]=0;
3147                                                                 accountcampaignscore[accountactive]=0;
3148                                                                 accountcampaignfasttime[accountactive]=0;
3149                                                                 accountcampaignhighscore[accountactive]=0;
3150                                                                 for(j=0;j<50;j++){
3151                                                                         accounthighscore[accountactive][j]=0;
3152                                                                         accountfasttime[accountactive][j]=0;
3153                                                                 }
3154                                                                 for(j=0;j<60;j++){
3155                                                                         accountunlocked[accountactive][j]=0;
3156                                                                 }
3157                                                                 accountcampaignchoicesmade[accountactive]=0;
3158
3159                                                                 for(j=0;j<255;j++){
3160                                                                         displaytext[0][j]=' ';
3161                                                                 }
3162                                                                 displaychars[0]=0;
3163                                                                 displayselected=0;
3164                                                                 entername=0;
3165
3166                                                                 mainmenu=8;
3167
3168                                                                 flashr=1;
3169                                                                 flashg=0;
3170                                                                 flashb=0;
3171                                                                 flashamount=1;
3172                                                                 flashdelay=1;
3173
3174                                                                 float gLoc[3]={0,0,0};
3175                                                                 float vel[3]={0,0,0};
3176                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3177                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3178                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3179                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3180                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3181                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3182
3183                                                                 for(j=0;j<255;j++){
3184                                                                         displaytext[0][j]=' ';
3185                                                                 }
3186                                                                 displaychars[0]=0;
3187
3188
3189                                                                 displayselected=0;
3190                                                         }}
3191
3192                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3193                                                         if(displaychars[0]){
3194                                                                 char serialstring[256];
3195                                                                 char tempstring[256];
3196                                                                 #if defined(__APPLE__)
3197                                                                 sprintf (tempstring, "%s", registrationname);
3198                                                                 #elif defined(_WIN32) || defined(__linux__)
3199                                                                 sprintf (tempstring, "%s-windows", registrationname);
3200                                                                 #else
3201                                                                 #error Please make sure you have the right registration key stuff here!
3202                                                                 #endif
3203                                                                 long num1;
3204                                                                 long num2;
3205                                                                 long num3;
3206                                                                 long num4;
3207                                                                 long long longnum;
3208                                                                 longnum = MD5_string ( tempstring);
3209                                                                 //longnum = 1111111111111111;
3210                                                                 num1 = longnum/100000000;
3211                                                                 num2 = longnum%100000000;
3212                                                                 sprintf (tempstring, "%ld-%ld-%ld-%ld\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3213
3214                                                                 int goodcode=3;
3215                                                                 int numchars=3;
3216                                                                 if(num1/10000>999)numchars+=4;
3217                                                                 else if(num1/10000>99)numchars+=3;
3218                                                                 else if(num1/10000>9)numchars+=2;
3219                                                                 else numchars+=1;
3220                                                                 if(num1%10000>999)numchars+=4;
3221                                                                 else if(num1%10000>99)numchars+=3;
3222                                                                 else if(num1%10000>9)numchars+=2;
3223                                                                 else numchars+=1;
3224                                                                 if(num2/10000>999)numchars+=4;
3225                                                                 else if(num2/10000>99)numchars+=3;
3226                                                                 else if(num2/10000>9)numchars+=2;
3227                                                                 else numchars+=1;
3228                                                                 if(num2%10000>999)numchars+=4;
3229                                                                 else if(num2%10000>99)numchars+=3;
3230                                                                 else if(num2%10000>9)numchars+=2;
3231                                                                 else numchars+=1;
3232
3233                                                                 //numchars=12;
3234
3235                                                                 for(j=0;j<numchars;j++){
3236                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3237                                                                 }
3238
3239                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3240
3241                                                                 if(goodcode<0)goodcode=0;
3242
3243                                                                 if(goodcode){
3244                                                                         registered=1;
3245                                                                         mainmenu=15;
3246
3247                                                                         FILE                    *tfile;
3248                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3249                                                                         if (tfile)
3250                                                                         {
3251                                                                                 int numchars;
3252                                                                                 numchars=strlen(registrationname);
3253                                                                                 fpackf(tfile, "Bb", registered);
3254                                                                                 fpackf(tfile, "Bi", numchars);
3255                                                                                 if(numchars>0)
3256                                                                                 {
3257                                                                                         for(j=0;j<numchars;j++)
3258                                                                                         {
3259                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3260                                                                                         }
3261                                                                                 }
3262                                                                                 fpackf(tfile, "Bi", num1);
3263                                                                                 fpackf(tfile, "Bi", num2);
3264                                                                                 fclose(tfile);
3265                                                                         }
3266                                                                 }
3267                                                                 else
3268                                                                 {
3269                                                                         mainmenu=16;
3270                                                                 }
3271                                                                 flashr=1;
3272                                                                 flashg=0;
3273                                                                 flashb=0;
3274                                                                 flashamount=1;
3275                                                                 flashdelay=1;
3276
3277                                                                 float gLoc[3]={0,0,0};
3278                                                                 float vel[3]={0,0,0};
3279                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3280                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3281                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3282                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3283                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3284                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3285
3286                                                                 for(j=0;j<255;j++){
3287                                                                         displaytext[0][j]=' ';
3288                                                                 }
3289                                                                 displaychars[0]=0;
3290                                                                 displayselected=0;
3291                                                         }}
3292
3293                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3294                                                         if(displaychars[0]){
3295                                                                 sprintf (registrationname, "%s", displaytext[0]);
3296                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3297
3298                                                                 mainmenu=14;
3299
3300                                                                 flashr=1;
3301                                                                 flashg=0;
3302                                                                 flashb=0;
3303                                                                 flashamount=1;
3304                                                                 flashdelay=1;
3305
3306                                                                 float gLoc[3]={0,0,0};
3307                                                                 float vel[3]={0,0,0};
3308                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3309                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3310                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3311                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3312                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3313                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3314
3315                                                                 for(j=0;j<255;j++){
3316                                                                         displaytext[0][j]=' ';
3317                                                                 }
3318                                                                 displaychars[0]=0;
3319
3320                                                                 /*char tempstring[50];
3321                                                                 sprintf (tempstring, registrationname);
3322                                                                 long num1;
3323                                                                 long num2;
3324                                                                 long num3;
3325                                                                 long num4;
3326                                                                 long long longnum;
3327                                                                 longnum = MD5_string ( tempstring);
3328                                                                 num1 = longnum/100000000;
3329                                                                 num2 = longnum%100000000;
3330                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3331
3332                                                                 displaychars[0]=strlen(displaytext[0]);
3333                                                                 */
3334                                                                 displayselected=0;
3335                                                         }}
3336                                         }
3337                                         togglekey[i]=1;
3338                                 }
3339                                 else {
3340                                         togglekey[i]=0;
3341                                         togglekeydelay[i]=0;
3342                                 }
3343                         }
3344
3345                         displayblinkdelay-=multiplier;
3346                         if(displayblinkdelay<=0){
3347                                 displayblinkdelay=.3;
3348                                 displayblink=1-displayblink;
3349                         }
3350                 }
3351         }
3352
3353         if(!mainmenu){
3354                 if(hostile==1)hostiletime+=multiplier;
3355                 else hostiletime=0;
3356                 if(!winfreeze)leveltime+=multiplier;
3357                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3358                         chatting=0;
3359                         console=0;
3360                         freeze=0;
3361                         displaychars[0]=0;
3362                 }
3363
3364                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3365                         chatting=1;
3366                         chattogglekeydown=1;
3367                         togglekey[chatkey]=1;
3368                         togglekeydelay[chatkey]=-20;
3369                 }
3370
3371                 if(!IsKeyDown(theKeyMap, chatkey)){
3372                         chattogglekeydown=0;
3373                 }
3374
3375                 if(chatting){
3376                         for(i=0;i<140;i++){
3377                                 if(IsKeyDown(theKeyMap, i)){
3378                                         togglekeydelay[i]+=multiplier;
3379                                         if(togglekeydelay[i]>.4){
3380                                                 togglekey[i]=0;
3381                                                 togglekeydelay[i]=.36;
3382                                         }
3383                                         if(!togglekey[i]){
3384                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3385                                                         for(j=255;j>=displayselected+1;j--){
3386                                                                 displaytext[0][j]=displaytext[0][j-1];
3387                                                         }
3388                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3389                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3390                                                         displayselected++;
3391                                                         displaychars[0]++;
3392                                                 }
3393                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3394                                                         for(j=displayselected-1;j<255;j++){
3395                                                                 displaytext[0][j]=displaytext[0][j+1];
3396                                                         }
3397                                                         displaytext[0][255]=' ';
3398                                                         displayselected--;
3399                                                         displaychars[0]--;
3400                                                 }
3401                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3402                                                         displayselected--;
3403                                                 }
3404                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3405                                                         displayselected++;
3406                                                 }
3407                                                 if(i==MAC_RETURN_KEY){
3408                                                         if(displaychars[0]){
3409                                                                 /*for(j=0;j<displaychars[0];j++){
3410                                                                 talkname[j]=displaytext[0][j];
3411                                                                 }
3412                                                                 talkname[displaychars[0]]='\0';
3413                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3414                                                                 //NetworkSendInformation(chatname);
3415                                                                 */
3416                                                                 for(j=0;j<255;j++){
3417                                                                         displaytext[0][j]=' ';
3418                                                                 }
3419                                                                 displaychars[0]=0;
3420                                                                 displayselected=0;
3421                                                                 chatting=0;
3422                                                         }
3423                                                 }
3424                                         }
3425                                         togglekey[i]=1;
3426                                 }
3427                                 else {
3428                                         togglekey[i]=0;
3429                                         togglekeydelay[i]=0;
3430                                 }
3431                         }
3432
3433                         displayblinkdelay-=multiplier;
3434                         if(displayblinkdelay<=0){
3435                                 displayblinkdelay=.3;
3436                                 displayblink=1-displayblink;
3437                         }
3438                 }
3439
3440                 if(chatting)keyboardfrozen=1;
3441
3442                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3443                         freeze=1-freeze;
3444                         if(freeze){
3445                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3446                         }
3447                         freezetogglekeydown=1;
3448                 }
3449
3450                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3451                         freezetogglekeydown=0;
3452                 }
3453
3454                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3455                         console=1-console;
3456                         if(!console)freeze=0;
3457                         if(console){
3458                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3459                         }
3460                         consoletogglekeydown=1;
3461                 }
3462
3463                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3464                         consoletogglekeydown=0;
3465                 }
3466
3467                 if(console)freeze=1;
3468
3469                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3470                         for(i=0;i<140;i++){
3471                                 if(IsKeyDown(theKeyMap, i)){
3472                                         togglekeydelay[i]+=multiplier;
3473                                         if(togglekeydelay[i]>.4){
3474                                                 togglekey[i]=0;
3475                                                 togglekeydelay[i]=.36;
3476                                         }
3477                                         if(!togglekey[i]){
3478                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3479                                                         for(j=255;j>=consoleselected+1;j--){
3480                                                                 consoletext[0][j]=consoletext[0][j-1];
3481                                                         }
3482                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3483                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3484                                                         consoleselected++;
3485                                                         consolechars[0]++;
3486                                                 }
3487                                                 else if(i==MAC_ENTER_KEY){
3488                                                         for(j=255;j>=consoleselected+1;j--){
3489                                                                 consoletext[0][j]=consoletext[0][j-1];
3490                                                         }
3491                                                         consoletext[0][consoleselected]='\n';
3492                                                         consoleselected++;
3493                                                         consolechars[0]++;
3494                                                 }
3495                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3496                                                         for(j=consoleselected-1;j<255;j++){
3497                                                                 consoletext[0][j]=consoletext[0][j+1];
3498                                                         }
3499                                                         consoletext[0][255]=' ';
3500                                                         consoleselected--;
3501                                                         consolechars[0]--;
3502                                                 }
3503                                                 if(i==MAC_ARROW_UP_KEY){
3504                                                         if(archiveselected<14)archiveselected++;
3505                                                         for(j=0;j<255;j++){
3506                                                                 consolechars[0]=consolechars[archiveselected];
3507                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3508                                                                 consoleselected=consolechars[0];
3509                                                         }
3510                                                 }
3511                                                 if(i==MAC_ARROW_DOWN_KEY){
3512                                                         if(archiveselected>0)archiveselected--;
3513                                                         for(j=0;j<255;j++){
3514                                                                 consolechars[0]=consolechars[archiveselected];
3515                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3516                                                                 consoleselected=consolechars[0];
3517                                                         }
3518                                                 }
3519                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3520                                                         consoleselected--;
3521                                                 }
3522                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3523                                                         consoleselected++;
3524                                                 }
3525                                                 if(i==MAC_RETURN_KEY){
3526                                                         archiveselected=0;
3527                                                         donesomething=0;
3528                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3529                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3530                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3531                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3532                                                                 donesomething=1;
3533                                                                 tryquit=1;
3534                                                         }
3535                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3536                                                         for(j=5;j<consolechars[0];j++){
3537                                                         talkname[j-5]=consoletext[0][j];
3538                                                         }
3539                                                         talkname[consolechars[0]-5]='\0';
3540                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3541                                                         //NetworkSendInformation(chatname);
3542                                                         donesomething=1;
3543                                                         }
3544                                                         if(Compare(consoletext[0],"name ",0,4)){
3545                                                         int numchars;
3546                                                         numchars=consolechars[0]-5;
3547                                                         if(numchars>32)numchars=32;
3548                                                         for(j=5;j<numchars+5;j++){
3549                                                         talkname[j-5]=consoletext[0][j];
3550                                                         }
3551                                                         talkname[numchars]='\0';
3552                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3553                                                         //NetworkSendInformation(chatname);
3554                                                         sprintf (playerName, "%s",talkname);
3555                                                         //NetworkSendName(playerName);
3556                                                         donesomething=1;
3557                                                         }*/
3558                                                         if(Compare(consoletext[0],"map ",0,3)){
3559                                                                 mapname[0]=':';
3560                                                                 mapname[1]='D';
3561                                                                 mapname[2]='a';
3562                                                                 mapname[3]='t';
3563                                                                 mapname[4]='a';
3564                                                                 mapname[5]=':';
3565                                                                 mapname[6]='M';
3566                                                                 mapname[7]='a';
3567                                                                 mapname[8]='p';
3568                                                                 mapname[9]='s';
3569                                                                 mapname[10]=':';
3570                                                                 for(j=4;j<consolechars[0];j++){
3571                                                                         mapname[j-4+11]=consoletext[0][j];
3572                                                                 }
3573                                                                 mapname[consolechars[0]-4+11]='\0';
3574                                                                 Loadlevel(mapname);
3575                                                                 whichlevel=-2;
3576                                                                 campaign=0;
3577                                                                 donesomething=1;
3578                                                         }
3579                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3580                                                         int v;
3581                                                         unsigned char playerNameStr[32];
3582                                                         char theIPAddress[256];
3583                                                         char thePort[32];
3584                                                         NMUInt32 port = 25710;
3585
3586                                                         strcpy(playerName, "Client");
3587                                                         GameC2PStr( playerName, playerNameStr );
3588
3589                                                         for(j=0;j<consolechars[0]-8;j++){
3590                                                         theIPAddress[j]=consoletext[0][j+8];
3591                                                         }
3592                                                         theIPAddress[consolechars[0]-8]='\0';
3593
3594                                                         sprintf( thePort, "%li", port );
3595                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3596                                                         if(v)
3597                                                         {
3598                                                         if(consolechars[0]>0){
3599                                                         for(k=14;k>=1;k--){
3600                                                         for(j=0;j<255;j++){
3601                                                         consoletext[k][j]=consoletext[k-1][j];
3602                                                         }
3603                                                         consolechars[k]=consolechars[k-1];
3604                                                         }
3605                                                         for(j=0;j<255;j++){
3606                                                         consoletext[0][j]=' ';
3607                                                         }
3608                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3609                                                         else sprintf (consoletext[0], "Could not open connection");
3610
3611                                                         consolechars[0]=255;
3612                                                         consoleselected=0;
3613                                                         }
3614                                                         }
3615                                                         else
3616                                                         {
3617                                                         donesomething=1;
3618                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3619                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3620                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3621
3622                                                         if(consolechars[0]>0){
3623                                                         for(k=14;k>=1;k--){
3624                                                         for(j=0;j<255;j++){
3625                                                         consoletext[k][j]=consoletext[k-1][j];
3626                                                         }
3627                                                         consolechars[k]=consolechars[k-1];
3628                                                         }
3629                                                         for(j=0;j<255;j++){
3630                                                         consoletext[0][j]=' ';
3631                                                         }
3632                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3633
3634                                                         consolechars[0]=255;
3635                                                         consoleselected=0;
3636                                                         }
3637                                                         }
3638                                                         }
3639
3640                                                         if(Compare(consoletext[0],"host ",0,4)){
3641                                                         unsigned char gameNameStr[32], playerNameStr[32];
3642                                                         char gameName[32];//, playerName[32];
3643                                                         NMUInt32 port;
3644                                                         int players;
3645                                                         int v;
3646
3647                                                         port = 25710;
3648                                                         players =4;
3649
3650                                                         strcpy(gameName, "Host's game");
3651                                                         strcpy(playerName, "Host");
3652                                                         GameC2PStr( gameName, gameNameStr );
3653                                                         GameC2PStr( playerName, playerNameStr );
3654
3655                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3656                                                         if(v)
3657                                                         {
3658                                                         if(consolechars[0]>0){
3659                                                         for(k=14;k>=1;k--){
3660                                                         for(j=0;j<255;j++){
3661                                                         consoletext[k][j]=consoletext[k-1][j];
3662                                                         }
3663                                                         consolechars[k]=consolechars[k-1];
3664                                                         }
3665                                                         for(j=0;j<255;j++){
3666                                                         consoletext[0][j]=' ';
3667                                                         }
3668                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3669
3670                                                         consolechars[0]=255;
3671                                                         consoleselected=0;
3672                                                         }
3673                                                         }
3674                                                         else
3675                                                         {
3676                                                         donesomething=1;
3677                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3678                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3679                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3680
3681                                                         if(consolechars[0]>0){
3682                                                         for(k=14;k>=1;k--){
3683                                                         for(j=0;j<255;j++){
3684                                                         consoletext[k][j]=consoletext[k-1][j];
3685                                                         }
3686                                                         consolechars[k]=consolechars[k-1];
3687                                                         }
3688                                                         for(j=0;j<255;j++){
3689                                                         consoletext[0][j]=' ';
3690                                                         }
3691                                                         sprintf (consoletext[0], "Game hosted");
3692
3693                                                         consolechars[0]=255;
3694                                                         consoleselected=0;
3695                                                         }
3696                                                         }
3697                                                         }
3698                                                         */
3699                                                         if(Compare(consoletext[0],"save ",0,4)){
3700                                                                 mapname[0]=':';
3701                                                                 mapname[1]='D';
3702                                                                 mapname[2]='a';
3703                                                                 mapname[3]='t';
3704                                                                 mapname[4]='a';
3705                                                                 mapname[5]=':';
3706                                                                 mapname[6]='M';
3707                                                                 mapname[7]='a';
3708                                                                 mapname[8]='p';
3709                                                                 mapname[9]='s';
3710                                                                 mapname[10]=':';
3711                                                                 for(j=5;j<consolechars[0];j++){
3712                                                                         mapname[j-5+11]=consoletext[0][j];
3713                                                                 }
3714                                                                 mapname[consolechars[0]-5+11]='\0';
3715
3716                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3717                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3718                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3719
3720                                                                 int mapvers;
3721                                                                 mapvers=12;
3722
3723
3724                                                                 FILE                    *tfile;
3725                                                                 tfile=fopen( mapname, "wb" );
3726                                                                 fpackf(tfile, "Bi", mapvers);
3727                                                                 //fpackf(tfile, "Bi", indemo);
3728                                                                 fpackf(tfile, "Bi", maptype);
3729                                                                 fpackf(tfile, "Bi", hostile);
3730                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3731                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3732                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3733                                                                 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);
3734                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3735                                                                         for(j=0;j<player[0].num_weapons;j++){
3736                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3737                                                                         }
3738
3739                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3740                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3741                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3742                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3743
3744                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3745
3746                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3747
3748                                                                         fpackf(tfile, "Bi", numdialogues);
3749                                                                         if(numdialogues)
3750                                                                                 for(k=0;k<numdialogues;k++){
3751                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3752                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3753                                                                                         for(l=0;l<10;l++){
3754                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3755                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3756                                                                                         }
3757                                                                                         if(numdialogueboxes)
3758                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3759                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3760                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3761                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3762                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3763                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3764
3765                                                                                                         templength=strlen(dialoguetext[k][l]);
3766                                                                                                         fpackf(tfile, "Bi",(templength));
3767                                                                                                         for(m=0;m<templength;m++){
3768                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3769                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3770                                                                                                         }
3771
3772                                                                                                         templength=strlen(dialoguename[k][l]);
3773                                                                                                         fpackf(tfile, "Bi",templength);
3774                                                                                                         for(m=0;m<templength;m++){
3775                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3776                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3777                                                                                                         }
3778
3779                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3780                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3781                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3782
3783                                                                                                         for(m=0;m<10;m++)
3784                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3785
3786                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3787                                                                                                 }
3788                                                                                 }
3789
3790                                                                                 if(player[0].numclothes)
3791                                                                                         for(k=0;k<player[0].numclothes;k++){
3792                                                                                                 templength=strlen(player[0].clothes[k]);
3793                                                                                                 fpackf(tfile, "Bi", templength);
3794                                                                                                 for(l=0;l<templength;l++)
3795                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3796                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3797                                                                                         }
3798
3799                                                                                         fpackf(tfile, "Bi", environment);
3800
3801                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3802
3803                                                                                         if(objects.numobjects)
3804                                                                                                 for(k=0;k<objects.numobjects;k++){
3805                                                                                                         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]);
3806                                                                                                 }
3807
3808                                                                                                 fpackf(tfile, "Bi", numhotspots);
3809                                                                                                 if(numhotspots)
3810                                                                                                         for(i=0;i<numhotspots;i++){
3811                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3812                                                                                                                 templength=strlen(hotspottext[i]);
3813                                                                                                                 fpackf(tfile, "Bi",templength);
3814                                                                                                                 for(l=0;l<templength;l++)
3815                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3816                                                                                                         }
3817
3818                                                                                                         fpackf(tfile, "Bi", numplayers);
3819                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3820                                                                                                                 for(j=1;j<numplayers;j++){
3821                                                                                                                         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);
3822                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3823                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3824                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3825                                                                                                                                 }
3826                                                                                                                                 if(player[j].numwaypoints<30){
3827                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3828                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3829                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3830                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3831                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3832                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3833                                                                                                                                         }
3834                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3835                                                                                                                                 }
3836                                                                                                                                 else{
3837                                                                                                                                         player[j].numwaypoints=0;
3838                                                                                                                                         player[j].waypoint=0;
3839                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3840                                                                                                                                 }
3841
3842                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3843                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3844                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3845                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3846
3847                                                                                                                                 if(player[j].creature==wolftype){
3848                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3849                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3850                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3851                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3852                                                                                                                                 }
3853
3854                                                                                                                                 if(player[j].creature==rabbittype){
3855                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3856                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3857                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3858                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3859                                                                                                                                 }
3860
3861                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3862
3863
3864
3865                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3866                                                                                                                                 if(player[j].numclothes)
3867                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3868                                                                                                                                                 int templength;
3869                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3870                                                                                                                                                 fpackf(tfile, "Bi", templength);
3871                                                                                                                                                 for(l=0;l<templength;l++)
3872                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3873                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3874                                                                                                                                         }
3875                                                                                                                 }
3876
3877                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3878                                                                                                                 if(numpathpoints)
3879                                                                                                                         for(j=0;j<numpathpoints;j++){
3880                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3881                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3882                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3883                                                                                                                                 }
3884                                                                                                                         }
3885
3886                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3887
3888
3889                                                                                                                         fclose(tfile);
3890                                                                                                                         donesomething=1;
3891
3892                                                                                                                         /*
3893                                                                                                                         FILE                    *tfile;
3894                                                                                                                         tfile=fopen( mapname, "wb" );
3895                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3896                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3897                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3898                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3899                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3900                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3901                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3902                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3903                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3904                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3905                                                                                                                         }
3906
3907                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3908                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3909                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3910                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3911                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3912                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3913                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3914                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3915                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3916                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3917                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3918
3919                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3920                                                                                                                         if(player[0].numclothes)
3921                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3922                                                                                                                         int templength;
3923                                                                                                                         templength=strlen(player[0].clothes[k]);
3924                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3925                                                                                                                         for(l=0;l<templength;l++)
3926                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3927                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3928                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3929                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3930                                                                                                                         }
3931
3932                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3933
3934                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3935
3936                                                                                                                         for(k=0;k<objects.numobjects;k++){
3937                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3938                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3939                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3940                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3941                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3942                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3943                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3944                                                                                                                         }
3945
3946                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3947                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3948                                                                                                                         for(j=1;j<numplayers;j++){
3949                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3950                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3951                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3952                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3953                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3954                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3955                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3956                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3957                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3958                                                                                                                         }
3959                                                                                                                         if(player[j].numwaypoints<30){
3960                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3961                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3962                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3963                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3964                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3965                                                                                                                         }
3966                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3967                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3968                                                                                                                         }
3969                                                                                                                         else{
3970                                                                                                                         player[j].numwaypoints=0;
3971                                                                                                                         player[j].waypoint=0;
3972                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3973                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3974                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3975                                                                                                                         }
3976                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3977                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3978                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3979                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3980                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3981                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3982                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3983                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3984                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3985                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3986                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3987
3988                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3989                                                                                                                         if(player[j].numclothes)
3990                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3991                                                                                                                         int templength;
3992                                                                                                                         templength=strlen(player[j].clothes[k]);
3993                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3994                                                                                                                         for(l=0;l<templength;l++)
3995                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3996                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
3997                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
3998                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
3999                                                                                                                         }
4000                                                                                                                         }
4001                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4002                                                                                                                         if(numpathpoints)
4003                                                                                                                         for(j=0;j<numpathpoints;j++){
4004                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
4005                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
4006                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
4007                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4008                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
4009                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4010                                                                                                                         }
4011                                                                                                                         }
4012
4013                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
4014                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
4015                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
4016
4017                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
4018
4019                                                                                                                         fclose(tfile);
4020                                                                                                                         donesomething=1;*/
4021                                                         }
4022                                                         /*
4023                                                         if(Compare(consoletext[0],"save ",0,4)){
4024                                                         mapname[0]=':';
4025                                                         mapname[1]='D';
4026                                                         mapname[2]='a';
4027                                                         mapname[3]='t';
4028                                                         mapname[4]='a';
4029                                                         mapname[5]=':';
4030                                                         mapname[6]='M';
4031                                                         mapname[7]='a';
4032                                                         mapname[8]='p';
4033                                                         mapname[9]='s';
4034                                                         mapname[10]=':';
4035                                                         for(j=5;j<consolechars[0];j++){
4036                                                         mapname[j-5+11]=consoletext[0][j];
4037                                                         }
4038                                                         mapname[consolechars[0]-5+11]='\0';
4039
4040                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
4041                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
4042                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
4043
4044                                                         FILE                    *tfile;
4045                                                         tfile=fopen( mapname, "wb" );
4046                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4047                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4048                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4049                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4050                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4051                                                         for(j=0;j<player[0].num_weapons;j++){
4052                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4053                                                         }
4054                                                         fwrite( &environment, 1, sizeof(int), tfile );
4055
4056                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4057                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4058                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4059                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4060                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4061
4062                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4063                                                         if(numplayers>1&&numplayers<maxplayers)
4064                                                         for(j=1;j<numplayers;j++){
4065                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4066                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4067                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4068                                                         for(k=0;k<player[j].num_weapons;k++){
4069                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4070                                                         }
4071                                                         if(player[j].numwaypoints<30){
4072                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4073                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4074                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4075                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4076                                                         }
4077                                                         else{
4078                                                         player[j].numwaypoints=0;
4079                                                         player[j].waypoint=0;
4080                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4081                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4082                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4083                                                         }
4084                                                         }
4085                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4086                                                         if(numpathpoints)
4087                                                         for(j=0;j<numpathpoints;j++){
4088                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4089                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4090                                                         for(k=0;k<numpathpointconnect[j];k++){
4091                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4092                                                         }
4093                                                         }
4094                                                         fclose(tfile);
4095                                                         donesomething=1;
4096                                                         }*/
4097                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4098                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4099                                                                 donesomething=1;
4100                                                         }
4101                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4102                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4103                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4104                                                         donesomething=1;
4105                                                         }*/
4106
4107                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4108                                                                 for(j=6;j<consolechars[0];j++){
4109                                                                         mapname[j-6]=consoletext[0][j];
4110                                                                 }
4111
4112                                                                 tintr=atof(mapname);
4113
4114                                                                 donesomething=1;
4115                                                         }
4116
4117                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4118                                                                 for(j=6;j<consolechars[0];j++){
4119                                                                         mapname[j-6]=consoletext[0][j];
4120                                                                 }
4121
4122                                                                 player[0].speedmult=atof(mapname);
4123
4124                                                                 donesomething=1;
4125                                                         }
4126
4127                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4128                                                                 for(j=9;j<consolechars[0];j++){
4129                                                                         mapname[j-9]=consoletext[0][j];
4130                                                                 }
4131
4132                                                                 player[0].power=atof(mapname);
4133
4134                                                                 donesomething=1;
4135                                                         }
4136
4137                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4138                                                                 for(j=13;j<consolechars[0];j++){
4139                                                                         mapname[j-13]=consoletext[0][j];
4140                                                                 }
4141
4142                                                                 viewdistance=atof(mapname)*100;
4143
4144                                                                 donesomething=1;
4145                                                         }
4146
4147                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4148                                                                 for(j=10;j<consolechars[0];j++){
4149                                                                         mapname[j-10]=consoletext[0][j];
4150                                                                 }
4151
4152                                                                 fadestart=atof(mapname);
4153
4154                                                                 donesomething=1;
4155                                                         }
4156
4157                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4158                                                                 for(j=6;j<consolechars[0];j++){
4159                                                                         mapname[j-6]=consoletext[0][j];
4160                                                                 }
4161
4162                                                                 player[0].power=atof(mapname);
4163
4164                                                                 donesomething=1;
4165                                                         }
4166
4167                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4168                                                                 for(j=6;j<consolechars[0];j++){
4169                                                                         mapname[j-6]=consoletext[0][j];
4170                                                                 }
4171
4172                                                                 slomospeed=atof(mapname);
4173                                                                 slomo=1-slomo;
4174                                                                 slomodelay=1000;
4175
4176                                                                 donesomething=1;
4177                                                         }
4178
4179                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4180                                                                 for(j=8;j<consolechars[0];j++){
4181                                                                         mapname[j-8]=consoletext[0][j];
4182                                                                 }
4183
4184                                                                 slomofreq=atoi(mapname);
4185
4186                                                                 donesomething=1;
4187                                                         }
4188
4189                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4190                                                                 for(j=5;j<consolechars[0];j++){
4191                                                                         mapname[j-5]=consoletext[0][j];
4192                                                                 }
4193
4194                                                                 player[0].scale=atof(mapname)*.2;
4195
4196                                                                 donesomething=1;
4197                                                         }
4198
4199                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4200                                                                 int closest=-1;
4201                                                                 float closestdist=-1;
4202                                                                 float distance;
4203                                                                 if(numplayers>1)
4204                                                                         for(i=1;i<numplayers;i++){
4205                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4206                                                                                 if(closestdist==-1||distance<closestdist){
4207                                                                                         closestdist=distance;
4208                                                                                         closest=i;
4209                                                                                 }
4210                                                                         }
4211
4212                                                                         for(j=9;j<consolechars[0];j++){
4213                                                                                 mapname[j-9]=consoletext[0][j];
4214                                                                         }
4215
4216                                                                         player[closest].scale=atof(mapname)*.2;
4217
4218                                                                         donesomething=1;
4219                                                         }
4220
4221                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4222                                                                 int startpoint;
4223                                                                 int alldone;
4224
4225                                                                 int closest=-1;
4226                                                                 float closestdist=-1;
4227                                                                 float distance;
4228                                                                 if(numplayers>1)
4229                                                                         for(i=1;i<numplayers;i++){
4230                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4231                                                                                 if(closestdist==-1||distance<closestdist){
4232                                                                                         closestdist=distance;
4233                                                                                         closest=i;
4234                                                                                 }
4235                                                                         }
4236
4237                                                                         alldone=0;
4238                                                                         startpoint=15;
4239                                                                         j=startpoint;
4240                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4241                                                                                 mapname[j-startpoint]=consoletext[0][j];
4242                                                                                 j++;
4243                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4244                                                                         }
4245                                                                         mapname[j-startpoint]='\0';
4246
4247                                                                         headprop=atof(mapname);
4248
4249                                                                         j++;
4250                                                                         startpoint=j;
4251                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4252                                                                                 mapname[j-startpoint]=consoletext[0][j];
4253                                                                                 j++;
4254                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4255                                                                         }
4256                                                                         mapname[j-startpoint]='\0';
4257
4258                                                                         bodyprop=atof(mapname);
4259
4260                                                                         j++;
4261                                                                         startpoint=j;
4262                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4263                                                                                 mapname[j-startpoint]=consoletext[0][j];
4264                                                                                 j++;
4265                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4266                                                                         }
4267                                                                         mapname[j-startpoint]='\0';
4268
4269                                                                         armprop=atof(mapname);
4270
4271                                                                         j++;
4272                                                                         startpoint=j;
4273                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4274                                                                                 mapname[j-startpoint]=consoletext[0][j];
4275                                                                                 j++;
4276                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4277                                                                         }
4278                                                                         mapname[j-startpoint]='\0';
4279
4280                                                                         legprop=atof(mapname);
4281
4282                                                                         if(player[closest].creature==wolftype){
4283                                                                                 player[closest].proportionhead=1.1*headprop;
4284                                                                                 player[closest].proportionbody=1.1*bodyprop;
4285                                                                                 player[closest].proportionarms=1.1*armprop;
4286                                                                                 player[closest].proportionlegs=1.1*legprop;
4287                                                                         }
4288
4289                                                                         if(player[closest].creature==rabbittype){
4290                                                                                 player[closest].proportionhead=1.2*headprop;
4291                                                                                 player[closest].proportionbody=1.05*bodyprop;
4292                                                                                 player[closest].proportionarms=1.00*armprop;
4293                                                                                 player[closest].proportionlegs=1.1*legprop;
4294                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4295                                                                         }
4296
4297                                                                         donesomething=1;
4298                                                         }
4299
4300
4301                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4302                                                                 for(i=1;i<numplayers;i++){
4303                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4304                                                                 }
4305
4306                                                                 donesomething=1;
4307                                                         }
4308
4309                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4310                                                                 for(j=9;j<consolechars[0];j++){
4311                                                                         mapname[j-9]=consoletext[0][j];
4312                                                                 }
4313
4314                                                                 tutoriallevel=atoi(mapname);
4315
4316                                                                 donesomething=1;
4317                                                         }
4318
4319
4320                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4321                                                                 for(j=6;j<consolechars[0];j++){
4322                                                                         mapname[j-6]=consoletext[0][j];
4323                                                                 }
4324
4325                                                                 tintg=atof(mapname);
4326
4327                                                                 donesomething=1;
4328                                                         }
4329
4330                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4331                                                                 for(j=6;j<consolechars[0];j++){
4332                                                                         mapname[j-6]=consoletext[0][j];
4333                                                                 }
4334
4335                                                                 tintb=atof(mapname);
4336
4337                                                                 donesomething=1;
4338                                                         }
4339
4340                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4341                                                                 for(j=8;j<consolechars[0];j++){
4342                                                                         mapname[j-8]=consoletext[0][j];
4343                                                                 }
4344
4345                                                                 hostile=atoi(mapname);
4346
4347                                                                 donesomething=1;
4348                                                         }
4349
4350
4351                                                         if(Compare(consoletext[0],"type active ",0,11)){
4352                                                                 editoractive=typeactive;
4353
4354                                                                 donesomething=1;
4355                                                         }
4356
4357                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4358                                                                 indemo=1;
4359                                                                 hotspot[numhotspots]=player[0].coords;
4360                                                                 hotspotsize[numhotspots]=0;
4361                                                                 hotspottype[numhotspots]=-111;
4362                                                                 mapname[0]='\0';
4363                                                                 strcpy(hotspottext[numhotspots],"mapname");
4364                                                                 numhotspots++;
4365
4366                                                                 donesomething=1;
4367                                                         }
4368
4369                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4370                                                                 indemo=0;
4371                                                                 numhotspots--;
4372
4373                                                                 donesomething=1;
4374                                                         }
4375
4376                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4377                                                                 editoractive=typesitting;
4378
4379                                                                 donesomething=1;
4380                                                         }
4381
4382                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4383                                                                 editoractive=typesittingwall;
4384
4385                                                                 donesomething=1;
4386                                                         }
4387
4388                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4389                                                                 editoractive=typesleeping;
4390
4391                                                                 donesomething=1;
4392                                                         }
4393                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4394                                                                 editoractive=typedead1;
4395
4396                                                                 donesomething=1;
4397                                                         }
4398                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4399                                                                 editoractive=typedead2;
4400
4401                                                                 donesomething=1;
4402                                                         }
4403                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4404                                                                 editoractive=typedead3;
4405                                                                 donesomething=1;
4406                                                         }
4407                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4408                                                                 editoractive=typedead4;
4409
4410                                                                 donesomething=1;
4411                                                         }
4412
4413                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4414                                                                 editorpathtype=wpkeepwalking;
4415
4416                                                                 donesomething=1;
4417                                                         }
4418
4419                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4420                                                                 editorpathtype=wppause;
4421
4422                                                                 donesomething=1;
4423                                                         }
4424
4425                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4426                                                                 maptype=mapkilleveryone;
4427
4428                                                                 donesomething=1;
4429                                                         }
4430
4431                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4432                                                                 maptype=mapgosomewhere;
4433
4434                                                                 donesomething=1;
4435                                                         }
4436
4437                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4438                                                                 maptype=mapkillsomeone;
4439
4440                                                                 donesomething=1;
4441
4442                                                         }
4443
4444                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4445                                                                 maptype=mapkillmost;
4446
4447                                                                 donesomething=1;
4448
4449                                                         }
4450
4451                                                         if(Compare(consoletext[0],"hs ",0,2)){
4452                                                                 int startpoint;
4453                                                                 int alldone;
4454
4455                                                                 hotspot[numhotspots]=player[0].coords;
4456
4457                                                                 alldone=0;
4458                                                                 startpoint=3;
4459                                                                 j=startpoint;
4460                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4461                                                                         mapname[j-startpoint]=consoletext[0][j];
4462                                                                         j++;
4463                                                                         if(consoletext[0][j]=='\0')alldone=1;
4464                                                                 }
4465                                                                 mapname[j-startpoint]='\0';
4466
4467                                                                 hotspotsize[numhotspots]=atof(mapname);
4468
4469                                                                 j++;
4470                                                                 startpoint=j;
4471                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4472                                                                         mapname[j-startpoint]=consoletext[0][j];
4473                                                                         j++;
4474                                                                         if(consoletext[0][j]=='\0')alldone=1;
4475                                                                 }
4476                                                                 mapname[j-startpoint]='\0';
4477
4478                                                                 hotspottype[numhotspots]=atoi(mapname);
4479
4480                                                                 j++;
4481                                                                 startpoint=j;
4482                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4483                                                                         mapname[j-startpoint]=consoletext[0][j];
4484                                                                         j++;
4485                                                                         if(consoletext[0][j]=='\0')alldone=1;
4486                                                                 }
4487                                                                 mapname[j-startpoint]='\n';
4488                                                                 mapname[j-startpoint+1]='\0';
4489
4490                                                                 strcpy(hotspottext[numhotspots],mapname);
4491
4492                                                                 numhotspots++;
4493
4494                                                                 donesomething=1;
4495                                                         }
4496
4497                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4498                                                                 int startpoint;
4499                                                                 int alldone;
4500
4501                                                                 alldone=0;
4502                                                                 startpoint=9;
4503                                                                 j=startpoint;
4504                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4505                                                                         mapname[j-startpoint]=consoletext[0][j];
4506                                                                         j++;
4507                                                                         if(consoletext[0][j]=='\0')alldone=1;
4508                                                                 }
4509                                                                 mapname[j-startpoint]='\0';
4510                                                                 startpoint=j+1;
4511
4512                                                                 dialoguetype[numdialogues]=atoi(mapname);
4513
4514                                                                 mapname[0]=':';
4515                                                                 mapname[1]='D';
4516                                                                 mapname[2]='a';
4517                                                                 mapname[3]='t';
4518                                                                 mapname[4]='a';
4519                                                                 mapname[5]=':';
4520                                                                 mapname[6]='D';
4521                                                                 mapname[7]='i';
4522                                                                 mapname[8]='a';
4523                                                                 mapname[9]='l';
4524                                                                 mapname[10]='o';
4525                                                                 mapname[11]='g';
4526                                                                 mapname[12]='u';
4527                                                                 mapname[13]='e';
4528                                                                 mapname[14]='s';
4529                                                                 mapname[15]=':';
4530                                                                 for(j=startpoint;j<consolechars[0];j++){
4531                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4532                                                                 }
4533                                                                 mapname[consolechars[0]-startpoint+16]='.';
4534                                                                 mapname[consolechars[0]-startpoint+17]='t';
4535                                                                 mapname[consolechars[0]-startpoint+18]='x';
4536                                                                 mapname[consolechars[0]-startpoint+19]='t';
4537                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4538
4539                                                                 for(j=0;j<max_dialoguelength;j++){
4540                                                                         for(k=0;k<128;k++){
4541                                                                                 dialoguetext[numdialogues][j][k]='\0';
4542                                                                         }
4543                                                                         for(k=0;k<64;k++){
4544                                                                                 dialoguename[numdialogues][j][k]='\0';
4545                                                                         }
4546                                                                 }
4547
4548                                                                 ifstream ipstream(ConvertFileName(mapname));
4549                                                                 ipstream.ignore(256,':');
4550                                                                 ipstream >> numdialogueboxes[numdialogues];
4551                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4552                                                                         ipstream.ignore(256,':');
4553                                                                         ipstream.ignore(256,':');
4554                                                                         ipstream.ignore(256,' ');
4555                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4556                                                                         ipstream.ignore(256,':');
4557                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4558                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4559                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4560                                                                         ipstream.ignore(256,':');
4561                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4562                                                                         ipstream.ignore(256,':');
4563                                                                         ipstream.ignore(256,' ');
4564                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4565                                                                         for(j=0;j<128;j++){
4566                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4567                                                                         }
4568                                                                         ipstream.ignore(256,':');
4569                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4570                                                                 }
4571
4572                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4573                                                                         for(j=0;j<numplayers;j++){
4574                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4575                                                                         }
4576                                                                 }
4577                                                                 ipstream.close();
4578
4579                                                                 directing=1;
4580                                                                 indialogue=0;
4581                                                                 whichdialogue=numdialogues;
4582
4583
4584                                                                 numdialogues++;
4585
4586                                                                 donesomething=1;
4587                                                         }
4588
4589                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4590                                                                 int startpoint;
4591                                                                 int alldone;
4592                                                                 int whichdi;
4593
4594                                                                 alldone=0;
4595                                                                 startpoint=12;
4596                                                                 j=startpoint;
4597                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4598                                                                         mapname[j-startpoint]=consoletext[0][j];
4599                                                                         j++;
4600                                                                         if(consoletext[0][j]=='\0')alldone=1;
4601                                                                 }
4602                                                                 mapname[j-startpoint]='\0';
4603                                                                 startpoint=j+1;
4604
4605                                                                 whichdi=atoi(mapname);
4606
4607                                                                 mapname[0]=':';
4608                                                                 mapname[1]='D';
4609                                                                 mapname[2]='a';
4610                                                                 mapname[3]='t';
4611                                                                 mapname[4]='a';
4612                                                                 mapname[5]=':';
4613                                                                 mapname[6]='D';
4614                                                                 mapname[7]='i';
4615                                                                 mapname[8]='a';
4616                                                                 mapname[9]='l';
4617                                                                 mapname[10]='o';
4618                                                                 mapname[11]='g';
4619                                                                 mapname[12]='u';
4620                                                                 mapname[13]='e';
4621                                                                 mapname[14]='s';
4622                                                                 mapname[15]=':';
4623                                                                 for(j=startpoint;j<consolechars[0];j++){
4624                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4625                                                                 }
4626                                                                 mapname[consolechars[0]-startpoint+16]='.';
4627                                                                 mapname[consolechars[0]-startpoint+17]='t';
4628                                                                 mapname[consolechars[0]-startpoint+18]='x';
4629                                                                 mapname[consolechars[0]-startpoint+19]='t';
4630                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4631
4632                                                                 for(j=0;j<max_dialoguelength;j++){
4633                                                                         for(k=0;k<128;k++){
4634                                                                                 dialoguetext[whichdi][j][k]='\0';
4635                                                                         }
4636                                                                         for(k=0;k<64;k++){
4637                                                                                 dialoguename[whichdi][j][k]='\0';
4638                                                                         }
4639                                                                 }
4640
4641                                                                 ifstream ipstream(ConvertFileName(mapname));
4642                                                                 ipstream.ignore(256,':');
4643                                                                 ipstream >> numdialogueboxes[whichdi];
4644                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4645                                                                         ipstream.ignore(256,':');
4646                                                                         ipstream.ignore(256,':');
4647                                                                         ipstream.ignore(256,' ');
4648                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4649                                                                         ipstream.ignore(256,':');
4650                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4651                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4652                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4653                                                                         ipstream.ignore(256,':');
4654                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4655                                                                         ipstream.ignore(256,':');
4656                                                                         ipstream.ignore(256,' ');
4657                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4658                                                                         for(j=0;j<128;j++){
4659                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4660                                                                         }
4661                                                                         ipstream.ignore(256,':');
4662                                                                         ipstream >> dialogueboxsound[whichdi][i];
4663                                                                 }
4664
4665                                                                 ipstream.close();
4666
4667                                                                 donesomething=1;
4668                                                         }
4669
4670                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4671                                                                 int startpoint;
4672                                                                 int alldone;
4673                                                                 int whichdi;
4674
4675                                                                 alldone=0;
4676                                                                 startpoint=8;
4677                                                                 j=startpoint;
4678                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4679                                                                         mapname[j-startpoint]=consoletext[0][j];
4680                                                                         j++;
4681                                                                         if(consoletext[0][j]=='\0')alldone=1;
4682                                                                 }
4683                                                                 mapname[j-startpoint]='\0';
4684                                                                 dialoguetype[0]=atoi(mapname);
4685
4686                                                                 startpoint=j+1;
4687
4688                                                                 donesomething=1;
4689                                                         }
4690
4691
4692                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4693                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4694
4695                                                                 donesomething=1;
4696                                                         }
4697
4698                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4699                                                                 numdialogues--;
4700                                                                 if(numdialogues<0)numdialogues=0;
4701
4702                                                                 donesomething=1;
4703                                                         }
4704
4705                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4706                                                                 player[0].immobile=1;
4707                                                                 donesomething=1;
4708                                                         }
4709
4710                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4711                                                                 player[0].immobile=0;
4712                                                                 donesomething=1;
4713                                                         }
4714
4715                                                         if(Compare(consoletext[0],"play ",0,4)){
4716                                                                 int startpoint;
4717                                                                 int alldone;
4718
4719                                                                 alldone=0;
4720                                                                 startpoint=5;
4721                                                                 j=startpoint;
4722                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4723                                                                         mapname[j-startpoint]=consoletext[0][j];
4724                                                                         j++;
4725                                                                         if(consoletext[0][j]=='\0')alldone=1;
4726                                                                 }
4727                                                                 mapname[j-startpoint]='\0';
4728                                                                 startpoint=j+1;
4729
4730                                                                 whichdialogue=atoi(mapname);
4731
4732                                                                 if(numdialogues>whichdialogue){
4733                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4734                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4735                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4736                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4737                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4738                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4739                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4740                                                                         }
4741
4742                                                                         directing=0;
4743                                                                         indialogue=0;
4744
4745                                                                         donesomething=1;
4746
4747                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4748                                                                         float gLoc[3];
4749                                                                         float vel[3];
4750                                                                         XYZ temppos;
4751                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4752                                                                         temppos=temppos-viewer;
4753                                                                         Normalise(&temppos);
4754                                                                         temppos+=viewer;
4755
4756                                                                         gLoc[0]=temppos.x;
4757                                                                         gLoc[1]=temppos.y;
4758                                                                         gLoc[2]=temppos.z;
4759                                                                         vel[0]=0;
4760                                                                         vel[1]=0;
4761                                                                         vel[2]=0;
4762                                                                         int whichsoundplay;
4763                                                                         whichsoundplay=rabbitchitter;
4764                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4765                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4766                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4767                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4768                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4769                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4770                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4771                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4772                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4773                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4774                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4775                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4776                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4777                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4778                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4779                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4780                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4781                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4782                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4783                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4784                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4785                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4786                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4787                                                                         //}
4788                                                                 }
4789                                                         }
4790
4791
4792
4793
4794                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4795                                                                 numhotspots--;
4796                                                                 if(numhotspots<0)numhotspots=0;
4797                                                                 donesomething=1;
4798                                                         }
4799
4800
4801                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4802                                                                 int startpoint;
4803                                                                 int alldone;
4804
4805                                                                 alldone=0;
4806                                                                 startpoint=11;
4807                                                                 j=startpoint;
4808                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4809                                                                         mapname[j-startpoint]=consoletext[0][j];
4810                                                                         j++;
4811                                                                         if(consoletext[0][j]=='\0')alldone=1;
4812                                                                 }
4813                                                                 mapname[j-startpoint]='\0';
4814
4815                                                                 headprop=atof(mapname);
4816
4817                                                                 j++;
4818                                                                 startpoint=j;
4819                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4820                                                                         mapname[j-startpoint]=consoletext[0][j];
4821                                                                         j++;
4822                                                                         if(consoletext[0][j]=='\0')alldone=1;
4823                                                                 }
4824                                                                 mapname[j-startpoint]='\0';
4825
4826                                                                 bodyprop=atof(mapname);
4827
4828                                                                 j++;
4829                                                                 startpoint=j;
4830                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4831                                                                         mapname[j-startpoint]=consoletext[0][j];
4832                                                                         j++;
4833                                                                         if(consoletext[0][j]=='\0')alldone=1;
4834                                                                 }
4835                                                                 mapname[j-startpoint]='\0';
4836
4837                                                                 armprop=atof(mapname);
4838
4839                                                                 j++;
4840                                                                 startpoint=j;
4841                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4842                                                                         mapname[j-startpoint]=consoletext[0][j];
4843                                                                         j++;
4844                                                                         if(consoletext[0][j]=='\0')alldone=1;
4845                                                                 }
4846                                                                 mapname[j-startpoint]='\0';
4847
4848                                                                 legprop=atof(mapname);
4849
4850                                                                 if(player[0].creature==wolftype){
4851                                                                         player[0].proportionhead=1.1*headprop;
4852                                                                         player[0].proportionbody=1.1*bodyprop;
4853                                                                         player[0].proportionarms=1.1*armprop;
4854                                                                         player[0].proportionlegs=1.1*legprop;
4855                                                                 }
4856
4857                                                                 if(player[0].creature==rabbittype){
4858                                                                         player[0].proportionhead=1.2*headprop;
4859                                                                         player[0].proportionbody=1.05*bodyprop;
4860                                                                         player[0].proportionarms=1.00*armprop;
4861                                                                         player[0].proportionlegs=1.1*legprop;
4862                                                                         player[0].proportionlegs.y=1.05*legprop;
4863                                                                 }
4864
4865                                                                 donesomething=1;
4866                                                         }
4867
4868                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4869                                                                 for(i=0;i<numplayers;i++){
4870                                                                         if(i>0)player[i].immobile=1;
4871                                                                 }
4872                                                                 donesomething=1;
4873                                                         }
4874
4875
4876                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4877                                                                 player[0].armorhead=1;
4878                                                                 player[0].armorhigh=1;
4879                                                                 player[0].armorlow=1;
4880                                                                 player[0].protectionhead=1;
4881                                                                 player[0].protectionhigh=1;
4882                                                                 player[0].protectionlow=1;
4883                                                                 player[0].metalhead=1;
4884                                                                 player[0].metalhigh=1;
4885                                                                 player[0].metallow=1;
4886                                                                 player[0].power=1;
4887                                                                 player[0].speedmult=1;
4888                                                                 player[0].scale=1;
4889
4890                                                                 if(player[0].creature==wolftype){
4891                                                                         player[0].proportionhead=1.1;
4892                                                                         player[0].proportionbody=1.1;
4893                                                                         player[0].proportionarms=1.1;
4894                                                                         player[0].proportionlegs=1.1;
4895                                                                 }
4896
4897                                                                 if(player[0].creature==rabbittype){
4898                                                                         player[0].proportionhead=1.2;
4899                                                                         player[0].proportionbody=1.05;
4900                                                                         player[0].proportionarms=1.00;
4901                                                                         player[0].proportionlegs=1.1;
4902                                                                         player[0].proportionlegs.y=1.05;
4903                                                                 }
4904
4905                                                                 player[0].numclothes=0;
4906                                                                 if(player[0].whichskin==0){
4907                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4908                                                                 }
4909                                                                 else if(player[0].whichskin==1){
4910                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4911                                                                 }
4912                                                                 else if(player[0].whichskin==2){
4913                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4914                                                                 }
4915                                                                 else if(player[0].whichskin==3){
4916                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4917                                                                 }
4918                                                                 else if(player[0].whichskin==4){
4919                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4920                                                                 }
4921                                                                 else if(player[0].whichskin==5){
4922                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4923                                                                 }
4924                                                                 else if(player[0].whichskin==6){
4925                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4926                                                                 }
4927                                                                 else if(player[0].whichskin==7){
4928                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4929                                                                 }
4930                                                                 else if(player[0].whichskin==8){
4931                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4932                                                                 }
4933                                                                 else if(player[0].whichskin==9){
4934                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4935                                                                 }
4936
4937                                                                 editoractive=typeactive;
4938                                                                 player[0].immobile=0;
4939
4940
4941
4942                                                                 donesomething=1;
4943                                                         }
4944
4945                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4946                                                                 int startpoint;
4947                                                                 int alldone;
4948                                                                 alldone=0;
4949                                                                 startpoint=5;
4950                                                                 j=startpoint;
4951                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4952                                                                         mapname[j-startpoint]=consoletext[0][j];
4953                                                                         j++;
4954                                                                         if(consoletext[0][j]=='\0')alldone=1;
4955                                                                 }
4956                                                                 mapname[j-startpoint]='\0';
4957
4958                                                                 tintr=atof(mapname);
4959
4960                                                                 j++;
4961                                                                 startpoint=j;
4962                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4963                                                                         mapname[j-startpoint]=consoletext[0][j];
4964                                                                         j++;
4965                                                                         if(consoletext[0][j]=='\0')alldone=1;
4966                                                                 }
4967                                                                 mapname[j-startpoint]='\0';
4968
4969                                                                 tintg=atof(mapname);
4970
4971                                                                 j++;
4972                                                                 startpoint=j;
4973                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4974                                                                         mapname[j-startpoint]=consoletext[0][j];
4975                                                                         j++;
4976                                                                         if(consoletext[0][j]=='\0')alldone=1;
4977                                                                 }
4978                                                                 mapname[j-startpoint]='\0';
4979
4980                                                                 tintb=atof(mapname);
4981
4982                                                                 donesomething=1;
4983                                                         }
4984
4985                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4986                                                                 int startpoint;
4987                                                                 int alldone;
4988                                                                 alldone=0;
4989                                                                 startpoint=9;
4990                                                                 j=startpoint;
4991                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4992                                                                         mapname[j-startpoint]=consoletext[0][j];
4993                                                                         j++;
4994                                                                         if(consoletext[0][j]=='\0')alldone=1;
4995                                                                 }
4996                                                                 mapname[j-startpoint]='\0';
4997
4998                                                                 skyboxr=atof(mapname);
4999
5000                                                                 j++;
5001                                                                 startpoint=j;
5002                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5003                                                                         mapname[j-startpoint]=consoletext[0][j];
5004                                                                         j++;
5005                                                                         if(consoletext[0][j]=='\0')alldone=1;
5006                                                                 }
5007                                                                 mapname[j-startpoint]='\0';
5008
5009                                                                 skyboxg=atof(mapname);
5010
5011                                                                 j++;
5012                                                                 startpoint=j;
5013                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5014                                                                         mapname[j-startpoint]=consoletext[0][j];
5015                                                                         j++;
5016                                                                         if(consoletext[0][j]=='\0')alldone=1;
5017                                                                 }
5018                                                                 mapname[j-startpoint]='\0';
5019
5020                                                                 skyboxb=atof(mapname);
5021
5022                                                                 skyboxlightr=skyboxr;
5023                                                                 skyboxlightg=skyboxg;
5024                                                                 skyboxlightb=skyboxb;
5025
5026                                                                 SetUpLighting();
5027
5028                                                                 //if(skyboxtexture){
5029                                                                 terrain.DoShadows();
5030                                                                 objects.DoShadows();
5031                                                                 /*}
5032                                                                 else terrain.DoLighting();
5033                                                                 */
5034                                                                 donesomething=1;
5035                                                         }
5036
5037                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5038                                                                 int startpoint;
5039                                                                 int alldone;
5040                                                                 alldone=0;
5041                                                                 startpoint=10;
5042                                                                 j=startpoint;
5043                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5044                                                                         mapname[j-startpoint]=consoletext[0][j];
5045                                                                         j++;
5046                                                                         if(consoletext[0][j]=='\0')alldone=1;
5047                                                                 }
5048                                                                 mapname[j-startpoint]='\0';
5049
5050                                                                 skyboxlightr=atof(mapname);
5051
5052                                                                 j++;
5053                                                                 startpoint=j;
5054                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5055                                                                         mapname[j-startpoint]=consoletext[0][j];
5056                                                                         j++;
5057                                                                         if(consoletext[0][j]=='\0')alldone=1;
5058                                                                 }
5059                                                                 mapname[j-startpoint]='\0';
5060
5061                                                                 skyboxlightg=atof(mapname);
5062
5063                                                                 j++;
5064                                                                 startpoint=j;
5065                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5066                                                                         mapname[j-startpoint]=consoletext[0][j];
5067                                                                         j++;
5068                                                                         if(consoletext[0][j]=='\0')alldone=1;
5069                                                                 }
5070                                                                 mapname[j-startpoint]='\0';
5071
5072                                                                 skyboxlightb=atof(mapname);
5073
5074                                                                 SetUpLighting();
5075
5076                                                                 //if(skyboxtexture){
5077                                                                 terrain.DoShadows();
5078                                                                 objects.DoShadows();
5079                                                                 /*}
5080                                                                 else terrain.DoLighting();
5081                                                                 */
5082                                                                 donesomething=1;
5083                                                         }
5084
5085                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5086                                                                 skyboxtexture=1-skyboxtexture;
5087
5088                                                                 SetUpLighting();
5089                                                                 //if(skyboxtexture){
5090                                                                 terrain.DoShadows();
5091                                                                 objects.DoShadows();
5092                                                                 /*}
5093                                                                 else terrain.DoLighting();
5094                                                                 */
5095                                                                 donesomething=1;
5096                                                         }
5097
5098                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5099                                                                 int startpoint;
5100                                                                 int alldone;
5101                                                                 alldone=0;
5102                                                                 startpoint=11;
5103                                                                 j=startpoint;
5104                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5105                                                                         mapname[j-startpoint]=consoletext[0][j];
5106                                                                         j++;
5107                                                                         if(consoletext[0][j]=='\0')alldone=1;
5108                                                                 }
5109                                                                 mapname[j-startpoint]='\0';
5110
5111                                                                 player[0].protectionhead=atof(mapname);
5112
5113                                                                 j++;
5114                                                                 startpoint=j;
5115                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5116                                                                         mapname[j-startpoint]=consoletext[0][j];
5117                                                                         j++;
5118                                                                         if(consoletext[0][j]=='\0')alldone=1;
5119                                                                 }
5120                                                                 mapname[j-startpoint]='\0';
5121
5122                                                                 player[0].protectionhigh=atof(mapname);
5123
5124                                                                 j++;
5125                                                                 startpoint=j;
5126                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5127                                                                         mapname[j-startpoint]=consoletext[0][j];
5128                                                                         j++;
5129                                                                         if(consoletext[0][j]=='\0')alldone=1;
5130                                                                 }
5131                                                                 mapname[j-startpoint]='\0';
5132
5133                                                                 player[0].protectionlow=atof(mapname);
5134
5135                                                                 donesomething=1;
5136                                                         }
5137
5138                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5139                                                                 int startpoint;
5140                                                                 int alldone;
5141                                                                 alldone=0;
5142                                                                 startpoint=6;
5143                                                                 j=startpoint;
5144                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5145                                                                         mapname[j-startpoint]=consoletext[0][j];
5146                                                                         j++;
5147                                                                         if(consoletext[0][j]=='\0')alldone=1;
5148                                                                 }
5149                                                                 mapname[j-startpoint]='\0';
5150
5151                                                                 player[0].armorhead=atof(mapname);
5152
5153                                                                 j++;
5154                                                                 startpoint=j;
5155                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5156                                                                         mapname[j-startpoint]=consoletext[0][j];
5157                                                                         j++;
5158                                                                         if(consoletext[0][j]=='\0')alldone=1;
5159                                                                 }
5160                                                                 mapname[j-startpoint]='\0';
5161
5162                                                                 player[0].armorhigh=atof(mapname);
5163
5164                                                                 j++;
5165                                                                 startpoint=j;
5166                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5167                                                                         mapname[j-startpoint]=consoletext[0][j];
5168                                                                         j++;
5169                                                                         if(consoletext[0][j]=='\0')alldone=1;
5170                                                                 }
5171                                                                 mapname[j-startpoint]='\0';
5172
5173                                                                 player[0].armorlow=atof(mapname);
5174
5175                                                                 donesomething=1;
5176                                                         }
5177
5178                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5179                                                                 for(i=0;i<numplayers;i++){
5180                                                                         player[i].protectionhead=1.0;
5181                                                                         player[i].protectionhigh=1.0;
5182                                                                         player[i].protectionlow=1.0;
5183                                                                         player[i].armorhead=1.0;
5184                                                                         player[i].armorhigh=1.0;
5185                                                                         player[i].armorlow=1.0;
5186                                                                 }
5187
5188                                                                 donesomething=1;
5189                                                         }
5190
5191                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5192                                                                 int closest=-1;
5193                                                                 float closestdist=-1;
5194                                                                 float distance;
5195                                                                 if(numplayers>1)
5196                                                                         for(i=1;i<numplayers;i++){
5197                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5198                                                                                 if(closestdist==-1||distance<closestdist){
5199                                                                                         closestdist=distance;
5200                                                                                         closest=i;
5201                                                                                 }
5202                                                                         }
5203
5204                                                                         int startpoint;
5205                                                                         int alldone;
5206                                                                         alldone=0;
5207                                                                         startpoint=15;
5208                                                                         j=startpoint;
5209                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5210                                                                                 mapname[j-startpoint]=consoletext[0][j];
5211                                                                                 j++;
5212                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5213                                                                         }
5214                                                                         mapname[j-startpoint]='\0';
5215
5216                                                                         player[closest].protectionhead=atof(mapname);
5217
5218                                                                         j++;
5219                                                                         startpoint=j;
5220                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5221                                                                                 mapname[j-startpoint]=consoletext[0][j];
5222                                                                                 j++;
5223                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5224                                                                         }
5225                                                                         mapname[j-startpoint]='\0';
5226
5227                                                                         player[closest].protectionhigh=atof(mapname);
5228
5229                                                                         j++;
5230                                                                         startpoint=j;
5231                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5232                                                                                 mapname[j-startpoint]=consoletext[0][j];
5233                                                                                 j++;
5234                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5235                                                                         }
5236                                                                         mapname[j-startpoint]='\0';
5237
5238                                                                         player[closest].protectionlow=atof(mapname);
5239
5240                                                                         donesomething=1;
5241                                                         }
5242
5243                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5244                                                                 int closest=-1;
5245                                                                 float closestdist=-1;
5246                                                                 float distance;
5247                                                                 if(numplayers>1)
5248                                                                         for(i=1;i<numplayers;i++){
5249                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5250                                                                                 if(closestdist==-1||distance<closestdist){
5251                                                                                         closestdist=distance;
5252                                                                                         closest=i;
5253                                                                                 }
5254                                                                         }
5255                                                                         int startpoint;
5256                                                                         int alldone;
5257                                                                         alldone=0;
5258                                                                         startpoint=10;
5259                                                                         j=startpoint;
5260                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5261                                                                                 mapname[j-startpoint]=consoletext[0][j];
5262                                                                                 j++;
5263                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5264                                                                         }
5265                                                                         mapname[j-startpoint]='\0';
5266
5267                                                                         player[closest].armorhead=atof(mapname);
5268
5269                                                                         j++;
5270                                                                         startpoint=j;
5271                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5272                                                                                 mapname[j-startpoint]=consoletext[0][j];
5273                                                                                 j++;
5274                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5275                                                                         }
5276                                                                         mapname[j-startpoint]='\0';
5277
5278                                                                         player[closest].armorhigh=atof(mapname);
5279
5280                                                                         j++;
5281                                                                         startpoint=j;
5282                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5283                                                                                 mapname[j-startpoint]=consoletext[0][j];
5284                                                                                 j++;
5285                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5286                                                                         }
5287                                                                         mapname[j-startpoint]='\0';
5288
5289                                                                         player[closest].armorlow=atof(mapname);
5290
5291                                                                         donesomething=1;
5292                                                         }
5293
5294
5295                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5296                                                                 int startpoint;
5297                                                                 int alldone;
5298                                                                 alldone=0;
5299                                                                 startpoint=6;
5300                                                                 j=startpoint;
5301                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5302                                                                         mapname[j-startpoint]=consoletext[0][j];
5303                                                                         j++;
5304                                                                         if(consoletext[0][j]=='\0')alldone=1;
5305                                                                 }
5306                                                                 mapname[j-startpoint]='\0';
5307
5308                                                                 player[0].metalhead=atof(mapname);
5309
5310                                                                 j++;
5311                                                                 startpoint=j;
5312                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5313                                                                         mapname[j-startpoint]=consoletext[0][j];
5314                                                                         j++;
5315                                                                         if(consoletext[0][j]=='\0')alldone=1;
5316                                                                 }
5317                                                                 mapname[j-startpoint]='\0';
5318
5319                                                                 player[0].metalhigh=atof(mapname);
5320
5321                                                                 j++;
5322                                                                 startpoint=j;
5323                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5324                                                                         mapname[j-startpoint]=consoletext[0][j];
5325                                                                         j++;
5326                                                                         if(consoletext[0][j]=='\0')alldone=1;
5327                                                                 }
5328
5329                                                                 mapname[j-startpoint]='\0';
5330
5331                                                                 player[0].metallow=atof(mapname);
5332
5333                                                                 donesomething=1;
5334                                                         }
5335
5336                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5337                                                                 int closest=-1;
5338                                                                 float closestdist=-1;
5339                                                                 float distance;
5340                                                                 if(numplayers>1)
5341                                                                         for(i=1;i<numplayers;i++){
5342                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5343                                                                                 if(closestdist==-1||distance<closestdist){
5344                                                                                         closestdist=distance;
5345                                                                                         closest=i;
5346                                                                                 }
5347                                                                         }
5348                                                                         player[closest].numclothes=0;
5349                                                                         if(player[closest].whichskin==0){
5350                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5351                                                                         }
5352                                                                         else if(player[closest].whichskin==1){
5353                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5354                                                                         }
5355                                                                         else if(player[closest].whichskin==2){
5356                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5357                                                                         }
5358                                                                         else if(player[closest].whichskin==3){
5359                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5360                                                                         }
5361                                                                         else if(player[closest].whichskin==4){
5362                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5363                                                                         }
5364                                                                         else if(player[closest].whichskin==5){
5365                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5366                                                                         }
5367                                                                         else if(player[closest].whichskin==6){
5368                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5369                                                                         }
5370                                                                         else if(player[closest].whichskin==7){
5371                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5372                                                                         }
5373                                                                         else if(player[closest].whichskin==8){
5374                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5375                                                                         }
5376                                                                         else if(player[closest].whichskin==9){
5377                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5378                                                                         }
5379
5380                                                                         donesomething=1;
5381                                                         }
5382
5383                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5384                                                                 int closest=0;
5385
5386                                                                 player[closest].numclothes=0;
5387                                                                 if(player[closest].whichskin==0){
5388                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5389                                                                 }
5390                                                                 else if(player[closest].whichskin==1){
5391                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5392                                                                 }
5393                                                                 else if(player[closest].whichskin==2){
5394                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5395                                                                 }
5396                                                                 else if(player[closest].whichskin==3){
5397                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5398                                                                 }
5399                                                                 else if(player[closest].whichskin==4){
5400                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5401                                                                 }
5402                                                                 else if(player[closest].whichskin==5){
5403                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5404                                                                 }
5405                                                                 else if(player[closest].whichskin==6){
5406                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5407                                                                 }
5408                                                                 else if(player[closest].whichskin==7){
5409                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5410                                                                 }
5411                                                                 else if(player[closest].whichskin==8){
5412                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5413                                                                 }
5414                                                                 else if(player[closest].whichskin==9){
5415                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5416                                                                 }
5417
5418                                                                 donesomething=1;
5419                                                         }
5420
5421                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5422                                                                 mapname[0]=':';
5423                                                                 mapname[1]='D';
5424                                                                 mapname[2]='a';
5425                                                                 mapname[3]='t';
5426                                                                 mapname[4]='a';
5427                                                                 mapname[5]=':';
5428                                                                 mapname[6]='T';
5429                                                                 mapname[7]='e';
5430                                                                 mapname[8]='x';
5431                                                                 mapname[9]='t';
5432                                                                 mapname[10]='u';
5433                                                                 mapname[11]='r';
5434                                                                 mapname[12]='e';
5435                                                                 mapname[13]='s';
5436                                                                 mapname[14]=':';
5437                                                                 for(j=8;j<consolechars[0];j++){
5438                                                                         mapname[j-8+15]=consoletext[0][j];
5439                                                                 }
5440                                                                 mapname[consolechars[0]-8+15]='.';
5441                                                                 mapname[consolechars[0]-8+16]='p';
5442                                                                 mapname[consolechars[0]-8+17]='n';
5443                                                                 mapname[consolechars[0]-8+18]='g';
5444                                                                 mapname[consolechars[0]-8+19]='\0';
5445
5446                                                                 //:Data:Textures:Pants.png
5447
5448                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5449                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5450                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5451                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5452                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5453                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5454                                                                         player[0].numclothes++;
5455                                                                 }
5456
5457                                                                 donesomething=1;
5458                                                         }
5459
5460                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5461                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5462
5463                                                                 donesomething=1;
5464                                                         }
5465
5466                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5467                                                                 cellophane=1-cellophane;
5468
5469                                                                 if(cellophane){
5470                                                                         for(i=0;i<numplayers;i++){
5471                                                                                 player[i].proportionhead.z=0;
5472                                                                                 player[i].proportionbody.z=0;
5473                                                                                 player[i].proportionarms.z=0;
5474                                                                                 player[i].proportionlegs.z=0;
5475                                                                         }
5476                                                                 }
5477
5478                                                                 if(!cellophane){
5479                                                                         for(i=0;i<numplayers;i++){
5480                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5481                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5482                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5483                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5484                                                                         }
5485                                                                 }
5486
5487                                                                 donesomething=1;
5488                                                         }
5489
5490                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5491                                                                 mapname[0]=':';
5492                                                                 mapname[1]='D';
5493                                                                 mapname[2]='a';
5494                                                                 mapname[3]='t';
5495                                                                 mapname[4]='a';
5496                                                                 mapname[5]=':';
5497                                                                 mapname[6]='T';
5498                                                                 mapname[7]='e';
5499                                                                 mapname[8]='x';
5500                                                                 mapname[9]='t';
5501                                                                 mapname[10]='u';
5502                                                                 mapname[11]='r';
5503                                                                 mapname[12]='e';
5504                                                                 mapname[13]='s';
5505                                                                 mapname[14]=':';
5506                                                                 for(j=12;j<consolechars[0];j++){
5507                                                                         mapname[j-12+15]=consoletext[0][j];
5508                                                                 }
5509                                                                 mapname[consolechars[0]-12+15]='.';
5510                                                                 mapname[consolechars[0]-12+16]='p';
5511                                                                 mapname[consolechars[0]-12+17]='n';
5512                                                                 mapname[consolechars[0]-12+18]='g';
5513                                                                 mapname[consolechars[0]-12+19]='\0';
5514
5515                                                                 //:Data:Textures:Pants.png
5516                                                                 int closest=-1;
5517                                                                 float closestdist=-1;
5518                                                                 float distance;
5519                                                                 if(numplayers>1)
5520                                                                         for(i=1;i<numplayers;i++){
5521                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5522                                                                                 if(closestdist==-1||distance<closestdist){
5523                                                                                         closestdist=distance;
5524                                                                                         closest=i;
5525                                                                                 }
5526                                                                         }
5527
5528                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5529                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5530                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5531                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5532                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5533                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5534                                                                                 player[closest].numclothes++;
5535                                                                         }
5536
5537                                                                         donesomething=1;
5538                                                         }
5539
5540                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5541                                                                 player[0].skeleton.id=0;
5542                                                                 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);
5543                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5544                                                                 player[0].creature=rabbittype;
5545                                                                 player[0].scale=.2;
5546
5547                                                                 player[0].proportionhead=1.2;
5548                                                                 player[0].proportionbody=1.05;
5549                                                                 player[0].proportionarms=1.00;
5550                                                                 player[0].proportionlegs=1.1;
5551                                                                 player[0].proportionlegs.y=1.05;
5552                                                                 player[0].headless=0;
5553
5554                                                                 player[0].damagetolerance=200;
5555
5556                                                                 donesomething=1;
5557                                                         }
5558                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5559                                                                 player[0].skeleton.id=0;
5560                                                                 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);
5561                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5562                                                                 player[0].creature=wolftype;
5563
5564                                                                 player[0].proportionhead=1.1;
5565                                                                 player[0].proportionbody=1.1;
5566                                                                 player[0].proportionarms=1.1;
5567                                                                 player[0].proportionlegs=1.1;
5568                                                                 player[0].proportionlegs.y=1.1;
5569                                                                 player[0].scale=.23;
5570
5571                                                                 player[0].damagetolerance=300;
5572
5573                                                                 donesomething=1;
5574                                                         }
5575                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5576                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5577                                                         donesomething=1;
5578                                                         }
5579                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5580                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5581                                                         donesomething=1;
5582                                                         }
5583                                                         if(Compare(consoletext[0],"david ",0,5)){
5584                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5585                                                         donesomething=1;
5586                                                         }*/
5587                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5588                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5589                                                                 donesomething=1;
5590                                                         }
5591                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5592                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5593                                                                 donesomething=1;
5594                                                         }
5595                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5596                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5597                                                                 donesomething=1;
5598                                                         }/*
5599                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5600                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5601                                                          donesomething=1;
5602                                                          }*/
5603                                                         if(Compare(consoletext[0],"white ",0,5)){
5604                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5605                                                                 donesomething=1;
5606                                                         }
5607                                                         if(Compare(consoletext[0],"brown ",0,5)){
5608                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5609                                                                 donesomething=1;
5610                                                         }
5611                                                         if(Compare(consoletext[0],"black ",0,5)){
5612                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5613                                                                 donesomething=1;
5614                                                         }
5615                                                         if(consolechars[0]>0){
5616                                                                 for(k=14;k>=1;k--){
5617                                                                         for(j=0;j<255;j++){
5618                                                                                 consoletext[k][j]=consoletext[k-1][j];
5619                                                                         }
5620                                                                         consolechars[k]=consolechars[k-1];
5621                                                                 }
5622                                                                 for(j=0;j<255;j++){
5623                                                                         consoletext[0][j]=' ';
5624                                                                 }
5625                                                                 consolechars[0]=0;
5626                                                                 consoleselected=0;
5627
5628                                                                 if(!donesomething){
5629                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5630                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5631                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5632                                                                 }
5633                                                         }
5634                                                 }
5635                                         }
5636                                         togglekey[i]=1;
5637                                 }
5638                                 else {
5639                                         togglekey[i]=0;
5640                                         togglekeydelay[i]=0;
5641                                 }
5642                         }
5643
5644                         consoleblinkdelay-=multiplier;
5645                         if(consoleblinkdelay<=0){
5646                                 consoleblinkdelay=.3;
5647                                 consoleblink=1-consoleblink;
5648                         }
5649                 }
5650
5651                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5652                         tryquit=1;
5653                         if(mainmenu==3){
5654                                 if(newdetail>2)newdetail=detail;
5655                                 if(newdetail<0)newdetail=detail;
5656                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5657                                 if(newscreenheight<0)newscreenheight=screenheight;
5658
5659                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5660                                 opstream << "Screenwidth:\n";
5661                                 opstream << newscreenwidth;
5662                                 opstream << "\nScreenheight:\n";
5663                                 opstream << newscreenheight;
5664                                 opstream << "\nMouse sensitivity:\n";
5665                                 opstream << usermousesensitivity;
5666                                 opstream << "\nBlur(0,1):\n";
5667                                 opstream << ismotionblur;
5668                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5669                                 opstream << newdetail;
5670                                 opstream << "\nFloating jump:\n";
5671                                 opstream << floatjump;
5672                                 opstream << "\nMouse jump:\n";
5673                                 opstream << mousejump;
5674                                 opstream << "\nAmbient sound:\n";
5675                                 opstream << ambientsound;
5676                                 opstream << "\nBlood (0,1,2):\n";
5677                                 opstream << bloodtoggle;
5678                                 opstream << "\nAuto slomo:\n";
5679                                 opstream << autoslomo;
5680                                 opstream << "\nFoliage:\n";
5681                                 opstream << foliage;
5682                                 opstream << "\nMusic:\n";
5683                                 opstream << musictoggle;
5684                                 opstream << "\nTrilinear:\n";
5685                                 opstream << trilinear;
5686                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5687                                 opstream << decals;
5688                                 opstream << "\nInvert mouse:\n";
5689                                 opstream << invertmouse;
5690                                 opstream << "\nGamespeed:\n";
5691                                 if(oldgamespeed==0)oldgamespeed=1;
5692                                 opstream << oldgamespeed;
5693                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5694                                 opstream << difficulty;
5695                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5696                                 opstream << damageeffects;
5697                                 opstream << "\nText:\n";
5698                                 opstream << texttoggle;
5699                                 opstream << "\nDebug:\n";
5700                                 opstream << debugmode;
5701                                 opstream << "\nVBL Sync:\n";
5702                                 opstream << vblsync;
5703                                 opstream << "\nShow Points:\n";
5704                                 opstream << showpoints;
5705                                 opstream << "\nAlways Blur:\n";
5706                                 opstream << alwaysblur;
5707                                 opstream << "\nImmediate mode (turn on on G5):\n";
5708                                 opstream << immediate;
5709                                 opstream << "\nVelocity blur:\n";
5710                                 opstream << velocityblur;
5711                             opstream << "\nVolume:\n";
5712                         opstream << volume;
5713                                 opstream << "\nForward key:\n";
5714                                 opstream << KeyToChar(forwardkey);
5715                                 opstream << "\nBack key:\n";
5716                                 opstream << KeyToChar(backkey);
5717                                 opstream << "\nLeft key:\n";
5718                                 opstream << KeyToChar(leftkey);
5719                                 opstream << "\nRight key:\n";
5720                                 opstream << KeyToChar(rightkey);
5721                                 opstream << "\nJump key:\n";
5722                                 opstream << KeyToChar(jumpkey);
5723                                 opstream << "\nCrouch key:\n";
5724                                 opstream << KeyToChar(crouchkey);
5725                                 opstream << "\nDraw key:\n";
5726                                 opstream << KeyToChar(drawkey);
5727                                 opstream << "\nThrow key:\n";
5728                                 opstream << KeyToChar(throwkey);
5729                                 opstream << "\nAttack key:\n";
5730                                 opstream << KeyToChar(attackkey);
5731                                 opstream << "\nChat key:\n";
5732                                 opstream << KeyToChar(chatkey);
5733                                 opstream.close();
5734                         }
5735                 }
5736
5737                 static int oldwinfreeze;
5738                 if(winfreeze&&!oldwinfreeze){
5739                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5740                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5741                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5742                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5743                 }
5744                 if(winfreeze==0)oldwinfreeze=winfreeze;
5745                 else oldwinfreeze++;
5746
5747                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5748                         if(winfreeze)winfreeze=0;
5749                         oldjumpkeydown=1;
5750                 }
5751                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5752                         if(winfreeze){
5753                                 mainmenu=9;
5754                                 gameon=0;
5755                         }
5756                 }
5757                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5758                         oldjumpkeydown=1;
5759                 }
5760                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5761
5762                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5763
5764                         static bool oldbuttondialogue;
5765
5766                         if(indialogue!=-1)talkdelay=1;
5767                         talkdelay-=multiplier;
5768
5769                         if(talkdelay<=0)
5770                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5771                                         for(i=0;i<numdialogues;i++){
5772                                                 int realdialoguetype;
5773                                                 bool special;
5774                                                 if(dialoguetype[i]>49){
5775                                                         realdialoguetype=dialoguetype[i]-50;
5776                                                         special=1;
5777                                                 }
5778                                                 else if(dialoguetype[i]>39){
5779                                                         realdialoguetype=dialoguetype[i]-40;
5780                                                         special=1;
5781                                                 }
5782                                                 else if(dialoguetype[i]>29){
5783                                                         realdialoguetype=dialoguetype[i]-30;
5784                                                         special=1;
5785                                                 }
5786                                                 else if(dialoguetype[i]>19){
5787                                                         realdialoguetype=dialoguetype[i]-20;
5788                                                         special=1;
5789                                                 }
5790                                                 else if(dialoguetype[i]>9){
5791                                                         realdialoguetype=dialoguetype[i]-10;
5792                                                         special=1;
5793                                                 }
5794                                                 else {
5795                                                         realdialoguetype=dialoguetype[i];
5796                                                         special=0;
5797                                                 }
5798                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5799                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5800                                                                 whichdialogue=i;
5801                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5802                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5803                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5804                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5805                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5806                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5807                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5808                                                                 }
5809                                                                 directing=0;
5810                                                                 indialogue=0;
5811                                                                 dialoguetime=0;
5812                                                                 dialoguegonethrough[i]++;
5813                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5814                                                                         static float gLoc[3];
5815                                                                         static float vel[3];
5816                                                                         XYZ temppos;
5817                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5818                                                                         temppos=temppos-viewer;
5819                                                                         Normalise(&temppos);
5820                                                                         temppos+=viewer;
5821
5822                                                                         gLoc[0]=temppos.x;
5823                                                                         gLoc[1]=temppos.y;
5824                                                                         gLoc[2]=temppos.z;vel[0]=0;
5825                                                                         vel[1]=0;
5826                                                                         vel[2]=0;
5827                                                                         int whichsoundplay;
5828                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5829                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5830                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5831                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5832                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5833                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5834                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5835                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5836                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5837                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5838                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5839                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5840                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5841                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5842                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5843                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5844                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5845                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5846                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5847                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5848                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5849                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5850                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5851                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5852                                                                 }
5853                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5854                                                         }
5855                                                 }
5856                                         }
5857
5858                                         windvar+=multiplier;
5859                                         smoketex+=multiplier;
5860                                         tutorialstagetime+=multiplier;
5861
5862                                         static float hotspotvisual[40];
5863                                         if(numhotspots){
5864                                                 XYZ hotspotsprite;
5865                                                 if(editorenabled)
5866                                                         for(i=0;i<numhotspots;i++)
5867                                                                 hotspotvisual[i]-=multiplier/320;
5868
5869                                                 for(i=0;i<numhotspots;i++){
5870                                                         //if(hotspottype[i]<=10)
5871                                                         while(hotspotvisual[i]<0){
5872                                                                 hotspotsprite=0;
5873                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5874                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5875                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5876                                                                 hotspotsprite+=hotspot[i];
5877                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5878                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5879                                                         }
5880                                                 }
5881
5882                                                 for(i=0;i<numhotspots;i++){
5883                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5884                                                                 hotspot[i]=player[hotspottype[i]].coords;
5885                                                         }
5886                                                 }
5887                                         }
5888
5889                                         //Tutorial
5890                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5891                                                 tutorialstage++;
5892                                                 tutorialsuccess=0;
5893                                                 if(tutorialstage<=1){
5894                                                         canattack=0;
5895                                                         cananger=0;
5896                                                         reversaltrain=0;
5897                                                 }
5898                                                 if(tutorialstage==1){
5899                                                         tutorialmaxtime=5;
5900                                                 }
5901                                                 if(tutorialstage==2){
5902                                                         tutorialmaxtime=2;
5903                                                 }
5904                                                 if(tutorialstage==3){
5905                                                         tutorialmaxtime=600;
5906                                                 }
5907                                                 if(tutorialstage==4){
5908                                                         tutorialmaxtime=1000;
5909                                                 }
5910                                                 if(tutorialstage==5){
5911                                                         tutorialmaxtime=600;
5912                                                 }
5913                                                 if(tutorialstage==6){
5914                                                         tutorialmaxtime=600;
5915                                                 }
5916                                                 if(tutorialstage==7){
5917                                                         tutorialmaxtime=600;
5918                                                 }
5919                                                 if(tutorialstage==8){
5920                                                         tutorialmaxtime=600;
5921                                                 }
5922                                                 if(tutorialstage==9){
5923                                                         tutorialmaxtime=600;
5924                                                 }
5925                                                 if(tutorialstage==10){
5926                                                         tutorialmaxtime=2;
5927                                                 }
5928                                                 if(tutorialstage==11){
5929                                                         tutorialmaxtime=1000;
5930                                                 }
5931                                                 if(tutorialstage==12){
5932                                                         tutorialmaxtime=1000;
5933                                                 }
5934                                                 if(tutorialstage==13){
5935                                                         tutorialmaxtime=2;
5936                                                 }
5937                                                 if(tutorialstage==14){
5938                                                         tutorialmaxtime=3;
5939
5940                                                         XYZ temp,temp2;
5941
5942                                                         temp.x=1011;
5943                                                         temp.y=84;
5944                                                         temp.z=491;
5945                                                         temp2.x=1025;
5946                                                         temp2.y=75;
5947                                                         temp2.z=447;
5948
5949                                                         player[1].coords=(temp+temp2)/2;
5950
5951                                                         float gLoc[3];
5952                                                         float vel[3];
5953                                                         gLoc[0]=player[1].coords.x;
5954                                                         gLoc[1]=player[1].coords.y;
5955                                                         gLoc[2]=player[1].coords.z;
5956                                                         vel[0]=0;
5957                                                         vel[1]=0;
5958                                                         vel[2]=0;
5959                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5960                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5961                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5962                                                         OPENAL_SetPaused(channels[fireendsound], false);
5963
5964                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5965                                                                 if(Random()%2==0){
5966                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5967                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5968                                                                         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;
5969                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5970                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5971                                                                 }
5972                                                         }
5973
5974                                                 }
5975                                                 if(tutorialstage==15){
5976                                                         tutorialmaxtime=500;
5977                                                 }
5978                                                 if(tutorialstage==16){
5979                                                         tutorialmaxtime=500;
5980                                                 }
5981                                                 if(tutorialstage==17){
5982                                                         tutorialmaxtime=500;
5983                                                 }
5984                                                 if(tutorialstage==18){
5985                                                         tutorialmaxtime=500;
5986                                                 }
5987                                                 if(tutorialstage==19){
5988                                                         tutorialstage=20;
5989                                                         //tutorialmaxtime=500;
5990                                                 }
5991                                                 if(tutorialstage==20){
5992                                                         tutorialmaxtime=500;
5993                                                 }
5994                                                 if(tutorialstage==21){
5995                                                         tutorialmaxtime=500;
5996                                                         if(bonus==cannon){
5997                                                                 bonus=Slicebonus;
5998                                                                 againbonus=1;
5999                                                         }
6000                                                         else againbonus=0;
6001                                                 }
6002                                                 if(tutorialstage==22){
6003                                                         tutorialmaxtime=500;
6004                                                 }
6005                                                 if(tutorialstage==23){
6006                                                         tutorialmaxtime=500;
6007                                                 }
6008                                                 if(tutorialstage==24){
6009                                                         tutorialmaxtime=500;
6010                                                 }
6011                                                 if(tutorialstage==25){
6012                                                         tutorialmaxtime=500;
6013                                                 }
6014                                                 if(tutorialstage==26){
6015                                                         tutorialmaxtime=2;
6016                                                 }
6017                                                 if(tutorialstage==27){
6018                                                         tutorialmaxtime=4;
6019                                                         reversaltrain=1;
6020                                                         cananger=1;
6021                                                         player[1].aitype=attacktypecutoff;
6022                                                 }
6023                                                 if(tutorialstage==28){
6024                                                         tutorialmaxtime=400;
6025                                                 }
6026                                                 if(tutorialstage==29){
6027                                                         tutorialmaxtime=400;
6028                                                         player[0].escapednum=0;
6029                                                 }
6030                                                 if(tutorialstage==30){
6031                                                         tutorialmaxtime=4;
6032                                                         reversaltrain=0;
6033                                                         cananger=0;
6034                                                         player[1].aitype=passivetype;
6035                                                 }
6036                                                 if(tutorialstage==31){
6037                                                         tutorialmaxtime=13;
6038                                                 }
6039                                                 if(tutorialstage==32){
6040                                                         tutorialmaxtime=8;
6041                                                 }
6042                                                 if(tutorialstage==33){
6043                                                         tutorialmaxtime=400;
6044                                                         cananger=1;
6045                                                         canattack=1;
6046                                                         player[1].aitype=attacktypecutoff;
6047                                                 }
6048                                                 if(tutorialstage==34){
6049                                                         tutorialmaxtime=400;
6050                                                 }
6051                                                 if(tutorialstage==35){
6052                                                         tutorialmaxtime=400;
6053                                                 }
6054                                                 if(tutorialstage==36){
6055                                                         tutorialmaxtime=2;
6056                                                         reversaltrain=0;
6057                                                         cananger=0;
6058                                                         player[1].aitype=passivetype;
6059                                                 }
6060                                                 if(tutorialstage==37){
6061                                                         damagedealt=0;
6062                                                         damagetaken=0;
6063                                                         tutorialmaxtime=50;
6064                                                         cananger=1;
6065                                                         canattack=1;
6066                                                         player[1].aitype=attacktypecutoff;
6067                                                 }
6068                                                 if(tutorialstage==38){
6069                                                         tutorialmaxtime=4;
6070                                                         canattack=0;
6071                                                         cananger=0;
6072                                                         player[1].aitype=passivetype;
6073                                                 }
6074                                                 if(tutorialstage==39){
6075                                                         XYZ temp,temp2;
6076
6077                                                         temp.x=1011;
6078                                                         temp.y=84;
6079                                                         temp.z=491;
6080                                                         temp2.x=1025;
6081                                                         temp2.y=75;
6082                                                         temp2.z=447;
6083
6084
6085                                                         weapons.owner[weapons.numweapons]=-1;
6086                                                         weapons.type[weapons.numweapons]=knife;
6087                                                         weapons.damage[weapons.numweapons]=0;
6088                                                         weapons.mass[weapons.numweapons]=1;
6089                                                         weapons.tipmass[weapons.numweapons]=1.2;
6090                                                         weapons.length[weapons.numweapons]=.25;
6091                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6092                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6093
6094                                                         weapons.velocity[weapons.numweapons]=0.1;
6095                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6096                                                         weapons.missed[weapons.numweapons]=1;
6097                                                         weapons.hitsomething[weapons.numweapons]=0;
6098                                                         weapons.freetime[weapons.numweapons]=0;
6099                                                         weapons.firstfree[weapons.numweapons]=1;
6100                                                         weapons.physics[weapons.numweapons]=1;
6101
6102                                                         weapons.numweapons++;
6103                                                 }
6104                                                 if(tutorialstage==40){
6105                                                         tutorialmaxtime=300;
6106                                                 }
6107                                                 if(tutorialstage==41){
6108                                                         tutorialmaxtime=300;
6109                                                 }
6110                                                 if(tutorialstage==42){
6111                                                         tutorialmaxtime=8;
6112                                                 }
6113                                                 if(tutorialstage==43){
6114                                                         tutorialmaxtime=300;
6115                                                 }
6116                                                 if(tutorialstage==44){
6117                                                         weapons.owner[0]=1;
6118                                                         player[0].weaponactive=-1;
6119                                                         player[0].num_weapons=0;
6120                                                         player[1].weaponactive=0;
6121                                                         player[1].num_weapons=1;
6122                                                         player[1].weaponids[0]=0;
6123
6124                                                         cananger=1;
6125                                                         canattack=1;
6126                                                         player[1].aitype=attacktypecutoff;
6127
6128                                                         tutorialmaxtime=300;
6129                                                 }
6130                                                 if(tutorialstage==45){
6131                                                         weapons.owner[0]=1;
6132                                                         player[0].weaponactive=-1;
6133                                                         player[0].num_weapons=0;
6134                                                         player[1].weaponactive=0;
6135                                                         player[1].num_weapons=1;
6136                                                         player[1].weaponids[0]=0;
6137
6138                                                         tutorialmaxtime=300;
6139                                                 }
6140                                                 if(tutorialstage==46){
6141                                                         weapons.owner[0]=1;
6142                                                         player[0].weaponactive=-1;
6143                                                         player[0].num_weapons=0;
6144                                                         player[1].weaponactive=0;
6145                                                         player[1].num_weapons=1;
6146                                                         player[1].weaponids[0]=0;
6147
6148                                                         weapons.type[0]=sword;
6149
6150                                                         tutorialmaxtime=300;
6151                                                 }
6152
6153                                                 if(tutorialstage==47){
6154                                                         tutorialmaxtime=10;
6155
6156                                                         XYZ temp,temp2;
6157
6158                                                         temp.x=1011;
6159                                                         temp.y=84;
6160                                                         temp.z=491;
6161                                                         temp2.x=1025;
6162                                                         temp2.y=75;
6163                                                         temp2.z=447;
6164
6165                                                         weapons.owner[weapons.numweapons]=-1;
6166                                                         weapons.type[weapons.numweapons]=sword;
6167                                                         weapons.damage[weapons.numweapons]=0;
6168                                                         weapons.mass[weapons.numweapons]=1;
6169                                                         weapons.tipmass[weapons.numweapons]=1.2;
6170                                                         weapons.length[weapons.numweapons]=.25;
6171                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6172                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6173
6174                                                         weapons.velocity[weapons.numweapons]=0.1;
6175                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6176                                                         weapons.missed[weapons.numweapons]=1;
6177                                                         weapons.hitsomething[weapons.numweapons]=0;
6178                                                         weapons.freetime[weapons.numweapons]=0;
6179                                                         weapons.firstfree[weapons.numweapons]=1;
6180                                                         weapons.physics[weapons.numweapons]=1;
6181
6182                                                         weapons.owner[0]=1;
6183                                                         weapons.owner[1]=0;
6184                                                         player[0].weaponactive=0;
6185                                                         player[0].num_weapons=1;
6186                                                         player[0].weaponids[0]=1;
6187                                                         player[1].weaponactive=0;
6188                                                         player[1].num_weapons=1;
6189                                                         player[1].weaponids[0]=0;
6190
6191                                                         weapons.numweapons++;
6192                                                 }
6193                                                 if(tutorialstage==48){
6194                                                         canattack=0;
6195                                                         cananger=0;
6196                                                         player[1].aitype=passivetype;
6197
6198                                                         tutorialmaxtime=15;
6199
6200                                                         weapons.owner[0]=1;
6201                                                         weapons.owner[1]=0;
6202                                                         player[0].weaponactive=0;
6203                                                         player[0].num_weapons=1;
6204                                                         player[0].weaponids[0]=1;
6205                                                         player[1].weaponactive=0;
6206                                                         player[1].num_weapons=1;
6207                                                         player[1].weaponids[0]=0;
6208
6209                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6210                                                         else weapons.type[0]=staff;
6211
6212                                                         weapons.numweapons++;
6213                                                 }
6214                                                 if(tutorialstage==49){
6215                                                         canattack=0;
6216                                                         cananger=0;
6217                                                         player[1].aitype=passivetype;
6218
6219                                                         tutorialmaxtime=200;
6220
6221                                                         weapons.position[1]=1000;
6222                                                         weapons.tippoint[1]=1000;
6223
6224                                                         weapons.numweapons=1;
6225                                                         weapons.owner[0]=0;
6226                                                         player[1].weaponactive=-1;
6227                                                         player[1].num_weapons=0;
6228                                                         player[0].weaponactive=0;
6229                                                         player[0].num_weapons=1;
6230                                                         player[0].weaponids[0]=0;
6231
6232                                                         weapons.type[0]=knife;
6233
6234                                                         weapons.numweapons++;
6235                                                 }
6236                                                 if(tutorialstage==50){
6237                                                         tutorialmaxtime=8;
6238
6239                                                         XYZ temp,temp2;
6240                                                         float gLoc[3];
6241                                                         float vel[3];
6242                                                         gLoc[0]=player[1].coords.x;
6243                                                         gLoc[1]=player[1].coords.y;
6244                                                         gLoc[2]=player[1].coords.z;
6245                                                         vel[0]=0;
6246                                                         vel[1]=0;
6247                                                         vel[2]=0;
6248                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6249                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6250                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6251                                                         OPENAL_SetPaused(channels[fireendsound], false);
6252
6253                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6254                                                                 if(Random()%2==0){
6255                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6256                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6257                                                                         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;
6258                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6259                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6260                                                                 }
6261                                                         }
6262
6263                                                         player[1].num_weapons=0;
6264                                                         player[1].weaponstuck=-1;
6265                                                         player[1].weaponactive=-1;
6266
6267                                                         weapons.numweapons=0;
6268
6269                                                         weapons.owner[0]=-1;
6270                                                         weapons.velocity[0]=0.1;
6271                                                         weapons.tipvelocity[0]=-0.1;
6272                                                         weapons.missed[0]=1;
6273                                                         weapons.hitsomething[0]=0;
6274                                                         weapons.freetime[0]=0;
6275                                                         weapons.firstfree[0]=1;
6276                                                         weapons.physics[0]=1;
6277                                                 }
6278                                                 if(tutorialstage==51){
6279                                                         tutorialmaxtime=80000;
6280                                                 }
6281                                                 if(tutorialstage<=51)tutorialstagetime=0;
6282                                         }
6283
6284                                         //Tutorial success
6285                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6286                                                 if(tutorialstage==3){
6287                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6288                                                 }
6289                                                 if(tutorialstage==4){
6290                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6291                                                 }
6292                                                 if(tutorialstage==5){
6293                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6294                                                 }
6295                                                 if(tutorialstage==6){
6296                                                         if(player[0].isCrouch())tutorialsuccess=1;
6297                                                 }
6298                                                 if(tutorialstage==7){
6299                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6300                                                 }
6301                                                 if(tutorialstage==8){
6302                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6303                                                 }
6304                                                 if(tutorialstage==9){
6305                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6306                                                 }
6307                                                 if(tutorialstage==11){
6308                                                         if(player[0].isWallJump())tutorialsuccess=1;
6309                                                 }
6310                                                 if(tutorialstage==12){
6311                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6312                                                 }
6313                                                 if(tutorialstage==15){
6314                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6315                                                 }
6316                                                 if(tutorialstage==16){
6317                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6318                                                 }
6319                                                 if(tutorialstage==17){
6320                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6321                                                 }
6322                                                 if(tutorialstage==18){
6323                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6324                                                 }
6325                                                 if(tutorialstage==19){
6326                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6327                                                 }
6328                                                 if(tutorialstage==20){
6329                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6330                                                 }
6331                                                 if(tutorialstage==21){
6332                                                         if(bonus==cannon)tutorialsuccess=1;
6333                                                 }
6334                                                 if(tutorialstage==22){
6335                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6336                                                 }
6337                                                 if(tutorialstage==23){
6338                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6339                                                 }
6340                                                 if(tutorialstage==24){
6341                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6342                                                 }
6343                                                 if(tutorialstage==25){
6344                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6345                                                 }
6346                                                 if(tutorialstage==28){
6347                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6348                                                 }
6349                                                 if(tutorialstage==29){
6350                                                         if(player[0].escapednum==2){
6351                                                                 tutorialsuccess=1;
6352                                                                 reversaltrain=0;
6353                                                                 cananger=0;
6354                                                                 player[1].aitype=passivetype;
6355                                                         }
6356                                                 }
6357                                                 if(tutorialstage==33){
6358                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6359                                                 }
6360                                                 if(tutorialstage==34){
6361                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6362                                                 }
6363                                                 if(tutorialstage==35){
6364                                                         if(animation[player[0].targetanimation].attack==reversal){
6365                                                                 tutorialsuccess=1;
6366                                                                 reversaltrain=0;
6367                                                                 cananger=0;
6368                                                                 player[1].aitype=passivetype;
6369                                                         }
6370                                                 }
6371                                                 if(tutorialstage==40){
6372                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6373                                                 }
6374                                                 if(tutorialstage==41){
6375                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6376                                                 }
6377                                                 if(tutorialstage==43){
6378                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6379                                                 }
6380                                                 if(tutorialstage==44){
6381                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6382                                                 }
6383                                                 if(tutorialstage==45){
6384                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6385                                                 }
6386                                                 if(tutorialstage==46){
6387                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6388                                                 }
6389                                                 if(tutorialstage==49){
6390                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6391                                                 }
6392                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6393
6394
6395                                                 if(tutorialstagetime==tutorialmaxtime-3){
6396                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6397                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6398                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6399                                                 }
6400
6401                                                 if(tutorialsuccess>=1){
6402                                                         if(tutorialstage==34||tutorialstage==35)
6403                                                                 tutorialstagetime=tutorialmaxtime-1;
6404                                                 }
6405                                         }
6406
6407                                         if(tutoriallevel){
6408                                                 if(tutorialstage<14||tutorialstage>=50){
6409                                                         player[1].coords.y=300;
6410                                                         player[1].velocity=0;
6411                                                 }
6412                                         }
6413
6414                                         if(tutoriallevel!=1){
6415                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6416                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6417                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6418                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6419                                                 }
6420                                         }
6421                                         else
6422                                                 if(bonustime==0){
6423                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6424                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6425                                                         OPENAL_SetPaused(channels[fireendsound], false);
6426                                                 }
6427                                                 if(bonustime==0){
6428                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6429                                                         else bonusnum[bonus]+=0.15;
6430                                                         if(tutoriallevel)bonusvalue=0;
6431                                                         bonusvalue/=bonusnum[bonus];
6432                                                         bonustotal+=bonusvalue;
6433                                                 }
6434                                                 bonustime+=multiplier;
6435
6436                                                 if(environment==snowyenvironment){
6437                                                         precipdelay-=multiplier;
6438                                                         while(precipdelay<0){
6439                                                                 precipdelay+=.04;
6440                                                                 if(!detail)precipdelay+=.04;
6441                                                                 XYZ footvel,footpoint;
6442
6443                                                                 footvel=0;
6444                                                                 footpoint=viewer+viewerfacing*6;
6445                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6446                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6447                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6448                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6449                                                         }
6450                                                 }
6451                                                 for(k=0;k<numplayers;k++){
6452                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6453                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6454
6455                                                         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){
6456                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6457                                                                 else if(player[k].rotation>player[k].targetrotation){
6458                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6459                                                                 }
6460                                                                 else if(player[k].rotation<player[k].targetrotation){
6461                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6462                                                                 }
6463                                                         }
6464
6465
6466                                                         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))){
6467                                                                 player[k].turnspeed*=2;
6468                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6469                                                                 else if(player[k].rotation>player[k].targetrotation){
6470                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6471                                                                 }
6472                                                                 else if(player[k].rotation<player[k].targetrotation){
6473                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6474                                                                 }
6475                                                                 player[k].turnspeed/=2;
6476                                                         }
6477
6478                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6479                                                                 player[k].turnspeed*=4;
6480                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6481                                                                 else if(player[k].rotation>player[k].targetrotation){
6482                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6483                                                                 }
6484                                                                 else if(player[k].rotation<player[k].targetrotation){
6485                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6486                                                                 }
6487                                                                 player[k].turnspeed/=4;
6488                                                         }
6489
6490                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6491                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6492
6493                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6494                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6495                                                                         bool tempcollide=0;
6496
6497                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6498                                                                         if(player[k].collide>1)player[k].collide=1;
6499                                                                         player[k].collide-=multiplier*30;
6500
6501                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6502                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6503                                                                         }
6504                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6505                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6506                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6507                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6508                                                                                                 lowpoint=player[k].coords;
6509                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6510                                                                                                 else lowpoint.y+=1.3;
6511                                                                                                 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){
6512                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6513                                                                                                 }
6514                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6515                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6516                                                                                                 */
6517                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6518                                                                                                         flatfacing=lowpoint-player[k].coords;
6519                                                                                                         player[k].coords=lowpoint;
6520                                                                                                         player[k].coords.y-=1.3;
6521                                                                                                         player[k].collide=1;
6522                                                                                                         tempcollide=1;
6523                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6524                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6525                                                                                                                 tempcoords1=lowpoint;
6526                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6527                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6528                                                                                                                         player[k].target=0;
6529                                                                                                                         player[k].targetanimation=walljumpleftanim;
6530                                                                                                                         player[k].targetframe=0;
6531                                                                                                                         float gLoc[3];
6532                                                                                                                         float vel[3];
6533                                                                                                                         gLoc[0]=player[k].coords.x;
6534                                                                                                                         gLoc[1]=player[k].coords.y;
6535                                                                                                                         gLoc[2]=player[k].coords.z;
6536                                                                                                                         vel[0]=0;
6537                                                                                                                         vel[1]=0;
6538                                                                                                                         vel[2]=0;
6539                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6540                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6541                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6542                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6543                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6544
6545                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6546                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6547                                                                                                                         player[k].rotation*=360/6.28;
6548                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6549                                                                                                                         player[k].targetrotation=player[k].rotation;
6550                                                                                                                         player[k].lowrotation=player[k].rotation;
6551                                                                                                                         if(k==0)numwallflipped++;
6552                                                                                                                 }
6553                                                                                                                 else
6554                                                                                                                 {
6555                                                                                                                         lowpoint=tempcoords1;
6556                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6557                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6558                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6559                                                                                                                                 player[k].target=0;
6560                                                                                                                                 player[k].targetanimation=walljumprightanim;
6561                                                                                                                                 player[k].targetframe=0;
6562                                                                                                                                 float gLoc[3];
6563                                                                                                                                 float vel[3];
6564                                                                                                                                 gLoc[0]=player[k].coords.x;
6565                                                                                                                                 gLoc[1]=player[k].coords.y;
6566                                                                                                                                 gLoc[2]=player[k].coords.z;
6567                                                                                                                                 vel[0]=0;
6568                                                                                                                                 vel[1]=0;
6569                                                                                                                                 vel[2]=0;
6570                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6571                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6572                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6573                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6574                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6575
6576                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6577                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6578                                                                                                                                 player[k].rotation*=360/6.28;
6579                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6580                                                                                                                                 player[k].targetrotation=player[k].rotation;
6581                                                                                                                                 player[k].lowrotation=player[k].rotation;
6582                                                                                                                                 if(k==0)numwallflipped++;
6583                                                                                                                         }
6584                                                                                                                         else
6585                                                                                                                         {
6586                                                                                                                                 lowpoint=tempcoords1;
6587                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6588                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6589                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6590                                                                                                                                         player[k].target=0;
6591                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6592                                                                                                                                         player[k].targetframe=0;
6593                                                                                                                                         float gLoc[3];
6594                                                                                                                                         float vel[3];
6595                                                                                                                                         gLoc[0]=player[k].coords.x;
6596                                                                                                                                         gLoc[1]=player[k].coords.y;
6597                                                                                                                                         gLoc[2]=player[k].coords.z;
6598                                                                                                                                         vel[0]=0;
6599                                                                                                                                         vel[1]=0;
6600                                                                                                                                         vel[2]=0;
6601                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6602                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6603                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6604                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6605                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6606
6607                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6608                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6609                                                                                                                                         player[k].rotation*=360/6.28;
6610                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6611                                                                                                                                         player[k].targetrotation=player[k].rotation;
6612                                                                                                                                         player[k].lowrotation=player[k].rotation;
6613                                                                                                                                         if(k==0)numwallflipped++;
6614                                                                                                                                 }
6615                                                                                                                                 else
6616                                                                                                                                 {
6617                                                                                                                                         lowpoint=tempcoords1;
6618                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6619                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6620                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6621                                                                                                                                                 player[k].target=0;
6622                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6623                                                                                                                                                 player[k].targetframe=0;
6624                                                                                                                                                 float gLoc[3];
6625                                                                                                                                                 float vel[3];
6626                                                                                                                                                 gLoc[0]=player[k].coords.x;
6627                                                                                                                                                 gLoc[1]=player[k].coords.y;
6628                                                                                                                                                 gLoc[2]=player[k].coords.z;
6629                                                                                                                                                 vel[0]=0;
6630                                                                                                                                                 vel[1]=0;
6631                                                                                                                                                 vel[2]=0;
6632                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6633                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6634                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6635                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6636                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6637
6638                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6639                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6640                                                                                                                                                 player[k].rotation*=360/6.28;
6641                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6642                                                                                                                                                 player[k].rotation+=180;
6643                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6644                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6645                                                                                                                                                 if(k==0)numwallflipped++;
6646                                                                                                                                         }
6647                                                                                                                                 }
6648                                                                                                                         }
6649                                                                                                                 }
6650                                                                                                         }
6651                                                                                                 }
6652                                                                                         }
6653                                                                                         else if(objects.type[i]==rocktype){
6654                                                                                                 lowpoint2=player[k].coords;
6655                                                                                                 lowpoint=player[k].coords;
6656                                                                                                 lowpoint.y+=2;
6657                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6658                                                                                                         player[k].coords=colpoint;
6659                                                                                                         player[k].collide=1;
6660                                                                                                         tempcollide=1;
6661
6662                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6663                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6664
6665                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6666                                                                                                                 player[k].target=0;
6667                                                                                                                 player[k].targetframe=0;
6668                                                                                                                 player[k].onterrain=1;
6669
6670                                                                                                                 if(player[k].id==0){
6671                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6672                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6673                                                                                                                 }
6674
6675                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6676                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6677                                                                                                                         player[k].targetanimation=player[k].getLanding();
6678                                                                                                                         float gLoc[3];
6679                                                                                                                         float vel[3];
6680                                                                                                                         gLoc[0]=player[k].coords.x;
6681                                                                                                                         gLoc[1]=player[k].coords.y;
6682                                                                                                                         gLoc[2]=player[k].coords.z;
6683                                                                                                                         vel[0]=player[k].velocity.x;
6684                                                                                                                         vel[1]=player[k].velocity.y;
6685                                                                                                                         vel[2]=player[k].velocity.z;
6686                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6687                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6688                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6689                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6690                                                                                                                         if(k==0){
6691                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6692                                                                                                                                 envsoundvol[numenvsounds]=16;
6693                                                                                                                                 envsoundlife[numenvsounds]=.4;
6694                                                                                                                                 numenvsounds++;
6695                                                                                                                         }
6696
6697                                                                                                                 }
6698                                                                                                         }
6699                                                                                                 }
6700                                                                                         }
6701                                                                                 }
6702                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6703                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6704                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6705                                                                                                 lowpoint=player[k].coords;
6706                                                                                                 lowpoint.y+=1.35;
6707                                                                                                 if(objects.type[i]!=rocktype)
6708                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6709                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6710                                                                                                                 player[k].coords=lowpoint;
6711                                                                                                                 player[k].coords.y-=1.35;
6712                                                                                                                 player[k].collide=1;
6713
6714                                                                                                                 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)){
6715                                                                                                                         lowpoint=player[k].coords;
6716                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6717                                                                                                                         lowpoint=player[k].coords;
6718                                                                                                                         lowpoint.y+=.05;
6719                                                                                                                         facing=0;
6720                                                                                                                         facing.z=-1;
6721                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6722                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6723                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6724                                                                                                                         if(whichhit!=-1){
6725                                                                                                                                 lowpoint=player[k].coords;
6726                                                                                                                                 lowpoint.y+=.1;
6727                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6728                                                                                                                                 lowpoint2=lowpoint;
6729                                                                                                                                 lowpointtarget2=lowpointtarget;
6730                                                                                                                                 lowpoint3=lowpoint;
6731                                                                                                                                 lowpointtarget3=lowpointtarget;
6732                                                                                                                                 lowpoint4=lowpoint;
6733                                                                                                                                 lowpointtarget4=lowpointtarget;
6734                                                                                                                                 lowpoint5=lowpoint;
6735                                                                                                                                 lowpointtarget5=lowpointtarget;
6736                                                                                                                                 lowpoint6=lowpoint;
6737                                                                                                                                 lowpointtarget6=lowpointtarget;
6738                                                                                                                                 lowpoint7=lowpoint;
6739                                                                                                                                 lowpointtarget7=lowpoint;
6740                                                                                                                                 lowpoint2.x+=.1;
6741                                                                                                                                 lowpointtarget2.x+=.1;
6742                                                                                                                                 lowpoint3.z+=.1;
6743                                                                                                                                 lowpointtarget3.z+=.1;
6744                                                                                                                                 lowpoint4.x-=.1;
6745                                                                                                                                 lowpointtarget4.x-=.1;
6746                                                                                                                                 lowpoint5.z-=.1;
6747                                                                                                                                 lowpointtarget5.z-=.1;
6748                                                                                                                                 lowpoint6.y+=45/13;
6749                                                                                                                                 lowpointtarget6.y+=45/13;
6750                                                                                                                                 lowpointtarget6+=facing*.6;
6751                                                                                                                                 lowpointtarget7.y+=90/13;
6752                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6753                                                                                                                                 if(objects.friction[i]>.5)
6754                                                                                                                                         if(whichhit!=-1){
6755                                                                                                                                                 //if(k==0){
6756                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6757                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6758                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6759                                                                                                                                                                 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)
6760                                                                                                                                                                         for(j=0;j<45;j++){
6761                                                                                                                                                                                 lowpoint=player[k].coords;
6762                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6763                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6764                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6765                                                                                                                                                                                         if(j<=6){
6766                                                                                                                                                                                                 j=100;
6767                                                                                                                                                                                         }
6768                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6769                                                                                                                                                                                         j=100;
6770                                                                                                                                                                                         }*/
6771                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6772                                                                                                                                                                                                 j=100;
6773                                                                                                                                                                                         }
6774                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6775                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6776                                                                                                                                                                                                 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)*/){
6777                                                                                                                                                                                                         lowpoint=player[k].coords;
6778                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6779                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6780                                                                                                                                                                                                         flatfacing=player[k].coords;
6781                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6782                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6783                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6784
6785                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6786                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6787                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6788                                                                                                                                                                                                                 }
6789                                                                                                                                                                                                                 float gLoc[3];
6790                                                                                                                                                                                                                 float vel[3];
6791                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6792                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6793                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6794                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6795                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6796                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6797                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6798                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6799                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6800                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6801
6802                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6803                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6804                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6805                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6806                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6807                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6808
6809                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6810                                                                                                                                                                                                                 player[k].velocity=0;
6811
6812                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6813                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6814                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6815                                                                                                                                                                                                                         player[k].jumppower=0;
6816                                                                                                                                                                                                                         player[k].jumpclimb=1;
6817                                                                                                                                                                                                                 }
6818                                                                                                                                                                                                                 player[k].transspeed=6;
6819                                                                                                                                                                                                                 player[k].target=0;
6820
6821                                                                                                                                                                                                                 //player[k].currentframe=1;
6822                                                                                                                                                                                                                 player[k].targetframe=1;
6823                                                                                                                                                                                                                 if(j>25){
6824                                                                                                                                                                                                                         //player[k].currentframe=0;
6825                                                                                                                                                                                                                         player[k].targetframe=0;
6826                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6827                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6828                                                                                                                                                                                                                         player[k].jumppower=0;
6829                                                                                                                                                                                                                 }
6830                                                                                                                                                                                                         }
6831                                                                                                                                                                                                         j=100;
6832                                                                                                                                                                                                 }
6833                                                                                                                                                                                         }
6834                                                                                                                                                                                 }
6835                                                                                                                                                                         }
6836                                                                                                                                                                         //}
6837                                                                                                                                         }
6838                                                                                                                         }
6839                                                                                                                 }
6840                                                                                                         }
6841                                                                                         }
6842                                                                                         if(player[k].collide<=0){
6843                                                                                                 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()){
6844                                                                                                         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)){
6845                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6846                                                                                                                 player[k].targetanimation=jumpdownanim;
6847                                                                                                                 player[k].targetframe=0;
6848                                                                                                                 player[k].target=0;
6849
6850                                                                                                                 float gLoc[3];
6851                                                                                                                 float vel[3];
6852                                                                                                                 gLoc[0]=player[k].coords.x;
6853                                                                                                                 gLoc[1]=player[k].coords.y;
6854                                                                                                                 gLoc[2]=player[k].coords.z;
6855                                                                                                                 vel[0]=player[k].velocity.x;
6856                                                                                                                 vel[1]=player[k].velocity.y;
6857                                                                                                                 vel[2]=player[k].velocity.z;
6858                                                                                                                 if(k==0){
6859                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6860                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6861                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6862                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6863                                                                                                                 }
6864                                                                                                         }
6865                                                                                                         player[k].velocity.y+=gravity;
6866                                                                                                 }
6867                                                                                         }
6868                                                                 }
6869                                                         }
6870                                                         player[k].realoldcoords=player[k].coords;
6871                                                 }
6872
6873                                                 static XYZ oldviewer;
6874
6875                                                 if(indialogue==-1){
6876                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6877                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6878                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6879                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6880                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6881                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6882                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6883                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6884                                                 }
6885                                                 else
6886                                                 {
6887                                                         player[0].forwardkeydown=0;
6888                                                         player[0].leftkeydown=0;
6889                                                         player[0].backkeydown=0;
6890                                                         player[0].rightkeydown=0;
6891                                                         player[0].jumpkeydown=0;
6892                                                         player[0].crouchkeydown=0;
6893                                                         player[0].drawkeydown=0;
6894                                                         player[0].throwkeydown=0;
6895                                                 }
6896
6897                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6898
6899
6900                                                 static bool endkeydown;
6901                                                 if(indialogue!=-1){
6902                                                         cameramode=1;
6903                                                         if(directing){
6904                                                                 facing=0;
6905                                                                 facing.z=-1;
6906
6907                                                                 facing=DoRotation(facing,-rotation2,0,0);
6908                                                                 facing=DoRotation(facing,0,0-rotation,0);
6909
6910                                                                 flatfacing=0;
6911                                                                 flatfacing.z=-1;
6912
6913                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6914
6915                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6916                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6917                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6918                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6919                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6920                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6921                                                                 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)
6922                                                                         ||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)
6923                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6924                                                                                 int whichend;
6925                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6926                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6927                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6928                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6929                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6930                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6931                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6932                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6933                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6934                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6935                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6936                                                                                 if(whichend!=-1){
6937                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6938                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6939                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6940                                                                                 }
6941                                                                                 if(whichend==-1){
6942                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6943                                                                                 }
6944                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6945                                                                                         indialogue=-1;
6946                                                                                         directing=0;
6947                                                                                         cameramode=0;
6948                                                                                 }
6949                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6950                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6951                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6952                                                                                 indialogue++;
6953                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6954                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6955                                                                                                 static float gLoc[3];
6956                                                                                                 static float vel[3];
6957                                                                                                 XYZ temppos;
6958                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6959                                                                                                 temppos=temppos-viewer;
6960                                                                                                 Normalise(&temppos);
6961                                                                                                 temppos+=viewer;
6962
6963                                                                                                 gLoc[0]=temppos.x;
6964                                                                                                 gLoc[1]=temppos.y;
6965                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6966                                                                                                 vel[1]=0;
6967                                                                                                 vel[2]=0;
6968                                                                                                 int whichsoundplay;
6969                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6970                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6971                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6972                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6973                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6974                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6975                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6976                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6977                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6978                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6979                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6980                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6981                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6982                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6983                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6984                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6985                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6986                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6987                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6988                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6989                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6990                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6991                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6992                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6993                                                                                         }
6994                                                                                 }
6995
6996                                                                                 for(j=0;j<numplayers;j++){
6997                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6998                                                                                 }
6999
7000                                                                                 endkeydown=1;
7001                                                                         }
7002                                                                         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)
7003                                                                                 ||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)
7004                                                                                 )){
7005                                                                                         int whichend;
7006                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
7007                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
7008                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
7009                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
7010                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
7011                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
7012                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
7013                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
7014                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
7015                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
7016                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
7017                                                                                 }
7018                                                                                 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)
7019                                                                                         &&!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)
7020                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7021                                                                                                 endkeydown=0;
7022                                                                                         }
7023                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7024                                                                                                 indialogue=-1;
7025                                                                                                 directing=0;
7026                                                                                                 cameramode=0;
7027                                                                                         }
7028                                                         }
7029                                                         if(!directing){
7030                                                                 OPENAL_SetPaused(channels[whooshsound], true);
7031                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7032                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7033                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7034                                                                 }
7035                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7036                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7037                                                                 if(dialoguetime>0.5)
7038                                                                         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)
7039                                                                                 ||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)
7040                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7041                                                                                         indialogue++;
7042                                                                                         endkeydown=1;
7043                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7044                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7045                                                                                                         static float gLoc[3];
7046                                                                                                         static float vel[3];
7047                                                                                                         XYZ temppos;
7048                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7049                                                                                                         temppos=temppos-viewer;
7050                                                                                                         Normalise(&temppos);
7051                                                                                                         temppos+=viewer;
7052
7053                                                                                                         gLoc[0]=temppos.x;
7054                                                                                                         gLoc[1]=temppos.y;
7055                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7056                                                                                                         vel[1]=0;
7057                                                                                                         vel[2]=0;
7058                                                                                                         int whichsoundplay;
7059                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7060                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7061                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7062                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7063                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7064                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7065                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7066                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7067                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7068                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7069                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7070                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7071                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7072                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7073                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7074                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7075                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7076                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7077                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7078                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7079                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7080                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7081                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
7082                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7083                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
7084                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
7085                                                                                                         }
7086                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7087                                                                                                                 hotspot[numhotspots]=player[0].coords;
7088                                                                                                                 hotspotsize[numhotspots]=10;
7089                                                                                                                 hotspottype[numhotspots]=-1;
7090
7091                                                                                                                 numhotspots++;
7092                                                                                                         }
7093                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7094                                                                                                                 hostile=1;
7095                                                                                                         }
7096
7097                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7098                                                                                                                 indialogue=-1;
7099                                                                                                                 directing=0;
7100                                                                                                                 cameramode=0;
7101                                                                                                         }
7102                                                                                                 }
7103                                                                                         }
7104                                                                                 }
7105                                                                                 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)
7106                                                                                         &&!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)
7107                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7108                                                                                                 endkeydown=0;
7109                                                                                         }
7110                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7111                                                                                                 indialogue=-1;
7112                                                                                                 directing=0;
7113                                                                                                 cameramode=0;
7114                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7115                                                                                                         hostile=1;
7116                                                                                                 }
7117                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7118                                                                                                         windialogue=1;
7119                                                                                                 }
7120                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7121                                                                                                         hostile=1;
7122                                                                                                         for(i=1;i<numplayers;i++){
7123                                                                                                                 player[i].aitype = attacktypecutoff;
7124                                                                                                         }
7125                                                                                                 }
7126                                                                                         }
7127                                                         }
7128                                                 }
7129
7130                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7131                                                 else oldbuttondialogue=1;
7132
7133                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7134
7135                                                 //Net updates
7136
7137                                                 /*keyrefreshdelay-=multiplier;
7138                                                 bigrefreshdelay-=multiplier;
7139
7140                                                 if(keyrefreshdelay<=0){
7141                                                 static int concat[4];
7142
7143                                                 concat[0]=player[0].forwardkeydown;
7144                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7145                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7146                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7147                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7148                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7149                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7150                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7151
7152                                                 concat[1]=player[0].crouchtogglekeydown;
7153                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7154                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7155                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7156                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7157                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7158
7159                                                 //concat[2]=(char)((int)(rotation/2)%180);
7160
7161                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7162
7163                                                 chatname[0]=concat[0]-128;
7164                                                 chatname[1]=concat[1]-128;
7165                                                 //chatname[2]=concat[2]-128;
7166                                                 //chatname[3]=concat[3]-128;
7167                                                 int temppoint=2;
7168                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7169                                                 temppoint+=sizeof(float);
7170                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7171                                                 temppoint+=sizeof(float);
7172
7173                                                 chatname[temppoint]='\0';
7174
7175                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7176                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7177                                                 //keyrefreshdelay=.01;
7178                                                 keyrefreshdelay=.03;
7179                                                 }
7180
7181                                                 if(bigrefreshdelay<=0){
7182                                                 for(i=0;i<1;i++){
7183                                                 /*int temppoint=0;
7184                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7185                                                 temppoint+=sizeof(int);
7186                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7187                                                 temppoint+=sizeof(float);
7188                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7189                                                 temppoint+=sizeof(float);
7190                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7191                                                 temppoint+=sizeof(float);
7192                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7193                                                 temppoint+=sizeof(float);
7194                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7195                                                 temppoint+=sizeof(float);
7196                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7197                                                 temppoint+=sizeof(int);
7198                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7199                                                 temppoint+=sizeof(int);
7200                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7201                                                 temppoint+=sizeof(float);
7202                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7203                                                 temppoint+=sizeof(float);
7204                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7205                                                 temppoint+=sizeof(float);
7206                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7207                                                 temppoint+=sizeof(int);
7208                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7209                                                 temppoint+=sizeof(int);
7210                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7211                                                 temppoint+=sizeof(float);
7212                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7213                                                 temppoint+=sizeof(float);
7214                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7215                                                 temppoint+=sizeof(float);
7216                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7217                                                 temppoint+=sizeof(int);
7218                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7219                                                 temppoint+=sizeof(int);
7220                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7221                                                 temppoint+=sizeof(int);
7222                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7223                                                 temppoint+=sizeof(int);
7224                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7225                                                 temppoint+=sizeof(int);
7226                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7227                                                 temppoint+=sizeof(int);
7228                                                 chatname[temppoint]='\0';
7229
7230                                                 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);
7231                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7232                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7233
7234                                                 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);
7235
7236                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7237                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7238                                                 }
7239                                                 //bigrefreshdelay=.02;
7240                                                 bigrefreshdelay=.1;
7241                                                 }
7242                                                 }*/
7243
7244                                                 if(!player[0].jumpkeydown){
7245                                                         player[0].jumptogglekeydown=0;
7246                                                 }
7247                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7248
7249
7250                                                 dialoguetime+=multiplier;
7251                                                 skybox.cloudmove+=multiplier;
7252                                                 hawkrotation+=multiplier*25;
7253                                                 realhawkcoords=0;
7254                                                 realhawkcoords.x=25;
7255                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7256                                                 hawkcalldelay-=multiplier/2;
7257
7258                                                 if(hawkcalldelay<=0)
7259                                                 {
7260                                                         static float gLoc[3];
7261                                                         static float vel[3];
7262                                                         gLoc[0]=realhawkcoords.x;
7263                                                         gLoc[1]=realhawkcoords.y;
7264                                                         gLoc[2]=realhawkcoords.z;
7265                                                         vel[0]=0;
7266                                                         vel[1]=0;
7267                                                         vel[2]=0;
7268                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
7269                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
7270                                                         OPENAL_SetVolume(channels[hawksound], 128);
7271                                                         OPENAL_SetPaused(channels[hawksound], false);
7272
7273                                                         hawkcalldelay=16+abs(Random()%8);
7274                                                 }
7275                                                 static float temptexdetail;
7276
7277
7278                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7279                                                         player[0].damagetolerance=200000;
7280                                                         player[0].damage=0;
7281                                                         player[0].burnt=0;
7282                                                         player[0].permanentdamage=0;
7283                                                         player[0].superpermanentdamage=0;
7284                                                         /*
7285                                                         int whichchar;
7286                                                         whichchar = abs(Random()%7);
7287                                                         registrationname[whichchar]+=1;
7288                                                         */
7289                                                 }
7290
7291                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7292                                                         environment++;
7293                                                         if(environment>2)environment=0;
7294                                                         Setenvironment(environment);
7295
7296                                                         envtogglekeydown=1;
7297                                                 }
7298
7299
7300                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7301                                                         envtogglekeydown=0;
7302                                                 }
7303
7304                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7305                                                         cameramode=1-cameramode;
7306                                                         cameratogglekeydown=1;
7307                                                 }
7308
7309                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7310                                                         cameratogglekeydown=0;
7311                                                 }
7312
7313                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7314                                                         if(player[0].num_weapons>0){
7315                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7316                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7317                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7318                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7319                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7320                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7321                                                                         weapons.length[player[0].weaponids[0]]=.8;
7322                                                                 }
7323                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7324                                                                         weapons.mass[player[0].weaponids[0]]=2;
7325                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7326                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7327                                                                 }
7328
7329                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7330                                                                         weapons.mass[player[0].weaponids[0]]=1;
7331                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7332                                                                         weapons.length[player[0].weaponids[0]]=.25;
7333                                                                 }
7334                                                         }
7335
7336                                                         /*for(i=0;i<objects.numobjects;i++){
7337                                                         if(objects.type[i]==treeleavestype){
7338                                                         for(j=0;j<objects.numobjects;j++){
7339                                                         if(objects.type[j]==treetrunktype)
7340                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7341                                                         objects.scale[i]=objects.scale[j];
7342                                                         }
7343                                                         }
7344                                                         }*/
7345                                                         detailtogglekeydown=1;
7346                                                 }
7347
7348                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7349                                                         int closest=-1;
7350                                                         float closestdist=-1;
7351                                                         float distance;
7352                                                         if(numplayers>1)
7353                                                                 for(i=1;i<numplayers;i++){
7354                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7355                                                                         if(closestdist==-1||distance<closestdist){
7356                                                                                 closestdist=distance;
7357                                                                                 closest=i;
7358                                                                         }
7359                                                                 }
7360                                                                 if(closest!=-1){
7361                                                                         if(player[closest].num_weapons)
7362                                                                         {
7363                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7364                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7365                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7366                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7367                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7368                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7369                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7370                                                                                 }
7371                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7372                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7373                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7374                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7375                                                                                 }
7376                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7377                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7378                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7379                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7380                                                                                 }
7381                                                                         }
7382                                                                         if(!player[closest].num_weapons)
7383                                                                         {
7384                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7385                                                                                 weapons.owner[weapons.numweapons]=closest;
7386                                                                                 weapons.type[weapons.numweapons]=knife;
7387                                                                                 weapons.damage[weapons.numweapons]=0;
7388                                                                                 weapons.numweapons++;
7389                                                                                 player[closest].num_weapons=1;
7390                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7391                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7392                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7393                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7394                                                                                 }
7395                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7396                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7397                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7398                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7399                                                                                 }
7400                                                                         }
7401                                                                 }
7402                                                                 detailtogglekeydown=1;
7403                                                 }
7404
7405                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7406                                                         int closest=-1;
7407                                                         float closestdist=-1;
7408                                                         float distance;
7409                                                         if(numplayers>1)
7410                                                                 for(i=1;i<numplayers;i++){
7411                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7412                                                                         if(closestdist==-1||distance<closestdist){
7413                                                                                 closestdist=distance;
7414                                                                                 closest=i;
7415                                                                         }
7416                                                                 }
7417
7418                                                                 player[closest].rotation+=multiplier*50;
7419                                                                 player[closest].targetrotation=player[closest].rotation;
7420                                                 }
7421
7422
7423                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7424                                                         int closest=-1;
7425                                                         float closestdist=-1;
7426                                                         float distance;
7427                                                         if(numplayers>1)
7428                                                                 for(i=1;i<numplayers;i++){
7429                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7430                                                                         if(closestdist==-1||distance<closestdist){
7431                                                                                 closestdist=distance;
7432                                                                                 closest=i;
7433                                                                         }
7434                                                                 }
7435                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7436
7437                                                                 if(closest!=-1){
7438                                                                         player[closest].whichskin++;
7439                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7440                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7441
7442                                                                         if(player[closest].creature==rabbittype){
7443                                                                                 if(player[closest].whichskin==0){
7444                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7445                                                                                 }
7446                                                                                 else if(player[closest].whichskin==1){
7447                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7448                                                                                 }
7449                                                                                 else if(player[closest].whichskin==2){
7450                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7451                                                                                 }
7452                                                                                 else if(player[closest].whichskin==3){
7453                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7454                                                                                 }
7455                                                                                 else if(player[closest].whichskin==4){
7456                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7457                                                                                 }
7458                                                                                 else if(player[closest].whichskin==5){
7459                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7460                                                                                 }
7461                                                                                 else if(player[closest].whichskin==6){
7462                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7463                                                                                 }
7464                                                                                 else if(player[closest].whichskin==7){
7465                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7466                                                                                 }
7467                                                                                 else if(player[closest].whichskin==8){
7468                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7469                                                                                 }
7470                                                                                 else if(player[closest].whichskin==9){
7471                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7472                                                                                 }
7473                                                                         }
7474                                                                         if(player[closest].creature==wolftype){
7475                                                                                 k=abs(Random()%3);
7476                                                                                 if(player[closest].whichskin==0){
7477                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7478                                                                                 }
7479                                                                                 else if(player[closest].whichskin==1){
7480                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7481                                                                                 }
7482                                                                                 else if(player[closest].whichskin==2){
7483                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7484                                                                                 }
7485                                                                         }
7486                                                                 }
7487
7488                                                                 if(player[closest].numclothes){
7489                                                                         for(i=0;i<player[closest].numclothes;i++){
7490                                                                                 tintr=player[closest].clothestintr[i];
7491                                                                                 tintg=player[closest].clothestintg[i];
7492                                                                                 tintb=player[closest].clothestintb[i];
7493                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7494                                                                         }
7495                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7496                                                                 }
7497
7498                                                                 detailtogglekeydown=1;
7499                                                 }
7500
7501                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7502                                                         int closest=-1;
7503                                                         float closestdist=-1;
7504                                                         float distance;
7505                                                         if(numplayers>1)
7506                                                                 for(i=1;i<numplayers;i++){
7507                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7508                                                                         if(closestdist==-1||distance<closestdist){
7509                                                                                 closestdist=distance;
7510                                                                                 closest=i;
7511                                                                         }
7512                                                                 }
7513                                                                 if(closest!=-1){
7514                                                                         if(player[closest].creature==wolftype){
7515                                                                                 headprop=player[closest].proportionhead.x/1.1;
7516                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7517                                                                                 armprop=player[closest].proportionarms.x/1.1;
7518                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7519                                                                         }
7520
7521                                                                         if(player[closest].creature==rabbittype){
7522                                                                                 headprop=player[closest].proportionhead.x/1.2;
7523                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7524                                                                                 armprop=player[closest].proportionarms.x/1.00;
7525                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7526                                                                         }
7527
7528
7529                                                                         if(player[closest].creature==rabbittype){
7530                                                                                 player[closest].skeleton.id=closest;
7531                                                                                 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);
7532                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7533                                                                                 player[closest].whichskin=0;
7534                                                                                 player[closest].creature=wolftype;
7535
7536                                                                                 player[closest].proportionhead=1.1;
7537                                                                                 player[closest].proportionbody=1.1;
7538                                                                                 player[closest].proportionarms=1.1;
7539                                                                                 player[closest].proportionlegs=1.1;
7540                                                                                 player[closest].proportionlegs.y=1.1;
7541                                                                                 player[closest].scale=.23*5*player[0].scale;
7542
7543                                                                                 player[closest].damagetolerance=300;
7544                                                                         }
7545                                                                         else
7546                                                                         {
7547                                                                                 player[closest].skeleton.id=closest;
7548                                                                                 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);
7549                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7550                                                                                 player[closest].whichskin=0;
7551                                                                                 player[closest].creature=rabbittype;
7552
7553                                                                                 player[closest].proportionhead=1.2;
7554                                                                                 player[closest].proportionbody=1.05;
7555                                                                                 player[closest].proportionarms=1.00;
7556                                                                                 player[closest].proportionlegs=1.1;
7557                                                                                 player[closest].proportionlegs.y=1.05;
7558                                                                                 player[closest].scale=.2*5*player[0].scale;
7559
7560                                                                                 player[closest].damagetolerance=200;
7561                                                                         }
7562
7563                                                                         if(player[closest].creature==wolftype){
7564                                                                                 player[closest].proportionhead=1.1*headprop;
7565                                                                                 player[closest].proportionbody=1.1*bodyprop;
7566                                                                                 player[closest].proportionarms=1.1*armprop;
7567                                                                                 player[closest].proportionlegs=1.1*legprop;
7568                                                                         }
7569
7570                                                                         if(player[closest].creature==rabbittype){
7571                                                                                 player[closest].proportionhead=1.2*headprop;
7572                                                                                 player[closest].proportionbody=1.05*bodyprop;
7573                                                                                 player[closest].proportionarms=1.00*armprop;
7574                                                                                 player[closest].proportionlegs=1.1*legprop;
7575                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7576                                                                         }
7577
7578                                                                 }
7579                                                                 detailtogglekeydown=1;
7580                                                 }
7581
7582                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7583                                                         detailtogglekeydown=0;
7584                                                 }
7585
7586                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7587                                                         slomo=1-slomo;
7588                                                         slomodelay=1000;
7589                                                         slomotogglekeydown=1;
7590                                                 }
7591
7592
7593                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7594                                                         int closest=-1;
7595                                                         float closestdist=-1;
7596                                                         float distance;
7597                                                         XYZ flatfacing2,flatvelocity2;
7598                                                         XYZ blah;
7599                                                         if(numplayers>1)
7600                                                                 for(i=1;i<numplayers;i++){
7601                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7602                                                                         if(distance<144&&!player[i].headless)
7603                                                                                 if(closestdist==-1||distance<closestdist){
7604                                                                                         closestdist=distance;
7605                                                                                         closest=i;
7606                                                                                         blah = player[i].coords;
7607                                                                                 }
7608                                                                 }
7609
7610                                                                 if(closest!=-1){
7611                                                                         XYZ headspurtdirection;
7612                                                                         int i = player[closest].skeleton.jointlabels[head];
7613                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7614                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7615                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7616                                                                                 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;
7617                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7618                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7619                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7620                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7621                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7622                                                                                 Normalise(&headspurtdirection);
7623                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7624                                                                                 flatvelocity2+=headspurtdirection*8;
7625                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7626                                                                         }
7627                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7628
7629                                                                         float gLoc[3];
7630                                                                         float vel[3];
7631                                                                         gLoc[0]=blah.x;
7632                                                                         gLoc[1]=blah.y;
7633                                                                         gLoc[2]=blah.z;
7634                                                                         vel[0]=0;
7635                                                                         vel[1]=0;
7636                                                                         vel[2]=0;
7637                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7638                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7639                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7640                                                                         OPENAL_SetPaused(channels[splattersound], false);
7641
7642                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7643                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7644                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7645                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7646
7647                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7648                                                                         player[closest].RagDoll(0);
7649                                                                         player[closest].dead=2;
7650                                                                         player[closest].headless=1;
7651                                                                         player[closest].DoBloodBig(3,165);
7652
7653                                                                         camerashake+=.3;
7654                                                                 }
7655
7656                                                                 explodetogglekeydown=1;
7657                                                 }
7658
7659                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7660                                                         int closest=-1;
7661                                                         float closestdist=-1;
7662                                                         float distance;
7663                                                         XYZ flatfacing2,flatvelocity2;
7664                                                         XYZ blah;
7665                                                         if(numplayers>1)
7666                                                                 for(i=1;i<numplayers;i++){
7667                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7668                                                                         if(distance<144)
7669                                                                                 if(closestdist==-1||distance<closestdist){
7670                                                                                         closestdist=distance;
7671                                                                                         closest=i;
7672                                                                                         blah=player[i].coords;
7673                                                                                 }
7674                                                                 }
7675
7676                                                                 if(closest!=-1){
7677                                                                         float gLoc[3];
7678                                                                         float vel[3];
7679                                                                         gLoc[0]=blah.x;
7680                                                                         gLoc[1]=blah.y;
7681                                                                         gLoc[2]=blah.z;
7682                                                                         vel[0]=0;
7683                                                                         vel[1]=0;
7684                                                                         vel[2]=0;
7685
7686                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7687                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7688                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7689                                                                         OPENAL_SetPaused(channels[splattersound], false);
7690
7691                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7692                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7693                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7694                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7695
7696                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7697                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7698                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7699                                                                                 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;
7700                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7701                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7702                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7703                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7704                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7705                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7706                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7707                                                                         }
7708
7709                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7710                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7711                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7712                                                                                 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;
7713                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7714                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7715                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7716                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7717                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7718                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7719                                                                         }
7720
7721                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7722                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7723                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7724                                                                                 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;
7725                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7726                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7727                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7728                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7729                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7730                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7731                                                                         }
7732
7733                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7734                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7735                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7736                                                                                 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;
7737                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7738                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7739                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7740                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7741                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7742                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7743                                                                         }
7744
7745                                                                         XYZ temppos;
7746                                                                         for(j=0;j<numplayers; j++){
7747                                                                                 if(j!=closest){
7748                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7749                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7750                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7751                                                                                                 player[j].skeleton.longdead=0;
7752                                                                                                 player[j].RagDoll(0);
7753                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7754                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7755                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7756                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7757                                                                                                                 Normalise(&flatvelocity2);
7758                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7759                                                                                                         }
7760                                                                                                 }
7761                                                                                         }
7762                                                                                 }
7763                                                                         }
7764
7765                                                                         player[closest].DoDamage(10000);
7766                                                                         player[closest].RagDoll(0);
7767                                                                         player[closest].dead=2;
7768                                                                         player[closest].coords=20;
7769                                                                         player[closest].skeleton.free=2;
7770
7771                                                                         camerashake+=.6;
7772
7773                                                                 }
7774
7775                                                                 explodetogglekeydown=1;
7776                                                 }
7777
7778                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7779                                                         explodetogglekeydown=0;
7780                                                 }
7781
7782                                                 /*
7783                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7784                                                 FILE                    *tfile;
7785                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7786                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7787                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7788                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7789                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7790                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7791                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7792
7793                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7794                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7795                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7796                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7797                                                 for(j=0;j<player[0].num_weapons;j++){
7798                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7799                                                 }
7800                                                 fwrite( &environment, 1, sizeof(int), tfile );
7801
7802                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7803                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7804                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7805                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7806                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7807
7808                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7809                                                 if(numplayers>1&&numplayers<maxplayers)
7810                                                 for(i=1;i<numplayers;i++){
7811                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7812                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7813                                                 for(j=0;j<player[i].num_weapons;j++){
7814                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7815                                                 }
7816                                                 if(player[i].numwaypoints<30){
7817                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7818                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7819                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7820                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7821                                                 }
7822                                                 else{
7823                                                 player[i].numwaypoints=0;
7824                                                 player[i].waypoint=0;
7825                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7826                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7827                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7828                                                 }
7829                                                 }
7830
7831                                                 fclose(tfile);
7832
7833                                                 slomotogglekeydown=1;
7834                                                 }*/
7835
7836                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7837                                                         slomotogglekeydown=0;
7838                                                 }
7839
7840
7841                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7842                                                         player[0].onfire=1-player[0].onfire;
7843                                                         if(player[0].onfire){
7844                                                                 player[0].CatchFire();
7845                                                         }
7846                                                         if(!player[0].onfire){
7847                                                                 float gLoc[3];
7848                                                                 float vel[3];
7849                                                                 gLoc[0]=player[0].coords.x;
7850                                                                 gLoc[1]=player[0].coords.y;
7851                                                                 gLoc[2]=player[0].coords.z;
7852                                                                 vel[0]=0;
7853                                                                 vel[1]=0;
7854                                                                 vel[2]=0;
7855                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7856                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7857                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7858                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7859                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7860                                                         }
7861                                                         slomotogglekeydown=1;
7862                                                 }
7863                                                 /*
7864                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7865                                                 if(player[0].bleeding<=0)
7866                                                 player[0].DoBlood(1,255);
7867                                                 }*/
7868
7869
7870                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7871                                                         int closest=-1;
7872                                                         float closestdist=-1;
7873                                                         float distance;
7874                                                         if(numplayers>1)
7875                                                                 for(i=1;i<numplayers;i++){
7876                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7877                                                                         if(closestdist==-1||distance<closestdist){
7878                                                                                 closestdist=distance;
7879                                                                                 closest=i;
7880                                                                         }
7881                                                                 }
7882                                                                 if(closestdist>0&&closest>=0){
7883                                                                         //player[closest]=player[numplayers-1];
7884                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7885                                                                         numplayers--;
7886                                                                 }
7887                                                                 drawmodetogglekeydown=1;
7888                                                 }
7889
7890                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7891                                                         int closest=-1;
7892                                                         float closestdist=-1;
7893                                                         float distance;
7894                                                         if(max_objects>1)
7895                                                                 for(i=1;i<max_objects;i++){
7896                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7897                                                                         if(closestdist==-1||distance<closestdist){
7898                                                                                 closestdist=distance;
7899                                                                                 closest=i;
7900                                                                         }
7901                                                                 }
7902                                                                 if(closestdist>0&&closest>=0){
7903                                                                         objects.position[closest].y-=500;
7904                                                                 }
7905                                                                 drawmodetogglekeydown=1;
7906                                                 }
7907
7908                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7909                                                         //drawmode++;
7910                                                         //if(drawmode>2)drawmode=0;
7911                                                         if(objects.numobjects<max_objects-1){
7912                                                                 XYZ boxcoords;
7913                                                                 boxcoords.x=player[0].coords.x;
7914                                                                 boxcoords.z=player[0].coords.z;
7915                                                                 boxcoords.y=player[0].coords.y-3;
7916                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7917                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7918                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7919                                                                 float temprotat,temprotat2;
7920                                                                 temprotat=editorrotation;
7921                                                                 temprotat2=editorrotation2;
7922                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7923                                                                 if(temprotat2<0)temprotat2=Random()%360;
7924
7925                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7926                                                                 if(editortype==treetrunktype)
7927                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7928                                                         }
7929
7930                                                         drawmodetogglekeydown=1;
7931                                                 }
7932
7933                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7934                                                         if(numplayers<maxplayers-1){
7935                                                                 player[numplayers].scale=.2*5*player[0].scale;
7936                                                                 player[numplayers].creature=rabbittype;
7937                                                                 player[numplayers].howactive=editoractive;
7938                                                                 player[numplayers].skeleton.id=numplayers;
7939                                                                 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);
7940
7941                                                                 //texsize=512*512*3/texdetail/texdetail;
7942                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7943                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7944
7945                                                                 k=abs(Random()%2)+1;
7946                                                                 if(k==0){
7947                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7948                                                                         player[numplayers].whichskin=0;
7949                                                                 }
7950                                                                 else if(k==1){
7951                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7952                                                                         player[numplayers].whichskin=1;
7953                                                                 }
7954                                                                 else {
7955                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7956                                                                         player[numplayers].whichskin=2;
7957                                                                 }
7958
7959                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7960                                                                 player[numplayers].power=1;
7961                                                                 player[numplayers].speedmult=1;
7962                                                                 player[numplayers].currentanimation=bounceidleanim;
7963                                                                 player[numplayers].targetanimation=bounceidleanim;
7964                                                                 player[numplayers].currentframe=0;
7965                                                                 player[numplayers].targetframe=1;
7966                                                                 player[numplayers].target=0;
7967                                                                 player[numplayers].bled=0;
7968                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7969
7970                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7971                                                                 player[numplayers].rotation=player[0].rotation;
7972
7973                                                                 player[numplayers].velocity=0;
7974                                                                 player[numplayers].coords=player[0].coords;
7975                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7976                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7977
7978                                                                 player[numplayers].id=numplayers;
7979                                                                 player[numplayers].skeleton.id=numplayers;
7980                                                                 player[numplayers].updatedelay=0;
7981                                                                 player[numplayers].normalsupdatedelay=0;
7982
7983                                                                 player[numplayers].aitype=passivetype;
7984                                                                 player[numplayers].aitarget=0;
7985
7986                                                                 if(player[0].creature==wolftype){
7987                                                                         headprop=player[0].proportionhead.x/1.1;
7988                                                                         bodyprop=player[0].proportionbody.x/1.1;
7989                                                                         armprop=player[0].proportionarms.x/1.1;
7990                                                                         legprop=player[0].proportionlegs.x/1.1;
7991                                                                 }
7992
7993                                                                 if(player[0].creature==rabbittype){
7994                                                                         headprop=player[0].proportionhead.x/1.2;
7995                                                                         bodyprop=player[0].proportionbody.x/1.05;
7996                                                                         armprop=player[0].proportionarms.x/1.00;
7997                                                                         legprop=player[0].proportionlegs.x/1.1;
7998                                                                 }
7999
8000                                                                 if(player[numplayers].creature==wolftype){
8001                                                                         player[numplayers].proportionhead=1.1*headprop;
8002                                                                         player[numplayers].proportionbody=1.1*bodyprop;
8003                                                                         player[numplayers].proportionarms=1.1*armprop;
8004                                                                         player[numplayers].proportionlegs=1.1*legprop;
8005                                                                 }
8006
8007                                                                 if(player[numplayers].creature==rabbittype){
8008                                                                         player[numplayers].proportionhead=1.2*headprop;
8009                                                                         player[numplayers].proportionbody=1.05*bodyprop;
8010                                                                         player[numplayers].proportionarms=1.00*armprop;
8011                                                                         player[numplayers].proportionlegs=1.1*legprop;
8012                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
8013                                                                 }
8014
8015                                                                 player[numplayers].headless=0;
8016                                                                 player[numplayers].onfire=0;
8017
8018                                                                 if(cellophane){
8019                                                                         player[numplayers].proportionhead.z=0;
8020                                                                         player[numplayers].proportionbody.z=0;
8021                                                                         player[numplayers].proportionarms.z=0;
8022                                                                         player[numplayers].proportionlegs.z=0;
8023                                                                 }
8024
8025                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
8026
8027                                                                 player[numplayers].damagetolerance=200;
8028
8029                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8030                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8031                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8032                                                                 player[numplayers].armorhead=player[0].armorhead;
8033                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8034                                                                 player[numplayers].armorlow=player[0].armorlow;
8035                                                                 player[numplayers].metalhead=player[0].metalhead;
8036                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8037                                                                 player[numplayers].metallow=player[0].metallow;
8038
8039                                                                 player[numplayers].immobile=player[0].immobile;
8040
8041                                                                 player[numplayers].numclothes=player[0].numclothes;
8042                                                                 if(player[numplayers].numclothes)
8043                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8044                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8045                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8046                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8047                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8048                                                                                 tintr=player[numplayers].clothestintr[i];
8049                                                                                 tintg=player[numplayers].clothestintg[i];
8050                                                                                 tintb=player[numplayers].clothestintb[i];
8051                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8052                                                                         }
8053                                                                         if(player[numplayers].numclothes){
8054                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8055                                                                         }
8056
8057                                                                         player[numplayers].power=player[0].power;
8058                                                                         player[numplayers].speedmult=player[0].speedmult;
8059
8060                                                                         player[numplayers].damage=0;
8061                                                                         player[numplayers].permanentdamage=0;
8062                                                                         player[numplayers].superpermanentdamage=0;
8063                                                                         player[numplayers].deathbleeding=0;
8064                                                                         player[numplayers].bleeding=0;
8065                                                                         player[numplayers].numwaypoints=0;
8066                                                                         player[numplayers].waypoint=0;
8067                                                                         player[numplayers].jumppath=0;
8068                                                                         player[numplayers].weaponstuck=-1;
8069                                                                         player[numplayers].weaponactive=-1;
8070                                                                         player[numplayers].num_weapons=0;
8071                                                                         player[numplayers].bloodloss=0;
8072                                                                         player[numplayers].dead=0;
8073
8074                                                                         player[numplayers].loaded=1;
8075
8076                                                                         numplayers++;
8077                                                         }
8078                                                         drawmodetogglekeydown=1;
8079                                                 }
8080
8081                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8082                                                         if(player[numplayers-1].numwaypoints<90){
8083                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8084                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8085                                                                 player[numplayers-1].numwaypoints++;
8086                                                         }
8087                                                         drawmodetogglekeydown=1;
8088                                                 }
8089
8090                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8091                                                         if(numpathpoints<30){
8092                                                                 bool connected,alreadyconnected;
8093                                                                 connected=0;
8094                                                                 if(numpathpoints>1)
8095                                                                         for(i=0;i<numpathpoints;i++){
8096                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8097                                                                                         alreadyconnected=0;
8098                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8099                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8100                                                                                         }
8101                                                                                         if(!alreadyconnected){
8102                                                                                                 numpathpointconnect[pathpointselected]++;
8103                                                                                                 connected=1;
8104                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8105                                                                                         }
8106                                                                                 }
8107                                                                         }
8108                                                                         if(!connected){
8109                                                                                 numpathpoints++;
8110                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8111                                                                                 numpathpointconnect[numpathpoints-1]=0;
8112                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8113                                                                                         numpathpointconnect[pathpointselected]++;
8114                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8115                                                                                 }
8116                                                                                 pathpointselected=numpathpoints-1;
8117                                                                         }
8118                                                         }
8119                                                         drawmodetogglekeydown=1;
8120                                                 }
8121
8122                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8123                                                         pathpointselected++;
8124                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8125                                                         drawmodetogglekeydown=1;
8126                                                 }
8127                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8128                                                         pathpointselected--;
8129                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8130                                                         drawmodetogglekeydown=1;
8131                                                 }
8132                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8133                                                         if(pathpointselected!=-1){
8134                                                                 numpathpoints--;
8135                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8136                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8137                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8138                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8139                                                                 }
8140                                                                 for(i=0;i<numpathpoints;i++){
8141                                                                         for(j=0;j<numpathpointconnect[i];j++){
8142                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8143                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8144                                                                                         numpathpointconnect[i]--;
8145                                                                                 }
8146                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8147                                                                                         pathpointconnect[i][j]=pathpointselected;
8148                                                                                 }
8149                                                                         }
8150                                                                 }
8151                                                                 pathpointselected=numpathpoints-1;
8152                                                         }
8153                                                         drawmodetogglekeydown=1;
8154                                                 }
8155
8156                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8157                                                         editorenabled=1-editorenabled;
8158                                                         if(editorenabled){
8159                                                                 player[0].damagetolerance=100000;
8160                                                                 player[0].damage=0;
8161                                                                 player[0].superpermanentdamage=0;
8162                                                                 player[0].bloodloss=0;
8163                                                                 player[0].deathbleeding=0;
8164                                                         }
8165                                                         if(!editorenabled){
8166                                                                 player[0].damagetolerance=200;
8167                                                                 player[0].damage=0;
8168                                                                 player[0].permanentdamage=0;
8169                                                                 player[0].superpermanentdamage=0;
8170                                                                 player[0].bloodloss=0;
8171                                                                 player[0].deathbleeding=0;
8172                                                         }
8173                                                         drawmodetogglekeydown=1;
8174                                                 }
8175
8176                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8177                                                         editortype--;
8178                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8179                                                         if(editortype<0)editortype=firetype;
8180                                                         drawmodetogglekeydown=1;
8181                                                 }
8182
8183                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8184                                                         editortype++;
8185                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8186                                                         if(editortype>firetype)editortype=0;
8187                                                         drawmodetogglekeydown=1;
8188                                                 }
8189
8190                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8191                                                         editorrotation-=multiplier*100;
8192                                                         if(editorrotation<-.01)editorrotation=-.01;
8193                                                         drawmodetogglekeydown=1;
8194                                                 }
8195
8196                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8197                                                         editorrotation+=multiplier*100;
8198                                                         drawmodetogglekeydown=1;
8199                                                 }
8200
8201                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8202                                                         editorsize+=multiplier;
8203                                                         drawmodetogglekeydown=1;
8204                                                 }
8205
8206                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8207                                                         editorsize-=multiplier;
8208                                                         if(editorsize<.1)editorsize=.1;
8209                                                         drawmodetogglekeydown=1;
8210                                                 }
8211
8212
8213                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8214                                                         mapradius-=multiplier*10;
8215                                                 }
8216
8217                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8218                                                         mapradius+=multiplier*10;
8219                                                 }
8220                                                 /*
8221                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8222                                                 mapcenter.x+=multiplier*20;
8223                                                 }
8224
8225                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8226                                                 mapcenter.x-=multiplier*20;
8227                                                 }
8228
8229                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8230                                                 mapcenter.z+=multiplier*20;
8231                                                 }
8232
8233                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8234                                                 mapcenter.z-=multiplier*20;
8235                                                 }
8236                                                 */
8237                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8238                                                         editorrotation2+=multiplier*100;
8239                                                 }
8240
8241                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8242                                                         editorrotation2-=multiplier*100;
8243                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8244                                                 }
8245                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8246                                                         int closest=-1;
8247                                                         float closestdist=-1;
8248                                                         float distance;
8249                                                         for(i=0;i<objects.numobjects;i++){
8250                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8251                                                                 if(closestdist==-1||distance<closestdist){
8252                                                                         closestdist=distance;
8253                                                                         closest=i;
8254                                                                 }
8255                                                         }
8256                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
8257                                                         drawmodetogglekeydown=1;
8258                                                 }
8259
8260
8261                                                 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)){
8262                                                         drawmodetogglekeydown=0;
8263                                                 }
8264
8265                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8266                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8267                                                         player[0].RagDoll(0);
8268                                                         //player[0].spurt=1;
8269                                                         //player[0].DoDamage(1000);
8270
8271                                                         float gLoc[3];
8272                                                         float vel[3];
8273                                                         gLoc[0]=player[0].coords.x;
8274                                                         gLoc[1]=player[0].coords.y;
8275                                                         gLoc[2]=player[0].coords.z;
8276                                                         vel[0]=player[0].velocity.x;
8277                                                         vel[1]=player[0].velocity.y;
8278                                                         vel[2]=player[0].velocity.z;
8279                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
8280                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8281                                                         OPENAL_SetVolume(channels[whooshsound], 128);
8282                                                         OPENAL_SetPaused(channels[whooshsound], false);
8283                                                         //OPENAL_SetPaused(channels[whooshsound], true);
8284
8285                                                         texturesizetogglekeydown=1;
8286                                                 }
8287
8288                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8289
8290                                                         int closest=-1;
8291                                                         float closestdist=-1;
8292                                                         float distance;
8293                                                         for(i=0;i<objects.numobjects;i++){
8294                                                                 if(objects.type[i]==treeleavestype){
8295                                                                         objects.scale[i]*=.9;
8296                                                                 }
8297                                                         }
8298                                                         texturesizetogglekeydown=1;
8299                                                 }
8300
8301                                                 static XYZ relative;
8302                                                 static int randattack;
8303                                                 //Attack
8304                                                 static bool playerrealattackkeydown=0;
8305
8306                                                 if(!buttons[0])oldbutton=0;
8307                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8308                                                 if(oldattackkey)player[0].attackkeydown=0;
8309                                                 if(oldattackkey)playerrealattackkeydown=0;
8310                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8311                                                 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);
8312                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8313                                                         for(k=0;k<numplayers;k++){
8314                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8315                                                                         player[k].Reverse();
8316                                                         }
8317                                                 }
8318
8319                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8320
8321                                                 for(k=0;k<numplayers;k++){
8322                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8323                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8324                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8325                                                                 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)){
8326                                                                         player[k].jumppower-=2;
8327                                                                 }
8328                                                                 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)){
8329                                                                         for(i=0;i<numplayers;i++){
8330                                                                                 if(i==k)i++;
8331                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8332                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8333                                                                                                 player[k].targetanimation=dodgebackanim;
8334                                                                                                 player[k].target=0;
8335                                                                                                 player[k].targetframe=0;
8336                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8337                                                                                                 Normalise(&rotatetarget);
8338                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8339                                                                                                 player[k].targetrotation*=360/6.28;
8340                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8341
8342                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8343                                                                                         }
8344                                                                         }
8345                                                                         if(player[k].targetanimation!=dodgebackanim){
8346                                                                                 if(k==0)numflipped++;
8347                                                                                 player[k].targetanimation=backhandspringanim;
8348                                                                                 player[k].target=0;
8349                                                                                 player[k].targetframe=0;
8350                                                                                 player[k].targetrotation=-rotation+180;
8351                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8352                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8353                                                                                 player[k].rotation=player[k].targetrotation;
8354                                                                                 player[k].jumppower-=2;
8355                                                                         }
8356                                                                 }
8357                                                                 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())){
8358                                                                         player[k].hasvictim=0;
8359                                                                         if(numplayers>1)
8360                                                                                 for(i=0;i<numplayers;i++){
8361                                                                                         if(i==k)i++;
8362                                                                                         if(!player[k].hasvictim)
8363                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
8364                                                                                                         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){
8365                                                                                                                 player[k].victim=&player[i];
8366                                                                                                                 player[k].hasvictim=1;
8367                                                                                                                 if(player[k].aitype==playercontrolled){
8368                                                                                                                         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;
8369                                                                                                                         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;
8370                                                                                                                         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;
8371                                                                                                                         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;
8372                                                                                                                         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;
8373                                                                                                                         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;
8374                                                                                                                         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;
8375                                                                                                                         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;
8376                                                                                                                         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;
8377                                                                                                                         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;
8378                                                                                                                 }
8379                                                                                                                 else {
8380                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8381                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8382                                                                                                                                 else randattack=abs(Random()%5);
8383                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8384                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8385                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8386                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8387                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8388                                                                                                                                 }
8389                                                                                                                                 if(player[k].weaponactive!=-1){
8390                                                                                                                                         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;
8391                                                                                                                                         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;
8392                                                                                                                                         //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;
8393                                                                                                                                         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;
8394                                                                                                                                         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;
8395                                                                                                                                         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;
8396                                                                                                                                         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;
8397                                                                                                                                         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;
8398                                                                                                                                 }
8399                                                                                                                         }
8400                                                                                                                 }
8401                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8402                                                                                                         }
8403                                                                                                         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)){
8404                                                                                                                 if(player[k].weaponactive==-1){
8405                                                                                                                         player[i].targetanimation=sneakattackedanim;
8406                                                                                                                         player[i].currentanimation=sneakattackedanim;
8407                                                                                                                         player[k].currentanimation=sneakattackanim;
8408                                                                                                                         player[k].targetanimation=sneakattackanim;
8409                                                                                                                         player[k].oldcoords=player[k].coords;
8410                                                                                                                         player[k].coords=player[i].coords;
8411                                                                                                                 }
8412                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8413                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8414                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8415                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8416                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8417                                                                                                                         player[i].oldcoords=player[i].coords;
8418                                                                                                                         player[i].coords=player[k].coords;
8419                                                                                                                 }
8420                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8421                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8422                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8423                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8424                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8425                                                                                                                         player[i].oldcoords=player[i].coords;
8426                                                                                                                         player[i].coords=player[k].coords;
8427                                                                                                                 }
8428                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8429                                                                                                                         player[k].victim=&player[i];
8430                                                                                                                         player[k].hasvictim=1;
8431                                                                                                                         player[i].targettilt2=0;
8432                                                                                                                         player[i].targetframe=1;
8433                                                                                                                         player[i].currentframe=0;
8434                                                                                                                         player[i].target=0;
8435                                                                                                                         player[i].velocity=0;
8436                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8437                                                                                                                         player[k].currentframe=player[i].currentframe;
8438                                                                                                                         player[k].targetframe=player[i].targetframe;
8439                                                                                                                         player[k].target=player[i].target;
8440                                                                                                                         player[k].velocity=0;
8441                                                                                                                         player[k].targetrotation=player[i].rotation;
8442                                                                                                                         player[k].rotation=player[i].rotation;
8443                                                                                                                         player[i].targetrotation=player[i].rotation;
8444                                                                                                                 }
8445                                                                                                         }
8446                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8447                                                                                                                 oldattackkey=1;
8448                                                                                                                 player[k].targetframe=0;
8449                                                                                                                 player[k].target=0;
8450                                                                                                                 //player[k].velocity=0;
8451
8452                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8453                                                                                                                 Normalise(&rotatetarget);
8454                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8455                                                                                                                 player[k].targetrotation*=360/6.28;
8456                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8457
8458                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8459
8460                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8461                                                                                                                 player[k].lastattack2=player[k].lastattack;
8462                                                                                                                 player[k].lastattack=player[k].targetanimation;
8463                                                                                                                 //player[k].targettilt2=0;
8464                                                                                                                 //slomo=1;
8465                                                                                                                 //slomodelay=.2;
8466                                                                                                         }
8467                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8468                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8469                                                                                                                 Normalise(&rotatetarget);
8470                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8471                                                                                                                 player[k].targetrotation*=360/6.28;
8472                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8473                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8474                                                                                                                 oldattackkey=1;
8475                                                                                                                 player[k].victim=&player[i];
8476                                                                                                                 player[k].hasvictim=1;
8477                                                                                                                 player[i].targetanimation=knifefollowedanim;
8478                                                                                                                 player[i].currentanimation=knifefollowedanim;
8479                                                                                                                 player[i].targettilt2=0;
8480                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8481                                                                                                                 player[i].targetframe=1;
8482                                                                                                                 player[i].currentframe=0;
8483                                                                                                                 player[i].target=0;
8484                                                                                                                 player[i].velocity=0;
8485                                                                                                                 player[k].currentanimation=knifefollowanim;
8486                                                                                                                 player[k].targetanimation=knifefollowanim;
8487                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8488                                                                                                                 player[k].currentframe=player[i].currentframe;
8489                                                                                                                 player[k].targetframe=player[i].targetframe;
8490                                                                                                                 player[k].target=player[i].target;
8491                                                                                                                 player[k].velocity=0;
8492                                                                                                                 player[k].oldcoords=player[k].coords;
8493                                                                                                                 player[i].coords=player[k].coords;
8494                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8495                                                                                                                 player[i].rotation=player[k].targetrotation;
8496                                                                                                                 player[k].rotation=player[k].targetrotation;
8497                                                                                                                 player[i].rotation=player[k].targetrotation;
8498                                                                                                         }
8499                                                                                                 }
8500                                                                                 }
8501                                                                                 bool hasstaff=0;
8502                                                                                 if(player[k].weaponactive!=-1){
8503                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8504                                                                                 }
8505                                                                                 if(numplayers>1)
8506                                                                                         for(i=0;i<numplayers;i++){
8507                                                                                                 if(i==k)i++;
8508                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8509                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8510                                                                                                                 if(player[i].skeleton.free)
8511                                                                                                                         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)))){
8512                                                                                                                                 player[k].victim=&player[i];
8513                                                                                                                                 player[k].hasvictim=1;
8514                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8515                                                                                                                                         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;
8516                                                                                                                                         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;
8517                                                                                                                                         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;
8518                                                                                                                                 }
8519                                                                                                                                 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){
8520                                                                                                                                         player[k].targetanimation=killanim;
8521                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8522                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8523                                                                                                                                                         terrain.DeleteDecal(j);
8524                                                                                                                                                 }
8525                                                                                                                                         }
8526                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8527                                                                                                                                                 if(objects.model[l].type==decalstype)
8528                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8529                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8530                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8531                                                                                                                                                                 }
8532                                                                                                                                                         }
8533                                                                                                                                         }
8534                                                                                                                                 }
8535                                                                                                                                 if(!player[i].dead||musictype!=2)
8536                                                                                                                                         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)){
8537                                                                                                                                                 player[k].targetanimation=dropkickanim;
8538                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8539                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8540                                                                                                                                                                 terrain.DeleteDecal(j);
8541                                                                                                                                                         }
8542                                                                                                                                                 }
8543                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8544                                                                                                                                                         if(objects.model[l].type==decalstype)
8545                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8546                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8547                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8548                                                                                                                                                                         }
8549                                                                                                                                                                 }
8550                                                                                                                                                 }
8551                                                                                                                                         }
8552                                                                                                                         }
8553                                                                                                                         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)){
8554                                                                                                                                 oldattackkey=1;
8555                                                                                                                                 player[k].targetframe=0;
8556                                                                                                                                 player[k].target=0;
8557                                                                                                                                 //player[k].velocity=0;
8558
8559                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8560                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8561                                                                                                                                         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;
8562                                                                                                                                 }
8563                                                                                                                                 Normalise(&rotatetarget);
8564                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8565                                                                                                                                 player[k].targetrotation*=360/6.28;
8566                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8567
8568                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8569                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8570                                                                                                                                 }
8571
8572                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8573                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8574
8575                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8576                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8577                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8578
8579                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8580                                                                                                                                         player[k].targetrotation+=30;
8581                                                                                                                                 }
8582                                                                                                                                 //player[k].targettilt2=0;
8583                                                                                                                                 //slomo=1;
8584                                                                                                                                 //slomodelay=.2;
8585                                                                                                                         }
8586                                                                                                 }
8587                                                                                         }
8588                                                                                         if(!player[k].hasvictim){
8589                                                                                                 for(i=0;i<numplayers;i++){
8590                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8591                                                                                                                 player[k].victim=&player[i];
8592                                                                                                                 player[k].hasvictim=1;
8593                                                                                                         }
8594                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8595                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8596                                                                                                                         player[k].victim=&player[i];
8597                                                                                                                 }
8598                                                                                                 }
8599                                                                                         }
8600                                                                                         if(player[k].aitype==playercontrolled)
8601                                                                                                 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)){
8602                                                                                                         oldattackkey=1;
8603                                                                                                         player[k].targetanimation=rabbitkickanim;
8604                                                                                                         player[k].targetframe=0;
8605                                                                                                         player[k].target=0;
8606                                                                                                 }
8607                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8608                                                                                                         numattacks++;
8609                                                                                                         bool armedstaff=0;
8610                                                                                                         if(player[k].weaponactive!=-1){
8611                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8612                                                                                                         }
8613                                                                                                         bool armedsword=0;
8614                                                                                                         if(player[k].weaponactive!=-1){
8615                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8616                                                                                                         }
8617                                                                                                         bool armedknife=0;
8618                                                                                                         if(player[k].weaponactive!=-1){
8619                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8620                                                                                                         }
8621                                                                                                         if(armedstaff)numstaffattack++;
8622                                                                                                         else if(armedsword)numswordattack++;
8623                                                                                                         else if(armedknife)numknifeattack++;
8624                                                                                                         else numunarmedattack++;
8625                                                                                                 }
8626                                                                 }
8627                                                         }
8628                                                 }
8629
8630                                                 //Collisions
8631                                                 static float collisionradius;
8632                                                 if(numplayers>1)
8633                                                         for(k=0;k<numplayers;k++){
8634                                                                 for(i=k;i<numplayers;i++){
8635                                                                         if(i==k)i++;
8636                                                                         if(i<numplayers)
8637                                                                                 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))
8638                                                                                         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))
8639                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8640                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8641                                                                                                                 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)
8642                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8643                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8644                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8645                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8646                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8647                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8648                                                                                                                                                                         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)){
8649                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8650                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8651                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8652                                                                                                                                                                                 }
8653                                                                                                                                                                         }
8654
8655                                                                                                                                                                         tempcoords1=player[i].coords;
8656                                                                                                                                                                         tempcoords2=player[k].coords;
8657                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8658                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8659                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8660                                                                                                                                                                         if(player[0].hasvictim)
8661                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8662                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8663                                                                                                                                                                                 if(k==0)
8664                                                                                                                                                                                         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)){
8665                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8666                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8667                                                                                                                                                                                                 player[i].skeleton.free=0;
8668                                                                                                                                                                                                 player[i].rotation=0;
8669                                                                                                                                                                                                 player[i].RagDoll(0);
8670                                                                                                                                                                                                 player[i].DoDamage(20);
8671                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8672                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8673                                                                                                                                                                                                 player[k].lastcollide=1;
8674                                                                                                                                                                                         }
8675                                                                                                                                                                                         if(i==0)
8676                                                                                                                                                                                                 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)){
8677                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8678                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8679                                                                                                                                                                                                         player[k].skeleton.free=0;
8680                                                                                                                                                                                                         player[k].rotation=0;
8681                                                                                                                                                                                                         player[k].RagDoll(0);
8682                                                                                                                                                                                                         player[k].DoDamage(20);
8683                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8684                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8685                                                                                                                                                                                                         player[i].lastcollide=1;
8686                                                                                                                                                                                                 }
8687
8688                                                                                                                                                                                                 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)){
8689                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8690                                                                                                                                                                                                         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))
8691                                                                                                                                                                                                                 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))){
8692                                                                                                                                                                                                                         //If hit by body
8693                                                                                                                                                                                                                         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)){
8694                                                                                                                                                                                                                                 static float gLoc[3];
8695                                                                                                                                                                                                                                 static float vel[3];
8696                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8697                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8698                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8699                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8700                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8701                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8702                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8703                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8704                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8705                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8706                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8707                                                                                                                                                                                                                                 }
8708                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8709                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8710
8711                                                                                                                                                                                                                                 player[i].RagDoll(0);
8712                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8713                                                                                                                                                                                                                                         bonus=aimbonus;
8714                                                                                                                                                                                                                                         bonustime=0;
8715                                                                                                                                                                                                                                         bonusvalue=150;
8716                                                                                                                                                                                                                                 }
8717                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8718                                                                                                                                                                                                                                 player[k].RagDoll(0);
8719                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8720                                                                                                                                                                                                                                         bonus=aimbonus;
8721                                                                                                                                                                                                                                         bonustime=0;
8722                                                                                                                                                                                                                                         bonusvalue=150;
8723                                                                                                                                                                                                                                 }
8724                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8725
8726                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8727                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8728                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8729                                                                                                                                                                                                                                 }
8730                                                                                                                                                                                                                                 //}
8731                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8732                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8733                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8734                                                                                                                                                                                                                                 }
8735                                                                                                                                                                                                                                 //}
8736
8737                                                                                                                                                                                                                         }
8738                                                                                                                                                                                                                 }
8739                                                                                                                                                                                                                 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)){
8740                                                                                                                                                                                                                         //If bumped
8741                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8742                                                                                                                                                                                                                                 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)){
8743                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8744                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8745                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8746                                                                                                                                                                                                                                         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);
8747                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8748                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8749                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8750                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8751                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8752                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8753                                                                                                                                                                                                                                                                 player[k].target=0;
8754                                                                                                                                                                                                                                                         }
8755                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8756                                                                                                                                                                                                                                                         {
8757                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8758                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8759                                                                                                                                                                                                                                                                 player[k].target=0;
8760                                                                                                                                                                                                                                                         }
8761                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8762                                                                                                                                                                                                                                                 }
8763                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8764                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8765                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8766                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8767                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8768                                                                                                                                                                                                                                                                         player[i].target=0;
8769                                                                                                                                                                                                                                                                 }
8770                                                                                                                                                                                                                                                                 else
8771                                                                                                                                                                                                                                                                 {
8772                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8773                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8774                                                                                                                                                                                                                                                                         player[i].target=0;
8775                                                                                                                                                                                                                                                                 }
8776                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8777                                                                                                                                                                                                                                                         }
8778                                                                                                                                                                                                                                 }
8779                                                                                                                                                                                                                                 if(hostile){
8780                                                                                                                                                                                                                                         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){
8781                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8782                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8783                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8784                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8785                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8786                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8787                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8788                                                                                                                                                                                                                                                 if(k==0){
8789                                                                                                                                                                                                                                                         bonus=AboveBonus;
8790                                                                                                                                                                                                                                                         bonustime=0;
8791                                                                                                                                                                                                                                                         bonusvalue=50;
8792                                                                                                                                                                                                                                                 }
8793                                                                                                                                                                                                                                         }
8794                                                                                                                                                                                                                                         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){
8795                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8796                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8797                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8798                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8799                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8800                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8801                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8802                                                                                                                                                                                                                                                 if(i==0){
8803                                                                                                                                                                                                                                                         bonus=AboveBonus;
8804                                                                                                                                                                                                                                                         bonustime=0;
8805                                                                                                                                                                                                                                                         bonusvalue=50;
8806                                                                                                                                                                                                                                                 }
8807                                                                                                                                                                                                                                         }
8808                                                                                                                                                                                                                                 }
8809                                                                                                                                                                                                                         }
8810                                                                                                                                                                                                                 }
8811                                                                                                                                                                                                 }
8812                                                                                                                                                                                                 player[i].CheckKick();
8813                                                                                                                                                                                                 player[k].CheckKick();
8814                                                                                                                                                                         }
8815                                                                                                                                                                 }
8816                                                                 }
8817                                                         }
8818
8819                                                         for(k=0;k<numplayers;k++){
8820                                                                 for(i=k;i<numplayers;i++){
8821                                                                         if(i==k)i++;
8822                                                                         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))){
8823                                                                                 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)){
8824                                                                                         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)){
8825                                                                                                 player[i].victim=&player[k];
8826                                                                                                 player[i].targetanimation=jumpreversedanim;
8827                                                                                                 player[i].currentanimation=jumpreversedanim;
8828                                                                                                 player[k].currentanimation=jumpreversalanim;
8829                                                                                                 player[k].targetanimation=jumpreversalanim;
8830                                                                                                 player[i].targettilt2=0;
8831                                                                                                 player[i].currentframe=0;
8832                                                                                                 player[i].targetframe=1;
8833                                                                                                 player[k].currentframe=0;
8834                                                                                                 player[k].targetframe=1;
8835                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8836                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8837                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8838                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8839                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8840                                                                                                         player[k].currentframe=1;
8841                                                                                                         player[k].targetframe=2;
8842                                                                                                         player[i].currentframe=1;
8843                                                                                                         player[i].targetframe=2;
8844                                                                                                 }
8845                                                                                                 player[k].targettilt2=0;
8846                                                                                                 player[i].target=0;
8847                                                                                                 player[i].velocity=0;
8848                                                                                                 player[k].velocity=0;
8849                                                                                                 player[k].oldcoords=player[k].coords;
8850                                                                                                 player[i].coords=player[k].coords;
8851                                                                                                 player[k].targetrotation=player[i].targetrotation;
8852                                                                                                 player[k].rotation=player[i].targetrotation;
8853                                                                                                 player[k].victim=&player[i];
8854                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8855                                                                                         }
8856                                                                                         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)){
8857                                                                                                 player[k].victim=&player[i];
8858                                                                                                 player[k].targetanimation=jumpreversedanim;
8859                                                                                                 player[k].currentanimation=jumpreversedanim;
8860                                                                                                 player[i].currentanimation=jumpreversalanim;
8861                                                                                                 player[i].targetanimation=jumpreversalanim;
8862                                                                                                 player[k].targettilt2=0;
8863                                                                                                 player[i].targettilt2=0;
8864                                                                                                 player[k].currentframe=0;
8865                                                                                                 player[k].targetframe=1;
8866                                                                                                 player[i].currentframe=0;
8867                                                                                                 player[i].targetframe=1;
8868                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8869                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8870                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8871                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8872                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8873                                                                                                         player[k].currentframe=1;
8874                                                                                                         player[k].targetframe=2;
8875                                                                                                         player[i].currentframe=1;
8876                                                                                                         player[i].targetframe=2;
8877                                                                                                 }
8878                                                                                                 player[k].target=0;
8879                                                                                                 player[k].velocity=0;
8880                                                                                                 player[i].velocity=0;
8881                                                                                                 player[i].oldcoords=player[i].coords;
8882                                                                                                 player[k].coords=player[i].coords;
8883                                                                                                 player[i].targetrotation=player[k].targetrotation;
8884                                                                                                 player[i].rotation=player[k].targetrotation;
8885                                                                                                 player[i].victim=&player[k];
8886                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8887                                                                                         }
8888                                                                                 }
8889                                                                         }
8890                                                                 }
8891                                                         }
8892
8893                                                         for(k=0;k<numplayers;k++)
8894                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8895
8896
8897                                                         //pile
8898                                                         /*
8899                                                         XYZ tempdiff;
8900                                                         XYZ tempoldpos;
8901                                                         XYZ temp1,temp2;
8902                                                         bool isgood;
8903                                                         static float checkdelay;
8904                                                         checkdelay-=multiplier;
8905                                                         int m;
8906                                                         static bool checkedcoll[maxplayers][maxplayers];
8907                                                         static bool above[maxplayers];
8908
8909                                                         for(i=0;i<maxplayers;i++){
8910                                                         for(j=0;j<maxplayers;j++){
8911                                                         checkedcoll[i][j]=0;
8912                                                         }
8913                                                         }
8914
8915                                                         if(numplayers>1&&checkdelay<=0){
8916                                                         checkdelay=.015;
8917                                                         for(k=0;k<numplayers;k++){
8918                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8919
8920                                                         for(i=k;i<numplayers;i++){
8921                                                         if(i==k)i++;
8922                                                         if(i<numplayers)
8923                                                         if(!checkedcoll[i][k]){
8924                                                         checkedcoll[i][k]=1;
8925                                                         checkedcoll[k][i]=1;
8926                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8927                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8928                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8929                                                         if(player[i].coords.y>player[k].coords.y-3)
8930                                                         if(player[i].coords.y<player[k].coords.y+3)
8931                                                         if(player[i].coords.x>player[k].coords.x-3)
8932                                                         if(player[i].coords.x<player[k].coords.x+3)
8933                                                         if(player[i].coords.z>player[k].coords.z-3)
8934                                                         if(player[i].coords.z<player[k].coords.z+3)
8935                                                         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)){
8936                                                         int stuck,moving;
8937                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8938                                                         stuck=i;
8939                                                         moving=k;
8940                                                         }
8941                                                         else
8942                                                         {
8943                                                         moving=i;
8944                                                         stuck=k;
8945                                                         }
8946                                                         isgood=1;
8947
8948                                                         if(isgood){
8949                                                         above[moving]=stuck;
8950                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8951                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8952                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8953                                                         {
8954                                                         player[moving].skeleton.joints[l].position.y+=.003;
8955                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8956
8957                                                         }
8958                                                         }
8959                                                         }
8960                                                         }
8961                                                         }
8962                                                         }
8963                                                         }
8964                                                         }
8965                                                         }
8966
8967                                                         */
8968
8969                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8970                                                                 texturesizetogglekeydown=0;
8971                                                         }
8972
8973                                                         for(k=0;k<numplayers;k++){
8974                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8975                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8976                                                                                 player[k].DoDamage(1000);
8977                                                                         }
8978                                                                 }
8979                                                         }
8980
8981                                                         static bool respawnkeydown;
8982                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8983                                                                 targetlevel=whichlevel;
8984                                                                 loading=1;
8985                                                                 leveltime=5;
8986                                                         }
8987                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8988                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8989
8990
8991
8992
8993                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8994                                                                 targetlevel++;
8995                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8996                                                                 loading=1;
8997                                                                 leveltime=5;
8998                                                                 slomotogglekeydown=1;
8999                                                         }
9000
9001                                                         /*
9002                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
9003                                                         //Respawn
9004                                                         OPENAL_SetPaused(channels[whooshsound], true);
9005                                                         changedelay=0;
9006                                                         for(k=0;k<numplayers;k++){
9007                                                         player[k].dead=0;
9008                                                         player[k].damage=0;
9009                                                         player[k].permanentdamage=0;
9010                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
9011                                                         player[k].aitype=passivetype;
9012                                                         }
9013                                                         player[0].aitype=playercontrolled;
9014                                                         }
9015                                                         */
9016
9017                                                         static bool movekey;
9018                                                         static bool connected;
9019                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
9020                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
9021                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
9022                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
9023                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
9024                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
9025
9026                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
9027
9028                 for(int i=0;i<numplayers;i++){
9029                                                                 if(!player[i].skeleton.free){
9030                                                                         oldtargetrotation=player[i].targetrotation;
9031                                                                         if(i==0&&indialogue==-1){
9032                                                                                 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){
9033                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9034                                                                                         if(cameramode)player[0].targetrotation=0;
9035                                                                                 }
9036
9037                                                                                 facing=0;
9038                                                                                 facing.z=-1;
9039
9040                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9041                                                                                 if(cameramode){facing=flatfacing;}
9042                                                                                 else{
9043                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9044                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9045                                                                                 }
9046
9047                                                                                 player[0].lookrotation=-rotation;
9048
9049                                                                                 player[i].targetheadrotation=rotation;
9050                                                                                 player[i].targetheadrotation2=rotation2;
9051                                                                         }
9052                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9053                                                                                 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){
9054                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9055                                                                                 }
9056
9057                                                                                 facing=0;
9058                                                                                 facing.z=-1;
9059
9060                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9061
9062                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9063                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9064
9065                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9066                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
9067                                                                         }
9068                                                                         if(indialogue!=-1){
9069                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9070                                                                                 Normalise(&rotatetarget);
9071                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9072                                                                                 player[i].targetheadrotation*=360/6.28;
9073                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9074
9075                                                                                 player[i].targetheadrotation*=-1;
9076                                                                                 player[i].targetheadrotation+=180;
9077                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9078                                                                         }
9079
9080                                                                         bool pause;
9081
9082                                                                         if(leveltime<.5)
9083                                                                                 numenvsounds=0;
9084
9085                                                                         player[i].avoidsomething=0;
9086
9087                                                                         for(j=0;j<objects.numobjects;j++){
9088                                                                                 if(objects.onfire[j]){
9089                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9090                                                                                         {
9091                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9092                                                                                                         player[i].collided=0;
9093                                                                                                         player[i].avoidcollided=1;
9094                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9095                                                                                                                 player[i].avoidwhere=objects.position[j];
9096                                                                                                 }
9097                                                                                         }
9098                                                                                 }
9099                                                                         }
9100
9101                                                                         //Add avoidwhere to players
9102
9103                                                                         for(j=0;j<numplayers;j++){
9104                                                                                 if(player[j].onfire){
9105                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9106                                                                                         {
9107                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9108                                                                                                         player[i].collided=0;
9109                                                                                                         player[i].avoidcollided=1;
9110                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9111                                                                                                                 player[i].avoidwhere=objects.position[j];
9112                                                                                                 }
9113                                                                                         }
9114                                                                                 }
9115                                                                         }
9116
9117                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9118                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9119                                                                                 player[i].jumpclimb=0;
9120                                                                                 //AI
9121                                                                                 if(editorenabled)player[i].stunned=1;
9122
9123                                                                                 player[i].pause=0;
9124                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9125                                                                                 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;
9126
9127                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9128                                                                                 player[i].forwardkeydown=0;
9129                                                                                 player[i].leftkeydown=0;
9130                                                                                 player[i].backkeydown=0;
9131                                                                                 player[i].rightkeydown=0;
9132                                                                                 player[i].crouchkeydown=0;
9133                                                                                 player[i].attackkeydown=0;
9134                                                                                 player[i].jumpkeydown=0;
9135                                                                                 player[i].throwkeydown=0;
9136                                                                                 }*/
9137
9138                                                                                 if(player[i].aitype==pathfindtype){
9139                                                                                         if(player[i].finalpathfindpoint==-1){
9140                                                                                                 float closestdistance;
9141                                                                                                 float tempdist;
9142                                                                                                 int closest;
9143                                                                                                 XYZ colpoint;
9144                                                                                                 closest=-1;
9145                                                                                                 closestdistance=-1;
9146                                                                                                 for(j=0;j<numpathpoints;j++){
9147                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9148                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9149                                                                                                                 closest=j;
9150                                                                                                                 player[i].finaltarget=pathpoint[j];
9151                                                                                                         }
9152                                                                                                 }
9153                                                                                                 player[i].finalpathfindpoint=closest;
9154                                                                                                 for(j=0;j<numpathpoints;j++){
9155                                                                                                         if(numpathpointconnect[j])
9156                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9157                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9158                                                                                                                         if(tempdist*tempdist<closestdistance){
9159                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9160                                                                                                                                         closestdistance=tempdist*tempdist;
9161                                                                                                                                         closest=j;
9162                                                                                                                                         player[i].finaltarget=colpoint;
9163                                                                                                                                 }
9164                                                                                                                         }
9165                                                                                                                 }
9166                                                                                                 }
9167                                                                                                 player[i].finalpathfindpoint=closest;
9168
9169                                                                                         }
9170                                                                                         if(player[i].targetpathfindpoint==-1){
9171                                                                                                 float closestdistance;
9172                                                                                                 float tempdist;
9173                                                                                                 int closest;
9174                                                                                                 XYZ colpoint;
9175                                                                                                 closest=-1;
9176                                                                                                 closestdistance=-1;
9177                                                                                                 if(player[i].lastpathfindpoint==-1){
9178                                                                                                         for(j=0;j<numpathpoints;j++){
9179                                                                                                                 if(j!=player[i].lastpathfindpoint)
9180                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9181                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9182                                                                                                                                 closest=j;
9183                                                                                                                         }
9184                                                                                                         }
9185                                                                                                         player[i].targetpathfindpoint=closest;
9186                                                                                                         for(j=0;j<numpathpoints;j++){
9187                                                                                                                 if(j!=player[i].lastpathfindpoint)
9188                                                                                                                         if(numpathpointconnect[j])
9189                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9190                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9191                                                                                                                                         if(tempdist*tempdist<closestdistance){
9192                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9193                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9194                                                                                                                                                         closestdistance=tempdist*tempdist;
9195                                                                                                                                                         closest=j;
9196                                                                                                                                                         //}
9197                                                                                                                                                 }
9198                                                                                                                                         }
9199                                                                                                                                 }
9200                                                                                                         }
9201                                                                                                         player[i].targetpathfindpoint=closest;
9202                                                                                                 }
9203                                                                                                 else
9204                                                                                                 {
9205                                                                                                         for(j=0;j<numpathpoints;j++){
9206                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9207                                                                                                                 {
9208                                                                                                                         connected=0;
9209                                                                                                                         if(numpathpointconnect[j])
9210                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9211                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9212                                                                                                                                 }
9213                                                                                                                                 if(!connected)
9214                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9215                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9216                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9217                                                                                                                                                 }
9218                                                                                                                                                 if(connected){
9219                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9220                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9221                                                                                                                                                                 closestdistance=tempdist;
9222                                                                                                                                                                 closest=j;
9223                                                                                                                                                         }
9224                                                                                                                                                 }
9225                                                                                                                 }
9226                                                                                                         }
9227                                                                                                         player[i].targetpathfindpoint=closest;
9228                                                                                                 }
9229                                                                                         }
9230                                                                                         player[i].losupdatedelay-=multiplier;
9231
9232                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9233                                                                                         Normalise(&rotatetarget);
9234                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9235                                                                                         player[i].targetrotation*=360/6.28;
9236                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9237                                                                                         player[i].lookrotation=player[i].targetrotation;
9238                                                                                         //player[i].aiupdatedelay=.05;
9239
9240                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9241                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9242                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9243                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9244                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9245                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9246                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9247                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9248                                                                                                 player[i].targetpathfindpoint=-1;
9249                                                                                         }
9250                                                                                         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){
9251                                                                                                 player[i].aitype=passivetype;
9252                                                                                         }
9253
9254                                                                                         player[i].forwardkeydown=1;
9255                                                                                         player[i].leftkeydown=0;
9256                                                                                         player[i].backkeydown=0;
9257                                                                                         player[i].rightkeydown=0;
9258                                                                                         player[i].crouchkeydown=0;
9259                                                                                         player[i].attackkeydown=0;
9260                                                                                         player[i].throwkeydown=0;
9261
9262                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9263
9264                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9265                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9266
9267                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9268                                                                                                 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))
9269                                                                                                         player[i].aitype=attacktypecutoff;
9270                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9271                                                                                                         player[i].aitype=attacktypecutoff;
9272
9273                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9274                                                                                                         player[i].losupdatedelay=.2;
9275                                                                                                         for(j=0;j<numplayers;j++){
9276                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9277                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9278                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9279                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9280                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9281                                                                                                                                                         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)){
9282                                                                                                                                                                 player[i].aitype=searchtype;
9283                                                                                                                                                                 player[i].lastchecktime=12;
9284                                                                                                                                                                 player[i].lastseen=player[j].coords;
9285                                                                                                                                                                 player[i].lastseentime=12;
9286                                                                                                                                                         }
9287                                                                                                                 }
9288                                                                                                         }
9289                                                                                                 }
9290                                                                                         }
9291                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9292                                                                                                 if(player[i].creature!=wolftype){
9293                                                                                                         player[i].stunned=.6;
9294                                                                                                         player[i].surprised=.6;
9295                                                                                                 }
9296                                                                                         }
9297                                                                                 }
9298
9299                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9300                                                                                         player[i].howactive=typeactive;
9301                                                                                 }
9302
9303                                                                                 if(player[i].aitype==passivetype){
9304                                                                                         player[i].aiupdatedelay-=multiplier;
9305                                                                                         player[i].losupdatedelay-=multiplier;
9306                                                                                         player[i].lastseentime+=multiplier;
9307                                                                                         player[i].pausetime-=multiplier;
9308                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9309
9310                                                                                         if(player[i].aiupdatedelay<0){
9311                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9312                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9313                                                                                                         Normalise(&rotatetarget);
9314                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9315                                                                                                         player[i].targetrotation*=360/6.28;
9316                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9317                                                                                                         player[i].lookrotation=player[i].targetrotation;
9318                                                                                                         player[i].aiupdatedelay=.05;
9319
9320                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9321                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9322                                                                                                                 player[i].waypoint++;
9323                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9324
9325                                                                                                         }
9326                                                                                                 }
9327
9328                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9329                                                                                                 else player[i].forwardkeydown=0;
9330                                                                                                 player[i].leftkeydown=0;
9331                                                                                                 player[i].backkeydown=0;
9332                                                                                                 player[i].rightkeydown=0;
9333                                                                                                 player[i].crouchkeydown=0;
9334                                                                                                 player[i].attackkeydown=0;
9335                                                                                                 player[i].throwkeydown=0;
9336
9337                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9338                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9339                                                                                                         else{
9340                                                                                                                 XYZ leftpos,rightpos;
9341                                                                                                                 float leftdist,rightdist;
9342                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9343                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9344                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9345                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9346                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9347                                                                                                                 else player[i].targetrotation-=90;
9348                                                                                                         }
9349                                                                                                 }
9350                                                                                         }
9351                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9352                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9353
9354
9355                                                                                         if(!editorenabled){
9356                                                                                                 if(player[i].howactive<typesleeping)
9357                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9358                                                                                                                 for(j=0;j<numenvsounds;j++){
9359                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9360                                                                                                                                 player[i].aitype=attacktypecutoff;
9361                                                                                                                         }
9362                                                                                                                 }
9363
9364                                                                                                                 if(player[i].howactive==typesleeping)
9365                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9366                                                                                                                                 for(j=0;j<numenvsounds;j++){
9367                                                                                                                                         if(envsoundvol[j]>14)
9368                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9369                                                                                                                                                         player[i].aitype=attacktypecutoff;
9370                                                                                                                                                 }
9371                                                                                                                                 }
9372
9373                                                                                                                                 if(player[i].aitype!=passivetype){
9374                                                                                                                                         if(player[i].howactive==typesleeping){
9375                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9376                                                                                                                                                 player[i].targetframe=0;
9377                                                                                                                                                 player[i].target=0;
9378                                                                                                                                         }
9379
9380                                                                                                                                         player[i].howactive=typeactive;
9381                                                                                                                                 }
9382                                                                                         }
9383
9384                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9385                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9386                                                                                                         player[i].aitype=attacktypecutoff;
9387                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9388                                                                                                         player[i].aitype=attacktypecutoff;
9389
9390                                                                                                 if(player[i].creature==wolftype){
9391                                                                                                         XYZ windsmell;
9392                                                                                                         float smelldistance;
9393                                                                                                         smelldistance=50;
9394                                                                                                         for(j=0;j<numplayers;j++){
9395                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9396                                                                                                                         if(j==0&&player[j].num_weapons>0){
9397                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9398                                                                                                                                 if(player[j].num_weapons==2)
9399                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9400                                                                                                                         }
9401                                                                                                                         if(j!=0){
9402                                                                                                                                 smelldistance=100;
9403                                                                                                                         }
9404                                                                                                                         windsmell=windvector;
9405                                                                                                                         Normalise(&windsmell);
9406                                                                                                                         windsmell=windsmell*2+player[j].coords;
9407                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9408                                                                                                                                 player[i].aitype=attacktypecutoff;
9409                                                                                                                 }
9410                                                                                                         }
9411                                                                                                 }
9412
9413                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9414                                                                                                         player[i].losupdatedelay=.2;
9415                                                                                                         for(j=0;j<numplayers;j++){
9416                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9417                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9418                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9419                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9420                                                                                                                                                 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)){
9421                                                                                                                                                         player[i].lastseentime-=.2;
9422                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9423                                                                                                                                                         else player[i].lastseentime-=.6;
9424                                                                                                                                                 }
9425                                                                                                                                                 if(player[i].lastseentime<=0){
9426                                                                                                                                                         player[i].aitype=searchtype;
9427                                                                                                                                                         player[i].lastchecktime=12;
9428                                                                                                                                                         player[i].lastseen=player[j].coords;
9429                                                                                                                                                         player[i].lastseentime=12;
9430                                                                                                                                                 }
9431                                                                                                                 }
9432                                                                                                         }
9433                                                                                                 }
9434                                                                                         }
9435                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9436                                                                                                 if(player[i].creature!=wolftype){
9437                                                                                                         player[i].stunned=.6;
9438                                                                                                         player[i].surprised=.6;
9439                                                                                                 }
9440                                                                                                 if(player[i].creature==wolftype){
9441                                                                                                         player[i].stunned=.47;
9442                                                                                                         player[i].surprised=.47;
9443                                                                                                 }
9444                                                                                                 numseen++;
9445                                                                                         }
9446                                                                                 }
9447
9448                                                                                 if(player[i].aitype==searchtype){
9449                                                                                         player[i].aiupdatedelay-=multiplier;
9450                                                                                         player[i].losupdatedelay-=multiplier;
9451                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9452                                                                                         player[i].lastchecktime-=multiplier;
9453
9454                                                                                         if(player[i].isRun()&&!player[i].onground){
9455                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9456                                                                                                         test2=player[i].coords+player[i].facing;
9457                                                                                                         test2.y+=5;
9458                                                                                                         test=player[i].coords+player[i].facing;
9459                                                                                                         test.y-=10;
9460                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9461                                                                                                         if(j==-1)j=checkcollide(test2,test);
9462                                                                                                         if(j==-1){
9463                                                                                                                 player[i].velocity=0;
9464                                                                                                                 player[i].targetanimation=player[i].getStop();
9465                                                                                                                 player[i].targetframe=0;
9466                                                                                                                 player[i].target=0;
9467                                                                                                                 player[i].targetrotation+=180;
9468                                                                                                                 player[i].stunned=.5;
9469                                                                                                                 //player[i].aitype=passivetype;
9470                                                                                                                 player[i].aitype=pathfindtype;
9471                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9472                                                                                                                 player[i].finalpathfindpoint=-1;
9473                                                                                                                 player[i].targetpathfindpoint=-1;
9474                                                                                                                 player[i].lastpathfindpoint=-1;
9475                                                                                                                 player[i].lastpathfindpoint2=-1;
9476                                                                                                                 player[i].lastpathfindpoint3=-1;
9477                                                                                                                 player[i].lastpathfindpoint4=-1;
9478                                                                                                         }
9479                                                                                                         else player[i].laststanding=j;
9480                                                                                                 }
9481                                                                                         }
9482                                                                                         if(player[i].aiupdatedelay<0){
9483                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9484                                                                                                 Normalise(&rotatetarget);
9485                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9486                                                                                                 player[i].targetrotation*=360/6.28;
9487                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9488                                                                                                 player[i].lookrotation=player[i].targetrotation;
9489                                                                                                 player[i].aiupdatedelay=.05;
9490                                                                                                 player[i].forwardkeydown=1;
9491
9492                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9493                                                                                                         player[i].forwardkeydown=0;
9494                                                                                                         player[i].aiupdatedelay=1;
9495                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9496                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9497                                                                                                         player[i].lastchecktime=3;
9498                                                                                                 }
9499
9500                                                                                                 player[i].leftkeydown=0;
9501                                                                                                 player[i].backkeydown=0;
9502                                                                                                 player[i].rightkeydown=0;
9503                                                                                                 player[i].crouchkeydown=0;
9504                                                                                                 player[i].attackkeydown=0;
9505                                                                                                 player[i].throwkeydown=0;
9506
9507                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9508                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9509                                                                                                         else{
9510                                                                                                                 XYZ leftpos,rightpos;
9511                                                                                                                 float leftdist,rightdist;
9512                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9513                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9514                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9515                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9516                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9517                                                                                                                 else player[i].targetrotation-=90;
9518                                                                                                         }
9519                                                                                                 }
9520                                                                                         }
9521                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9522                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9523
9524                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9525                                                                                                 for(j=0;j<numenvsounds;j++){
9526                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9527                                                                                                                 player[i].aitype=attacktypecutoff;
9528                                                                                                         }
9529                                                                                                 }
9530
9531                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9532                                                                                                         player[i].losupdatedelay=.2;
9533                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9534                                                                                                         {player[i].aitype=attacktypecutoff;
9535                                                                                                         player[i].lastseentime=1;}
9536                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9537                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9538                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9539                                                                                                                                 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)){
9540                                                                                                                                         player[i].aitype=attacktypecutoff;
9541                                                                                                                                         player[i].lastseentime=1;
9542                                                                                                                                 }
9543                                                                                                 }
9544                                                                                                 if(player[i].lastseentime<0){
9545                                                                                                         //player[i].aitype=passivetype;
9546                                                                                                         numescaped++;
9547                                                                                                         player[i].aitype=pathfindtype;
9548                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9549                                                                                                         player[i].finalpathfindpoint=-1;
9550                                                                                                         player[i].targetpathfindpoint=-1;
9551                                                                                                         player[i].lastpathfindpoint=-1;
9552                                                                                                         player[i].lastpathfindpoint2=-1;
9553                                                                                                         player[i].lastpathfindpoint3=-1;
9554                                                                                                         player[i].lastpathfindpoint4=-1;
9555                                                                                                 }
9556                                                                                 }
9557
9558                                                                                 if(player[i].aitype!=gethelptype){
9559                                                                                         player[i].runninghowlong=0;
9560                                                                                 }
9561
9562                                                                                 if(player[i].aitype==gethelptype){
9563                                                                                         player[i].runninghowlong+=multiplier;
9564                                                                                         player[i].aiupdatedelay-=multiplier;
9565
9566                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9567                                                                                                 player[i].aiupdatedelay=.2;
9568
9569                                                                                                 int closest;
9570                                                                                                 float closestdist;
9571                                                                                                 closest=-1;
9572                                                                                                 closestdist=-1;
9573                                                                                                 float distance;
9574
9575                                                                                                 if(!player[i].ally){
9576                                                                                                         for(j=0;j<numplayers;j++){
9577                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9578                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9579                                                                                                                         if(closestdist==-1||distance<closestdist){
9580                                                                                                                                 closestdist=distance;
9581                                                                                                                                 closest=j;
9582                                                                                                                         }
9583                                                                                                                         closest=j;
9584                                                                                                                 }
9585                                                                                                         }
9586                                                                                                         if(closest!=-1)player[i].ally=closest;
9587                                                                                                         else player[i].ally=0;
9588                                                                                                         player[i].lastseen=player[0].coords;
9589                                                                                                         player[i].lastseentime=12;
9590                                                                                                 }
9591
9592
9593                                                                                                 player[i].lastchecktime=12;
9594                                                                                                 //player[i].lastseentime-=.5;
9595
9596                                                                                                 facing=player[i].coords;
9597                                                                                                 flatfacing=player[player[i].ally].coords;
9598                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9599                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9600                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9601                                                                                                         player[i].lastseentime-=.1;
9602
9603                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9604                                                                                                         player[i].aitype=searchtype;
9605                                                                                                         player[i].lastseentime=12;
9606                                                                                                 }
9607
9608                                                                                                 if(player[i].ally>0){
9609                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9610                                                                                                         Normalise(&rotatetarget);
9611                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9612                                                                                                         player[i].targetrotation*=360/6.28;
9613                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9614                                                                                                         player[i].lookrotation=player[i].targetrotation;
9615                                                                                                         player[i].aiupdatedelay=.05;
9616                                                                                                         player[i].forwardkeydown=1;
9617
9618                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9619                                                                                                                 player[i].aitype=searchtype;
9620                                                                                                                 player[i].lastseentime=12;
9621                                                                                                                 player[player[i].ally].aitype=searchtype;
9622                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9623                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9624                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9625                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9626                                                                                                                 }
9627                                                                                                         }
9628
9629                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9630                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9631                                                                                                                 else{
9632                                                                                                                         XYZ leftpos,rightpos;
9633                                                                                                                         float leftdist,rightdist;
9634                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9635                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9636                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9637                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9638                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9639                                                                                                                         else player[i].targetrotation-=90;
9640                                                                                                                 }
9641                                                                                                         }
9642                                                                                                 }
9643
9644                                                                                                 player[i].leftkeydown=0;
9645                                                                                                 player[i].backkeydown=0;
9646                                                                                                 player[i].rightkeydown=0;
9647                                                                                                 player[i].crouchkeydown=0;
9648                                                                                                 player[i].attackkeydown=0;
9649                                                                                         }
9650                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9651                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9652                                                                                 }
9653
9654                                                                                 if(player[i].aitype==getweapontype){
9655                                                                                         player[i].aiupdatedelay-=multiplier;
9656                                                                                         player[i].lastchecktime-=multiplier;
9657
9658                                                                                         if(player[i].aiupdatedelay<0){
9659                                                                                                 player[i].aiupdatedelay=.2;
9660
9661                                                                                                 int closest;
9662                                                                                                 float closestdist;
9663                                                                                                 closest=-1;
9664                                                                                                 closestdist=-1;
9665                                                                                                 float distance;
9666
9667                                                                                                 if(player[i].ally<0){
9668                                                                                                         for(j=0;j<weapons.numweapons;j++){
9669                                                                                                                 if(weapons.owner[j]==-1){
9670                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9671                                                                                                                         if(closestdist==-1||distance<closestdist){
9672                                                                                                                                 closestdist=distance;
9673                                                                                                                                 closest=j;
9674                                                                                                                         }
9675                                                                                                                         closest=j;
9676                                                                                                                 }
9677                                                                                                         }
9678                                                                                                         if(closest!=-1)player[i].ally=closest;
9679                                                                                                         else player[i].ally=-1;
9680                                                                                                 }
9681
9682                                                                                                 player[i].lastseentime=12;
9683
9684                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9685                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9686                                                                                                                 player[i].aitype=attacktypecutoff;
9687                                                                                                                 player[i].lastseentime=1;
9688                                                                                                         }
9689                                                                                                         if(!player[0].dead)
9690                                                                                                                 if(player[i].ally>=0){
9691                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9692                                                                                                                                 player[i].aitype=attacktypecutoff;
9693                                                                                                                                 player[i].lastseentime=1;
9694                                                                                                                         }
9695                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9696                                                                                                                         Normalise(&rotatetarget);
9697                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9698                                                                                                                         player[i].targetrotation*=360/6.28;
9699                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9700                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9701                                                                                                                         player[i].aiupdatedelay=.05;
9702                                                                                                                         player[i].forwardkeydown=1;
9703
9704
9705                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9706                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9707                                                                                                                                 else{
9708                                                                                                                                         XYZ leftpos,rightpos;
9709                                                                                                                                         float leftdist,rightdist;
9710                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9711                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9712                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9713                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9714                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9715                                                                                                                                         else player[i].targetrotation-=90;
9716                                                                                                                                 }
9717                                                                                                                         }
9718                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9719                                                                                                                         if(abs(Random()%6)){
9720                                                                                                                         player[i].crouchkeydown=1;
9721                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9722                                                                                                                         if(player[i].isRun()){
9723                                                                                                                         player[i].targetframe=0;
9724                                                                                                                         player[i].target=0;
9725                                                                                                                         player[i].targetanimation=sneakanim;
9726                                                                                                                         }
9727                                                                                                                         }
9728                                                                                                                         else player[i].forwardkeydown=0;
9729                                                                                                                         }
9730                                                                                                                         else player[i].crouchkeydown=0;
9731                                                                                                                         }
9732                                                                                                                         else player[i].crouchkeydown=0;*/
9733                                                                                                                 }
9734
9735                                                                                                                 player[i].leftkeydown=0;
9736                                                                                                                 player[i].backkeydown=0;
9737                                                                                                                 player[i].rightkeydown=0;
9738                                                                                                                 player[i].attackkeydown=0;
9739                                                                                                                 player[i].throwkeydown=1;
9740                                                                                                                 player[i].crouchkeydown=0;
9741                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9742                                                                                                                 player[i].drawkeydown=0;
9743                                                                                         }
9744                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9745                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9746                                                                                 }
9747
9748                                                                                 if(player[i].aitype==attacktypecutoff){
9749                                                                                         player[i].aiupdatedelay-=multiplier;
9750                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9751                                                                                                 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)){
9752                                                                                                         player[i].attackkeydown=0;
9753                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9754                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9755                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9756                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9757                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9758                                                                                                                                 else player[i].targetanimation=rollanim;
9759                                                                                                                                 player[i].target=0;
9760                                                                                                                                 player[i].targetframe=0;
9761                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9762                                                                                                                                 player[i].wentforweapon=0;
9763                                                                                                                         }
9764                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9765                                                                                                                                 player[i].targetanimation=flipanim;
9766                                                                                                                                 player[i].target=0;
9767                                                                                                                                 player[i].targetframe=0;
9768                                                                                                                         }
9769                                                                                                                 }
9770                                                                                                         }
9771                                                                                                         player[i].forwardkeydown=0;
9772                                                                                                         player[i].aiupdatedelay=.02;
9773                                                                                                 }
9774                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9775                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9776                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9777                                                                                                 }
9778                                                                                                 if(player[i].wentforweapon<3)
9779                                                                                                         for(j=0;j<weapons.numweapons;j++){
9780                                                                                                                 if(player[i].creature!=wolftype)
9781                                                                                                                         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){
9782                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9783                                                                                                                                         player[i].wentforweapon++;
9784                                                                                                                                         player[i].lastchecktime=6;
9785                                                                                                                                         player[i].aitype=getweapontype;
9786                                                                                                                                         player[i].ally=-1;
9787                                                                                                                                 }
9788                                                                                                                         }
9789                                                                                                         }
9790                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9791                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9792                                                                                                                         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)))){
9793                                                                                                                                 player[i].crouchkeydown=1;
9794                                                                                                                         }
9795                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9796                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9797                                                                                                                                         test2=player[i].coords+player[i].facing;
9798                                                                                                                                         test2.y+=5;
9799                                                                                                                                         test=player[i].coords+player[i].facing;
9800                                                                                                                                         test.y-=10;
9801                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9802                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9803                                                                                                                                         if(j==-1){
9804                                                                                                                                                 player[i].velocity=0;
9805                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9806                                                                                                                                                 player[i].targetframe=0;
9807                                                                                                                                                 player[i].target=0;
9808                                                                                                                                                 player[i].targetrotation+=180;
9809                                                                                                                                                 player[i].stunned=.5;
9810                                                                                                                                                 //player[i].aitype=passivetype;
9811                                                                                                                                                 player[i].aitype=pathfindtype;
9812                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9813                                                                                                                                                 player[i].finalpathfindpoint=-1;
9814                                                                                                                                                 player[i].targetpathfindpoint=-1;
9815                                                                                                                                                 player[i].lastpathfindpoint=-1;
9816                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9817                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9818                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9819                                                                                                                                         }
9820                                                                                                                                         else player[i].laststanding=j;
9821                                                                                                                                 }
9822                                                                                                                         }
9823                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9824                                                                                                                                 player[i].aitype=pathfindtype;
9825                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9826                                                                                                                                 player[i].finalpathfindpoint=-1;
9827                                                                                                                                 player[i].targetpathfindpoint=-1;
9828                                                                                                                                 player[i].lastpathfindpoint=-1;
9829                                                                                                                                 player[i].lastpathfindpoint2=-1;
9830                                                                                                                                 player[i].lastpathfindpoint3=-1;
9831                                                                                                                                 player[i].lastpathfindpoint4=-1;
9832                                                                                                                         }
9833                                                                                                                         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){
9834                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9835                                                                                                                                 else player[i].drawkeydown=0;
9836                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9837                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9838                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9839                                                                                                                                         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;
9840                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-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                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9846                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9847
9848                                                                                                                                 oldkey=player[i].forwardkeydown;
9849                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9850                                                                                                                                 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;
9851                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9852                                                                                                                                 else player[i].forwardkeydown=0;
9853                                                                                                                                 if(player[0].dead){
9854                                                                                                                                         player[i].forwardkeydown=0;
9855                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9856                                                                                                                                         if(Random()%100==0){
9857                                                                                                                                                 player[i].aitype=pathfindtype;
9858                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9859                                                                                                                                                 player[i].finalpathfindpoint=-1;
9860                                                                                                                                                 player[i].targetpathfindpoint=-1;
9861                                                                                                                                                 player[i].lastpathfindpoint=-1;
9862                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9863                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9864                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9865                                                                                                                                         }
9866                                                                                                                                 }
9867                                                                                                                                 player[i].leftkeydown=0;
9868                                                                                                                                 player[i].backkeydown=0;
9869                                                                                                                                 player[i].rightkeydown=0;
9870                                                                                                                                 player[i].crouchkeydown=0;
9871                                                                                                                                 player[i].throwkeydown=0;
9872
9873                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9874                                                                                                                                 /*for(j=0;j<numplayers;j++){
9875                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9876                                                                                                                                 player[i].crouchkeydown=1;
9877                                                                                                                                 }
9878                                                                                                                                 }*/
9879                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9880                                                                                                                                 else player[i].attackkeydown=0;
9881                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9882                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9883                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9884                                                                                                                                 player[i].attackkeydown=0;
9885                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9886                                                                                                                                 player[i].forwardkeydown=0;
9887                                                                                                                                 player[i].aiupdatedelay=.02;
9888                                                                                                                                 }*/
9889
9890                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9891                                                                                                                                         target=-2;
9892                                                                                                                                         for(j=0;j<numplayers;j++){
9893                                                                                                                                                 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)){
9894                                                                                                                                                         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))))){
9895                                                                                                                                                                 if(target>=0)target=-1;
9896                                                                                                                                                                 else target=j;
9897                                                                                                                                                         }
9898                                                                                                                                                 }
9899                                                                                                                                         }
9900                                                                                                                                         if(target>=0)player[target].Reverse();
9901                                                                                                                                 }
9902
9903                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9904                                                                                                                                 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;
9905                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9906                                                                                                                                         player[0].jumpkeydown=0;
9907                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9908                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9909                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9910
9911                                                                                                                                 if(tutoriallevel==1){
9912                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9913                                                                                                                                 }
9914
9915
9916                                                                                                                                 facing=player[i].coords;
9917                                                                                                                                 flatfacing=player[0].coords;
9918                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9919                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9920                                                                                                                                 if(player[i].occluded>=2)
9921                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9922                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9923                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9924                                                                                                                                                         player[i].aitype=searchtype;
9925                                                                                                                                                         player[i].lastchecktime=12;
9926                                                                                                                                                         player[i].lastseen=player[0].coords;
9927                                                                                                                                                         player[i].lastseentime=12;
9928                                                                                                                                                 }
9929                                                                                                                                         }
9930                                                                                                                                         else player[i].lastseentime=1;
9931                                                                                                                         }
9932                                                                                 }
9933                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9934                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9935                                                                                                 test=player[0].coords;
9936                                                                                                 test.y-=40;
9937                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9938                                                                                         }
9939                                                                                 }
9940                                                                                 // NOTE: Ask about logic of this call : NOTE
9941                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9942                                                                                         player[i].stunned>0 ||
9943                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9944                                                                                 {
9945                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9946                                                                                         player[i].targetrotation=player[i].rotation;
9947                                                                                         player[i].forwardkeydown=0;
9948                                                                                         player[i].leftkeydown=0;
9949                                                                                         player[i].backkeydown=0;
9950                                                                                         player[i].rightkeydown=0;
9951                                                                                         player[i].jumpkeydown=0;
9952                                                                                         player[i].attackkeydown=0;
9953                                                                                         player[i].crouchkeydown=0;
9954                                                                                         player[i].throwkeydown=0;
9955                                                                                 }
9956
9957
9958                                                                                 facing=0;
9959                                                                                 facing.z=-1;
9960
9961                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9962                                                                                 facing=flatfacing;
9963
9964                                                                                 if(player[i].aitype==attacktypecutoff){
9965                                                                                         rotatetarget=player[0].coords-player[i].coords;
9966                                                                                         Normalise(&rotatetarget);
9967                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9968                                                                                         player[i].targetheadrotation*=360/6.28;
9969                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9970
9971                                                                                         player[i].targetheadrotation*=-1;
9972                                                                                         player[i].targetheadrotation+=180;
9973                                                                                         //player[i].targetheadrotation2=0;
9974                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9975                                                                                 }
9976                                                                                 else if(player[i].howactive>=typesleeping){
9977                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9978                                                                                         player[i].targetheadrotation2=0;
9979                                                                                 }
9980                                                                                 else {
9981                                                                                         if(player[i].interestdelay<=0){
9982                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9983                                                                                                 player[i].headtarget=player[i].coords;
9984                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9985                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9986                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9987                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9988                                                                                         }
9989                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9990                                                                                         Normalise(&rotatetarget);
9991                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9992                                                                                         player[i].targetheadrotation*=360/6.28;
9993                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9994
9995                                                                                         player[i].targetheadrotation*=-1;
9996                                                                                         player[i].targetheadrotation+=180;
9997                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9998                                                                                 }
9999                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
10000                                                                         }
10001                                                                         if(animation[player[i].targetanimation].attack==reversed){
10002                                                                                 //player[i].targetrotation=player[i].rotation;
10003                                                                                 player[i].forwardkeydown=0;
10004                                                                                 player[i].leftkeydown=0;
10005                                                                                 player[i].backkeydown=0;
10006                                                                                 player[i].rightkeydown=0;
10007                                                                                 player[i].jumpkeydown=0;
10008                                                                                 player[i].attackkeydown=0;
10009                                                                                 //player[i].crouchkeydown=0;
10010                                                                                 player[i].throwkeydown=0;
10011                                                                         }
10012
10013                                                                         if(indialogue!=-1){
10014                                                                                 player[i].forwardkeydown=0;
10015                                                                                 player[i].leftkeydown=0;
10016                                                                                 player[i].backkeydown=0;
10017                                                                                 player[i].rightkeydown=0;
10018                                                                                 player[i].jumpkeydown=0;
10019                                                                                 player[i].crouchkeydown=0;
10020                                                                                 player[i].drawkeydown=0;
10021                                                                                 player[i].throwkeydown=0;
10022                                                                         }
10023
10024                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
10025                                                                         if(player[i].collided>1)player[i].collided=1;
10026                                                                         player[i].collided-=multiplier*4;
10027                                                                         player[i].whichdirectiondelay-=multiplier;
10028                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10029                                                                                 player[i].avoidcollided=-.3;
10030                                                                                 player[i].whichdirection=abs(Random()%2);
10031                                                                                 player[i].whichdirectiondelay=.4;
10032                                                                         }
10033                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10034                                                                         player[i].avoidcollided-=multiplier/4;
10035                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10036                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10037                                                                         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;
10038
10039                                                                         if(!player[i].throwkeydown){
10040                                                                                 player[i].throwtogglekeydown=0;
10041                                                                         }
10042                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10043                                                                                 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)){
10044                                                                                         for(j=0;j<weapons.numweapons;j++){
10045                                                                                                 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)
10046                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10047                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10048                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10049                                                                                                                                 player[i].throwtogglekeydown=1;
10050                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10051                                                                                                                                 player[i].target=0;
10052                                                                                                                                 player[i].targetframe=0;
10053                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10054                                                                                                                                 Normalise(&rotatetarget);
10055                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10056                                                                                                                                 player[i].targetrotation*=360/6.28;
10057                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10058                                                                                                                                 player[i].hasvictim=0;
10059                                                                                                                         }
10060                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10061                                                                                                                                 player[i].throwtogglekeydown=1;
10062                                                                                                                                 player[i].hasvictim=0;
10063
10064                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10065                                                                                                                                 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))
10066                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10067                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10068                                                                                                                                                         float gLoc[3];
10069                                                                                                                                                         float vel[3];
10070                                                                                                                                                         gLoc[0]=player[i].coords.x;
10071                                                                                                                                                         gLoc[1]=player[i].coords.y;
10072                                                                                                                                                         gLoc[2]=player[i].coords.z;
10073                                                                                                                                                         vel[0]=player[i].velocity.x;
10074                                                                                                                                                         vel[1]=player[i].velocity.y;
10075                                                                                                                                                         vel[2]=player[i].velocity.z;
10076                                                                                                                                                         if(weapons.type[j]!=staff){
10077                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10078                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10079                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
10080                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
10081                                                                                                                                                         }
10082
10083                                                                                                                                                         player[i].weaponactive=0;
10084                                                                                                                                                         weapons.owner[j]=player[i].id;
10085                                                                                                                                                         if(player[i].num_weapons>0){
10086                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10087                                                                                                                                                         }
10088                                                                                                                                                         player[i].num_weapons++;
10089                                                                                                                                                         player[i].weaponids[0]=j;
10090                                                                                                                                                 }
10091                                                                                                                                         }
10092                                                                                                                                         //}
10093                                                                                                                         }
10094                                                                                                                 }
10095                                                                                                                 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){
10096                                                                                                                         if(!player[i].isFlip()){
10097                                                                                                                                 player[i].throwtogglekeydown=1;
10098                                                                                                                                 player[i].targetanimation=removeknifeanim;
10099                                                                                                                                 player[i].target=0;
10100                                                                                                                                 player[i].targetframe=0;
10101                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10102                                                                                                                                 Normalise(&rotatetarget);
10103                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10104                                                                                                                                 player[i].targetrotation*=360/6.28;
10105                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10106                                                                                                                         }
10107                                                                                                                         if(player[i].isFlip()){
10108                                                                                                                                 player[i].throwtogglekeydown=1;
10109                                                                                                                                 player[i].hasvictim=0;
10110
10111                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10112                                                                                                                                         if(player[i].weaponactive==-1)
10113                                                                                                                                                 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))
10114                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10115                                                                                                                                                                 float gLoc[3];
10116                                                                                                                                                                 float vel[3];
10117                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10118                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10119                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10120                                                                                                                                                                 vel[0]=player[i].velocity.x;
10121                                                                                                                                                                 vel[1]=player[i].velocity.y;
10122                                                                                                                                                                 vel[2]=player[i].velocity.z;
10123                                                                                                                                                                 if(weapons.type[k]!=staff){
10124                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10125                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10126                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
10127                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
10128                                                                                                                                                                 }
10129
10130                                                                                                                                                                 player[i].weaponactive=0;
10131                                                                                                                                                                 weapons.owner[k]=player[i].id;
10132                                                                                                                                                                 if(player[i].num_weapons>0){
10133                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10134                                                                                                                                                                 }
10135                                                                                                                                                                 player[i].num_weapons++;
10136                                                                                                                                                                 player[i].weaponids[0]=k;
10137                                                                                                                                                         }
10138                                                                                                                                 }
10139                                                                                                                         }
10140                                                                                                                 }
10141                                                                                                         }
10142                                                                                         }
10143                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10144                                                                                                 if(numplayers>1)
10145                                                                                                         for(j=0;j<numplayers;j++){
10146                                                                                                                 if(player[i].weaponactive==-1)
10147                                                                                                                         if(j!=i)
10148                                                                                                                                 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)){
10149                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10150                                                                                                                                                 player[i].throwtogglekeydown=1;
10151                                                                                                                                                 player[i].victim=&player[j];
10152                                                                                                                                                 player[i].hasvictim=1;
10153                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10154                                                                                                                                                 player[i].target=0;
10155                                                                                                                                                 player[i].targetframe=0;
10156                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10157                                                                                                                                                 Normalise(&rotatetarget);
10158                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10159                                                                                                                                                 player[i].targetrotation*=360/6.28;
10160                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10161                                                                                                                                         }
10162                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10163                                                                                                                                                 player[i].throwtogglekeydown=1;
10164                                                                                                                                                 player[i].victim=&player[j];
10165                                                                                                                                                 player[i].hasvictim=1;
10166                                                                                                                                                 int k = player[j].weaponids[0];
10167                                                                                                                                                 if(player[i].hasvictim){
10168                                                                                                                                                         float gLoc[3];
10169                                                                                                                                                         float vel[3];
10170                                                                                                                                                         gLoc[0]=player[i].coords.x;
10171                                                                                                                                                         gLoc[1]=player[i].coords.y;
10172                                                                                                                                                         gLoc[2]=player[i].coords.z;
10173                                                                                                                                                         vel[0]=player[i].velocity.x;
10174                                                                                                                                                         vel[1]=player[i].velocity.y;
10175                                                                                                                                                         vel[2]=player[i].velocity.z;
10176                                                                                                                                                         bool fleshstuck;
10177                                                                                                                                                         fleshstuck=0;
10178                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10179                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10180                                                                                                                                                                         fleshstuck=1;
10181                                                                                                                                                                 }
10182                                                                                                                                                         }
10183                                                                                                                                                         if(!fleshstuck){
10184                                                                                                                                                                 if(weapons.type[k]!=staff){
10185                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10186                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10187                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
10188                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
10189                                                                                                                                                                 }
10190                                                                                                                                                         }
10191                                                                                                                                                         if(fleshstuck){
10192                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
10193                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10194                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
10195                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
10196                                                                                                                                                         }
10197
10198                                                                                                                                                         player[i].weaponactive=0;
10199                                                                                                                                                         if(weapons.owner[k]!=-1){
10200                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10201                                                                                                                                                                 else player[i].victim->num_weapons=1;
10202
10203                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10204                                                                                                                                                                 player[i].victim->skeleton.free=1;
10205                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10206
10207                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10208                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10209                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10210                                                                                                                                                                 }
10211
10212                                                                                                                                                                 XYZ relative;
10213                                                                                                                                                                 relative=0;
10214                                                                                                                                                                 relative.y=10;
10215                                                                                                                                                                 Normalise(&relative);
10216                                                                                                                                                                 XYZ footvel,footpoint;
10217                                                                                                                                                                 footvel=0;
10218                                                                                                                                                                 footpoint=weapons.position[k];
10219                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10220                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10221                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10222                                                                                                                                                                                 weapons.bloody[k]=2;
10223                                                                                                                                                                                 weapons.blooddrip[k]=5;
10224                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10225                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10226                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10227                                                                                                                                                                         }
10228                                                                                                                                                                 }
10229                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10230                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10231                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10232                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10233                                                                                                                                                                 }
10234
10235                                                                                                                                                                 player[i].victim->weaponactive=-1;
10236
10237                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10238                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10239                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10240                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10241                                                                                                                                                         }
10242                                                                                                                                                         weapons.owner[k]=i;
10243                                                                                                                                                         if(player[i].num_weapons>0){
10244                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10245                                                                                                                                                         }
10246                                                                                                                                                         player[i].num_weapons++;
10247                                                                                                                                                         player[i].weaponids[0]=k;
10248                                                                                                                                                 }
10249                                                                                                                                         }
10250                                                                                                                                 }
10251                                                                                                         }
10252                                                                                         }
10253                                                                                 }
10254                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10255                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10256                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10257                                                                                                         if(numplayers>1)
10258                                                                                                                 for(j=0;j<numplayers;j++){
10259                                                                                                                         if(i!=j)
10260                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10261                                                                                                                                         if(hostile)
10262                                                                                                                                                 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)){
10263                                                                                                                                                         if(!player[i].isFlip()){
10264                                                                                                                                                                 player[i].throwtogglekeydown=1;
10265                                                                                                                                                                 player[i].victim=&player[j];
10266                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10267                                                                                                                                                                 player[i].target=0;
10268                                                                                                                                                                 player[i].targetframe=0;
10269                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10270                                                                                                                                                                 Normalise(&rotatetarget);
10271                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10272                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10273                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10274
10275                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10276                                                                                                                                                         }
10277                                                                                                                                                         if(player[i].isFlip()){
10278                                                                                                                                                                 if(player[i].weaponactive!=-1){
10279                                                                                                                                                                         player[i].throwtogglekeydown=1;
10280                                                                                                                                                                         player[i].victim=&player[j];
10281                                                                                                                                                                         XYZ aim;
10282                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10283                                                                                                                                                                         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);
10284                                                                                                                                                                         Normalise(&aim);
10285
10286                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10287
10288                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10289                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10290                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10291                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10292                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10293                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10294                                                                                                                                                                         player[i].num_weapons--;
10295                                                                                                                                                                         if(player[i].num_weapons){
10296                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10297                                                                                                                                                                         }
10298                                                                                                                                                                         player[i].weaponactive=-1;
10299                                                                                                                                                                 }
10300                                                                                                                                                         }
10301                                                                                                                                                 }
10302                                                                                                                 }
10303                                                                                         }
10304                                                                                 }
10305                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10306                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10307                                                                                         {
10308                                                                                                 player[i].throwtogglekeydown=1;
10309                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10310                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10311                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10312                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10313                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10314                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10315                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10316                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10317                                                                                                 player[i].num_weapons--;
10318                                                                                                 if(player[i].num_weapons){
10319                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10320                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10321                                                                                                 }
10322
10323                                                                                                 player[i].weaponactive=-1;
10324                                                                                                 for(j=0;j<numplayers;j++){
10325                                                                                                         player[j].wentforweapon=0;
10326                                                                                                 }
10327                                                                                         }
10328                                                                                 }
10329
10330                                                                         }
10331
10332                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10333                                                                                 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)){
10334                                                                                         //Setenvironment(1-environment);
10335                                                                                         bool isgood;
10336                                                                                         isgood=1;
10337                                                                                         if(player[i].weaponactive!=-1){
10338                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10339                                                                                         }
10340                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10341                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10342                                                                                                         player[i].targetanimation=drawrightanim;
10343                                                                                                         player[i].targetframe=0;
10344                                                                                                         player[i].target=0;
10345                                                                                                         player[i].drawtogglekeydown=1;
10346                                                                                                 }
10347                                                                                                 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){
10348                                                                                                         player[i].targetanimation=drawleftanim;
10349                                                                                                         player[i].targetframe=0;
10350                                                                                                         player[i].target=0;
10351                                                                                                         player[i].drawtogglekeydown=1;
10352                                                                                                 }
10353                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10354                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10355                                                                                                         player[i].targetframe=0;
10356                                                                                                         player[i].target=0;
10357                                                                                                         player[i].drawtogglekeydown=1;
10358                                                                                                 }
10359                                                                                         }
10360                                                                                 }
10361                                                                                 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){
10362                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10363                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10364                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10365                                                                                                 player[i].targetframe=0;
10366                                                                                                 player[i].target=0;
10367                                                                                                 player[i].hasvictim=0;
10368                                                                                                 //player[i].attacktogglekeydown=1;
10369                                                                                         }
10370                                                                                 }
10371
10372                                                                                 if(!player[i].drawkeydown){
10373                                                                                         player[i].drawtogglekeydown=0;
10374                                                                                 }
10375
10376                                                                                 if(i==0){
10377                                                                                         absflatfacing=0;
10378                                                                                         absflatfacing.z=-1;
10379
10380                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10381                                                                                 }
10382                                                                                 else absflatfacing=flatfacing;
10383
10384                                                                                 if(indialogue!=-1){
10385                                                                                         player[i].forwardkeydown=0;
10386                                                                                         player[i].leftkeydown=0;
10387                                                                                         player[i].backkeydown=0;
10388                                                                                         player[i].rightkeydown=0;
10389                                                                                         player[i].jumpkeydown=0;
10390                                                                                         player[i].crouchkeydown=0;
10391                                                                                         player[i].drawkeydown=0;
10392                                                                                         player[i].throwkeydown=0;
10393                                                                                 }
10394                                                                                 movekey=0;
10395                                                                                 //Do controls
10396                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10397                                                                                         if(!player[i].forwardkeydown){
10398                                                                                                 player[i].forwardstogglekeydown=0;
10399                                                                                         }
10400                                                                                         if(player[i].crouchkeydown){
10401                                                                                                 //Crouch
10402                                                                                                 target=-2;
10403                                                                                                 if(i==0){
10404                                                                                                         player[i].superruntoggle=1;
10405                                                                                                         if(numplayers>1)
10406                                                                                                                 for(j=0;j<numplayers;j++){
10407                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10408                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10409                                                                                                                                         player[i].superruntoggle=0;
10410                                                                                                                                 }
10411                                                                                                                         }
10412                                                                                                                 }
10413                                                                                                 }
10414
10415                                                                                                 if(numplayers>1)
10416                                                                                                         for(j=0;j<numplayers;j++){
10417                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10418                                                                                                                         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))){
10419                                                                                                                                 if(target>=0)target=-1;
10420                                                                                                                                 else target=j;
10421                                                                                                                         }
10422                                                                                                                 }
10423                                                                                                         }
10424                                                                                                         if(target>=0)player[target].Reverse();
10425                                                                                                         player[i].lowreversaldelay=.5;
10426
10427                                                                                                         if(player[i].isIdle()){
10428                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10429                                                                                                                 player[i].target=0;
10430                                                                                                                 player[i].targetframe=0;
10431                                                                                                                 player[i].transspeed=10;
10432                                                                                                         }
10433                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10434                                                                                                                 player[i].targetanimation=rollanim;
10435                                                                                                                 player[i].target=0;
10436                                                                                                                 player[i].targetframe=0;
10437                                                                                                                 player[i].transspeed=20;
10438                                                                                                         }
10439                                                                                         }
10440                                                                                         if(!player[i].crouchkeydown){
10441                                                                                                 //Uncrouch
10442                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10443                                                                                                 target=-2;
10444                                                                                                 if(player[i].isCrouch()){
10445                                                                                                         if(numplayers>1)
10446                                                                                                                 for(j=0;j<numplayers;j++){
10447                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10448                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10449                                                                                                                                         if(target>=0)target=-1;
10450                                                                                                                                         else target=j;
10451                                                                                                                                 }
10452                                                                                                                         }
10453                                                                                                                 }
10454                                                                                                                 if(target>=0)player[target].Reverse();
10455                                                                                                                 player[i].highreversaldelay=.5;
10456
10457                                                                                                                 if(player[i].isCrouch()){
10458                                                                                                                         if(!player[i].wasCrouch()){
10459                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10460                                                                                                                                 player[i].currentframe=0;
10461                                                                                                                         }
10462                                                                                                                         player[i].target=0;
10463                                                                                                                         player[i].targetanimation=player[i].getIdle();
10464                                                                                                                         player[i].targetframe=0;
10465                                                                                                                         player[i].transspeed=10;
10466                                                                                                                 }
10467                                                                                                 }
10468                                                                                                 if(player[i].targetanimation==sneakanim){
10469                                                                                                         player[i].targetanimation=player[i].getIdle();
10470                                                                                                         player[i].target=0;
10471                                                                                                         player[i].targetframe=0;
10472                                                                                                         player[i].transspeed=10;
10473                                                                                                 }
10474                                                                                         }
10475                                                                                         if(player[i].forwardkeydown){
10476                                                                                                 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)){
10477                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10478                                                                                                         else player[i].targetanimation=player[i].getRun();
10479                                                                                                         player[i].target=0;
10480                                                                                                         player[i].targetframe=0;
10481                                                                                                 }
10482                                                                                                 if(player[i].isCrouch()){
10483                                                                                                         player[i].targetanimation=sneakanim;
10484                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10485                                                                                                         player[i].targetframe=0;
10486                                                                                                 }
10487                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10488                                                                                                         player[i].targetanimation=climbanim;
10489                                                                                                         player[i].target=0;
10490                                                                                                         player[i].targetframe=1;
10491                                                                                                         player[i].jumpclimb=1;
10492                                                                                                 }
10493                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10494                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10495                                                                                                 }
10496                                                                                                 player[i].forwardstogglekeydown=1;
10497                                                                                                 movekey=1;
10498                                                                                         }
10499                                                                                         if (player[i].rightkeydown){
10500                                                                                                 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)){
10501                                                                                                         player[i].targetanimation=player[i].getRun();
10502                                                                                                         player[i].target=0;
10503                                                                                                         player[i].targetframe=0;
10504                                                                                                 }
10505                                                                                                 if(player[i].isCrouch()){
10506                                                                                                         player[i].targetanimation=sneakanim;
10507                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10508                                                                                                         player[i].targetframe=0;
10509                                                                                                 }
10510                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10511                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10512                                                                                                 }
10513                                                                                                 player[i].targetrotation-=90;
10514                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10515                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10516                                                                                                 movekey=1;
10517                                                                                         }
10518                                                                                         if ( player[i].leftkeydown){
10519                                                                                                 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)){
10520                                                                                                         player[i].targetanimation=player[i].getRun();
10521                                                                                                         player[i].target=0;
10522                                                                                                         player[i].targetframe=0;
10523                                                                                                 }
10524                                                                                                 if(player[i].isCrouch()){
10525                                                                                                         player[i].targetanimation=sneakanim;
10526                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10527                                                                                                         player[i].targetframe=0;
10528                                                                                                 }
10529                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10530                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10531                                                                                                 }
10532                                                                                                 player[i].targetrotation+=90;
10533                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10534                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10535                                                                                                 movekey=1;
10536                                                                                         }
10537                                                                                         if(player[i].backkeydown){
10538                                                                                                 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)){
10539                                                                                                         player[i].targetanimation=player[i].getRun();
10540                                                                                                         player[i].target=0;
10541                                                                                                         player[i].targetframe=0;
10542                                                                                                 }
10543                                                                                                 if(player[i].isCrouch()){
10544                                                                                                         player[i].targetanimation=sneakanim;
10545                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10546                                                                                                         player[i].targetframe=0;
10547                                                                                                 }
10548                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10549                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10550                                                                                                 }
10551                                                                                                 if(player[i].targetanimation==hanganim){
10552                                                                                                         player[i].currentanimation=jumpdownanim;
10553                                                                                                         player[i].targetanimation=jumpdownanim;
10554                                                                                                         player[i].target=0;
10555                                                                                                         player[i].currentframe=0;
10556                                                                                                         player[i].targetframe=1;
10557                                                                                                         player[i].velocity=0;
10558                                                                                                         player[i].velocity.y+=gravity;
10559                                                                                                         player[i].coords.y-=1.4;
10560                                                                                                         player[i].grabdelay=1;
10561                                                                                                 }
10562                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10563                                                                                                         player[i].targetrotation+=180;
10564                                                                                                 movekey=1;
10565                                                                                         }
10566                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10567                                                                                                 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)){
10568                                                                                                         player[i].jumpstart=0;
10569                                                                                                         player[i].targetanimation=jumpupanim;
10570                                                                                                         player[i].target=0;
10571                                                                                                         player[i].targetframe=0;
10572                                                                                                         player[i].rotation=player[i].targetrotation;
10573                                                                                                         player[i].transspeed=20;
10574                                                                                                         player[i].FootLand(0,1);
10575                                                                                                         player[i].FootLand(1,1);
10576
10577                                                                                                         facing=0;
10578                                                                                                         facing.z=-1;
10579                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10580
10581                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10582                                                                                                         if(!movekey)player[i].velocity=0;
10583
10584                                                                                                         //Dodge sweep?
10585                                                                                                         target=-2;
10586                                                                                                         if(numplayers>1)
10587                                                                                                                 for(j=0;j<numplayers;j++){
10588                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10589                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10590                                                                                                                                         if(target>=0)target=-1;
10591                                                                                                                                         else target=j;
10592                                                                                                                                 }
10593                                                                                                                         }
10594                                                                                                                 }
10595                                                                                                                 if(target>=0)player[i].velocity.y=1;
10596                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10597                                                                                                                         player[i].velocity.y=7;
10598                                                                                                                         player[i].crouchtogglekeydown=1;
10599                                                                                                                 }
10600                                                                                                                 else player[i].velocity.y=5;
10601
10602                                                                                                                 if(mousejump&&i==0&&debugmode){
10603                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10604                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10605                                                                                                                 }
10606
10607                                                                                                                 player[i].coords.y+=.2;
10608                                                                                                                 player[i].jumppower-=1;
10609
10610                                                                                                                 static float gLoc[3];
10611                                                                                                                 static float vel[3];
10612                                                                                                                 gLoc[0]=player[i].coords.x;
10613                                                                                                                 gLoc[1]=player[i].coords.y;
10614                                                                                                                 gLoc[2]=player[i].coords.z;
10615                                                                                                                 vel[0]=player[i].velocity.x;
10616                                                                                                                 vel[1]=player[i].velocity.y;
10617                                                                                                                 vel[2]=player[i].velocity.z;
10618
10619                                                                                                                 if(i==0){
10620                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10621                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10622                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10623                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10624                                                                                                                 }
10625
10626                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10627                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10628                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10629                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10630                                                                                                 }
10631                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10632                                                                                                         player[i].targetanimation=player[i].getLanding();
10633                                                                                                         player[i].landhard=0;
10634                                                                                                         player[i].target=0;
10635                                                                                                         player[i].targetframe=2;
10636                                                                                                         player[i].jumpstart=1;
10637                                                                                                         player[i].tempdeltav=deltav;
10638                                                                                                 }
10639                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10640                                                                                                         if(player[i].jumppower>multiplier*6){
10641                                                                                                                 player[i].velocity.y+=multiplier*6;
10642                                                                                                                 player[i].jumppower-=multiplier*6;
10643                                                                                                         }
10644                                                                                                         if(player[i].jumppower<=multiplier*6){
10645                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10646                                                                                                                 player[i].jumppower=0;
10647                                                                                                         }
10648                                                                                                 }
10649                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10650                                                                                         }
10651
10652                                                                                         if(!movekey){
10653                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10654                                                                                                         player[i].targetanimation=player[i].getStop();
10655                                                                                                         player[i].target=0;
10656                                                                                                         player[i].targetframe=0;
10657                                                                                                 }
10658                                                                                                 if(player[i].targetanimation==sneakanim){
10659                                                                                                         player[i].targetanimation=player[i].getCrouch();
10660                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10661                                                                                                         player[i].targetframe=0;
10662                                                                                                 }
10663                                                                                         }
10664                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10665                                                                                                 player[i].targetanimation=player[i].getStop();
10666                                                                                                 player[i].target=0;
10667                                                                                                 player[i].targetframe=0;
10668                                                                                         }
10669                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10670                                                                                                 player[i].targetanimation=player[i].getStop();
10671                                                                                                 player[i].target=0;
10672                                                                                                 player[i].targetframe=0;
10673                                                                                         }
10674                                                                                 }
10675                                                                 }
10676                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10677                                                         }
10678
10679                                                         //Rotation
10680                                                         for(k=0;k<numplayers;k++){
10681                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10682                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10683                                                                         else player[k].rotation+=360;
10684                                                                 }
10685
10686                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10687                                                                         player[k].targetanimation=player[k].getStop();
10688                                                                         player[k].targetframe=0;
10689                                                                         player[k].target=0;
10690                                                                 }
10691
10692                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10693                                                                         player[k].targettilt=0;
10694                                                                 }
10695                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10696                                                                         player[k].targettilt=0;
10697                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10698                                                                         player[k].jumppower+=multiplier*7;
10699                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10700                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10701                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10702                                                                 }
10703
10704                                                                 if(player[k].isRun()){
10705                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10706                                                                 }
10707
10708                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10709                                                                 else if(player[k].tilt>player[k].targettilt){
10710                                                                         player[k].tilt-=multiplier*150;
10711                                                                 }
10712                                                                 else if(player[k].tilt<player[k].targettilt){
10713                                                                         player[k].tilt+=multiplier*150;
10714                                                                 }
10715
10716                                                                 player[k].grabdelay-=multiplier;
10717                                                         }
10718
10719                                                         for(k=0;k<numplayers;k++){
10720                                                                 player[k].DoAnimations();
10721                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10722                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10723                                                         }
10724
10725                                                         objects.DoStuff();
10726                                                         /*
10727                                                         player[0].righthandmorphstart=0;
10728                                                         player[0].righthandmorphend=1;
10729                                                         player[0].lefthandmorphstart=0;
10730                                                         player[0].lefthandmorphend=1;
10731                                                         player[0].headmorphstart=0;
10732                                                         player[0].headmorphend=2;*/
10733
10734                                                         /*
10735                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10736                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10737                                                         player[0].righthandmorphend=1;
10738                                                         player[0].targetrighthandmorphness=1;
10739
10740                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10741                                                         player[0].lefthandmorphend=0;
10742                                                         player[0].targetlefthandmorphness=1;
10743
10744                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10745                                                         player[0].headmorphend=2;
10746                                                         player[0].targetheadmorphness=1;
10747                                                         }
10748                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10749                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10750                                                         player[0].righthandmorphend=0;
10751                                                         player[0].targetrighthandmorphness=1;
10752
10753                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10754                                                         player[0].lefthandmorphend=1;
10755                                                         player[0].targetlefthandmorphness=1;
10756
10757                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10758                                                         player[0].headmorphend=0;
10759                                                         player[0].targetheadmorphness=1;
10760                                                         }
10761                                                         */
10762                                                         if(numenvsounds!=0)
10763                                                                 for(j=numenvsounds-1;j>=0;j--){
10764                                                                         envsoundlife[j]-=multiplier;
10765                                                                         if(envsoundlife[j]<0){
10766                                                                                 numenvsounds--;
10767                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10768                                                                                 envsound[j]=envsound[numenvsounds];
10769                                                                         }
10770                                                                 }
10771                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10772                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10773
10774                                                                 if(tutoriallevel==1){
10775                                                                         XYZ temp;
10776                                                                         XYZ temp2;
10777                                                                         XYZ temp3;
10778                                                                         XYZ oldtemp;
10779                                                                         XYZ oldtemp2;
10780                                                                         temp.x=1011;
10781                                                                         temp.y=84;
10782                                                                         temp.z=491;
10783                                                                         temp2.x=1025;
10784                                                                         temp2.y=75;
10785                                                                         temp2.z=447;
10786                                                                         temp3.x=1038;
10787                                                                         temp3.y=76;
10788                                                                         temp3.z=453;
10789                                                                         oldtemp=temp;
10790                                                                         oldtemp2=temp2;
10791                                                                         if(tutorialstage>=51)
10792                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10793                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10794                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10795
10796                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10797                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10798                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10799
10800                                                                                         gameon=0;
10801                                                                                         mainmenu=5;
10802
10803                                                                                         float gLoc[3]={0,0,0};
10804                                                                                         float vel[3]={0,0,0};
10805                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10806                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10807                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10808                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10809                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10810                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10811
10812                                                                                         flashr=1;
10813                                                                                         flashg=0;
10814                                                                                         flashb=0;
10815                                                                                         flashamount=1;
10816                                                                                         flashdelay=1;
10817                                                                                 }
10818                                                                                 if(tutorialstage<51)
10819                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10820                                                                                                 float gLoc[3];
10821                                                                                                 float vel[3];
10822                                                                                                 gLoc[0]=player[0].coords.x;
10823                                                                                                 gLoc[1]=player[0].coords.y;
10824                                                                                                 gLoc[2]=player[0].coords.z;
10825                                                                                                 vel[0]=0;
10826                                                                                                 vel[1]=0;
10827                                                                                                 vel[2]=0;
10828                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10829                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10830                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10831                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10832
10833                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10834
10835                                                                                                 flashr=1;
10836                                                                                                 flashg=1;
10837                                                                                                 flashb=1;
10838                                                                                                 flashamount=1;
10839                                                                                                 flashdelay=1;
10840                                                                                         }
10841                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10842                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10843                                                                                                         float gLoc[3];
10844                                                                                                         float vel[3];
10845                                                                                                         gLoc[0]=player[1].coords.x;
10846                                                                                                         gLoc[1]=player[1].coords.y;
10847                                                                                                         gLoc[2]=player[1].coords.z;
10848                                                                                                         vel[0]=0;
10849                                                                                                         vel[1]=0;
10850                                                                                                         vel[2]=0;
10851                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10852                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10853                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10854                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10855
10856                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10857                                                                                                                 if(Random()%2==0){
10858                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10859                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10860                                                                                                                         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;
10861                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10862                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10863                                                                                                                 }
10864                                                                                                         }
10865
10866                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10867                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10868                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10869                                                                                                                 if(Random()%2==0){
10870                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10871                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10872                                                                                                                         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;
10873                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10874                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10875                                                                                                                 }
10876                                                                                                         }
10877                                                                                                 }
10878                                                                 }
10879
10880
10881                                                                 //3d sound
10882                                                                 static float gLoc[3];
10883                                                                 gLoc[0]=viewer.x;
10884                                                                 gLoc[1]=viewer.y;
10885                                                                 gLoc[2]=viewer.z;
10886                                                                 static float vel[3];
10887                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10888                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10889                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10890
10891                                                                 //Set orientation with forward and up vectors
10892                                                                 static XYZ upvector;
10893                                                                 upvector=0;
10894                                                                 upvector.z=-1;
10895
10896                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10897                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10898
10899                                                                 facing=0;
10900                                                                 facing.z=-1;
10901
10902                                                                 facing=DoRotation(facing,-rotation2,0,0);
10903                                                                 facing=DoRotation(facing,0,0-rotation,0);
10904
10905
10906                                                                 static float ori[6];
10907                                                                 ori[0] = -facing.x;
10908                                                                 ori[1] = facing.y;
10909                                                                 ori[2] = -facing.z;
10910                                                                 ori[3] = -upvector.x;
10911                                                                 ori[4] = upvector.y;
10912                                                                 ori[5] = -upvector.z;
10913
10914                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10915                                                                 OPENAL_Update();
10916
10917                                                                 oldviewer=viewer;
10918                 }
10919         }
10920
10921         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10922                 Screenshot();
10923                 freezetogglekeydown=1;
10924         }
10925 }
10926
10927 void    Game::TickOnce(){
10928         //if(!console){
10929         if(!mainmenu)
10930                 if(directing||indialogue==-1){
10931                         rotation+=deltah*.7;
10932                         if(!invertmouse)rotation2+=deltav*.7;
10933                         if(invertmouse)rotation2-=deltav*.7;
10934                         if(rotation2>90)rotation2=90;
10935                         if(rotation2<-70)rotation2=-70;
10936                 }
10937                 if(mainmenu)rotation+=multiplier*5;
10938                 if(!mainmenu&&!indemo&&!registered){
10939                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10940                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10941                         OPENAL_SetPaused(channels[stream_music3], false);
10942                         OPENAL_SetVolume(channels[stream_music3], 256);
10943
10944                         gameon=0;
10945                         mainmenu=12;
10946
10947                         float gLoc[3]={0,0,0};
10948                         float vel[3]={0,0,0};
10949                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10950                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10951                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10952                         OPENAL_SetVolume(channels[fireendsound], 256);
10953                         OPENAL_SetPaused(channels[fireendsound], false);
10954                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10955
10956                         flashr=1;
10957                         flashg=0;
10958                         flashb=0;
10959                         flashamount=1;
10960                         flashdelay=1;
10961                 }
10962
10963                 if(tryquit==1&&!registered&&mainmenu!=12){
10964                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10965                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10966                         OPENAL_SetPaused(channels[stream_music3], false);
10967                         OPENAL_SetVolume(channels[stream_music3], 256);
10968
10969                         gameon=0;
10970                         mainmenu=12;
10971
10972                         float gLoc[3]={0,0,0};
10973                         float vel[3]={0,0,0};
10974                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10975                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10976                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10977                         OPENAL_SetVolume(channels[fireendsound], 256);
10978                         OPENAL_SetPaused(channels[fireendsound], false);
10979                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10980
10981                         flashr=1;
10982                         flashg=0;
10983                         flashb=0;
10984                         flashamount=1;
10985                         flashdelay=1;
10986                 }
10987                 //}
10988 }
10989
10990 void    Game::TickOnceAfter(){
10991         static XYZ colviewer;
10992         static XYZ coltarget;
10993         static XYZ target;
10994         static XYZ col;
10995         static float brotate;
10996         static XYZ facing;
10997         static int i,j;
10998         static float changedelay;
10999         static bool alldead;
11000         static float unseendelay;
11001         static float cameraspeed;
11002
11003         if(!mainmenu){
11004
11005                 if(environment==snowyenvironment)music1=stream_music1snow;
11006                 if(environment==grassyenvironment)music1=stream_music1grass;
11007                 if(environment==desertenvironment)music1=stream_music1desert;
11008
11009                 realthreat=0;
11010
11011                 musictype=music1;
11012                 for(i=0;i<numplayers;i++){
11013                         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)){
11014                                 musictype=stream_music2;
11015                                 realthreat=1;
11016                         }
11017                 }
11018                 if(player[0].dead)musictype=stream_music3;
11019
11020
11021                 if(musictype==stream_music2){
11022                         unseendelay=1;
11023                 }
11024
11025                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
11026                         unseendelay-=multiplier;
11027                         if(unseendelay>0){
11028                                 musictype=stream_music2;
11029                         }
11030                 }
11031
11032
11033                 if(loading==2){
11034                         musictype=stream_music3;
11035                         musicvolume[2]=512;
11036                         musicvolume[0]=0;
11037                         musicvolume[1]=0;
11038                         musicvolume[3]=0;
11039                 }
11040
11041                 if(musictoggle){
11042                         if(musictype!=oldmusictype&&musictype==stream_music2){
11043                                 static float gLoc[3];
11044                                 static float vel[3];
11045                                 gLoc[0]=cameraloc.x;
11046                                 gLoc[1]=cameraloc.y;
11047                                 gLoc[2]=cameraloc.z;
11048                                 vel[0]=0;
11049                                 vel[1]=0;
11050                                 vel[2]=0;
11051                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
11052                                 OPENAL_SetVolume(channels[alarmsound], 512);
11053                                 OPENAL_SetPaused(channels[alarmsound], false);
11054
11055                         }
11056                 }
11057                 musicselected=musictype;
11058
11059                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11060                 else musicvolume[0]-=multiplier*450;
11061                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11062                 else musicvolume[1]-=multiplier*450;
11063                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11064                 else musicvolume[2]-=multiplier*450;
11065                 /*
11066                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11067                 else musicvolume[0]-=multiplier*450;
11068                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11069                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11070                 else musicvolume[1]-=multiplier*100;
11071                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11072                 else musicvolume[2]-=multiplier*450;*/
11073
11074                 for(i=0;i<3;i++){
11075                         if(musicvolume[i]<0)musicvolume[i]=0;
11076                         if(musicvolume[i]>512)musicvolume[i]=512;
11077                 }
11078
11079                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11080
11081                 if(musictoggle){
11082                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11083                                 PlayStreamEx( music1, strm[music1], NULL, true);
11084                                 OPENAL_SetPaused(channels[music1], false);
11085                         }
11086                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11087                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
11088                                 OPENAL_SetPaused(channels[stream_music2], false);
11089                         }
11090                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11091                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11092                                 OPENAL_SetPaused(channels[stream_music3], false);
11093                         }
11094                 }
11095
11096                 if(!musictoggle){
11097                         OPENAL_SetPaused(channels[music1], true);
11098                         OPENAL_SetPaused(channels[stream_music2], true);
11099                         OPENAL_SetPaused(channels[stream_music3], true);
11100
11101                         for(i=0;i<4;i++){
11102                                 oldmusicvolume[i]=0;
11103                                 musicvolume[i]=0;
11104                         }
11105                 }
11106
11107                 if(musictoggle){
11108                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11109                                 OPENAL_SetPaused(channels[music1], true);
11110                         }
11111                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11112                                 OPENAL_SetPaused(channels[stream_music2], true);
11113                         }
11114                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11115                                 OPENAL_SetPaused(channels[stream_music3], true);
11116                         }
11117
11118                         if(musicvolume[0]!=oldmusicvolume[0]){
11119                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
11120                         }
11121                         if(musicvolume[1]!=oldmusicvolume[1]){
11122                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
11123                         }
11124                         if(musicvolume[2]!=oldmusicvolume[2]){
11125                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
11126                         }
11127
11128                         for(i=0;i<3;i++){
11129                                 oldmusicvolume[i]=musicvolume[i];
11130                         }
11131                 }
11132
11133                 killhotspot=2;
11134                 if(numhotspots)
11135                         for(i=0;i<numhotspots;i++){
11136                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11137                                         if(player[hotspottype[i]-10].dead==0){
11138                                                 killhotspot=0;
11139                                         }
11140                                         else if(killhotspot==2)
11141                                                 killhotspot=1;
11142                                 }
11143                         }
11144                         if(killhotspot==2)killhotspot=0;
11145
11146
11147                         winhotspot=0;
11148                         if(numhotspots)
11149                                 for(i=0;i<numhotspots;i++){
11150                                         if(hotspottype[i]==-1){
11151                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11152                                                         winhotspot=1;
11153                                         }
11154                                 }
11155
11156                                 int numalarmed=0;
11157                                 if(numplayers>1)
11158                                         for(i=1;i<numplayers;i++){
11159                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11160                                         }
11161                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11162
11163                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
11164                                                 if(player[0].dead&&changedelay<=0){
11165                                                         changedelay=1;
11166                                                         targetlevel=whichlevel;
11167                                                 }
11168                                                 alldead=1;
11169                                                 if(numplayers>1)
11170                                                         for(i=1;i<numplayers;i++){
11171                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11172                                                         }
11173
11174
11175                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11176                                                                 changedelay=1;
11177                                                                 targetlevel=whichlevel+1;
11178                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11179                                                         }
11180                                                         if(winhotspot||windialogue){
11181                                                                 changedelay=0.1;
11182                                                                 targetlevel=whichlevel+1;
11183                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11184                                                         }
11185
11186
11187                                                         if(killhotspot){
11188                                                                 changedelay=1;
11189                                                                 targetlevel=whichlevel+1;
11190                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11191                                                         }
11192
11193                                                         if(changedelay>0&&!player[0].dead&&!won){
11194                                                                 //high scores, awards, win
11195                                                                 if(campaign){
11196                                                                         won=1;
11197                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11198                                                                         accountcampaignchoicesmade[accountactive]++;
11199                                                                         accountcampaignscore[accountactive]+=bonustotal;
11200                                                                         scoreadded=1;
11201                                                                         accountcampaigntime[accountactive]+=leveltime;
11202                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11203
11204                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11205                                                                 }
11206                                                                 else
11207                                                                 {
11208                                                                         won=1;
11209                                                                         if(!debugmode){
11210                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11211                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
11212                                                                         }
11213                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11214
11215                                                                 }
11216                                                         }
11217                                         }
11218
11219                                         if(!winfreeze){
11220
11221                                                 if(leveltime<1){
11222                                                         loading=0;
11223                                                         changedelay=.1;
11224                                                         alldead=0;
11225                                                         winhotspot=0;
11226                                                         killhotspot=0;
11227                                                 }
11228
11229                                                 if(!editorenabled&&gameon&&!mainmenu){
11230                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11231                                                         if(player[0].dead)targetlevel=whichlevel;
11232                                                         if(loading==2&&!campaign){
11233                                                                 flashr=1;
11234                                                                 flashg=0;
11235                                                                 flashb=0;
11236                                                                 flashamount=1;
11237                                                                 flashdelay=1;
11238                                                                 loadtime=0;
11239
11240                                                                 float gLoc[3]={0,0,0};
11241                                                                 float vel[3]={0,0,0};
11242                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11243                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11244                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11245                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
11246                                                                 OPENAL_SetPaused(channels[firestartsound], false);
11247                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11248
11249                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11250                                                                         startbonustotal=bonustotal;
11251                                                                 }
11252                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11253                                                                 if(player[0].dead)Loadlevel(whichlevel);
11254
11255                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11256                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11257                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11258                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
11259                                                                 OPENAL_SetPaused(channels[fireendsound], false);
11260                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11261
11262                                                                 loading=3;
11263                                                         }
11264                                                         if(loading==2&&targetlevel==whichlevel){
11265                                                                 flashr=1;
11266                                                                 flashg=0;
11267                                                                 flashb=0;
11268                                                                 flashamount=1;
11269                                                                 flashdelay=1;
11270                                                                 loadtime=0;
11271
11272                                                                 float gLoc[3]={0,0,0};
11273                                                                 float vel[3]={0,0,0};
11274                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11275                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11276                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11277                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
11278                                                                 OPENAL_SetPaused(channels[firestartsound], false);
11279                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11280
11281                                                                 for(i=0;i<255;i++){
11282                                                                         mapname[i]='\0';
11283                                                                 }
11284                                                                 mapname[0]=':';
11285                                                                 mapname[1]='D';
11286                                                                 mapname[2]='a';
11287                                                                 mapname[3]='t';
11288                                                                 mapname[4]='a';
11289                                                                 mapname[5]=':';
11290                                                                 mapname[6]='M';
11291                                                                 mapname[7]='a';
11292                                                                 mapname[8]='p';
11293                                                                 mapname[9]='s';
11294                                                                 mapname[10]=':';
11295                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11296                                                                 Loadlevel(mapname);
11297
11298                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11299                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11300                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11301                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
11302                                                                 OPENAL_SetPaused(channels[fireendsound], false);
11303                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11304
11305                                                                 loading=3;
11306                                                         }
11307                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11308                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11309                                                                 if(accountprogress[accountactive]>3&&!registered){
11310                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
11311                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11312                                                                         OPENAL_SetPaused(channels[stream_music3], false);
11313                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
11314
11315                                                                         gameon=0;
11316                                                                         mainmenu=12;
11317                                                                         accountprogress[accountactive]=3;
11318
11319                                                                         float gLoc[3]={0,0,0};
11320                                                                         float vel[3]={0,0,0};
11321                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11322                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11323                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11324                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
11325                                                                         OPENAL_SetPaused(channels[fireendsound], false);
11326                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11327
11328                                                                         flashr=1;
11329                                                                         flashg=0;
11330                                                                         flashb=0;
11331                                                                         flashamount=1;
11332                                                                         flashdelay=1;
11333                                                                 }
11334                                                                 else{
11335                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11336                                                                                 winfreeze=1;
11337                                                                                 changedelay=-999;
11338                                                                         }
11339                                                                         if(player[0].dead)loading=1;
11340                                                                 }
11341                                                         }
11342                                                 }
11343
11344                                                 if(campaign)
11345                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11346                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11347                                                                         endgame=1;
11348                                                                 }
11349                                                         }
11350                                                         else if(mainmenu==0&&winfreeze){
11351                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11352                                                                         stealthloading=1;
11353                                                                 else stealthloading=0;
11354
11355                                                                 if(!stealthloading){
11356                                                                         float gLoc[3]={0,0,0};
11357                                                                         float vel[3]={0,0,0};
11358                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11359                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11360                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11361                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
11362                                                                         OPENAL_SetPaused(channels[firestartsound], false);
11363                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11364
11365                                                                         flashr=1;
11366                                                                         flashg=0;
11367                                                                         flashb=0;
11368                                                                         flashamount=1;
11369                                                                         flashdelay=1;
11370                                                                 }
11371
11372                                                                 startbonustotal=0;
11373
11374                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11375                                                                 //campaignnumlevels=0;
11376                                                                 //accountcampaignchoicesmade[accountactive]=0;
11377                                                                 ipstream.ignore(256,':');
11378                                                                 ipstream >> campaignnumlevels;
11379                                                                 for(i=0;i<campaignnumlevels;i++){
11380                                                                         ipstream.ignore(256,':');
11381                                                                         ipstream.ignore(256,':');
11382                                                                         ipstream.ignore(256,' ');
11383                                                                         ipstream >> campaignmapname[i];
11384                                                                         ipstream.ignore(256,':');
11385                                                                         ipstream >> campaigndescription[i];
11386                                                                         for(j=0;j<256;j++){
11387                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11388                                                                         }
11389                                                                         ipstream.ignore(256,':');
11390                                                                         ipstream >> campaignchoosenext[i];
11391                                                                         ipstream.ignore(256,':');
11392                                                                         ipstream >> campaignnumnext[i];
11393                                                                         if(campaignnumnext[i])
11394                                                                                 for(j=0;j<campaignnumnext[i];j++){
11395                                                                                         ipstream.ignore(256,':');
11396                                                                                         ipstream >> campaignnextlevel[i][j];
11397                                                                                         campaignnextlevel[i][j]-=1;
11398                                                                                 }
11399                                                                                 ipstream.ignore(256,':');
11400                                                                                 ipstream >> campaignlocationx[i];
11401                                                                                 ipstream.ignore(256,':');
11402                                                                                 ipstream >> campaignlocationy[i];
11403                                                                 }
11404                                                                 ipstream.close();
11405
11406                                                                 for(i=0;i<campaignnumlevels;i++){
11407                                                                         levelvisible[i]=0;
11408                                                                         levelhighlight[i]=0;
11409                                                                 }
11410
11411
11412                                                                 for(i=0;i<campaignnumlevels;i++){
11413                                                                         levelvisible[i]=0;
11414                                                                         levelhighlight[i]=0;
11415                                                                 }
11416
11417                                                                 levelorder[0]=0;
11418                                                                 levelvisible[0]=1;
11419                                                                 if(accountcampaignchoicesmade[accountactive])
11420                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11421                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11422                                                                                 levelvisible[levelorder[i+1]]=1;
11423                                                                         }
11424                                                                         int whichlevelstart;
11425                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11426                                                                         if(whichlevelstart<0){
11427                                                                                 campaignchoicenum=1;
11428                                                                                 campaignchoicewhich[0]=0;
11429                                                                         }
11430                                                                         else
11431                                                                         {
11432                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11433                                                                                 if(campaignchoicenum)
11434                                                                                         for(i=0;i<campaignchoicenum;i++){
11435                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11436                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11437                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11438                                                                                         }
11439                                                                         }
11440
11441                                                                         loading=2;
11442                                                                         loadtime=0;
11443                                                                         targetlevel=7;
11444                                                                         //if(firstload)TickOnceAfter();
11445                                                                         if(!firstload)LoadStuff();
11446                                                                         //else {
11447                                                                         for(i=0;i<255;i++){
11448                                                                                 mapname[i]='\0';
11449                                                                         }
11450                                                                         mapname[0]=':';
11451                                                                         mapname[1]='D';
11452                                                                         mapname[2]='a';
11453                                                                         mapname[3]='t';
11454                                                                         mapname[4]='a';
11455                                                                         mapname[5]=':';
11456                                                                         mapname[6]='M';
11457                                                                         mapname[7]='a';
11458                                                                         mapname[8]='p';
11459                                                                         mapname[9]='s';
11460                                                                         mapname[10]=':';
11461
11462                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11463                                                                         //accountcampaignchoicesmade[accountactive]++;
11464
11465
11466                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11467                                                                         whichchoice=0;
11468                                                                         visibleloading=1;
11469                                                                         stillloading=1;
11470                                                                         Loadlevel(mapname);
11471                                                                         campaign=1;
11472                                                                         mainmenu=0;
11473                                                                         gameon=1;
11474                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11475
11476                                                                         stealthloading=0;
11477                                                         }
11478
11479                                                         if(loading==3)loading=0;
11480
11481                                         }
11482
11483                                         oldmusictype=musictype;
11484         }
11485
11486         facing=0;
11487         facing.z=-1;
11488
11489         facing=DoRotation(facing,-rotation2,0,0);
11490         facing=DoRotation(facing,0,0-rotation,0);
11491         viewerfacing=facing;
11492
11493         brotate=0;
11494         if(!cameramode){
11495                 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;
11496                 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;
11497                 target.y+=.1;
11498                 if(player[0].skeleton.free){
11499                         for(i=0;i<player[0].skeleton.num_joints;i++){
11500                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11501                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11502                         }
11503                         target.y+=.1;
11504                 }
11505                 if(player[0].skeleton.free!=2&&!autocam){
11506                         cameraspeed=20;
11507                         if(findLengthfast(&player[0].velocity)>400){
11508                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11509                         }
11510                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11511                         coltarget=target-cameraloc;
11512                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11513                         else {
11514                                 Normalise(&coltarget);
11515                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11516                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11517                         }
11518                         if(editorenabled)cameraloc=target;
11519                         cameradist+=multiplier*5;
11520                         if(cameradist>2.3)cameradist=2.3;
11521                         viewer=cameraloc-facing*cameradist;
11522                         colviewer=viewer;
11523                         coltarget=cameraloc;
11524                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11525                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11526                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11527                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11528                                         colviewer=viewer;
11529                                         coltarget=cameraloc;
11530                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11531                                 }
11532                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11533                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11534                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11535                                                 colviewer=viewer;
11536                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11537                                                         viewer=colviewer;
11538                                                 }
11539                                         }
11540                                         cameradist=findDistance(&viewer,&target);
11541                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11542                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11543                                         }
11544                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11545                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11546                                         }
11547                 }
11548                 if(player[0].skeleton.free!=2&&autocam){
11549                         cameraspeed=20;
11550                         if(findLengthfast(&player[0].velocity)>400){
11551                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11552                         }
11553                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11554                         cameradist+=multiplier*5;
11555                         if(cameradist>3.3)cameradist=3.3;
11556                         coltarget=target-cameraloc;
11557                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11558                         else if(findLengthfast(&coltarget)>1)
11559                         {
11560                                 Normalise(&coltarget);
11561                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11562                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11563                         }
11564                         if(editorenabled)cameraloc=target;
11565                         viewer=cameraloc;
11566                         colviewer=viewer;
11567                         coltarget=cameraloc;
11568                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11569                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11570                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11571                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11572                                         colviewer=viewer;
11573                                         coltarget=cameraloc;
11574                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11575                                 }
11576                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11577                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11578                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11579                                                 colviewer=viewer;
11580                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11581                                                         viewer=colviewer;
11582                                                 }
11583                                         }
11584                                         cameradist=findDistance(&viewer,&target);
11585                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11586                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11587                                         }
11588                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11589                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11590                                         }
11591                 }
11592                 if(camerashake>.8)camerashake=.8;
11593                 //if(woozy>10)woozy=10;
11594                 //woozy+=multiplier;
11595                 woozy+=multiplier;
11596                 if(player[0].dead)camerashake=0;
11597                 if(player[0].dead)woozy=0;
11598                 camerashake-=multiplier*2;
11599                 blackout-=multiplier*2;
11600                 //if(player[0].isCrouch())woozy-=multiplier*8;
11601                 if(camerashake<0)camerashake=0;
11602                 if(blackout<0)blackout=0;
11603                 //if(woozy<0)woozy=0;
11604                 if(camerashake){
11605                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11606                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11607                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11608                 }
11609         }
11610 }