]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
5a22e08414398df609904e75c23c83ba44fe1f02
[lugaru.git] / Source / GameTick.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #if PLATFORM_UNIX
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #else
27 #include <direct.h>
28 #endif
29
30 #include <ctime>
31 #include "Game.h"
32 #include "openal_wrapper.h"
33
34 using namespace std;
35
36 extern float multiplier;
37 extern XYZ viewer;
38 extern int environment;
39 extern float texscale;
40 extern Terrain terrain;
41 extern OPENAL_SAMPLE    *samp[100];
42 extern int channels[100];
43 extern Sprites sprites;
44 extern int kTextureSize;
45 extern float screenwidth,screenheight;
46 extern float gravity;
47 extern int detail;
48 extern float texdetail;
49 extern Objects objects;
50 extern int slomo;
51 extern float slomodelay;
52 extern bool floatjump;
53 extern float volume;
54 extern Animation animation[animation_count];
55 extern Light light;
56 extern float texdetail;
57 extern GLubyte bloodText[512*512*3];
58 extern GLubyte wolfbloodText[512*512*3];
59 extern float terraindetail;
60 extern float camerashake;
61 extern float woozy;
62 extern float blackout;
63 extern bool cellophane;
64 extern bool musictoggle;
65 extern int difficulty;
66 extern Weapons weapons;
67 extern Person player[maxplayers];
68 extern int numplayers;
69 extern int bloodtoggle;
70 extern bool invertmouse;
71 extern float windvar;
72 extern float precipdelay;
73 extern XYZ viewerfacing;
74 extern bool ambientsound;
75 extern bool mousejump;
76 extern float viewdistance;
77 extern bool freeze;
78 extern bool autoslomo;
79 extern bool keyboardfrozen;
80 extern int netdatanew;
81 extern bool loadingstuff;
82 extern char mapname[256];
83 extern XYZ windvector;
84 extern bool buttons[3];
85 extern bool debugmode;
86 static int music1;
87 extern int mainmenu;
88 extern int oldmainmenu;
89 extern bool visibleloading;
90 extern int loadscreencolor;
91 extern float flashamount,flashr,flashg,flashb;
92 extern int flashdelay;
93 extern XYZ envsound[30];
94 extern float envsoundvol[30];
95 extern int numenvsounds;
96 extern float envsoundlife[30];
97 extern float usermousesensitivity;
98 extern bool ismotionblur;
99 extern bool foliage;
100 extern bool trilinear;
101 extern bool damageeffects;
102 extern bool showpoints;
103 extern bool texttoggle;
104 extern bool alwaysblur;
105 extern float gamespeed;
106 extern bool decals;
107 extern bool vblsync;
108 extern bool immediate;
109 extern bool velocityblur;
110 extern int bonus;
111 extern int oldbonus;
112 extern float bonusvalue;
113 extern float bonustotal;
114 extern float bonustime;
115 extern float startbonustotal;
116 extern float tintr,tintg,tintb;
117 extern float bonusnum[100];
118 extern bool skyboxtexture;
119 extern float skyboxr;
120 extern float skyboxg;
121 extern float skyboxb;
122 extern float skyboxlightr;
123 extern float skyboxlightg;
124 extern float skyboxlightb;
125 extern float fadestart;
126 extern float slomospeed;
127 extern float slomofreq;
128 extern int tutoriallevel;
129 extern float smoketex;
130 extern float tutorialstagetime;
131 extern int tutorialstage;
132 extern float tutorialmaxtime;
133 extern float tutorialsuccess;
134 extern bool againbonus;
135 extern bool reversaltrain;
136 extern bool canattack;
137 extern bool cananger;
138 extern float damagedealt;
139 extern float damagetaken;
140 extern int maptype;
141 extern int editoractive;
142 extern int editorpathtype;
143 extern bool oldbuttons[3];
144
145 extern float hostiletime;
146
147 extern bool gamestarted;
148
149 extern int numhotspots;
150 extern int winhotspot;
151 extern int windialogue;
152 extern int killhotspot;
153 extern XYZ hotspot[40];
154 extern int hotspottype[40];
155 extern float hotspotsize[40];
156 extern char hotspottext[40][256];
157 extern int currenthotspot;
158
159 extern int kBitsPerPixel;
160 extern int hostile;
161
162 extern int numaccounts;
163 extern int accountactive;
164 extern int accountdifficulty[10];
165 extern int accountprogress[10];
166 extern float accountpoints[10];
167 extern float accounthighscore[10][50];
168 extern float accountfasttime[10][50];
169 extern bool accountunlocked[10][60];
170 extern char accountname[10][256];
171
172 extern bool stillloading;
173 extern bool winfreeze;
174
175 extern int numfalls;
176 extern int numflipfail;
177 extern int numseen;
178 extern int numstaffattack;
179 extern int numswordattack;
180 extern int numknifeattack;
181 extern int numunarmedattack;
182 extern int numescaped;
183 extern int numflipped;
184 extern int numwallflipped;
185 extern int numthrowkill;
186 extern int numafterkill;
187 extern int numreversals;
188 extern int numattacks;
189 extern int maxalarmed;
190 extern int numresponded;
191
192 extern int numdialogues;
193 extern int numdialogueboxes[max_dialogues];
194 extern int dialoguetype[max_dialogues];
195 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
196 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
197 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
198 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
199 extern char dialoguename[max_dialogues][max_dialoguelength][64];
200 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
201 extern XYZ participantlocation[max_dialogues][10];
202 extern int participantfocus[max_dialogues][max_dialoguelength];
203 extern int participantaction[max_dialogues][max_dialoguelength];
204 extern float participantrotation[max_dialogues][10];
205 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
206 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
207 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
208 extern int indialogue;
209 extern int whichdialogue;
210 extern int directing;
211 extern float dialoguetime;
212 extern int dialoguegonethrough[20];
213
214 extern bool campaign;
215
216 extern float oldgamespeed;
217
218 extern float accountcampaignhighscore[10];
219 extern float accountcampaignfasttime[10];
220 extern float accountcampaignscore[10];
221 extern float accountcampaigntime[10];
222
223 extern int accountcampaignchoicesmade[10];
224 extern int accountcampaignchoices[10][5000];
225 /********************> Tick() <*****/
226 extern OPENAL_STREAM * strm[20];
227 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
228 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
229
230 extern void ScreenShot(const char * fname);
231 void Screenshot (void)
232 {
233         char temp[1024];
234         time_t  t = time(NULL);
235         struct  tm *tme = localtime(&t);
236         sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
237
238         #if defined(_WIN32)
239         mkdir("Screenshots");
240         #else
241         mkdir("Screenshots", S_IRWXU);
242         #endif
243
244         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
245
246         /*FSSpec                                MAC_file;
247         GraphicsExportComponent QT_exporter;
248         OSErr                           MAC_error_code;
249         CGrafPtr                        MAC_currentPort;
250         GDHandle                        MAC_currentDevice;
251         unsigned char*          MAC_pixels;
252         Rect                            MAC_picture_rectangle;
253         GWorldPtr                       MAC_offscreen_graphics_port;
254
255         static int numscreenshots=0;
256
257         // Make an FSSpec
258         static char buf[256];
259         if(numscreenshots==0){
260         buf[0]=26;
261         buf[1]=':';
262         buf[2]='S';
263         buf[3]='c';
264         buf[4]='r';
265         buf[5]='e';
266         buf[6]='e';
267         buf[7]='n';
268         buf[8]='s';
269         buf[9]='h';
270         buf[10]='o';
271         buf[11]='t';
272         buf[12]='s';
273         buf[13]=':';
274         buf[14]='S';
275         buf[15]='c';
276         buf[16]='r';
277         buf[17]='e';
278         buf[18]='e';
279         buf[19]='n';
280         buf[20]='s';
281         buf[21]='h';
282         buf[22]='o';
283         buf[23]='t';
284         buf[24]='0';
285         buf[25]='0';
286         buf[26]='0';
287         }
288
289         FInfo *fndrInfo;
290         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
291         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
292         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
293         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
294         numscreenshots++;
295         buf[26]++;
296         if(buf[26]==':'){
297         buf[26]='0';
298         buf[25]++;
299         if(buf[25]==':'){
300         buf[25]='0';
301         buf[24]++;
302         if(buf[24]==':'){
303         buf[24]='9';
304         buf[25]='9';
305         buf[26]='9';
306         }
307         }
308         }
309         }
310         }
311
312
313         // Get the GWorld
314         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
315         //assert(MAC_gWorld != NULL);
316
317         // Allocate memory for loading image
318         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
319         if (MAC_pixels == NULL) {
320         //UTIL_Error("Could not create Texture data.");
321         return;
322         }
323
324         // Get GWorld
325         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
326
327         // Make a picture Rectangle
328         MAC_picture_rectangle.left = 0;
329         MAC_picture_rectangle.right = screenwidth;
330         MAC_picture_rectangle.top = 0;
331         MAC_picture_rectangle.bottom = screenheight;
332
333         // Create new offscreen GWorld
334         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
335         if (MAC_error_code)     {
336         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
337         delete MAC_pixels;
338         //UTIL_Error("Could not create offscreen GWorld. ");
339         return;
340
341         }
342
343         // Copy OpenGL Context to new GWorld
344         glReadBuffer(GL_FRONT);
345         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
346
347         // Swizzle texture
348         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
349         unsigned char temp = MAC_pixels[byte+0];
350         MAC_pixels[byte+0] = MAC_pixels[byte+3];
351         MAC_pixels[byte+3] = MAC_pixels[byte+2];
352         MAC_pixels[byte+2] = MAC_pixels[byte+1];
353         MAC_pixels[byte+1] = temp;
354         }
355
356         // Flip the image  :(   This could probably be optimized
357         int vert;
358         int src_index;
359         int dst_index;
360         unsigned char temp;
361         for (int horz = 0; horz < screenwidth; ++horz)
362         for (vert = 0; vert < screenheight / 2; ++vert) {
363         src_index = (screenwidth * vert + horz) * 4;
364         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
365
366         temp=MAC_pixels[src_index+0];
367         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
368         MAC_pixels[dst_index+0]=temp;
369
370         temp=MAC_pixels[src_index+1];
371         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
372         MAC_pixels[dst_index+1]=temp;
373
374         temp=MAC_pixels[src_index+2];
375         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
376         MAC_pixels[dst_index+2]=temp;
377
378         temp=MAC_pixels[src_index+3];
379         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
380         MAC_pixels[dst_index+3]=temp;
381         }
382
383
384
385         // Export the Gworld
386         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
387         if (MAC_error_code) {
388         //UTIL_Warning("Unable to export screenshot.");
389         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
390         ::DisposeGWorld(MAC_offscreen_graphics_port);
391         delete MAC_pixels;
392         return;
393         }
394
395         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
396         if (MAC_error_code) {
397         ::CloseComponent(QT_exporter);
398         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
399         ::DisposeGWorld(MAC_offscreen_graphics_port);
400         delete MAC_pixels;
401         //UTIL_Warning("Unable to export screenshot.");
402         return;
403         }
404
405         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
406         if (MAC_error_code) {
407         ::CloseComponent(QT_exporter);
408         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
409         ::DisposeGWorld(MAC_offscreen_graphics_port);
410         delete MAC_pixels;
411         //UTIL_Warning("Unable to export screenshot.");
412         return;
413         }
414
415         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
416         if (MAC_error_code) {
417         ::CloseComponent(QT_exporter);
418         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
419         ::DisposeGWorld(MAC_offscreen_graphics_port);
420         delete MAC_pixels;
421         //UTIL_Warning("Unable to export screenshot.");
422         return;
423         }
424
425         ::CloseComponent(QT_exporter);
426         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
427         ::DisposeGWorld(MAC_offscreen_graphics_port);
428
429         delete MAC_pixels;*/
430 }
431
432
433
434 void    Game::SetUpLighting(){
435         if(environment==snowyenvironment){
436                 light.color[0]=.65;
437                 light.color[1]=.65;
438                 light.color[2]=.7;
439                 light.ambient[0]=.4;
440                 light.ambient[1]=.4;
441                 light.ambient[2]=.44;
442         }
443         if(environment==desertenvironment){
444                 light.color[0]=.95;
445                 light.color[1]=.95;
446                 light.color[2]=.95;
447                 light.ambient[0]=.4;
448                 light.ambient[1]=.35;
449                 light.ambient[2]=.3;
450         }
451
452         if(environment==grassyenvironment){
453                 light.color[0]=.95;
454                 light.color[1]=.95;
455                 light.color[2]=1;
456                 light.ambient[0]=.4;
457                 light.ambient[1]=.4;
458                 light.ambient[2]=.44;
459         }
460         if(!skyboxtexture){
461                 light.color[0]=1;
462                 light.color[1]=1;
463                 light.color[2]=1;
464                 light.ambient[0]=.4;
465                 light.ambient[1]=.4;
466                 light.ambient[2]=.4;
467         }
468         float average;
469         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
470         light.color[0]*=(skyboxlightr+average)/2;
471         light.color[1]*=(skyboxlightg+average)/2;
472         light.color[2]*=(skyboxlightb+average)/2;
473         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
474         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
475         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
476         /*
477         light.ambient[0]=0;
478         light.ambient[1]=0;
479         light.ambient[2]=0;     */
480 }
481
482 int Game::findPathDist(int start,int end){
483         int i,j,k,smallestcount,count,connected;
484         int last,last2,last3,last4;
485         int closest;
486
487         smallestcount=1000;
488         for(i=0;i<50;i++){
489                 count=0;
490                 last=start;
491                 last2=-1;
492                 last3=-1;
493                 last4=-1;
494                 while(last!=end&&count<30){
495                         closest=-1;
496                         for(j=0;j<numpathpoints;j++){
497                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
498                                 {
499                                         connected=0;
500                                         if(numpathpointconnect[j])
501                                                 for(k=0;k<numpathpointconnect[j];k++){
502                                                         if(pathpointconnect[j][k]==last)connected=1;
503                                                 }
504                                                 if(!connected)
505                                                         if(numpathpointconnect[last])
506                                                                 for(k=0;k<numpathpointconnect[last];k++){
507                                                                         if(pathpointconnect[last][k]==j)connected=1;
508                                                                 }
509                                                                 if(connected)
510                                                                         if(closest==-1||Random()%2==0){
511                                                                                 closest=j;
512                                                                         }
513                                 }
514                         }
515                         last4=last3;
516                         last3=last2;
517                         last2=last;
518                         last=closest;
519                         count++;
520                 }
521                 if(count<smallestcount)smallestcount=count;
522         }
523         return smallestcount;
524 }
525
526 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
527         static XYZ colpoint,colviewer,coltarget;
528         static float minx,minz,maxx,maxz,miny,maxy;
529         static int i;
530
531         //startpoint.y+=.7;
532         //endpoint.y+=.7;
533         //startpoint.y-=.1;
534         //endpoint.y-=.1;
535
536         minx=startpoint.x;
537         if(minx>endpoint.x)minx=endpoint.x;
538         miny=startpoint.y;
539         if(miny>endpoint.y)miny=endpoint.y;
540         minz=startpoint.z;
541         if(minz>endpoint.z)minz=endpoint.z;
542
543         maxx=startpoint.x;
544         if(maxx<endpoint.x)maxx=endpoint.x;
545         maxy=startpoint.y;
546         if(maxy<endpoint.y)maxy=endpoint.y;
547         maxz=startpoint.z;
548         if(maxz<endpoint.z)maxz=endpoint.z;
549
550         minx-=1;
551         miny-=1;
552         minz-=1;
553         maxx+=1;
554         maxy+=1;
555         maxz+=1;
556
557         for(i=0;i<objects.numobjects;i++){
558                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
559                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
560                                 colviewer=startpoint;
561                                 coltarget=endpoint;
562                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
563                         }
564                 }
565         }
566
567         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
568
569         return -1;
570 }
571
572 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
573         static XYZ colpoint,colviewer,coltarget;
574         static float minx,minz,maxx,maxz,miny,maxy;
575         static int i;
576
577         //startpoint.y+=.7;
578         //endpoint.y+=.7;
579         //startpoint.y-=.1;
580         //endpoint.y-=.1;
581
582         minx=startpoint.x;
583         if(minx>endpoint.x)minx=endpoint.x;
584         miny=startpoint.y;
585         if(miny>endpoint.y)miny=endpoint.y;
586         minz=startpoint.z;
587         if(minz>endpoint.z)minz=endpoint.z;
588
589         maxx=startpoint.x;
590         if(maxx<endpoint.x)maxx=endpoint.x;
591         maxy=startpoint.y;
592         if(maxy<endpoint.y)maxy=endpoint.y;
593         maxz=startpoint.z;
594         if(maxz<endpoint.z)maxz=endpoint.z;
595
596         minx-=1;
597         miny-=1;
598         minz-=1;
599         maxx+=1;
600         maxy+=1;
601         maxz+=1;
602
603         if(what!=1000){
604                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
605                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
606                                 colviewer=startpoint;
607                                 coltarget=endpoint;
608                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
609                         }
610                 }
611         }
612
613         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
614
615         return -1;
616 }
617
618 void    Game::Setenvironment(int which)
619 {
620         LOGFUNC;
621
622         LOG(" Setting environment...");
623
624         float temptexdetail;
625         environment=which;
626 /*
627         OPENAL_SetPaused(channels[music1snow], true);
628         OPENAL_SetPaused(channels[music1grass], true);
629         OPENAL_SetPaused(channels[music1desert], true);
630         OPENAL_SetPaused(channels[wind], true);
631         OPENAL_SetPaused(channels[desertambient], true);
632 */
633         OPENAL_SetPaused(channels[stream_music1snow], true);
634         OPENAL_SetPaused(channels[stream_music1grass], true);
635         OPENAL_SetPaused(channels[stream_music1desert], true);
636         OPENAL_SetPaused(channels[stream_wind], true);
637         OPENAL_SetPaused(channels[stream_desertambient], true);
638
639
640         if(environment==snowyenvironment){
641                 windvector=0;
642                 windvector.z=3;
643                 if(ambientsound){
644                         //PlaySoundEx( wind, samp[wind], NULL, true);
645                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
646                         OPENAL_SetPaused(channels[stream_wind], false);
647                         OPENAL_SetVolume(channels[stream_wind], 256);
648                 }
649
650                 LoadTexture("/Data/Textures/snowtree.png",&objects.treetextureptr,0,1);
651                 LoadTexture("/Data/Textures/bushsnow.png",&objects.bushtextureptr,0,1);
652                 LoadTexture("/Data/Textures/bouldersnow.jpg",&objects.rocktextureptr,1,0);
653                 LoadTexture("/Data/Textures/snowbox.jpg",&objects.boxtextureptr,1,0);
654
655                 OPENAL_Sample_Free(samp[footstepsound]);
656                 OPENAL_Sample_Free(samp[footstepsound2]);
657                 OPENAL_Sample_Free(samp[footstepsound3]);
658                 OPENAL_Sample_Free(samp[footstepsound4]);
659                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
660                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
661                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepstone1.ogg", OPENAL_HW3D, 0, 0);
662                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepstone2.ogg", OPENAL_HW3D, 0, 0);
663                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
664                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
665                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
666                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
667
668                 LoadTexture("/Data/Textures/snow.jpg",&terraintexture,1,0);
669
670                 LoadTexture("/Data/Textures/rock.jpg",&terraintexture2,1,0);
671
672                 //LoadTexture("/Data/Textures/detailgrain.png",&terraintexture3,1);
673
674
675
676
677                 temptexdetail=texdetail;
678                 if(texdetail>1)texdetail=4;
679                 skybox.load(    "/Data/Textures/Skybox(snow):Front.jpg",
680                         "/Data/Textures/Skybox(snow):Left.jpg",
681                         "/Data/Textures/Skybox(snow):Back.jpg",
682                         "/Data/Textures/Skybox(snow):Right.jpg",
683                         "/Data/Textures/Skybox(snow):Up.jpg",
684                         "/Data/Textures/Skybox(snow):Down.jpg",
685                         "/Data/Textures/Skybox(snow):Cloud.jpg",
686                         "/Data/Textures/Skybox(snow):Reflect.jpg");
687
688
689
690
691                 texdetail=temptexdetail;
692         }
693         if(environment==desertenvironment){
694                 windvector=0;
695                 windvector.z=2;
696                 LoadTexture("/Data/Textures/deserttree.png",&objects.treetextureptr,0,1);
697                 LoadTexture("/Data/Textures/bushdesert.png",&objects.bushtextureptr,0,1);
698                 LoadTexture("/Data/Textures/boulderdesert.jpg",&objects.rocktextureptr,1,0);
699                 LoadTexture("/Data/Textures/desertbox.jpg",&objects.boxtextureptr,1,0);
700
701
702                 if(ambientsound){
703                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
704                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
705                         OPENAL_SetPaused(channels[stream_desertambient], false);
706                         OPENAL_SetVolume(channels[stream_desertambient], 256);
707                 }
708
709                 OPENAL_Sample_Free(samp[footstepsound]);
710                 OPENAL_Sample_Free(samp[footstepsound2]);
711                 OPENAL_Sample_Free(samp[footstepsound3]);
712                 OPENAL_Sample_Free(samp[footstepsound4]);
713                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
714                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
715                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
716                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
717                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
718                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
719                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
720                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
721
722                 LoadTexture("/Data/Textures/sand.jpg",&terraintexture,1,0);
723
724                 LoadTexture("/Data/Textures/sandslope.jpg",&terraintexture2,1,0);
725
726                 //LoadTexture("/Data/Textures/detailgrain.png",&terraintexture3,1);
727
728
729
730                 temptexdetail=texdetail;
731                 if(texdetail>1)texdetail=4;
732                 skybox.load(    "/Data/Textures/Skybox(sand):Front.jpg",
733                         "/Data/Textures/Skybox(sand):Left.jpg",
734                         "/Data/Textures/Skybox(sand):Back.jpg",
735                         "/Data/Textures/Skybox(sand):Right.jpg",
736                         "/Data/Textures/Skybox(sand):Up.jpg",
737                         "/Data/Textures/Skybox(sand):Down.jpg",
738                         "/Data/Textures/Skybox(sand):Cloud.jpg",
739                         "/Data/Textures/Skybox(sand):Reflect.jpg");
740
741
742
743
744                 texdetail=temptexdetail;
745         }
746         if(environment==grassyenvironment){
747                 windvector=0;
748                 windvector.z=2;
749                 LoadTexture("/Data/Textures/tree.png",&objects.treetextureptr,0,1);
750                 LoadTexture("/Data/Textures/bush.png",&objects.bushtextureptr,0,1);
751                 LoadTexture("/Data/Textures/boulder.jpg",&objects.rocktextureptr,1,0);
752                 LoadTexture("/Data/Textures/grassbox.jpg",&objects.boxtextureptr,1,0);
753
754                 if(ambientsound){
755                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
756                         OPENAL_SetPaused(channels[stream_wind], false);
757                         OPENAL_SetVolume(channels[stream_wind], 100);
758                 }
759
760                 OPENAL_Sample_Free(samp[footstepsound]);
761                 OPENAL_Sample_Free(samp[footstepsound2]);
762                 OPENAL_Sample_Free(samp[footstepsound3]);
763                 OPENAL_Sample_Free(samp[footstepsound4]);
764                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepgrass1.ogg", OPENAL_HW3D, 0, 0);
765                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepgrass2.ogg", OPENAL_HW3D, 0, 0);
766                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepstone1.ogg", OPENAL_HW3D, 0, 0);
767                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, "/Data/Sounds/footstepstone2.ogg", OPENAL_HW3D, 0, 0);
768                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
769                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
770                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
771                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
772
773                 LoadTexture("/Data/Textures/grassdirt.jpg",&terraintexture,1,0);
774
775                 LoadTexture("/Data/Textures/mossrock.jpg",&terraintexture2,1,0);
776
777                 //LoadTexture("/Data/Textures/detail.png",&terraintexture3,1);
778
779
780
781                 temptexdetail=texdetail;
782                 if(texdetail>1)texdetail=4;
783                 skybox.load(    "/Data/Textures/Skybox(grass):Front.jpg",
784                         "/Data/Textures/Skybox(grass):Left.jpg",
785                         "/Data/Textures/Skybox(grass):Back.jpg",
786                         "/Data/Textures/Skybox(grass):Right.jpg",
787                         "/Data/Textures/Skybox(grass):Up.jpg",
788                         "/Data/Textures/Skybox(grass):Down.jpg",
789                         "/Data/Textures/Skybox(grass):Cloud.jpg",
790                         "/Data/Textures/Skybox(grass):Reflect.jpg");
791
792
793
794                 texdetail=temptexdetail;
795         }
796         temptexdetail=texdetail;
797         texdetail=1;
798         terrain.load("/Data/Textures/heightmap.png");
799
800         texdetail=temptexdetail;
801 }
802
803
804 void    Game::Loadlevel(int which){
805         stealthloading=0;
806
807         if(which==0)Loadlevel((char *)"/Data/Maps/map1");
808         else if(which==1)Loadlevel((char *)"/Data/Maps/map2");
809         else if(which==2)Loadlevel((char *)"/Data/Maps/map3");
810         else if(which==3)Loadlevel((char *)"/Data/Maps/map4");
811         else if(which==4)Loadlevel((char *)"/Data/Maps/map5");
812         else if(which==5)Loadlevel((char *)"/Data/Maps/map6");
813         else if(which==6)Loadlevel((char *)"/Data/Maps/map7");
814         else if(which==7)Loadlevel((char *)"/Data/Maps/map8");
815         else if(which==8)Loadlevel((char *)"/Data/Maps/map9");
816         else if(which==9)Loadlevel((char *)"/Data/Maps/map10");
817         else if(which==10)Loadlevel((char *)"/Data/Maps/map11");
818         else if(which==11)Loadlevel((char *)"/Data/Maps/map12");
819         else if(which==12)Loadlevel((char *)"/Data/Maps/map13");
820         else if(which==13)Loadlevel((char *)"/Data/Maps/map14");
821         else if(which==14)Loadlevel((char *)"/Data/Maps/map15");
822         else if(which==15)Loadlevel((char *)"/Data/Maps/map16");
823         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)"/Data/Maps/tutorial");}
824         else Loadlevel((char *)"/Data/Maps/mapsave");
825
826         whichlevel=which;
827 }
828
829 /*char * Game::MD5_string (unsigned char *string){
830 char temp[50];
831 char temp2[100];
832
833 strcpy(temp2,(const char *)string);
834 strcat((char *)temp2,(const char *)"Lugaru");
835 sprintf (temp, "%d",strlen((char *)temp2));
836 strcat((char *)temp2,temp);
837
838 MD5 context;
839 unsigned int len = strlen ( (char *)temp2);
840
841 context.update   ((unsigned char *)temp2, len);
842 context.finalize ();
843
844 return context.hex_digest();
845 }*/
846
847
848
849 void    Game::Loadlevel(char *name){
850         int i,j,k,l,m;
851         static int oldlevel;
852         int templength;
853         float lamefloat;
854         int lameint;
855
856         float headprop,legprop,armprop,bodyprop;
857
858         LOGFUNC;
859
860         LOG(std::string("Loading level...") + name);
861
862         if(!gameon)visibleloading=1;
863
864         if(stealthloading)visibleloading=0;
865
866         if(!stillloading)loadtime=0;
867         gamestarted=1;
868
869         numenvsounds=0;
870         //visibleloading=1;
871         if(tutoriallevel!=-1)tutoriallevel=0;
872         else tutoriallevel=1;
873
874         if(tutoriallevel==1)tutorialstage=0;
875         if(tutorialstage==0){
876                 tutorialstagetime=0;
877                 tutorialmaxtime=1;
878         }
879         loadingstuff=1;
880         if(!firstload){
881                 oldlevel=50;
882         }
883         OPENAL_SetPaused(channels[whooshsound], true);
884         OPENAL_SetPaused(channels[stream_firesound], true);
885
886         int mapvers;
887         FILE                    *tfile;
888         tfile=fopen( name, "rb" );
889         if(tfile)
890         {
891                 OPENAL_SetPaused(channels[stream_firesound], true);
892
893
894                 scoreadded=0;
895                 windialogue=0;
896
897                 hostiletime=0;
898
899                 won=0;
900
901                 //campaign=0;
902                 animation[bounceidleanim].Load((char *)"/Data/Animations/Idle",middleheight,neutral);
903
904                 numdialogues=0;
905
906                 for(i=0;i<20;i++)
907                 {
908                         dialoguegonethrough[i]=0;
909                 }
910
911                 indialogue=-1;
912                 cameramode=0;
913
914                 damagedealt=0;
915                 damagetaken=0;
916
917                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
918
919                 if(difficulty!=2)minimap=1;
920                 else minimap=0;
921
922                 numhotspots=0;
923                 currenthotspot=-1;
924                 bonustime=1;
925
926                 skyboxtexture=1;
927                 skyboxr=1;
928                 skyboxg=1;
929                 skyboxb=1;
930
931                 freeze=0;
932                 winfreeze=0;
933
934                 for(i=0;i<100;i++)
935                 {
936                         bonusnum[i]=0;
937                 }
938
939                 numfalls=0;
940                 numflipfail=0;
941                 numseen=0;
942                 numstaffattack=0;
943                 numswordattack=0;
944                 numknifeattack=0;
945                 numunarmedattack=0;
946                 numescaped=0;
947                 numflipped=0;
948                 numwallflipped=0;
949                 numthrowkill=0;
950                 numafterkill=0;
951                 numreversals=0;
952                 numattacks=0;
953                 maxalarmed=0;
954                 numresponded=0;
955
956                 bonustotal=startbonustotal;
957                 bonus=0;
958                 gameon=1;
959                 changedelay=0;
960                 if(console)
961                 {
962                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
963                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
964                         OPENAL_SetPaused(channels[consolesuccesssound], false);
965                         freeze=0;
966                         console=0;
967                 }
968
969                 if(!stealthloading)
970                 {
971                         terrain.numdecals=0;
972                         sprites.numsprites=0;
973                         for(i=0;i<objects.numobjects;i++)
974                         {
975                                 objects.model[i].numdecals=0;
976                         }
977
978                         j=objects.numobjects;
979                         for(i=0;i<j;i++)
980                         {
981                                 objects.DeleteObject(0);
982                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
983                         }
984
985                         for(i=0;i<subdivision;i++)
986                         {
987                                 for(j=0;j<subdivision;j++)
988                                 {
989                                         terrain.patchobjectnum[i][j]=0;
990                                 }
991                         }
992                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
993                 }
994
995                 weapons.numweapons=0;
996
997                 funpackf(tfile, "Bi", &mapvers);
998                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
999                 else indemo=0;
1000                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1001                 else maptype=mapkilleveryone;
1002                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1003                 else hostile=1;
1004                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1005                 else
1006                 {
1007                         viewdistance=100;
1008                         fadestart=.6;
1009                 }
1010                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1011                 else
1012                 {
1013                         skyboxtexture=1;
1014                         skyboxr=1;
1015                         skyboxg=1;
1016                         skyboxb=1;
1017                 }
1018                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1019                 else
1020                 {
1021                         skyboxlightr=skyboxr;
1022                         skyboxlightg=skyboxg;
1023                         skyboxlightb=skyboxb;
1024                 }
1025                 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);
1026                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1027                 player[0].originalcoords=player[0].coords;
1028                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1029                 {
1030                         for(j=0;j<player[0].num_weapons;j++)
1031                         {
1032                                 player[0].weaponids[j]=weapons.numweapons;
1033                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1034                                 weapons.owner[weapons.numweapons]=0;
1035                                 weapons.numweapons++;
1036                         }
1037                 }
1038
1039                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1040
1041                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1042                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1043                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1044                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1045
1046                 funpackf(tfile, "Bi", &player[0].numclothes);
1047
1048                 if(mapvers>=9)
1049                 {
1050                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1051                 }
1052                 else
1053                 {
1054                         player[0].whichskin=0;
1055                         player[0].creature=rabbittype;
1056                 }
1057
1058                 for(i=0;i<max_dialogues;i++)
1059                 {
1060                         for(j=0;j<max_dialoguelength;j++)
1061                         {
1062                                 for(k=0;k<128;k++)
1063                                 {
1064                                         dialoguetext[i][j][k]='\0';
1065                                 }
1066                                 for(k=0;k<64;k++)
1067                                 {
1068                                         dialoguename[i][j][k]='\0';
1069                                 }
1070                         }
1071                 }
1072
1073                 player[0].lastattack=-1;
1074                 player[0].lastattack2=-1;
1075                 player[0].lastattack3=-1;
1076
1077                 if(mapvers>=8)
1078                 {
1079                         funpackf(tfile, "Bi", &numdialogues);
1080                         if(numdialogues)
1081                         {
1082                                 for(k=0;k<numdialogues;k++)
1083                                 {
1084                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1085                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1086                                         for(l=0;l<10;l++)
1087                                         {
1088                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1089                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1090                                         }
1091                                         if(numdialogueboxes)
1092                                         {
1093                                                 for(l=0;l<numdialogueboxes[k];l++)
1094                                                 {
1095                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1096                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1097                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1098                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1099                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1100
1101                                                         bool doneread;
1102
1103                                                         funpackf(tfile, "Bi",&templength);
1104                                                         if(templength>128||templength<=0)templength=128;
1105                                                         for(m=0;m<templength;m++){
1106                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1107                                                                 if(dialoguetext[k][l][m]=='\0')break;
1108                                                         }
1109
1110                                                         funpackf(tfile, "Bi",&templength);
1111                                                         if(templength>64||templength<=0)templength=64;
1112                                                         for(m=0;m<templength;m++){
1113                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1114                                                                 if(dialoguename[k][l][m]=='\0'){
1115                                                                         break;
1116                                                                 }
1117                                                         }
1118                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1119                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1120                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1121
1122                                                         for(m=0;m<10;m++)
1123                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1124
1125                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1126                                                 }
1127                                         }
1128                                 }
1129                         }
1130                 }
1131                 else numdialogues=0;
1132
1133                 if(player[0].numclothes)
1134                 {
1135                         for(k=0;k<player[0].numclothes;k++)
1136                         {
1137                                 funpackf(tfile, "Bi", &templength);
1138                                 for(l=0;l<templength;l++)
1139                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1140                                 player[0].clothes[k][templength]='\0';
1141                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1142                         }
1143                 }
1144
1145                 funpackf(tfile, "Bi", &environment);
1146
1147                 funpackf(tfile, "Bi", &objects.numobjects);
1148                 if(objects.numobjects)
1149                 {
1150                         for(i=0;i<objects.numobjects;i++)
1151                         {
1152                                 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]);
1153                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1154                         }
1155                 }
1156
1157                 if(mapvers>=7)
1158                 {
1159                         funpackf(tfile, "Bi", &numhotspots);
1160                         if(numhotspots)
1161                         {
1162                                 for(i=0;i<numhotspots;i++)
1163                                 {
1164                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1165                                         funpackf(tfile, "Bi", &templength);
1166                                         if(templength)
1167                                                 for(l=0;l<templength;l++)
1168                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1169                                         hotspottext[i][templength]='\0';
1170                                         if(hotspottype[i]==-111)indemo=1;
1171                                 }
1172                         }
1173                 }
1174                 else numhotspots=0;
1175
1176                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1177
1178                 if(!stealthloading)
1179                 {
1180                         objects.center=0;
1181                         for(i=0;i<objects.numobjects;i++)
1182                         {
1183                                 objects.center+=objects.position[i];
1184                         }
1185                         objects.center/=objects.numobjects;
1186
1187
1188                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1189
1190                         float maxdistance=0;
1191                         float tempdist;
1192                         int whichclosest;
1193                         for(i=0;i<objects.numobjects;i++)
1194                         {
1195                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1196                                 if(tempdist>maxdistance)
1197                                 {
1198                                         whichclosest=i;
1199                                         maxdistance=tempdist;
1200                                 }
1201                         }
1202                         objects.radius=fast_sqrt(maxdistance);
1203                 }
1204
1205                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1206                 //mapcenter=objects.center;
1207                 //mapradius=objects.radius;
1208
1209                 funpackf(tfile, "Bi", &numplayers);
1210                 int howmanyremoved=0;
1211                 bool removeanother=0;
1212                 if(numplayers>1&&numplayers<maxplayers)
1213                 {
1214                         for(i=1;i<numplayers;i++)
1215                         {
1216                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1217                                 removeanother=0;
1218
1219                                 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);
1220                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1221                                 else player[i-howmanyremoved].howactive=typeactive;
1222                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1223                                 else player[i-howmanyremoved].scale=-1;
1224                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1225                                 else player[i-howmanyremoved].immobile=0;
1226                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1227                                 else player[i-howmanyremoved].rotation=0;
1228                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1229                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1230                                         removeanother=1;
1231                                         howmanyremoved++;
1232                                 }
1233                                 if(!removeanother)
1234                                 {
1235                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1236                                         {
1237                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1238                                                 {
1239                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1240                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1241                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1242                                                         weapons.numweapons++;
1243                                                 }
1244                                         }
1245                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1246                                         //player[i-howmanyremoved].numwaypoints=10;
1247                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1248                                         {
1249                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1250                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1251                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1252                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1253                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1254                                         }
1255
1256                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1257                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1258
1259                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1260                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1261                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1262                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1263
1264                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1265                                         else
1266                                         {
1267                                                 headprop=1;
1268                                                 bodyprop=1;
1269                                                 armprop=1;
1270                                                 legprop=1;
1271                                         }
1272                                         if(player[i-howmanyremoved].creature==wolftype)
1273                                         {
1274                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1275                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1276                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1277                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1278                                         }
1279
1280                                         if(player[i-howmanyremoved].creature==rabbittype)
1281                                         {
1282                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1283                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1284                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1285                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1286                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1287                                         }
1288
1289                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1290                                         if(player[i-howmanyremoved].numclothes)
1291                                         {
1292                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1293                                                 {
1294                                                         int templength;
1295                                                         funpackf(tfile, "Bi", &templength);
1296                                                         for(l=0;l<templength;l++)
1297                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1298                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1299                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1300                                                 }
1301                                         }
1302                                 }
1303                         }
1304                 }
1305                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1306
1307                 numplayers-=howmanyremoved;
1308                 funpackf(tfile, "Bi", &numpathpoints);
1309                 if(numpathpoints>30||numpathpoints<0)
1310                         numpathpoints=0;
1311                 if(numpathpoints)
1312                 {
1313                         for(j=0;j<numpathpoints;j++)
1314                         {
1315                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1316                                 for(k=0;k<numpathpointconnect[j];k++){
1317                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1318                                 }
1319                         }
1320                 }
1321                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1322
1323                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1324
1325                 SetUpLighting();
1326                 if(environment!=oldenvironment)Setenvironment(environment);
1327                 oldenvironment=environment;
1328
1329                 if(!stealthloading)
1330                 {
1331                         j=objects.numobjects;
1332                         objects.numobjects=0;
1333                         for(i=0;i<j;i++)
1334                         {
1335                                 //if(objects.type[i]!=spiketype)
1336                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1337                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1338                         }
1339
1340                         //if(skyboxtexture){
1341                         terrain.DoShadows();
1342                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1343                         objects.DoShadows();
1344                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1345                         /*}
1346                         else terrain.DoLighting();
1347                         */
1348                 }
1349
1350                 fclose(tfile);
1351
1352                 oldlevel=whichlevel;
1353
1354
1355                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1356                 for(i=0;i<numplayers;i++)
1357                 {
1358                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1359                         player[i].burnt=0;
1360                         player[i].bled=0;
1361                         player[i].onfire=0;
1362                         if(i==0||player[i].scale<0)player[i].scale=.2;
1363                         player[i].skeleton.free=0;
1364                         player[i].skeleton.id=i;
1365                         //if(Random()%2==0)player[i].creature=wolftype;
1366                         //else player[i].creature=rabbittype;
1367                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1368                         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);
1369                         else
1370                         {
1371                                 if(player[i].creature!=wolftype){
1372                                         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);
1373                                         LoadTexture("/Data/Textures/Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1374                                 }
1375                                 if(player[i].creature==wolftype){
1376                                         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);
1377                                 }
1378                         }
1379
1380
1381                         int texsize;
1382                         texsize=512*512*3/texdetail/texdetail;
1383                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1384                         //player[i].skeleton.skinText.resize(texsize);
1385
1386                         if(player[i].creature==rabbittype)
1387                         {
1388                                 if(player[i].whichskin==0){
1389                                         LoadTextureSave("/Data/Textures/Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1390                                 }
1391                                 else if(player[i].whichskin==1){
1392                                         LoadTextureSave("/Data/Textures/Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1393                                 }
1394                                 else if(player[i].whichskin==2){
1395                                         LoadTextureSave("/Data/Textures/Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1396                                 }
1397                                 else if(player[i].whichskin==3){
1398                                         LoadTextureSave("/Data/Textures/Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1399                                 }
1400                                 else if(player[i].whichskin==4){
1401                                         LoadTextureSave("/Data/Textures/Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1402                                 }
1403                                 else if(player[i].whichskin==5){
1404                                         LoadTextureSave("/Data/Textures/Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1405                                 }
1406                                 else if(player[i].whichskin==6){
1407                                         LoadTextureSave("/Data/Textures/Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1408                                 }
1409                                 else if(player[i].whichskin==7){
1410                                         LoadTextureSave("/Data/Textures/Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1411                                 }
1412                                 else if(player[i].whichskin==8){
1413                                         LoadTextureSave("/Data/Textures/BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1414                                 }
1415                                 else if(player[i].whichskin==9){
1416                                         LoadTextureSave("/Data/Textures/WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1417                                 }
1418                         }
1419                         if(player[i].creature==wolftype)
1420                         {
1421                                 //k=abs(Random()%3);
1422                                 if(player[i].whichskin==0){
1423                                         LoadTextureSave("/Data/Textures/Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1424                                 }
1425                                 else if(player[i].whichskin==1){
1426                                         LoadTextureSave("/Data/Textures/Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1427                                 }
1428                                 else if(player[i].whichskin==2){
1429                                         LoadTextureSave("/Data/Textures/Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1430                                 }
1431                         }
1432
1433                         if(player[i].numclothes)
1434                         {
1435                                 for(j=0;j<player[i].numclothes;j++)
1436                                 {
1437                                         tintr=player[i].clothestintr[j];
1438                                         tintg=player[i].clothestintg[j];
1439                                         tintb=player[i].clothestintb[j];
1440                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1441                                 }
1442                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1443                         }
1444
1445                         player[i].currentanimation=bounceidleanim;
1446                         player[i].targetanimation=bounceidleanim;
1447                         player[i].currentframe=0;
1448                         player[i].targetframe=1;
1449                         player[i].target=0;
1450                         player[i].speed=1+(float)(Random()%100)/1000;
1451                         if(difficulty==0)player[i].speed-=.2;
1452                         if(difficulty==1)player[i].speed-=.1;
1453
1454                         player[i].velocity=0;
1455                         player[i].oldcoords=player[i].coords;
1456                         player[i].realoldcoords=player[i].coords;
1457
1458                         player[i].id=i;
1459                         player[i].skeleton.id=i;
1460                         player[i].updatedelay=0;
1461                         player[i].normalsupdatedelay=0;
1462
1463                         player[i].aitype=passivetype;
1464                         player[i].aitarget=0;
1465                         player[i].madskills=0;
1466
1467                         if(i==0)
1468                         {
1469                                 player[i].proportionhead=1.2;
1470                                 player[i].proportionbody=1.05;
1471                                 player[i].proportionarms=1.00;
1472                                 player[i].proportionlegs=1.1;
1473                                 player[i].proportionlegs.y=1.05;
1474                         }
1475                         player[i].headless=0;
1476                         player[i].currentoffset=0;
1477                         player[i].targetoffset=0;
1478                         /*player[i].armorhead=1;
1479                         player[i].armorhigh=1;
1480                         player[i].armorlow=1;
1481                         player[i].protectionhead=1;
1482                         player[i].protectionhigh=1;
1483                         player[i].protectionlow=1;
1484                         player[i].metalhead=1;
1485                         player[i].metalhigh=1;
1486                         player[i].metallow=1;
1487                         player[i].power=1;
1488                         player[i].speedmult=1;*/
1489
1490                         player[i].damagetolerance=200;
1491
1492                         if(player[i].creature==wolftype)
1493                         {
1494                                 /*player[i].proportionhead=1.1;
1495                                 player[i].proportionbody=1.1;
1496                                 player[i].proportionarms=1.1;
1497                                 player[i].proportionlegs=1.1;
1498                                 player[i].proportionlegs.y=1.1;*/
1499                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1500
1501                                 player[i].damagetolerance=300;
1502                         }
1503
1504                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1505                         if(cellophane)
1506                         {
1507                                 player[i].proportionhead.z=0;
1508                                 player[i].proportionbody.z=0;
1509                                 player[i].proportionarms.z=0;
1510                                 player[i].proportionlegs.z=0;
1511                         }
1512
1513                         player[i].tempanimation.Load((char *)"/Data/Animations/Tempanim",0,0);
1514
1515                         player[i].headmorphness=0;
1516                         player[i].targetheadmorphness=1;
1517                         player[i].headmorphstart=0;
1518                         player[i].headmorphend=0;
1519
1520                         player[i].pausetime=0;
1521
1522                         player[i].dead=0;
1523                         player[i].jumppower=5;
1524                         player[i].damage=0;
1525                         player[i].permanentdamage=0;
1526                         player[i].superpermanentdamage=0;
1527
1528                         player[i].forwardkeydown=0;
1529                         player[i].leftkeydown=0;
1530                         player[i].backkeydown=0;
1531                         player[i].rightkeydown=0;
1532                         player[i].jumpkeydown=0;
1533                         player[i].crouchkeydown=0;
1534                         player[i].throwkeydown=0;
1535
1536                         player[i].collided=-10;
1537                         player[i].loaded=1;
1538                         player[i].bloodloss=0;
1539                         player[i].weaponactive=-1;
1540                         player[i].weaponstuck=-1;
1541                         player[i].bleeding=0;
1542                         player[i].deathbleeding=0;
1543                         player[i].stunned=0;
1544                         player[i].hasvictim=0;
1545                         player[i].wentforweapon=0;
1546                 }
1547
1548                 player[0].aitype=playercontrolled;
1549                 player[0].weaponactive=-1;
1550
1551                 if(difficulty==1)
1552                 {
1553                         //player[0].speedmult=1/.9;
1554                         player[0].power=1/.9;
1555                 }
1556
1557                 if(difficulty==0)
1558                 {
1559                         //player[0].speedmult=1/.8;
1560                         player[0].power=1/.8;
1561                 }
1562
1563                 //player[0].weaponstuck=1;
1564
1565                 if(difficulty==1)player[0].damagetolerance=250;
1566                 if(difficulty==0)player[0].damagetolerance=300;
1567                 if(difficulty==0)player[0].armorhead*=1.5;
1568                 if(difficulty==0)player[0].armorhigh*=1.5;
1569                 if(difficulty==0)player[0].armorlow*=1.5;
1570                 cameraloc=player[0].coords;
1571                 cameraloc.y+=5;
1572                 rotation=player[0].rotation;
1573
1574                 hawkcoords=player[0].coords;
1575                 hawkcoords.y+=30;
1576
1577                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1578                 //weapons.numweapons=numplayers;
1579                 for(i=0;i<weapons.numweapons;i++)
1580                 {
1581                         weapons.bloody[i]=0;
1582                         weapons.blooddrip[i]=0;
1583                         weapons.blooddripdelay[i]=0;
1584                         weapons.onfire[i]=0;
1585                         weapons.flamedelay[i]=0;
1586                         weapons.damage[i]=0;
1587                         //weapons.type[i]=sword;
1588                         if(weapons.type[i]==sword){
1589                                 weapons.mass[i]=1.5;
1590                                 weapons.tipmass[i]=1;
1591                                 weapons.length[i]=.8;
1592                         }
1593                         if(weapons.type[i]==staff){
1594                                 weapons.mass[i]=2;
1595                                 weapons.tipmass[i]=1;
1596                                 weapons.length[i]=1.5;
1597                         }
1598                         if(weapons.type[i]==knife){
1599                                 weapons.mass[i]=1;
1600                                 weapons.tipmass[i]=1.2;
1601                                 weapons.length[i]=.25;
1602                         }
1603                         weapons.position[i]=-1000;
1604                         weapons.tippoint[i]=-1000;
1605                 }
1606
1607 /*              for(i=0;i<32;i++){
1608                         //if(i<16||i>20)
1609                         OPENAL_StopSound(i);
1610                 }
1611 */
1612                 LOG("Starting background music...");
1613
1614                 OPENAL_StopSound(OPENAL_ALL);
1615                 if(environment==snowyenvironment)
1616                 {
1617                         if(ambientsound)
1618                         {
1619                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1620                                 OPENAL_SetPaused(channels[stream_wind], false);
1621                                 OPENAL_SetVolume(channels[stream_wind], 256);
1622                         }
1623                 }
1624                 else if(environment==desertenvironment)
1625                 {
1626                         if(ambientsound)
1627                         {
1628                                 //PlaySoundEx(desertambient,
1629                                 //      samp[desertambient], NULL, true);
1630                                 PlayStreamEx(stream_desertambient,
1631                                         strm[stream_desertambient], NULL, true);
1632                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1633                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1634                         }
1635                 }
1636                 else if(environment==grassyenvironment)
1637                 {
1638                         if(ambientsound)
1639                         {
1640                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1641                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1642                                 OPENAL_SetPaused(channels[stream_wind], false);
1643                                 OPENAL_SetVolume(channels[stream_wind], 100);
1644                         }
1645                 }
1646                 oldmusicvolume[0]=0;
1647                 oldmusicvolume[1]=0;
1648                 oldmusicvolume[2]=0;
1649                 oldmusicvolume[3]=0;
1650
1651
1652                 /*LoadTexture("/Data/Textures/cloud.png",&sprites.cloudtexture,1,1);
1653                 LoadTexture("/Data/Textures/cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1654                 LoadTexture("/Data/Textures/bloodparticle.png",&sprites.bloodtexture,1,1);
1655                 LoadTexture("/Data/Textures/snowflake.png",&sprites.snowflaketexture,1,1);
1656                 LoadTexture("/Data/Textures/flame.png",&sprites.flametexture,1,1);
1657                 LoadTexture("/Data/Textures/bloodflame.png",&sprites.bloodflametexture,1,1);
1658                 LoadTexture("/Data/Textures/smoke.png",&sprites.smoketexture,1,1);
1659                 LoadTexture("/Data/Textures/shine.png",&sprites.shinetexture,1,0);
1660                 */
1661
1662                 if(!firstload)
1663                 {
1664                         firstload=1;
1665                 }
1666         }
1667         leveltime=0;
1668         loadingstuff=0;
1669         visibleloading=0;
1670 }
1671
1672 void    Game::Tick()
1673 {
1674         static int i,k,j,l,m;
1675         static XYZ facing,flatfacing,absflatfacing;
1676         static XYZ rotatetarget;
1677         static bool oldkey;
1678         static float oldtargetrotation;
1679         static int target, numgood;
1680         static XYZ tempcoords1,tempcoords2;
1681         static XYZ test;
1682         static XYZ test2;
1683         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1684         static int whichhit;
1685         static bool donesomething;
1686         static bool oldjumpkeydown;
1687
1688         int templength;
1689
1690         float headprop,bodyprop,armprop,legprop;
1691
1692         for(i=0;i<15;i++){
1693                 displaytime[i]+=multiplier;
1694         }
1695
1696         static unsigned char    theKeyMap[16];
1697         GetKeys( theKeyMap );
1698
1699         keyboardfrozen=0;
1700
1701
1702         static bool mainmenutogglekeydown;
1703         if(!console){
1704                 if(mainmenu&&endgame==1)mainmenu=10;
1705                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1706                         for(j=0;j<255;j++){
1707                                 displaytext[0][j]=' ';
1708                         }
1709                         displaychars[0]=0;
1710                         displayselected=0;
1711                         entername=0;
1712                         mainmenutogglekeydown=1;
1713                 }
1714                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)){
1715                         selected=-1;
1716                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1717                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1718                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1719                                 else if(mainmenu==0&&winfreeze){
1720                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1721                                         stealthloading=1;
1722                                         else stealthloading=0;
1723
1724                                         if(!stealthloading){
1725                                         float gLoc[3]={0,0,0};
1726                                         float vel[3]={0,0,0};
1727                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1728                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1729                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1730                                         OPENAL_SetVolume(channels[firestartsound], 256);
1731                                         OPENAL_SetPaused(channels[firestartsound], false);
1732                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1733
1734                                         flashr=1;
1735                                         flashg=0;
1736                                         flashb=0;
1737                                         flashamount=1;
1738                                         flashdelay=1;
1739                                         }
1740
1741                                         startbonustotal=0;
1742
1743                                         for(i=0;i<campaignnumlevels;i++){
1744                                         levelvisible[i]=0;
1745                                         levelhighlight[i]=0;
1746                                         }
1747
1748                                         levelorder[0]=0;
1749                                         levelvisible[0]=1;
1750                                         if(accountcampaignchoicesmade[accountactive])
1751                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1752                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1753                                         levelvisible[levelorder[i+1]]=1;
1754                                         }
1755                                         int whichlevelstart;
1756                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1757                                         if(whichlevelstart<0){
1758                                         campaignchoicenum=1;
1759                                         campaignchoicewhich[0]=0;
1760                                         }
1761                                         else
1762                                         {
1763                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1764                                         if(campaignchoicenum)
1765                                         for(i=0;i<campaignchoicenum;i++){
1766                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1767                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1768                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1769                                         }
1770                                         }
1771
1772                                         loading=2;
1773                                         loadtime=0;
1774                                         targetlevel=7;
1775                                         if(firstload)TickOnceAfter();
1776                                         if(!firstload)LoadStuff();
1777                                         //else {
1778                                         for(i=0;i<255;i++){
1779                                         mapname[i]='\0';
1780                                         }
1781                                         mapname[0]=':';
1782                                         mapname[1]='D';
1783                                         mapname[2]='a';
1784                                         mapname[3]='t';
1785                                         mapname[4]='a';
1786                                         mapname[5]=':';
1787                                         mapname[6]='M';
1788                                         mapname[7]='a';
1789                                         mapname[8]='p';
1790                                         mapname[9]='s';
1791                                         mapname[10]=':';
1792
1793                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1794                                         //accountcampaignchoicesmade[accountactive]++;
1795
1796
1797                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1798                                         whichchoice=0;
1799                                         visibleloading=1;
1800                                         stillloading=1;
1801                                         Loadlevel(mapname);
1802                                         campaign=1;
1803                                         mainmenu=0;
1804                                         gameon=1;
1805                                         OPENAL_SetPaused(channels[music3], true);
1806
1807                                         stealthloading=0;*/
1808                                 }
1809                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1810                                 if(mainmenu&&musictoggle){
1811                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1812                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1813                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1814                                                 OPENAL_SetPaused(channels[stream_music3], false);
1815                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1816                                                 OPENAL_SetPaused(channels[music1], true);
1817                                         }
1818                                 }
1819                                 if(!mainmenu){
1820                                         OPENAL_SetPaused(channels[stream_music3], true);
1821                                         OPENAL_SetPaused(channels[music1], false);
1822                                 }
1823                         }
1824                         if(mainmenu==3){
1825                                 float gLoc[3]={0,0,0};
1826                                 float vel[3]={0,0,0};
1827                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1828                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1829                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1830                                 OPENAL_SetVolume(channels[fireendsound], 256);
1831                                 OPENAL_SetPaused(channels[fireendsound], false);
1832                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1833
1834                                 flashr=1;
1835                                 flashg=0;
1836                                 flashb=0;
1837                                 flashamount=1;
1838                                 flashdelay=1;
1839
1840                                 if(newdetail>2)newdetail=detail;
1841                                 if(newdetail<0)newdetail=detail;
1842                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1843                                 if(newscreenheight<0)newscreenheight=screenheight;
1844
1845                                 ofstream opstream(ConvertFileName("/Data/config.txt", "w"));
1846                                 opstream << "Screenwidth:\n";
1847                                 opstream << newscreenwidth;
1848                                 opstream << "\nScreenheight:\n";
1849                                 opstream << newscreenheight;
1850                                 opstream << "\nMouse sensitivity:\n";
1851                                 opstream << usermousesensitivity;
1852                                 opstream << "\nBlur(0,1):\n";
1853                                 opstream << ismotionblur;
1854                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1855                                 opstream << newdetail;
1856                                 opstream << "\nFloating jump:\n";
1857                                 opstream << floatjump;
1858                                 opstream << "\nMouse jump:\n";
1859                                 opstream << mousejump;
1860                                 opstream << "\nAmbient sound:\n";
1861                                 opstream << ambientsound;
1862                                 opstream << "\nBlood (0,1,2):\n";
1863                                 opstream << bloodtoggle;
1864                                 opstream << "\nAuto slomo:\n";
1865                                 opstream << autoslomo;
1866                                 opstream << "\nFoliage:\n";
1867                                 opstream << foliage;
1868                                 opstream << "\nMusic:\n";
1869                                 opstream << musictoggle;
1870                                 opstream << "\nTrilinear:\n";
1871                                 opstream << trilinear;
1872                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1873                                 opstream << decals;
1874                                 opstream << "\nInvert mouse:\n";
1875                                 opstream << invertmouse;
1876                                 opstream << "\nGamespeed:\n";
1877                                 if(oldgamespeed==0)oldgamespeed=1;
1878                                 opstream << oldgamespeed;
1879                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1880                                 opstream << difficulty;
1881                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1882                                 opstream << damageeffects;
1883                                 opstream << "\nText:\n";
1884                                 opstream << texttoggle;
1885                                 opstream << "\nDebug:\n";
1886                                 opstream << debugmode;
1887                                 opstream << "\nVBL Sync:\n";
1888                                 opstream << vblsync;
1889                                 opstream << "\nShow Points:\n";
1890                                 opstream << showpoints;
1891                                 opstream << "\nAlways Blur:\n";
1892                                 opstream << alwaysblur;
1893                                 opstream << "\nImmediate mode (turn on on G5):\n";
1894                                 opstream << immediate;
1895                                 opstream << "\nVelocity blur:\n";
1896                                 opstream << velocityblur;
1897                             opstream << "\nVolume:\n";
1898                         opstream << volume;
1899                                 opstream << "\nForward key:\n";
1900                                 opstream << KeyToChar(forwardkey);
1901                                 opstream << "\nBack key:\n";
1902                                 opstream << KeyToChar(backkey);
1903                                 opstream << "\nLeft key:\n";
1904                                 opstream << KeyToChar(leftkey);
1905                                 opstream << "\nRight key:\n";
1906                                 opstream << KeyToChar(rightkey);
1907                                 opstream << "\nJump key:\n";
1908                                 opstream << KeyToChar(jumpkey);
1909                                 opstream << "\nCrouch key:\n";
1910                                 opstream << KeyToChar(crouchkey);
1911                                 opstream << "\nDraw key:\n";
1912                                 opstream << KeyToChar(drawkey);
1913                                 opstream << "\nThrow key:\n";
1914                                 opstream << KeyToChar(throwkey);
1915                                 opstream << "\nAttack key:\n";
1916                                 opstream << KeyToChar(attackkey);
1917                                 opstream << "\nChat key:\n";
1918                                 opstream << KeyToChar(chatkey);
1919                                 opstream.close();
1920                         }
1921                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
1922                                 float gLoc[3]={0,0,0};
1923                                 float vel[3]={0,0,0};
1924                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1925                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1926                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1927                                 OPENAL_SetVolume(channels[fireendsound], 256);
1928                                 OPENAL_SetPaused(channels[fireendsound], false);
1929                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1930
1931                                 flashr=1;
1932                                 flashg=0;
1933                                 flashb=0;
1934                                 flashamount=1;
1935                                 flashdelay=1;
1936                         }
1937                         if(mainmenu==3&&gameon)mainmenu=2;
1938                         if(mainmenu==3&&!gameon)mainmenu=1;
1939                         if(mainmenu==5&&gameon)mainmenu=2;
1940                         if(mainmenu==5&&!gameon)mainmenu=1;
1941                         if(mainmenu==4)mainmenu=3;
1942                         if(mainmenu==6)mainmenu=5;
1943                         if(mainmenu==7)mainmenu=1;
1944                         if(mainmenu==9)mainmenu=5;
1945                         if(mainmenu==11)mainmenu=5;
1946                         if(mainmenu==13)mainmenu=12;
1947                         if(mainmenu==10)mainmenu=5;
1948                         if(mainmenu==100){
1949                                 mainmenu=5;
1950                                 gameon=0;
1951                                 winfreeze=0;
1952                         }
1953                         mainmenutogglekeydown=1;
1954                 }
1955                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1956                         mainmenutogglekeydown=0;
1957                 }
1958         }
1959
1960         /*static bool minimaptogglekeydown;
1961         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
1962         minimap=1-minimap;
1963         minimaptogglekeydown=1;
1964         }
1965         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1966         minimaptogglekeydown=0;
1967         }
1968         */
1969
1970         static bool minimaptogglekeydown;
1971         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
1972                 if(tutorialstage!=51)
1973                         tutorialstagetime=tutorialmaxtime;
1974                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
1975                 OPENAL_SetVolume(channels[consolefailsound], 128);
1976                 OPENAL_SetPaused(channels[consolefailsound], false);
1977                 minimaptogglekeydown=1;
1978         }
1979         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
1980                 minimaptogglekeydown=0;
1981         }
1982
1983         if(mainmenu){
1984                 //menu buttons
1985                 if(mainmenu==1||mainmenu==2){
1986                         if(Button()&&!oldbutton&&selected==1){
1987                                 if(!gameon){
1988                                         float gLoc[3]={0,0,0};
1989                                         float vel[3]={0,0,0};
1990                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1991                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1992                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1993                                         OPENAL_SetVolume(channels[firestartsound], 256);
1994                                         OPENAL_SetPaused(channels[firestartsound], false);
1995                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1996
1997                                         flashr=1;
1998                                         flashg=0;
1999                                         flashb=0;
2000                                         flashamount=1;
2001                                         flashdelay=1;
2002
2003                                         //new game
2004                                         if(accountactive!=-1)mainmenu=5;
2005                                         else mainmenu=7;
2006                                         /*
2007                                         startbonustotal=0;
2008
2009                                         loading=2;
2010                                         loadtime=0;
2011                                         if(firstload)TickOnceAfter();
2012                                         if(!firstload)LoadStuff();
2013                                         else {
2014                                         Loadlevel(0);
2015                                         }
2016                                         mainmenu=0;
2017                                         gameon=1;
2018                                         OPENAL_SetPaused(channels[music3], true);       */
2019                                 }
2020                                 else
2021                                 {
2022                                         //resume
2023                                         mainmenu=0;
2024                                         OPENAL_SetPaused(channels[stream_music3], true);
2025                                         OPENAL_SetPaused(channels[music1], false);
2026                                 }
2027                         }
2028
2029                         if(Button()&&!oldbutton&&selected==2){
2030                                 float gLoc[3]={0,0,0};
2031                                 float vel[3]={0,0,0};
2032                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2033                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2034                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2035                                 OPENAL_SetVolume(channels[firestartsound], 256);
2036                                 OPENAL_SetPaused(channels[firestartsound], false);
2037                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2038
2039                                 flashr=1;
2040                                 flashg=0;
2041                                 flashb=0;
2042                                 flashamount=1;
2043                                 flashdelay=1;
2044
2045                                 //options
2046
2047                                 mainmenu=3;
2048
2049                                 if(newdetail>2)newdetail=detail;
2050                                 if(newdetail<0)newdetail=detail;
2051                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2052                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2053                                 if(newscreenheight>3000)newscreenheight=screenheight;
2054                                 if(newscreenheight<0)newscreenheight=screenheight;
2055                         }
2056
2057                         if(Button()&&!oldbutton&&selected==3){
2058                                 float gLoc[3]={0,0,0};
2059                                 float vel[3]={0,0,0};
2060                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2061                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2062                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2063                                 OPENAL_SetVolume(channels[fireendsound], 256);
2064                                 OPENAL_SetPaused(channels[fireendsound], false);
2065                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2066
2067                                 flashr=1;
2068                                 flashg=0;
2069                                 flashb=0;
2070                                 flashamount=1;
2071                                 flashdelay=1;
2072
2073                                 if(!gameon){
2074                                         //quit
2075                                         tryquit=1;
2076                                         OPENAL_SetPaused(channels[stream_music3], true);
2077                                 }
2078                                 else{
2079                                         //end game
2080                                         gameon=0;
2081                                         mainmenu=1;
2082                                 }
2083                         }
2084                         if(Button())oldbutton=1;
2085                         else oldbutton=0;
2086                 }
2087
2088                 if(mainmenu==3){
2089                         if(Button()&&!oldbutton&&selected!=-1){
2090                                 float gLoc[3]={0,0,0};
2091                                 float vel[3]={0,0,0};
2092                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2093                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2094                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2095                                 OPENAL_SetVolume(channels[firestartsound], 256);
2096                                 OPENAL_SetPaused(channels[firestartsound], false);
2097                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2098                         }
2099                         if(Button()&&!oldbutton&&selected==0){
2100                         
2101                                 extern SDL_Rect **resolutions;
2102                                 bool isCustomResolution = true;
2103                                 bool found = false;
2104                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2105                                 {
2106                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2107                                                 isCustomResolution = false;
2108
2109                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2110                                         {
2111                                                 i++;
2112                                                 if (resolutions[i] != NULL)
2113                                                 {
2114                                                         newscreenwidth = (int) resolutions[i]->w;
2115                                                         newscreenheight = (int) resolutions[i]->h;
2116                                                 }
2117                                                 else if (isCustomResolution)
2118                                                 {
2119                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2120                                                         {
2121                                                                 newscreenwidth = (int) resolutions[0]->w;
2122                                                                 newscreenheight = (int) resolutions[0]->h;
2123                                                         }
2124                                                         else
2125                                                         {
2126                                                                 newscreenwidth = screenwidth;
2127                                                                 newscreenheight = screenheight;
2128                                                         }
2129                                                 }
2130                                                 else
2131                                                 {
2132                                                         newscreenwidth = (int) resolutions[0]->w;
2133                                                         newscreenheight = (int) resolutions[0]->h;
2134                                                 }
2135                                                 found = true;
2136                                         }
2137                                 }
2138
2139                                 if (!found)
2140                                 {
2141                                         newscreenwidth = (int) resolutions[0]->w;
2142                                         newscreenheight = (int) resolutions[0]->h;
2143                                 }
2144
2145                                 
2146                         }
2147                         if(Button()&&!oldbutton&&selected==1){
2148                                 newdetail++;
2149                                 if(newdetail>2)newdetail=0;
2150                         }
2151                         if(Button()&&!oldbutton&&selected==2){
2152                                 bloodtoggle++;
2153                                 if(bloodtoggle>2)bloodtoggle=0;
2154                         }
2155                         if(Button()&&!oldbutton&&selected==3){
2156                                 difficulty++;
2157                                 if(difficulty>2)difficulty=0;
2158                         }
2159                         if(Button()&&!oldbutton&&selected==4){
2160                                 ismotionblur=1-ismotionblur;
2161                         }
2162                         if(Button()&&!oldbutton&&selected==5){
2163                                 decals=1-decals;
2164                         }
2165                         if(Button()&&!oldbutton&&selected==6){
2166                                 musictoggle=1-musictoggle;
2167
2168                                 if(!musictoggle){
2169                                         OPENAL_SetPaused(channels[music1], true);
2170                                         OPENAL_SetPaused(channels[stream_music2], true);
2171                                         OPENAL_SetPaused(channels[stream_music3], true);
2172
2173                                         for(i=0;i<4;i++){
2174                                                 oldmusicvolume[i]=0;
2175                                                 musicvolume[i]=0;
2176                                         }
2177                                 }
2178
2179                                 if(musictoggle){
2180                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2181                                         OPENAL_SetPaused(channels[stream_music3], false);
2182                                         OPENAL_SetVolume(channels[stream_music3], 256);
2183                                 }
2184                         }
2185                         if(Button()&&!oldbutton&&selected==9){
2186                                 invertmouse=1-invertmouse;
2187                         }
2188                         if(Button()&&!oldbutton&&selected==10){
2189                                 usermousesensitivity+=.2;
2190                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2191                         }
2192                         if(Button()&&!oldbutton&&selected==11){
2193                                 volume+=.1f;
2194                                 if(volume>1.0001f)volume=0;
2195                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2196                         }
2197                         if(Button()&&!oldbutton&&selected==7){
2198                                 /*float gLoc[3]={0,0,0};
2199                                 float vel[3]={0,0,0};
2200                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2201                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2202                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2203                                 OPENAL_SetVolume(channels[firestartsound], 256);
2204                                 OPENAL_SetPaused(channels[firestartsound], false);
2205                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2206                                 */
2207                                 flashr=1;
2208                                 flashg=0;
2209                                 flashb=0;
2210                                 flashamount=1;
2211                                 flashdelay=1;
2212
2213                                 //options
2214
2215                                 mainmenu=4;
2216                                 keyselect=-1;
2217                         }
2218                         if(Button()&&!oldbutton&&selected==8){
2219                                 float gLoc[3]={0,0,0};
2220                                 float vel[3]={0,0,0};
2221                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2222                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2223                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2224                                 OPENAL_SetVolume(channels[fireendsound], 256);
2225                                 OPENAL_SetPaused(channels[fireendsound], false);
2226                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2227
2228                                 flashr=1;
2229                                 flashg=0;
2230                                 flashb=0;
2231                                 flashamount=1;
2232                                 flashdelay=1;
2233
2234                                 if(newdetail>2)newdetail=detail;
2235                                 if(newdetail<0)newdetail=detail;
2236                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2237                                 if(newscreenheight<0)newscreenheight=screenheight;
2238
2239
2240                                 ofstream opstream(ConvertFileName("/Data/config.txt", "w"));
2241                                 opstream << "Screenwidth:\n";
2242                                 opstream << newscreenwidth;
2243                                 opstream << "\nScreenheight:\n";
2244                                 opstream << newscreenheight;
2245                                 opstream << "\nMouse sensitivity:\n";
2246                                 opstream << usermousesensitivity;
2247                                 opstream << "\nBlur(0,1):\n";
2248                                 opstream << ismotionblur;
2249                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2250                                 opstream << newdetail;
2251                                 opstream << "\nFloating jump:\n";
2252                                 opstream << floatjump;
2253                                 opstream << "\nMouse jump:\n";
2254                                 opstream << mousejump;
2255                                 opstream << "\nAmbient sound:\n";
2256                                 opstream << ambientsound;
2257                                 opstream << "\nBlood (0,1,2):\n";
2258                                 opstream << bloodtoggle;
2259                                 opstream << "\nAuto slomo:\n";
2260                                 opstream << autoslomo;
2261                                 opstream << "\nFoliage:\n";
2262                                 opstream << foliage;
2263                                 opstream << "\nMusic:\n";
2264                                 opstream << musictoggle;
2265                                 opstream << "\nTrilinear:\n";
2266                                 opstream << trilinear;
2267                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2268                                 opstream << decals;
2269                                 opstream << "\nInvert mouse:\n";
2270                                 opstream << invertmouse;
2271                                 opstream << "\nGamespeed:\n";
2272                                 if(oldgamespeed==0)oldgamespeed=1;
2273                                 opstream << oldgamespeed;
2274                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2275                                 opstream << difficulty;
2276                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2277                                 opstream << damageeffects;
2278                                 opstream << "\nText:\n";
2279                                 opstream << texttoggle;
2280                                 opstream << "\nDebug:\n";
2281                                 opstream << debugmode;
2282                                 opstream << "\nVBL Sync:\n";
2283                                 opstream << vblsync;
2284                                 opstream << "\nShow Points:\n";
2285                                 opstream << showpoints;
2286                                 opstream << "\nAlways Blur:\n";
2287                                 opstream << alwaysblur;
2288                                 opstream << "\nImmediate mode (turn on on G5):\n";
2289                                 opstream << immediate;
2290                                 opstream << "\nVelocity blur:\n";
2291                                 opstream << velocityblur;
2292                             opstream << "\nVolume:\n";
2293                         opstream << volume;
2294                                 opstream << "\nForward key:\n";
2295                                 opstream << KeyToChar(forwardkey);
2296                                 opstream << "\nBack key:\n";
2297                                 opstream << KeyToChar(backkey);
2298                                 opstream << "\nLeft key:\n";
2299                                 opstream << KeyToChar(leftkey);
2300                                 opstream << "\nRight key:\n";
2301                                 opstream << KeyToChar(rightkey);
2302                                 opstream << "\nJump key:\n";
2303                                 opstream << KeyToChar(jumpkey);
2304                                 opstream << "\nCrouch key:\n";
2305                                 opstream << KeyToChar(crouchkey);
2306                                 opstream << "\nDraw key:\n";
2307                                 opstream << KeyToChar(drawkey);
2308                                 opstream << "\nThrow key:\n";
2309                                 opstream << KeyToChar(throwkey);
2310                                 opstream << "\nAttack key:\n";
2311                                 opstream << KeyToChar(attackkey);
2312                                 opstream << "\nChat key:\n";
2313                                 opstream << KeyToChar(chatkey);
2314                                 opstream.close();
2315
2316                                 if(mainmenu==3&&gameon)mainmenu=2;
2317                                 if(mainmenu==3&&!gameon)mainmenu=1;
2318                         }
2319                         if(Button())oldbutton=1;
2320                         else oldbutton=0;
2321                 }
2322                 if(mainmenu==4){
2323                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2324                                 float gLoc[3]={0,0,0};
2325                                 float vel[3]={0,0,0};
2326                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2327                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2328                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2329                                 OPENAL_SetVolume(channels[firestartsound], 256);
2330                                 OPENAL_SetPaused(channels[firestartsound], false);
2331                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2332                         }
2333                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2334                                 keyselect=selected;
2335                                 oldbuttons[0]=1;
2336                                 oldbuttons[1]=1;
2337                                 oldbuttons[2]=1;
2338                         }
2339                         if(keyselect!=-1){
2340                                 for(i=0;i<3;i++)
2341                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2342                                 for(i=0;i<140;i++){
2343                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2344                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2345                                                         float gLoc[3]={0,0,0};
2346                                                         float vel[3]={0,0,0};
2347                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2348                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2349                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2350                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2351                                                         OPENAL_SetPaused(channels[fireendsound], false);
2352                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2353
2354                                                         int keynum;
2355                                                         keynum=i;
2356                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2357                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2358
2359
2360
2361                                                         if(keyselect==0)forwardkey=keynum;
2362                                                         if(keyselect==1)backkey=keynum;
2363                                                         if(keyselect==2)leftkey=keynum;
2364                                                         if(keyselect==3)rightkey=keynum;
2365                                                         if(keyselect==4)crouchkey=keynum;
2366                                                         if(keyselect==5)jumpkey=keynum;
2367                                                         if(keyselect==6)drawkey=keynum;
2368                                                         if(keyselect==7)throwkey=keynum;
2369                                                         if(keyselect==8)attackkey=keynum;
2370                                                         keyselect=-1;
2371                                                 }
2372                                         }
2373                                 }}
2374                         if(Button()&&!oldbutton&&selected==9){
2375                                 float gLoc[3]={0,0,0};
2376                                 float vel[3]={0,0,0};
2377                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2378                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2379                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2380                                 OPENAL_SetVolume(channels[fireendsound], 256);
2381                                 OPENAL_SetPaused(channels[fireendsound], false);
2382                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2383
2384                                 flashr=1;
2385                                 flashg=0;
2386                                 flashb=0;
2387                                 flashamount=1;
2388                                 flashdelay=1;
2389
2390                                 mainmenu=3;
2391
2392                                 if(newdetail>2)newdetail=detail;
2393                                 if(newdetail<0)newdetail=detail;
2394                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2395                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2396                                 if(newscreenheight>3000)newscreenheight=screenheight;
2397                                 if(newscreenheight<0)newscreenheight=screenheight;
2398                         }
2399                 }
2400
2401                 if(mainmenu==5){
2402
2403                         if(endgame==2){
2404                                 accountcampaignchoicesmade[accountactive]=0;
2405                                 accountcampaignscore[accountactive]=0;
2406                                 accountcampaigntime[accountactive]=0;
2407                                 endgame=0;
2408                         }
2409
2410                         if(Button()&&!oldbutton&&selected==1){
2411                                 float gLoc[3]={0,0,0};
2412                                 float vel[3]={0,0,0};
2413                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2414                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2415                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2416                                 OPENAL_SetVolume(channels[firestartsound], 256);
2417                                 OPENAL_SetPaused(channels[firestartsound], false);
2418                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2419
2420                                 flashr=1;
2421                                 flashg=0;
2422                                 flashb=0;
2423                                 flashamount=1;
2424                                 flashdelay=1;
2425
2426                                 startbonustotal=0;
2427
2428                                 loading=2;
2429                                 loadtime=0;
2430                                 targetlevel=-1;
2431                                 if(firstload)TickOnceAfter();
2432                                 if(!firstload)LoadStuff();
2433                                 else {
2434                                         Loadlevel(-1);
2435                                 }
2436
2437                                 mainmenu=0;
2438                                 gameon=1;
2439                                 OPENAL_SetPaused(channels[stream_music3], true);
2440                         }
2441                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2442                                 float gLoc[3]={0,0,0};
2443                                 float vel[3]={0,0,0};
2444                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2445                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2446                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2447                                 OPENAL_SetVolume(channels[firestartsound], 256);
2448                                 OPENAL_SetPaused(channels[firestartsound], false);
2449                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2450
2451                                 flashr=1;
2452                                 flashg=0;
2453                                 flashb=0;
2454                                 flashamount=1;
2455                                 flashdelay=1;
2456
2457                                 startbonustotal=0;
2458
2459                                 loading=2;
2460                                 loadtime=0;
2461                                 targetlevel=7;
2462                                 if(firstload)TickOnceAfter();
2463                                 if(!firstload)LoadStuff();
2464                                 //else {
2465                                 for(i=0;i<255;i++){
2466                                         mapname[i]='\0';
2467                                 }
2468                                 mapname[0]=':';
2469                                 mapname[1]='D';
2470                                 mapname[2]='a';
2471                                 mapname[3]='t';
2472                                 mapname[4]='a';
2473                                 mapname[5]=':';
2474                                 mapname[6]='M';
2475                                 mapname[7]='a';
2476                                 mapname[8]='p';
2477                                 mapname[9]='s';
2478                                 mapname[10]=':';
2479                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2480                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2481                                 visibleloading=1;
2482                                 stillloading=1;
2483                                 Loadlevel(mapname);
2484                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2485                                 //}
2486                                 campaign=1;
2487                                 mainmenu=0;
2488                                 gameon=1;
2489                                 OPENAL_SetPaused(channels[stream_music3], true);
2490                         }
2491                         if(Button()&&!oldbutton&&selected==4){
2492                                 float gLoc[3]={0,0,0};
2493                                 float vel[3]={0,0,0};
2494                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2495                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2496                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2497                                 OPENAL_SetVolume(channels[fireendsound], 256);
2498                                 OPENAL_SetPaused(channels[fireendsound], false);
2499                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2500
2501                                 flashr=1;
2502                                 flashg=0;
2503                                 flashb=0;
2504                                 flashamount=1;
2505                                 flashdelay=1;
2506
2507                                 if(mainmenu==5&&gameon)mainmenu=2;
2508                                 if(mainmenu==5&&!gameon)mainmenu=1;
2509                         }
2510                         if(Button()&&!oldbutton&&selected==5){
2511                                 float gLoc[3]={0,0,0};
2512                                 float vel[3]={0,0,0};
2513                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2514                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2515                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2516                                 OPENAL_SetVolume(channels[fireendsound], 256);
2517                                 OPENAL_SetPaused(channels[fireendsound], false);
2518                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2519
2520                                 flashr=1;
2521                                 flashg=0;
2522                                 flashb=0;
2523                                 flashamount=1;
2524                                 flashdelay=1;
2525
2526                                 mainmenu=7;
2527                         }
2528                         if(Button()&&!oldbutton&&selected==3){
2529                                 float gLoc[3]={0,0,0};
2530                                 float vel[3]={0,0,0};
2531                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2532                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2533                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2534                                 OPENAL_SetVolume(channels[firestartsound], 256);
2535                                 OPENAL_SetPaused(channels[firestartsound], false);
2536                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2537
2538                                 flashr=1;
2539                                 flashg=0;
2540                                 flashb=0;
2541                                 flashamount=1;
2542                                 flashdelay=1;
2543
2544                                 mainmenu=6;
2545                         }
2546                         if(Button()&&!oldbutton&&selected==2){
2547                                 float gLoc[3]={0,0,0};
2548                                 float vel[3]={0,0,0};
2549                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2550                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2551                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2552                                 OPENAL_SetVolume(channels[firestartsound], 256);
2553                                 OPENAL_SetPaused(channels[firestartsound], false);
2554                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2555
2556                                 flashr=1;
2557                                 flashg=0;
2558                                 flashb=0;
2559                                 flashamount=1;
2560                                 flashdelay=1;
2561
2562                                 mainmenu=9;
2563                         }
2564                         if(Button())oldbutton=1;
2565                         else oldbutton=0;
2566                 }
2567                 if(mainmenu==9){
2568                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2569                                 float gLoc[3]={0,0,0};
2570                                 float vel[3]={0,0,0};
2571                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2572                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2573                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2574                                 OPENAL_SetVolume(channels[firestartsound], 256);
2575                                 OPENAL_SetPaused(channels[firestartsound], false);
2576                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2577
2578                                 flashr=1;
2579                                 flashg=0;
2580                                 flashb=0;
2581                                 flashamount=1;
2582                                 flashdelay=1;
2583
2584                                 startbonustotal=0;
2585
2586                                 loading=2;
2587                                 loadtime=0;
2588                                 targetlevel=selected;
2589                                 if(firstload)TickOnceAfter();
2590                                 if(!firstload)LoadStuff();
2591                                 else {
2592                                         Loadlevel(selected);
2593                                 }
2594                                 campaign=0;
2595
2596                                 mainmenu=0;
2597                                 gameon=1;
2598                                 OPENAL_SetPaused(channels[stream_music3], true);
2599                         }
2600                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2601                                 float gLoc[3]={0,0,0};
2602                                 float vel[3]={0,0,0};
2603                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2604                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2605                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2606                                 OPENAL_SetVolume(channels[fireendsound], 256);
2607                                 OPENAL_SetPaused(channels[fireendsound], false);
2608                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2609
2610                                 flashr=1;
2611                                 flashg=0;
2612                                 flashb=0;
2613                                 flashamount=1;
2614                                 flashdelay=1;
2615
2616                                 mainmenu=5;
2617                         }
2618                         if(Button())oldbutton=1;
2619                         else oldbutton=0;
2620                 }
2621                 if(mainmenu==11){
2622                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2623                                 float gLoc[3]={0,0,0};
2624                                 float vel[3]={0,0,0};
2625                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2626                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2627                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2628                                 OPENAL_SetVolume(channels[firestartsound], 256);
2629                                 OPENAL_SetPaused(channels[firestartsound], false);
2630                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2631
2632                                 flashr=1;
2633                                 flashg=0;
2634                                 flashb=0;
2635                                 flashamount=1;
2636                                 flashdelay=1;
2637
2638                                 startbonustotal=0;
2639
2640                                 loading=2;
2641                                 loadtime=0;
2642                                 targetlevel=selected;
2643                                 if(firstload)TickOnceAfter();
2644                                 if(!firstload)LoadStuff();
2645                                 else {
2646                                         Loadlevel(selected);
2647                                 }
2648                                 campaign=0;
2649
2650                                 mainmenu=0;
2651                                 gameon=1;
2652                                 OPENAL_SetPaused(channels[stream_music3], true);
2653                         }
2654                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2655                                 float gLoc[3]={0,0,0};
2656                                 float vel[3]={0,0,0};
2657                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2658                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2659                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2660                                 OPENAL_SetVolume(channels[fireendsound], 256);
2661                                 OPENAL_SetPaused(channels[fireendsound], false);
2662                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2663
2664                                 flashr=1;
2665                                 flashg=0;
2666                                 flashb=0;
2667                                 flashamount=1;
2668                                 flashdelay=1;
2669
2670                                 mainmenu=5;
2671                         }
2672                         if(Button())oldbutton=1;
2673                         else oldbutton=0;
2674                 }
2675                 if(mainmenu==10){
2676                         endgame=2;
2677                         if(Button()&&!oldbutton&&selected==3){
2678                                 float gLoc[3]={0,0,0};
2679                                 float vel[3]={0,0,0};
2680                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2681                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2682                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2683                                 OPENAL_SetVolume(channels[fireendsound], 256);
2684                                 OPENAL_SetPaused(channels[fireendsound], false);
2685                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2686
2687                                 flashr=1;
2688                                 flashg=0;
2689                                 flashb=0;
2690                                 flashamount=1;
2691                                 flashdelay=1;
2692
2693                                 mainmenu=5;
2694                         }
2695                         if(Button())oldbutton=1;
2696                         else oldbutton=0;
2697                 }
2698
2699                 if(mainmenu==6){
2700                         if(Button()&&!oldbutton&&selected!=-1){
2701                                 float gLoc[3]={0,0,0};
2702                                 float vel[3]={0,0,0};
2703                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2704                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2705                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2706                                 OPENAL_SetVolume(channels[firestartsound], 256);
2707                                 OPENAL_SetPaused(channels[firestartsound], false);
2708                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2709                         }
2710                         if(Button()&&!oldbutton&&selected==1){
2711                                 float gLoc[3]={0,0,0};
2712                                 float vel[3]={0,0,0};
2713                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2714                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2715                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2716                                 OPENAL_SetVolume(channels[fireendsound], 256);
2717                                 OPENAL_SetPaused(channels[fireendsound], false);
2718                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2719
2720                                 flashr=1;
2721                                 flashg=0;
2722                                 flashb=0;
2723                                 flashamount=1;
2724                                 flashdelay=1;
2725
2726                                 for(i=accountactive;i<numaccounts-1;i++){
2727                                         accountdifficulty[i]=accountdifficulty[i+1];
2728                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2729                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2730                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2731                                         }
2732                                         accountpoints[i]=accountpoints[i+1];
2733                                         for(j=0;j<50;j++){
2734                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2735                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2736                                         }
2737                                         for(j=0;j<60;j++){
2738                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2739                                         }
2740                                         for(j=0;j<256;j++){
2741                                                 accountname[i][j]=accountname[i+1][j];
2742                                         }
2743                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2744                                         accountprogress[i]=accountprogress[i+1];
2745                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2746                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2747                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2748                                 }
2749
2750                                 numaccounts--;
2751                                 accountactive=-1;
2752
2753
2754                                 mainmenu=7;
2755                         }
2756                         if(Button()&&!oldbutton&&selected==2){
2757                                 float gLoc[3]={0,0,0};
2758                                 float vel[3]={0,0,0};
2759                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2760                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2761                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2762                                 OPENAL_SetVolume(channels[fireendsound], 256);
2763                                 OPENAL_SetPaused(channels[fireendsound], false);
2764                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2765
2766                                 flashr=1;
2767                                 flashg=0;
2768                                 flashb=0;
2769                                 flashamount=1;
2770                                 flashdelay=1;
2771
2772                                 mainmenu=5;
2773                         }
2774                         if(Button())oldbutton=1;
2775                         else oldbutton=0;
2776                 }
2777                 if(mainmenu==7){
2778                         if(Button()&&!oldbutton&&selected!=-1){
2779                                 float gLoc[3]={0,0,0};
2780                                 float vel[3]={0,0,0};
2781                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2782                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2783                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2784                                 OPENAL_SetVolume(channels[firestartsound], 256);
2785                                 OPENAL_SetPaused(channels[firestartsound], false);
2786                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2787                         }
2788                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2789                                 entername=1;
2790                         }
2791                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2792                                 accountactive=selected-1;
2793                                 mainmenu=5;
2794                                 flashr=1;
2795                                 flashg=0;
2796                                 flashb=0;
2797                                 flashamount=1;
2798                                 flashdelay=1;
2799                         }
2800                         if(Button()&&!oldbutton&&selected==numaccounts+1){
2801                                 float gLoc[3]={0,0,0};
2802                                 float vel[3]={0,0,0};
2803                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2804                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2805                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2806                                 OPENAL_SetVolume(channels[fireendsound], 256);
2807                                 OPENAL_SetPaused(channels[fireendsound], false);
2808                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2809
2810                                 flashr=1;
2811                                 flashg=0;
2812                                 flashb=0;
2813                                 flashamount=1;
2814                                 flashdelay=1;
2815
2816                                 mainmenu=1;
2817
2818                                 for(j=0;j<255;j++){
2819                                         displaytext[0][j]=' ';
2820                                 }
2821                                 displaychars[0]=0;
2822                                 displayselected=0;
2823                                 entername=0;
2824                         }
2825                         if(Button())oldbutton=1;
2826                         else oldbutton=0;
2827                 }
2828                 if(mainmenu==8){
2829                         if(Button()&&!oldbutton&&selected!=-1){
2830                                 float gLoc[3]={0,0,0};
2831                                 float vel[3]={0,0,0};
2832                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2833                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2834                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2835                                 OPENAL_SetVolume(channels[firestartsound], 256);
2836                                 OPENAL_SetPaused(channels[firestartsound], false);
2837                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2838
2839                                 if(selected==0)accountdifficulty[accountactive]=0;
2840                                 if(selected==1)accountdifficulty[accountactive]=1;
2841                                 if(selected==2)accountdifficulty[accountactive]=2;
2842
2843                                 mainmenu=5;
2844
2845                                 flashr=1;
2846                                 flashg=0;
2847                                 flashb=0;
2848                                 flashamount=1;
2849                                 flashdelay=1;
2850
2851                         }
2852                         if(Button())oldbutton=1;
2853                         else oldbutton=0;
2854                 }
2855
2856
2857                 if(Button())oldbutton=1;
2858                 else oldbutton=0;
2859
2860                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
2861                         tryquit=1;
2862                         if(mainmenu==3){
2863                                 if(newdetail>2)newdetail=detail;
2864                                 if(newdetail<0)newdetail=detail;
2865                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2866                                 if(newscreenheight<0)newscreenheight=screenheight;
2867
2868                                 ofstream opstream(ConvertFileName("/Data/config.txt", "w"));
2869                                 opstream << "Screenwidth:\n";
2870                                 opstream << newscreenwidth;
2871                                 opstream << "\nScreenheight:\n";
2872                                 opstream << newscreenheight;
2873                                 opstream << "\nMouse sensitivity:\n";
2874                                 opstream << usermousesensitivity;
2875                                 opstream << "\nBlur(0,1):\n";
2876                                 opstream << ismotionblur;
2877                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2878                                 opstream << newdetail;
2879                                 opstream << "\nFloating jump:\n";
2880                                 opstream << floatjump;
2881                                 opstream << "\nMouse jump:\n";
2882                                 opstream << mousejump;
2883                                 opstream << "\nAmbient sound:\n";
2884                                 opstream << ambientsound;
2885                                 opstream << "\nBlood (0,1,2):\n";
2886                                 opstream << bloodtoggle;
2887                                 opstream << "\nAuto slomo:\n";
2888                                 opstream << autoslomo;
2889                                 opstream << "\nFoliage:\n";
2890                                 opstream << foliage;
2891                                 opstream << "\nMusic:\n";
2892                                 opstream << musictoggle;
2893                                 opstream << "\nTrilinear:\n";
2894                                 opstream << trilinear;
2895                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2896                                 opstream << decals;
2897                                 opstream << "\nInvert mouse:\n";
2898                                 opstream << invertmouse;
2899                                 opstream << "\nGamespeed:\n";
2900                                 if(oldgamespeed==0)oldgamespeed=1;
2901                                 opstream << oldgamespeed;
2902                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2903                                 opstream << difficulty;
2904                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2905                                 opstream << damageeffects;
2906                                 opstream << "\nText:\n";
2907                                 opstream << texttoggle;
2908                                 opstream << "\nDebug:\n";
2909                                 opstream << debugmode;
2910                                 opstream << "\nVBL Sync:\n";
2911                                 opstream << vblsync;
2912                                 opstream << "\nShow Points:\n";
2913                                 opstream << showpoints;
2914                                 opstream << "\nAlways Blur:\n";
2915                                 opstream << alwaysblur;
2916                                 opstream << "\nImmediate mode (turn on on G5):\n";
2917                                 opstream << immediate;
2918                                 opstream << "\nVelocity blur:\n";
2919                                 opstream << velocityblur;
2920                             opstream << "\nVolume:\n";
2921                         opstream << volume;
2922                                 opstream << "\nForward key:\n";
2923                                 opstream << KeyToChar(forwardkey);
2924                                 opstream << "\nBack key:\n";
2925                                 opstream << KeyToChar(backkey);
2926                                 opstream << "\nLeft key:\n";
2927                                 opstream << KeyToChar(leftkey);
2928                                 opstream << "\nRight key:\n";
2929                                 opstream << KeyToChar(rightkey);
2930                                 opstream << "\nJump key:\n";
2931                                 opstream << KeyToChar(jumpkey);
2932                                 opstream << "\nCrouch key:\n";
2933                                 opstream << KeyToChar(crouchkey);
2934                                 opstream << "\nDraw key:\n";
2935                                 opstream << KeyToChar(drawkey);
2936                                 opstream << "\nThrow key:\n";
2937                                 opstream << KeyToChar(throwkey);
2938                                 opstream << "\nAttack key:\n";
2939                                 opstream << KeyToChar(attackkey);
2940                                 opstream << "\nChat key:\n";
2941                                 opstream << KeyToChar(chatkey);
2942                                 opstream.close();
2943                         }
2944                 }
2945
2946                 if(mainmenu==1||mainmenu==2){
2947                         if(loaddistrib>4)transition+=multiplier/8;
2948                         if(transition>1){
2949                                 transition=0;
2950                                 anim++;
2951                                 if(anim>4)anim=0;
2952                                 loaddistrib=0;
2953                         }
2954                 }
2955                 OPENAL_SetFrequency(channels[stream_music3], 22050);
2956
2957                 if(entername){
2958                         for(i=0;i<140;i++){
2959                                 if(IsKeyDown(theKeyMap, i)){
2960                                         togglekeydelay[i]+=multiplier;
2961                                         if(togglekeydelay[i]>.4){
2962                                                 togglekey[i]=0;
2963                                                 togglekeydelay[i]=.36;
2964                                         }
2965                                         if(!togglekey[i]){
2966                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
2967                                                         for(j=255;j>=displayselected+1;j--){
2968                                                                 displaytext[0][j]=displaytext[0][j-1];
2969                                                         }
2970                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
2971                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
2972                                                         displayselected++;
2973                                                         displaychars[0]++;
2974                                                 }
2975                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
2976                                                         for(j=displayselected-1;j<255;j++){
2977                                                                 displaytext[0][j]=displaytext[0][j+1];
2978                                                         }
2979                                                         displaytext[0][255]=' ';
2980                                                         displayselected--;
2981                                                         displaychars[0]--;
2982                                                 }
2983                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
2984                                                         displayselected--;
2985                                                 }
2986                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
2987                                                         displayselected++;
2988                                                 }
2989                                                 if(i==MAC_RETURN_KEY&&entername){
2990                                                         if(displaychars[0]){
2991                                                                 numaccounts++;
2992                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
2993                                                                 accountactive=numaccounts-1;
2994                                                                 accountdifficulty[accountactive]=1;
2995                                                                 accountprogress[accountactive]=0;
2996                                                                 accountpoints[accountactive]=0;
2997                                                                 accountcampaigntime[accountactive]=0;
2998                                                                 accountcampaignscore[accountactive]=0;
2999                                                                 accountcampaignfasttime[accountactive]=0;
3000                                                                 accountcampaignhighscore[accountactive]=0;
3001                                                                 for(j=0;j<50;j++){
3002                                                                         accounthighscore[accountactive][j]=0;
3003                                                                         accountfasttime[accountactive][j]=0;
3004                                                                 }
3005                                                                 for(j=0;j<60;j++){
3006                                                                         accountunlocked[accountactive][j]=0;
3007                                                                 }
3008                                                                 accountcampaignchoicesmade[accountactive]=0;
3009
3010                                                                 for(j=0;j<255;j++){
3011                                                                         displaytext[0][j]=' ';
3012                                                                 }
3013                                                                 displaychars[0]=0;
3014                                                                 displayselected=0;
3015                                                                 entername=0;
3016
3017                                                                 mainmenu=8;
3018
3019                                                                 flashr=1;
3020                                                                 flashg=0;
3021                                                                 flashb=0;
3022                                                                 flashamount=1;
3023                                                                 flashdelay=1;
3024
3025                                                                 float gLoc[3]={0,0,0};
3026                                                                 float vel[3]={0,0,0};
3027                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3028                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3029                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3030                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3031                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3032                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3033
3034                                                                 for(j=0;j<255;j++){
3035                                                                         displaytext[0][j]=' ';
3036                                                                 }
3037                                                                 displaychars[0]=0;
3038
3039
3040                                                                 displayselected=0;
3041                                                         }}
3042
3043                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3044                                                         if(displaychars[0]){
3045                                                                 sprintf (registrationname, "%s", displaytext[0]);
3046                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3047
3048                                                                 mainmenu=5;
3049                         
3050                                                                 flashr=1;
3051                                                                 flashg=0;
3052                                                                 flashb=0;
3053                                                                 flashamount=1;
3054                                                                 flashdelay=1;
3055
3056                                                                 float gLoc[3]={0,0,0};
3057                                                                 float vel[3]={0,0,0};
3058                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3059                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3060                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3061                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3062                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3063                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3064
3065                                                                 for(j=0;j<255;j++){
3066                                                                         displaytext[0][j]=' ';
3067                                                                 }
3068                                                                 displaychars[0]=0;
3069                         
3070                                                                 displayselected=0;
3071                                                         }}
3072                                         }
3073                                         togglekey[i]=1;
3074                                 }
3075                                 else {
3076                                         togglekey[i]=0;
3077                                         togglekeydelay[i]=0;
3078                                 }
3079                         }
3080
3081                         displayblinkdelay-=multiplier;
3082                         if(displayblinkdelay<=0){
3083                                 displayblinkdelay=.3;
3084                                 displayblink=1-displayblink;
3085                         }
3086                 }
3087         }
3088
3089         if(!mainmenu){
3090                 if(hostile==1)hostiletime+=multiplier;
3091                 else hostiletime=0;
3092                 if(!winfreeze)leveltime+=multiplier;
3093                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3094                         chatting=0;
3095                         console=0;
3096                         freeze=0;
3097                         displaychars[0]=0;
3098                 }
3099
3100                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3101                         chatting=1;
3102                         chattogglekeydown=1;
3103                         togglekey[chatkey]=1;
3104                         togglekeydelay[chatkey]=-20;
3105                 }
3106
3107                 if(!IsKeyDown(theKeyMap, chatkey)){
3108                         chattogglekeydown=0;
3109                 }
3110
3111                 if(chatting){
3112                         for(i=0;i<140;i++){
3113                                 if(IsKeyDown(theKeyMap, i)){
3114                                         togglekeydelay[i]+=multiplier;
3115                                         if(togglekeydelay[i]>.4){
3116                                                 togglekey[i]=0;
3117                                                 togglekeydelay[i]=.36;
3118                                         }
3119                                         if(!togglekey[i]){
3120                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3121                                                         for(j=255;j>=displayselected+1;j--){
3122                                                                 displaytext[0][j]=displaytext[0][j-1];
3123                                                         }
3124                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3125                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3126                                                         displayselected++;
3127                                                         displaychars[0]++;
3128                                                 }
3129                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3130                                                         for(j=displayselected-1;j<255;j++){
3131                                                                 displaytext[0][j]=displaytext[0][j+1];
3132                                                         }
3133                                                         displaytext[0][255]=' ';
3134                                                         displayselected--;
3135                                                         displaychars[0]--;
3136                                                 }
3137                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3138                                                         displayselected--;
3139                                                 }
3140                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3141                                                         displayselected++;
3142                                                 }
3143                                                 if(i==MAC_RETURN_KEY){
3144                                                         if(displaychars[0]){
3145                                                                 /*for(j=0;j<displaychars[0];j++){
3146                                                                 talkname[j]=displaytext[0][j];
3147                                                                 }
3148                                                                 talkname[displaychars[0]]='\0';
3149                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3150                                                                 //NetworkSendInformation(chatname);
3151                                                                 */
3152                                                                 for(j=0;j<255;j++){
3153                                                                         displaytext[0][j]=' ';
3154                                                                 }
3155                                                                 displaychars[0]=0;
3156                                                                 displayselected=0;
3157                                                                 chatting=0;
3158                                                         }
3159                                                 }
3160                                         }
3161                                         togglekey[i]=1;
3162                                 }
3163                                 else {
3164                                         togglekey[i]=0;
3165                                         togglekeydelay[i]=0;
3166                                 }
3167                         }
3168
3169                         displayblinkdelay-=multiplier;
3170                         if(displayblinkdelay<=0){
3171                                 displayblinkdelay=.3;
3172                                 displayblink=1-displayblink;
3173                         }
3174                 }
3175
3176                 if(chatting)keyboardfrozen=1;
3177
3178                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3179                         freeze=1-freeze;
3180                         if(freeze){
3181                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3182                         }
3183                         freezetogglekeydown=1;
3184                 }
3185
3186                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3187                         freezetogglekeydown=0;
3188                 }
3189
3190                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3191                         console=1-console;
3192                         if(!console)freeze=0;
3193                         if(console){
3194                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3195                         }
3196                         consoletogglekeydown=1;
3197                 }
3198
3199                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3200                         consoletogglekeydown=0;
3201                 }
3202
3203                 if(console)freeze=1;
3204
3205                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3206                         for(i=0;i<140;i++){
3207                                 if(IsKeyDown(theKeyMap, i)){
3208                                         togglekeydelay[i]+=multiplier;
3209                                         if(togglekeydelay[i]>.4){
3210                                                 togglekey[i]=0;
3211                                                 togglekeydelay[i]=.36;
3212                                         }
3213                                         if(!togglekey[i]){
3214                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3215                                                         for(j=255;j>=consoleselected+1;j--){
3216                                                                 consoletext[0][j]=consoletext[0][j-1];
3217                                                         }
3218                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3219                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3220                                                         consoleselected++;
3221                                                         consolechars[0]++;
3222                                                 }
3223                                                 else if(i==MAC_ENTER_KEY){
3224                                                         for(j=255;j>=consoleselected+1;j--){
3225                                                                 consoletext[0][j]=consoletext[0][j-1];
3226                                                         }
3227                                                         consoletext[0][consoleselected]='\n';
3228                                                         consoleselected++;
3229                                                         consolechars[0]++;
3230                                                 }
3231                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3232                                                         for(j=consoleselected-1;j<255;j++){
3233                                                                 consoletext[0][j]=consoletext[0][j+1];
3234                                                         }
3235                                                         consoletext[0][255]=' ';
3236                                                         consoleselected--;
3237                                                         consolechars[0]--;
3238                                                 }
3239                                                 if(i==MAC_ARROW_UP_KEY){
3240                                                         if(archiveselected<14)archiveselected++;
3241                                                         for(j=0;j<255;j++){
3242                                                                 consolechars[0]=consolechars[archiveselected];
3243                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3244                                                                 consoleselected=consolechars[0];
3245                                                         }
3246                                                 }
3247                                                 if(i==MAC_ARROW_DOWN_KEY){
3248                                                         if(archiveselected>0)archiveselected--;
3249                                                         for(j=0;j<255;j++){
3250                                                                 consolechars[0]=consolechars[archiveselected];
3251                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3252                                                                 consoleselected=consolechars[0];
3253                                                         }
3254                                                 }
3255                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3256                                                         consoleselected--;
3257                                                 }
3258                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3259                                                         consoleselected++;
3260                                                 }
3261                                                 if(i==MAC_RETURN_KEY){
3262                                                         archiveselected=0;
3263                                                         donesomething=0;
3264                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3265                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3266                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3267                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3268                                                                 donesomething=1;
3269                                                                 tryquit=1;
3270                                                         }
3271                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3272                                                         for(j=5;j<consolechars[0];j++){
3273                                                         talkname[j-5]=consoletext[0][j];
3274                                                         }
3275                                                         talkname[consolechars[0]-5]='\0';
3276                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3277                                                         //NetworkSendInformation(chatname);
3278                                                         donesomething=1;
3279                                                         }
3280                                                         if(Compare(consoletext[0],"name ",0,4)){
3281                                                         int numchars;
3282                                                         numchars=consolechars[0]-5;
3283                                                         if(numchars>32)numchars=32;
3284                                                         for(j=5;j<numchars+5;j++){
3285                                                         talkname[j-5]=consoletext[0][j];
3286                                                         }
3287                                                         talkname[numchars]='\0';
3288                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3289                                                         //NetworkSendInformation(chatname);
3290                                                         sprintf (playerName, "%s",talkname);
3291                                                         //NetworkSendName(playerName);
3292                                                         donesomething=1;
3293                                                         }*/
3294                                                         if(Compare(consoletext[0],"map ",0,3)){
3295                                                                 mapname[0]=':';
3296                                                                 mapname[1]='D';
3297                                                                 mapname[2]='a';
3298                                                                 mapname[3]='t';
3299                                                                 mapname[4]='a';
3300                                                                 mapname[5]=':';
3301                                                                 mapname[6]='M';
3302                                                                 mapname[7]='a';
3303                                                                 mapname[8]='p';
3304                                                                 mapname[9]='s';
3305                                                                 mapname[10]=':';
3306                                                                 for(j=4;j<consolechars[0];j++){
3307                                                                         mapname[j-4+11]=consoletext[0][j];
3308                                                                 }
3309                                                                 mapname[consolechars[0]-4+11]='\0';
3310                                                                 Loadlevel(mapname);
3311                                                                 whichlevel=-2;
3312                                                                 campaign=0;
3313                                                                 donesomething=1;
3314                                                         }
3315                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3316                                                         int v;
3317                                                         unsigned char playerNameStr[32];
3318                                                         char theIPAddress[256];
3319                                                         char thePort[32];
3320                                                         NMUInt32 port = 25710;
3321
3322                                                         strcpy(playerName, "Client");
3323                                                         GameC2PStr( playerName, playerNameStr );
3324
3325                                                         for(j=0;j<consolechars[0]-8;j++){
3326                                                         theIPAddress[j]=consoletext[0][j+8];
3327                                                         }
3328                                                         theIPAddress[consolechars[0]-8]='\0';
3329
3330                                                         sprintf( thePort, "%li", port );
3331                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3332                                                         if(v)
3333                                                         {
3334                                                         if(consolechars[0]>0){
3335                                                         for(k=14;k>=1;k--){
3336                                                         for(j=0;j<255;j++){
3337                                                         consoletext[k][j]=consoletext[k-1][j];
3338                                                         }
3339                                                         consolechars[k]=consolechars[k-1];
3340                                                         }
3341                                                         for(j=0;j<255;j++){
3342                                                         consoletext[0][j]=' ';
3343                                                         }
3344                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3345                                                         else sprintf (consoletext[0], "Could not open connection");
3346
3347                                                         consolechars[0]=255;
3348                                                         consoleselected=0;
3349                                                         }
3350                                                         }
3351                                                         else
3352                                                         {
3353                                                         donesomething=1;
3354                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3355                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3356                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3357
3358                                                         if(consolechars[0]>0){
3359                                                         for(k=14;k>=1;k--){
3360                                                         for(j=0;j<255;j++){
3361                                                         consoletext[k][j]=consoletext[k-1][j];
3362                                                         }
3363                                                         consolechars[k]=consolechars[k-1];
3364                                                         }
3365                                                         for(j=0;j<255;j++){
3366                                                         consoletext[0][j]=' ';
3367                                                         }
3368                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3369
3370                                                         consolechars[0]=255;
3371                                                         consoleselected=0;
3372                                                         }
3373                                                         }
3374                                                         }
3375
3376                                                         if(Compare(consoletext[0],"host ",0,4)){
3377                                                         unsigned char gameNameStr[32], playerNameStr[32];
3378                                                         char gameName[32];//, playerName[32];
3379                                                         NMUInt32 port;
3380                                                         int players;
3381                                                         int v;
3382
3383                                                         port = 25710;
3384                                                         players =4;
3385
3386                                                         strcpy(gameName, "Host's game");
3387                                                         strcpy(playerName, "Host");
3388                                                         GameC2PStr( gameName, gameNameStr );
3389                                                         GameC2PStr( playerName, playerNameStr );
3390
3391                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3392                                                         if(v)
3393                                                         {
3394                                                         if(consolechars[0]>0){
3395                                                         for(k=14;k>=1;k--){
3396                                                         for(j=0;j<255;j++){
3397                                                         consoletext[k][j]=consoletext[k-1][j];
3398                                                         }
3399                                                         consolechars[k]=consolechars[k-1];
3400                                                         }
3401                                                         for(j=0;j<255;j++){
3402                                                         consoletext[0][j]=' ';
3403                                                         }
3404                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3405
3406                                                         consolechars[0]=255;
3407                                                         consoleselected=0;
3408                                                         }
3409                                                         }
3410                                                         else
3411                                                         {
3412                                                         donesomething=1;
3413                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3414                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3415                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3416
3417                                                         if(consolechars[0]>0){
3418                                                         for(k=14;k>=1;k--){
3419                                                         for(j=0;j<255;j++){
3420                                                         consoletext[k][j]=consoletext[k-1][j];
3421                                                         }
3422                                                         consolechars[k]=consolechars[k-1];
3423                                                         }
3424                                                         for(j=0;j<255;j++){
3425                                                         consoletext[0][j]=' ';
3426                                                         }
3427                                                         sprintf (consoletext[0], "Game hosted");
3428
3429                                                         consolechars[0]=255;
3430                                                         consoleselected=0;
3431                                                         }
3432                                                         }
3433                                                         }
3434                                                         */
3435                                                         if(Compare(consoletext[0],"save ",0,4)){
3436                                                                 mapname[0]=':';
3437                                                                 mapname[1]='D';
3438                                                                 mapname[2]='a';
3439                                                                 mapname[3]='t';
3440                                                                 mapname[4]='a';
3441                                                                 mapname[5]=':';
3442                                                                 mapname[6]='M';
3443                                                                 mapname[7]='a';
3444                                                                 mapname[8]='p';
3445                                                                 mapname[9]='s';
3446                                                                 mapname[10]=':';
3447                                                                 for(j=5;j<consolechars[0];j++){
3448                                                                         mapname[j-5+11]=consoletext[0][j];
3449                                                                 }
3450                                                                 mapname[consolechars[0]-5+11]='\0';
3451
3452                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3453                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3454                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3455
3456                                                                 int mapvers;
3457                                                                 mapvers=12;
3458
3459
3460                                                                 FILE                    *tfile;
3461                                                                 tfile=fopen( mapname, "wb" );
3462                                                                 fpackf(tfile, "Bi", mapvers);
3463                                                                 //fpackf(tfile, "Bi", indemo);
3464                                                                 fpackf(tfile, "Bi", maptype);
3465                                                                 fpackf(tfile, "Bi", hostile);
3466                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3467                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3468                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3469                                                                 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);
3470                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3471                                                                         for(j=0;j<player[0].num_weapons;j++){
3472                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3473                                                                         }
3474
3475                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3476                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3477                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3478                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3479
3480                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3481
3482                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3483
3484                                                                         fpackf(tfile, "Bi", numdialogues);
3485                                                                         if(numdialogues)
3486                                                                                 for(k=0;k<numdialogues;k++){
3487                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3488                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3489                                                                                         for(l=0;l<10;l++){
3490                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3491                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3492                                                                                         }
3493                                                                                         if(numdialogueboxes)
3494                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3495                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3496                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3497                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3498                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3499                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3500
3501                                                                                                         templength=strlen(dialoguetext[k][l]);
3502                                                                                                         fpackf(tfile, "Bi",(templength));
3503                                                                                                         for(m=0;m<templength;m++){
3504                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3505                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3506                                                                                                         }
3507
3508                                                                                                         templength=strlen(dialoguename[k][l]);
3509                                                                                                         fpackf(tfile, "Bi",templength);
3510                                                                                                         for(m=0;m<templength;m++){
3511                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3512                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3513                                                                                                         }
3514
3515                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3516                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3517                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3518
3519                                                                                                         for(m=0;m<10;m++)
3520                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3521
3522                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3523                                                                                                 }
3524                                                                                 }
3525
3526                                                                                 if(player[0].numclothes)
3527                                                                                         for(k=0;k<player[0].numclothes;k++){
3528                                                                                                 templength=strlen(player[0].clothes[k]);
3529                                                                                                 fpackf(tfile, "Bi", templength);
3530                                                                                                 for(l=0;l<templength;l++)
3531                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3532                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3533                                                                                         }
3534
3535                                                                                         fpackf(tfile, "Bi", environment);
3536
3537                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3538
3539                                                                                         if(objects.numobjects)
3540                                                                                                 for(k=0;k<objects.numobjects;k++){
3541                                                                                                         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]);
3542                                                                                                 }
3543
3544                                                                                                 fpackf(tfile, "Bi", numhotspots);
3545                                                                                                 if(numhotspots)
3546                                                                                                         for(i=0;i<numhotspots;i++){
3547                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3548                                                                                                                 templength=strlen(hotspottext[i]);
3549                                                                                                                 fpackf(tfile, "Bi",templength);
3550                                                                                                                 for(l=0;l<templength;l++)
3551                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3552                                                                                                         }
3553
3554                                                                                                         fpackf(tfile, "Bi", numplayers);
3555                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3556                                                                                                                 for(j=1;j<numplayers;j++){
3557                                                                                                                         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);
3558                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3559                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3560                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3561                                                                                                                                 }
3562                                                                                                                                 if(player[j].numwaypoints<30){
3563                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3564                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3565                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3566                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3567                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3568                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3569                                                                                                                                         }
3570                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3571                                                                                                                                 }
3572                                                                                                                                 else{
3573                                                                                                                                         player[j].numwaypoints=0;
3574                                                                                                                                         player[j].waypoint=0;
3575                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3576                                                                                                                                 }
3577
3578                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3579                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3580                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3581                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3582
3583                                                                                                                                 if(player[j].creature==wolftype){
3584                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3585                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3586                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3587                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3588                                                                                                                                 }
3589
3590                                                                                                                                 if(player[j].creature==rabbittype){
3591                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3592                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3593                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3594                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3595                                                                                                                                 }
3596
3597                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3598
3599
3600
3601                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3602                                                                                                                                 if(player[j].numclothes)
3603                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3604                                                                                                                                                 int templength;
3605                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3606                                                                                                                                                 fpackf(tfile, "Bi", templength);
3607                                                                                                                                                 for(l=0;l<templength;l++)
3608                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3609                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3610                                                                                                                                         }
3611                                                                                                                 }
3612
3613                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3614                                                                                                                 if(numpathpoints)
3615                                                                                                                         for(j=0;j<numpathpoints;j++){
3616                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3617                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3618                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3619                                                                                                                                 }
3620                                                                                                                         }
3621
3622                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3623
3624
3625                                                                                                                         fclose(tfile);
3626                                                                                                                         donesomething=1;
3627
3628                                                                                                                         /*
3629                                                                                                                         FILE                    *tfile;
3630                                                                                                                         tfile=fopen( mapname, "wb" );
3631                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3632                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3633                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3634                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3635                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3636                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3637                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3638                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3639                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3640                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3641                                                                                                                         }
3642
3643                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3644                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3645                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3646                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3647                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3648                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3649                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3650                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3651                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3652                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3653                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3654
3655                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3656                                                                                                                         if(player[0].numclothes)
3657                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3658                                                                                                                         int templength;
3659                                                                                                                         templength=strlen(player[0].clothes[k]);
3660                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3661                                                                                                                         for(l=0;l<templength;l++)
3662                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3663                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3664                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3665                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3666                                                                                                                         }
3667
3668                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3669
3670                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3671
3672                                                                                                                         for(k=0;k<objects.numobjects;k++){
3673                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3674                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
3675                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
3676                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
3677                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
3678                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
3679                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
3680                                                                                                                         }
3681
3682                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3683                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3684                                                                                                                         for(j=1;j<numplayers;j++){
3685                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
3686                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
3687                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
3688                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
3689                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
3690                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3691                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3692                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
3693                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3694                                                                                                                         }
3695                                                                                                                         if(player[j].numwaypoints<30){
3696                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3697                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3698                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
3699                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
3700                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
3701                                                                                                                         }
3702                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3703                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3704                                                                                                                         }
3705                                                                                                                         else{
3706                                                                                                                         player[j].numwaypoints=0;
3707                                                                                                                         player[j].waypoint=0;
3708                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3709                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3710                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3711                                                                                                                         }
3712                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
3713                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
3714                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
3715                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
3716                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
3717                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
3718                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
3719                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
3720                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
3721                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
3722                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
3723
3724                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
3725                                                                                                                         if(player[j].numclothes)
3726                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3727                                                                                                                         int templength;
3728                                                                                                                         templength=strlen(player[j].clothes[k]);
3729                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3730                                                                                                                         for(l=0;l<templength;l++)
3731                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
3732                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
3733                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
3734                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
3735                                                                                                                         }
3736                                                                                                                         }
3737                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3738                                                                                                                         if(numpathpoints)
3739                                                                                                                         for(j=0;j<numpathpoints;j++){
3740                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
3741                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
3742                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
3743                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3744                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
3745                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3746                                                                                                                         }
3747                                                                                                                         }
3748
3749                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
3750                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
3751                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
3752
3753                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
3754
3755                                                                                                                         fclose(tfile);
3756                                                                                                                         donesomething=1;*/
3757                                                         }
3758                                                         /*
3759                                                         if(Compare(consoletext[0],"save ",0,4)){
3760                                                         mapname[0]=':';
3761                                                         mapname[1]='D';
3762                                                         mapname[2]='a';
3763                                                         mapname[3]='t';
3764                                                         mapname[4]='a';
3765                                                         mapname[5]=':';
3766                                                         mapname[6]='M';
3767                                                         mapname[7]='a';
3768                                                         mapname[8]='p';
3769                                                         mapname[9]='s';
3770                                                         mapname[10]=':';
3771                                                         for(j=5;j<consolechars[0];j++){
3772                                                         mapname[j-5+11]=consoletext[0][j];
3773                                                         }
3774                                                         mapname[consolechars[0]-5+11]='\0';
3775
3776                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3777                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3778                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3779
3780                                                         FILE                    *tfile;
3781                                                         tfile=fopen( mapname, "wb" );
3782                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
3783                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3784                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3785                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3786                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3787                                                         for(j=0;j<player[0].num_weapons;j++){
3788                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3789                                                         }
3790                                                         fwrite( &environment, 1, sizeof(int), tfile );
3791
3792                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3793                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
3794                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
3795                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
3796                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
3797
3798                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
3799                                                         if(numplayers>1&&numplayers<maxplayers)
3800                                                         for(j=1;j<numplayers;j++){
3801                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
3802                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
3803                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3804                                                         for(k=0;k<player[j].num_weapons;k++){
3805                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
3806                                                         }
3807                                                         if(player[j].numwaypoints<30){
3808                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3809                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
3810                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3811                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
3812                                                         }
3813                                                         else{
3814                                                         player[j].numwaypoints=0;
3815                                                         player[j].waypoint=0;
3816                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
3817                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3818                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
3819                                                         }
3820                                                         }
3821                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
3822                                                         if(numpathpoints)
3823                                                         for(j=0;j<numpathpoints;j++){
3824                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
3825                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
3826                                                         for(k=0;k<numpathpointconnect[j];k++){
3827                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
3828                                                         }
3829                                                         }
3830                                                         fclose(tfile);
3831                                                         donesomething=1;
3832                                                         }*/
3833                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
3834                                                                 LoadTextureSave("/Data/Textures/Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
3835                                                                 donesomething=1;
3836                                                         }
3837                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
3838                                                         AddClothes("/Data/Textures/Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
3839                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
3840                                                         donesomething=1;
3841                                                         }*/
3842
3843                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
3844                                                                 for(j=6;j<consolechars[0];j++){
3845                                                                         mapname[j-6]=consoletext[0][j];
3846                                                                 }
3847
3848                                                                 tintr=atof(mapname);
3849
3850                                                                 donesomething=1;
3851                                                         }
3852
3853                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
3854                                                                 for(j=6;j<consolechars[0];j++){
3855                                                                         mapname[j-6]=consoletext[0][j];
3856                                                                 }
3857
3858                                                                 player[0].speedmult=atof(mapname);
3859
3860                                                                 donesomething=1;
3861                                                         }
3862
3863                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
3864                                                                 for(j=9;j<consolechars[0];j++){
3865                                                                         mapname[j-9]=consoletext[0][j];
3866                                                                 }
3867
3868                                                                 player[0].power=atof(mapname);
3869
3870                                                                 donesomething=1;
3871                                                         }
3872
3873                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
3874                                                                 for(j=13;j<consolechars[0];j++){
3875                                                                         mapname[j-13]=consoletext[0][j];
3876                                                                 }
3877
3878                                                                 viewdistance=atof(mapname)*100;
3879
3880                                                                 donesomething=1;
3881                                                         }
3882
3883                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
3884                                                                 for(j=10;j<consolechars[0];j++){
3885                                                                         mapname[j-10]=consoletext[0][j];
3886                                                                 }
3887
3888                                                                 fadestart=atof(mapname);
3889
3890                                                                 donesomething=1;
3891                                                         }
3892
3893                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
3894                                                                 for(j=6;j<consolechars[0];j++){
3895                                                                         mapname[j-6]=consoletext[0][j];
3896                                                                 }
3897
3898                                                                 player[0].power=atof(mapname);
3899
3900                                                                 donesomething=1;
3901                                                         }
3902
3903                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
3904                                                                 for(j=6;j<consolechars[0];j++){
3905                                                                         mapname[j-6]=consoletext[0][j];
3906                                                                 }
3907
3908                                                                 slomospeed=atof(mapname);
3909                                                                 slomo=1-slomo;
3910                                                                 slomodelay=1000;
3911
3912                                                                 donesomething=1;
3913                                                         }
3914
3915                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
3916                                                                 for(j=8;j<consolechars[0];j++){
3917                                                                         mapname[j-8]=consoletext[0][j];
3918                                                                 }
3919
3920                                                                 slomofreq=atoi(mapname);
3921
3922                                                                 donesomething=1;
3923                                                         }
3924
3925                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
3926                                                                 for(j=5;j<consolechars[0];j++){
3927                                                                         mapname[j-5]=consoletext[0][j];
3928                                                                 }
3929
3930                                                                 player[0].scale=atof(mapname)*.2;
3931
3932                                                                 donesomething=1;
3933                                                         }
3934
3935                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
3936                                                                 int closest=-1;
3937                                                                 float closestdist=-1;
3938                                                                 float distance;
3939                                                                 if(numplayers>1)
3940                                                                         for(i=1;i<numplayers;i++){
3941                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3942                                                                                 if(closestdist==-1||distance<closestdist){
3943                                                                                         closestdist=distance;
3944                                                                                         closest=i;
3945                                                                                 }
3946                                                                         }
3947
3948                                                                         for(j=9;j<consolechars[0];j++){
3949                                                                                 mapname[j-9]=consoletext[0][j];
3950                                                                         }
3951
3952                                                                         player[closest].scale=atof(mapname)*.2;
3953
3954                                                                         donesomething=1;
3955                                                         }
3956
3957                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
3958                                                                 int startpoint;
3959                                                                 int alldone;
3960
3961                                                                 int closest=-1;
3962                                                                 float closestdist=-1;
3963                                                                 float distance;
3964                                                                 if(numplayers>1)
3965                                                                         for(i=1;i<numplayers;i++){
3966                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
3967                                                                                 if(closestdist==-1||distance<closestdist){
3968                                                                                         closestdist=distance;
3969                                                                                         closest=i;
3970                                                                                 }
3971                                                                         }
3972
3973                                                                         alldone=0;
3974                                                                         startpoint=15;
3975                                                                         j=startpoint;
3976                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3977                                                                                 mapname[j-startpoint]=consoletext[0][j];
3978                                                                                 j++;
3979                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3980                                                                         }
3981                                                                         mapname[j-startpoint]='\0';
3982
3983                                                                         headprop=atof(mapname);
3984
3985                                                                         j++;
3986                                                                         startpoint=j;
3987                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3988                                                                                 mapname[j-startpoint]=consoletext[0][j];
3989                                                                                 j++;
3990                                                                                 if(consoletext[0][j]=='\0')alldone=1;
3991                                                                         }
3992                                                                         mapname[j-startpoint]='\0';
3993
3994                                                                         bodyprop=atof(mapname);
3995
3996                                                                         j++;
3997                                                                         startpoint=j;
3998                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
3999                                                                                 mapname[j-startpoint]=consoletext[0][j];
4000                                                                                 j++;
4001                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4002                                                                         }
4003                                                                         mapname[j-startpoint]='\0';
4004
4005                                                                         armprop=atof(mapname);
4006
4007                                                                         j++;
4008                                                                         startpoint=j;
4009                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4010                                                                                 mapname[j-startpoint]=consoletext[0][j];
4011                                                                                 j++;
4012                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4013                                                                         }
4014                                                                         mapname[j-startpoint]='\0';
4015
4016                                                                         legprop=atof(mapname);
4017
4018                                                                         if(player[closest].creature==wolftype){
4019                                                                                 player[closest].proportionhead=1.1*headprop;
4020                                                                                 player[closest].proportionbody=1.1*bodyprop;
4021                                                                                 player[closest].proportionarms=1.1*armprop;
4022                                                                                 player[closest].proportionlegs=1.1*legprop;
4023                                                                         }
4024
4025                                                                         if(player[closest].creature==rabbittype){
4026                                                                                 player[closest].proportionhead=1.2*headprop;
4027                                                                                 player[closest].proportionbody=1.05*bodyprop;
4028                                                                                 player[closest].proportionarms=1.00*armprop;
4029                                                                                 player[closest].proportionlegs=1.1*legprop;
4030                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4031                                                                         }
4032
4033                                                                         donesomething=1;
4034                                                         }
4035
4036
4037                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4038                                                                 for(i=1;i<numplayers;i++){
4039                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4040                                                                 }
4041
4042                                                                 donesomething=1;
4043                                                         }
4044
4045                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4046                                                                 for(j=9;j<consolechars[0];j++){
4047                                                                         mapname[j-9]=consoletext[0][j];
4048                                                                 }
4049
4050                                                                 tutoriallevel=atoi(mapname);
4051
4052                                                                 donesomething=1;
4053                                                         }
4054
4055
4056                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4057                                                                 for(j=6;j<consolechars[0];j++){
4058                                                                         mapname[j-6]=consoletext[0][j];
4059                                                                 }
4060
4061                                                                 tintg=atof(mapname);
4062
4063                                                                 donesomething=1;
4064                                                         }
4065
4066                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4067                                                                 for(j=6;j<consolechars[0];j++){
4068                                                                         mapname[j-6]=consoletext[0][j];
4069                                                                 }
4070
4071                                                                 tintb=atof(mapname);
4072
4073                                                                 donesomething=1;
4074                                                         }
4075
4076                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4077                                                                 for(j=8;j<consolechars[0];j++){
4078                                                                         mapname[j-8]=consoletext[0][j];
4079                                                                 }
4080
4081                                                                 hostile=atoi(mapname);
4082
4083                                                                 donesomething=1;
4084                                                         }
4085
4086
4087                                                         if(Compare(consoletext[0],"type active ",0,11)){
4088                                                                 editoractive=typeactive;
4089
4090                                                                 donesomething=1;
4091                                                         }
4092
4093                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4094                                                                 indemo=1;
4095                                                                 hotspot[numhotspots]=player[0].coords;
4096                                                                 hotspotsize[numhotspots]=0;
4097                                                                 hotspottype[numhotspots]=-111;
4098                                                                 mapname[0]='\0';
4099                                                                 strcpy(hotspottext[numhotspots],"mapname");
4100                                                                 numhotspots++;
4101
4102                                                                 donesomething=1;
4103                                                         }
4104
4105                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4106                                                                 indemo=0;
4107                                                                 numhotspots--;
4108
4109                                                                 donesomething=1;
4110                                                         }
4111
4112                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4113                                                                 editoractive=typesitting;
4114
4115                                                                 donesomething=1;
4116                                                         }
4117
4118                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4119                                                                 editoractive=typesittingwall;
4120
4121                                                                 donesomething=1;
4122                                                         }
4123
4124                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4125                                                                 editoractive=typesleeping;
4126
4127                                                                 donesomething=1;
4128                                                         }
4129                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4130                                                                 editoractive=typedead1;
4131
4132                                                                 donesomething=1;
4133                                                         }
4134                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4135                                                                 editoractive=typedead2;
4136
4137                                                                 donesomething=1;
4138                                                         }
4139                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4140                                                                 editoractive=typedead3;
4141                                                                 donesomething=1;
4142                                                         }
4143                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4144                                                                 editoractive=typedead4;
4145
4146                                                                 donesomething=1;
4147                                                         }
4148
4149                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4150                                                                 editorpathtype=wpkeepwalking;
4151
4152                                                                 donesomething=1;
4153                                                         }
4154
4155                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4156                                                                 editorpathtype=wppause;
4157
4158                                                                 donesomething=1;
4159                                                         }
4160
4161                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4162                                                                 maptype=mapkilleveryone;
4163
4164                                                                 donesomething=1;
4165                                                         }
4166
4167                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4168                                                                 maptype=mapgosomewhere;
4169
4170                                                                 donesomething=1;
4171                                                         }
4172
4173                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4174                                                                 maptype=mapkillsomeone;
4175
4176                                                                 donesomething=1;
4177
4178                                                         }
4179
4180                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4181                                                                 maptype=mapkillmost;
4182
4183                                                                 donesomething=1;
4184
4185                                                         }
4186
4187                                                         if(Compare(consoletext[0],"hs ",0,2)){
4188                                                                 int startpoint;
4189                                                                 int alldone;
4190
4191                                                                 hotspot[numhotspots]=player[0].coords;
4192
4193                                                                 alldone=0;
4194                                                                 startpoint=3;
4195                                                                 j=startpoint;
4196                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4197                                                                         mapname[j-startpoint]=consoletext[0][j];
4198                                                                         j++;
4199                                                                         if(consoletext[0][j]=='\0')alldone=1;
4200                                                                 }
4201                                                                 mapname[j-startpoint]='\0';
4202
4203                                                                 hotspotsize[numhotspots]=atof(mapname);
4204
4205                                                                 j++;
4206                                                                 startpoint=j;
4207                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4208                                                                         mapname[j-startpoint]=consoletext[0][j];
4209                                                                         j++;
4210                                                                         if(consoletext[0][j]=='\0')alldone=1;
4211                                                                 }
4212                                                                 mapname[j-startpoint]='\0';
4213
4214                                                                 hotspottype[numhotspots]=atoi(mapname);
4215
4216                                                                 j++;
4217                                                                 startpoint=j;
4218                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4219                                                                         mapname[j-startpoint]=consoletext[0][j];
4220                                                                         j++;
4221                                                                         if(consoletext[0][j]=='\0')alldone=1;
4222                                                                 }
4223                                                                 mapname[j-startpoint]='\n';
4224                                                                 mapname[j-startpoint+1]='\0';
4225
4226                                                                 strcpy(hotspottext[numhotspots],mapname);
4227
4228                                                                 numhotspots++;
4229
4230                                                                 donesomething=1;
4231                                                         }
4232
4233                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4234                                                                 int startpoint;
4235                                                                 int alldone;
4236
4237                                                                 alldone=0;
4238                                                                 startpoint=9;
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                                                                 startpoint=j+1;
4247
4248                                                                 dialoguetype[numdialogues]=atoi(mapname);
4249
4250                                                                 mapname[0]=':';
4251                                                                 mapname[1]='D';
4252                                                                 mapname[2]='a';
4253                                                                 mapname[3]='t';
4254                                                                 mapname[4]='a';
4255                                                                 mapname[5]=':';
4256                                                                 mapname[6]='D';
4257                                                                 mapname[7]='i';
4258                                                                 mapname[8]='a';
4259                                                                 mapname[9]='l';
4260                                                                 mapname[10]='o';
4261                                                                 mapname[11]='g';
4262                                                                 mapname[12]='u';
4263                                                                 mapname[13]='e';
4264                                                                 mapname[14]='s';
4265                                                                 mapname[15]=':';
4266                                                                 for(j=startpoint;j<consolechars[0];j++){
4267                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4268                                                                 }
4269                                                                 mapname[consolechars[0]-startpoint+16]='.';
4270                                                                 mapname[consolechars[0]-startpoint+17]='t';
4271                                                                 mapname[consolechars[0]-startpoint+18]='x';
4272                                                                 mapname[consolechars[0]-startpoint+19]='t';
4273                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4274
4275                                                                 for(j=0;j<max_dialoguelength;j++){
4276                                                                         for(k=0;k<128;k++){
4277                                                                                 dialoguetext[numdialogues][j][k]='\0';
4278                                                                         }
4279                                                                         for(k=0;k<64;k++){
4280                                                                                 dialoguename[numdialogues][j][k]='\0';
4281                                                                         }
4282                                                                 }
4283
4284                                                                 ifstream ipstream(ConvertFileName(mapname));
4285                                                                 ipstream.ignore(256,':');
4286                                                                 ipstream >> numdialogueboxes[numdialogues];
4287                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4288                                                                         ipstream.ignore(256,':');
4289                                                                         ipstream.ignore(256,':');
4290                                                                         ipstream.ignore(256,' ');
4291                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4292                                                                         ipstream.ignore(256,':');
4293                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4294                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4295                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4296                                                                         ipstream.ignore(256,':');
4297                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4298                                                                         ipstream.ignore(256,':');
4299                                                                         ipstream.ignore(256,' ');
4300                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4301                                                                         for(j=0;j<128;j++){
4302                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4303                                                                         }
4304                                                                         ipstream.ignore(256,':');
4305                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4306                                                                 }
4307
4308                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4309                                                                         for(j=0;j<numplayers;j++){
4310                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4311                                                                         }
4312                                                                 }
4313                                                                 ipstream.close();
4314
4315                                                                 directing=1;
4316                                                                 indialogue=0;
4317                                                                 whichdialogue=numdialogues;
4318
4319
4320                                                                 numdialogues++;
4321
4322                                                                 donesomething=1;
4323                                                         }
4324
4325                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4326                                                                 int startpoint;
4327                                                                 int alldone;
4328                                                                 int whichdi;
4329
4330                                                                 alldone=0;
4331                                                                 startpoint=12;
4332                                                                 j=startpoint;
4333                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4334                                                                         mapname[j-startpoint]=consoletext[0][j];
4335                                                                         j++;
4336                                                                         if(consoletext[0][j]=='\0')alldone=1;
4337                                                                 }
4338                                                                 mapname[j-startpoint]='\0';
4339                                                                 startpoint=j+1;
4340
4341                                                                 whichdi=atoi(mapname);
4342
4343                                                                 mapname[0]=':';
4344                                                                 mapname[1]='D';
4345                                                                 mapname[2]='a';
4346                                                                 mapname[3]='t';
4347                                                                 mapname[4]='a';
4348                                                                 mapname[5]=':';
4349                                                                 mapname[6]='D';
4350                                                                 mapname[7]='i';
4351                                                                 mapname[8]='a';
4352                                                                 mapname[9]='l';
4353                                                                 mapname[10]='o';
4354                                                                 mapname[11]='g';
4355                                                                 mapname[12]='u';
4356                                                                 mapname[13]='e';
4357                                                                 mapname[14]='s';
4358                                                                 mapname[15]=':';
4359                                                                 for(j=startpoint;j<consolechars[0];j++){
4360                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4361                                                                 }
4362                                                                 mapname[consolechars[0]-startpoint+16]='.';
4363                                                                 mapname[consolechars[0]-startpoint+17]='t';
4364                                                                 mapname[consolechars[0]-startpoint+18]='x';
4365                                                                 mapname[consolechars[0]-startpoint+19]='t';
4366                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4367
4368                                                                 for(j=0;j<max_dialoguelength;j++){
4369                                                                         for(k=0;k<128;k++){
4370                                                                                 dialoguetext[whichdi][j][k]='\0';
4371                                                                         }
4372                                                                         for(k=0;k<64;k++){
4373                                                                                 dialoguename[whichdi][j][k]='\0';
4374                                                                         }
4375                                                                 }
4376
4377                                                                 ifstream ipstream(ConvertFileName(mapname));
4378                                                                 ipstream.ignore(256,':');
4379                                                                 ipstream >> numdialogueboxes[whichdi];
4380                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4381                                                                         ipstream.ignore(256,':');
4382                                                                         ipstream.ignore(256,':');
4383                                                                         ipstream.ignore(256,' ');
4384                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4385                                                                         ipstream.ignore(256,':');
4386                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4387                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4388                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4389                                                                         ipstream.ignore(256,':');
4390                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4391                                                                         ipstream.ignore(256,':');
4392                                                                         ipstream.ignore(256,' ');
4393                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4394                                                                         for(j=0;j<128;j++){
4395                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4396                                                                         }
4397                                                                         ipstream.ignore(256,':');
4398                                                                         ipstream >> dialogueboxsound[whichdi][i];
4399                                                                 }
4400
4401                                                                 ipstream.close();
4402
4403                                                                 donesomething=1;
4404                                                         }
4405
4406                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4407                                                                 int startpoint;
4408                                                                 int alldone;
4409                                                                 int whichdi;
4410
4411                                                                 alldone=0;
4412                                                                 startpoint=8;
4413                                                                 j=startpoint;
4414                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4415                                                                         mapname[j-startpoint]=consoletext[0][j];
4416                                                                         j++;
4417                                                                         if(consoletext[0][j]=='\0')alldone=1;
4418                                                                 }
4419                                                                 mapname[j-startpoint]='\0';
4420                                                                 dialoguetype[0]=atoi(mapname);
4421
4422                                                                 startpoint=j+1;
4423
4424                                                                 donesomething=1;
4425                                                         }
4426
4427
4428                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4429                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4430
4431                                                                 donesomething=1;
4432                                                         }
4433
4434                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4435                                                                 numdialogues--;
4436                                                                 if(numdialogues<0)numdialogues=0;
4437
4438                                                                 donesomething=1;
4439                                                         }
4440
4441                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4442                                                                 player[0].immobile=1;
4443                                                                 donesomething=1;
4444                                                         }
4445
4446                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4447                                                                 player[0].immobile=0;
4448                                                                 donesomething=1;
4449                                                         }
4450
4451                                                         if(Compare(consoletext[0],"play ",0,4)){
4452                                                                 int startpoint;
4453                                                                 int alldone;
4454
4455                                                                 alldone=0;
4456                                                                 startpoint=5;
4457                                                                 j=startpoint;
4458                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4459                                                                         mapname[j-startpoint]=consoletext[0][j];
4460                                                                         j++;
4461                                                                         if(consoletext[0][j]=='\0')alldone=1;
4462                                                                 }
4463                                                                 mapname[j-startpoint]='\0';
4464                                                                 startpoint=j+1;
4465
4466                                                                 whichdialogue=atoi(mapname);
4467
4468                                                                 if(numdialogues>whichdialogue){
4469                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4470                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4471                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4472                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4473                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4474                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4475                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4476                                                                         }
4477
4478                                                                         directing=0;
4479                                                                         indialogue=0;
4480
4481                                                                         donesomething=1;
4482
4483                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4484                                                                         float gLoc[3];
4485                                                                         float vel[3];
4486                                                                         XYZ temppos;
4487                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4488                                                                         temppos=temppos-viewer;
4489                                                                         Normalise(&temppos);
4490                                                                         temppos+=viewer;
4491
4492                                                                         gLoc[0]=temppos.x;
4493                                                                         gLoc[1]=temppos.y;
4494                                                                         gLoc[2]=temppos.z;
4495                                                                         vel[0]=0;
4496                                                                         vel[1]=0;
4497                                                                         vel[2]=0;
4498                                                                         int whichsoundplay;
4499                                                                         whichsoundplay=rabbitchitter;
4500                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4501                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4502                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4503                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4504                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4505                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4506                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4507                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4508                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4509                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4510                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4511                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4512                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4513                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4514                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4515                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4516                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4517                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4518                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4519                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4520                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4521                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4522                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4523                                                                         //}
4524                                                                 }
4525                                                         }
4526
4527
4528
4529
4530                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4531                                                                 numhotspots--;
4532                                                                 if(numhotspots<0)numhotspots=0;
4533                                                                 donesomething=1;
4534                                                         }
4535
4536
4537                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4538                                                                 int startpoint;
4539                                                                 int alldone;
4540
4541                                                                 alldone=0;
4542                                                                 startpoint=11;
4543                                                                 j=startpoint;
4544                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4545                                                                         mapname[j-startpoint]=consoletext[0][j];
4546                                                                         j++;
4547                                                                         if(consoletext[0][j]=='\0')alldone=1;
4548                                                                 }
4549                                                                 mapname[j-startpoint]='\0';
4550
4551                                                                 headprop=atof(mapname);
4552
4553                                                                 j++;
4554                                                                 startpoint=j;
4555                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4556                                                                         mapname[j-startpoint]=consoletext[0][j];
4557                                                                         j++;
4558                                                                         if(consoletext[0][j]=='\0')alldone=1;
4559                                                                 }
4560                                                                 mapname[j-startpoint]='\0';
4561
4562                                                                 bodyprop=atof(mapname);
4563
4564                                                                 j++;
4565                                                                 startpoint=j;
4566                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4567                                                                         mapname[j-startpoint]=consoletext[0][j];
4568                                                                         j++;
4569                                                                         if(consoletext[0][j]=='\0')alldone=1;
4570                                                                 }
4571                                                                 mapname[j-startpoint]='\0';
4572
4573                                                                 armprop=atof(mapname);
4574
4575                                                                 j++;
4576                                                                 startpoint=j;
4577                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4578                                                                         mapname[j-startpoint]=consoletext[0][j];
4579                                                                         j++;
4580                                                                         if(consoletext[0][j]=='\0')alldone=1;
4581                                                                 }
4582                                                                 mapname[j-startpoint]='\0';
4583
4584                                                                 legprop=atof(mapname);
4585
4586                                                                 if(player[0].creature==wolftype){
4587                                                                         player[0].proportionhead=1.1*headprop;
4588                                                                         player[0].proportionbody=1.1*bodyprop;
4589                                                                         player[0].proportionarms=1.1*armprop;
4590                                                                         player[0].proportionlegs=1.1*legprop;
4591                                                                 }
4592
4593                                                                 if(player[0].creature==rabbittype){
4594                                                                         player[0].proportionhead=1.2*headprop;
4595                                                                         player[0].proportionbody=1.05*bodyprop;
4596                                                                         player[0].proportionarms=1.00*armprop;
4597                                                                         player[0].proportionlegs=1.1*legprop;
4598                                                                         player[0].proportionlegs.y=1.05*legprop;
4599                                                                 }
4600
4601                                                                 donesomething=1;
4602                                                         }
4603
4604                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4605                                                                 for(i=0;i<numplayers;i++){
4606                                                                         if(i>0)player[i].immobile=1;
4607                                                                 }
4608                                                                 donesomething=1;
4609                                                         }
4610
4611
4612                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4613                                                                 player[0].armorhead=1;
4614                                                                 player[0].armorhigh=1;
4615                                                                 player[0].armorlow=1;
4616                                                                 player[0].protectionhead=1;
4617                                                                 player[0].protectionhigh=1;
4618                                                                 player[0].protectionlow=1;
4619                                                                 player[0].metalhead=1;
4620                                                                 player[0].metalhigh=1;
4621                                                                 player[0].metallow=1;
4622                                                                 player[0].power=1;
4623                                                                 player[0].speedmult=1;
4624                                                                 player[0].scale=1;
4625
4626                                                                 if(player[0].creature==wolftype){
4627                                                                         player[0].proportionhead=1.1;
4628                                                                         player[0].proportionbody=1.1;
4629                                                                         player[0].proportionarms=1.1;
4630                                                                         player[0].proportionlegs=1.1;
4631                                                                 }
4632
4633                                                                 if(player[0].creature==rabbittype){
4634                                                                         player[0].proportionhead=1.2;
4635                                                                         player[0].proportionbody=1.05;
4636                                                                         player[0].proportionarms=1.00;
4637                                                                         player[0].proportionlegs=1.1;
4638                                                                         player[0].proportionlegs.y=1.05;
4639                                                                 }
4640
4641                                                                 player[0].numclothes=0;
4642                                                                 if(player[0].whichskin==0){
4643                                                                         LoadTextureSave("/Data/Textures/Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4644                                                                 }
4645                                                                 else if(player[0].whichskin==1){
4646                                                                         LoadTextureSave("/Data/Textures/Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4647                                                                 }
4648                                                                 else if(player[0].whichskin==2){
4649                                                                         LoadTextureSave("/Data/Textures/Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4650                                                                 }
4651                                                                 else if(player[0].whichskin==3){
4652                                                                         LoadTextureSave("/Data/Textures/Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4653                                                                 }
4654                                                                 else if(player[0].whichskin==4){
4655                                                                         LoadTextureSave("/Data/Textures/Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4656                                                                 }
4657                                                                 else if(player[0].whichskin==5){
4658                                                                         LoadTextureSave("/Data/Textures/Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4659                                                                 }
4660                                                                 else if(player[0].whichskin==6){
4661                                                                         LoadTextureSave("/Data/Textures/Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4662                                                                 }
4663                                                                 else if(player[0].whichskin==7){
4664                                                                         LoadTextureSave("/Data/Textures/Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4665                                                                 }
4666                                                                 else if(player[0].whichskin==8){
4667                                                                         LoadTextureSave("/Data/Textures/BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4668                                                                 }
4669                                                                 else if(player[0].whichskin==9){
4670                                                                         LoadTextureSave("/Data/Textures/WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4671                                                                 }
4672
4673                                                                 editoractive=typeactive;
4674                                                                 player[0].immobile=0;
4675
4676
4677
4678                                                                 donesomething=1;
4679                                                         }
4680
4681                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
4682                                                                 int startpoint;
4683                                                                 int alldone;
4684                                                                 alldone=0;
4685                                                                 startpoint=5;
4686                                                                 j=startpoint;
4687                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4688                                                                         mapname[j-startpoint]=consoletext[0][j];
4689                                                                         j++;
4690                                                                         if(consoletext[0][j]=='\0')alldone=1;
4691                                                                 }
4692                                                                 mapname[j-startpoint]='\0';
4693
4694                                                                 tintr=atof(mapname);
4695
4696                                                                 j++;
4697                                                                 startpoint=j;
4698                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4699                                                                         mapname[j-startpoint]=consoletext[0][j];
4700                                                                         j++;
4701                                                                         if(consoletext[0][j]=='\0')alldone=1;
4702                                                                 }
4703                                                                 mapname[j-startpoint]='\0';
4704
4705                                                                 tintg=atof(mapname);
4706
4707                                                                 j++;
4708                                                                 startpoint=j;
4709                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4710                                                                         mapname[j-startpoint]=consoletext[0][j];
4711                                                                         j++;
4712                                                                         if(consoletext[0][j]=='\0')alldone=1;
4713                                                                 }
4714                                                                 mapname[j-startpoint]='\0';
4715
4716                                                                 tintb=atof(mapname);
4717
4718                                                                 donesomething=1;
4719                                                         }
4720
4721                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
4722                                                                 int startpoint;
4723                                                                 int alldone;
4724                                                                 alldone=0;
4725                                                                 startpoint=9;
4726                                                                 j=startpoint;
4727                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4728                                                                         mapname[j-startpoint]=consoletext[0][j];
4729                                                                         j++;
4730                                                                         if(consoletext[0][j]=='\0')alldone=1;
4731                                                                 }
4732                                                                 mapname[j-startpoint]='\0';
4733
4734                                                                 skyboxr=atof(mapname);
4735
4736                                                                 j++;
4737                                                                 startpoint=j;
4738                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4739                                                                         mapname[j-startpoint]=consoletext[0][j];
4740                                                                         j++;
4741                                                                         if(consoletext[0][j]=='\0')alldone=1;
4742                                                                 }
4743                                                                 mapname[j-startpoint]='\0';
4744
4745                                                                 skyboxg=atof(mapname);
4746
4747                                                                 j++;
4748                                                                 startpoint=j;
4749                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4750                                                                         mapname[j-startpoint]=consoletext[0][j];
4751                                                                         j++;
4752                                                                         if(consoletext[0][j]=='\0')alldone=1;
4753                                                                 }
4754                                                                 mapname[j-startpoint]='\0';
4755
4756                                                                 skyboxb=atof(mapname);
4757
4758                                                                 skyboxlightr=skyboxr;
4759                                                                 skyboxlightg=skyboxg;
4760                                                                 skyboxlightb=skyboxb;
4761
4762                                                                 SetUpLighting();
4763
4764                                                                 //if(skyboxtexture){
4765                                                                 terrain.DoShadows();
4766                                                                 objects.DoShadows();
4767                                                                 /*}
4768                                                                 else terrain.DoLighting();
4769                                                                 */
4770                                                                 donesomething=1;
4771                                                         }
4772
4773                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
4774                                                                 int startpoint;
4775                                                                 int alldone;
4776                                                                 alldone=0;
4777                                                                 startpoint=10;
4778                                                                 j=startpoint;
4779                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4780                                                                         mapname[j-startpoint]=consoletext[0][j];
4781                                                                         j++;
4782                                                                         if(consoletext[0][j]=='\0')alldone=1;
4783                                                                 }
4784                                                                 mapname[j-startpoint]='\0';
4785
4786                                                                 skyboxlightr=atof(mapname);
4787
4788                                                                 j++;
4789                                                                 startpoint=j;
4790                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4791                                                                         mapname[j-startpoint]=consoletext[0][j];
4792                                                                         j++;
4793                                                                         if(consoletext[0][j]=='\0')alldone=1;
4794                                                                 }
4795                                                                 mapname[j-startpoint]='\0';
4796
4797                                                                 skyboxlightg=atof(mapname);
4798
4799                                                                 j++;
4800                                                                 startpoint=j;
4801                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4802                                                                         mapname[j-startpoint]=consoletext[0][j];
4803                                                                         j++;
4804                                                                         if(consoletext[0][j]=='\0')alldone=1;
4805                                                                 }
4806                                                                 mapname[j-startpoint]='\0';
4807
4808                                                                 skyboxlightb=atof(mapname);
4809
4810                                                                 SetUpLighting();
4811
4812                                                                 //if(skyboxtexture){
4813                                                                 terrain.DoShadows();
4814                                                                 objects.DoShadows();
4815                                                                 /*}
4816                                                                 else terrain.DoLighting();
4817                                                                 */
4818                                                                 donesomething=1;
4819                                                         }
4820
4821                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
4822                                                                 skyboxtexture=1-skyboxtexture;
4823
4824                                                                 SetUpLighting();
4825                                                                 //if(skyboxtexture){
4826                                                                 terrain.DoShadows();
4827                                                                 objects.DoShadows();
4828                                                                 /*}
4829                                                                 else terrain.DoLighting();
4830                                                                 */
4831                                                                 donesomething=1;
4832                                                         }
4833
4834                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
4835                                                                 int startpoint;
4836                                                                 int alldone;
4837                                                                 alldone=0;
4838                                                                 startpoint=11;
4839                                                                 j=startpoint;
4840                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4841                                                                         mapname[j-startpoint]=consoletext[0][j];
4842                                                                         j++;
4843                                                                         if(consoletext[0][j]=='\0')alldone=1;
4844                                                                 }
4845                                                                 mapname[j-startpoint]='\0';
4846
4847                                                                 player[0].protectionhead=atof(mapname);
4848
4849                                                                 j++;
4850                                                                 startpoint=j;
4851                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4852                                                                         mapname[j-startpoint]=consoletext[0][j];
4853                                                                         j++;
4854                                                                         if(consoletext[0][j]=='\0')alldone=1;
4855                                                                 }
4856                                                                 mapname[j-startpoint]='\0';
4857
4858                                                                 player[0].protectionhigh=atof(mapname);
4859
4860                                                                 j++;
4861                                                                 startpoint=j;
4862                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4863                                                                         mapname[j-startpoint]=consoletext[0][j];
4864                                                                         j++;
4865                                                                         if(consoletext[0][j]=='\0')alldone=1;
4866                                                                 }
4867                                                                 mapname[j-startpoint]='\0';
4868
4869                                                                 player[0].protectionlow=atof(mapname);
4870
4871                                                                 donesomething=1;
4872                                                         }
4873
4874                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
4875                                                                 int startpoint;
4876                                                                 int alldone;
4877                                                                 alldone=0;
4878                                                                 startpoint=6;
4879                                                                 j=startpoint;
4880                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4881                                                                         mapname[j-startpoint]=consoletext[0][j];
4882                                                                         j++;
4883                                                                         if(consoletext[0][j]=='\0')alldone=1;
4884                                                                 }
4885                                                                 mapname[j-startpoint]='\0';
4886
4887                                                                 player[0].armorhead=atof(mapname);
4888
4889                                                                 j++;
4890                                                                 startpoint=j;
4891                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4892                                                                         mapname[j-startpoint]=consoletext[0][j];
4893                                                                         j++;
4894                                                                         if(consoletext[0][j]=='\0')alldone=1;
4895                                                                 }
4896                                                                 mapname[j-startpoint]='\0';
4897
4898                                                                 player[0].armorhigh=atof(mapname);
4899
4900                                                                 j++;
4901                                                                 startpoint=j;
4902                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4903                                                                         mapname[j-startpoint]=consoletext[0][j];
4904                                                                         j++;
4905                                                                         if(consoletext[0][j]=='\0')alldone=1;
4906                                                                 }
4907                                                                 mapname[j-startpoint]='\0';
4908
4909                                                                 player[0].armorlow=atof(mapname);
4910
4911                                                                 donesomething=1;
4912                                                         }
4913
4914                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
4915                                                                 for(i=0;i<numplayers;i++){
4916                                                                         player[i].protectionhead=1.0;
4917                                                                         player[i].protectionhigh=1.0;
4918                                                                         player[i].protectionlow=1.0;
4919                                                                         player[i].armorhead=1.0;
4920                                                                         player[i].armorhigh=1.0;
4921                                                                         player[i].armorlow=1.0;
4922                                                                 }
4923
4924                                                                 donesomething=1;
4925                                                         }
4926
4927                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
4928                                                                 int closest=-1;
4929                                                                 float closestdist=-1;
4930                                                                 float distance;
4931                                                                 if(numplayers>1)
4932                                                                         for(i=1;i<numplayers;i++){
4933                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4934                                                                                 if(closestdist==-1||distance<closestdist){
4935                                                                                         closestdist=distance;
4936                                                                                         closest=i;
4937                                                                                 }
4938                                                                         }
4939
4940                                                                         int startpoint;
4941                                                                         int alldone;
4942                                                                         alldone=0;
4943                                                                         startpoint=15;
4944                                                                         j=startpoint;
4945                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4946                                                                                 mapname[j-startpoint]=consoletext[0][j];
4947                                                                                 j++;
4948                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4949                                                                         }
4950                                                                         mapname[j-startpoint]='\0';
4951
4952                                                                         player[closest].protectionhead=atof(mapname);
4953
4954                                                                         j++;
4955                                                                         startpoint=j;
4956                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4957                                                                                 mapname[j-startpoint]=consoletext[0][j];
4958                                                                                 j++;
4959                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4960                                                                         }
4961                                                                         mapname[j-startpoint]='\0';
4962
4963                                                                         player[closest].protectionhigh=atof(mapname);
4964
4965                                                                         j++;
4966                                                                         startpoint=j;
4967                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4968                                                                                 mapname[j-startpoint]=consoletext[0][j];
4969                                                                                 j++;
4970                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4971                                                                         }
4972                                                                         mapname[j-startpoint]='\0';
4973
4974                                                                         player[closest].protectionlow=atof(mapname);
4975
4976                                                                         donesomething=1;
4977                                                         }
4978
4979                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
4980                                                                 int closest=-1;
4981                                                                 float closestdist=-1;
4982                                                                 float distance;
4983                                                                 if(numplayers>1)
4984                                                                         for(i=1;i<numplayers;i++){
4985                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4986                                                                                 if(closestdist==-1||distance<closestdist){
4987                                                                                         closestdist=distance;
4988                                                                                         closest=i;
4989                                                                                 }
4990                                                                         }
4991                                                                         int startpoint;
4992                                                                         int alldone;
4993                                                                         alldone=0;
4994                                                                         startpoint=10;
4995                                                                         j=startpoint;
4996                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4997                                                                                 mapname[j-startpoint]=consoletext[0][j];
4998                                                                                 j++;
4999                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5000                                                                         }
5001                                                                         mapname[j-startpoint]='\0';
5002
5003                                                                         player[closest].armorhead=atof(mapname);
5004
5005                                                                         j++;
5006                                                                         startpoint=j;
5007                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5008                                                                                 mapname[j-startpoint]=consoletext[0][j];
5009                                                                                 j++;
5010                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5011                                                                         }
5012                                                                         mapname[j-startpoint]='\0';
5013
5014                                                                         player[closest].armorhigh=atof(mapname);
5015
5016                                                                         j++;
5017                                                                         startpoint=j;
5018                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5019                                                                                 mapname[j-startpoint]=consoletext[0][j];
5020                                                                                 j++;
5021                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5022                                                                         }
5023                                                                         mapname[j-startpoint]='\0';
5024
5025                                                                         player[closest].armorlow=atof(mapname);
5026
5027                                                                         donesomething=1;
5028                                                         }
5029
5030
5031                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5032                                                                 int startpoint;
5033                                                                 int alldone;
5034                                                                 alldone=0;
5035                                                                 startpoint=6;
5036                                                                 j=startpoint;
5037                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5038                                                                         mapname[j-startpoint]=consoletext[0][j];
5039                                                                         j++;
5040                                                                         if(consoletext[0][j]=='\0')alldone=1;
5041                                                                 }
5042                                                                 mapname[j-startpoint]='\0';
5043
5044                                                                 player[0].metalhead=atof(mapname);
5045
5046                                                                 j++;
5047                                                                 startpoint=j;
5048                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5049                                                                         mapname[j-startpoint]=consoletext[0][j];
5050                                                                         j++;
5051                                                                         if(consoletext[0][j]=='\0')alldone=1;
5052                                                                 }
5053                                                                 mapname[j-startpoint]='\0';
5054
5055                                                                 player[0].metalhigh=atof(mapname);
5056
5057                                                                 j++;
5058                                                                 startpoint=j;
5059                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5060                                                                         mapname[j-startpoint]=consoletext[0][j];
5061                                                                         j++;
5062                                                                         if(consoletext[0][j]=='\0')alldone=1;
5063                                                                 }
5064
5065                                                                 mapname[j-startpoint]='\0';
5066
5067                                                                 player[0].metallow=atof(mapname);
5068
5069                                                                 donesomething=1;
5070                                                         }
5071
5072                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5073                                                                 int closest=-1;
5074                                                                 float closestdist=-1;
5075                                                                 float distance;
5076                                                                 if(numplayers>1)
5077                                                                         for(i=1;i<numplayers;i++){
5078                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5079                                                                                 if(closestdist==-1||distance<closestdist){
5080                                                                                         closestdist=distance;
5081                                                                                         closest=i;
5082                                                                                 }
5083                                                                         }
5084                                                                         player[closest].numclothes=0;
5085                                                                         if(player[closest].whichskin==0){
5086                                                                                 LoadTextureSave("/Data/Textures/Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5087                                                                         }
5088                                                                         else if(player[closest].whichskin==1){
5089                                                                                 LoadTextureSave("/Data/Textures/Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5090                                                                         }
5091                                                                         else if(player[closest].whichskin==2){
5092                                                                                 LoadTextureSave("/Data/Textures/Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5093                                                                         }
5094                                                                         else if(player[closest].whichskin==3){
5095                                                                                 LoadTextureSave("/Data/Textures/Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5096                                                                         }
5097                                                                         else if(player[closest].whichskin==4){
5098                                                                                 LoadTextureSave("/Data/Textures/Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5099                                                                         }
5100                                                                         else if(player[closest].whichskin==5){
5101                                                                                 LoadTextureSave("/Data/Textures/Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5102                                                                         }
5103                                                                         else if(player[closest].whichskin==6){
5104                                                                                 LoadTextureSave("/Data/Textures/Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5105                                                                         }
5106                                                                         else if(player[closest].whichskin==7){
5107                                                                                 LoadTextureSave("/Data/Textures/Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5108                                                                         }
5109                                                                         else if(player[closest].whichskin==8){
5110                                                                                 LoadTextureSave("/Data/Textures/BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5111                                                                         }
5112                                                                         else if(player[closest].whichskin==9){
5113                                                                                 LoadTextureSave("/Data/Textures/WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5114                                                                         }
5115
5116                                                                         donesomething=1;
5117                                                         }
5118
5119                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5120                                                                 int closest=0;
5121
5122                                                                 player[closest].numclothes=0;
5123                                                                 if(player[closest].whichskin==0){
5124                                                                         LoadTextureSave("/Data/Textures/Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5125                                                                 }
5126                                                                 else if(player[closest].whichskin==1){
5127                                                                         LoadTextureSave("/Data/Textures/Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5128                                                                 }
5129                                                                 else if(player[closest].whichskin==2){
5130                                                                         LoadTextureSave("/Data/Textures/Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5131                                                                 }
5132                                                                 else if(player[closest].whichskin==3){
5133                                                                         LoadTextureSave("/Data/Textures/Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5134                                                                 }
5135                                                                 else if(player[closest].whichskin==4){
5136                                                                         LoadTextureSave("/Data/Textures/Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5137                                                                 }
5138                                                                 else if(player[closest].whichskin==5){
5139                                                                         LoadTextureSave("/Data/Textures/Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5140                                                                 }
5141                                                                 else if(player[closest].whichskin==6){
5142                                                                         LoadTextureSave("/Data/Textures/Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5143                                                                 }
5144                                                                 else if(player[closest].whichskin==7){
5145                                                                         LoadTextureSave("/Data/Textures/Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5146                                                                 }
5147                                                                 else if(player[closest].whichskin==8){
5148                                                                         LoadTextureSave("/Data/Textures/BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5149                                                                 }
5150                                                                 else if(player[closest].whichskin==9){
5151                                                                         LoadTextureSave("/Data/Textures/WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5152                                                                 }
5153
5154                                                                 donesomething=1;
5155                                                         }
5156
5157                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5158                                                                 mapname[0]=':';
5159                                                                 mapname[1]='D';
5160                                                                 mapname[2]='a';
5161                                                                 mapname[3]='t';
5162                                                                 mapname[4]='a';
5163                                                                 mapname[5]=':';
5164                                                                 mapname[6]='T';
5165                                                                 mapname[7]='e';
5166                                                                 mapname[8]='x';
5167                                                                 mapname[9]='t';
5168                                                                 mapname[10]='u';
5169                                                                 mapname[11]='r';
5170                                                                 mapname[12]='e';
5171                                                                 mapname[13]='s';
5172                                                                 mapname[14]=':';
5173                                                                 for(j=8;j<consolechars[0];j++){
5174                                                                         mapname[j-8+15]=consoletext[0][j];
5175                                                                 }
5176                                                                 mapname[consolechars[0]-8+15]='.';
5177                                                                 mapname[consolechars[0]-8+16]='p';
5178                                                                 mapname[consolechars[0]-8+17]='n';
5179                                                                 mapname[consolechars[0]-8+18]='g';
5180                                                                 mapname[consolechars[0]-8+19]='\0';
5181
5182                                                                 //:Data:Textures:Pants.png
5183
5184                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5185                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5186                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5187                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5188                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5189                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5190                                                                         player[0].numclothes++;
5191                                                                 }
5192
5193                                                                 donesomething=1;
5194                                                         }
5195
5196                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5197                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5198
5199                                                                 donesomething=1;
5200                                                         }
5201
5202                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5203                                                                 cellophane=1-cellophane;
5204
5205                                                                 if(cellophane){
5206                                                                         for(i=0;i<numplayers;i++){
5207                                                                                 player[i].proportionhead.z=0;
5208                                                                                 player[i].proportionbody.z=0;
5209                                                                                 player[i].proportionarms.z=0;
5210                                                                                 player[i].proportionlegs.z=0;
5211                                                                         }
5212                                                                 }
5213
5214                                                                 if(!cellophane){
5215                                                                         for(i=0;i<numplayers;i++){
5216                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5217                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5218                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5219                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5220                                                                         }
5221                                                                 }
5222
5223                                                                 donesomething=1;
5224                                                         }
5225
5226                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5227                                                                 mapname[0]=':';
5228                                                                 mapname[1]='D';
5229                                                                 mapname[2]='a';
5230                                                                 mapname[3]='t';
5231                                                                 mapname[4]='a';
5232                                                                 mapname[5]=':';
5233                                                                 mapname[6]='T';
5234                                                                 mapname[7]='e';
5235                                                                 mapname[8]='x';
5236                                                                 mapname[9]='t';
5237                                                                 mapname[10]='u';
5238                                                                 mapname[11]='r';
5239                                                                 mapname[12]='e';
5240                                                                 mapname[13]='s';
5241                                                                 mapname[14]=':';
5242                                                                 for(j=12;j<consolechars[0];j++){
5243                                                                         mapname[j-12+15]=consoletext[0][j];
5244                                                                 }
5245                                                                 mapname[consolechars[0]-12+15]='.';
5246                                                                 mapname[consolechars[0]-12+16]='p';
5247                                                                 mapname[consolechars[0]-12+17]='n';
5248                                                                 mapname[consolechars[0]-12+18]='g';
5249                                                                 mapname[consolechars[0]-12+19]='\0';
5250
5251                                                                 //:Data:Textures:Pants.png
5252                                                                 int closest=-1;
5253                                                                 float closestdist=-1;
5254                                                                 float distance;
5255                                                                 if(numplayers>1)
5256                                                                         for(i=1;i<numplayers;i++){
5257                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5258                                                                                 if(closestdist==-1||distance<closestdist){
5259                                                                                         closestdist=distance;
5260                                                                                         closest=i;
5261                                                                                 }
5262                                                                         }
5263
5264                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5265                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5266                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5267                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5268                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5269                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5270                                                                                 player[closest].numclothes++;
5271                                                                         }
5272
5273                                                                         donesomething=1;
5274                                                         }
5275
5276                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5277                                                                 player[0].skeleton.id=0;
5278                                                                 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);
5279                                                                 LoadTextureSave("/Data/Textures/fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5280                                                                 player[0].creature=rabbittype;
5281                                                                 player[0].scale=.2;
5282
5283                                                                 player[0].proportionhead=1.2;
5284                                                                 player[0].proportionbody=1.05;
5285                                                                 player[0].proportionarms=1.00;
5286                                                                 player[0].proportionlegs=1.1;
5287                                                                 player[0].proportionlegs.y=1.05;
5288                                                                 player[0].headless=0;
5289
5290                                                                 player[0].damagetolerance=200;
5291
5292                                                                 donesomething=1;
5293                                                         }
5294                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5295                                                                 player[0].skeleton.id=0;
5296                                                                 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);
5297                                                                 LoadTextureSave("/Data/Textures/Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5298                                                                 player[0].creature=wolftype;
5299
5300                                                                 player[0].proportionhead=1.1;
5301                                                                 player[0].proportionbody=1.1;
5302                                                                 player[0].proportionarms=1.1;
5303                                                                 player[0].proportionlegs=1.1;
5304                                                                 player[0].proportionlegs.y=1.1;
5305                                                                 player[0].scale=.23;
5306
5307                                                                 player[0].damagetolerance=300;
5308
5309                                                                 donesomething=1;
5310                                                         }
5311                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5312                                                         LoadTextureSave("/Data/Textures/Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5313                                                         donesomething=1;
5314                                                         }
5315                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5316                                                         LoadTextureSave("/Data/Textures/Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5317                                                         donesomething=1;
5318                                                         }
5319                                                         if(Compare(consoletext[0],"david ",0,5)){
5320                                                         LoadTextureSave("/Data/Textures/David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5321                                                         donesomething=1;
5322                                                         }*/
5323                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5324                                                                 LoadTextureSave("/Data/Textures/Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5325                                                                 donesomething=1;
5326                                                         }
5327                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5328                                                                 LoadTextureSave("/Data/Textures/DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5329                                                                 donesomething=1;
5330                                                         }
5331                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5332                                                                 LoadTextureSave("/Data/Textures/Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5333                                                                 donesomething=1;
5334                                                         }/*
5335                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5336                                                          LoadTextureSave("/Data/Textures/Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5337                                                          donesomething=1;
5338                                                          }*/
5339                                                         if(Compare(consoletext[0],"white ",0,5)){
5340                                                                 LoadTextureSave("/Data/Textures/fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5341                                                                 donesomething=1;
5342                                                         }
5343                                                         if(Compare(consoletext[0],"brown ",0,5)){
5344                                                                 LoadTextureSave("/Data/Textures/fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5345                                                                 donesomething=1;
5346                                                         }
5347                                                         if(Compare(consoletext[0],"black ",0,5)){
5348                                                                 LoadTextureSave("/Data/Textures/fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5349                                                                 donesomething=1;
5350                                                         }
5351                                                         if(consolechars[0]>0){
5352                                                                 for(k=14;k>=1;k--){
5353                                                                         for(j=0;j<255;j++){
5354                                                                                 consoletext[k][j]=consoletext[k-1][j];
5355                                                                         }
5356                                                                         consolechars[k]=consolechars[k-1];
5357                                                                 }
5358                                                                 for(j=0;j<255;j++){
5359                                                                         consoletext[0][j]=' ';
5360                                                                 }
5361                                                                 consolechars[0]=0;
5362                                                                 consoleselected=0;
5363
5364                                                                 if(!donesomething){
5365                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5366                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5367                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5368                                                                 }
5369                                                         }
5370                                                 }
5371                                         }
5372                                         togglekey[i]=1;
5373                                 }
5374                                 else {
5375                                         togglekey[i]=0;
5376                                         togglekeydelay[i]=0;
5377                                 }
5378                         }
5379
5380                         consoleblinkdelay-=multiplier;
5381                         if(consoleblinkdelay<=0){
5382                                 consoleblinkdelay=.3;
5383                                 consoleblink=1-consoleblink;
5384                         }
5385                 }
5386
5387                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5388                         tryquit=1;
5389                         if(mainmenu==3){
5390                                 if(newdetail>2)newdetail=detail;
5391                                 if(newdetail<0)newdetail=detail;
5392                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5393                                 if(newscreenheight<0)newscreenheight=screenheight;
5394
5395                                 ofstream opstream(ConvertFileName("/Data/config.txt", "w"));
5396                                 opstream << "Screenwidth:\n";
5397                                 opstream << newscreenwidth;
5398                                 opstream << "\nScreenheight:\n";
5399                                 opstream << newscreenheight;
5400                                 opstream << "\nMouse sensitivity:\n";
5401                                 opstream << usermousesensitivity;
5402                                 opstream << "\nBlur(0,1):\n";
5403                                 opstream << ismotionblur;
5404                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5405                                 opstream << newdetail;
5406                                 opstream << "\nFloating jump:\n";
5407                                 opstream << floatjump;
5408                                 opstream << "\nMouse jump:\n";
5409                                 opstream << mousejump;
5410                                 opstream << "\nAmbient sound:\n";
5411                                 opstream << ambientsound;
5412                                 opstream << "\nBlood (0,1,2):\n";
5413                                 opstream << bloodtoggle;
5414                                 opstream << "\nAuto slomo:\n";
5415                                 opstream << autoslomo;
5416                                 opstream << "\nFoliage:\n";
5417                                 opstream << foliage;
5418                                 opstream << "\nMusic:\n";
5419                                 opstream << musictoggle;
5420                                 opstream << "\nTrilinear:\n";
5421                                 opstream << trilinear;
5422                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5423                                 opstream << decals;
5424                                 opstream << "\nInvert mouse:\n";
5425                                 opstream << invertmouse;
5426                                 opstream << "\nGamespeed:\n";
5427                                 if(oldgamespeed==0)oldgamespeed=1;
5428                                 opstream << oldgamespeed;
5429                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5430                                 opstream << difficulty;
5431                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5432                                 opstream << damageeffects;
5433                                 opstream << "\nText:\n";
5434                                 opstream << texttoggle;
5435                                 opstream << "\nDebug:\n";
5436                                 opstream << debugmode;
5437                                 opstream << "\nVBL Sync:\n";
5438                                 opstream << vblsync;
5439                                 opstream << "\nShow Points:\n";
5440                                 opstream << showpoints;
5441                                 opstream << "\nAlways Blur:\n";
5442                                 opstream << alwaysblur;
5443                                 opstream << "\nImmediate mode (turn on on G5):\n";
5444                                 opstream << immediate;
5445                                 opstream << "\nVelocity blur:\n";
5446                                 opstream << velocityblur;
5447                             opstream << "\nVolume:\n";
5448                         opstream << volume;
5449                                 opstream << "\nForward key:\n";
5450                                 opstream << KeyToChar(forwardkey);
5451                                 opstream << "\nBack key:\n";
5452                                 opstream << KeyToChar(backkey);
5453                                 opstream << "\nLeft key:\n";
5454                                 opstream << KeyToChar(leftkey);
5455                                 opstream << "\nRight key:\n";
5456                                 opstream << KeyToChar(rightkey);
5457                                 opstream << "\nJump key:\n";
5458                                 opstream << KeyToChar(jumpkey);
5459                                 opstream << "\nCrouch key:\n";
5460                                 opstream << KeyToChar(crouchkey);
5461                                 opstream << "\nDraw key:\n";
5462                                 opstream << KeyToChar(drawkey);
5463                                 opstream << "\nThrow key:\n";
5464                                 opstream << KeyToChar(throwkey);
5465                                 opstream << "\nAttack key:\n";
5466                                 opstream << KeyToChar(attackkey);
5467                                 opstream << "\nChat key:\n";
5468                                 opstream << KeyToChar(chatkey);
5469                                 opstream.close();
5470                         }
5471                 }
5472
5473                 static int oldwinfreeze;
5474                 if(winfreeze&&!oldwinfreeze){
5475                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5476                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5477                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5478                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5479                 }
5480                 if(winfreeze==0)oldwinfreeze=winfreeze;
5481                 else oldwinfreeze++;
5482
5483                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5484                         if(winfreeze)winfreeze=0;
5485                         oldjumpkeydown=1;
5486                 }
5487                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5488                         if(winfreeze){
5489                                 mainmenu=9;
5490                                 gameon=0;
5491                         }
5492                 }
5493                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5494                         oldjumpkeydown=1;
5495                 }
5496                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5497
5498                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5499
5500                         static bool oldbuttondialogue;
5501
5502                         if(indialogue!=-1)talkdelay=1;
5503                         talkdelay-=multiplier;
5504
5505                         if(talkdelay<=0)
5506                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5507                                         for(i=0;i<numdialogues;i++){
5508                                                 int realdialoguetype;
5509                                                 bool special;
5510                                                 if(dialoguetype[i]>49){
5511                                                         realdialoguetype=dialoguetype[i]-50;
5512                                                         special=1;
5513                                                 }
5514                                                 else if(dialoguetype[i]>39){
5515                                                         realdialoguetype=dialoguetype[i]-40;
5516                                                         special=1;
5517                                                 }
5518                                                 else if(dialoguetype[i]>29){
5519                                                         realdialoguetype=dialoguetype[i]-30;
5520                                                         special=1;
5521                                                 }
5522                                                 else if(dialoguetype[i]>19){
5523                                                         realdialoguetype=dialoguetype[i]-20;
5524                                                         special=1;
5525                                                 }
5526                                                 else if(dialoguetype[i]>9){
5527                                                         realdialoguetype=dialoguetype[i]-10;
5528                                                         special=1;
5529                                                 }
5530                                                 else {
5531                                                         realdialoguetype=dialoguetype[i];
5532                                                         special=0;
5533                                                 }
5534                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5535                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5536                                                                 whichdialogue=i;
5537                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5538                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5539                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5540                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5541                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5542                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5543                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5544                                                                 }
5545                                                                 directing=0;
5546                                                                 indialogue=0;
5547                                                                 dialoguetime=0;
5548                                                                 dialoguegonethrough[i]++;
5549                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5550                                                                         static float gLoc[3];
5551                                                                         static float vel[3];
5552                                                                         XYZ temppos;
5553                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5554                                                                         temppos=temppos-viewer;
5555                                                                         Normalise(&temppos);
5556                                                                         temppos+=viewer;
5557
5558                                                                         gLoc[0]=temppos.x;
5559                                                                         gLoc[1]=temppos.y;
5560                                                                         gLoc[2]=temppos.z;vel[0]=0;
5561                                                                         vel[1]=0;
5562                                                                         vel[2]=0;
5563                                                                         int whichsoundplay;
5564                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5565                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5566                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5567                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5568                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5569                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5570                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5571                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5572                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5573                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5574                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5575                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5576                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5577                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5578                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5579                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5580                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5581                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5582                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5583                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5584                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5585                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5586                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5587                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5588                                                                 }
5589                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5590                                                         }
5591                                                 }
5592                                         }
5593
5594                                         windvar+=multiplier;
5595                                         smoketex+=multiplier;
5596                                         tutorialstagetime+=multiplier;
5597
5598                                         static float hotspotvisual[40];
5599                                         if(numhotspots){
5600                                                 XYZ hotspotsprite;
5601                                                 if(editorenabled)
5602                                                         for(i=0;i<numhotspots;i++)
5603                                                                 hotspotvisual[i]-=multiplier/320;
5604
5605                                                 for(i=0;i<numhotspots;i++){
5606                                                         //if(hotspottype[i]<=10)
5607                                                         while(hotspotvisual[i]<0){
5608                                                                 hotspotsprite=0;
5609                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5610                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5611                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5612                                                                 hotspotsprite+=hotspot[i];
5613                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5614                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5615                                                         }
5616                                                 }
5617
5618                                                 for(i=0;i<numhotspots;i++){
5619                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5620                                                                 hotspot[i]=player[hotspottype[i]].coords;
5621                                                         }
5622                                                 }
5623                                         }
5624
5625                                         //Tutorial
5626                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5627                                                 tutorialstage++;
5628                                                 tutorialsuccess=0;
5629                                                 if(tutorialstage<=1){
5630                                                         canattack=0;
5631                                                         cananger=0;
5632                                                         reversaltrain=0;
5633                                                 }
5634                                                 if(tutorialstage==1){
5635                                                         tutorialmaxtime=5;
5636                                                 }
5637                                                 if(tutorialstage==2){
5638                                                         tutorialmaxtime=2;
5639                                                 }
5640                                                 if(tutorialstage==3){
5641                                                         tutorialmaxtime=600;
5642                                                 }
5643                                                 if(tutorialstage==4){
5644                                                         tutorialmaxtime=1000;
5645                                                 }
5646                                                 if(tutorialstage==5){
5647                                                         tutorialmaxtime=600;
5648                                                 }
5649                                                 if(tutorialstage==6){
5650                                                         tutorialmaxtime=600;
5651                                                 }
5652                                                 if(tutorialstage==7){
5653                                                         tutorialmaxtime=600;
5654                                                 }
5655                                                 if(tutorialstage==8){
5656                                                         tutorialmaxtime=600;
5657                                                 }
5658                                                 if(tutorialstage==9){
5659                                                         tutorialmaxtime=600;
5660                                                 }
5661                                                 if(tutorialstage==10){
5662                                                         tutorialmaxtime=2;
5663                                                 }
5664                                                 if(tutorialstage==11){
5665                                                         tutorialmaxtime=1000;
5666                                                 }
5667                                                 if(tutorialstage==12){
5668                                                         tutorialmaxtime=1000;
5669                                                 }
5670                                                 if(tutorialstage==13){
5671                                                         tutorialmaxtime=2;
5672                                                 }
5673                                                 if(tutorialstage==14){
5674                                                         tutorialmaxtime=3;
5675
5676                                                         XYZ temp,temp2;
5677
5678                                                         temp.x=1011;
5679                                                         temp.y=84;
5680                                                         temp.z=491;
5681                                                         temp2.x=1025;
5682                                                         temp2.y=75;
5683                                                         temp2.z=447;
5684
5685                                                         player[1].coords=(temp+temp2)/2;
5686
5687                                                         float gLoc[3];
5688                                                         float vel[3];
5689                                                         gLoc[0]=player[1].coords.x;
5690                                                         gLoc[1]=player[1].coords.y;
5691                                                         gLoc[2]=player[1].coords.z;
5692                                                         vel[0]=0;
5693                                                         vel[1]=0;
5694                                                         vel[2]=0;
5695                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5696                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5697                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5698                                                         OPENAL_SetPaused(channels[fireendsound], false);
5699
5700                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5701                                                                 if(Random()%2==0){
5702                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5703                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5704                                                                         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;
5705                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5706                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5707                                                                 }
5708                                                         }
5709
5710                                                 }
5711                                                 if(tutorialstage==15){
5712                                                         tutorialmaxtime=500;
5713                                                 }
5714                                                 if(tutorialstage==16){
5715                                                         tutorialmaxtime=500;
5716                                                 }
5717                                                 if(tutorialstage==17){
5718                                                         tutorialmaxtime=500;
5719                                                 }
5720                                                 if(tutorialstage==18){
5721                                                         tutorialmaxtime=500;
5722                                                 }
5723                                                 if(tutorialstage==19){
5724                                                         tutorialstage=20;
5725                                                         //tutorialmaxtime=500;
5726                                                 }
5727                                                 if(tutorialstage==20){
5728                                                         tutorialmaxtime=500;
5729                                                 }
5730                                                 if(tutorialstage==21){
5731                                                         tutorialmaxtime=500;
5732                                                         if(bonus==cannon){
5733                                                                 bonus=Slicebonus;
5734                                                                 againbonus=1;
5735                                                         }
5736                                                         else againbonus=0;
5737                                                 }
5738                                                 if(tutorialstage==22){
5739                                                         tutorialmaxtime=500;
5740                                                 }
5741                                                 if(tutorialstage==23){
5742                                                         tutorialmaxtime=500;
5743                                                 }
5744                                                 if(tutorialstage==24){
5745                                                         tutorialmaxtime=500;
5746                                                 }
5747                                                 if(tutorialstage==25){
5748                                                         tutorialmaxtime=500;
5749                                                 }
5750                                                 if(tutorialstage==26){
5751                                                         tutorialmaxtime=2;
5752                                                 }
5753                                                 if(tutorialstage==27){
5754                                                         tutorialmaxtime=4;
5755                                                         reversaltrain=1;
5756                                                         cananger=1;
5757                                                         player[1].aitype=attacktypecutoff;
5758                                                 }
5759                                                 if(tutorialstage==28){
5760                                                         tutorialmaxtime=400;
5761                                                 }
5762                                                 if(tutorialstage==29){
5763                                                         tutorialmaxtime=400;
5764                                                         player[0].escapednum=0;
5765                                                 }
5766                                                 if(tutorialstage==30){
5767                                                         tutorialmaxtime=4;
5768                                                         reversaltrain=0;
5769                                                         cananger=0;
5770                                                         player[1].aitype=passivetype;
5771                                                 }
5772                                                 if(tutorialstage==31){
5773                                                         tutorialmaxtime=13;
5774                                                 }
5775                                                 if(tutorialstage==32){
5776                                                         tutorialmaxtime=8;
5777                                                 }
5778                                                 if(tutorialstage==33){
5779                                                         tutorialmaxtime=400;
5780                                                         cananger=1;
5781                                                         canattack=1;
5782                                                         player[1].aitype=attacktypecutoff;
5783                                                 }
5784                                                 if(tutorialstage==34){
5785                                                         tutorialmaxtime=400;
5786                                                 }
5787                                                 if(tutorialstage==35){
5788                                                         tutorialmaxtime=400;
5789                                                 }
5790                                                 if(tutorialstage==36){
5791                                                         tutorialmaxtime=2;
5792                                                         reversaltrain=0;
5793                                                         cananger=0;
5794                                                         player[1].aitype=passivetype;
5795                                                 }
5796                                                 if(tutorialstage==37){
5797                                                         damagedealt=0;
5798                                                         damagetaken=0;
5799                                                         tutorialmaxtime=50;
5800                                                         cananger=1;
5801                                                         canattack=1;
5802                                                         player[1].aitype=attacktypecutoff;
5803                                                 }
5804                                                 if(tutorialstage==38){
5805                                                         tutorialmaxtime=4;
5806                                                         canattack=0;
5807                                                         cananger=0;
5808                                                         player[1].aitype=passivetype;
5809                                                 }
5810                                                 if(tutorialstage==39){
5811                                                         XYZ temp,temp2;
5812
5813                                                         temp.x=1011;
5814                                                         temp.y=84;
5815                                                         temp.z=491;
5816                                                         temp2.x=1025;
5817                                                         temp2.y=75;
5818                                                         temp2.z=447;
5819
5820
5821                                                         weapons.owner[weapons.numweapons]=-1;
5822                                                         weapons.type[weapons.numweapons]=knife;
5823                                                         weapons.damage[weapons.numweapons]=0;
5824                                                         weapons.mass[weapons.numweapons]=1;
5825                                                         weapons.tipmass[weapons.numweapons]=1.2;
5826                                                         weapons.length[weapons.numweapons]=.25;
5827                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5828                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5829
5830                                                         weapons.velocity[weapons.numweapons]=0.1;
5831                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5832                                                         weapons.missed[weapons.numweapons]=1;
5833                                                         weapons.hitsomething[weapons.numweapons]=0;
5834                                                         weapons.freetime[weapons.numweapons]=0;
5835                                                         weapons.firstfree[weapons.numweapons]=1;
5836                                                         weapons.physics[weapons.numweapons]=1;
5837
5838                                                         weapons.numweapons++;
5839                                                 }
5840                                                 if(tutorialstage==40){
5841                                                         tutorialmaxtime=300;
5842                                                 }
5843                                                 if(tutorialstage==41){
5844                                                         tutorialmaxtime=300;
5845                                                 }
5846                                                 if(tutorialstage==42){
5847                                                         tutorialmaxtime=8;
5848                                                 }
5849                                                 if(tutorialstage==43){
5850                                                         tutorialmaxtime=300;
5851                                                 }
5852                                                 if(tutorialstage==44){
5853                                                         weapons.owner[0]=1;
5854                                                         player[0].weaponactive=-1;
5855                                                         player[0].num_weapons=0;
5856                                                         player[1].weaponactive=0;
5857                                                         player[1].num_weapons=1;
5858                                                         player[1].weaponids[0]=0;
5859
5860                                                         cananger=1;
5861                                                         canattack=1;
5862                                                         player[1].aitype=attacktypecutoff;
5863
5864                                                         tutorialmaxtime=300;
5865                                                 }
5866                                                 if(tutorialstage==45){
5867                                                         weapons.owner[0]=1;
5868                                                         player[0].weaponactive=-1;
5869                                                         player[0].num_weapons=0;
5870                                                         player[1].weaponactive=0;
5871                                                         player[1].num_weapons=1;
5872                                                         player[1].weaponids[0]=0;
5873
5874                                                         tutorialmaxtime=300;
5875                                                 }
5876                                                 if(tutorialstage==46){
5877                                                         weapons.owner[0]=1;
5878                                                         player[0].weaponactive=-1;
5879                                                         player[0].num_weapons=0;
5880                                                         player[1].weaponactive=0;
5881                                                         player[1].num_weapons=1;
5882                                                         player[1].weaponids[0]=0;
5883
5884                                                         weapons.type[0]=sword;
5885
5886                                                         tutorialmaxtime=300;
5887                                                 }
5888
5889                                                 if(tutorialstage==47){
5890                                                         tutorialmaxtime=10;
5891
5892                                                         XYZ temp,temp2;
5893
5894                                                         temp.x=1011;
5895                                                         temp.y=84;
5896                                                         temp.z=491;
5897                                                         temp2.x=1025;
5898                                                         temp2.y=75;
5899                                                         temp2.z=447;
5900
5901                                                         weapons.owner[weapons.numweapons]=-1;
5902                                                         weapons.type[weapons.numweapons]=sword;
5903                                                         weapons.damage[weapons.numweapons]=0;
5904                                                         weapons.mass[weapons.numweapons]=1;
5905                                                         weapons.tipmass[weapons.numweapons]=1.2;
5906                                                         weapons.length[weapons.numweapons]=.25;
5907                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
5908                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
5909
5910                                                         weapons.velocity[weapons.numweapons]=0.1;
5911                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
5912                                                         weapons.missed[weapons.numweapons]=1;
5913                                                         weapons.hitsomething[weapons.numweapons]=0;
5914                                                         weapons.freetime[weapons.numweapons]=0;
5915                                                         weapons.firstfree[weapons.numweapons]=1;
5916                                                         weapons.physics[weapons.numweapons]=1;
5917
5918                                                         weapons.owner[0]=1;
5919                                                         weapons.owner[1]=0;
5920                                                         player[0].weaponactive=0;
5921                                                         player[0].num_weapons=1;
5922                                                         player[0].weaponids[0]=1;
5923                                                         player[1].weaponactive=0;
5924                                                         player[1].num_weapons=1;
5925                                                         player[1].weaponids[0]=0;
5926
5927                                                         weapons.numweapons++;
5928                                                 }
5929                                                 if(tutorialstage==48){
5930                                                         canattack=0;
5931                                                         cananger=0;
5932                                                         player[1].aitype=passivetype;
5933
5934                                                         tutorialmaxtime=15;
5935
5936                                                         weapons.owner[0]=1;
5937                                                         weapons.owner[1]=0;
5938                                                         player[0].weaponactive=0;
5939                                                         player[0].num_weapons=1;
5940                                                         player[0].weaponids[0]=1;
5941                                                         player[1].weaponactive=0;
5942                                                         player[1].num_weapons=1;
5943                                                         player[1].weaponids[0]=0;
5944
5945                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
5946                                                         else weapons.type[0]=staff;
5947
5948                                                         weapons.numweapons++;
5949                                                 }
5950                                                 if(tutorialstage==49){
5951                                                         canattack=0;
5952                                                         cananger=0;
5953                                                         player[1].aitype=passivetype;
5954
5955                                                         tutorialmaxtime=200;
5956
5957                                                         weapons.position[1]=1000;
5958                                                         weapons.tippoint[1]=1000;
5959
5960                                                         weapons.numweapons=1;
5961                                                         weapons.owner[0]=0;
5962                                                         player[1].weaponactive=-1;
5963                                                         player[1].num_weapons=0;
5964                                                         player[0].weaponactive=0;
5965                                                         player[0].num_weapons=1;
5966                                                         player[0].weaponids[0]=0;
5967
5968                                                         weapons.type[0]=knife;
5969
5970                                                         weapons.numweapons++;
5971                                                 }
5972                                                 if(tutorialstage==50){
5973                                                         tutorialmaxtime=8;
5974
5975                                                         XYZ temp,temp2;
5976                                                         float gLoc[3];
5977                                                         float vel[3];
5978                                                         gLoc[0]=player[1].coords.x;
5979                                                         gLoc[1]=player[1].coords.y;
5980                                                         gLoc[2]=player[1].coords.z;
5981                                                         vel[0]=0;
5982                                                         vel[1]=0;
5983                                                         vel[2]=0;
5984                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
5985                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
5986                                                         OPENAL_SetVolume(channels[fireendsound], 256);
5987                                                         OPENAL_SetPaused(channels[fireendsound], false);
5988
5989                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
5990                                                                 if(Random()%2==0){
5991                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
5992                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
5993                                                                         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;
5994                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
5995                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
5996                                                                 }
5997                                                         }
5998
5999                                                         player[1].num_weapons=0;
6000                                                         player[1].weaponstuck=-1;
6001                                                         player[1].weaponactive=-1;
6002
6003                                                         weapons.numweapons=0;
6004
6005                                                         weapons.owner[0]=-1;
6006                                                         weapons.velocity[0]=0.1;
6007                                                         weapons.tipvelocity[0]=-0.1;
6008                                                         weapons.missed[0]=1;
6009                                                         weapons.hitsomething[0]=0;
6010                                                         weapons.freetime[0]=0;
6011                                                         weapons.firstfree[0]=1;
6012                                                         weapons.physics[0]=1;
6013                                                 }
6014                                                 if(tutorialstage==51){
6015                                                         tutorialmaxtime=80000;
6016                                                 }
6017                                                 if(tutorialstage<=51)tutorialstagetime=0;
6018                                         }
6019
6020                                         //Tutorial success
6021                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6022                                                 if(tutorialstage==3){
6023                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6024                                                 }
6025                                                 if(tutorialstage==4){
6026                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6027                                                 }
6028                                                 if(tutorialstage==5){
6029                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6030                                                 }
6031                                                 if(tutorialstage==6){
6032                                                         if(player[0].isCrouch())tutorialsuccess=1;
6033                                                 }
6034                                                 if(tutorialstage==7){
6035                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6036                                                 }
6037                                                 if(tutorialstage==8){
6038                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6039                                                 }
6040                                                 if(tutorialstage==9){
6041                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6042                                                 }
6043                                                 if(tutorialstage==11){
6044                                                         if(player[0].isWallJump())tutorialsuccess=1;
6045                                                 }
6046                                                 if(tutorialstage==12){
6047                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6048                                                 }
6049                                                 if(tutorialstage==15){
6050                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6051                                                 }
6052                                                 if(tutorialstage==16){
6053                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6054                                                 }
6055                                                 if(tutorialstage==17){
6056                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6057                                                 }
6058                                                 if(tutorialstage==18){
6059                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6060                                                 }
6061                                                 if(tutorialstage==19){
6062                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6063                                                 }
6064                                                 if(tutorialstage==20){
6065                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6066                                                 }
6067                                                 if(tutorialstage==21){
6068                                                         if(bonus==cannon)tutorialsuccess=1;
6069                                                 }
6070                                                 if(tutorialstage==22){
6071                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6072                                                 }
6073                                                 if(tutorialstage==23){
6074                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6075                                                 }
6076                                                 if(tutorialstage==24){
6077                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6078                                                 }
6079                                                 if(tutorialstage==25){
6080                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6081                                                 }
6082                                                 if(tutorialstage==28){
6083                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6084                                                 }
6085                                                 if(tutorialstage==29){
6086                                                         if(player[0].escapednum==2){
6087                                                                 tutorialsuccess=1;
6088                                                                 reversaltrain=0;
6089                                                                 cananger=0;
6090                                                                 player[1].aitype=passivetype;
6091                                                         }
6092                                                 }
6093                                                 if(tutorialstage==33){
6094                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6095                                                 }
6096                                                 if(tutorialstage==34){
6097                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6098                                                 }
6099                                                 if(tutorialstage==35){
6100                                                         if(animation[player[0].targetanimation].attack==reversal){
6101                                                                 tutorialsuccess=1;
6102                                                                 reversaltrain=0;
6103                                                                 cananger=0;
6104                                                                 player[1].aitype=passivetype;
6105                                                         }
6106                                                 }
6107                                                 if(tutorialstage==40){
6108                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6109                                                 }
6110                                                 if(tutorialstage==41){
6111                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6112                                                 }
6113                                                 if(tutorialstage==43){
6114                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6115                                                 }
6116                                                 if(tutorialstage==44){
6117                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6118                                                 }
6119                                                 if(tutorialstage==45){
6120                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6121                                                 }
6122                                                 if(tutorialstage==46){
6123                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6124                                                 }
6125                                                 if(tutorialstage==49){
6126                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6127                                                 }
6128                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6129
6130
6131                                                 if(tutorialstagetime==tutorialmaxtime-3){
6132                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6133                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6134                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6135                                                 }
6136
6137                                                 if(tutorialsuccess>=1){
6138                                                         if(tutorialstage==34||tutorialstage==35)
6139                                                                 tutorialstagetime=tutorialmaxtime-1;
6140                                                 }
6141                                         }
6142
6143                                         if(tutoriallevel){
6144                                                 if(tutorialstage<14||tutorialstage>=50){
6145                                                         player[1].coords.y=300;
6146                                                         player[1].velocity=0;
6147                                                 }
6148                                         }
6149
6150                                         if(tutoriallevel!=1){
6151                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6152                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6153                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6154                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6155                                                 }
6156                                         }
6157                                         else
6158                                                 if(bonustime==0){
6159                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6160                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6161                                                         OPENAL_SetPaused(channels[fireendsound], false);
6162                                                 }
6163                                                 if(bonustime==0){
6164                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6165                                                         else bonusnum[bonus]+=0.15;
6166                                                         if(tutoriallevel)bonusvalue=0;
6167                                                         bonusvalue/=bonusnum[bonus];
6168                                                         bonustotal+=bonusvalue;
6169                                                 }
6170                                                 bonustime+=multiplier;
6171
6172                                                 if(environment==snowyenvironment){
6173                                                         precipdelay-=multiplier;
6174                                                         while(precipdelay<0){
6175                                                                 precipdelay+=.04;
6176                                                                 if(!detail)precipdelay+=.04;
6177                                                                 XYZ footvel,footpoint;
6178
6179                                                                 footvel=0;
6180                                                                 footpoint=viewer+viewerfacing*6;
6181                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6182                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6183                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6184                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6185                                                         }
6186                                                 }
6187                                                 for(k=0;k<numplayers;k++){
6188                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6189                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6190
6191                                                         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){
6192                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6193                                                                 else if(player[k].rotation>player[k].targetrotation){
6194                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6195                                                                 }
6196                                                                 else if(player[k].rotation<player[k].targetrotation){
6197                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6198                                                                 }
6199                                                         }
6200
6201
6202                                                         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))){
6203                                                                 player[k].turnspeed*=2;
6204                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6205                                                                 else if(player[k].rotation>player[k].targetrotation){
6206                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6207                                                                 }
6208                                                                 else if(player[k].rotation<player[k].targetrotation){
6209                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6210                                                                 }
6211                                                                 player[k].turnspeed/=2;
6212                                                         }
6213
6214                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6215                                                                 player[k].turnspeed*=4;
6216                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6217                                                                 else if(player[k].rotation>player[k].targetrotation){
6218                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6219                                                                 }
6220                                                                 else if(player[k].rotation<player[k].targetrotation){
6221                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6222                                                                 }
6223                                                                 player[k].turnspeed/=4;
6224                                                         }
6225
6226                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6227                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6228
6229                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6230                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6231                                                                         bool tempcollide=0;
6232
6233                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6234                                                                         if(player[k].collide>1)player[k].collide=1;
6235                                                                         player[k].collide-=multiplier*30;
6236
6237                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6238                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6239                                                                         }
6240                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6241                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6242                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6243                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6244                                                                                                 lowpoint=player[k].coords;
6245                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6246                                                                                                 else lowpoint.y+=1.3;
6247                                                                                                 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){
6248                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6249                                                                                                 }
6250                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6251                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6252                                                                                                 */
6253                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6254                                                                                                         flatfacing=lowpoint-player[k].coords;
6255                                                                                                         player[k].coords=lowpoint;
6256                                                                                                         player[k].coords.y-=1.3;
6257                                                                                                         player[k].collide=1;
6258                                                                                                         tempcollide=1;
6259                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6260                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6261                                                                                                                 tempcoords1=lowpoint;
6262                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6263                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6264                                                                                                                         player[k].target=0;
6265                                                                                                                         player[k].targetanimation=walljumpleftanim;
6266                                                                                                                         player[k].targetframe=0;
6267                                                                                                                         float gLoc[3];
6268                                                                                                                         float vel[3];
6269                                                                                                                         gLoc[0]=player[k].coords.x;
6270                                                                                                                         gLoc[1]=player[k].coords.y;
6271                                                                                                                         gLoc[2]=player[k].coords.z;
6272                                                                                                                         vel[0]=0;
6273                                                                                                                         vel[1]=0;
6274                                                                                                                         vel[2]=0;
6275                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6276                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6277                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6278                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6279                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6280
6281                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6282                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6283                                                                                                                         player[k].rotation*=360/6.28;
6284                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6285                                                                                                                         player[k].targetrotation=player[k].rotation;
6286                                                                                                                         player[k].lowrotation=player[k].rotation;
6287                                                                                                                         if(k==0)numwallflipped++;
6288                                                                                                                 }
6289                                                                                                                 else
6290                                                                                                                 {
6291                                                                                                                         lowpoint=tempcoords1;
6292                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6293                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6294                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6295                                                                                                                                 player[k].target=0;
6296                                                                                                                                 player[k].targetanimation=walljumprightanim;
6297                                                                                                                                 player[k].targetframe=0;
6298                                                                                                                                 float gLoc[3];
6299                                                                                                                                 float vel[3];
6300                                                                                                                                 gLoc[0]=player[k].coords.x;
6301                                                                                                                                 gLoc[1]=player[k].coords.y;
6302                                                                                                                                 gLoc[2]=player[k].coords.z;
6303                                                                                                                                 vel[0]=0;
6304                                                                                                                                 vel[1]=0;
6305                                                                                                                                 vel[2]=0;
6306                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6307                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6308                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6309                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6310                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6311
6312                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6313                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6314                                                                                                                                 player[k].rotation*=360/6.28;
6315                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6316                                                                                                                                 player[k].targetrotation=player[k].rotation;
6317                                                                                                                                 player[k].lowrotation=player[k].rotation;
6318                                                                                                                                 if(k==0)numwallflipped++;
6319                                                                                                                         }
6320                                                                                                                         else
6321                                                                                                                         {
6322                                                                                                                                 lowpoint=tempcoords1;
6323                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6324                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6325                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6326                                                                                                                                         player[k].target=0;
6327                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6328                                                                                                                                         player[k].targetframe=0;
6329                                                                                                                                         float gLoc[3];
6330                                                                                                                                         float vel[3];
6331                                                                                                                                         gLoc[0]=player[k].coords.x;
6332                                                                                                                                         gLoc[1]=player[k].coords.y;
6333                                                                                                                                         gLoc[2]=player[k].coords.z;
6334                                                                                                                                         vel[0]=0;
6335                                                                                                                                         vel[1]=0;
6336                                                                                                                                         vel[2]=0;
6337                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6338                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6339                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6340                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6341                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6342
6343                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6344                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6345                                                                                                                                         player[k].rotation*=360/6.28;
6346                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6347                                                                                                                                         player[k].targetrotation=player[k].rotation;
6348                                                                                                                                         player[k].lowrotation=player[k].rotation;
6349                                                                                                                                         if(k==0)numwallflipped++;
6350                                                                                                                                 }
6351                                                                                                                                 else
6352                                                                                                                                 {
6353                                                                                                                                         lowpoint=tempcoords1;
6354                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6355                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6356                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6357                                                                                                                                                 player[k].target=0;
6358                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6359                                                                                                                                                 player[k].targetframe=0;
6360                                                                                                                                                 float gLoc[3];
6361                                                                                                                                                 float vel[3];
6362                                                                                                                                                 gLoc[0]=player[k].coords.x;
6363                                                                                                                                                 gLoc[1]=player[k].coords.y;
6364                                                                                                                                                 gLoc[2]=player[k].coords.z;
6365                                                                                                                                                 vel[0]=0;
6366                                                                                                                                                 vel[1]=0;
6367                                                                                                                                                 vel[2]=0;
6368                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6369                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6370                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6371                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6372                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6373
6374                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6375                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6376                                                                                                                                                 player[k].rotation*=360/6.28;
6377                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6378                                                                                                                                                 player[k].rotation+=180;
6379                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6380                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6381                                                                                                                                                 if(k==0)numwallflipped++;
6382                                                                                                                                         }
6383                                                                                                                                 }
6384                                                                                                                         }
6385                                                                                                                 }
6386                                                                                                         }
6387                                                                                                 }
6388                                                                                         }
6389                                                                                         else if(objects.type[i]==rocktype){
6390                                                                                                 lowpoint2=player[k].coords;
6391                                                                                                 lowpoint=player[k].coords;
6392                                                                                                 lowpoint.y+=2;
6393                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6394                                                                                                         player[k].coords=colpoint;
6395                                                                                                         player[k].collide=1;
6396                                                                                                         tempcollide=1;
6397
6398                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6399                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6400
6401                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6402                                                                                                                 player[k].target=0;
6403                                                                                                                 player[k].targetframe=0;
6404                                                                                                                 player[k].onterrain=1;
6405
6406                                                                                                                 if(player[k].id==0){
6407                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6408                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6409                                                                                                                 }
6410
6411                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6412                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6413                                                                                                                         player[k].targetanimation=player[k].getLanding();
6414                                                                                                                         float gLoc[3];
6415                                                                                                                         float vel[3];
6416                                                                                                                         gLoc[0]=player[k].coords.x;
6417                                                                                                                         gLoc[1]=player[k].coords.y;
6418                                                                                                                         gLoc[2]=player[k].coords.z;
6419                                                                                                                         vel[0]=player[k].velocity.x;
6420                                                                                                                         vel[1]=player[k].velocity.y;
6421                                                                                                                         vel[2]=player[k].velocity.z;
6422                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6423                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6424                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6425                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6426                                                                                                                         if(k==0){
6427                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6428                                                                                                                                 envsoundvol[numenvsounds]=16;
6429                                                                                                                                 envsoundlife[numenvsounds]=.4;
6430                                                                                                                                 numenvsounds++;
6431                                                                                                                         }
6432
6433                                                                                                                 }
6434                                                                                                         }
6435                                                                                                 }
6436                                                                                         }
6437                                                                                 }
6438                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6439                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6440                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6441                                                                                                 lowpoint=player[k].coords;
6442                                                                                                 lowpoint.y+=1.35;
6443                                                                                                 if(objects.type[i]!=rocktype)
6444                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6445                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6446                                                                                                                 player[k].coords=lowpoint;
6447                                                                                                                 player[k].coords.y-=1.35;
6448                                                                                                                 player[k].collide=1;
6449
6450                                                                                                                 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)){
6451                                                                                                                         lowpoint=player[k].coords;
6452                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6453                                                                                                                         lowpoint=player[k].coords;
6454                                                                                                                         lowpoint.y+=.05;
6455                                                                                                                         facing=0;
6456                                                                                                                         facing.z=-1;
6457                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6458                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6459                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6460                                                                                                                         if(whichhit!=-1){
6461                                                                                                                                 lowpoint=player[k].coords;
6462                                                                                                                                 lowpoint.y+=.1;
6463                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6464                                                                                                                                 lowpoint2=lowpoint;
6465                                                                                                                                 lowpointtarget2=lowpointtarget;
6466                                                                                                                                 lowpoint3=lowpoint;
6467                                                                                                                                 lowpointtarget3=lowpointtarget;
6468                                                                                                                                 lowpoint4=lowpoint;
6469                                                                                                                                 lowpointtarget4=lowpointtarget;
6470                                                                                                                                 lowpoint5=lowpoint;
6471                                                                                                                                 lowpointtarget5=lowpointtarget;
6472                                                                                                                                 lowpoint6=lowpoint;
6473                                                                                                                                 lowpointtarget6=lowpointtarget;
6474                                                                                                                                 lowpoint7=lowpoint;
6475                                                                                                                                 lowpointtarget7=lowpoint;
6476                                                                                                                                 lowpoint2.x+=.1;
6477                                                                                                                                 lowpointtarget2.x+=.1;
6478                                                                                                                                 lowpoint3.z+=.1;
6479                                                                                                                                 lowpointtarget3.z+=.1;
6480                                                                                                                                 lowpoint4.x-=.1;
6481                                                                                                                                 lowpointtarget4.x-=.1;
6482                                                                                                                                 lowpoint5.z-=.1;
6483                                                                                                                                 lowpointtarget5.z-=.1;
6484                                                                                                                                 lowpoint6.y+=45/13;
6485                                                                                                                                 lowpointtarget6.y+=45/13;
6486                                                                                                                                 lowpointtarget6+=facing*.6;
6487                                                                                                                                 lowpointtarget7.y+=90/13;
6488                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6489                                                                                                                                 if(objects.friction[i]>.5)
6490                                                                                                                                         if(whichhit!=-1){
6491                                                                                                                                                 //if(k==0){
6492                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6493                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6494                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6495                                                                                                                                                                 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)
6496                                                                                                                                                                         for(j=0;j<45;j++){
6497                                                                                                                                                                                 lowpoint=player[k].coords;
6498                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6499                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6500                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6501                                                                                                                                                                                         if(j<=6){
6502                                                                                                                                                                                                 j=100;
6503                                                                                                                                                                                         }
6504                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6505                                                                                                                                                                                         j=100;
6506                                                                                                                                                                                         }*/
6507                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6508                                                                                                                                                                                                 j=100;
6509                                                                                                                                                                                         }
6510                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6511                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6512                                                                                                                                                                                                 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)*/){
6513                                                                                                                                                                                                         lowpoint=player[k].coords;
6514                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6515                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6516                                                                                                                                                                                                         flatfacing=player[k].coords;
6517                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6518                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6519                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6520
6521                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6522                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6523                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6524                                                                                                                                                                                                                 }
6525                                                                                                                                                                                                                 float gLoc[3];
6526                                                                                                                                                                                                                 float vel[3];
6527                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6528                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6529                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6530                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6531                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6532                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6533                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6534                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6535                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6536                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6537
6538                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6539                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6540                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6541                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6542                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6543                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6544
6545                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6546                                                                                                                                                                                                                 player[k].velocity=0;
6547
6548                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6549                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6550                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6551                                                                                                                                                                                                                         player[k].jumppower=0;
6552                                                                                                                                                                                                                         player[k].jumpclimb=1;
6553                                                                                                                                                                                                                 }
6554                                                                                                                                                                                                                 player[k].transspeed=6;
6555                                                                                                                                                                                                                 player[k].target=0;
6556
6557                                                                                                                                                                                                                 //player[k].currentframe=1;
6558                                                                                                                                                                                                                 player[k].targetframe=1;
6559                                                                                                                                                                                                                 if(j>25){
6560                                                                                                                                                                                                                         //player[k].currentframe=0;
6561                                                                                                                                                                                                                         player[k].targetframe=0;
6562                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6563                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6564                                                                                                                                                                                                                         player[k].jumppower=0;
6565                                                                                                                                                                                                                 }
6566                                                                                                                                                                                                         }
6567                                                                                                                                                                                                         j=100;
6568                                                                                                                                                                                                 }
6569                                                                                                                                                                                         }
6570                                                                                                                                                                                 }
6571                                                                                                                                                                         }
6572                                                                                                                                                                         //}
6573                                                                                                                                         }
6574                                                                                                                         }
6575                                                                                                                 }
6576                                                                                                         }
6577                                                                                         }
6578                                                                                         if(player[k].collide<=0){
6579                                                                                                 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()){
6580                                                                                                         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)){
6581                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6582                                                                                                                 player[k].targetanimation=jumpdownanim;
6583                                                                                                                 player[k].targetframe=0;
6584                                                                                                                 player[k].target=0;
6585
6586                                                                                                                 float gLoc[3];
6587                                                                                                                 float vel[3];
6588                                                                                                                 gLoc[0]=player[k].coords.x;
6589                                                                                                                 gLoc[1]=player[k].coords.y;
6590                                                                                                                 gLoc[2]=player[k].coords.z;
6591                                                                                                                 vel[0]=player[k].velocity.x;
6592                                                                                                                 vel[1]=player[k].velocity.y;
6593                                                                                                                 vel[2]=player[k].velocity.z;
6594                                                                                                                 if(k==0){
6595                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6596                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6597                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6598                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6599                                                                                                                 }
6600                                                                                                         }
6601                                                                                                         player[k].velocity.y+=gravity;
6602                                                                                                 }
6603                                                                                         }
6604                                                                 }
6605                                                         }
6606                                                         player[k].realoldcoords=player[k].coords;
6607                                                 }
6608
6609                                                 static XYZ oldviewer;
6610
6611                                                 if(indialogue==-1){
6612                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6613                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6614                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6615                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6616                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6617                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6618                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6619                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6620                                                 }
6621                                                 else
6622                                                 {
6623                                                         player[0].forwardkeydown=0;
6624                                                         player[0].leftkeydown=0;
6625                                                         player[0].backkeydown=0;
6626                                                         player[0].rightkeydown=0;
6627                                                         player[0].jumpkeydown=0;
6628                                                         player[0].crouchkeydown=0;
6629                                                         player[0].drawkeydown=0;
6630                                                         player[0].throwkeydown=0;
6631                                                 }
6632
6633                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6634
6635
6636                                                 static bool endkeydown;
6637                                                 if(indialogue!=-1){
6638                                                         cameramode=1;
6639                                                         if(directing){
6640                                                                 facing=0;
6641                                                                 facing.z=-1;
6642
6643                                                                 facing=DoRotation(facing,-rotation2,0,0);
6644                                                                 facing=DoRotation(facing,0,0-rotation,0);
6645
6646                                                                 flatfacing=0;
6647                                                                 flatfacing.z=-1;
6648
6649                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6650
6651                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6652                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6653                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6654                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6655                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6656                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6657                                                                 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)
6658                                                                         ||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)
6659                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6660                                                                                 int whichend;
6661                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6662                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6663                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6664                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6665                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6666                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6667                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6668                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6669                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6670                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
6671                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
6672                                                                                 if(whichend!=-1){
6673                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
6674                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
6675                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
6676                                                                                 }
6677                                                                                 if(whichend==-1){
6678                                                                                         participantfocus[whichdialogue][indialogue]=-1;
6679                                                                                 }
6680                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
6681                                                                                         indialogue=-1;
6682                                                                                         directing=0;
6683                                                                                         cameramode=0;
6684                                                                                 }
6685                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
6686                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
6687                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
6688                                                                                 indialogue++;
6689                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
6690                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
6691                                                                                                 static float gLoc[3];
6692                                                                                                 static float vel[3];
6693                                                                                                 XYZ temppos;
6694                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6695                                                                                                 temppos=temppos-viewer;
6696                                                                                                 Normalise(&temppos);
6697                                                                                                 temppos+=viewer;
6698
6699                                                                                                 gLoc[0]=temppos.x;
6700                                                                                                 gLoc[1]=temppos.y;
6701                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
6702                                                                                                 vel[1]=0;
6703                                                                                                 vel[2]=0;
6704                                                                                                 int whichsoundplay;
6705                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6706                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6707                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6708                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6709                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6710                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6711                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6712                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6713                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6714                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6715                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6716                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6717                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6718                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6719                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6720                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6721                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6722                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6723                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6724                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6725                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6726                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6727                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6728                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6729                                                                                         }
6730                                                                                 }
6731
6732                                                                                 for(j=0;j<numplayers;j++){
6733                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
6734                                                                                 }
6735
6736                                                                                 endkeydown=1;
6737                                                                         }
6738                                                                         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)
6739                                                                                 ||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)
6740                                                                                 )){
6741                                                                                         int whichend;
6742                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
6743                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
6744                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
6745                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
6746                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
6747                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
6748                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
6749                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
6750                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
6751                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
6752                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
6753                                                                                 }
6754                                                                                 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)
6755                                                                                         &&!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)
6756                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6757                                                                                                 endkeydown=0;
6758                                                                                         }
6759                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6760                                                                                                 indialogue=-1;
6761                                                                                                 directing=0;
6762                                                                                                 cameramode=0;
6763                                                                                         }
6764                                                         }
6765                                                         if(!directing){
6766                                                                 OPENAL_SetPaused(channels[whooshsound], true);
6767                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
6768                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
6769                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
6770                                                                 }
6771                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
6772                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
6773                                                                 if(dialoguetime>0.5)
6774                                                                         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)
6775                                                                                 ||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)
6776                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
6777                                                                                         indialogue++;
6778                                                                                         endkeydown=1;
6779                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
6780                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
6781                                                                                                         static float gLoc[3];
6782                                                                                                         static float vel[3];
6783                                                                                                         XYZ temppos;
6784                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
6785                                                                                                         temppos=temppos-viewer;
6786                                                                                                         Normalise(&temppos);
6787                                                                                                         temppos+=viewer;
6788
6789                                                                                                         gLoc[0]=temppos.x;
6790                                                                                                         gLoc[1]=temppos.y;
6791                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
6792                                                                                                         vel[1]=0;
6793                                                                                                         vel[2]=0;
6794                                                                                                         int whichsoundplay;
6795                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
6796                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
6797                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
6798                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
6799                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
6800                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
6801                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
6802                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
6803                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
6804                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
6805                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
6806                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
6807                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
6808                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
6809                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
6810                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
6811                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
6812                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
6813                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
6814                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
6815                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
6816                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
6817                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
6818                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
6819                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
6820                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
6821                                                                                                         }
6822                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
6823                                                                                                                 hotspot[numhotspots]=player[0].coords;
6824                                                                                                                 hotspotsize[numhotspots]=10;
6825                                                                                                                 hotspottype[numhotspots]=-1;
6826
6827                                                                                                                 numhotspots++;
6828                                                                                                         }
6829                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
6830                                                                                                                 hostile=1;
6831                                                                                                         }
6832
6833                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
6834                                                                                                                 indialogue=-1;
6835                                                                                                                 directing=0;
6836                                                                                                                 cameramode=0;
6837                                                                                                         }
6838                                                                                                 }
6839                                                                                         }
6840                                                                                 }
6841                                                                                 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)
6842                                                                                         &&!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)
6843                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
6844                                                                                                 endkeydown=0;
6845                                                                                         }
6846                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
6847                                                                                                 indialogue=-1;
6848                                                                                                 directing=0;
6849                                                                                                 cameramode=0;
6850                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
6851                                                                                                         hostile=1;
6852                                                                                                 }
6853                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
6854                                                                                                         windialogue=1;
6855                                                                                                 }
6856                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
6857                                                                                                         hostile=1;
6858                                                                                                         for(i=1;i<numplayers;i++){
6859                                                                                                                 player[i].aitype = attacktypecutoff;
6860                                                                                                         }
6861                                                                                                 }
6862                                                                                         }
6863                                                         }
6864                                                 }
6865
6866                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
6867                                                 else oldbuttondialogue=1;
6868
6869                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
6870
6871                                                 //Net updates
6872
6873                                                 /*keyrefreshdelay-=multiplier;
6874                                                 bigrefreshdelay-=multiplier;
6875
6876                                                 if(keyrefreshdelay<=0){
6877                                                 static int concat[4];
6878
6879                                                 concat[0]=player[0].forwardkeydown;
6880                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
6881                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
6882                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
6883                                                 concat[0]=concat[0]*2+player[0].backkeydown;
6884                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
6885                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
6886                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
6887
6888                                                 concat[1]=player[0].crouchtogglekeydown;
6889                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
6890                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
6891                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
6892                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
6893                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
6894
6895                                                 //concat[2]=(char)((int)(rotation/2)%180);
6896
6897                                                 //concat[3]=(char)((int)(rotation2/2)%180);
6898
6899                                                 chatname[0]=concat[0]-128;
6900                                                 chatname[1]=concat[1]-128;
6901                                                 //chatname[2]=concat[2]-128;
6902                                                 //chatname[3]=concat[3]-128;
6903                                                 int temppoint=2;
6904                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
6905                                                 temppoint+=sizeof(float);
6906                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
6907                                                 temppoint+=sizeof(float);
6908
6909                                                 chatname[temppoint]='\0';
6910
6911                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
6912                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
6913                                                 //keyrefreshdelay=.01;
6914                                                 keyrefreshdelay=.03;
6915                                                 }
6916
6917                                                 if(bigrefreshdelay<=0){
6918                                                 for(i=0;i<1;i++){
6919                                                 /*int temppoint=0;
6920                                                 memcpy(chatname+temppoint,&i,sizeof(int));
6921                                                 temppoint+=sizeof(int);
6922                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
6923                                                 temppoint+=sizeof(float);
6924                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
6925                                                 temppoint+=sizeof(float);
6926                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
6927                                                 temppoint+=sizeof(float);
6928                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
6929                                                 temppoint+=sizeof(float);
6930                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
6931                                                 temppoint+=sizeof(float);
6932                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
6933                                                 temppoint+=sizeof(int);
6934                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
6935                                                 temppoint+=sizeof(int);
6936                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
6937                                                 temppoint+=sizeof(float);
6938                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
6939                                                 temppoint+=sizeof(float);
6940                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
6941                                                 temppoint+=sizeof(float);
6942                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
6943                                                 temppoint+=sizeof(int);
6944                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
6945                                                 temppoint+=sizeof(int);
6946                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
6947                                                 temppoint+=sizeof(float);
6948                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
6949                                                 temppoint+=sizeof(float);
6950                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
6951                                                 temppoint+=sizeof(float);
6952                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
6953                                                 temppoint+=sizeof(int);
6954                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
6955                                                 temppoint+=sizeof(int);
6956                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
6957                                                 temppoint+=sizeof(int);
6958                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
6959                                                 temppoint+=sizeof(int);
6960                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
6961                                                 temppoint+=sizeof(int);
6962                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
6963                                                 temppoint+=sizeof(int);
6964                                                 chatname[temppoint]='\0';
6965
6966                                                 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);
6967                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
6968                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
6969
6970                                                 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);
6971
6972                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
6973                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
6974                                                 }
6975                                                 //bigrefreshdelay=.02;
6976                                                 bigrefreshdelay=.1;
6977                                                 }
6978                                                 }*/
6979
6980                                                 if(!player[0].jumpkeydown){
6981                                                         player[0].jumptogglekeydown=0;
6982                                                 }
6983                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
6984
6985
6986                                                 dialoguetime+=multiplier;
6987                                                 skybox.cloudmove+=multiplier;
6988                                                 hawkrotation+=multiplier*25;
6989                                                 realhawkcoords=0;
6990                                                 realhawkcoords.x=25;
6991                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
6992                                                 hawkcalldelay-=multiplier/2;
6993
6994                                                 if(hawkcalldelay<=0)
6995                                                 {
6996                                                         static float gLoc[3];
6997                                                         static float vel[3];
6998                                                         gLoc[0]=realhawkcoords.x;
6999                                                         gLoc[1]=realhawkcoords.y;
7000                                                         gLoc[2]=realhawkcoords.z;
7001                                                         vel[0]=0;
7002                                                         vel[1]=0;
7003                                                         vel[2]=0;
7004                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
7005                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
7006                                                         OPENAL_SetVolume(channels[hawksound], 128);
7007                                                         OPENAL_SetPaused(channels[hawksound], false);
7008
7009                                                         hawkcalldelay=16+abs(Random()%8);
7010                                                 }
7011                                                 static float temptexdetail;
7012
7013
7014                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7015                                                         player[0].damagetolerance=200000;
7016                                                         player[0].damage=0;
7017                                                         player[0].burnt=0;
7018                                                         player[0].permanentdamage=0;
7019                                                         player[0].superpermanentdamage=0;
7020                                                         /*
7021                                                         int whichchar;
7022                                                         whichchar = abs(Random()%7);
7023                                                         registrationname[whichchar]+=1;
7024                                                         */
7025                                                 }
7026
7027                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7028                                                         environment++;
7029                                                         if(environment>2)environment=0;
7030                                                         Setenvironment(environment);
7031
7032                                                         envtogglekeydown=1;
7033                                                 }
7034
7035
7036                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7037                                                         envtogglekeydown=0;
7038                                                 }
7039
7040                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7041                                                         cameramode=1-cameramode;
7042                                                         cameratogglekeydown=1;
7043                                                 }
7044
7045                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7046                                                         cameratogglekeydown=0;
7047                                                 }
7048
7049                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7050                                                         if(player[0].num_weapons>0){
7051                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7052                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7053                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7054                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7055                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7056                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7057                                                                         weapons.length[player[0].weaponids[0]]=.8;
7058                                                                 }
7059                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7060                                                                         weapons.mass[player[0].weaponids[0]]=2;
7061                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7062                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7063                                                                 }
7064
7065                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7066                                                                         weapons.mass[player[0].weaponids[0]]=1;
7067                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7068                                                                         weapons.length[player[0].weaponids[0]]=.25;
7069                                                                 }
7070                                                         }
7071
7072                                                         /*for(i=0;i<objects.numobjects;i++){
7073                                                         if(objects.type[i]==treeleavestype){
7074                                                         for(j=0;j<objects.numobjects;j++){
7075                                                         if(objects.type[j]==treetrunktype)
7076                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7077                                                         objects.scale[i]=objects.scale[j];
7078                                                         }
7079                                                         }
7080                                                         }*/
7081                                                         detailtogglekeydown=1;
7082                                                 }
7083
7084                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7085                                                         int closest=-1;
7086                                                         float closestdist=-1;
7087                                                         float distance;
7088                                                         if(numplayers>1)
7089                                                                 for(i=1;i<numplayers;i++){
7090                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7091                                                                         if(closestdist==-1||distance<closestdist){
7092                                                                                 closestdist=distance;
7093                                                                                 closest=i;
7094                                                                         }
7095                                                                 }
7096                                                                 if(closest!=-1){
7097                                                                         if(player[closest].num_weapons)
7098                                                                         {
7099                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7100                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7101                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7102                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7103                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7104                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7105                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7106                                                                                 }
7107                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7108                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7109                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7110                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7111                                                                                 }
7112                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7113                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7114                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7115                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7116                                                                                 }
7117                                                                         }
7118                                                                         if(!player[closest].num_weapons)
7119                                                                         {
7120                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7121                                                                                 weapons.owner[weapons.numweapons]=closest;
7122                                                                                 weapons.type[weapons.numweapons]=knife;
7123                                                                                 weapons.damage[weapons.numweapons]=0;
7124                                                                                 weapons.numweapons++;
7125                                                                                 player[closest].num_weapons=1;
7126                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7127                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7128                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7129                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7130                                                                                 }
7131                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7132                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7133                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7134                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7135                                                                                 }
7136                                                                         }
7137                                                                 }
7138                                                                 detailtogglekeydown=1;
7139                                                 }
7140
7141                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7142                                                         int closest=-1;
7143                                                         float closestdist=-1;
7144                                                         float distance;
7145                                                         if(numplayers>1)
7146                                                                 for(i=1;i<numplayers;i++){
7147                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7148                                                                         if(closestdist==-1||distance<closestdist){
7149                                                                                 closestdist=distance;
7150                                                                                 closest=i;
7151                                                                         }
7152                                                                 }
7153
7154                                                                 player[closest].rotation+=multiplier*50;
7155                                                                 player[closest].targetrotation=player[closest].rotation;
7156                                                 }
7157
7158
7159                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7160                                                         int closest=-1;
7161                                                         float closestdist=-1;
7162                                                         float distance;
7163                                                         if(numplayers>1)
7164                                                                 for(i=1;i<numplayers;i++){
7165                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7166                                                                         if(closestdist==-1||distance<closestdist){
7167                                                                                 closestdist=distance;
7168                                                                                 closest=i;
7169                                                                         }
7170                                                                 }
7171                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7172
7173                                                                 if(closest!=-1){
7174                                                                         player[closest].whichskin++;
7175                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7176                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7177
7178                                                                         if(player[closest].creature==rabbittype){
7179                                                                                 if(player[closest].whichskin==0){
7180                                                                                         LoadTextureSave("/Data/Textures/Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7181                                                                                 }
7182                                                                                 else if(player[closest].whichskin==1){
7183                                                                                         LoadTextureSave("/Data/Textures/Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7184                                                                                 }
7185                                                                                 else if(player[closest].whichskin==2){
7186                                                                                         LoadTextureSave("/Data/Textures/Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7187                                                                                 }
7188                                                                                 else if(player[closest].whichskin==3){
7189                                                                                         LoadTextureSave("/Data/Textures/Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7190                                                                                 }
7191                                                                                 else if(player[closest].whichskin==4){
7192                                                                                         LoadTextureSave("/Data/Textures/Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7193                                                                                 }
7194                                                                                 else if(player[closest].whichskin==5){
7195                                                                                         LoadTextureSave("/Data/Textures/Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7196                                                                                 }
7197                                                                                 else if(player[closest].whichskin==6){
7198                                                                                         LoadTextureSave("/Data/Textures/Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7199                                                                                 }
7200                                                                                 else if(player[closest].whichskin==7){
7201                                                                                         LoadTextureSave("/Data/Textures/Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7202                                                                                 }
7203                                                                                 else if(player[closest].whichskin==8){
7204                                                                                         LoadTextureSave("/Data/Textures/BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7205                                                                                 }
7206                                                                                 else if(player[closest].whichskin==9){
7207                                                                                         LoadTextureSave("/Data/Textures/WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7208                                                                                 }
7209                                                                         }
7210                                                                         if(player[closest].creature==wolftype){
7211                                                                                 k=abs(Random()%3);
7212                                                                                 if(player[closest].whichskin==0){
7213                                                                                         LoadTextureSave("/Data/Textures/Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7214                                                                                 }
7215                                                                                 else if(player[closest].whichskin==1){
7216                                                                                         LoadTextureSave("/Data/Textures/Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7217                                                                                 }
7218                                                                                 else if(player[closest].whichskin==2){
7219                                                                                         LoadTextureSave("/Data/Textures/Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7220                                                                                 }
7221                                                                         }
7222                                                                 }
7223
7224                                                                 if(player[closest].numclothes){
7225                                                                         for(i=0;i<player[closest].numclothes;i++){
7226                                                                                 tintr=player[closest].clothestintr[i];
7227                                                                                 tintg=player[closest].clothestintg[i];
7228                                                                                 tintb=player[closest].clothestintb[i];
7229                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7230                                                                         }
7231                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7232                                                                 }
7233
7234                                                                 detailtogglekeydown=1;
7235                                                 }
7236
7237                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7238                                                         int closest=-1;
7239                                                         float closestdist=-1;
7240                                                         float distance;
7241                                                         if(numplayers>1)
7242                                                                 for(i=1;i<numplayers;i++){
7243                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7244                                                                         if(closestdist==-1||distance<closestdist){
7245                                                                                 closestdist=distance;
7246                                                                                 closest=i;
7247                                                                         }
7248                                                                 }
7249                                                                 if(closest!=-1){
7250                                                                         if(player[closest].creature==wolftype){
7251                                                                                 headprop=player[closest].proportionhead.x/1.1;
7252                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7253                                                                                 armprop=player[closest].proportionarms.x/1.1;
7254                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7255                                                                         }
7256
7257                                                                         if(player[closest].creature==rabbittype){
7258                                                                                 headprop=player[closest].proportionhead.x/1.2;
7259                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7260                                                                                 armprop=player[closest].proportionarms.x/1.00;
7261                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7262                                                                         }
7263
7264
7265                                                                         if(player[closest].creature==rabbittype){
7266                                                                                 player[closest].skeleton.id=closest;
7267                                                                                 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);
7268                                                                                 LoadTextureSave("/Data/Textures/Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7269                                                                                 player[closest].whichskin=0;
7270                                                                                 player[closest].creature=wolftype;
7271
7272                                                                                 player[closest].proportionhead=1.1;
7273                                                                                 player[closest].proportionbody=1.1;
7274                                                                                 player[closest].proportionarms=1.1;
7275                                                                                 player[closest].proportionlegs=1.1;
7276                                                                                 player[closest].proportionlegs.y=1.1;
7277                                                                                 player[closest].scale=.23*5*player[0].scale;
7278
7279                                                                                 player[closest].damagetolerance=300;
7280                                                                         }
7281                                                                         else
7282                                                                         {
7283                                                                                 player[closest].skeleton.id=closest;
7284                                                                                 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);
7285                                                                                 LoadTextureSave("/Data/Textures/Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7286                                                                                 player[closest].whichskin=0;
7287                                                                                 player[closest].creature=rabbittype;
7288
7289                                                                                 player[closest].proportionhead=1.2;
7290                                                                                 player[closest].proportionbody=1.05;
7291                                                                                 player[closest].proportionarms=1.00;
7292                                                                                 player[closest].proportionlegs=1.1;
7293                                                                                 player[closest].proportionlegs.y=1.05;
7294                                                                                 player[closest].scale=.2*5*player[0].scale;
7295
7296                                                                                 player[closest].damagetolerance=200;
7297                                                                         }
7298
7299                                                                         if(player[closest].creature==wolftype){
7300                                                                                 player[closest].proportionhead=1.1*headprop;
7301                                                                                 player[closest].proportionbody=1.1*bodyprop;
7302                                                                                 player[closest].proportionarms=1.1*armprop;
7303                                                                                 player[closest].proportionlegs=1.1*legprop;
7304                                                                         }
7305
7306                                                                         if(player[closest].creature==rabbittype){
7307                                                                                 player[closest].proportionhead=1.2*headprop;
7308                                                                                 player[closest].proportionbody=1.05*bodyprop;
7309                                                                                 player[closest].proportionarms=1.00*armprop;
7310                                                                                 player[closest].proportionlegs=1.1*legprop;
7311                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7312                                                                         }
7313
7314                                                                 }
7315                                                                 detailtogglekeydown=1;
7316                                                 }
7317
7318                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7319                                                         detailtogglekeydown=0;
7320                                                 }
7321
7322                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7323                                                         slomo=1-slomo;
7324                                                         slomodelay=1000;
7325                                                         slomotogglekeydown=1;
7326                                                 }
7327
7328
7329                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7330                                                         int closest=-1;
7331                                                         float closestdist=-1;
7332                                                         float distance;
7333                                                         XYZ flatfacing2,flatvelocity2;
7334                                                         XYZ blah;
7335                                                         if(numplayers>1)
7336                                                                 for(i=1;i<numplayers;i++){
7337                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7338                                                                         if(distance<144&&!player[i].headless)
7339                                                                                 if(closestdist==-1||distance<closestdist){
7340                                                                                         closestdist=distance;
7341                                                                                         closest=i;
7342                                                                                         blah = player[i].coords;
7343                                                                                 }
7344                                                                 }
7345
7346                                                                 if(closest!=-1){
7347                                                                         XYZ headspurtdirection;
7348                                                                         int i = player[closest].skeleton.jointlabels[head];
7349                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7350                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7351                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7352                                                                                 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;
7353                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7354                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7355                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7356                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7357                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7358                                                                                 Normalise(&headspurtdirection);
7359                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7360                                                                                 flatvelocity2+=headspurtdirection*8;
7361                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7362                                                                         }
7363                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7364
7365                                                                         float gLoc[3];
7366                                                                         float vel[3];
7367                                                                         gLoc[0]=blah.x;
7368                                                                         gLoc[1]=blah.y;
7369                                                                         gLoc[2]=blah.z;
7370                                                                         vel[0]=0;
7371                                                                         vel[1]=0;
7372                                                                         vel[2]=0;
7373                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7374                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7375                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7376                                                                         OPENAL_SetPaused(channels[splattersound], false);
7377
7378                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7379                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7380                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7381                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7382
7383                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7384                                                                         player[closest].RagDoll(0);
7385                                                                         player[closest].dead=2;
7386                                                                         player[closest].headless=1;
7387                                                                         player[closest].DoBloodBig(3,165);
7388
7389                                                                         camerashake+=.3;
7390                                                                 }
7391
7392                                                                 explodetogglekeydown=1;
7393                                                 }
7394
7395                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7396                                                         int closest=-1;
7397                                                         float closestdist=-1;
7398                                                         float distance;
7399                                                         XYZ flatfacing2,flatvelocity2;
7400                                                         XYZ blah;
7401                                                         if(numplayers>1)
7402                                                                 for(i=1;i<numplayers;i++){
7403                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7404                                                                         if(distance<144)
7405                                                                                 if(closestdist==-1||distance<closestdist){
7406                                                                                         closestdist=distance;
7407                                                                                         closest=i;
7408                                                                                         blah=player[i].coords;
7409                                                                                 }
7410                                                                 }
7411
7412                                                                 if(closest!=-1){
7413                                                                         float gLoc[3];
7414                                                                         float vel[3];
7415                                                                         gLoc[0]=blah.x;
7416                                                                         gLoc[1]=blah.y;
7417                                                                         gLoc[2]=blah.z;
7418                                                                         vel[0]=0;
7419                                                                         vel[1]=0;
7420                                                                         vel[2]=0;
7421
7422                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7423                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7424                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7425                                                                         OPENAL_SetPaused(channels[splattersound], false);
7426
7427                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7428                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7429                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7430                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7431
7432                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7433                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7434                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7435                                                                                 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;
7436                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7437                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7438                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7439                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7440                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7441                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7442                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7443                                                                         }
7444
7445                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7446                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7447                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7448                                                                                 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;
7449                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7450                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7451                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7452                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7453                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7454                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7455                                                                         }
7456
7457                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7458                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7459                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7460                                                                                 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;
7461                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7462                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7463                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7464                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7465                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7466                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7467                                                                         }
7468
7469                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7470                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7471                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7472                                                                                 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;
7473                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7474                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7475                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7476                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7477                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7478                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7479                                                                         }
7480
7481                                                                         XYZ temppos;
7482                                                                         for(j=0;j<numplayers; j++){
7483                                                                                 if(j!=closest){
7484                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7485                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7486                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7487                                                                                                 player[j].skeleton.longdead=0;
7488                                                                                                 player[j].RagDoll(0);
7489                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7490                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7491                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7492                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7493                                                                                                                 Normalise(&flatvelocity2);
7494                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7495                                                                                                         }
7496                                                                                                 }
7497                                                                                         }
7498                                                                                 }
7499                                                                         }
7500
7501                                                                         player[closest].DoDamage(10000);
7502                                                                         player[closest].RagDoll(0);
7503                                                                         player[closest].dead=2;
7504                                                                         player[closest].coords=20;
7505                                                                         player[closest].skeleton.free=2;
7506
7507                                                                         camerashake+=.6;
7508
7509                                                                 }
7510
7511                                                                 explodetogglekeydown=1;
7512                                                 }
7513
7514                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7515                                                         explodetogglekeydown=0;
7516                                                 }
7517
7518                                                 /*
7519                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7520                                                 FILE                    *tfile;
7521                                                 //tfile=fopen( "/Data/Maps/mapsave", "wb" );
7522                                                 if(whichlevel==0)tfile=fopen( "/Data/Maps/map1", "wb" );
7523                                                 else if(whichlevel==1)tfile=fopen( "/Data/Maps/map2", "wb" );
7524                                                 else if(whichlevel==2)tfile=fopen( "/Data/Maps/map3", "wb" );
7525                                                 else if(whichlevel==3)tfile=fopen( "/Data/Maps/map4", "wb" );
7526                                                 else if(whichlevel==4)tfile=fopen( "/Data/Maps/map5", "wb" );
7527                                                 else tfile=fopen( "/Data/Maps/mapsave", "wb" );
7528
7529                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7530                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7531                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7532                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7533                                                 for(j=0;j<player[0].num_weapons;j++){
7534                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7535                                                 }
7536                                                 fwrite( &environment, 1, sizeof(int), tfile );
7537
7538                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7539                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7540                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7541                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7542                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7543
7544                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7545                                                 if(numplayers>1&&numplayers<maxplayers)
7546                                                 for(i=1;i<numplayers;i++){
7547                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7548                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7549                                                 for(j=0;j<player[i].num_weapons;j++){
7550                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7551                                                 }
7552                                                 if(player[i].numwaypoints<30){
7553                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7554                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7555                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7556                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7557                                                 }
7558                                                 else{
7559                                                 player[i].numwaypoints=0;
7560                                                 player[i].waypoint=0;
7561                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7562                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7563                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7564                                                 }
7565                                                 }
7566
7567                                                 fclose(tfile);
7568
7569                                                 slomotogglekeydown=1;
7570                                                 }*/
7571
7572                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7573                                                         slomotogglekeydown=0;
7574                                                 }
7575
7576
7577                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7578                                                         player[0].onfire=1-player[0].onfire;
7579                                                         if(player[0].onfire){
7580                                                                 player[0].CatchFire();
7581                                                         }
7582                                                         if(!player[0].onfire){
7583                                                                 float gLoc[3];
7584                                                                 float vel[3];
7585                                                                 gLoc[0]=player[0].coords.x;
7586                                                                 gLoc[1]=player[0].coords.y;
7587                                                                 gLoc[2]=player[0].coords.z;
7588                                                                 vel[0]=0;
7589                                                                 vel[1]=0;
7590                                                                 vel[2]=0;
7591                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7592                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7593                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7594                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7595                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7596                                                         }
7597                                                         slomotogglekeydown=1;
7598                                                 }
7599                                                 /*
7600                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7601                                                 if(player[0].bleeding<=0)
7602                                                 player[0].DoBlood(1,255);
7603                                                 }*/
7604
7605
7606                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7607                                                         int closest=-1;
7608                                                         float closestdist=-1;
7609                                                         float distance;
7610                                                         if(numplayers>1)
7611                                                                 for(i=1;i<numplayers;i++){
7612                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7613                                                                         if(closestdist==-1||distance<closestdist){
7614                                                                                 closestdist=distance;
7615                                                                                 closest=i;
7616                                                                         }
7617                                                                 }
7618                                                                 if(closestdist>0&&closest>=0){
7619                                                                         //player[closest]=player[numplayers-1];
7620                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7621                                                                         numplayers--;
7622                                                                 }
7623                                                                 drawmodetogglekeydown=1;
7624                                                 }
7625
7626                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7627                                                         int closest=-1;
7628                                                         float closestdist=-1;
7629                                                         float distance;
7630                                                         if(max_objects>1)
7631                                                                 for(i=1;i<max_objects;i++){
7632                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7633                                                                         if(closestdist==-1||distance<closestdist){
7634                                                                                 closestdist=distance;
7635                                                                                 closest=i;
7636                                                                         }
7637                                                                 }
7638                                                                 if(closestdist>0&&closest>=0){
7639                                                                         objects.position[closest].y-=500;
7640                                                                 }
7641                                                                 drawmodetogglekeydown=1;
7642                                                 }
7643
7644                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7645                                                         //drawmode++;
7646                                                         //if(drawmode>2)drawmode=0;
7647                                                         if(objects.numobjects<max_objects-1){
7648                                                                 XYZ boxcoords;
7649                                                                 boxcoords.x=player[0].coords.x;
7650                                                                 boxcoords.z=player[0].coords.z;
7651                                                                 boxcoords.y=player[0].coords.y-3;
7652                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7653                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7654                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7655                                                                 float temprotat,temprotat2;
7656                                                                 temprotat=editorrotation;
7657                                                                 temprotat2=editorrotation2;
7658                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7659                                                                 if(temprotat2<0)temprotat2=Random()%360;
7660
7661                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7662                                                                 if(editortype==treetrunktype)
7663                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7664                                                         }
7665
7666                                                         drawmodetogglekeydown=1;
7667                                                 }
7668
7669                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7670                                                         if(numplayers<maxplayers-1){
7671                                                                 player[numplayers].scale=.2*5*player[0].scale;
7672                                                                 player[numplayers].creature=rabbittype;
7673                                                                 player[numplayers].howactive=editoractive;
7674                                                                 player[numplayers].skeleton.id=numplayers;
7675                                                                 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);
7676
7677                                                                 //texsize=512*512*3/texdetail/texdetail;
7678                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
7679                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
7680
7681                                                                 k=abs(Random()%2)+1;
7682                                                                 if(k==0){
7683                                                                         LoadTextureSave("/Data/Textures/Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7684                                                                         player[numplayers].whichskin=0;
7685                                                                 }
7686                                                                 else if(k==1){
7687                                                                         LoadTextureSave("/Data/Textures/Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7688                                                                         player[numplayers].whichskin=1;
7689                                                                 }
7690                                                                 else {
7691                                                                         LoadTextureSave("/Data/Textures/Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7692                                                                         player[numplayers].whichskin=2;
7693                                                                 }
7694
7695                                                                 LoadTexture("/Data/Textures/Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
7696                                                                 player[numplayers].power=1;
7697                                                                 player[numplayers].speedmult=1;
7698                                                                 player[numplayers].currentanimation=bounceidleanim;
7699                                                                 player[numplayers].targetanimation=bounceidleanim;
7700                                                                 player[numplayers].currentframe=0;
7701                                                                 player[numplayers].targetframe=1;
7702                                                                 player[numplayers].target=0;
7703                                                                 player[numplayers].bled=0;
7704                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
7705
7706                                                                 player[numplayers].targetrotation=player[0].targetrotation;
7707                                                                 player[numplayers].rotation=player[0].rotation;
7708
7709                                                                 player[numplayers].velocity=0;
7710                                                                 player[numplayers].coords=player[0].coords;
7711                                                                 player[numplayers].oldcoords=player[numplayers].coords;
7712                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
7713
7714                                                                 player[numplayers].id=numplayers;
7715                                                                 player[numplayers].skeleton.id=numplayers;
7716                                                                 player[numplayers].updatedelay=0;
7717                                                                 player[numplayers].normalsupdatedelay=0;
7718
7719                                                                 player[numplayers].aitype=passivetype;
7720                                                                 player[numplayers].aitarget=0;
7721
7722                                                                 if(player[0].creature==wolftype){
7723                                                                         headprop=player[0].proportionhead.x/1.1;
7724                                                                         bodyprop=player[0].proportionbody.x/1.1;
7725                                                                         armprop=player[0].proportionarms.x/1.1;
7726                                                                         legprop=player[0].proportionlegs.x/1.1;
7727                                                                 }
7728
7729                                                                 if(player[0].creature==rabbittype){
7730                                                                         headprop=player[0].proportionhead.x/1.2;
7731                                                                         bodyprop=player[0].proportionbody.x/1.05;
7732                                                                         armprop=player[0].proportionarms.x/1.00;
7733                                                                         legprop=player[0].proportionlegs.x/1.1;
7734                                                                 }
7735
7736                                                                 if(player[numplayers].creature==wolftype){
7737                                                                         player[numplayers].proportionhead=1.1*headprop;
7738                                                                         player[numplayers].proportionbody=1.1*bodyprop;
7739                                                                         player[numplayers].proportionarms=1.1*armprop;
7740                                                                         player[numplayers].proportionlegs=1.1*legprop;
7741                                                                 }
7742
7743                                                                 if(player[numplayers].creature==rabbittype){
7744                                                                         player[numplayers].proportionhead=1.2*headprop;
7745                                                                         player[numplayers].proportionbody=1.05*bodyprop;
7746                                                                         player[numplayers].proportionarms=1.00*armprop;
7747                                                                         player[numplayers].proportionlegs=1.1*legprop;
7748                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
7749                                                                 }
7750
7751                                                                 player[numplayers].headless=0;
7752                                                                 player[numplayers].onfire=0;
7753
7754                                                                 if(cellophane){
7755                                                                         player[numplayers].proportionhead.z=0;
7756                                                                         player[numplayers].proportionbody.z=0;
7757                                                                         player[numplayers].proportionarms.z=0;
7758                                                                         player[numplayers].proportionlegs.z=0;
7759                                                                 }
7760
7761                                                                 player[numplayers].tempanimation.Load((char *)"/Data/Animations/Tempanim",0,0);
7762
7763                                                                 player[numplayers].damagetolerance=200;
7764
7765                                                                 player[numplayers].protectionhead=player[0].protectionhead;
7766                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
7767                                                                 player[numplayers].protectionlow=player[0].protectionlow;
7768                                                                 player[numplayers].armorhead=player[0].armorhead;
7769                                                                 player[numplayers].armorhigh=player[0].armorhigh;
7770                                                                 player[numplayers].armorlow=player[0].armorlow;
7771                                                                 player[numplayers].metalhead=player[0].metalhead;
7772                                                                 player[numplayers].metalhigh=player[0].metalhigh;
7773                                                                 player[numplayers].metallow=player[0].metallow;
7774
7775                                                                 player[numplayers].immobile=player[0].immobile;
7776
7777                                                                 player[numplayers].numclothes=player[0].numclothes;
7778                                                                 if(player[numplayers].numclothes)
7779                                                                         for(i=0;i<player[numplayers].numclothes;i++){
7780                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
7781                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
7782                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
7783                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
7784                                                                                 tintr=player[numplayers].clothestintr[i];
7785                                                                                 tintg=player[numplayers].clothestintg[i];
7786                                                                                 tintb=player[numplayers].clothestintb[i];
7787                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
7788                                                                         }
7789                                                                         if(player[numplayers].numclothes){
7790                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
7791                                                                         }
7792
7793                                                                         player[numplayers].power=player[0].power;
7794                                                                         player[numplayers].speedmult=player[0].speedmult;
7795
7796                                                                         player[numplayers].damage=0;
7797                                                                         player[numplayers].permanentdamage=0;
7798                                                                         player[numplayers].superpermanentdamage=0;
7799                                                                         player[numplayers].deathbleeding=0;
7800                                                                         player[numplayers].bleeding=0;
7801                                                                         player[numplayers].numwaypoints=0;
7802                                                                         player[numplayers].waypoint=0;
7803                                                                         player[numplayers].jumppath=0;
7804                                                                         player[numplayers].weaponstuck=-1;
7805                                                                         player[numplayers].weaponactive=-1;
7806                                                                         player[numplayers].num_weapons=0;
7807                                                                         player[numplayers].bloodloss=0;
7808                                                                         player[numplayers].dead=0;
7809
7810                                                                         player[numplayers].loaded=1;
7811
7812                                                                         numplayers++;
7813                                                         }
7814                                                         drawmodetogglekeydown=1;
7815                                                 }
7816
7817                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
7818                                                         if(player[numplayers-1].numwaypoints<90){
7819                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
7820                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
7821                                                                 player[numplayers-1].numwaypoints++;
7822                                                         }
7823                                                         drawmodetogglekeydown=1;
7824                                                 }
7825
7826                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7827                                                         if(numpathpoints<30){
7828                                                                 bool connected,alreadyconnected;
7829                                                                 connected=0;
7830                                                                 if(numpathpoints>1)
7831                                                                         for(i=0;i<numpathpoints;i++){
7832                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
7833                                                                                         alreadyconnected=0;
7834                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
7835                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
7836                                                                                         }
7837                                                                                         if(!alreadyconnected){
7838                                                                                                 numpathpointconnect[pathpointselected]++;
7839                                                                                                 connected=1;
7840                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
7841                                                                                         }
7842                                                                                 }
7843                                                                         }
7844                                                                         if(!connected){
7845                                                                                 numpathpoints++;
7846                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
7847                                                                                 numpathpointconnect[numpathpoints-1]=0;
7848                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
7849                                                                                         numpathpointconnect[pathpointselected]++;
7850                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
7851                                                                                 }
7852                                                                                 pathpointselected=numpathpoints-1;
7853                                                                         }
7854                                                         }
7855                                                         drawmodetogglekeydown=1;
7856                                                 }
7857
7858                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
7859                                                         pathpointselected++;
7860                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
7861                                                         drawmodetogglekeydown=1;
7862                                                 }
7863                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7864                                                         pathpointselected--;
7865                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
7866                                                         drawmodetogglekeydown=1;
7867                                                 }
7868                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
7869                                                         if(pathpointselected!=-1){
7870                                                                 numpathpoints--;
7871                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
7872                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
7873                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
7874                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
7875                                                                 }
7876                                                                 for(i=0;i<numpathpoints;i++){
7877                                                                         for(j=0;j<numpathpointconnect[i];j++){
7878                                                                                 if(pathpointconnect[i][j]==pathpointselected){
7879                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
7880                                                                                         numpathpointconnect[i]--;
7881                                                                                 }
7882                                                                                 if(pathpointconnect[i][j]==numpathpoints){
7883                                                                                         pathpointconnect[i][j]=pathpointselected;
7884                                                                                 }
7885                                                                         }
7886                                                                 }
7887                                                                 pathpointselected=numpathpoints-1;
7888                                                         }
7889                                                         drawmodetogglekeydown=1;
7890                                                 }
7891
7892                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7893                                                         editorenabled=1-editorenabled;
7894                                                         if(editorenabled){
7895                                                                 player[0].damagetolerance=100000;
7896                                                                 player[0].damage=0;
7897                                                                 player[0].superpermanentdamage=0;
7898                                                                 player[0].bloodloss=0;
7899                                                                 player[0].deathbleeding=0;
7900                                                         }
7901                                                         if(!editorenabled){
7902                                                                 player[0].damagetolerance=200;
7903                                                                 player[0].damage=0;
7904                                                                 player[0].permanentdamage=0;
7905                                                                 player[0].superpermanentdamage=0;
7906                                                                 player[0].bloodloss=0;
7907                                                                 player[0].deathbleeding=0;
7908                                                         }
7909                                                         drawmodetogglekeydown=1;
7910                                                 }
7911
7912                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7913                                                         editortype--;
7914                                                         if(editortype==treeleavestype||editortype==10)editortype--;
7915                                                         if(editortype<0)editortype=firetype;
7916                                                         drawmodetogglekeydown=1;
7917                                                 }
7918
7919                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7920                                                         editortype++;
7921                                                         if(editortype==treeleavestype||editortype==10)editortype++;
7922                                                         if(editortype>firetype)editortype=0;
7923                                                         drawmodetogglekeydown=1;
7924                                                 }
7925
7926                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7927                                                         editorrotation-=multiplier*100;
7928                                                         if(editorrotation<-.01)editorrotation=-.01;
7929                                                         drawmodetogglekeydown=1;
7930                                                 }
7931
7932                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7933                                                         editorrotation+=multiplier*100;
7934                                                         drawmodetogglekeydown=1;
7935                                                 }
7936
7937                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7938                                                         editorsize+=multiplier;
7939                                                         drawmodetogglekeydown=1;
7940                                                 }
7941
7942                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7943                                                         editorsize-=multiplier;
7944                                                         if(editorsize<.1)editorsize=.1;
7945                                                         drawmodetogglekeydown=1;
7946                                                 }
7947
7948
7949                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7950                                                         mapradius-=multiplier*10;
7951                                                 }
7952
7953                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7954                                                         mapradius+=multiplier*10;
7955                                                 }
7956                                                 /*
7957                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7958                                                 mapcenter.x+=multiplier*20;
7959                                                 }
7960
7961                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7962                                                 mapcenter.x-=multiplier*20;
7963                                                 }
7964
7965                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7966                                                 mapcenter.z+=multiplier*20;
7967                                                 }
7968
7969                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7970                                                 mapcenter.z-=multiplier*20;
7971                                                 }
7972                                                 */
7973                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7974                                                         editorrotation2+=multiplier*100;
7975                                                 }
7976
7977                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7978                                                         editorrotation2-=multiplier*100;
7979                                                         if(editorrotation2<-.01)editorrotation2=-.01;
7980                                                 }
7981                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7982                                                         int closest=-1;
7983                                                         float closestdist=-1;
7984                                                         float distance;
7985                                                         for(i=0;i<objects.numobjects;i++){
7986                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
7987                                                                 if(closestdist==-1||distance<closestdist){
7988                                                                         closestdist=distance;
7989                                                                         closest=i;
7990                                                                 }
7991                                                         }
7992                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
7993                                                         drawmodetogglekeydown=1;
7994                                                 }
7995
7996
7997                                                 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)){
7998                                                         drawmodetogglekeydown=0;
7999                                                 }
8000
8001                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8002                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8003                                                         player[0].RagDoll(0);
8004                                                         //player[0].spurt=1;
8005                                                         //player[0].DoDamage(1000);
8006
8007                                                         float gLoc[3];
8008                                                         float vel[3];
8009                                                         gLoc[0]=player[0].coords.x;
8010                                                         gLoc[1]=player[0].coords.y;
8011                                                         gLoc[2]=player[0].coords.z;
8012                                                         vel[0]=player[0].velocity.x;
8013                                                         vel[1]=player[0].velocity.y;
8014                                                         vel[2]=player[0].velocity.z;
8015                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
8016                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8017                                                         OPENAL_SetVolume(channels[whooshsound], 128);
8018                                                         OPENAL_SetPaused(channels[whooshsound], false);
8019                                                         //OPENAL_SetPaused(channels[whooshsound], true);
8020
8021                                                         texturesizetogglekeydown=1;
8022                                                 }
8023
8024                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8025
8026                                                         int closest=-1;
8027                                                         float closestdist=-1;
8028                                                         float distance;
8029                                                         for(i=0;i<objects.numobjects;i++){
8030                                                                 if(objects.type[i]==treeleavestype){
8031                                                                         objects.scale[i]*=.9;
8032                                                                 }
8033                                                         }
8034                                                         texturesizetogglekeydown=1;
8035                                                 }
8036
8037                                                 static XYZ relative;
8038                                                 static int randattack;
8039                                                 //Attack
8040                                                 static bool playerrealattackkeydown=0;
8041
8042                                                 if(!buttons[0])oldbutton=0;
8043                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8044                                                 if(oldattackkey)player[0].attackkeydown=0;
8045                                                 if(oldattackkey)playerrealattackkeydown=0;
8046                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8047                                                 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);
8048                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8049                                                         for(k=0;k<numplayers;k++){
8050                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8051                                                                         player[k].Reverse();
8052                                                         }
8053                                                 }
8054
8055                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8056
8057                                                 for(k=0;k<numplayers;k++){
8058                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8059                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8060                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8061                                                                 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)){
8062                                                                         player[k].jumppower-=2;
8063                                                                 }
8064                                                                 if(player[k].attackkeydown&&player[k].jumppower>1&&player[k].backkeydown&&player[k].targetanimation!=backhandspringanim&&(player[k].isIdle()||player[k].isStop()||player[k].isRun()||player[k].targetanimation==walkanim)){
8065                                                                         for(i=0;i<numplayers;i++){
8066                                                                                 if(i==k)i++;
8067                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8068                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8069                                                                                                 player[k].targetanimation=dodgebackanim;
8070                                                                                                 player[k].target=0;
8071                                                                                                 player[k].targetframe=0;
8072                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8073                                                                                                 Normalise(&rotatetarget);
8074                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8075                                                                                                 player[k].targetrotation*=360/6.28;
8076                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8077
8078                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8079                                                                                         }
8080                                                                         }
8081                                                                         if(player[k].targetanimation!=dodgebackanim){
8082                                                                                 if(k==0)numflipped++;
8083                                                                                 player[k].targetanimation=backhandspringanim;
8084                                                                                 player[k].target=0;
8085                                                                                 player[k].targetframe=0;
8086                                                                                 player[k].targetrotation=-rotation+180;
8087                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8088                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8089                                                                                 player[k].rotation=player[k].targetrotation;
8090                                                                                 player[k].jumppower-=2;
8091                                                                         }
8092                                                                 }
8093                                                                 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())){
8094                                                                         player[k].hasvictim=0;
8095                                                                         if(numplayers>1)
8096                                                                                 for(i=0;i<numplayers;i++){
8097                                                                                         if(i==k)i++;
8098                                                                                         if(!player[k].hasvictim)
8099                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
8100                                                                                                         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){
8101                                                                                                                 player[k].victim=&player[i];
8102                                                                                                                 player[k].hasvictim=1;
8103                                                                                                                 if(player[k].aitype==playercontrolled){
8104                                                                                                                         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;
8105                                                                                                                         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;
8106                                                                                                                         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;
8107                                                                                                                         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;
8108                                                                                                                         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;
8109                                                                                                                         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;
8110                                                                                                                         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;
8111                                                                                                                         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;
8112                                                                                                                         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;
8113                                                                                                                         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;
8114                                                                                                                 }
8115                                                                                                                 else {
8116                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8117                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8118                                                                                                                                 else randattack=abs(Random()%5);
8119                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8120                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8121                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8122                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8123                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8124                                                                                                                                 }
8125                                                                                                                                 if(player[k].weaponactive!=-1){
8126                                                                                                                                         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;
8127                                                                                                                                         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;
8128                                                                                                                                         //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;
8129                                                                                                                                         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;
8130                                                                                                                                         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;
8131                                                                                                                                         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;
8132                                                                                                                                         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;
8133                                                                                                                                         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;
8134                                                                                                                                 }
8135                                                                                                                         }
8136                                                                                                                 }
8137                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8138                                                                                                         }
8139                                                                                                         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)){
8140                                                                                                                 if(player[k].weaponactive==-1){
8141                                                                                                                         player[i].targetanimation=sneakattackedanim;
8142                                                                                                                         player[i].currentanimation=sneakattackedanim;
8143                                                                                                                         player[k].currentanimation=sneakattackanim;
8144                                                                                                                         player[k].targetanimation=sneakattackanim;
8145                                                                                                                         player[k].oldcoords=player[k].coords;
8146                                                                                                                         player[k].coords=player[i].coords;
8147                                                                                                                 }
8148                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8149                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8150                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8151                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8152                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8153                                                                                                                         player[i].oldcoords=player[i].coords;
8154                                                                                                                         player[i].coords=player[k].coords;
8155                                                                                                                 }
8156                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8157                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8158                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8159                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8160                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8161                                                                                                                         player[i].oldcoords=player[i].coords;
8162                                                                                                                         player[i].coords=player[k].coords;
8163                                                                                                                 }
8164                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8165                                                                                                                         player[k].victim=&player[i];
8166                                                                                                                         player[k].hasvictim=1;
8167                                                                                                                         player[i].targettilt2=0;
8168                                                                                                                         player[i].targetframe=1;
8169                                                                                                                         player[i].currentframe=0;
8170                                                                                                                         player[i].target=0;
8171                                                                                                                         player[i].velocity=0;
8172                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8173                                                                                                                         player[k].currentframe=player[i].currentframe;
8174                                                                                                                         player[k].targetframe=player[i].targetframe;
8175                                                                                                                         player[k].target=player[i].target;
8176                                                                                                                         player[k].velocity=0;
8177                                                                                                                         player[k].targetrotation=player[i].rotation;
8178                                                                                                                         player[k].rotation=player[i].rotation;
8179                                                                                                                         player[i].targetrotation=player[i].rotation;
8180                                                                                                                 }
8181                                                                                                         }
8182                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8183                                                                                                                 oldattackkey=1;
8184                                                                                                                 player[k].targetframe=0;
8185                                                                                                                 player[k].target=0;
8186                                                                                                                 //player[k].velocity=0;
8187
8188                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8189                                                                                                                 Normalise(&rotatetarget);
8190                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8191                                                                                                                 player[k].targetrotation*=360/6.28;
8192                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8193
8194                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8195
8196                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8197                                                                                                                 player[k].lastattack2=player[k].lastattack;
8198                                                                                                                 player[k].lastattack=player[k].targetanimation;
8199                                                                                                                 //player[k].targettilt2=0;
8200                                                                                                                 //slomo=1;
8201                                                                                                                 //slomodelay=.2;
8202                                                                                                         }
8203                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8204                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8205                                                                                                                 Normalise(&rotatetarget);
8206                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8207                                                                                                                 player[k].targetrotation*=360/6.28;
8208                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8209                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8210                                                                                                                 oldattackkey=1;
8211                                                                                                                 player[k].victim=&player[i];
8212                                                                                                                 player[k].hasvictim=1;
8213                                                                                                                 player[i].targetanimation=knifefollowedanim;
8214                                                                                                                 player[i].currentanimation=knifefollowedanim;
8215                                                                                                                 player[i].targettilt2=0;
8216                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8217                                                                                                                 player[i].targetframe=1;
8218                                                                                                                 player[i].currentframe=0;
8219                                                                                                                 player[i].target=0;
8220                                                                                                                 player[i].velocity=0;
8221                                                                                                                 player[k].currentanimation=knifefollowanim;
8222                                                                                                                 player[k].targetanimation=knifefollowanim;
8223                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8224                                                                                                                 player[k].currentframe=player[i].currentframe;
8225                                                                                                                 player[k].targetframe=player[i].targetframe;
8226                                                                                                                 player[k].target=player[i].target;
8227                                                                                                                 player[k].velocity=0;
8228                                                                                                                 player[k].oldcoords=player[k].coords;
8229                                                                                                                 player[i].coords=player[k].coords;
8230                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8231                                                                                                                 player[i].rotation=player[k].targetrotation;
8232                                                                                                                 player[k].rotation=player[k].targetrotation;
8233                                                                                                                 player[i].rotation=player[k].targetrotation;
8234                                                                                                         }
8235                                                                                                 }
8236                                                                                 }
8237                                                                                 bool hasstaff=0;
8238                                                                                 if(player[k].weaponactive!=-1){
8239                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8240                                                                                 }
8241                                                                                 if(numplayers>1)
8242                                                                                         for(i=0;i<numplayers;i++){
8243                                                                                                 if(i==k)i++;
8244                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8245                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8246                                                                                                                 if(player[i].skeleton.free)
8247                                                                                                                         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)))){
8248                                                                                                                                 player[k].victim=&player[i];
8249                                                                                                                                 player[k].hasvictim=1;
8250                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8251                                                                                                                                         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;
8252                                                                                                                                         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;
8253                                                                                                                                         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;
8254                                                                                                                                 }
8255                                                                                                                                 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){
8256                                                                                                                                         player[k].targetanimation=killanim;
8257                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8258                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8259                                                                                                                                                         terrain.DeleteDecal(j);
8260                                                                                                                                                 }
8261                                                                                                                                         }
8262                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8263                                                                                                                                                 if(objects.model[l].type==decalstype)
8264                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8265                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8266                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8267                                                                                                                                                                 }
8268                                                                                                                                                         }
8269                                                                                                                                         }
8270                                                                                                                                 }
8271                                                                                                                                 if(!player[i].dead||musictype!=2)
8272                                                                                                                                         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)){
8273                                                                                                                                                 player[k].targetanimation=dropkickanim;
8274                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8275                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8276                                                                                                                                                                 terrain.DeleteDecal(j);
8277                                                                                                                                                         }
8278                                                                                                                                                 }
8279                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8280                                                                                                                                                         if(objects.model[l].type==decalstype)
8281                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8282                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8283                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8284                                                                                                                                                                         }
8285                                                                                                                                                                 }
8286                                                                                                                                                 }
8287                                                                                                                                         }
8288                                                                                                                         }
8289                                                                                                                         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)){
8290                                                                                                                                 oldattackkey=1;
8291                                                                                                                                 player[k].targetframe=0;
8292                                                                                                                                 player[k].target=0;
8293                                                                                                                                 //player[k].velocity=0;
8294
8295                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8296                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8297                                                                                                                                         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;
8298                                                                                                                                 }
8299                                                                                                                                 Normalise(&rotatetarget);
8300                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8301                                                                                                                                 player[k].targetrotation*=360/6.28;
8302                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8303
8304                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8305                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8306                                                                                                                                 }
8307
8308                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8309                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8310
8311                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8312                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8313                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8314
8315                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8316                                                                                                                                         player[k].targetrotation+=30;
8317                                                                                                                                 }
8318                                                                                                                                 //player[k].targettilt2=0;
8319                                                                                                                                 //slomo=1;
8320                                                                                                                                 //slomodelay=.2;
8321                                                                                                                         }
8322                                                                                                 }
8323                                                                                         }
8324                                                                                         if(!player[k].hasvictim){
8325                                                                                                 for(i=0;i<numplayers;i++){
8326                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8327                                                                                                                 player[k].victim=&player[i];
8328                                                                                                                 player[k].hasvictim=1;
8329                                                                                                         }
8330                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8331                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8332                                                                                                                         player[k].victim=&player[i];
8333                                                                                                                 }
8334                                                                                                 }
8335                                                                                         }
8336                                                                                         if(player[k].aitype==playercontrolled)
8337                                                                                                 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)){
8338                                                                                                         oldattackkey=1;
8339                                                                                                         player[k].targetanimation=rabbitkickanim;
8340                                                                                                         player[k].targetframe=0;
8341                                                                                                         player[k].target=0;
8342                                                                                                 }
8343                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8344                                                                                                         numattacks++;
8345                                                                                                         bool armedstaff=0;
8346                                                                                                         if(player[k].weaponactive!=-1){
8347                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8348                                                                                                         }
8349                                                                                                         bool armedsword=0;
8350                                                                                                         if(player[k].weaponactive!=-1){
8351                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8352                                                                                                         }
8353                                                                                                         bool armedknife=0;
8354                                                                                                         if(player[k].weaponactive!=-1){
8355                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8356                                                                                                         }
8357                                                                                                         if(armedstaff)numstaffattack++;
8358                                                                                                         else if(armedsword)numswordattack++;
8359                                                                                                         else if(armedknife)numknifeattack++;
8360                                                                                                         else numunarmedattack++;
8361                                                                                                 }
8362                                                                 }
8363                                                         }
8364                                                 }
8365
8366                                                 //Collisions
8367                                                 static float collisionradius;
8368                                                 if(numplayers>1)
8369                                                         for(k=0;k<numplayers;k++){
8370                                                                 for(i=k;i<numplayers;i++){
8371                                                                         if(i==k)i++;
8372                                                                         if(i<numplayers)
8373                                                                                 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))
8374                                                                                         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))
8375                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8376                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8377                                                                                                                 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)
8378                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8379                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8380                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8381                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8382                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8383                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8384                                                                                                                                                                         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)){
8385                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8386                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8387                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8388                                                                                                                                                                                 }
8389                                                                                                                                                                         }
8390
8391                                                                                                                                                                         tempcoords1=player[i].coords;
8392                                                                                                                                                                         tempcoords2=player[k].coords;
8393                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8394                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8395                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8396                                                                                                                                                                         if(player[0].hasvictim)
8397                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8398                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8399                                                                                                                                                                                 if(k==0)
8400                                                                                                                                                                                         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)){
8401                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8402                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8403                                                                                                                                                                                                 player[i].skeleton.free=0;
8404                                                                                                                                                                                                 player[i].rotation=0;
8405                                                                                                                                                                                                 player[i].RagDoll(0);
8406                                                                                                                                                                                                 player[i].DoDamage(20);
8407                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8408                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8409                                                                                                                                                                                                 player[k].lastcollide=1;
8410                                                                                                                                                                                         }
8411                                                                                                                                                                                         if(i==0)
8412                                                                                                                                                                                                 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)){
8413                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8414                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8415                                                                                                                                                                                                         player[k].skeleton.free=0;
8416                                                                                                                                                                                                         player[k].rotation=0;
8417                                                                                                                                                                                                         player[k].RagDoll(0);
8418                                                                                                                                                                                                         player[k].DoDamage(20);
8419                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8420                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8421                                                                                                                                                                                                         player[i].lastcollide=1;
8422                                                                                                                                                                                                 }
8423
8424                                                                                                                                                                                                 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)){
8425                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8426                                                                                                                                                                                                         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))
8427                                                                                                                                                                                                                 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))){
8428                                                                                                                                                                                                                         //If hit by body
8429                                                                                                                                                                                                                         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)){
8430                                                                                                                                                                                                                                 static float gLoc[3];
8431                                                                                                                                                                                                                                 static float vel[3];
8432                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8433                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8434                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8435                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8436                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8437                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8438                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8439                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8440                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8441                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8442                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8443                                                                                                                                                                                                                                 }
8444                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8445                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8446
8447                                                                                                                                                                                                                                 player[i].RagDoll(0);
8448                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8449                                                                                                                                                                                                                                         bonus=aimbonus;
8450                                                                                                                                                                                                                                         bonustime=0;
8451                                                                                                                                                                                                                                         bonusvalue=150;
8452                                                                                                                                                                                                                                 }
8453                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8454                                                                                                                                                                                                                                 player[k].RagDoll(0);
8455                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8456                                                                                                                                                                                                                                         bonus=aimbonus;
8457                                                                                                                                                                                                                                         bonustime=0;
8458                                                                                                                                                                                                                                         bonusvalue=150;
8459                                                                                                                                                                                                                                 }
8460                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8461
8462                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8463                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8464                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8465                                                                                                                                                                                                                                 }
8466                                                                                                                                                                                                                                 //}
8467                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8468                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8469                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8470                                                                                                                                                                                                                                 }
8471                                                                                                                                                                                                                                 //}
8472
8473                                                                                                                                                                                                                         }
8474                                                                                                                                                                                                                 }
8475                                                                                                                                                                                                                 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)){
8476                                                                                                                                                                                                                         //If bumped
8477                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8478                                                                                                                                                                                                                                 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)){
8479                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8480                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8481                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8482                                                                                                                                                                                                                                         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);
8483                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8484                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8485                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8486                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8487                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8488                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8489                                                                                                                                                                                                                                                                 player[k].target=0;
8490                                                                                                                                                                                                                                                         }
8491                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8492                                                                                                                                                                                                                                                         {
8493                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8494                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8495                                                                                                                                                                                                                                                                 player[k].target=0;
8496                                                                                                                                                                                                                                                         }
8497                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8498                                                                                                                                                                                                                                                 }
8499                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8500                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8501                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8502                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8503                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8504                                                                                                                                                                                                                                                                         player[i].target=0;
8505                                                                                                                                                                                                                                                                 }
8506                                                                                                                                                                                                                                                                 else
8507                                                                                                                                                                                                                                                                 {
8508                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8509                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8510                                                                                                                                                                                                                                                                         player[i].target=0;
8511                                                                                                                                                                                                                                                                 }
8512                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8513                                                                                                                                                                                                                                                         }
8514                                                                                                                                                                                                                                 }
8515                                                                                                                                                                                                                                 if(hostile){
8516                                                                                                                                                                                                                                         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){
8517                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8518                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8519                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8520                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8521                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8522                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8523                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8524                                                                                                                                                                                                                                                 if(k==0){
8525                                                                                                                                                                                                                                                         bonus=AboveBonus;
8526                                                                                                                                                                                                                                                         bonustime=0;
8527                                                                                                                                                                                                                                                         bonusvalue=50;
8528                                                                                                                                                                                                                                                 }
8529                                                                                                                                                                                                                                         }
8530                                                                                                                                                                                                                                         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){
8531                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8532                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8533                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8534                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8535                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8536                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8537                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8538                                                                                                                                                                                                                                                 if(i==0){
8539                                                                                                                                                                                                                                                         bonus=AboveBonus;
8540                                                                                                                                                                                                                                                         bonustime=0;
8541                                                                                                                                                                                                                                                         bonusvalue=50;
8542                                                                                                                                                                                                                                                 }
8543                                                                                                                                                                                                                                         }
8544                                                                                                                                                                                                                                 }
8545                                                                                                                                                                                                                         }
8546                                                                                                                                                                                                                 }
8547                                                                                                                                                                                                 }
8548                                                                                                                                                                                                 player[i].CheckKick();
8549                                                                                                                                                                                                 player[k].CheckKick();
8550                                                                                                                                                                         }
8551                                                                                                                                                                 }
8552                                                                 }
8553                                                         }
8554
8555                                                         for(k=0;k<numplayers;k++){
8556                                                                 for(i=k;i<numplayers;i++){
8557                                                                         if(i==k)i++;
8558                                                                         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))){
8559                                                                                 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)){
8560                                                                                         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)){
8561                                                                                                 player[i].victim=&player[k];
8562                                                                                                 player[i].targetanimation=jumpreversedanim;
8563                                                                                                 player[i].currentanimation=jumpreversedanim;
8564                                                                                                 player[k].currentanimation=jumpreversalanim;
8565                                                                                                 player[k].targetanimation=jumpreversalanim;
8566                                                                                                 player[i].targettilt2=0;
8567                                                                                                 player[i].currentframe=0;
8568                                                                                                 player[i].targetframe=1;
8569                                                                                                 player[k].currentframe=0;
8570                                                                                                 player[k].targetframe=1;
8571                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8572                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8573                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8574                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8575                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8576                                                                                                         player[k].currentframe=1;
8577                                                                                                         player[k].targetframe=2;
8578                                                                                                         player[i].currentframe=1;
8579                                                                                                         player[i].targetframe=2;
8580                                                                                                 }
8581                                                                                                 player[k].targettilt2=0;
8582                                                                                                 player[i].target=0;
8583                                                                                                 player[i].velocity=0;
8584                                                                                                 player[k].velocity=0;
8585                                                                                                 player[k].oldcoords=player[k].coords;
8586                                                                                                 player[i].coords=player[k].coords;
8587                                                                                                 player[k].targetrotation=player[i].targetrotation;
8588                                                                                                 player[k].rotation=player[i].targetrotation;
8589                                                                                                 player[k].victim=&player[i];
8590                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8591                                                                                         }
8592                                                                                         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)){
8593                                                                                                 player[k].victim=&player[i];
8594                                                                                                 player[k].targetanimation=jumpreversedanim;
8595                                                                                                 player[k].currentanimation=jumpreversedanim;
8596                                                                                                 player[i].currentanimation=jumpreversalanim;
8597                                                                                                 player[i].targetanimation=jumpreversalanim;
8598                                                                                                 player[k].targettilt2=0;
8599                                                                                                 player[i].targettilt2=0;
8600                                                                                                 player[k].currentframe=0;
8601                                                                                                 player[k].targetframe=1;
8602                                                                                                 player[i].currentframe=0;
8603                                                                                                 player[i].targetframe=1;
8604                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8605                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8606                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8607                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8608                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8609                                                                                                         player[k].currentframe=1;
8610                                                                                                         player[k].targetframe=2;
8611                                                                                                         player[i].currentframe=1;
8612                                                                                                         player[i].targetframe=2;
8613                                                                                                 }
8614                                                                                                 player[k].target=0;
8615                                                                                                 player[k].velocity=0;
8616                                                                                                 player[i].velocity=0;
8617                                                                                                 player[i].oldcoords=player[i].coords;
8618                                                                                                 player[k].coords=player[i].coords;
8619                                                                                                 player[i].targetrotation=player[k].targetrotation;
8620                                                                                                 player[i].rotation=player[k].targetrotation;
8621                                                                                                 player[i].victim=&player[k];
8622                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8623                                                                                         }
8624                                                                                 }
8625                                                                         }
8626                                                                 }
8627                                                         }
8628
8629                                                         for(k=0;k<numplayers;k++)
8630                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8631
8632
8633                                                         //pile
8634                                                         /*
8635                                                         XYZ tempdiff;
8636                                                         XYZ tempoldpos;
8637                                                         XYZ temp1,temp2;
8638                                                         bool isgood;
8639                                                         static float checkdelay;
8640                                                         checkdelay-=multiplier;
8641                                                         int m;
8642                                                         static bool checkedcoll[maxplayers][maxplayers];
8643                                                         static bool above[maxplayers];
8644
8645                                                         for(i=0;i<maxplayers;i++){
8646                                                         for(j=0;j<maxplayers;j++){
8647                                                         checkedcoll[i][j]=0;
8648                                                         }
8649                                                         }
8650
8651                                                         if(numplayers>1&&checkdelay<=0){
8652                                                         checkdelay=.015;
8653                                                         for(k=0;k<numplayers;k++){
8654                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8655
8656                                                         for(i=k;i<numplayers;i++){
8657                                                         if(i==k)i++;
8658                                                         if(i<numplayers)
8659                                                         if(!checkedcoll[i][k]){
8660                                                         checkedcoll[i][k]=1;
8661                                                         checkedcoll[k][i]=1;
8662                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8663                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8664                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8665                                                         if(player[i].coords.y>player[k].coords.y-3)
8666                                                         if(player[i].coords.y<player[k].coords.y+3)
8667                                                         if(player[i].coords.x>player[k].coords.x-3)
8668                                                         if(player[i].coords.x<player[k].coords.x+3)
8669                                                         if(player[i].coords.z>player[k].coords.z-3)
8670                                                         if(player[i].coords.z<player[k].coords.z+3)
8671                                                         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)){
8672                                                         int stuck,moving;
8673                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
8674                                                         stuck=i;
8675                                                         moving=k;
8676                                                         }
8677                                                         else
8678                                                         {
8679                                                         moving=i;
8680                                                         stuck=k;
8681                                                         }
8682                                                         isgood=1;
8683
8684                                                         if(isgood){
8685                                                         above[moving]=stuck;
8686                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
8687                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
8688                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
8689                                                         {
8690                                                         player[moving].skeleton.joints[l].position.y+=.003;
8691                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
8692
8693                                                         }
8694                                                         }
8695                                                         }
8696                                                         }
8697                                                         }
8698                                                         }
8699                                                         }
8700                                                         }
8701                                                         }
8702
8703                                                         */
8704
8705                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
8706                                                                 texturesizetogglekeydown=0;
8707                                                         }
8708
8709                                                         for(k=0;k<numplayers;k++){
8710                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8711                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
8712                                                                                 player[k].DoDamage(1000);
8713                                                                         }
8714                                                                 }
8715                                                         }
8716
8717                                                         static bool respawnkeydown;
8718                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
8719                                                                 targetlevel=whichlevel;
8720                                                                 loading=1;
8721                                                                 leveltime=5;
8722                                                         }
8723                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
8724                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
8725
8726
8727
8728
8729                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
8730                                                                 targetlevel++;
8731                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
8732                                                                 loading=1;
8733                                                                 leveltime=5;
8734                                                                 slomotogglekeydown=1;
8735                                                         }
8736
8737                                                         /*
8738                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
8739                                                         //Respawn
8740                                                         OPENAL_SetPaused(channels[whooshsound], true);
8741                                                         changedelay=0;
8742                                                         for(k=0;k<numplayers;k++){
8743                                                         player[k].dead=0;
8744                                                         player[k].damage=0;
8745                                                         player[k].permanentdamage=0;
8746                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
8747                                                         player[k].aitype=passivetype;
8748                                                         }
8749                                                         player[0].aitype=playercontrolled;
8750                                                         }
8751                                                         */
8752
8753                                                         static bool movekey;
8754                                                         static bool connected;
8755                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
8756                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
8757                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
8758                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
8759                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
8760                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
8761
8762                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
8763
8764                 for(int i=0;i<numplayers;i++){
8765                                                                 if(!player[i].skeleton.free){
8766                                                                         oldtargetrotation=player[i].targetrotation;
8767                                                                         if(i==0&&indialogue==-1){
8768                                                                                 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){
8769                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
8770                                                                                         if(cameramode)player[0].targetrotation=0;
8771                                                                                 }
8772
8773                                                                                 facing=0;
8774                                                                                 facing.z=-1;
8775
8776                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8777                                                                                 if(cameramode){facing=flatfacing;}
8778                                                                                 else{
8779                                                                                         facing=DoRotation(facing,-rotation2,0,0);
8780                                                                                         facing=DoRotation(facing,0,0-rotation,0);
8781                                                                                 }
8782
8783                                                                                 player[0].lookrotation=-rotation;
8784
8785                                                                                 player[i].targetheadrotation=rotation;
8786                                                                                 player[i].targetheadrotation2=rotation2;
8787                                                                         }
8788                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
8789                                                                                 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){
8790                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
8791                                                                                 }
8792
8793                                                                                 facing=0;
8794                                                                                 facing.z=-1;
8795
8796                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
8797
8798                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
8799                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
8800
8801                                                                                 player[i].targetheadrotation=player[i].lookrotation;
8802                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
8803                                                                         }
8804                                                                         if(indialogue!=-1){
8805                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
8806                                                                                 Normalise(&rotatetarget);
8807                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
8808                                                                                 player[i].targetheadrotation*=360/6.28;
8809                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
8810
8811                                                                                 player[i].targetheadrotation*=-1;
8812                                                                                 player[i].targetheadrotation+=180;
8813                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
8814                                                                         }
8815
8816                                                                         bool pause;
8817
8818                                                                         if(leveltime<.5)
8819                                                                                 numenvsounds=0;
8820
8821                                                                         player[i].avoidsomething=0;
8822
8823                                                                         for(j=0;j<objects.numobjects;j++){
8824                                                                                 if(objects.onfire[j]){
8825                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
8826                                                                                         {
8827                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
8828                                                                                                         player[i].collided=0;
8829                                                                                                         player[i].avoidcollided=1;
8830                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8831                                                                                                                 player[i].avoidwhere=objects.position[j];
8832                                                                                                 }
8833                                                                                         }
8834                                                                                 }
8835                                                                         }
8836
8837                                                                         //Add avoidwhere to players
8838
8839                                                                         for(j=0;j<numplayers;j++){
8840                                                                                 if(player[j].onfire){
8841                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
8842                                                                                         {
8843                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
8844                                                                                                         player[i].collided=0;
8845                                                                                                         player[i].avoidcollided=1;
8846                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
8847                                                                                                                 player[i].avoidwhere=objects.position[j];
8848                                                                                                 }
8849                                                                                         }
8850                                                                                 }
8851                                                                         }
8852
8853                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
8854                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
8855                                                                                 player[i].jumpclimb=0;
8856                                                                                 //AI
8857                                                                                 if(editorenabled)player[i].stunned=1;
8858
8859                                                                                 player[i].pause=0;
8860                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
8861                                                                                 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;
8862
8863                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
8864                                                                                 player[i].forwardkeydown=0;
8865                                                                                 player[i].leftkeydown=0;
8866                                                                                 player[i].backkeydown=0;
8867                                                                                 player[i].rightkeydown=0;
8868                                                                                 player[i].crouchkeydown=0;
8869                                                                                 player[i].attackkeydown=0;
8870                                                                                 player[i].jumpkeydown=0;
8871                                                                                 player[i].throwkeydown=0;
8872                                                                                 }*/
8873
8874                                                                                 if(player[i].aitype==pathfindtype){
8875                                                                                         if(player[i].finalpathfindpoint==-1){
8876                                                                                                 float closestdistance;
8877                                                                                                 float tempdist;
8878                                                                                                 int closest;
8879                                                                                                 XYZ colpoint;
8880                                                                                                 closest=-1;
8881                                                                                                 closestdistance=-1;
8882                                                                                                 for(j=0;j<numpathpoints;j++){
8883                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
8884                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
8885                                                                                                                 closest=j;
8886                                                                                                                 player[i].finaltarget=pathpoint[j];
8887                                                                                                         }
8888                                                                                                 }
8889                                                                                                 player[i].finalpathfindpoint=closest;
8890                                                                                                 for(j=0;j<numpathpoints;j++){
8891                                                                                                         if(numpathpointconnect[j])
8892                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8893                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8894                                                                                                                         if(tempdist*tempdist<closestdistance){
8895                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8896                                                                                                                                         closestdistance=tempdist*tempdist;
8897                                                                                                                                         closest=j;
8898                                                                                                                                         player[i].finaltarget=colpoint;
8899                                                                                                                                 }
8900                                                                                                                         }
8901                                                                                                                 }
8902                                                                                                 }
8903                                                                                                 player[i].finalpathfindpoint=closest;
8904
8905                                                                                         }
8906                                                                                         if(player[i].targetpathfindpoint==-1){
8907                                                                                                 float closestdistance;
8908                                                                                                 float tempdist;
8909                                                                                                 int closest;
8910                                                                                                 XYZ colpoint;
8911                                                                                                 closest=-1;
8912                                                                                                 closestdistance=-1;
8913                                                                                                 if(player[i].lastpathfindpoint==-1){
8914                                                                                                         for(j=0;j<numpathpoints;j++){
8915                                                                                                                 if(j!=player[i].lastpathfindpoint)
8916                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
8917                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
8918                                                                                                                                 closest=j;
8919                                                                                                                         }
8920                                                                                                         }
8921                                                                                                         player[i].targetpathfindpoint=closest;
8922                                                                                                         for(j=0;j<numpathpoints;j++){
8923                                                                                                                 if(j!=player[i].lastpathfindpoint)
8924                                                                                                                         if(numpathpointconnect[j])
8925                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8926                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
8927                                                                                                                                         if(tempdist*tempdist<closestdistance){
8928                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
8929                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
8930                                                                                                                                                         closestdistance=tempdist*tempdist;
8931                                                                                                                                                         closest=j;
8932                                                                                                                                                         //}
8933                                                                                                                                                 }
8934                                                                                                                                         }
8935                                                                                                                                 }
8936                                                                                                         }
8937                                                                                                         player[i].targetpathfindpoint=closest;
8938                                                                                                 }
8939                                                                                                 else
8940                                                                                                 {
8941                                                                                                         for(j=0;j<numpathpoints;j++){
8942                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
8943                                                                                                                 {
8944                                                                                                                         connected=0;
8945                                                                                                                         if(numpathpointconnect[j])
8946                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
8947                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
8948                                                                                                                                 }
8949                                                                                                                                 if(!connected)
8950                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
8951                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
8952                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
8953                                                                                                                                                 }
8954                                                                                                                                                 if(connected){
8955                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
8956                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
8957                                                                                                                                                                 closestdistance=tempdist;
8958                                                                                                                                                                 closest=j;
8959                                                                                                                                                         }
8960                                                                                                                                                 }
8961                                                                                                                 }
8962                                                                                                         }
8963                                                                                                         player[i].targetpathfindpoint=closest;
8964                                                                                                 }
8965                                                                                         }
8966                                                                                         player[i].losupdatedelay-=multiplier;
8967
8968                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
8969                                                                                         Normalise(&rotatetarget);
8970                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
8971                                                                                         player[i].targetrotation*=360/6.28;
8972                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
8973                                                                                         player[i].lookrotation=player[i].targetrotation;
8974                                                                                         //player[i].aiupdatedelay=.05;
8975
8976                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
8977                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8978                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8979                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8980                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
8981                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
8982                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
8983                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
8984                                                                                                 player[i].targetpathfindpoint=-1;
8985                                                                                         }
8986                                                                                         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){
8987                                                                                                 player[i].aitype=passivetype;
8988                                                                                         }
8989
8990                                                                                         player[i].forwardkeydown=1;
8991                                                                                         player[i].leftkeydown=0;
8992                                                                                         player[i].backkeydown=0;
8993                                                                                         player[i].rightkeydown=0;
8994                                                                                         player[i].crouchkeydown=0;
8995                                                                                         player[i].attackkeydown=0;
8996                                                                                         player[i].throwkeydown=0;
8997
8998                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
8999
9000                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9001                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9002
9003                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9004                                                                                                 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))
9005                                                                                                         player[i].aitype=attacktypecutoff;
9006                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9007                                                                                                         player[i].aitype=attacktypecutoff;
9008
9009                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9010                                                                                                         player[i].losupdatedelay=.2;
9011                                                                                                         for(j=0;j<numplayers;j++){
9012                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9013                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9014                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9015                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9016                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9017                                                                                                                                                         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)){
9018                                                                                                                                                                 player[i].aitype=searchtype;
9019                                                                                                                                                                 player[i].lastchecktime=12;
9020                                                                                                                                                                 player[i].lastseen=player[j].coords;
9021                                                                                                                                                                 player[i].lastseentime=12;
9022                                                                                                                                                         }
9023                                                                                                                 }
9024                                                                                                         }
9025                                                                                                 }
9026                                                                                         }
9027                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9028                                                                                                 if(player[i].creature!=wolftype){
9029                                                                                                         player[i].stunned=.6;
9030                                                                                                         player[i].surprised=.6;
9031                                                                                                 }
9032                                                                                         }
9033                                                                                 }
9034
9035                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9036                                                                                         player[i].howactive=typeactive;
9037                                                                                 }
9038
9039                                                                                 if(player[i].aitype==passivetype){
9040                                                                                         player[i].aiupdatedelay-=multiplier;
9041                                                                                         player[i].losupdatedelay-=multiplier;
9042                                                                                         player[i].lastseentime+=multiplier;
9043                                                                                         player[i].pausetime-=multiplier;
9044                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9045
9046                                                                                         if(player[i].aiupdatedelay<0){
9047                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9048                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9049                                                                                                         Normalise(&rotatetarget);
9050                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9051                                                                                                         player[i].targetrotation*=360/6.28;
9052                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9053                                                                                                         player[i].lookrotation=player[i].targetrotation;
9054                                                                                                         player[i].aiupdatedelay=.05;
9055
9056                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9057                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9058                                                                                                                 player[i].waypoint++;
9059                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9060
9061                                                                                                         }
9062                                                                                                 }
9063
9064                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9065                                                                                                 else player[i].forwardkeydown=0;
9066                                                                                                 player[i].leftkeydown=0;
9067                                                                                                 player[i].backkeydown=0;
9068                                                                                                 player[i].rightkeydown=0;
9069                                                                                                 player[i].crouchkeydown=0;
9070                                                                                                 player[i].attackkeydown=0;
9071                                                                                                 player[i].throwkeydown=0;
9072
9073                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9074                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9075                                                                                                         else{
9076                                                                                                                 XYZ leftpos,rightpos;
9077                                                                                                                 float leftdist,rightdist;
9078                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9079                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9080                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9081                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9082                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9083                                                                                                                 else player[i].targetrotation-=90;
9084                                                                                                         }
9085                                                                                                 }
9086                                                                                         }
9087                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9088                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9089
9090
9091                                                                                         if(!editorenabled){
9092                                                                                                 if(player[i].howactive<typesleeping)
9093                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9094                                                                                                                 for(j=0;j<numenvsounds;j++){
9095                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9096                                                                                                                                 player[i].aitype=attacktypecutoff;
9097                                                                                                                         }
9098                                                                                                                 }
9099
9100                                                                                                                 if(player[i].howactive==typesleeping)
9101                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9102                                                                                                                                 for(j=0;j<numenvsounds;j++){
9103                                                                                                                                         if(envsoundvol[j]>14)
9104                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9105                                                                                                                                                         player[i].aitype=attacktypecutoff;
9106                                                                                                                                                 }
9107                                                                                                                                 }
9108
9109                                                                                                                                 if(player[i].aitype!=passivetype){
9110                                                                                                                                         if(player[i].howactive==typesleeping){
9111                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9112                                                                                                                                                 player[i].targetframe=0;
9113                                                                                                                                                 player[i].target=0;
9114                                                                                                                                         }
9115
9116                                                                                                                                         player[i].howactive=typeactive;
9117                                                                                                                                 }
9118                                                                                         }
9119
9120                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9121                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9122                                                                                                         player[i].aitype=attacktypecutoff;
9123                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9124                                                                                                         player[i].aitype=attacktypecutoff;
9125
9126                                                                                                 if(player[i].creature==wolftype){
9127                                                                                                         XYZ windsmell;
9128                                                                                                         float smelldistance;
9129                                                                                                         smelldistance=50;
9130                                                                                                         for(j=0;j<numplayers;j++){
9131                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9132                                                                                                                         if(j==0&&player[j].num_weapons>0){
9133                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9134                                                                                                                                 if(player[j].num_weapons==2)
9135                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9136                                                                                                                         }
9137                                                                                                                         if(j!=0){
9138                                                                                                                                 smelldistance=100;
9139                                                                                                                         }
9140                                                                                                                         windsmell=windvector;
9141                                                                                                                         Normalise(&windsmell);
9142                                                                                                                         windsmell=windsmell*2+player[j].coords;
9143                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9144                                                                                                                                 player[i].aitype=attacktypecutoff;
9145                                                                                                                 }
9146                                                                                                         }
9147                                                                                                 }
9148
9149                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9150                                                                                                         player[i].losupdatedelay=.2;
9151                                                                                                         for(j=0;j<numplayers;j++){
9152                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9153                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9154                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9155                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9156                                                                                                                                                 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)){
9157                                                                                                                                                         player[i].lastseentime-=.2;
9158                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9159                                                                                                                                                         else player[i].lastseentime-=.6;
9160                                                                                                                                                 }
9161                                                                                                                                                 if(player[i].lastseentime<=0){
9162                                                                                                                                                         player[i].aitype=searchtype;
9163                                                                                                                                                         player[i].lastchecktime=12;
9164                                                                                                                                                         player[i].lastseen=player[j].coords;
9165                                                                                                                                                         player[i].lastseentime=12;
9166                                                                                                                                                 }
9167                                                                                                                 }
9168                                                                                                         }
9169                                                                                                 }
9170                                                                                         }
9171                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9172                                                                                                 if(player[i].creature!=wolftype){
9173                                                                                                         player[i].stunned=.6;
9174                                                                                                         player[i].surprised=.6;
9175                                                                                                 }
9176                                                                                                 if(player[i].creature==wolftype){
9177                                                                                                         player[i].stunned=.47;
9178                                                                                                         player[i].surprised=.47;
9179                                                                                                 }
9180                                                                                                 numseen++;
9181                                                                                         }
9182                                                                                 }
9183
9184                                                                                 if(player[i].aitype==searchtype){
9185                                                                                         player[i].aiupdatedelay-=multiplier;
9186                                                                                         player[i].losupdatedelay-=multiplier;
9187                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9188                                                                                         player[i].lastchecktime-=multiplier;
9189
9190                                                                                         if(player[i].isRun()&&!player[i].onground){
9191                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9192                                                                                                         test2=player[i].coords+player[i].facing;
9193                                                                                                         test2.y+=5;
9194                                                                                                         test=player[i].coords+player[i].facing;
9195                                                                                                         test.y-=10;
9196                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9197                                                                                                         if(j==-1)j=checkcollide(test2,test);
9198                                                                                                         if(j==-1){
9199                                                                                                                 player[i].velocity=0;
9200                                                                                                                 player[i].targetanimation=player[i].getStop();
9201                                                                                                                 player[i].targetframe=0;
9202                                                                                                                 player[i].target=0;
9203                                                                                                                 player[i].targetrotation+=180;
9204                                                                                                                 player[i].stunned=.5;
9205                                                                                                                 //player[i].aitype=passivetype;
9206                                                                                                                 player[i].aitype=pathfindtype;
9207                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9208                                                                                                                 player[i].finalpathfindpoint=-1;
9209                                                                                                                 player[i].targetpathfindpoint=-1;
9210                                                                                                                 player[i].lastpathfindpoint=-1;
9211                                                                                                                 player[i].lastpathfindpoint2=-1;
9212                                                                                                                 player[i].lastpathfindpoint3=-1;
9213                                                                                                                 player[i].lastpathfindpoint4=-1;
9214                                                                                                         }
9215                                                                                                         else player[i].laststanding=j;
9216                                                                                                 }
9217                                                                                         }
9218                                                                                         if(player[i].aiupdatedelay<0){
9219                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9220                                                                                                 Normalise(&rotatetarget);
9221                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9222                                                                                                 player[i].targetrotation*=360/6.28;
9223                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9224                                                                                                 player[i].lookrotation=player[i].targetrotation;
9225                                                                                                 player[i].aiupdatedelay=.05;
9226                                                                                                 player[i].forwardkeydown=1;
9227
9228                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9229                                                                                                         player[i].forwardkeydown=0;
9230                                                                                                         player[i].aiupdatedelay=1;
9231                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9232                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9233                                                                                                         player[i].lastchecktime=3;
9234                                                                                                 }
9235
9236                                                                                                 player[i].leftkeydown=0;
9237                                                                                                 player[i].backkeydown=0;
9238                                                                                                 player[i].rightkeydown=0;
9239                                                                                                 player[i].crouchkeydown=0;
9240                                                                                                 player[i].attackkeydown=0;
9241                                                                                                 player[i].throwkeydown=0;
9242
9243                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9244                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9245                                                                                                         else{
9246                                                                                                                 XYZ leftpos,rightpos;
9247                                                                                                                 float leftdist,rightdist;
9248                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9249                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9250                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9251                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9252                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9253                                                                                                                 else player[i].targetrotation-=90;
9254                                                                                                         }
9255                                                                                                 }
9256                                                                                         }
9257                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9258                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9259
9260                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9261                                                                                                 for(j=0;j<numenvsounds;j++){
9262                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9263                                                                                                                 player[i].aitype=attacktypecutoff;
9264                                                                                                         }
9265                                                                                                 }
9266
9267                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9268                                                                                                         player[i].losupdatedelay=.2;
9269                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9270                                                                                                         {player[i].aitype=attacktypecutoff;
9271                                                                                                         player[i].lastseentime=1;}
9272                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9273                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9274                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9275                                                                                                                                 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)){
9276                                                                                                                                         player[i].aitype=attacktypecutoff;
9277                                                                                                                                         player[i].lastseentime=1;
9278                                                                                                                                 }
9279                                                                                                 }
9280                                                                                                 if(player[i].lastseentime<0){
9281                                                                                                         //player[i].aitype=passivetype;
9282                                                                                                         numescaped++;
9283                                                                                                         player[i].aitype=pathfindtype;
9284                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9285                                                                                                         player[i].finalpathfindpoint=-1;
9286                                                                                                         player[i].targetpathfindpoint=-1;
9287                                                                                                         player[i].lastpathfindpoint=-1;
9288                                                                                                         player[i].lastpathfindpoint2=-1;
9289                                                                                                         player[i].lastpathfindpoint3=-1;
9290                                                                                                         player[i].lastpathfindpoint4=-1;
9291                                                                                                 }
9292                                                                                 }
9293
9294                                                                                 if(player[i].aitype!=gethelptype){
9295                                                                                         player[i].runninghowlong=0;
9296                                                                                 }
9297
9298                                                                                 if(player[i].aitype==gethelptype){
9299                                                                                         player[i].runninghowlong+=multiplier;
9300                                                                                         player[i].aiupdatedelay-=multiplier;
9301
9302                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9303                                                                                                 player[i].aiupdatedelay=.2;
9304
9305                                                                                                 int closest;
9306                                                                                                 float closestdist;
9307                                                                                                 closest=-1;
9308                                                                                                 closestdist=-1;
9309                                                                                                 float distance;
9310
9311                                                                                                 if(!player[i].ally){
9312                                                                                                         for(j=0;j<numplayers;j++){
9313                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9314                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9315                                                                                                                         if(closestdist==-1||distance<closestdist){
9316                                                                                                                                 closestdist=distance;
9317                                                                                                                                 closest=j;
9318                                                                                                                         }
9319                                                                                                                         closest=j;
9320                                                                                                                 }
9321                                                                                                         }
9322                                                                                                         if(closest!=-1)player[i].ally=closest;
9323                                                                                                         else player[i].ally=0;
9324                                                                                                         player[i].lastseen=player[0].coords;
9325                                                                                                         player[i].lastseentime=12;
9326                                                                                                 }
9327
9328
9329                                                                                                 player[i].lastchecktime=12;
9330                                                                                                 //player[i].lastseentime-=.5;
9331
9332                                                                                                 facing=player[i].coords;
9333                                                                                                 flatfacing=player[player[i].ally].coords;
9334                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9335                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9336                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9337                                                                                                         player[i].lastseentime-=.1;
9338
9339                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9340                                                                                                         player[i].aitype=searchtype;
9341                                                                                                         player[i].lastseentime=12;
9342                                                                                                 }
9343
9344                                                                                                 if(player[i].ally>0){
9345                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9346                                                                                                         Normalise(&rotatetarget);
9347                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9348                                                                                                         player[i].targetrotation*=360/6.28;
9349                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9350                                                                                                         player[i].lookrotation=player[i].targetrotation;
9351                                                                                                         player[i].aiupdatedelay=.05;
9352                                                                                                         player[i].forwardkeydown=1;
9353
9354                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9355                                                                                                                 player[i].aitype=searchtype;
9356                                                                                                                 player[i].lastseentime=12;
9357                                                                                                                 player[player[i].ally].aitype=searchtype;
9358                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9359                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9360                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9361                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9362                                                                                                                 }
9363                                                                                                         }
9364
9365                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9366                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9367                                                                                                                 else{
9368                                                                                                                         XYZ leftpos,rightpos;
9369                                                                                                                         float leftdist,rightdist;
9370                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9371                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9372                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9373                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9374                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9375                                                                                                                         else player[i].targetrotation-=90;
9376                                                                                                                 }
9377                                                                                                         }
9378                                                                                                 }
9379
9380                                                                                                 player[i].leftkeydown=0;
9381                                                                                                 player[i].backkeydown=0;
9382                                                                                                 player[i].rightkeydown=0;
9383                                                                                                 player[i].crouchkeydown=0;
9384                                                                                                 player[i].attackkeydown=0;
9385                                                                                         }
9386                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9387                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9388                                                                                 }
9389
9390                                                                                 if(player[i].aitype==getweapontype){
9391                                                                                         player[i].aiupdatedelay-=multiplier;
9392                                                                                         player[i].lastchecktime-=multiplier;
9393
9394                                                                                         if(player[i].aiupdatedelay<0){
9395                                                                                                 player[i].aiupdatedelay=.2;
9396
9397                                                                                                 int closest;
9398                                                                                                 float closestdist;
9399                                                                                                 closest=-1;
9400                                                                                                 closestdist=-1;
9401                                                                                                 float distance;
9402
9403                                                                                                 if(player[i].ally<0){
9404                                                                                                         for(j=0;j<weapons.numweapons;j++){
9405                                                                                                                 if(weapons.owner[j]==-1){
9406                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9407                                                                                                                         if(closestdist==-1||distance<closestdist){
9408                                                                                                                                 closestdist=distance;
9409                                                                                                                                 closest=j;
9410                                                                                                                         }
9411                                                                                                                         closest=j;
9412                                                                                                                 }
9413                                                                                                         }
9414                                                                                                         if(closest!=-1)player[i].ally=closest;
9415                                                                                                         else player[i].ally=-1;
9416                                                                                                 }
9417
9418                                                                                                 player[i].lastseentime=12;
9419
9420                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9421                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9422                                                                                                                 player[i].aitype=attacktypecutoff;
9423                                                                                                                 player[i].lastseentime=1;
9424                                                                                                         }
9425                                                                                                         if(!player[0].dead)
9426                                                                                                                 if(player[i].ally>=0){
9427                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9428                                                                                                                                 player[i].aitype=attacktypecutoff;
9429                                                                                                                                 player[i].lastseentime=1;
9430                                                                                                                         }
9431                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9432                                                                                                                         Normalise(&rotatetarget);
9433                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9434                                                                                                                         player[i].targetrotation*=360/6.28;
9435                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9436                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9437                                                                                                                         player[i].aiupdatedelay=.05;
9438                                                                                                                         player[i].forwardkeydown=1;
9439
9440
9441                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9442                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9443                                                                                                                                 else{
9444                                                                                                                                         XYZ leftpos,rightpos;
9445                                                                                                                                         float leftdist,rightdist;
9446                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9447                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9448                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9449                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9450                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9451                                                                                                                                         else player[i].targetrotation-=90;
9452                                                                                                                                 }
9453                                                                                                                         }
9454                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9455                                                                                                                         if(abs(Random()%6)){
9456                                                                                                                         player[i].crouchkeydown=1;
9457                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9458                                                                                                                         if(player[i].isRun()){
9459                                                                                                                         player[i].targetframe=0;
9460                                                                                                                         player[i].target=0;
9461                                                                                                                         player[i].targetanimation=sneakanim;
9462                                                                                                                         }
9463                                                                                                                         }
9464                                                                                                                         else player[i].forwardkeydown=0;
9465                                                                                                                         }
9466                                                                                                                         else player[i].crouchkeydown=0;
9467                                                                                                                         }
9468                                                                                                                         else player[i].crouchkeydown=0;*/
9469                                                                                                                 }
9470
9471                                                                                                                 player[i].leftkeydown=0;
9472                                                                                                                 player[i].backkeydown=0;
9473                                                                                                                 player[i].rightkeydown=0;
9474                                                                                                                 player[i].attackkeydown=0;
9475                                                                                                                 player[i].throwkeydown=1;
9476                                                                                                                 player[i].crouchkeydown=0;
9477                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9478                                                                                                                 player[i].drawkeydown=0;
9479                                                                                         }
9480                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9481                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9482                                                                                 }
9483
9484                                                                                 if(player[i].aitype==attacktypecutoff){
9485                                                                                         player[i].aiupdatedelay-=multiplier;
9486                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9487                                                                                                 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)){
9488                                                                                                         player[i].attackkeydown=0;
9489                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9490                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9491                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9492                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9493                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9494                                                                                                                                 else player[i].targetanimation=rollanim;
9495                                                                                                                                 player[i].target=0;
9496                                                                                                                                 player[i].targetframe=0;
9497                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9498                                                                                                                                 player[i].wentforweapon=0;
9499                                                                                                                         }
9500                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9501                                                                                                                                 player[i].targetanimation=flipanim;
9502                                                                                                                                 player[i].target=0;
9503                                                                                                                                 player[i].targetframe=0;
9504                                                                                                                         }
9505                                                                                                                 }
9506                                                                                                         }
9507                                                                                                         player[i].forwardkeydown=0;
9508                                                                                                         player[i].aiupdatedelay=.02;
9509                                                                                                 }
9510                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9511                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9512                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9513                                                                                                 }
9514                                                                                                 if(player[i].wentforweapon<3)
9515                                                                                                         for(j=0;j<weapons.numweapons;j++){
9516                                                                                                                 if(player[i].creature!=wolftype)
9517                                                                                                                         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){
9518                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9519                                                                                                                                         player[i].wentforweapon++;
9520                                                                                                                                         player[i].lastchecktime=6;
9521                                                                                                                                         player[i].aitype=getweapontype;
9522                                                                                                                                         player[i].ally=-1;
9523                                                                                                                                 }
9524                                                                                                                         }
9525                                                                                                         }
9526                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9527                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9528                                                                                                                         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)))){
9529                                                                                                                                 player[i].crouchkeydown=1;
9530                                                                                                                         }
9531                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9532                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9533                                                                                                                                         test2=player[i].coords+player[i].facing;
9534                                                                                                                                         test2.y+=5;
9535                                                                                                                                         test=player[i].coords+player[i].facing;
9536                                                                                                                                         test.y-=10;
9537                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9538                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9539                                                                                                                                         if(j==-1){
9540                                                                                                                                                 player[i].velocity=0;
9541                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9542                                                                                                                                                 player[i].targetframe=0;
9543                                                                                                                                                 player[i].target=0;
9544                                                                                                                                                 player[i].targetrotation+=180;
9545                                                                                                                                                 player[i].stunned=.5;
9546                                                                                                                                                 //player[i].aitype=passivetype;
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                                                                                                                                         else player[i].laststanding=j;
9557                                                                                                                                 }
9558                                                                                                                         }
9559                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9560                                                                                                                                 player[i].aitype=pathfindtype;
9561                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9562                                                                                                                                 player[i].finalpathfindpoint=-1;
9563                                                                                                                                 player[i].targetpathfindpoint=-1;
9564                                                                                                                                 player[i].lastpathfindpoint=-1;
9565                                                                                                                                 player[i].lastpathfindpoint2=-1;
9566                                                                                                                                 player[i].lastpathfindpoint3=-1;
9567                                                                                                                                 player[i].lastpathfindpoint4=-1;
9568                                                                                                                         }
9569                                                                                                                         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){
9570                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9571                                                                                                                                 else player[i].drawkeydown=0;
9572                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9573                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9574                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9575                                                                                                                                         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;
9576                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9577                                                                                                                                 Normalise(&rotatetarget);
9578                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9579                                                                                                                                 player[i].targetrotation*=360/6.28;
9580                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9581                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9582                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9583
9584                                                                                                                                 oldkey=player[i].forwardkeydown;
9585                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9586                                                                                                                                 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;
9587                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9588                                                                                                                                 else player[i].forwardkeydown=0;
9589                                                                                                                                 if(player[0].dead){
9590                                                                                                                                         player[i].forwardkeydown=0;
9591                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9592                                                                                                                                         if(Random()%100==0){
9593                                                                                                                                                 player[i].aitype=pathfindtype;
9594                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9595                                                                                                                                                 player[i].finalpathfindpoint=-1;
9596                                                                                                                                                 player[i].targetpathfindpoint=-1;
9597                                                                                                                                                 player[i].lastpathfindpoint=-1;
9598                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9599                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9600                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9601                                                                                                                                         }
9602                                                                                                                                 }
9603                                                                                                                                 player[i].leftkeydown=0;
9604                                                                                                                                 player[i].backkeydown=0;
9605                                                                                                                                 player[i].rightkeydown=0;
9606                                                                                                                                 player[i].crouchkeydown=0;
9607                                                                                                                                 player[i].throwkeydown=0;
9608
9609                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9610                                                                                                                                 /*for(j=0;j<numplayers;j++){
9611                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9612                                                                                                                                 player[i].crouchkeydown=1;
9613                                                                                                                                 }
9614                                                                                                                                 }*/
9615                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9616                                                                                                                                 else player[i].attackkeydown=0;
9617                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9618                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9619                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9620                                                                                                                                 player[i].attackkeydown=0;
9621                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9622                                                                                                                                 player[i].forwardkeydown=0;
9623                                                                                                                                 player[i].aiupdatedelay=.02;
9624                                                                                                                                 }*/
9625
9626                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9627                                                                                                                                         target=-2;
9628                                                                                                                                         for(j=0;j<numplayers;j++){
9629                                                                                                                                                 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)){
9630                                                                                                                                                         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))))){
9631                                                                                                                                                                 if(target>=0)target=-1;
9632                                                                                                                                                                 else target=j;
9633                                                                                                                                                         }
9634                                                                                                                                                 }
9635                                                                                                                                         }
9636                                                                                                                                         if(target>=0)player[target].Reverse();
9637                                                                                                                                 }
9638
9639                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9640                                                                                                                                 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;
9641                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9642                                                                                                                                         player[0].jumpkeydown=0;
9643                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9644                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9645                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9646
9647                                                                                                                                 if(tutoriallevel==1){
9648                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9649                                                                                                                                 }
9650
9651
9652                                                                                                                                 facing=player[i].coords;
9653                                                                                                                                 flatfacing=player[0].coords;
9654                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9655                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9656                                                                                                                                 if(player[i].occluded>=2)
9657                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9658                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9659                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9660                                                                                                                                                         player[i].aitype=searchtype;
9661                                                                                                                                                         player[i].lastchecktime=12;
9662                                                                                                                                                         player[i].lastseen=player[0].coords;
9663                                                                                                                                                         player[i].lastseentime=12;
9664                                                                                                                                                 }
9665                                                                                                                                         }
9666                                                                                                                                         else player[i].lastseentime=1;
9667                                                                                                                         }
9668                                                                                 }
9669                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9670                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
9671                                                                                                 test=player[0].coords;
9672                                                                                                 test.y-=40;
9673                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
9674                                                                                         }
9675                                                                                 }
9676                                                                                 // NOTE: Ask about logic of this call : NOTE
9677                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
9678                                                                                         player[i].stunned>0 ||
9679                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
9680                                                                                 {
9681                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
9682                                                                                         player[i].targetrotation=player[i].rotation;
9683                                                                                         player[i].forwardkeydown=0;
9684                                                                                         player[i].leftkeydown=0;
9685                                                                                         player[i].backkeydown=0;
9686                                                                                         player[i].rightkeydown=0;
9687                                                                                         player[i].jumpkeydown=0;
9688                                                                                         player[i].attackkeydown=0;
9689                                                                                         player[i].crouchkeydown=0;
9690                                                                                         player[i].throwkeydown=0;
9691                                                                                 }
9692
9693
9694                                                                                 facing=0;
9695                                                                                 facing.z=-1;
9696
9697                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9698                                                                                 facing=flatfacing;
9699
9700                                                                                 if(player[i].aitype==attacktypecutoff){
9701                                                                                         rotatetarget=player[0].coords-player[i].coords;
9702                                                                                         Normalise(&rotatetarget);
9703                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9704                                                                                         player[i].targetheadrotation*=360/6.28;
9705                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9706
9707                                                                                         player[i].targetheadrotation*=-1;
9708                                                                                         player[i].targetheadrotation+=180;
9709                                                                                         //player[i].targetheadrotation2=0;
9710                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9711                                                                                 }
9712                                                                                 else if(player[i].howactive>=typesleeping){
9713                                                                                         player[i].targetheadrotation=player[i].targetrotation;
9714                                                                                         player[i].targetheadrotation2=0;
9715                                                                                 }
9716                                                                                 else {
9717                                                                                         if(player[i].interestdelay<=0){
9718                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
9719                                                                                                 player[i].headtarget=player[i].coords;
9720                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
9721                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
9722                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
9723                                                                                                 player[i].headtarget+=player[i].facing*1.5;
9724                                                                                         }
9725                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
9726                                                                                         Normalise(&rotatetarget);
9727                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
9728                                                                                         player[i].targetheadrotation*=360/6.28;
9729                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9730
9731                                                                                         player[i].targetheadrotation*=-1;
9732                                                                                         player[i].targetheadrotation+=180;
9733                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9734                                                                                 }
9735                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
9736                                                                         }
9737                                                                         if(animation[player[i].targetanimation].attack==reversed){
9738                                                                                 //player[i].targetrotation=player[i].rotation;
9739                                                                                 player[i].forwardkeydown=0;
9740                                                                                 player[i].leftkeydown=0;
9741                                                                                 player[i].backkeydown=0;
9742                                                                                 player[i].rightkeydown=0;
9743                                                                                 player[i].jumpkeydown=0;
9744                                                                                 player[i].attackkeydown=0;
9745                                                                                 //player[i].crouchkeydown=0;
9746                                                                                 player[i].throwkeydown=0;
9747                                                                         }
9748
9749                                                                         if(indialogue!=-1){
9750                                                                                 player[i].forwardkeydown=0;
9751                                                                                 player[i].leftkeydown=0;
9752                                                                                 player[i].backkeydown=0;
9753                                                                                 player[i].rightkeydown=0;
9754                                                                                 player[i].jumpkeydown=0;
9755                                                                                 player[i].crouchkeydown=0;
9756                                                                                 player[i].drawkeydown=0;
9757                                                                                 player[i].throwkeydown=0;
9758                                                                         }
9759
9760                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
9761                                                                         if(player[i].collided>1)player[i].collided=1;
9762                                                                         player[i].collided-=multiplier*4;
9763                                                                         player[i].whichdirectiondelay-=multiplier;
9764                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
9765                                                                                 player[i].avoidcollided=-.3;
9766                                                                                 player[i].whichdirection=abs(Random()%2);
9767                                                                                 player[i].whichdirectiondelay=.4;
9768                                                                         }
9769                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
9770                                                                         player[i].avoidcollided-=multiplier/4;
9771                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
9772                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
9773                                                                         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;
9774
9775                                                                         if(!player[i].throwkeydown){
9776                                                                                 player[i].throwtogglekeydown=0;
9777                                                                         }
9778                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
9779                                                                                 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)){
9780                                                                                         for(j=0;j<weapons.numweapons;j++){
9781                                                                                                 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)
9782                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
9783                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
9784                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
9785                                                                                                                                 player[i].throwtogglekeydown=1;
9786                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9787                                                                                                                                 player[i].target=0;
9788                                                                                                                                 player[i].targetframe=0;
9789                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9790                                                                                                                                 Normalise(&rotatetarget);
9791                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9792                                                                                                                                 player[i].targetrotation*=360/6.28;
9793                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9794                                                                                                                                 player[i].hasvictim=0;
9795                                                                                                                         }
9796                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9797                                                                                                                                 player[i].throwtogglekeydown=1;
9798                                                                                                                                 player[i].hasvictim=0;
9799
9800                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
9801                                                                                                                                 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))
9802                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
9803                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
9804                                                                                                                                                         float gLoc[3];
9805                                                                                                                                                         float vel[3];
9806                                                                                                                                                         gLoc[0]=player[i].coords.x;
9807                                                                                                                                                         gLoc[1]=player[i].coords.y;
9808                                                                                                                                                         gLoc[2]=player[i].coords.z;
9809                                                                                                                                                         vel[0]=player[i].velocity.x;
9810                                                                                                                                                         vel[1]=player[i].velocity.y;
9811                                                                                                                                                         vel[2]=player[i].velocity.z;
9812                                                                                                                                                         if(weapons.type[j]!=staff){
9813                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9814                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9815                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
9816                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
9817                                                                                                                                                         }
9818
9819                                                                                                                                                         player[i].weaponactive=0;
9820                                                                                                                                                         weapons.owner[j]=player[i].id;
9821                                                                                                                                                         if(player[i].num_weapons>0){
9822                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9823                                                                                                                                                         }
9824                                                                                                                                                         player[i].num_weapons++;
9825                                                                                                                                                         player[i].weaponids[0]=j;
9826                                                                                                                                                 }
9827                                                                                                                                         }
9828                                                                                                                                         //}
9829                                                                                                                         }
9830                                                                                                                 }
9831                                                                                                                 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){
9832                                                                                                                         if(!player[i].isFlip()){
9833                                                                                                                                 player[i].throwtogglekeydown=1;
9834                                                                                                                                 player[i].targetanimation=removeknifeanim;
9835                                                                                                                                 player[i].target=0;
9836                                                                                                                                 player[i].targetframe=0;
9837                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
9838                                                                                                                                 Normalise(&rotatetarget);
9839                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9840                                                                                                                                 player[i].targetrotation*=360/6.28;
9841                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9842                                                                                                                         }
9843                                                                                                                         if(player[i].isFlip()){
9844                                                                                                                                 player[i].throwtogglekeydown=1;
9845                                                                                                                                 player[i].hasvictim=0;
9846
9847                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
9848                                                                                                                                         if(player[i].weaponactive==-1)
9849                                                                                                                                                 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))
9850                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
9851                                                                                                                                                                 float gLoc[3];
9852                                                                                                                                                                 float vel[3];
9853                                                                                                                                                                 gLoc[0]=player[i].coords.x;
9854                                                                                                                                                                 gLoc[1]=player[i].coords.y;
9855                                                                                                                                                                 gLoc[2]=player[i].coords.z;
9856                                                                                                                                                                 vel[0]=player[i].velocity.x;
9857                                                                                                                                                                 vel[1]=player[i].velocity.y;
9858                                                                                                                                                                 vel[2]=player[i].velocity.z;
9859                                                                                                                                                                 if(weapons.type[k]!=staff){
9860                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9861                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9862                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9863                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9864                                                                                                                                                                 }
9865
9866                                                                                                                                                                 player[i].weaponactive=0;
9867                                                                                                                                                                 weapons.owner[k]=player[i].id;
9868                                                                                                                                                                 if(player[i].num_weapons>0){
9869                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9870                                                                                                                                                                 }
9871                                                                                                                                                                 player[i].num_weapons++;
9872                                                                                                                                                                 player[i].weaponids[0]=k;
9873                                                                                                                                                         }
9874                                                                                                                                 }
9875                                                                                                                         }
9876                                                                                                                 }
9877                                                                                                         }
9878                                                                                         }
9879                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9880                                                                                                 if(numplayers>1)
9881                                                                                                         for(j=0;j<numplayers;j++){
9882                                                                                                                 if(player[i].weaponactive==-1)
9883                                                                                                                         if(j!=i)
9884                                                                                                                                 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)){
9885                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
9886                                                                                                                                                 player[i].throwtogglekeydown=1;
9887                                                                                                                                                 player[i].victim=&player[j];
9888                                                                                                                                                 player[i].hasvictim=1;
9889                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
9890                                                                                                                                                 player[i].target=0;
9891                                                                                                                                                 player[i].targetframe=0;
9892                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
9893                                                                                                                                                 Normalise(&rotatetarget);
9894                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9895                                                                                                                                                 player[i].targetrotation*=360/6.28;
9896                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9897                                                                                                                                         }
9898                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
9899                                                                                                                                                 player[i].throwtogglekeydown=1;
9900                                                                                                                                                 player[i].victim=&player[j];
9901                                                                                                                                                 player[i].hasvictim=1;
9902                                                                                                                                                 int k = player[j].weaponids[0];
9903                                                                                                                                                 if(player[i].hasvictim){
9904                                                                                                                                                         float gLoc[3];
9905                                                                                                                                                         float vel[3];
9906                                                                                                                                                         gLoc[0]=player[i].coords.x;
9907                                                                                                                                                         gLoc[1]=player[i].coords.y;
9908                                                                                                                                                         gLoc[2]=player[i].coords.z;
9909                                                                                                                                                         vel[0]=player[i].velocity.x;
9910                                                                                                                                                         vel[1]=player[i].velocity.y;
9911                                                                                                                                                         vel[2]=player[i].velocity.z;
9912                                                                                                                                                         bool fleshstuck;
9913                                                                                                                                                         fleshstuck=0;
9914                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
9915                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9916                                                                                                                                                                         fleshstuck=1;
9917                                                                                                                                                                 }
9918                                                                                                                                                         }
9919                                                                                                                                                         if(!fleshstuck){
9920                                                                                                                                                                 if(weapons.type[k]!=staff){
9921                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
9922                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
9923                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
9924                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
9925                                                                                                                                                                 }
9926                                                                                                                                                         }
9927                                                                                                                                                         if(fleshstuck){
9928                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
9929                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
9930                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
9931                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
9932                                                                                                                                                         }
9933
9934                                                                                                                                                         player[i].weaponactive=0;
9935                                                                                                                                                         if(weapons.owner[k]!=-1){
9936                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
9937                                                                                                                                                                 else player[i].victim->num_weapons=1;
9938
9939                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
9940                                                                                                                                                                 player[i].victim->skeleton.free=1;
9941                                                                                                                                                                 player[i].victim->skeleton.broken=0;
9942
9943                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
9944                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
9945                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
9946                                                                                                                                                                 }
9947
9948                                                                                                                                                                 XYZ relative;
9949                                                                                                                                                                 relative=0;
9950                                                                                                                                                                 relative.y=10;
9951                                                                                                                                                                 Normalise(&relative);
9952                                                                                                                                                                 XYZ footvel,footpoint;
9953                                                                                                                                                                 footvel=0;
9954                                                                                                                                                                 footpoint=weapons.position[k];
9955                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
9956                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
9957                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
9958                                                                                                                                                                                 weapons.bloody[k]=2;
9959                                                                                                                                                                                 weapons.blooddrip[k]=5;
9960                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
9961                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
9962                                                                                                                                                                                 player[i].victim->DoDamage(2000);
9963                                                                                                                                                                         }
9964                                                                                                                                                                 }
9965                                                                                                                                                                 if(player[i].victim->num_weapons>0){
9966                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
9967                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
9968                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
9969                                                                                                                                                                 }
9970
9971                                                                                                                                                                 player[i].victim->weaponactive=-1;
9972
9973                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
9974                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
9975                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
9976                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
9977                                                                                                                                                         }
9978                                                                                                                                                         weapons.owner[k]=i;
9979                                                                                                                                                         if(player[i].num_weapons>0){
9980                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
9981                                                                                                                                                         }
9982                                                                                                                                                         player[i].num_weapons++;
9983                                                                                                                                                         player[i].weaponids[0]=k;
9984                                                                                                                                                 }
9985                                                                                                                                         }
9986                                                                                                                                 }
9987                                                                                                         }
9988                                                                                         }
9989                                                                                 }
9990                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
9991                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
9992                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
9993                                                                                                         if(numplayers>1)
9994                                                                                                                 for(j=0;j<numplayers;j++){
9995                                                                                                                         if(i!=j)
9996                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
9997                                                                                                                                         if(hostile)
9998                                                                                                                                                 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)){
9999                                                                                                                                                         if(!player[i].isFlip()){
10000                                                                                                                                                                 player[i].throwtogglekeydown=1;
10001                                                                                                                                                                 player[i].victim=&player[j];
10002                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10003                                                                                                                                                                 player[i].target=0;
10004                                                                                                                                                                 player[i].targetframe=0;
10005                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10006                                                                                                                                                                 Normalise(&rotatetarget);
10007                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10008                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10009                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10010
10011                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10012                                                                                                                                                         }
10013                                                                                                                                                         if(player[i].isFlip()){
10014                                                                                                                                                                 if(player[i].weaponactive!=-1){
10015                                                                                                                                                                         player[i].throwtogglekeydown=1;
10016                                                                                                                                                                         player[i].victim=&player[j];
10017                                                                                                                                                                         XYZ aim;
10018                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10019                                                                                                                                                                         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);
10020                                                                                                                                                                         Normalise(&aim);
10021
10022                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10023
10024                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10025                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10026                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10027                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10028                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10029                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10030                                                                                                                                                                         player[i].num_weapons--;
10031                                                                                                                                                                         if(player[i].num_weapons){
10032                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10033                                                                                                                                                                         }
10034                                                                                                                                                                         player[i].weaponactive=-1;
10035                                                                                                                                                                 }
10036                                                                                                                                                         }
10037                                                                                                                                                 }
10038                                                                                                                 }
10039                                                                                         }
10040                                                                                 }
10041                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10042                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10043                                                                                         {
10044                                                                                                 player[i].throwtogglekeydown=1;
10045                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10046                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10047                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10048                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10049                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10050                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10051                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10052                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10053                                                                                                 player[i].num_weapons--;
10054                                                                                                 if(player[i].num_weapons){
10055                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10056                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10057                                                                                                 }
10058
10059                                                                                                 player[i].weaponactive=-1;
10060                                                                                                 for(j=0;j<numplayers;j++){
10061                                                                                                         player[j].wentforweapon=0;
10062                                                                                                 }
10063                                                                                         }
10064                                                                                 }
10065
10066                                                                         }
10067
10068                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10069                                                                                 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)){
10070                                                                                         //Setenvironment(1-environment);
10071                                                                                         bool isgood;
10072                                                                                         isgood=1;
10073                                                                                         if(player[i].weaponactive!=-1){
10074                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10075                                                                                         }
10076                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10077                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10078                                                                                                         player[i].targetanimation=drawrightanim;
10079                                                                                                         player[i].targetframe=0;
10080                                                                                                         player[i].target=0;
10081                                                                                                         player[i].drawtogglekeydown=1;
10082                                                                                                 }
10083                                                                                                 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){
10084                                                                                                         player[i].targetanimation=drawleftanim;
10085                                                                                                         player[i].targetframe=0;
10086                                                                                                         player[i].target=0;
10087                                                                                                         player[i].drawtogglekeydown=1;
10088                                                                                                 }
10089                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10090                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10091                                                                                                         player[i].targetframe=0;
10092                                                                                                         player[i].target=0;
10093                                                                                                         player[i].drawtogglekeydown=1;
10094                                                                                                 }
10095                                                                                         }
10096                                                                                 }
10097                                                                                 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){
10098                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10099                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10100                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10101                                                                                                 player[i].targetframe=0;
10102                                                                                                 player[i].target=0;
10103                                                                                                 player[i].hasvictim=0;
10104                                                                                                 //player[i].attacktogglekeydown=1;
10105                                                                                         }
10106                                                                                 }
10107
10108                                                                                 if(!player[i].drawkeydown){
10109                                                                                         player[i].drawtogglekeydown=0;
10110                                                                                 }
10111
10112                                                                                 if(i==0){
10113                                                                                         absflatfacing=0;
10114                                                                                         absflatfacing.z=-1;
10115
10116                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10117                                                                                 }
10118                                                                                 else absflatfacing=flatfacing;
10119
10120                                                                                 if(indialogue!=-1){
10121                                                                                         player[i].forwardkeydown=0;
10122                                                                                         player[i].leftkeydown=0;
10123                                                                                         player[i].backkeydown=0;
10124                                                                                         player[i].rightkeydown=0;
10125                                                                                         player[i].jumpkeydown=0;
10126                                                                                         player[i].crouchkeydown=0;
10127                                                                                         player[i].drawkeydown=0;
10128                                                                                         player[i].throwkeydown=0;
10129                                                                                 }
10130                                                                                 movekey=0;
10131                                                                                 //Do controls
10132                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10133                                                                                         if(!player[i].forwardkeydown){
10134                                                                                                 player[i].forwardstogglekeydown=0;
10135                                                                                         }
10136                                                                                         if(player[i].crouchkeydown){
10137                                                                                                 //Crouch
10138                                                                                                 target=-2;
10139                                                                                                 if(i==0){
10140                                                                                                         player[i].superruntoggle=1;
10141                                                                                                         if(numplayers>1)
10142                                                                                                                 for(j=0;j<numplayers;j++){
10143                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10144                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10145                                                                                                                                         player[i].superruntoggle=0;
10146                                                                                                                                 }
10147                                                                                                                         }
10148                                                                                                                 }
10149                                                                                                 }
10150
10151                                                                                                 if(numplayers>1)
10152                                                                                                         for(j=0;j<numplayers;j++){
10153                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10154                                                                                                                         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))){
10155                                                                                                                                 if(target>=0)target=-1;
10156                                                                                                                                 else target=j;
10157                                                                                                                         }
10158                                                                                                                 }
10159                                                                                                         }
10160                                                                                                         if(target>=0)player[target].Reverse();
10161                                                                                                         player[i].lowreversaldelay=.5;
10162
10163                                                                                                         if(player[i].isIdle()){
10164                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10165                                                                                                                 player[i].target=0;
10166                                                                                                                 player[i].targetframe=0;
10167                                                                                                                 player[i].transspeed=10;
10168                                                                                                         }
10169                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10170                                                                                                                 player[i].targetanimation=rollanim;
10171                                                                                                                 player[i].target=0;
10172                                                                                                                 player[i].targetframe=0;
10173                                                                                                                 player[i].transspeed=20;
10174                                                                                                         }
10175                                                                                         }
10176                                                                                         if(!player[i].crouchkeydown){
10177                                                                                                 //Uncrouch
10178                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10179                                                                                                 target=-2;
10180                                                                                                 if(player[i].isCrouch()){
10181                                                                                                         if(numplayers>1)
10182                                                                                                                 for(j=0;j<numplayers;j++){
10183                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10184                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10185                                                                                                                                         if(target>=0)target=-1;
10186                                                                                                                                         else target=j;
10187                                                                                                                                 }
10188                                                                                                                         }
10189                                                                                                                 }
10190                                                                                                                 if(target>=0)player[target].Reverse();
10191                                                                                                                 player[i].highreversaldelay=.5;
10192
10193                                                                                                                 if(player[i].isCrouch()){
10194                                                                                                                         if(!player[i].wasCrouch()){
10195                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10196                                                                                                                                 player[i].currentframe=0;
10197                                                                                                                         }
10198                                                                                                                         player[i].target=0;
10199                                                                                                                         player[i].targetanimation=player[i].getIdle();
10200                                                                                                                         player[i].targetframe=0;
10201                                                                                                                         player[i].transspeed=10;
10202                                                                                                                 }
10203                                                                                                 }
10204                                                                                                 if(player[i].targetanimation==sneakanim){
10205                                                                                                         player[i].targetanimation=player[i].getIdle();
10206                                                                                                         player[i].target=0;
10207                                                                                                         player[i].targetframe=0;
10208                                                                                                         player[i].transspeed=10;
10209                                                                                                 }
10210                                                                                         }
10211                                                                                         if(player[i].forwardkeydown){
10212                                                                                                 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)){
10213                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10214                                                                                                         else player[i].targetanimation=player[i].getRun();
10215                                                                                                         player[i].target=0;
10216                                                                                                         player[i].targetframe=0;
10217                                                                                                 }
10218                                                                                                 if(player[i].isCrouch()){
10219                                                                                                         player[i].targetanimation=sneakanim;
10220                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10221                                                                                                         player[i].targetframe=0;
10222                                                                                                 }
10223                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10224                                                                                                         player[i].targetanimation=climbanim;
10225                                                                                                         player[i].target=0;
10226                                                                                                         player[i].targetframe=1;
10227                                                                                                         player[i].jumpclimb=1;
10228                                                                                                 }
10229                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10230                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10231                                                                                                 }
10232                                                                                                 player[i].forwardstogglekeydown=1;
10233                                                                                                 movekey=1;
10234                                                                                         }
10235                                                                                         if (player[i].rightkeydown){
10236                                                                                                 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)){
10237                                                                                                         player[i].targetanimation=player[i].getRun();
10238                                                                                                         player[i].target=0;
10239                                                                                                         player[i].targetframe=0;
10240                                                                                                 }
10241                                                                                                 if(player[i].isCrouch()){
10242                                                                                                         player[i].targetanimation=sneakanim;
10243                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10244                                                                                                         player[i].targetframe=0;
10245                                                                                                 }
10246                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10247                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10248                                                                                                 }
10249                                                                                                 player[i].targetrotation-=90;
10250                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10251                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10252                                                                                                 movekey=1;
10253                                                                                         }
10254                                                                                         if ( player[i].leftkeydown){
10255                                                                                                 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)){
10256                                                                                                         player[i].targetanimation=player[i].getRun();
10257                                                                                                         player[i].target=0;
10258                                                                                                         player[i].targetframe=0;
10259                                                                                                 }
10260                                                                                                 if(player[i].isCrouch()){
10261                                                                                                         player[i].targetanimation=sneakanim;
10262                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10263                                                                                                         player[i].targetframe=0;
10264                                                                                                 }
10265                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10266                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10267                                                                                                 }
10268                                                                                                 player[i].targetrotation+=90;
10269                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10270                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10271                                                                                                 movekey=1;
10272                                                                                         }
10273                                                                                         if(player[i].backkeydown){
10274                                                                                                 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)){
10275                                                                                                         player[i].targetanimation=player[i].getRun();
10276                                                                                                         player[i].target=0;
10277                                                                                                         player[i].targetframe=0;
10278                                                                                                 }
10279                                                                                                 if(player[i].isCrouch()){
10280                                                                                                         player[i].targetanimation=sneakanim;
10281                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10282                                                                                                         player[i].targetframe=0;
10283                                                                                                 }
10284                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10285                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10286                                                                                                 }
10287                                                                                                 if(player[i].targetanimation==hanganim){
10288                                                                                                         player[i].currentanimation=jumpdownanim;
10289                                                                                                         player[i].targetanimation=jumpdownanim;
10290                                                                                                         player[i].target=0;
10291                                                                                                         player[i].currentframe=0;
10292                                                                                                         player[i].targetframe=1;
10293                                                                                                         player[i].velocity=0;
10294                                                                                                         player[i].velocity.y+=gravity;
10295                                                                                                         player[i].coords.y-=1.4;
10296                                                                                                         player[i].grabdelay=1;
10297                                                                                                 }
10298                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10299                                                                                                         player[i].targetrotation+=180;
10300                                                                                                 movekey=1;
10301                                                                                         }
10302                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10303                                                                                                 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)){
10304                                                                                                         player[i].jumpstart=0;
10305                                                                                                         player[i].targetanimation=jumpupanim;
10306                                                                                                         player[i].target=0;
10307                                                                                                         player[i].targetframe=0;
10308                                                                                                         player[i].rotation=player[i].targetrotation;
10309                                                                                                         player[i].transspeed=20;
10310                                                                                                         player[i].FootLand(0,1);
10311                                                                                                         player[i].FootLand(1,1);
10312
10313                                                                                                         facing=0;
10314                                                                                                         facing.z=-1;
10315                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10316
10317                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10318                                                                                                         if(!movekey)player[i].velocity=0;
10319
10320                                                                                                         //Dodge sweep?
10321                                                                                                         target=-2;
10322                                                                                                         if(numplayers>1)
10323                                                                                                                 for(j=0;j<numplayers;j++){
10324                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10325                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10326                                                                                                                                         if(target>=0)target=-1;
10327                                                                                                                                         else target=j;
10328                                                                                                                                 }
10329                                                                                                                         }
10330                                                                                                                 }
10331                                                                                                                 if(target>=0)player[i].velocity.y=1;
10332                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10333                                                                                                                         player[i].velocity.y=7;
10334                                                                                                                         player[i].crouchtogglekeydown=1;
10335                                                                                                                 }
10336                                                                                                                 else player[i].velocity.y=5;
10337
10338                                                                                                                 if(mousejump&&i==0&&debugmode){
10339                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10340                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10341                                                                                                                 }
10342
10343                                                                                                                 player[i].coords.y+=.2;
10344                                                                                                                 player[i].jumppower-=1;
10345
10346                                                                                                                 static float gLoc[3];
10347                                                                                                                 static float vel[3];
10348                                                                                                                 gLoc[0]=player[i].coords.x;
10349                                                                                                                 gLoc[1]=player[i].coords.y;
10350                                                                                                                 gLoc[2]=player[i].coords.z;
10351                                                                                                                 vel[0]=player[i].velocity.x;
10352                                                                                                                 vel[1]=player[i].velocity.y;
10353                                                                                                                 vel[2]=player[i].velocity.z;
10354
10355                                                                                                                 if(i==0){
10356                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10357                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10358                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10359                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10360                                                                                                                 }
10361
10362                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10363                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10364                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10365                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10366                                                                                                 }
10367                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10368                                                                                                         player[i].targetanimation=player[i].getLanding();
10369                                                                                                         player[i].landhard=0;
10370                                                                                                         player[i].target=0;
10371                                                                                                         player[i].targetframe=2;
10372                                                                                                         player[i].jumpstart=1;
10373                                                                                                         player[i].tempdeltav=deltav;
10374                                                                                                 }
10375                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10376                                                                                                         if(player[i].jumppower>multiplier*6){
10377                                                                                                                 player[i].velocity.y+=multiplier*6;
10378                                                                                                                 player[i].jumppower-=multiplier*6;
10379                                                                                                         }
10380                                                                                                         if(player[i].jumppower<=multiplier*6){
10381                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10382                                                                                                                 player[i].jumppower=0;
10383                                                                                                         }
10384                                                                                                 }
10385                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10386                                                                                         }
10387
10388                                                                                         if(!movekey){
10389                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10390                                                                                                         player[i].targetanimation=player[i].getStop();
10391                                                                                                         player[i].target=0;
10392                                                                                                         player[i].targetframe=0;
10393                                                                                                 }
10394                                                                                                 if(player[i].targetanimation==sneakanim){
10395                                                                                                         player[i].targetanimation=player[i].getCrouch();
10396                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10397                                                                                                         player[i].targetframe=0;
10398                                                                                                 }
10399                                                                                         }
10400                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10401                                                                                                 player[i].targetanimation=player[i].getStop();
10402                                                                                                 player[i].target=0;
10403                                                                                                 player[i].targetframe=0;
10404                                                                                         }
10405                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10406                                                                                                 player[i].targetanimation=player[i].getStop();
10407                                                                                                 player[i].target=0;
10408                                                                                                 player[i].targetframe=0;
10409                                                                                         }
10410                                                                                 }
10411                                                                 }
10412                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10413                                                         }
10414
10415                                                         //Rotation
10416                                                         for(k=0;k<numplayers;k++){
10417                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10418                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10419                                                                         else player[k].rotation+=360;
10420                                                                 }
10421
10422                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10423                                                                         player[k].targetanimation=player[k].getStop();
10424                                                                         player[k].targetframe=0;
10425                                                                         player[k].target=0;
10426                                                                 }
10427
10428                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10429                                                                         player[k].targettilt=0;
10430                                                                 }
10431                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10432                                                                         player[k].targettilt=0;
10433                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10434                                                                         player[k].jumppower+=multiplier*7;
10435                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10436                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10437                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10438                                                                 }
10439
10440                                                                 if(player[k].isRun()){
10441                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10442                                                                 }
10443
10444                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10445                                                                 else if(player[k].tilt>player[k].targettilt){
10446                                                                         player[k].tilt-=multiplier*150;
10447                                                                 }
10448                                                                 else if(player[k].tilt<player[k].targettilt){
10449                                                                         player[k].tilt+=multiplier*150;
10450                                                                 }
10451
10452                                                                 player[k].grabdelay-=multiplier;
10453                                                         }
10454
10455                                                         for(k=0;k<numplayers;k++){
10456                                                                 player[k].DoAnimations();
10457                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10458                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10459                                                         }
10460
10461                                                         objects.DoStuff();
10462                                                         /*
10463                                                         player[0].righthandmorphstart=0;
10464                                                         player[0].righthandmorphend=1;
10465                                                         player[0].lefthandmorphstart=0;
10466                                                         player[0].lefthandmorphend=1;
10467                                                         player[0].headmorphstart=0;
10468                                                         player[0].headmorphend=2;*/
10469
10470                                                         /*
10471                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10472                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10473                                                         player[0].righthandmorphend=1;
10474                                                         player[0].targetrighthandmorphness=1;
10475
10476                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10477                                                         player[0].lefthandmorphend=0;
10478                                                         player[0].targetlefthandmorphness=1;
10479
10480                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10481                                                         player[0].headmorphend=2;
10482                                                         player[0].targetheadmorphness=1;
10483                                                         }
10484                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10485                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10486                                                         player[0].righthandmorphend=0;
10487                                                         player[0].targetrighthandmorphness=1;
10488
10489                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10490                                                         player[0].lefthandmorphend=1;
10491                                                         player[0].targetlefthandmorphness=1;
10492
10493                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10494                                                         player[0].headmorphend=0;
10495                                                         player[0].targetheadmorphness=1;
10496                                                         }
10497                                                         */
10498                                                         if(numenvsounds!=0)
10499                                                                 for(j=numenvsounds-1;j>=0;j--){
10500                                                                         envsoundlife[j]-=multiplier;
10501                                                                         if(envsoundlife[j]<0){
10502                                                                                 numenvsounds--;
10503                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10504                                                                                 envsound[j]=envsound[numenvsounds];
10505                                                                         }
10506                                                                 }
10507                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10508                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10509
10510                                                                 if(tutoriallevel==1){
10511                                                                         XYZ temp;
10512                                                                         XYZ temp2;
10513                                                                         XYZ temp3;
10514                                                                         XYZ oldtemp;
10515                                                                         XYZ oldtemp2;
10516                                                                         temp.x=1011;
10517                                                                         temp.y=84;
10518                                                                         temp.z=491;
10519                                                                         temp2.x=1025;
10520                                                                         temp2.y=75;
10521                                                                         temp2.z=447;
10522                                                                         temp3.x=1038;
10523                                                                         temp3.y=76;
10524                                                                         temp3.z=453;
10525                                                                         oldtemp=temp;
10526                                                                         oldtemp2=temp2;
10527                                                                         if(tutorialstage>=51)
10528                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10529                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10530                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10531
10532                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10533                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10534                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10535
10536                                                                                         gameon=0;
10537                                                                                         mainmenu=5;
10538
10539                                                                                         float gLoc[3]={0,0,0};
10540                                                                                         float vel[3]={0,0,0};
10541                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10542                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10543                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10544                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10545                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10546                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10547
10548                                                                                         flashr=1;
10549                                                                                         flashg=0;
10550                                                                                         flashb=0;
10551                                                                                         flashamount=1;
10552                                                                                         flashdelay=1;
10553                                                                                 }
10554                                                                                 if(tutorialstage<51)
10555                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10556                                                                                                 float gLoc[3];
10557                                                                                                 float vel[3];
10558                                                                                                 gLoc[0]=player[0].coords.x;
10559                                                                                                 gLoc[1]=player[0].coords.y;
10560                                                                                                 gLoc[2]=player[0].coords.z;
10561                                                                                                 vel[0]=0;
10562                                                                                                 vel[1]=0;
10563                                                                                                 vel[2]=0;
10564                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10565                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10566                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10567                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10568
10569                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10570
10571                                                                                                 flashr=1;
10572                                                                                                 flashg=1;
10573                                                                                                 flashb=1;
10574                                                                                                 flashamount=1;
10575                                                                                                 flashdelay=1;
10576                                                                                         }
10577                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10578                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10579                                                                                                         float gLoc[3];
10580                                                                                                         float vel[3];
10581                                                                                                         gLoc[0]=player[1].coords.x;
10582                                                                                                         gLoc[1]=player[1].coords.y;
10583                                                                                                         gLoc[2]=player[1].coords.z;
10584                                                                                                         vel[0]=0;
10585                                                                                                         vel[1]=0;
10586                                                                                                         vel[2]=0;
10587                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10588                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10589                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10590                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10591
10592                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10593                                                                                                                 if(Random()%2==0){
10594                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10595                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10596                                                                                                                         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;
10597                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10598                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10599                                                                                                                 }
10600                                                                                                         }
10601
10602                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10603                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10604                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10605                                                                                                                 if(Random()%2==0){
10606                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10607                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10608                                                                                                                         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;
10609                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10610                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10611                                                                                                                 }
10612                                                                                                         }
10613                                                                                                 }
10614                                                                 }
10615
10616
10617                                                                 //3d sound
10618                                                                 static float gLoc[3];
10619                                                                 gLoc[0]=viewer.x;
10620                                                                 gLoc[1]=viewer.y;
10621                                                                 gLoc[2]=viewer.z;
10622                                                                 static float vel[3];
10623                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10624                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10625                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10626
10627                                                                 //Set orientation with forward and up vectors
10628                                                                 static XYZ upvector;
10629                                                                 upvector=0;
10630                                                                 upvector.z=-1;
10631
10632                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10633                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10634
10635                                                                 facing=0;
10636                                                                 facing.z=-1;
10637
10638                                                                 facing=DoRotation(facing,-rotation2,0,0);
10639                                                                 facing=DoRotation(facing,0,0-rotation,0);
10640
10641
10642                                                                 static float ori[6];
10643                                                                 ori[0] = -facing.x;
10644                                                                 ori[1] = facing.y;
10645                                                                 ori[2] = -facing.z;
10646                                                                 ori[3] = -upvector.x;
10647                                                                 ori[4] = upvector.y;
10648                                                                 ori[5] = -upvector.z;
10649
10650                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10651                                                                 OPENAL_Update();
10652
10653                                                                 oldviewer=viewer;
10654                 }
10655         }
10656
10657         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10658                 Screenshot();
10659                 freezetogglekeydown=1;
10660         }
10661 }
10662
10663 void    Game::TickOnce(){
10664         //if(!console){
10665         if(!mainmenu)
10666                 if(directing||indialogue==-1){
10667                         rotation+=deltah*.7;
10668                         if(!invertmouse)rotation2+=deltav*.7;
10669                         if(invertmouse)rotation2-=deltav*.7;
10670                         if(rotation2>90)rotation2=90;
10671                         if(rotation2<-70)rotation2=-70;
10672                 }
10673                 if(mainmenu)rotation+=multiplier*5;
10674       
10675                 //}
10676 }
10677
10678 void    Game::TickOnceAfter(){
10679         static XYZ colviewer;
10680         static XYZ coltarget;
10681         static XYZ target;
10682         static XYZ col;
10683         static float brotate;
10684         static XYZ facing;
10685         static int i,j;
10686         static float changedelay;
10687         static bool alldead;
10688         static float unseendelay;
10689         static float cameraspeed;
10690
10691         if(!mainmenu){
10692
10693                 if(environment==snowyenvironment)music1=stream_music1snow;
10694                 if(environment==grassyenvironment)music1=stream_music1grass;
10695                 if(environment==desertenvironment)music1=stream_music1desert;
10696
10697                 realthreat=0;
10698
10699                 musictype=music1;
10700                 for(i=0;i<numplayers;i++){
10701                         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)){
10702                                 musictype=stream_music2;
10703                                 realthreat=1;
10704                         }
10705                 }
10706                 if(player[0].dead)musictype=stream_music3;
10707
10708
10709                 if(musictype==stream_music2){
10710                         unseendelay=1;
10711                 }
10712
10713                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
10714                         unseendelay-=multiplier;
10715                         if(unseendelay>0){
10716                                 musictype=stream_music2;
10717                         }
10718                 }
10719
10720
10721                 if(loading==2){
10722                         musictype=stream_music3;
10723                         musicvolume[2]=512;
10724                         musicvolume[0]=0;
10725                         musicvolume[1]=0;
10726                         musicvolume[3]=0;
10727                 }
10728
10729                 if(musictoggle){
10730                         if(musictype!=oldmusictype&&musictype==stream_music2){
10731                                 static float gLoc[3];
10732                                 static float vel[3];
10733                                 gLoc[0]=cameraloc.x;
10734                                 gLoc[1]=cameraloc.y;
10735                                 gLoc[2]=cameraloc.z;
10736                                 vel[0]=0;
10737                                 vel[1]=0;
10738                                 vel[2]=0;
10739                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
10740                                 OPENAL_SetVolume(channels[alarmsound], 512);
10741                                 OPENAL_SetPaused(channels[alarmsound], false);
10742
10743                         }
10744                 }
10745                 musicselected=musictype;
10746
10747                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
10748                 else musicvolume[0]-=multiplier*450;
10749                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
10750                 else musicvolume[1]-=multiplier*450;
10751                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
10752                 else musicvolume[2]-=multiplier*450;
10753                 /*
10754                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
10755                 else musicvolume[0]-=multiplier*450;
10756                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
10757                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
10758                 else musicvolume[1]-=multiplier*100;
10759                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
10760                 else musicvolume[2]-=multiplier*450;*/
10761
10762                 for(i=0;i<3;i++){
10763                         if(musicvolume[i]<0)musicvolume[i]=0;
10764                         if(musicvolume[i]>512)musicvolume[i]=512;
10765                 }
10766
10767                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
10768
10769                 if(musictoggle){
10770                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
10771                                 PlayStreamEx( music1, strm[music1], NULL, true);
10772                                 OPENAL_SetPaused(channels[music1], false);
10773                         }
10774                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
10775                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
10776                                 OPENAL_SetPaused(channels[stream_music2], false);
10777                         }
10778                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
10779                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10780                                 OPENAL_SetPaused(channels[stream_music3], false);
10781                         }
10782                 }
10783
10784                 if(!musictoggle){
10785                         OPENAL_SetPaused(channels[music1], true);
10786                         OPENAL_SetPaused(channels[stream_music2], true);
10787                         OPENAL_SetPaused(channels[stream_music3], true);
10788
10789                         for(i=0;i<4;i++){
10790                                 oldmusicvolume[i]=0;
10791                                 musicvolume[i]=0;
10792                         }
10793                 }
10794
10795                 if(musictoggle){
10796                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
10797                                 OPENAL_SetPaused(channels[music1], true);
10798                         }
10799                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
10800                                 OPENAL_SetPaused(channels[stream_music2], true);
10801                         }
10802                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
10803                                 OPENAL_SetPaused(channels[stream_music3], true);
10804                         }
10805
10806                         if(musicvolume[0]!=oldmusicvolume[0]){
10807                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
10808                         }
10809                         if(musicvolume[1]!=oldmusicvolume[1]){
10810                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
10811                         }
10812                         if(musicvolume[2]!=oldmusicvolume[2]){
10813                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
10814                         }
10815
10816                         for(i=0;i<3;i++){
10817                                 oldmusicvolume[i]=musicvolume[i];
10818                         }
10819                 }
10820
10821                 killhotspot=2;
10822                 if(numhotspots)
10823                         for(i=0;i<numhotspots;i++){
10824                                 if(hotspottype[i]>10&&hotspottype[i]<20){
10825                                         if(player[hotspottype[i]-10].dead==0){
10826                                                 killhotspot=0;
10827                                         }
10828                                         else if(killhotspot==2)
10829                                                 killhotspot=1;
10830                                 }
10831                         }
10832                         if(killhotspot==2)killhotspot=0;
10833
10834
10835                         winhotspot=0;
10836                         if(numhotspots)
10837                                 for(i=0;i<numhotspots;i++){
10838                                         if(hotspottype[i]==-1){
10839                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
10840                                                         winhotspot=1;
10841                                         }
10842                                 }
10843
10844                                 int numalarmed=0;
10845                                 if(numplayers>1)
10846                                         for(i=1;i<numplayers;i++){
10847                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
10848                                         }
10849                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
10850
10851                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
10852                                                 if(player[0].dead&&changedelay<=0){
10853                                                         changedelay=1;
10854                                                         targetlevel=whichlevel;
10855                                                 }
10856                                                 alldead=1;
10857                                                 if(numplayers>1)
10858                                                         for(i=1;i<numplayers;i++){
10859                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
10860                                                         }
10861
10862
10863                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
10864                                                                 changedelay=1;
10865                                                                 targetlevel=whichlevel+1;
10866                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10867                                                         }
10868                                                         if(winhotspot||windialogue){
10869                                                                 changedelay=0.1;
10870                                                                 targetlevel=whichlevel+1;
10871                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10872                                                         }
10873
10874
10875                                                         if(killhotspot){
10876                                                                 changedelay=1;
10877                                                                 targetlevel=whichlevel+1;
10878                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
10879                                                         }
10880
10881                                                         if(changedelay>0&&!player[0].dead&&!won){
10882                                                                 //high scores, awards, win
10883                                                                 if(campaign){
10884                                                                         won=1;
10885                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
10886                                                                         accountcampaignchoicesmade[accountactive]++;
10887                                                                         accountcampaignscore[accountactive]+=bonustotal;
10888                                                                         scoreadded=1;
10889                                                                         accountcampaigntime[accountactive]+=leveltime;
10890                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
10891
10892                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10893                                                                 }
10894                                                                 else
10895                                                                 {
10896                                                                         won=1;
10897                                                                         if(!debugmode){
10898                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
10899                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
10900                                                                         }
10901                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
10902
10903                                                                 }
10904                                                         }
10905                                         }
10906
10907                                         if(!winfreeze){
10908
10909                                                 if(leveltime<1){
10910                                                         loading=0;
10911                                                         changedelay=.1;
10912                                                         alldead=0;
10913                                                         winhotspot=0;
10914                                                         killhotspot=0;
10915                                                 }
10916
10917                                                 if(!editorenabled&&gameon&&!mainmenu){
10918                                                         if(changedelay!=-999)changedelay-=multiplier/7;
10919                                                         if(player[0].dead)targetlevel=whichlevel;
10920                                                         if(loading==2&&!campaign){
10921                                                                 flashr=1;
10922                                                                 flashg=0;
10923                                                                 flashb=0;
10924                                                                 flashamount=1;
10925                                                                 flashdelay=1;
10926                                                                 loadtime=0;
10927
10928                                                                 float gLoc[3]={0,0,0};
10929                                                                 float vel[3]={0,0,0};
10930                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10931                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10932                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10933                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10934                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10935                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10936
10937                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
10938                                                                         startbonustotal=bonustotal;
10939                                                                 }
10940                                                                 if(!player[0].dead)Loadlevel(targetlevel);
10941                                                                 if(player[0].dead)Loadlevel(whichlevel);
10942
10943                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10944                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10945                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10946                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10947                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10948                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10949
10950                                                                 loading=3;
10951                                                         }
10952                                                         if(loading==2&&targetlevel==whichlevel){
10953                                                                 flashr=1;
10954                                                                 flashg=0;
10955                                                                 flashb=0;
10956                                                                 flashamount=1;
10957                                                                 flashdelay=1;
10958                                                                 loadtime=0;
10959
10960                                                                 float gLoc[3]={0,0,0};
10961                                                                 float vel[3]={0,0,0};
10962                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
10963                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
10964                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
10965                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
10966                                                                 OPENAL_SetPaused(channels[firestartsound], false);
10967                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
10968
10969                                                                 for(i=0;i<255;i++){
10970                                                                         mapname[i]='\0';
10971                                                                 }
10972                                                                 mapname[0]=':';
10973                                                                 mapname[1]='D';
10974                                                                 mapname[2]='a';
10975                                                                 mapname[3]='t';
10976                                                                 mapname[4]='a';
10977                                                                 mapname[5]=':';
10978                                                                 mapname[6]='M';
10979                                                                 mapname[7]='a';
10980                                                                 mapname[8]='p';
10981                                                                 mapname[9]='s';
10982                                                                 mapname[10]=':';
10983                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
10984                                                                 Loadlevel(mapname);
10985
10986                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10987                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10988                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10989                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10990                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10991                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10992
10993                                                                 loading=3;
10994                                                         }
10995                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
10996                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
10997                         {
10998                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
10999                                                                                 winfreeze=1;
11000                                                                                 changedelay=-999;
11001                                                                         }
11002                                                                         if(player[0].dead)loading=1;
11003                                                                 }
11004                                                         }
11005                                                 }
11006
11007                                                 if(campaign)
11008                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11009                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11010                                                                         endgame=1;
11011                                                                 }
11012                                                         }
11013                                                         else if(mainmenu==0&&winfreeze){
11014                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11015                                                                         stealthloading=1;
11016                                                                 else stealthloading=0;
11017
11018                                                                 if(!stealthloading){
11019                                                                         float gLoc[3]={0,0,0};
11020                                                                         float vel[3]={0,0,0};
11021                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11022                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11023                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11024                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
11025                                                                         OPENAL_SetPaused(channels[firestartsound], false);
11026                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11027
11028                                                                         flashr=1;
11029                                                                         flashg=0;
11030                                                                         flashb=0;
11031                                                                         flashamount=1;
11032                                                                         flashdelay=1;
11033                                                                 }
11034
11035                                                                 startbonustotal=0;
11036
11037                                                                 ifstream ipstream(ConvertFileName("/Data/Campaigns:main.txt"));
11038                                                                 //campaignnumlevels=0;
11039                                                                 //accountcampaignchoicesmade[accountactive]=0;
11040                                                                 ipstream.ignore(256,':');
11041                                                                 ipstream >> campaignnumlevels;
11042                                                                 for(i=0;i<campaignnumlevels;i++){
11043                                                                         ipstream.ignore(256,':');
11044                                                                         ipstream.ignore(256,':');
11045                                                                         ipstream.ignore(256,' ');
11046                                                                         ipstream >> campaignmapname[i];
11047                                                                         ipstream.ignore(256,':');
11048                                                                         ipstream >> campaigndescription[i];
11049                                                                         for(j=0;j<256;j++){
11050                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11051                                                                         }
11052                                                                         ipstream.ignore(256,':');
11053                                                                         ipstream >> campaignchoosenext[i];
11054                                                                         ipstream.ignore(256,':');
11055                                                                         ipstream >> campaignnumnext[i];
11056                                                                         if(campaignnumnext[i])
11057                                                                                 for(j=0;j<campaignnumnext[i];j++){
11058                                                                                         ipstream.ignore(256,':');
11059                                                                                         ipstream >> campaignnextlevel[i][j];
11060                                                                                         campaignnextlevel[i][j]-=1;
11061                                                                                 }
11062                                                                                 ipstream.ignore(256,':');
11063                                                                                 ipstream >> campaignlocationx[i];
11064                                                                                 ipstream.ignore(256,':');
11065                                                                                 ipstream >> campaignlocationy[i];
11066                                                                 }
11067                                                                 ipstream.close();
11068
11069                                                                 for(i=0;i<campaignnumlevels;i++){
11070                                                                         levelvisible[i]=0;
11071                                                                         levelhighlight[i]=0;
11072                                                                 }
11073
11074
11075                                                                 for(i=0;i<campaignnumlevels;i++){
11076                                                                         levelvisible[i]=0;
11077                                                                         levelhighlight[i]=0;
11078                                                                 }
11079
11080                                                                 levelorder[0]=0;
11081                                                                 levelvisible[0]=1;
11082                                                                 if(accountcampaignchoicesmade[accountactive])
11083                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11084                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11085                                                                                 levelvisible[levelorder[i+1]]=1;
11086                                                                         }
11087                                                                         int whichlevelstart;
11088                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11089                                                                         if(whichlevelstart<0){
11090                                                                                 campaignchoicenum=1;
11091                                                                                 campaignchoicewhich[0]=0;
11092                                                                         }
11093                                                                         else
11094                                                                         {
11095                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11096                                                                                 if(campaignchoicenum)
11097                                                                                         for(i=0;i<campaignchoicenum;i++){
11098                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11099                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11100                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11101                                                                                         }
11102                                                                         }
11103
11104                                                                         loading=2;
11105                                                                         loadtime=0;
11106                                                                         targetlevel=7;
11107                                                                         //if(firstload)TickOnceAfter();
11108                                                                         if(!firstload)LoadStuff();
11109                                                                         //else {
11110                                                                         for(i=0;i<255;i++){
11111                                                                                 mapname[i]='\0';
11112                                                                         }
11113                                                                         mapname[0]=':';
11114                                                                         mapname[1]='D';
11115                                                                         mapname[2]='a';
11116                                                                         mapname[3]='t';
11117                                                                         mapname[4]='a';
11118                                                                         mapname[5]=':';
11119                                                                         mapname[6]='M';
11120                                                                         mapname[7]='a';
11121                                                                         mapname[8]='p';
11122                                                                         mapname[9]='s';
11123                                                                         mapname[10]=':';
11124
11125                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11126                                                                         //accountcampaignchoicesmade[accountactive]++;
11127
11128
11129                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11130                                                                         whichchoice=0;
11131                                                                         visibleloading=1;
11132                                                                         stillloading=1;
11133                                                                         Loadlevel(mapname);
11134                                                                         campaign=1;
11135                                                                         mainmenu=0;
11136                                                                         gameon=1;
11137                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11138
11139                                                                         stealthloading=0;
11140                                                         }
11141
11142                                                         if(loading==3)loading=0;
11143
11144                                         }
11145
11146                                         oldmusictype=musictype;
11147         }
11148
11149         facing=0;
11150         facing.z=-1;
11151
11152         facing=DoRotation(facing,-rotation2,0,0);
11153         facing=DoRotation(facing,0,0-rotation,0);
11154         viewerfacing=facing;
11155
11156         brotate=0;
11157         if(!cameramode){
11158                 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;
11159                 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;
11160                 target.y+=.1;
11161                 if(player[0].skeleton.free){
11162                         for(i=0;i<player[0].skeleton.num_joints;i++){
11163                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11164                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11165                         }
11166                         target.y+=.1;
11167                 }
11168                 if(player[0].skeleton.free!=2&&!autocam){
11169                         cameraspeed=20;
11170                         if(findLengthfast(&player[0].velocity)>400){
11171                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11172                         }
11173                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11174                         coltarget=target-cameraloc;
11175                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11176                         else {
11177                                 Normalise(&coltarget);
11178                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11179                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11180                         }
11181                         if(editorenabled)cameraloc=target;
11182                         cameradist+=multiplier*5;
11183                         if(cameradist>2.3)cameradist=2.3;
11184                         viewer=cameraloc-facing*cameradist;
11185                         colviewer=viewer;
11186                         coltarget=cameraloc;
11187                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11188                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11189                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11190                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11191                                         colviewer=viewer;
11192                                         coltarget=cameraloc;
11193                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11194                                 }
11195                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11196                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11197                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11198                                                 colviewer=viewer;
11199                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11200                                                         viewer=colviewer;
11201                                                 }
11202                                         }
11203                                         cameradist=findDistance(&viewer,&target);
11204                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11205                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11206                                         }
11207                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11208                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11209                                         }
11210                 }
11211                 if(player[0].skeleton.free!=2&&autocam){
11212                         cameraspeed=20;
11213                         if(findLengthfast(&player[0].velocity)>400){
11214                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11215                         }
11216                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11217                         cameradist+=multiplier*5;
11218                         if(cameradist>3.3)cameradist=3.3;
11219                         coltarget=target-cameraloc;
11220                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11221                         else if(findLengthfast(&coltarget)>1)
11222                         {
11223                                 Normalise(&coltarget);
11224                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11225                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11226                         }
11227                         if(editorenabled)cameraloc=target;
11228                         viewer=cameraloc;
11229                         colviewer=viewer;
11230                         coltarget=cameraloc;
11231                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11232                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11233                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11234                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11235                                         colviewer=viewer;
11236                                         coltarget=cameraloc;
11237                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11238                                 }
11239                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11240                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11241                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11242                                                 colviewer=viewer;
11243                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11244                                                         viewer=colviewer;
11245                                                 }
11246                                         }
11247                                         cameradist=findDistance(&viewer,&target);
11248                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11249                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11250                                         }
11251                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11252                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11253                                         }
11254                 }
11255                 if(camerashake>.8)camerashake=.8;
11256                 //if(woozy>10)woozy=10;
11257                 //woozy+=multiplier;
11258                 woozy+=multiplier;
11259                 if(player[0].dead)camerashake=0;
11260                 if(player[0].dead)woozy=0;
11261                 camerashake-=multiplier*2;
11262                 blackout-=multiplier*2;
11263                 //if(player[0].isCrouch())woozy-=multiplier*8;
11264                 if(camerashake<0)camerashake=0;
11265                 if(blackout<0)blackout=0;
11266                 //if(woozy<0)woozy=0;
11267                 if(camerashake){
11268                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11269                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11270                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11271                 }
11272         }
11273 }