]> git.jsancho.org Git - lugaru.git/blob - Source/GameTick.cpp
Merged
[lugaru.git] / Source / GameTick.cpp
1 /*
2 Copyright (C) 2003, 2010 - Wolfire Games
3
4 This file is part of Lugaru.
5
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
15 See the GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21
22 #if PLATFORM_UNIX
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #else
27 #include <direct.h>
28 #endif
29
30 #include <ctime>
31 #include "Game.h"
32 #include "openal_wrapper.h"
33
34 using namespace std;
35
36 extern float multiplier;
37 extern XYZ viewer;
38 extern int environment;
39 extern float texscale;
40 extern Terrain terrain;
41 extern OPENAL_SAMPLE    *samp[100];
42 extern int channels[100];
43 extern Sprites sprites;
44 extern int kTextureSize;
45 extern float screenwidth,screenheight;
46 extern float gravity;
47 extern int detail;
48 extern float texdetail;
49 extern Objects objects;
50 extern int slomo;
51 extern float slomodelay;
52 extern bool floatjump;
53 extern float volume;
54 extern Animation animation[animation_count];
55 extern Light light;
56 extern float texdetail;
57 extern GLubyte bloodText[512*512*3];
58 extern GLubyte wolfbloodText[512*512*3];
59 extern float terraindetail;
60 extern float camerashake;
61 extern float woozy;
62 extern float blackout;
63 extern bool cellophane;
64 extern bool musictoggle;
65 extern int difficulty;
66 extern Weapons weapons;
67 extern Person player[maxplayers];
68 extern int numplayers;
69 extern int bloodtoggle;
70 extern bool invertmouse;
71 extern float windvar;
72 extern float precipdelay;
73 extern XYZ viewerfacing;
74 extern bool ambientsound;
75 extern bool mousejump;
76 extern float viewdistance;
77 extern bool freeze;
78 extern bool autoslomo;
79 extern int newnetmessages;
80 extern char netmessages[256];
81 extern bool keyboardfrozen;
82 extern int netdatanew;
83 extern bool loadingstuff;
84 extern char mapname[256];
85 extern XYZ windvector;
86 extern bool buttons[3];
87 extern bool debugmode;
88 static int music1;
89 extern int mainmenu;
90 extern int oldmainmenu;
91 extern bool visibleloading;
92 extern int loadscreencolor;
93 extern float flashamount,flashr,flashg,flashb;
94 extern int flashdelay;
95 extern XYZ envsound[30];
96 extern float envsoundvol[30];
97 extern int numenvsounds;
98 extern float envsoundlife[30];
99 extern float usermousesensitivity;
100 extern bool ismotionblur;
101 extern bool foliage;
102 extern bool trilinear;
103 extern bool damageeffects;
104 extern bool showpoints;
105 extern bool texttoggle;
106 extern bool alwaysblur;
107 extern float gamespeed;
108 extern bool decals;
109 extern bool vblsync;
110 extern bool immediate;
111 extern bool velocityblur;
112 extern int bonus;
113 extern int oldbonus;
114 extern float bonusvalue;
115 extern float bonustotal;
116 extern float bonustime;
117 extern float startbonustotal;
118 extern float tintr,tintg,tintb;
119 extern float bonusnum[100];
120 extern bool skyboxtexture;
121 extern float skyboxr;
122 extern float skyboxg;
123 extern float skyboxb;
124 extern float skyboxlightr;
125 extern float skyboxlightg;
126 extern float skyboxlightb;
127 extern float fadestart;
128 extern float slomospeed;
129 extern float slomofreq;
130 extern int tutoriallevel;
131 extern float smoketex;
132 extern float tutorialstagetime;
133 extern int tutorialstage;
134 extern float tutorialmaxtime;
135 extern float tutorialsuccess;
136 extern bool againbonus;
137 extern bool reversaltrain;
138 extern bool canattack;
139 extern bool cananger;
140 extern float damagedealt;
141 extern float damagetaken;
142 extern int maptype;
143 extern int editoractive;
144 extern int editorpathtype;
145 extern bool oldbuttons[3];
146
147 extern float hostiletime;
148
149 extern bool gamestarted;
150
151 extern int numhotspots;
152 extern int winhotspot;
153 extern int windialogue;
154 extern int killhotspot;
155 extern XYZ hotspot[40];
156 extern int hotspottype[40];
157 extern float hotspotsize[40];
158 extern char hotspottext[40][256];
159 extern int currenthotspot;
160
161 extern int kBitsPerPixel;
162 extern int hostile;
163
164 extern int numaccounts;
165 extern int accountactive;
166 extern int accountdifficulty[10];
167 extern int accountprogress[10];
168 extern float accountpoints[10];
169 extern float accounthighscore[10][50];
170 extern float accountfasttime[10][50];
171 extern bool accountunlocked[10][60];
172 extern char accountname[10][256];
173
174 extern bool stillloading;
175 extern bool winfreeze;
176
177 extern int numfalls;
178 extern int numflipfail;
179 extern int numseen;
180 extern int numstaffattack;
181 extern int numswordattack;
182 extern int numknifeattack;
183 extern int numunarmedattack;
184 extern int numescaped;
185 extern int numflipped;
186 extern int numwallflipped;
187 extern int numthrowkill;
188 extern int numafterkill;
189 extern int numreversals;
190 extern int numattacks;
191 extern int maxalarmed;
192 extern int numresponded;
193
194 extern int numdialogues;
195 extern int numdialogueboxes[max_dialogues];
196 extern int dialoguetype[max_dialogues];
197 extern int dialogueboxlocation[max_dialogues][max_dialoguelength];
198 extern float dialogueboxcolor[max_dialogues][max_dialoguelength][3];
199 extern int dialogueboxsound[max_dialogues][max_dialoguelength];
200 extern char dialoguetext[max_dialogues][max_dialoguelength][128];
201 extern char dialoguename[max_dialogues][max_dialoguelength][64];
202 extern XYZ dialoguecamera[max_dialogues][max_dialoguelength];
203 extern XYZ participantlocation[max_dialogues][10];
204 extern int participantfocus[max_dialogues][max_dialoguelength];
205 extern int participantaction[max_dialogues][max_dialoguelength];
206 extern float participantrotation[max_dialogues][10];
207 extern XYZ participantfacing[max_dialogues][max_dialoguelength][10];
208 extern float dialoguecamerarotation[max_dialogues][max_dialoguelength];
209 extern float dialoguecamerarotation2[max_dialogues][max_dialoguelength];
210 extern int indialogue;
211 extern int whichdialogue;
212 extern int directing;
213 extern float dialoguetime;
214 extern int dialoguegonethrough[20];
215
216 extern bool campaign;
217
218 extern float oldgamespeed;
219
220 extern float accountcampaignhighscore[10];
221 extern float accountcampaignfasttime[10];
222 extern float accountcampaignscore[10];
223 extern float accountcampaigntime[10];
224
225 extern int accountcampaignchoicesmade[10];
226 extern int accountcampaignchoices[10][5000];
227 /********************> Tick() <*****/
228 extern OPENAL_STREAM * strm[20];
229 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
230 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
231
232 extern void ScreenShot(const char * fname);
233 void Screenshot (void)
234 {
235         char temp[1024];
236         time_t  t = time(NULL);
237         struct  tm *tme = localtime(&t);
238         sprintf(temp, "Screenshots\\Screenshot_%04d_%02d_%02d--%02d_%02d_%02d.png", tme->tm_year + 1900, tme->tm_mon + 1, tme->tm_mday, tme->tm_hour, tme->tm_min, tme->tm_sec);
239
240         #if defined(_WIN32)
241         mkdir("Screenshots");
242         #else
243         mkdir("Screenshots", S_IRWXU);
244         #endif
245
246         ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
247
248         /*FSSpec                                MAC_file;
249         GraphicsExportComponent QT_exporter;
250         OSErr                           MAC_error_code;
251         CGrafPtr                        MAC_currentPort;
252         GDHandle                        MAC_currentDevice;
253         unsigned char*          MAC_pixels;
254         Rect                            MAC_picture_rectangle;
255         GWorldPtr                       MAC_offscreen_graphics_port;
256
257         static int numscreenshots=0;
258
259         // Make an FSSpec
260         static char buf[256];
261         if(numscreenshots==0){
262         buf[0]=26;
263         buf[1]=':';
264         buf[2]='S';
265         buf[3]='c';
266         buf[4]='r';
267         buf[5]='e';
268         buf[6]='e';
269         buf[7]='n';
270         buf[8]='s';
271         buf[9]='h';
272         buf[10]='o';
273         buf[11]='t';
274         buf[12]='s';
275         buf[13]=':';
276         buf[14]='S';
277         buf[15]='c';
278         buf[16]='r';
279         buf[17]='e';
280         buf[18]='e';
281         buf[19]='n';
282         buf[20]='s';
283         buf[21]='h';
284         buf[22]='o';
285         buf[23]='t';
286         buf[24]='0';
287         buf[25]='0';
288         buf[26]='0';
289         }
290
291         FInfo *fndrInfo;
292         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
293         while(!FSpGetFInfo (&MAC_file, fndrInfo)){
294         FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
295         if(!FSpGetFInfo (&MAC_file, fndrInfo)){
296         numscreenshots++;
297         buf[26]++;
298         if(buf[26]==':'){
299         buf[26]='0';
300         buf[25]++;
301         if(buf[25]==':'){
302         buf[25]='0';
303         buf[24]++;
304         if(buf[24]==':'){
305         buf[24]='9';
306         buf[25]='9';
307         buf[26]='9';
308         }
309         }
310         }
311         }
312         }
313
314
315         // Get the GWorld
316         GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
317         //assert(MAC_gWorld != NULL);
318
319         // Allocate memory for loading image
320         MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
321         if (MAC_pixels == NULL) {
322         //UTIL_Error("Could not create Texture data.");
323         return;
324         }
325
326         // Get GWorld
327         ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
328
329         // Make a picture Rectangle
330         MAC_picture_rectangle.left = 0;
331         MAC_picture_rectangle.right = screenwidth;
332         MAC_picture_rectangle.top = 0;
333         MAC_picture_rectangle.bottom = screenheight;
334
335         // Create new offscreen GWorld
336         MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
337         if (MAC_error_code)     {
338         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
339         delete MAC_pixels;
340         //UTIL_Error("Could not create offscreen GWorld. ");
341         return;
342
343         }
344
345         // Copy OpenGL Context to new GWorld
346         glReadBuffer(GL_FRONT);
347         glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
348
349         // Swizzle texture
350         for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
351         unsigned char temp = MAC_pixels[byte+0];
352         MAC_pixels[byte+0] = MAC_pixels[byte+3];
353         MAC_pixels[byte+3] = MAC_pixels[byte+2];
354         MAC_pixels[byte+2] = MAC_pixels[byte+1];
355         MAC_pixels[byte+1] = temp;
356         }
357
358         // Flip the image  :(   This could probably be optimized
359         int vert;
360         int src_index;
361         int dst_index;
362         unsigned char temp;
363         for (int horz = 0; horz < screenwidth; ++horz)
364         for (vert = 0; vert < screenheight / 2; ++vert) {
365         src_index = (screenwidth * vert + horz) * 4;
366         dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
367
368         temp=MAC_pixels[src_index+0];
369         MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
370         MAC_pixels[dst_index+0]=temp;
371
372         temp=MAC_pixels[src_index+1];
373         MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
374         MAC_pixels[dst_index+1]=temp;
375
376         temp=MAC_pixels[src_index+2];
377         MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
378         MAC_pixels[dst_index+2]=temp;
379
380         temp=MAC_pixels[src_index+3];
381         MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
382         MAC_pixels[dst_index+3]=temp;
383         }
384
385
386
387         // Export the Gworld
388         MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
389         if (MAC_error_code) {
390         //UTIL_Warning("Unable to export screenshot.");
391         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
392         ::DisposeGWorld(MAC_offscreen_graphics_port);
393         delete MAC_pixels;
394         return;
395         }
396
397         MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
398         if (MAC_error_code) {
399         ::CloseComponent(QT_exporter);
400         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
401         ::DisposeGWorld(MAC_offscreen_graphics_port);
402         delete MAC_pixels;
403         //UTIL_Warning("Unable to export screenshot.");
404         return;
405         }
406
407         MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
408         if (MAC_error_code) {
409         ::CloseComponent(QT_exporter);
410         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
411         ::DisposeGWorld(MAC_offscreen_graphics_port);
412         delete MAC_pixels;
413         //UTIL_Warning("Unable to export screenshot.");
414         return;
415         }
416
417         MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
418         if (MAC_error_code) {
419         ::CloseComponent(QT_exporter);
420         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
421         ::DisposeGWorld(MAC_offscreen_graphics_port);
422         delete MAC_pixels;
423         //UTIL_Warning("Unable to export screenshot.");
424         return;
425         }
426
427         ::CloseComponent(QT_exporter);
428         ::SetGWorld(MAC_currentPort, MAC_currentDevice);
429         ::DisposeGWorld(MAC_offscreen_graphics_port);
430
431         delete MAC_pixels;*/
432 }
433
434
435
436 void    Game::SetUpLighting(){
437         if(environment==snowyenvironment){
438                 light.color[0]=.65;
439                 light.color[1]=.65;
440                 light.color[2]=.7;
441                 light.ambient[0]=.4;
442                 light.ambient[1]=.4;
443                 light.ambient[2]=.44;
444         }
445         if(environment==desertenvironment){
446                 light.color[0]=.95;
447                 light.color[1]=.95;
448                 light.color[2]=.95;
449                 light.ambient[0]=.4;
450                 light.ambient[1]=.35;
451                 light.ambient[2]=.3;
452         }
453
454         if(environment==grassyenvironment){
455                 light.color[0]=.95;
456                 light.color[1]=.95;
457                 light.color[2]=1;
458                 light.ambient[0]=.4;
459                 light.ambient[1]=.4;
460                 light.ambient[2]=.44;
461         }
462         if(!skyboxtexture){
463                 light.color[0]=1;
464                 light.color[1]=1;
465                 light.color[2]=1;
466                 light.ambient[0]=.4;
467                 light.ambient[1]=.4;
468                 light.ambient[2]=.4;
469         }
470         float average;
471         average=(skyboxlightr+skyboxlightg+skyboxlightb)/3;
472         light.color[0]*=(skyboxlightr+average)/2;
473         light.color[1]*=(skyboxlightg+average)/2;
474         light.color[2]*=(skyboxlightb+average)/2;
475         light.ambient[0]=light.ambient[0]*(skyboxlightr+average)/2*1;
476         light.ambient[1]=light.ambient[1]*(skyboxlightg+average)/2*1;
477         light.ambient[2]=light.ambient[2]*(skyboxlightb+average)/2*1;
478         /*
479         light.ambient[0]=0;
480         light.ambient[1]=0;
481         light.ambient[2]=0;     */
482 }
483
484 int Game::findPathDist(int start,int end){
485         int i,j,k,smallestcount,count,connected;
486         int last,last2,last3,last4;
487         int closest;
488
489         smallestcount=1000;
490         for(i=0;i<50;i++){
491                 count=0;
492                 last=start;
493                 last2=-1;
494                 last3=-1;
495                 last4=-1;
496                 while(last!=end&&count<30){
497                         closest=-1;
498                         for(j=0;j<numpathpoints;j++){
499                                 if(j!=last&&j!=last2&&j!=last3&&j!=last4)
500                                 {
501                                         connected=0;
502                                         if(numpathpointconnect[j])
503                                                 for(k=0;k<numpathpointconnect[j];k++){
504                                                         if(pathpointconnect[j][k]==last)connected=1;
505                                                 }
506                                                 if(!connected)
507                                                         if(numpathpointconnect[last])
508                                                                 for(k=0;k<numpathpointconnect[last];k++){
509                                                                         if(pathpointconnect[last][k]==j)connected=1;
510                                                                 }
511                                                                 if(connected)
512                                                                         if(closest==-1||Random()%2==0){
513                                                                                 closest=j;
514                                                                         }
515                                 }
516                         }
517                         last4=last3;
518                         last3=last2;
519                         last2=last;
520                         last=closest;
521                         count++;
522                 }
523                 if(count<smallestcount)smallestcount=count;
524         }
525         return smallestcount;
526 }
527
528 int Game::checkcollide(XYZ startpoint,XYZ endpoint){
529         static XYZ colpoint,colviewer,coltarget;
530         static float minx,minz,maxx,maxz,miny,maxy;
531         static int i;
532
533         //startpoint.y+=.7;
534         //endpoint.y+=.7;
535         //startpoint.y-=.1;
536         //endpoint.y-=.1;
537
538         minx=startpoint.x;
539         if(minx>endpoint.x)minx=endpoint.x;
540         miny=startpoint.y;
541         if(miny>endpoint.y)miny=endpoint.y;
542         minz=startpoint.z;
543         if(minz>endpoint.z)minz=endpoint.z;
544
545         maxx=startpoint.x;
546         if(maxx<endpoint.x)maxx=endpoint.x;
547         maxy=startpoint.y;
548         if(maxy<endpoint.y)maxy=endpoint.y;
549         maxz=startpoint.z;
550         if(maxz<endpoint.z)maxz=endpoint.z;
551
552         minx-=1;
553         miny-=1;
554         minz-=1;
555         maxx+=1;
556         maxy+=1;
557         maxz+=1;
558
559         for(i=0;i<objects.numobjects;i++){
560                 if(objects.position[i].x>minx-objects.model[i].boundingsphereradius&&objects.position[i].x<maxx+objects.model[i].boundingsphereradius&&objects.position[i].y>miny-objects.model[i].boundingsphereradius&&objects.position[i].y<maxy+objects.model[i].boundingsphereradius&&objects.position[i].z>minz-objects.model[i].boundingsphereradius&&objects.position[i].z<maxz+objects.model[i].boundingsphereradius){
561                         if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
562                                 colviewer=startpoint;
563                                 coltarget=endpoint;
564                                 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)return i;
565                         }
566                 }
567         }
568
569         //if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
570
571         return -1;
572 }
573
574 int Game::checkcollide(XYZ startpoint,XYZ endpoint,int what){
575         static XYZ colpoint,colviewer,coltarget;
576         static float minx,minz,maxx,maxz,miny,maxy;
577         static int i;
578
579         //startpoint.y+=.7;
580         //endpoint.y+=.7;
581         //startpoint.y-=.1;
582         //endpoint.y-=.1;
583
584         minx=startpoint.x;
585         if(minx>endpoint.x)minx=endpoint.x;
586         miny=startpoint.y;
587         if(miny>endpoint.y)miny=endpoint.y;
588         minz=startpoint.z;
589         if(minz>endpoint.z)minz=endpoint.z;
590
591         maxx=startpoint.x;
592         if(maxx<endpoint.x)maxx=endpoint.x;
593         maxy=startpoint.y;
594         if(maxy<endpoint.y)maxy=endpoint.y;
595         maxz=startpoint.z;
596         if(maxz<endpoint.z)maxz=endpoint.z;
597
598         minx-=1;
599         miny-=1;
600         minz-=1;
601         maxx+=1;
602         maxy+=1;
603         maxz+=1;
604
605         if(what!=1000){
606                 if(objects.position[what].x>minx-objects.model[what].boundingsphereradius&&objects.position[what].x<maxx+objects.model[what].boundingsphereradius&&objects.position[what].y>miny-objects.model[what].boundingsphereradius&&objects.position[what].y<maxy+objects.model[what].boundingsphereradius&&objects.position[what].z>minz-objects.model[what].boundingsphereradius&&objects.position[what].z<maxz+objects.model[what].boundingsphereradius){
607                         if(objects.type[what]!=treeleavestype&&objects.type[what]!=bushtype&&objects.type[what]!=firetype){
608                                 colviewer=startpoint;
609                                 coltarget=endpoint;
610                                 if(objects.model[what].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[what],&objects.rotation[what])!=-1)return i;
611                         }
612                 }
613         }
614
615         if(what==1000)if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)return 1000;
616
617         return -1;
618 }
619
620 void    Game::Setenvironment(int which)
621 {
622         LOGFUNC;
623
624         LOG(" Setting environment...");
625
626         float temptexdetail;
627         environment=which;
628 /*
629         OPENAL_SetPaused(channels[music1snow], true);
630         OPENAL_SetPaused(channels[music1grass], true);
631         OPENAL_SetPaused(channels[music1desert], true);
632         OPENAL_SetPaused(channels[wind], true);
633         OPENAL_SetPaused(channels[desertambient], true);
634 */
635         OPENAL_SetPaused(channels[stream_music1snow], true);
636         OPENAL_SetPaused(channels[stream_music1grass], true);
637         OPENAL_SetPaused(channels[stream_music1desert], true);
638         OPENAL_SetPaused(channels[stream_wind], true);
639         OPENAL_SetPaused(channels[stream_desertambient], true);
640
641
642         if(environment==snowyenvironment){
643                 windvector=0;
644                 windvector.z=3;
645                 if(ambientsound){
646                         //PlaySoundEx( wind, samp[wind], NULL, true);
647                         PlayStreamEx(stream_wind, strm[stream_wind], 0, true);
648                         OPENAL_SetPaused(channels[stream_wind], false);
649                         OPENAL_SetVolume(channels[stream_wind], 256);
650                 }
651
652                 LoadTexture(":Data:Textures:snowtree.png",&objects.treetextureptr,0,1);
653                 LoadTexture(":Data:Textures:bushsnow.png",&objects.bushtextureptr,0,1);
654                 LoadTexture(":Data:Textures:bouldersnow.jpg",&objects.rocktextureptr,1,0);
655                 LoadTexture(":Data:Textures:snowbox.jpg",&objects.boxtextureptr,1,0);
656
657                 OPENAL_Sample_Free(samp[footstepsound]);
658                 OPENAL_Sample_Free(samp[footstepsound2]);
659                 OPENAL_Sample_Free(samp[footstepsound3]);
660                 OPENAL_Sample_Free(samp[footstepsound4]);
661                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
662                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
663                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
664                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
665                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
666                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
667                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
668                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
669
670                 LoadTexture(":Data:Textures:snow.jpg",&terraintexture,1,0);
671
672                 LoadTexture(":Data:Textures:rock.jpg",&terraintexture2,1,0);
673
674                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
675
676
677
678
679                 temptexdetail=texdetail;
680                 if(texdetail>1)texdetail=4;
681                 skybox.load(    ":Data:Textures:Skybox(snow):Front.jpg",
682                         ":Data:Textures:Skybox(snow):Left.jpg",
683                         ":Data:Textures:Skybox(snow):Back.jpg",
684                         ":Data:Textures:Skybox(snow):Right.jpg",
685                         ":Data:Textures:Skybox(snow):Up.jpg",
686                         ":Data:Textures:Skybox(snow):Down.jpg",
687                         ":Data:Textures:Skybox(snow):Cloud.jpg",
688                         ":Data:Textures:Skybox(snow):Reflect.jpg");
689
690
691
692
693                 texdetail=temptexdetail;
694         }
695         if(environment==desertenvironment){
696                 windvector=0;
697                 windvector.z=2;
698                 LoadTexture(":Data:Textures:deserttree.png",&objects.treetextureptr,0,1);
699                 LoadTexture(":Data:Textures:bushdesert.png",&objects.bushtextureptr,0,1);
700                 LoadTexture(":Data:Textures:boulderdesert.jpg",&objects.rocktextureptr,1,0);
701                 LoadTexture(":Data:Textures:desertbox.jpg",&objects.boxtextureptr,1,0);
702
703
704                 if(ambientsound){
705                         //PlaySoundEx( desertambient, samp[desertambient], NULL, true);
706                         PlayStreamEx( stream_desertambient, strm[stream_desertambient], NULL, true);
707                         OPENAL_SetPaused(channels[stream_desertambient], false);
708                         OPENAL_SetVolume(channels[stream_desertambient], 256);
709                 }
710
711                 OPENAL_Sample_Free(samp[footstepsound]);
712                 OPENAL_Sample_Free(samp[footstepsound2]);
713                 OPENAL_Sample_Free(samp[footstepsound3]);
714                 OPENAL_Sample_Free(samp[footstepsound4]);
715                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
716                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
717                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow1.ogg", OPENAL_HW3D, 0, 0);
718                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepsnow2.ogg", OPENAL_HW3D, 0, 0);
719                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
720                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
721                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
722                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
723
724                 LoadTexture(":Data:Textures:sand.jpg",&terraintexture,1,0);
725
726                 LoadTexture(":Data:Textures:sandslope.jpg",&terraintexture2,1,0);
727
728                 //LoadTexture(":Data:Textures:detailgrain.png",&terraintexture3,1);
729
730
731
732                 temptexdetail=texdetail;
733                 if(texdetail>1)texdetail=4;
734                 skybox.load(    ":Data:Textures:Skybox(sand):Front.jpg",
735                         ":Data:Textures:Skybox(sand):Left.jpg",
736                         ":Data:Textures:Skybox(sand):Back.jpg",
737                         ":Data:Textures:Skybox(sand):Right.jpg",
738                         ":Data:Textures:Skybox(sand):Up.jpg",
739                         ":Data:Textures:Skybox(sand):Down.jpg",
740                         ":Data:Textures:Skybox(sand):Cloud.jpg",
741                         ":Data:Textures:Skybox(sand):Reflect.jpg");
742
743
744
745
746                 texdetail=temptexdetail;
747         }
748         if(environment==grassyenvironment){
749                 windvector=0;
750                 windvector.z=2;
751                 LoadTexture(":Data:Textures:tree.png",&objects.treetextureptr,0,1);
752                 LoadTexture(":Data:Textures:bush.png",&objects.bushtextureptr,0,1);
753                 LoadTexture(":Data:Textures:boulder.jpg",&objects.rocktextureptr,1,0);
754                 LoadTexture(":Data:Textures:grassbox.jpg",&objects.boxtextureptr,1,0);
755
756                 if(ambientsound){
757                         PlayStreamEx( stream_wind, strm[stream_wind], NULL, true);
758                         OPENAL_SetPaused(channels[stream_wind], false);
759                         OPENAL_SetVolume(channels[stream_wind], 100);
760                 }
761
762                 OPENAL_Sample_Free(samp[footstepsound]);
763                 OPENAL_Sample_Free(samp[footstepsound2]);
764                 OPENAL_Sample_Free(samp[footstepsound3]);
765                 OPENAL_Sample_Free(samp[footstepsound4]);
766                 samp[footstepsound] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass1.ogg", OPENAL_HW3D, 0, 0);
767                 samp[footstepsound2] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepgrass2.ogg", OPENAL_HW3D, 0, 0);
768                 samp[footstepsound3] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone1.ogg", OPENAL_HW3D, 0, 0);
769                 samp[footstepsound4] = OPENAL_Sample_Load(OPENAL_FREE, ":Data:Sounds:footstepstone2.ogg", OPENAL_HW3D, 0, 0);
770                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound], 4.0f, 1000.0f);
771                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound2], 4.0f, 1000.0f);
772                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound3], 4.0f, 1000.0f);
773                 OPENAL_Sample_SetMinMaxDistance(samp[footstepsound4], 4.0f, 1000.0f);
774
775                 LoadTexture(":Data:Textures:grassdirt.jpg",&terraintexture,1,0);
776
777                 LoadTexture(":Data:Textures:mossrock.jpg",&terraintexture2,1,0);
778
779                 //LoadTexture(":Data:Textures:detail.png",&terraintexture3,1);
780
781
782
783                 temptexdetail=texdetail;
784                 if(texdetail>1)texdetail=4;
785                 skybox.load(    ":Data:Textures:Skybox(grass):Front.jpg",
786                         ":Data:Textures:Skybox(grass):Left.jpg",
787                         ":Data:Textures:Skybox(grass):Back.jpg",
788                         ":Data:Textures:Skybox(grass):Right.jpg",
789                         ":Data:Textures:Skybox(grass):Up.jpg",
790                         ":Data:Textures:Skybox(grass):Down.jpg",
791                         ":Data:Textures:Skybox(grass):Cloud.jpg",
792                         ":Data:Textures:Skybox(grass):Reflect.jpg");
793
794
795
796                 texdetail=temptexdetail;
797         }
798         temptexdetail=texdetail;
799         texdetail=1;
800         terrain.load(":Data:Textures:heightmap.png");
801
802         texdetail=temptexdetail;
803 }
804
805
806 void    Game::Loadlevel(int which){
807         stealthloading=0;
808
809         if(which==0)Loadlevel((char *)":Data:Maps:map1");
810         else if(which==1)Loadlevel((char *)":Data:Maps:map2");
811         else if(which==2)Loadlevel((char *)":Data:Maps:map3");
812         else if(which==3)Loadlevel((char *)":Data:Maps:map4");
813         else if(which==4)Loadlevel((char *)":Data:Maps:map5");
814         else if(which==5)Loadlevel((char *)":Data:Maps:map6");
815         else if(which==6)Loadlevel((char *)":Data:Maps:map7");
816         else if(which==7)Loadlevel((char *)":Data:Maps:map8");
817         else if(which==8)Loadlevel((char *)":Data:Maps:map9");
818         else if(which==9)Loadlevel((char *)":Data:Maps:map10");
819         else if(which==10)Loadlevel((char *)":Data:Maps:map11");
820         else if(which==11)Loadlevel((char *)":Data:Maps:map12");
821         else if(which==12)Loadlevel((char *)":Data:Maps:map13");
822         else if(which==13)Loadlevel((char *)":Data:Maps:map14");
823         else if(which==14)Loadlevel((char *)":Data:Maps:map15");
824         else if(which==15)Loadlevel((char *)":Data:Maps:map16");
825         else if(which==-1){tutoriallevel=-1;Loadlevel((char *)":Data:Maps:tutorial");}
826         else Loadlevel((char *)":Data:Maps:mapsave");
827
828         whichlevel=which;
829 }
830
831 /*char * Game::MD5_string (unsigned char *string){
832 char temp[50];
833 char temp2[100];
834
835 strcpy(temp2,(const char *)string);
836 strcat((char *)temp2,(const char *)"Lugaru");
837 sprintf (temp, "%d",strlen((char *)temp2));
838 strcat((char *)temp2,temp);
839
840 MD5 context;
841 unsigned int len = strlen ( (char *)temp2);
842
843 context.update   ((unsigned char *)temp2, len);
844 context.finalize ();
845
846 return context.hex_digest();
847 }*/
848
849
850
851 void    Game::Loadlevel(char *name){
852         int i,j,k,l,m;
853         static int oldlevel;
854         int templength;
855         float lamefloat;
856         int lameint;
857
858         float headprop,legprop,armprop,bodyprop;
859
860         LOGFUNC;
861
862         LOG(std::string("Loading level...") + name);
863
864         if(!gameon)visibleloading=1;
865
866         if(stealthloading)visibleloading=0;
867
868         if(!stillloading)loadtime=0;
869         gamestarted=1;
870
871         numenvsounds=0;
872         //visibleloading=1;
873         if(tutoriallevel!=-1)tutoriallevel=0;
874         else tutoriallevel=1;
875
876         if(tutoriallevel==1)tutorialstage=0;
877         if(tutorialstage==0){
878                 tutorialstagetime=0;
879                 tutorialmaxtime=1;
880         }
881         loadingstuff=1;
882         if(!firstload){
883                 oldlevel=50;
884         }
885         OPENAL_SetPaused(channels[whooshsound], true);
886         OPENAL_SetPaused(channels[stream_firesound], true);
887
888         int mapvers;
889         FILE                    *tfile;
890         tfile=fopen( name, "rb" );
891         if(tfile)
892         {
893                 OPENAL_SetPaused(channels[stream_firesound], true);
894
895
896                 scoreadded=0;
897                 windialogue=0;
898
899                 hostiletime=0;
900
901                 won=0;
902
903                 //campaign=0;
904                 animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
905
906                 numdialogues=0;
907
908                 for(i=0;i<20;i++)
909                 {
910                         dialoguegonethrough[i]=0;
911                 }
912
913                 indialogue=-1;
914                 cameramode=0;
915
916                 damagedealt=0;
917                 damagetaken=0;
918
919                 if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
920
921                 if(difficulty!=2)minimap=1;
922                 else minimap=0;
923
924                 numhotspots=0;
925                 currenthotspot=-1;
926                 bonustime=1;
927
928                 skyboxtexture=1;
929                 skyboxr=1;
930                 skyboxg=1;
931                 skyboxb=1;
932
933                 freeze=0;
934                 winfreeze=0;
935
936                 for(i=0;i<100;i++)
937                 {
938                         bonusnum[i]=0;
939                 }
940
941                 numfalls=0;
942                 numflipfail=0;
943                 numseen=0;
944                 numstaffattack=0;
945                 numswordattack=0;
946                 numknifeattack=0;
947                 numunarmedattack=0;
948                 numescaped=0;
949                 numflipped=0;
950                 numwallflipped=0;
951                 numthrowkill=0;
952                 numafterkill=0;
953                 numreversals=0;
954                 numattacks=0;
955                 maxalarmed=0;
956                 numresponded=0;
957
958                 bonustotal=startbonustotal;
959                 bonus=0;
960                 gameon=1;
961                 changedelay=0;
962                 if(console)
963                 {
964                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
965                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
966                         OPENAL_SetPaused(channels[consolesuccesssound], false);
967                         freeze=0;
968                         console=0;
969                 }
970
971                 if(!stealthloading)
972                 {
973                         terrain.numdecals=0;
974                         sprites.numsprites=0;
975                         for(i=0;i<objects.numobjects;i++)
976                         {
977                                 objects.model[i].numdecals=0;
978                         }
979
980                         j=objects.numobjects;
981                         for(i=0;i<j;i++)
982                         {
983                                 objects.DeleteObject(0);
984                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
985                         }
986
987                         for(i=0;i<subdivision;i++)
988                         {
989                                 for(j=0;j<subdivision;j++)
990                                 {
991                                         terrain.patchobjectnum[i][j]=0;
992                                 }
993                         }
994                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
995                 }
996
997                 weapons.numweapons=0;
998
999                 funpackf(tfile, "Bi", &mapvers);
1000                 if(mapvers>=15)funpackf(tfile, "Bi", &indemo);
1001                 else indemo=0;
1002                 if(mapvers>=5)funpackf(tfile, "Bi", &maptype);
1003                 else maptype=mapkilleveryone;
1004                 if(mapvers>=6)funpackf(tfile, "Bi", &hostile);
1005                 else hostile=1;
1006                 if(mapvers>=4)funpackf(tfile, "Bf Bf", &viewdistance, &fadestart);
1007                 else
1008                 {
1009                         viewdistance=100;
1010                         fadestart=.6;
1011                 }
1012                 if(mapvers>=2)funpackf(tfile, "Bb Bf Bf Bf", &skyboxtexture, &skyboxr, &skyboxg, &skyboxb);
1013                 else
1014                 {
1015                         skyboxtexture=1;
1016                         skyboxr=1;
1017                         skyboxg=1;
1018                         skyboxb=1;
1019                 }
1020                 if(mapvers>=10)funpackf(tfile, "Bf Bf Bf", &skyboxlightr, &skyboxlightg, &skyboxlightb);
1021                 else
1022                 {
1023                         skyboxlightr=skyboxr;
1024                         skyboxlightg=skyboxg;
1025                         skyboxlightb=skyboxb;
1026                 }
1027                 if(!stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &player[0].coords.x,&player[0].coords.y,&player[0].coords.z,&player[0].rotation,&player[0].targetrotation, &player[0].num_weapons);
1028                 if(stealthloading)funpackf(tfile, "Bf Bf Bf Bf Bf Bi", &lamefloat,&lamefloat,&lamefloat,&lamefloat,&lamefloat, &player[0].num_weapons);
1029                 player[0].originalcoords=player[0].coords;
1030                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
1031                 {
1032                         for(j=0;j<player[0].num_weapons;j++)
1033                         {
1034                                 player[0].weaponids[j]=weapons.numweapons;
1035                                 funpackf(tfile, "Bi", &weapons.type[weapons.numweapons]);
1036                                 weapons.owner[weapons.numweapons]=0;
1037                                 weapons.numweapons++;
1038                         }
1039                 }
1040
1041                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1042
1043                 funpackf(tfile, "Bf Bf Bf", &player[0].armorhead, &player[0].armorhigh, &player[0].armorlow);
1044                 funpackf(tfile, "Bf Bf Bf", &player[0].protectionhead, &player[0].protectionhigh, &player[0].protectionlow);
1045                 funpackf(tfile, "Bf Bf Bf", &player[0].metalhead, &player[0].metalhigh, &player[0].metallow);
1046                 funpackf(tfile, "Bf Bf", &player[0].power, &player[0].speedmult);
1047
1048                 funpackf(tfile, "Bi", &player[0].numclothes);
1049
1050                 if(mapvers>=9)
1051                 {
1052                         funpackf(tfile, "Bi Bi", &player[0].whichskin, &player[0].creature);
1053                 }
1054                 else
1055                 {
1056                         player[0].whichskin=0;
1057                         player[0].creature=rabbittype;
1058                 }
1059
1060                 for(i=0;i<max_dialogues;i++)
1061                 {
1062                         for(j=0;j<max_dialoguelength;j++)
1063                         {
1064                                 for(k=0;k<128;k++)
1065                                 {
1066                                         dialoguetext[i][j][k]='\0';
1067                                 }
1068                                 for(k=0;k<64;k++)
1069                                 {
1070                                         dialoguename[i][j][k]='\0';
1071                                 }
1072                         }
1073                 }
1074
1075                 player[0].lastattack=-1;
1076                 player[0].lastattack2=-1;
1077                 player[0].lastattack3=-1;
1078
1079                 if(mapvers>=8)
1080                 {
1081                         funpackf(tfile, "Bi", &numdialogues);
1082                         if(numdialogues)
1083                         {
1084                                 for(k=0;k<numdialogues;k++)
1085                                 {
1086                                         funpackf(tfile, "Bi", &numdialogueboxes[k]);
1087                                         funpackf(tfile, "Bi", &dialoguetype[k]);
1088                                         for(l=0;l<10;l++)
1089                                         {
1090                                                 funpackf(tfile, "Bf Bf Bf", &participantlocation[k][l].x, &participantlocation[k][l].y, &participantlocation[k][l].z);
1091                                                 funpackf(tfile, "Bf", &participantrotation[k][l]);
1092                                         }
1093                                         if(numdialogueboxes)
1094                                         {
1095                                                 for(l=0;l<numdialogueboxes[k];l++)
1096                                                 {
1097                                                         funpackf(tfile, "Bi", &dialogueboxlocation[k][l]);
1098                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][0]);
1099                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][1]);
1100                                                         funpackf(tfile, "Bf", &dialogueboxcolor[k][l][2]);
1101                                                         funpackf(tfile, "Bi", &dialogueboxsound[k][l]);
1102
1103                                                         bool doneread;
1104
1105                                                         funpackf(tfile, "Bi",&templength);
1106                                                         if(templength>128||templength<=0)templength=128;
1107                                                         for(m=0;m<templength;m++){
1108                                                                 funpackf(tfile, "Bb", &dialoguetext[k][l][m]);
1109                                                                 if(dialoguetext[k][l][m]=='\0')break;
1110                                                         }
1111
1112                                                         funpackf(tfile, "Bi",&templength);
1113                                                         if(templength>64||templength<=0)templength=64;
1114                                                         for(m=0;m<templength;m++){
1115                                                                 funpackf(tfile, "Bb", &dialoguename[k][l][m]);
1116                                                                 if(dialoguename[k][l][m]=='\0'){
1117                                                                         break;
1118                                                                 }
1119                                                         }
1120                                                         funpackf(tfile, "Bf Bf Bf", &dialoguecamera[k][l].x, &dialoguecamera[k][l].y, &dialoguecamera[k][l].z);
1121                                                         funpackf(tfile, "Bi", &participantfocus[k][l]);
1122                                                         funpackf(tfile, "Bi", &participantaction[k][l]);
1123
1124                                                         for(m=0;m<10;m++)
1125                                                                 funpackf(tfile, "Bf Bf Bf", &participantfacing[k][l][m].x, &participantfacing[k][l][m].y, &participantfacing[k][l][m].z);
1126
1127                                                         funpackf(tfile, "Bf Bf",&dialoguecamerarotation[k][l],&dialoguecamerarotation2[k][l]);
1128                                                 }
1129                                         }
1130                                 }
1131                         }
1132                 }
1133                 else numdialogues=0;
1134
1135                 if(player[0].numclothes)
1136                 {
1137                         for(k=0;k<player[0].numclothes;k++)
1138                         {
1139                                 funpackf(tfile, "Bi", &templength);
1140                                 for(l=0;l<templength;l++)
1141                                         funpackf(tfile, "Bb", &player[0].clothes[k][l]);
1142                                 player[0].clothes[k][templength]='\0';
1143                                 funpackf(tfile, "Bf Bf Bf", &player[0].clothestintr[k], &player[0].clothestintg[k], &player[0].clothestintb[k]);
1144                         }
1145                 }
1146
1147                 funpackf(tfile, "Bi", &environment);
1148
1149                 funpackf(tfile, "Bi", &objects.numobjects);
1150                 if(objects.numobjects)
1151                 {
1152                         for(i=0;i<objects.numobjects;i++)
1153                         {
1154                                 funpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", &objects.type[i],&objects.rotation[i],&objects.rotation2[i], &objects.position[i].x, &objects.position[i].y, &objects.position[i].z,&objects.scale[i]);
1155                                 if(objects.type[i]==treeleavestype)objects.scale[i]=objects.scale[i-1];
1156                         }
1157                 }
1158
1159                 if(mapvers>=7)
1160                 {
1161                         funpackf(tfile, "Bi", &numhotspots);
1162                         if(numhotspots)
1163                         {
1164                                 for(i=0;i<numhotspots;i++)
1165                                 {
1166                                         funpackf(tfile, "Bi Bf Bf Bf Bf", &hotspottype[i],&hotspotsize[i],&hotspot[i].x,&hotspot[i].y,&hotspot[i].z);
1167                                         funpackf(tfile, "Bi", &templength);
1168                                         if(templength)
1169                                                 for(l=0;l<templength;l++)
1170                                                         funpackf(tfile, "Bb", &hotspottext[i][l]);
1171                                         hotspottext[i][templength]='\0';
1172                                         if(hotspottype[i]==-111)indemo=1;
1173                                 }
1174                         }
1175                 }
1176                 else numhotspots=0;
1177
1178                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1179
1180                 if(!stealthloading)
1181                 {
1182                         objects.center=0;
1183                         for(i=0;i<objects.numobjects;i++)
1184                         {
1185                                 objects.center+=objects.position[i];
1186                         }
1187                         objects.center/=objects.numobjects;
1188
1189
1190                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1191
1192                         float maxdistance=0;
1193                         float tempdist;
1194                         int whichclosest;
1195                         for(i=0;i<objects.numobjects;i++)
1196                         {
1197                                 tempdist=findDistancefast(&objects.center,&objects.position[i]);
1198                                 if(tempdist>maxdistance)
1199                                 {
1200                                         whichclosest=i;
1201                                         maxdistance=tempdist;
1202                                 }
1203                         }
1204                         objects.radius=fast_sqrt(maxdistance);
1205                 }
1206
1207                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1208                 //mapcenter=objects.center;
1209                 //mapradius=objects.radius;
1210
1211                 funpackf(tfile, "Bi", &numplayers);
1212                 int howmanyremoved=0;
1213                 bool removeanother=0;
1214                 if(numplayers>1&&numplayers<maxplayers)
1215                 {
1216                         for(i=1;i<numplayers;i++)
1217                         {
1218                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1219                                 removeanother=0;
1220
1221                                 funpackf(tfile, "Bi Bi Bf Bf Bf Bi",&player[i-howmanyremoved].whichskin,&player[i-howmanyremoved].creature, &player[i-howmanyremoved].coords.x,&player[i-howmanyremoved].coords.y,&player[i-howmanyremoved].coords.z,&player[i-howmanyremoved].num_weapons);
1222                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].howactive);
1223                                 else player[i-howmanyremoved].howactive=typeactive;
1224                                 if(mapvers>=3)funpackf(tfile, "Bf",&player[i-howmanyremoved].scale);
1225                                 else player[i-howmanyremoved].scale=-1;
1226                                 if(mapvers>=11)funpackf(tfile, "Bb",&player[i-howmanyremoved].immobile);
1227                                 else player[i-howmanyremoved].immobile=0;
1228                                 if(mapvers>=12)funpackf(tfile, "Bf",&player[i-howmanyremoved].rotation);
1229                                 else player[i-howmanyremoved].rotation=0;
1230                                 player[i-howmanyremoved].targetrotation=player[i-howmanyremoved].rotation;
1231                                 if(player[i-howmanyremoved].num_weapons<0||player[i-howmanyremoved].num_weapons>5){
1232                                         removeanother=1;
1233                                         howmanyremoved++;
1234                                 }
1235                                 if(!removeanother)
1236                                 {
1237                                         if(player[i-howmanyremoved].num_weapons>0&&player[i-howmanyremoved].num_weapons<5)
1238                                         {
1239                                                 for(j=0;j<player[i-howmanyremoved].num_weapons;j++)
1240                                                 {
1241                                                         player[i-howmanyremoved].weaponids[j]=weapons.numweapons;
1242                                                         funpackf(tfile, "Bi", &weapons.type[player[i-howmanyremoved].weaponids[j]]);
1243                                                         weapons.owner[player[i-howmanyremoved].weaponids[j]]=i;
1244                                                         weapons.numweapons++;
1245                                                 }
1246                                         }
1247                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numwaypoints);
1248                                         //player[i-howmanyremoved].numwaypoints=10;
1249                                         for(j=0;j<player[i-howmanyremoved].numwaypoints;j++)
1250                                         {
1251                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].x);
1252                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].y);
1253                                                 funpackf(tfile, "Bf", &player[i-howmanyremoved].waypoints[j].z);
1254                                                 if(mapvers>=5)funpackf(tfile, "Bi", &player[i-howmanyremoved].waypointtype[j]);
1255                                                 else player[i-howmanyremoved].waypointtype[j] = wpkeepwalking;
1256                                         }
1257
1258                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].waypoint);
1259                                         if(player[i-howmanyremoved].waypoint>player[i-howmanyremoved].numwaypoints-1)player[i-howmanyremoved].waypoint=0;
1260
1261                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].armorhead, &player[i-howmanyremoved].armorhigh, &player[i-howmanyremoved].armorlow);
1262                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].protectionhead, &player[i-howmanyremoved].protectionhigh, &player[i-howmanyremoved].protectionlow);
1263                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].metalhead, &player[i-howmanyremoved].metalhigh, &player[i-howmanyremoved].metallow);
1264                                         funpackf(tfile, "Bf Bf", &player[i-howmanyremoved].power, &player[i-howmanyremoved].speedmult);
1265
1266                                         if(mapvers>=4)funpackf(tfile, "Bf Bf Bf Bf", &headprop, &bodyprop, &armprop, &legprop);
1267                                         else
1268                                         {
1269                                                 headprop=1;
1270                                                 bodyprop=1;
1271                                                 armprop=1;
1272                                                 legprop=1;
1273                                         }
1274                                         if(player[i-howmanyremoved].creature==wolftype)
1275                                         {
1276                                                 player[i-howmanyremoved].proportionhead=1.1*headprop;
1277                                                 player[i-howmanyremoved].proportionbody=1.1*bodyprop;
1278                                                 player[i-howmanyremoved].proportionarms=1.1*armprop;
1279                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1280                                         }
1281
1282                                         if(player[i-howmanyremoved].creature==rabbittype)
1283                                         {
1284                                                 player[i-howmanyremoved].proportionhead=1.2*headprop;
1285                                                 player[i-howmanyremoved].proportionbody=1.05*bodyprop;
1286                                                 player[i-howmanyremoved].proportionarms=1.00*armprop;
1287                                                 player[i-howmanyremoved].proportionlegs=1.1*legprop;
1288                                                 player[i-howmanyremoved].proportionlegs.y=1.05*legprop;
1289                                         }
1290
1291                                         funpackf(tfile, "Bi", &player[i-howmanyremoved].numclothes);
1292                                         if(player[i-howmanyremoved].numclothes)
1293                                         {
1294                                                 for(k=0;k<player[i-howmanyremoved].numclothes;k++)
1295                                                 {
1296                                                         int templength;
1297                                                         funpackf(tfile, "Bi", &templength);
1298                                                         for(l=0;l<templength;l++)
1299                                                                 funpackf(tfile, "Bb", &player[i-howmanyremoved].clothes[k][l]);
1300                                                         player[i-howmanyremoved].clothes[k][templength]='\0';
1301                                                         funpackf(tfile, "Bf Bf Bf", &player[i-howmanyremoved].clothestintr[k], &player[i-howmanyremoved].clothestintg[k], &player[i-howmanyremoved].clothestintb[k]);
1302                                                 }
1303                                         }
1304                                 }
1305                         }
1306                 }
1307                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1308
1309                 numplayers-=howmanyremoved;
1310                 funpackf(tfile, "Bi", &numpathpoints);
1311                 if(numpathpoints>30||numpathpoints<0)
1312                         numpathpoints=0;
1313                 if(numpathpoints)
1314                 {
1315                         for(j=0;j<numpathpoints;j++)
1316                         {
1317                                 funpackf(tfile, "Bf Bf Bf Bi", &pathpoint[j].x,&pathpoint[j].y,&pathpoint[j].z,&numpathpointconnect[j]);
1318                                 for(k=0;k<numpathpointconnect[j];k++){
1319                                         funpackf(tfile, "Bi", &pathpointconnect[j][k]);
1320                                 }
1321                         }
1322                 }
1323                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1324
1325                 funpackf(tfile, "Bf Bf Bf Bf", &mapcenter.x,&mapcenter.y,&mapcenter.z,&mapradius);
1326
1327                 SetUpLighting();
1328                 if(environment!=oldenvironment)Setenvironment(environment);
1329                 oldenvironment=environment;
1330
1331                 if(!stealthloading)
1332                 {
1333                         j=objects.numobjects;
1334                         objects.numobjects=0;
1335                         for(i=0;i<j;i++)
1336                         {
1337                                 //if(objects.type[i]!=spiketype)
1338                                 objects.MakeObject(objects.type[i],objects.position[i],objects.rotation[i],objects.rotation2[i],objects.scale[i]);
1339                                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1340                         }
1341
1342                         //if(skyboxtexture){
1343                         terrain.DoShadows();
1344                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1345                         objects.DoShadows();
1346                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1347                         /*}
1348                         else terrain.DoLighting();
1349                         */
1350                 }
1351
1352                 fclose(tfile);
1353
1354                 oldlevel=whichlevel;
1355
1356
1357                 if(numplayers>maxplayers-1)numplayers=maxplayers-1;
1358                 for(i=0;i<numplayers;i++)
1359                 {
1360                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1361                         player[i].burnt=0;
1362                         player[i].bled=0;
1363                         player[i].onfire=0;
1364                         if(i==0||player[i].scale<0)player[i].scale=.2;
1365                         player[i].skeleton.free=0;
1366                         player[i].skeleton.id=i;
1367                         //if(Random()%2==0)player[i].creature=wolftype;
1368                         //else player[i].creature=rabbittype;
1369                         if(i==0&&mapvers<9)player[i].creature=rabbittype;
1370                         if(player[i].creature!=wolftype)player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",0);
1371                         else
1372                         {
1373                                 if(player[i].creature!=wolftype){
1374                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure",(char *)":Data:Skeleton:Basic Figurelow",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Body.solid",(char *)":Data:Models:Body2.solid",(char *)":Data:Models:Body3.solid",(char *)":Data:Models:Body4.solid",(char *)":Data:Models:Body5.solid",(char *)":Data:Models:Body6.solid",(char *)":Data:Models:Body7.solid",(char *)":Data:Models:Bodylow.solid",(char *)":Data:Models:Belt.solid",1);
1375                                         LoadTexture(":Data:Textures:Belt.png",&player[i].skeleton.drawmodelclothes.textureptr,1,1);
1376                                 }
1377                                 if(player[i].creature==wolftype){
1378                                         player[i].skeleton.Load((char *)":Data:Skeleton:Basic Figure Wolf",(char *)":Data:Skeleton:Basic Figure Wolf Low",(char *)":Data:Skeleton:Rabbitbelt",(char *)":Data:Models:Wolf.solid",(char *)":Data:Models:Wolf2.solid",(char *)":Data:Models:Wolf3.solid",(char *)":Data:Models:Wolf4.solid",(char *)":Data:Models:Wolf5.solid",(char *)":Data:Models:Wolf6.solid",(char *)":Data:Models:Wolf7.solid",(char *)":Data:Models:Wolflow.solid",(char *)":Data:Models:Belt.solid",0);
1379                                 }
1380                         }
1381
1382
1383                         int texsize;
1384                         texsize=512*512*3/texdetail/texdetail;
1385                         //if(!player[i].loaded)player[i].skeleton.skinText = new GLubyte[texsize];
1386                         //player[i].skeleton.skinText.resize(texsize);
1387
1388                         if(player[i].creature==rabbittype)
1389                         {
1390                                 if(player[i].whichskin==0){
1391                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1392                                 }
1393                                 else if(player[i].whichskin==1){
1394                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1395                                 }
1396                                 else if(player[i].whichskin==2){
1397                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1398                                 }
1399                                 else if(player[i].whichskin==3){
1400                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1401                                 }
1402                                 else if(player[i].whichskin==4){
1403                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1404                                 }
1405                                 else if(player[i].whichskin==5){
1406                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1407                                 }
1408                                 else if(player[i].whichskin==6){
1409                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1410                                 }
1411                                 else if(player[i].whichskin==7){
1412                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1413                                 }
1414                                 else if(player[i].whichskin==8){
1415                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1416                                 }
1417                                 else if(player[i].whichskin==9){
1418                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1419                                 }
1420                         }
1421                         if(player[i].creature==wolftype)
1422                         {
1423                                 //k=abs(Random()%3);
1424                                 if(player[i].whichskin==0){
1425                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1426                                 }
1427                                 else if(player[i].whichskin==1){
1428                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1429                                 }
1430                                 else if(player[i].whichskin==2){
1431                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[i].skeleton.drawmodel.textureptr,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1432                                 }
1433                         }
1434
1435                         if(player[i].numclothes)
1436                         {
1437                                 for(j=0;j<player[i].numclothes;j++)
1438                                 {
1439                                         tintr=player[i].clothestintr[j];
1440                                         tintg=player[i].clothestintg[j];
1441                                         tintb=player[i].clothestintb[j];
1442                                         AddClothes((char *)player[i].clothes[j],0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
1443                                 }
1444                                 player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
1445                         }
1446
1447                         player[i].currentanimation=bounceidleanim;
1448                         player[i].targetanimation=bounceidleanim;
1449                         player[i].currentframe=0;
1450                         player[i].targetframe=1;
1451                         player[i].target=0;
1452                         player[i].speed=1+(float)(Random()%100)/1000;
1453                         if(difficulty==0)player[i].speed-=.2;
1454                         if(difficulty==1)player[i].speed-=.1;
1455
1456                         player[i].velocity=0;
1457                         player[i].oldcoords=player[i].coords;
1458                         player[i].realoldcoords=player[i].coords;
1459
1460                         player[i].id=i;
1461                         player[i].skeleton.id=i;
1462                         player[i].updatedelay=0;
1463                         player[i].normalsupdatedelay=0;
1464
1465                         player[i].aitype=passivetype;
1466                         player[i].aitarget=0;
1467                         player[i].madskills=0;
1468
1469                         if(i==0)
1470                         {
1471                                 player[i].proportionhead=1.2;
1472                                 player[i].proportionbody=1.05;
1473                                 player[i].proportionarms=1.00;
1474                                 player[i].proportionlegs=1.1;
1475                                 player[i].proportionlegs.y=1.05;
1476                         }
1477                         player[i].headless=0;
1478                         player[i].currentoffset=0;
1479                         player[i].targetoffset=0;
1480                         /*player[i].armorhead=1;
1481                         player[i].armorhigh=1;
1482                         player[i].armorlow=1;
1483                         player[i].protectionhead=1;
1484                         player[i].protectionhigh=1;
1485                         player[i].protectionlow=1;
1486                         player[i].metalhead=1;
1487                         player[i].metalhigh=1;
1488                         player[i].metallow=1;
1489                         player[i].power=1;
1490                         player[i].speedmult=1;*/
1491
1492                         player[i].damagetolerance=200;
1493
1494                         if(player[i].creature==wolftype)
1495                         {
1496                                 /*player[i].proportionhead=1.1;
1497                                 player[i].proportionbody=1.1;
1498                                 player[i].proportionarms=1.1;
1499                                 player[i].proportionlegs=1.1;
1500                                 player[i].proportionlegs.y=1.1;*/
1501                                 if(i==0||player[i].scale<0)player[i].scale=.23;
1502
1503                                 player[i].damagetolerance=300;
1504                         }
1505
1506                         if(visibleloading){loadscreencolor=4; LoadingScreen();}
1507                         if(cellophane)
1508                         {
1509                                 player[i].proportionhead.z=0;
1510                                 player[i].proportionbody.z=0;
1511                                 player[i].proportionarms.z=0;
1512                                 player[i].proportionlegs.z=0;
1513                         }
1514
1515                         player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
1516
1517                         player[i].headmorphness=0;
1518                         player[i].targetheadmorphness=1;
1519                         player[i].headmorphstart=0;
1520                         player[i].headmorphend=0;
1521
1522                         player[i].pausetime=0;
1523
1524                         player[i].dead=0;
1525                         player[i].jumppower=5;
1526                         player[i].damage=0;
1527                         player[i].permanentdamage=0;
1528                         player[i].superpermanentdamage=0;
1529
1530                         player[i].forwardkeydown=0;
1531                         player[i].leftkeydown=0;
1532                         player[i].backkeydown=0;
1533                         player[i].rightkeydown=0;
1534                         player[i].jumpkeydown=0;
1535                         player[i].crouchkeydown=0;
1536                         player[i].throwkeydown=0;
1537
1538                         player[i].collided=-10;
1539                         player[i].loaded=1;
1540                         player[i].bloodloss=0;
1541                         player[i].weaponactive=-1;
1542                         player[i].weaponstuck=-1;
1543                         player[i].bleeding=0;
1544                         player[i].deathbleeding=0;
1545                         player[i].stunned=0;
1546                         player[i].hasvictim=0;
1547                         player[i].wentforweapon=0;
1548                 }
1549
1550                 player[0].aitype=playercontrolled;
1551                 player[0].weaponactive=-1;
1552
1553                 if(difficulty==1)
1554                 {
1555                         //player[0].speedmult=1/.9;
1556                         player[0].power=1/.9;
1557                 }
1558
1559                 if(difficulty==0)
1560                 {
1561                         //player[0].speedmult=1/.8;
1562                         player[0].power=1/.8;
1563                 }
1564
1565                 //player[0].weaponstuck=1;
1566
1567                 if(difficulty==1)player[0].damagetolerance=250;
1568                 if(difficulty==0)player[0].damagetolerance=300;
1569                 if(difficulty==0)player[0].armorhead*=1.5;
1570                 if(difficulty==0)player[0].armorhigh*=1.5;
1571                 if(difficulty==0)player[0].armorlow*=1.5;
1572                 cameraloc=player[0].coords;
1573                 cameraloc.y+=5;
1574                 rotation=player[0].rotation;
1575
1576                 hawkcoords=player[0].coords;
1577                 hawkcoords.y+=30;
1578
1579                 if(visibleloading){loadscreencolor=4; LoadingScreen();}
1580                 //weapons.numweapons=numplayers;
1581                 for(i=0;i<weapons.numweapons;i++)
1582                 {
1583                         weapons.bloody[i]=0;
1584                         weapons.blooddrip[i]=0;
1585                         weapons.blooddripdelay[i]=0;
1586                         weapons.onfire[i]=0;
1587                         weapons.flamedelay[i]=0;
1588                         weapons.damage[i]=0;
1589                         //weapons.type[i]=sword;
1590                         if(weapons.type[i]==sword){
1591                                 weapons.mass[i]=1.5;
1592                                 weapons.tipmass[i]=1;
1593                                 weapons.length[i]=.8;
1594                         }
1595                         if(weapons.type[i]==staff){
1596                                 weapons.mass[i]=2;
1597                                 weapons.tipmass[i]=1;
1598                                 weapons.length[i]=1.5;
1599                         }
1600                         if(weapons.type[i]==knife){
1601                                 weapons.mass[i]=1;
1602                                 weapons.tipmass[i]=1.2;
1603                                 weapons.length[i]=.25;
1604                         }
1605                         weapons.position[i]=-1000;
1606                         weapons.tippoint[i]=-1000;
1607                 }
1608
1609 /*              for(i=0;i<32;i++){
1610                         //if(i<16||i>20)
1611                         OPENAL_StopSound(i);
1612                 }
1613 */
1614                 LOG("Starting background music...");
1615
1616                 OPENAL_StopSound(OPENAL_ALL);
1617                 if(environment==snowyenvironment)
1618                 {
1619                         if(ambientsound)
1620                         {
1621                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1622                                 OPENAL_SetPaused(channels[stream_wind], false);
1623                                 OPENAL_SetVolume(channels[stream_wind], 256);
1624                         }
1625                 }
1626                 else if(environment==desertenvironment)
1627                 {
1628                         if(ambientsound)
1629                         {
1630                                 //PlaySoundEx(desertambient,
1631                                 //      samp[desertambient], NULL, true);
1632                                 PlayStreamEx(stream_desertambient,
1633                                         strm[stream_desertambient], NULL, true);
1634                                 OPENAL_SetPaused(channels[stream_desertambient], false);
1635                                 OPENAL_SetVolume(channels[stream_desertambient], 256);
1636                         }
1637                 }
1638                 else if(environment==grassyenvironment)
1639                 {
1640                         if(ambientsound)
1641                         {
1642                                 //PlaySoundEx(wind, samp[wind], NULL, true);
1643                                 PlayStreamEx(stream_wind, strm[stream_wind], NULL, true);
1644                                 OPENAL_SetPaused(channels[stream_wind], false);
1645                                 OPENAL_SetVolume(channels[stream_wind], 100);
1646                         }
1647                 }
1648                 oldmusicvolume[0]=0;
1649                 oldmusicvolume[1]=0;
1650                 oldmusicvolume[2]=0;
1651                 oldmusicvolume[3]=0;
1652
1653
1654                 /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
1655                 LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
1656                 LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
1657                 LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
1658                 LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
1659                 LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
1660                 LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
1661                 LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
1662                 */
1663
1664                 if(!firstload)
1665                 {
1666                         firstload=1;
1667                 }
1668         }
1669         leveltime=0;
1670         loadingstuff=0;
1671         visibleloading=0;
1672 }
1673
1674 void    Game::Tick()
1675 {
1676         static int i,k,j,l,m;
1677         static XYZ facing,flatfacing,absflatfacing;
1678         static XYZ rotatetarget;
1679         static bool oldkey;
1680         static float oldtargetrotation;
1681         static int target, numgood;
1682         static XYZ tempcoords1,tempcoords2;
1683         static XYZ test;
1684         static XYZ test2;
1685         static XYZ lowpoint,lowpointtarget,lowpoint2,lowpointtarget2,lowpoint3,lowpointtarget3,lowpoint4,lowpointtarget4,lowpoint5,lowpointtarget5,lowpoint6,lowpointtarget6,lowpoint7,lowpointtarget7,colpoint,colpoint2;
1686         static int whichhit;
1687         static bool donesomething;
1688         static bool oldjumpkeydown;
1689
1690         int templength;
1691
1692         float headprop,bodyprop,armprop,legprop;
1693
1694         if(newnetmessages){
1695                 newnetmessages=0;
1696                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
1697                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
1698                 OPENAL_SetPaused(channels[consolesuccesssound], false);
1699
1700                 for(k=14;k>=2;k--){
1701                         for(j=0;j<255;j++){
1702                                 consoletext[k][j]=consoletext[k-1][j];
1703                         }
1704                         consolechars[k]=consolechars[k-1];
1705                 }
1706                 for(k=14;k>=2;k--){
1707                         for(j=0;j<255;j++){
1708                                 displaytext[k][j]=displaytext[k-1][j];
1709                         }
1710                         displaychars[k]=displaychars[k-1];
1711                         displaytime[k]=displaytime[k-1];
1712                 }
1713                 for(j=0;j<255;j++){
1714                         consoletext[1][j]=' ';
1715                         displaytext[1][j]=' ';
1716                 }
1717                 sprintf (consoletext[1], netmessages);
1718                 sprintf (displaytext[1], netmessages);
1719                 consolechars[1]=255;
1720                 displaychars[1]=255;
1721                 displaytime[1]=0;
1722         }
1723
1724         for(i=0;i<15;i++){
1725                 displaytime[i]+=multiplier;
1726         }
1727
1728         static unsigned char    theKeyMap[16];
1729         GetKeys( theKeyMap );
1730
1731         keyboardfrozen=0;
1732
1733
1734         static bool mainmenutogglekeydown;
1735         if(!console){
1736                 if(mainmenu&&endgame==1)mainmenu=10;
1737                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
1738                         for(j=0;j<255;j++){
1739                                 displaytext[0][j]=' ';
1740                         }
1741                         displaychars[0]=0;
1742                         displayselected=0;
1743                         entername=0;
1744                         mainmenutogglekeydown=1;
1745                 }
1746                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||(mainmenu==12&&!tryquit)||mainmenu==13||mainmenu==14||mainmenu==15||mainmenu==16||mainmenu==17||mainmenu==10)){
1747                         selected=-1;
1748                         if(mainmenu==1||mainmenu==2||mainmenu==0){
1749                                 if(mainmenu==0&&!winfreeze)mainmenu=2;
1750                                 else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
1751                                 else if(mainmenu==0&&winfreeze){
1752                                         /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
1753                                         stealthloading=1;
1754                                         else stealthloading=0;
1755
1756                                         if(!stealthloading){
1757                                         float gLoc[3]={0,0,0};
1758                                         float vel[3]={0,0,0};
1759                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
1760                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
1761                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
1762                                         OPENAL_SetVolume(channels[firestartsound], 256);
1763                                         OPENAL_SetPaused(channels[firestartsound], false);
1764                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
1765
1766                                         flashr=1;
1767                                         flashg=0;
1768                                         flashb=0;
1769                                         flashamount=1;
1770                                         flashdelay=1;
1771                                         }
1772
1773                                         startbonustotal=0;
1774
1775                                         for(i=0;i<campaignnumlevels;i++){
1776                                         levelvisible[i]=0;
1777                                         levelhighlight[i]=0;
1778                                         }
1779
1780                                         levelorder[0]=0;
1781                                         levelvisible[0]=1;
1782                                         if(accountcampaignchoicesmade[accountactive])
1783                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
1784                                         levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
1785                                         levelvisible[levelorder[i+1]]=1;
1786                                         }
1787                                         int whichlevelstart;
1788                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
1789                                         if(whichlevelstart<0){
1790                                         campaignchoicenum=1;
1791                                         campaignchoicewhich[0]=0;
1792                                         }
1793                                         else
1794                                         {
1795                                         campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
1796                                         if(campaignchoicenum)
1797                                         for(i=0;i<campaignchoicenum;i++){
1798                                         campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
1799                                         levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1800                                         levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
1801                                         }
1802                                         }
1803
1804                                         loading=2;
1805                                         loadtime=0;
1806                                         targetlevel=7;
1807                                         if(firstload)TickOnceAfter();
1808                                         if(!firstload)LoadStuff();
1809                                         //else {
1810                                         for(i=0;i<255;i++){
1811                                         mapname[i]='\0';
1812                                         }
1813                                         mapname[0]=':';
1814                                         mapname[1]='D';
1815                                         mapname[2]='a';
1816                                         mapname[3]='t';
1817                                         mapname[4]='a';
1818                                         mapname[5]=':';
1819                                         mapname[6]='M';
1820                                         mapname[7]='a';
1821                                         mapname[8]='p';
1822                                         mapname[9]='s';
1823                                         mapname[10]=':';
1824
1825                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
1826                                         //accountcampaignchoicesmade[accountactive]++;
1827
1828
1829                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
1830                                         whichchoice=0;
1831                                         visibleloading=1;
1832                                         stillloading=1;
1833                                         Loadlevel(mapname);
1834                                         campaign=1;
1835                                         mainmenu=0;
1836                                         gameon=1;
1837                                         OPENAL_SetPaused(channels[music3], true);
1838
1839                                         stealthloading=0;*/
1840                                 }
1841                                 else if(mainmenu==1||mainmenu==2)mainmenu=0;
1842                                 if(mainmenu&&musictoggle){
1843                                         if(mainmenu==1||mainmenu==2||mainmenu==100){
1844                                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
1845                                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
1846                                                 OPENAL_SetPaused(channels[stream_music3], false);
1847                                                 OPENAL_SetVolume(channels[stream_music3], 256);
1848                                                 OPENAL_SetPaused(channels[music1], true);
1849                                         }
1850                                 }
1851                                 if(!mainmenu){
1852                                         OPENAL_SetPaused(channels[stream_music3], true);
1853                                         OPENAL_SetPaused(channels[music1], false);
1854                                 }
1855                         }
1856                         if(mainmenu==3){
1857                                 float gLoc[3]={0,0,0};
1858                                 float vel[3]={0,0,0};
1859                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1860                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1861                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1862                                 OPENAL_SetVolume(channels[fireendsound], 256);
1863                                 OPENAL_SetPaused(channels[fireendsound], false);
1864                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1865
1866                                 flashr=1;
1867                                 flashg=0;
1868                                 flashb=0;
1869                                 flashamount=1;
1870                                 flashdelay=1;
1871
1872                                 if(newdetail>2)newdetail=detail;
1873                                 if(newdetail<0)newdetail=detail;
1874 #if !USE_SDL  // we'll take anything that works.
1875                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
1876                                 if(newscreenheight>3000)newscreenheight=screenheight;
1877 #endif
1878                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
1879                                 if(newscreenheight<0)newscreenheight=screenheight;
1880
1881                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
1882                                 opstream << "Screenwidth:\n";
1883                                 opstream << newscreenwidth;
1884                                 opstream << "\nScreenheight:\n";
1885                                 opstream << newscreenheight;
1886                                 opstream << "\nMouse sensitivity:\n";
1887                                 opstream << usermousesensitivity;
1888                                 opstream << "\nBlur(0,1):\n";
1889                                 opstream << ismotionblur;
1890                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
1891                                 opstream << newdetail;
1892                                 opstream << "\nFloating jump:\n";
1893                                 opstream << floatjump;
1894                                 opstream << "\nMouse jump:\n";
1895                                 opstream << mousejump;
1896                                 opstream << "\nAmbient sound:\n";
1897                                 opstream << ambientsound;
1898                                 opstream << "\nBlood (0,1,2):\n";
1899                                 opstream << bloodtoggle;
1900                                 opstream << "\nAuto slomo:\n";
1901                                 opstream << autoslomo;
1902                                 opstream << "\nFoliage:\n";
1903                                 opstream << foliage;
1904                                 opstream << "\nMusic:\n";
1905                                 opstream << musictoggle;
1906                                 opstream << "\nTrilinear:\n";
1907                                 opstream << trilinear;
1908                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
1909                                 opstream << decals;
1910                                 opstream << "\nInvert mouse:\n";
1911                                 opstream << invertmouse;
1912                                 opstream << "\nGamespeed:\n";
1913                                 if(oldgamespeed==0)oldgamespeed=1;
1914                                 opstream << oldgamespeed;
1915                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
1916                                 opstream << difficulty;
1917                                 opstream << "\nDamage effects(blackout, doublevision):\n";
1918                                 opstream << damageeffects;
1919                                 opstream << "\nText:\n";
1920                                 opstream << texttoggle;
1921                                 opstream << "\nDebug:\n";
1922                                 opstream << debugmode;
1923                                 opstream << "\nVBL Sync:\n";
1924                                 opstream << vblsync;
1925                                 opstream << "\nShow Points:\n";
1926                                 opstream << showpoints;
1927                                 opstream << "\nAlways Blur:\n";
1928                                 opstream << alwaysblur;
1929                                 opstream << "\nImmediate mode (turn on on G5):\n";
1930                                 opstream << immediate;
1931                                 opstream << "\nVelocity blur:\n";
1932                                 opstream << velocityblur;
1933                             opstream << "\nVolume:\n";
1934                         opstream << volume;
1935                                 opstream << "\nForward key:\n";
1936                                 opstream << KeyToChar(forwardkey);
1937                                 opstream << "\nBack key:\n";
1938                                 opstream << KeyToChar(backkey);
1939                                 opstream << "\nLeft key:\n";
1940                                 opstream << KeyToChar(leftkey);
1941                                 opstream << "\nRight key:\n";
1942                                 opstream << KeyToChar(rightkey);
1943                                 opstream << "\nJump key:\n";
1944                                 opstream << KeyToChar(jumpkey);
1945                                 opstream << "\nCrouch key:\n";
1946                                 opstream << KeyToChar(crouchkey);
1947                                 opstream << "\nDraw key:\n";
1948                                 opstream << KeyToChar(drawkey);
1949                                 opstream << "\nThrow key:\n";
1950                                 opstream << KeyToChar(throwkey);
1951                                 opstream << "\nAttack key:\n";
1952                                 opstream << KeyToChar(attackkey);
1953                                 opstream << "\nChat key:\n";
1954                                 opstream << KeyToChar(chatkey);
1955                                 opstream.close();
1956                         }
1957                         if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==12||mainmenu==13||mainmenu==14||mainmenu==10||mainmenu==11||mainmenu==100){
1958                                 float gLoc[3]={0,0,0};
1959                                 float vel[3]={0,0,0};
1960                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
1961                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1962                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1963                                 OPENAL_SetVolume(channels[fireendsound], 256);
1964                                 OPENAL_SetPaused(channels[fireendsound], false);
1965                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
1966
1967                                 flashr=1;
1968                                 flashg=0;
1969                                 flashb=0;
1970                                 flashamount=1;
1971                                 flashdelay=1;
1972                         }
1973                         if(mainmenu==3&&gameon)mainmenu=2;
1974                         if(mainmenu==3&&!gameon)mainmenu=1;
1975                         if(mainmenu==5&&gameon)mainmenu=2;
1976                         if(mainmenu==5&&!gameon)mainmenu=1;
1977                         if(mainmenu==4)mainmenu=3;
1978                         if(mainmenu==6)mainmenu=5;
1979                         if(mainmenu==7)mainmenu=1;
1980                         if(mainmenu==9)mainmenu=5;
1981                         if(mainmenu==11)mainmenu=5;
1982                         if(mainmenu==12)mainmenu=5;
1983                         if(mainmenu==13)mainmenu=12;
1984                         if(mainmenu==14)mainmenu=13;
1985                         if(mainmenu==10)mainmenu=5;
1986                         if(mainmenu==100){
1987                                 mainmenu=5;
1988                                 gameon=0;
1989                                 winfreeze=0;
1990                         }
1991                         mainmenutogglekeydown=1;
1992                 }
1993                 if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
1994                         mainmenutogglekeydown=0;
1995                 }
1996         }
1997
1998         /*static bool minimaptogglekeydown;
1999         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
2000         minimap=1-minimap;
2001         minimaptogglekeydown=1;
2002         }
2003         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2004         minimaptogglekeydown=0;
2005         }
2006         */
2007
2008         static bool minimaptogglekeydown;
2009         if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
2010                 if(tutorialstage!=51)
2011                         tutorialstagetime=tutorialmaxtime;
2012                 PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
2013                 OPENAL_SetVolume(channels[consolefailsound], 128);
2014                 OPENAL_SetPaused(channels[consolefailsound], false);
2015                 minimaptogglekeydown=1;
2016         }
2017         if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
2018                 minimaptogglekeydown=0;
2019         }
2020
2021         if(mainmenu){
2022                 //menu buttons
2023                 if(mainmenu==1||mainmenu==2){
2024                         if(Button()&&!oldbutton&&selected==1){
2025                                 if(!gameon){
2026                                         float gLoc[3]={0,0,0};
2027                                         float vel[3]={0,0,0};
2028                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2029                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2030                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2031                                         OPENAL_SetVolume(channels[firestartsound], 256);
2032                                         OPENAL_SetPaused(channels[firestartsound], false);
2033                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2034
2035                                         flashr=1;
2036                                         flashg=0;
2037                                         flashb=0;
2038                                         flashamount=1;
2039                                         flashdelay=1;
2040
2041                                         //new game
2042                                         if(accountactive!=-1)mainmenu=5;
2043                                         else mainmenu=7;
2044                                         /*
2045                                         startbonustotal=0;
2046
2047                                         loading=2;
2048                                         loadtime=0;
2049                                         if(firstload)TickOnceAfter();
2050                                         if(!firstload)LoadStuff();
2051                                         else {
2052                                         Loadlevel(0);
2053                                         }
2054                                         mainmenu=0;
2055                                         gameon=1;
2056                                         OPENAL_SetPaused(channels[music3], true);       */
2057                                 }
2058                                 else
2059                                 {
2060                                         //resume
2061                                         mainmenu=0;
2062                                         OPENAL_SetPaused(channels[stream_music3], true);
2063                                         OPENAL_SetPaused(channels[music1], false);
2064                                 }
2065                         }
2066
2067                         if(Button()&&!oldbutton&&selected==2){
2068                                 float gLoc[3]={0,0,0};
2069                                 float vel[3]={0,0,0};
2070                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2071                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2072                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2073                                 OPENAL_SetVolume(channels[firestartsound], 256);
2074                                 OPENAL_SetPaused(channels[firestartsound], false);
2075                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2076
2077                                 flashr=1;
2078                                 flashg=0;
2079                                 flashb=0;
2080                                 flashamount=1;
2081                                 flashdelay=1;
2082
2083                                 //options
2084
2085                                 mainmenu=3;
2086
2087                                 if(newdetail>2)newdetail=detail;
2088                                 if(newdetail<0)newdetail=detail;
2089                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2090                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2091                                 if(newscreenheight>3000)newscreenheight=screenheight;
2092                                 if(newscreenheight<0)newscreenheight=screenheight;
2093                         }
2094
2095                         if(Button()&&!oldbutton&&selected==3){
2096                                 float gLoc[3]={0,0,0};
2097                                 float vel[3]={0,0,0};
2098                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2099                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2100                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2101                                 OPENAL_SetVolume(channels[fireendsound], 256);
2102                                 OPENAL_SetPaused(channels[fireendsound], false);
2103                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2104
2105                                 flashr=1;
2106                                 flashg=0;
2107                                 flashb=0;
2108                                 flashamount=1;
2109                                 flashdelay=1;
2110
2111                                 if(!gameon){
2112                                         //quit
2113                                         tryquit=1;
2114                                         if(registered)OPENAL_SetPaused(channels[stream_music3], true);
2115                                 }
2116                                 else{
2117                                         //end game
2118                                         gameon=0;
2119                                         mainmenu=1;
2120                                 }
2121                         }
2122                         if(Button())oldbutton=1;
2123                         else oldbutton=0;
2124                 }
2125
2126                 if(mainmenu==3){
2127                         if(Button()&&!oldbutton&&selected!=-1){
2128                                 float gLoc[3]={0,0,0};
2129                                 float vel[3]={0,0,0};
2130                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2131                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2132                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2133                                 OPENAL_SetVolume(channels[firestartsound], 256);
2134                                 OPENAL_SetPaused(channels[firestartsound], false);
2135                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2136                         }
2137                         if(Button()&&!oldbutton&&selected==0){
2138                                 #if USE_SDL
2139                                 extern SDL_Rect **resolutions;
2140                                 bool isCustomResolution = true;
2141                                 bool found = false;
2142                                 for (int i = 0; (!found) && (resolutions[i]); i++)
2143                                 {
2144                                         if ((resolutions[i]->w == screenwidth) && (resolutions[i]->h == screenwidth))
2145                                                 isCustomResolution = false;
2146
2147                                         if ((resolutions[i]->w == newscreenwidth) && (resolutions[i]->h == newscreenheight))
2148                                         {
2149                                                 i++;
2150                                                 if (resolutions[i] != NULL)
2151                                                 {
2152                                                         newscreenwidth = (int) resolutions[i]->w;
2153                                                         newscreenheight = (int) resolutions[i]->h;
2154                                                 }
2155                                                 else if (isCustomResolution)
2156                                                 {
2157                                                         if ((screenwidth == newscreenwidth) && (screenheight == newscreenheight))
2158                                                         {
2159                                                                 newscreenwidth = (int) resolutions[0]->w;
2160                                                                 newscreenheight = (int) resolutions[0]->h;
2161                                                         }
2162                                                         else
2163                                                         {
2164                                                                 newscreenwidth = screenwidth;
2165                                                                 newscreenheight = screenheight;
2166                                                         }
2167                                                 }
2168                                                 else
2169                                                 {
2170                                                         newscreenwidth = (int) resolutions[0]->w;
2171                                                         newscreenheight = (int) resolutions[0]->h;
2172                                                 }
2173                                                 found = true;
2174                                         }
2175                                 }
2176
2177                                 if (!found)
2178                                 {
2179                                         newscreenwidth = (int) resolutions[0]->w;
2180                                         newscreenheight = (int) resolutions[0]->h;
2181                                 }
2182
2183                                 #else
2184                                 int whichres;
2185                                 whichres=-1;
2186                                 if(newscreenwidth==640&&newscreenheight==480)whichres=0;
2187                                 if(newscreenwidth==800&&newscreenheight==600)whichres=1;
2188                                 if(newscreenwidth==1024&&newscreenheight==768)whichres=2;
2189                                 if(newscreenwidth==1280&&newscreenheight==1024)whichres=3;
2190                                 if(newscreenwidth==1600&&newscreenheight==1200)whichres=4;
2191                                 if(newscreenwidth==840&&newscreenheight==524)whichres=5;
2192                                 if(newscreenwidth==1024&&newscreenheight==640)whichres=6;
2193                                 if(newscreenwidth==1344&&newscreenheight==840)whichres=7;
2194                                 if(newscreenwidth==1920&&newscreenheight==1200)whichres=8;
2195
2196                                 if(whichres==-1||whichres==8){
2197                                         newscreenwidth=640;
2198                                         newscreenheight=480;
2199                                 }
2200                                 if(whichres==0){
2201                                         newscreenwidth=800;
2202                                         newscreenheight=600;
2203                                 }
2204                                 if(whichres==1){
2205                                         newscreenwidth=1024;
2206                                         newscreenheight=768;
2207                                 }
2208                                 if(whichres==2){
2209                                         newscreenwidth=1280;
2210                                         newscreenheight=1024;
2211                                 }
2212                                 if(whichres==3){
2213                                         newscreenwidth=1600;
2214                                         newscreenheight=1200;
2215                                 }
2216                                 if(whichres==4){
2217                                         newscreenwidth=840;
2218                                         newscreenheight=524;
2219                                 }
2220                                 if(whichres==5){
2221                                         newscreenwidth=1024;
2222                                         newscreenheight=640;
2223                                 }
2224                                 if(whichres==6){
2225                                         newscreenwidth=1344;
2226                                         newscreenheight=840;
2227                                 }
2228                                 if(whichres==7){
2229                                         newscreenwidth=1920;
2230                                         newscreenheight=1200;
2231                                 }
2232                                 #endif
2233                         }
2234                         if(Button()&&!oldbutton&&selected==1){
2235                                 newdetail++;
2236                                 if(newdetail>2)newdetail=0;
2237                         }
2238                         if(Button()&&!oldbutton&&selected==2){
2239                                 bloodtoggle++;
2240                                 if(bloodtoggle>2)bloodtoggle=0;
2241                         }
2242                         if(Button()&&!oldbutton&&selected==3){
2243                                 difficulty++;
2244                                 if(difficulty>2)difficulty=0;
2245                         }
2246                         if(Button()&&!oldbutton&&selected==4){
2247                                 ismotionblur=1-ismotionblur;
2248                         }
2249                         if(Button()&&!oldbutton&&selected==5){
2250                                 decals=1-decals;
2251                         }
2252                         if(Button()&&!oldbutton&&selected==6){
2253                                 musictoggle=1-musictoggle;
2254
2255                                 if(!musictoggle){
2256                                         OPENAL_SetPaused(channels[music1], true);
2257                                         OPENAL_SetPaused(channels[stream_music2], true);
2258                                         OPENAL_SetPaused(channels[stream_music3], true);
2259
2260                                         for(i=0;i<4;i++){
2261                                                 oldmusicvolume[i]=0;
2262                                                 musicvolume[i]=0;
2263                                         }
2264                                 }
2265
2266                                 if(musictoggle){
2267                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2268                                         OPENAL_SetPaused(channels[stream_music3], false);
2269                                         OPENAL_SetVolume(channels[stream_music3], 256);
2270                                 }
2271                         }
2272                         if(Button()&&!oldbutton&&selected==9){
2273                                 invertmouse=1-invertmouse;
2274                         }
2275                         if(Button()&&!oldbutton&&selected==10){
2276                                 usermousesensitivity+=.2;
2277                                 if(usermousesensitivity>2)usermousesensitivity=.2;
2278                         }
2279                         if(Button()&&!oldbutton&&selected==11){
2280                                 volume+=.1f;
2281                                 if(volume>1.0001f)volume=0;
2282                                 OPENAL_SetSFXMasterVolume((int)(volume*255));
2283                         }
2284                         if(Button()&&!oldbutton&&selected==7){
2285                                 /*float gLoc[3]={0,0,0};
2286                                 float vel[3]={0,0,0};
2287                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2288                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2289                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2290                                 OPENAL_SetVolume(channels[firestartsound], 256);
2291                                 OPENAL_SetPaused(channels[firestartsound], false);
2292                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2293                                 */
2294                                 flashr=1;
2295                                 flashg=0;
2296                                 flashb=0;
2297                                 flashamount=1;
2298                                 flashdelay=1;
2299
2300                                 //options
2301
2302                                 mainmenu=4;
2303                                 keyselect=-1;
2304                         }
2305                         if(Button()&&!oldbutton&&selected==8){
2306                                 float gLoc[3]={0,0,0};
2307                                 float vel[3]={0,0,0};
2308                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2309                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2310                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2311                                 OPENAL_SetVolume(channels[fireendsound], 256);
2312                                 OPENAL_SetPaused(channels[fireendsound], false);
2313                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2314
2315                                 flashr=1;
2316                                 flashg=0;
2317                                 flashb=0;
2318                                 flashamount=1;
2319                                 flashdelay=1;
2320
2321                                 if(newdetail>2)newdetail=detail;
2322                                 if(newdetail<0)newdetail=detail;
2323 #if !USE_SDL  // we'll take anything that works.
2324                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2325                                 if(newscreenheight>3000)newscreenheight=screenheight;
2326 #endif
2327                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2328                                 if(newscreenheight<0)newscreenheight=screenheight;
2329
2330
2331                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
2332                                 opstream << "Screenwidth:\n";
2333                                 opstream << newscreenwidth;
2334                                 opstream << "\nScreenheight:\n";
2335                                 opstream << newscreenheight;
2336                                 opstream << "\nMouse sensitivity:\n";
2337                                 opstream << usermousesensitivity;
2338                                 opstream << "\nBlur(0,1):\n";
2339                                 opstream << ismotionblur;
2340                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
2341                                 opstream << newdetail;
2342                                 opstream << "\nFloating jump:\n";
2343                                 opstream << floatjump;
2344                                 opstream << "\nMouse jump:\n";
2345                                 opstream << mousejump;
2346                                 opstream << "\nAmbient sound:\n";
2347                                 opstream << ambientsound;
2348                                 opstream << "\nBlood (0,1,2):\n";
2349                                 opstream << bloodtoggle;
2350                                 opstream << "\nAuto slomo:\n";
2351                                 opstream << autoslomo;
2352                                 opstream << "\nFoliage:\n";
2353                                 opstream << foliage;
2354                                 opstream << "\nMusic:\n";
2355                                 opstream << musictoggle;
2356                                 opstream << "\nTrilinear:\n";
2357                                 opstream << trilinear;
2358                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
2359                                 opstream << decals;
2360                                 opstream << "\nInvert mouse:\n";
2361                                 opstream << invertmouse;
2362                                 opstream << "\nGamespeed:\n";
2363                                 if(oldgamespeed==0)oldgamespeed=1;
2364                                 opstream << oldgamespeed;
2365                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
2366                                 opstream << difficulty;
2367                                 opstream << "\nDamage effects(blackout, doublevision):\n";
2368                                 opstream << damageeffects;
2369                                 opstream << "\nText:\n";
2370                                 opstream << texttoggle;
2371                                 opstream << "\nDebug:\n";
2372                                 opstream << debugmode;
2373                                 opstream << "\nVBL Sync:\n";
2374                                 opstream << vblsync;
2375                                 opstream << "\nShow Points:\n";
2376                                 opstream << showpoints;
2377                                 opstream << "\nAlways Blur:\n";
2378                                 opstream << alwaysblur;
2379                                 opstream << "\nImmediate mode (turn on on G5):\n";
2380                                 opstream << immediate;
2381                                 opstream << "\nVelocity blur:\n";
2382                                 opstream << velocityblur;
2383                             opstream << "\nVolume:\n";
2384                         opstream << volume;
2385                                 opstream << "\nForward key:\n";
2386                                 opstream << KeyToChar(forwardkey);
2387                                 opstream << "\nBack key:\n";
2388                                 opstream << KeyToChar(backkey);
2389                                 opstream << "\nLeft key:\n";
2390                                 opstream << KeyToChar(leftkey);
2391                                 opstream << "\nRight key:\n";
2392                                 opstream << KeyToChar(rightkey);
2393                                 opstream << "\nJump key:\n";
2394                                 opstream << KeyToChar(jumpkey);
2395                                 opstream << "\nCrouch key:\n";
2396                                 opstream << KeyToChar(crouchkey);
2397                                 opstream << "\nDraw key:\n";
2398                                 opstream << KeyToChar(drawkey);
2399                                 opstream << "\nThrow key:\n";
2400                                 opstream << KeyToChar(throwkey);
2401                                 opstream << "\nAttack key:\n";
2402                                 opstream << KeyToChar(attackkey);
2403                                 opstream << "\nChat key:\n";
2404                                 opstream << KeyToChar(chatkey);
2405                                 opstream.close();
2406
2407                                 if(mainmenu==3&&gameon)mainmenu=2;
2408                                 if(mainmenu==3&&!gameon)mainmenu=1;
2409                         }
2410                         if(Button())oldbutton=1;
2411                         else oldbutton=0;
2412                 }
2413                 if(mainmenu==4){
2414                         if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
2415                                 float gLoc[3]={0,0,0};
2416                                 float vel[3]={0,0,0};
2417                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2418                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2419                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2420                                 OPENAL_SetVolume(channels[firestartsound], 256);
2421                                 OPENAL_SetPaused(channels[firestartsound], false);
2422                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2423                         }
2424                         if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
2425                                 keyselect=selected;
2426                                 oldbuttons[0]=1;
2427                                 oldbuttons[1]=1;
2428                                 oldbuttons[2]=1;
2429                         }
2430                         if(keyselect!=-1){
2431                                 for(i=0;i<3;i++)
2432                                         if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
2433                                 for(i=0;i<140;i++){
2434                                         if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
2435                                                 if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
2436                                                         float gLoc[3]={0,0,0};
2437                                                         float vel[3]={0,0,0};
2438                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2439                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2440                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2441                                                         OPENAL_SetVolume(channels[fireendsound], 256);
2442                                                         OPENAL_SetPaused(channels[fireendsound], false);
2443                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2444
2445                                                         int keynum;
2446                                                         keynum=i;
2447                                                         if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
2448                                                         if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
2449
2450
2451
2452                                                         if(keyselect==0)forwardkey=keynum;
2453                                                         if(keyselect==1)backkey=keynum;
2454                                                         if(keyselect==2)leftkey=keynum;
2455                                                         if(keyselect==3)rightkey=keynum;
2456                                                         if(keyselect==4)crouchkey=keynum;
2457                                                         if(keyselect==5)jumpkey=keynum;
2458                                                         if(keyselect==6)drawkey=keynum;
2459                                                         if(keyselect==7)throwkey=keynum;
2460                                                         if(keyselect==8)attackkey=keynum;
2461                                                         keyselect=-1;
2462                                                 }
2463                                         }
2464                                 }}
2465                         if(Button()&&!oldbutton&&selected==9){
2466                                 float gLoc[3]={0,0,0};
2467                                 float vel[3]={0,0,0};
2468                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2469                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2470                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2471                                 OPENAL_SetVolume(channels[fireendsound], 256);
2472                                 OPENAL_SetPaused(channels[fireendsound], false);
2473                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2474
2475                                 flashr=1;
2476                                 flashg=0;
2477                                 flashb=0;
2478                                 flashamount=1;
2479                                 flashdelay=1;
2480
2481                                 mainmenu=3;
2482
2483                                 if(newdetail>2)newdetail=detail;
2484                                 if(newdetail<0)newdetail=detail;
2485                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
2486                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
2487                                 if(newscreenheight>3000)newscreenheight=screenheight;
2488                                 if(newscreenheight<0)newscreenheight=screenheight;
2489                         }
2490                 }
2491
2492                 if(mainmenu==5){
2493                         if(accountcampaignchoicesmade[accountactive]>8&&!registered){
2494                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
2495                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
2496                                 OPENAL_SetPaused(channels[stream_music3], false);
2497                                 OPENAL_SetVolume(channels[stream_music3], 256);
2498
2499                                 gameon=0;
2500                                 mainmenu=12;
2501                                 accountcampaignchoicesmade[accountactive]=0;
2502                                 accountcampaignscore[accountactive]=0;
2503                                 accountcampaigntime[accountactive]=0;
2504
2505                                 float gLoc[3]={0,0,0};
2506                                 float vel[3]={0,0,0};
2507                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2508                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2509                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2510                                 OPENAL_SetVolume(channels[fireendsound], 256);
2511                                 OPENAL_SetPaused(channels[fireendsound], false);
2512                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2513
2514                                 flashr=1;
2515                                 flashg=0;
2516                                 flashb=0;
2517                                 flashamount=1;
2518                                 flashdelay=1;
2519                         }
2520
2521                         if(endgame==2){
2522                                 accountcampaignchoicesmade[accountactive]=0;
2523                                 accountcampaignscore[accountactive]=0;
2524                                 accountcampaigntime[accountactive]=0;
2525                                 endgame=0;
2526                         }
2527
2528                         if(Button()&&!oldbutton&&selected==1){
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                                 startbonustotal=0;
2545
2546                                 loading=2;
2547                                 loadtime=0;
2548                                 targetlevel=-1;
2549                                 if(firstload)TickOnceAfter();
2550                                 if(!firstload)LoadStuff();
2551                                 else {
2552                                         Loadlevel(-1);
2553                                 }
2554
2555                                 mainmenu=0;
2556                                 gameon=1;
2557                                 OPENAL_SetPaused(channels[stream_music3], true);
2558                         }
2559                         if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
2560                                 float gLoc[3]={0,0,0};
2561                                 float vel[3]={0,0,0};
2562                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2563                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2564                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2565                                 OPENAL_SetVolume(channels[firestartsound], 256);
2566                                 OPENAL_SetPaused(channels[firestartsound], false);
2567                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2568
2569                                 flashr=1;
2570                                 flashg=0;
2571                                 flashb=0;
2572                                 flashamount=1;
2573                                 flashdelay=1;
2574
2575                                 startbonustotal=0;
2576
2577                                 loading=2;
2578                                 loadtime=0;
2579                                 targetlevel=7;
2580                                 if(firstload)TickOnceAfter();
2581                                 if(!firstload)LoadStuff();
2582                                 //else {
2583                                 for(i=0;i<255;i++){
2584                                         mapname[i]='\0';
2585                                 }
2586                                 mapname[0]=':';
2587                                 mapname[1]='D';
2588                                 mapname[2]='a';
2589                                 mapname[3]='t';
2590                                 mapname[4]='a';
2591                                 mapname[5]=':';
2592                                 mapname[6]='M';
2593                                 mapname[7]='a';
2594                                 mapname[8]='p';
2595                                 mapname[9]='s';
2596                                 mapname[10]=':';
2597                                 strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
2598                                 whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
2599                                 visibleloading=1;
2600                                 stillloading=1;
2601                                 Loadlevel(mapname);
2602                                 //Loadlevel(campaignmapname[levelorder[selected-7]]);
2603                                 //}
2604                                 campaign=1;
2605                                 mainmenu=0;
2606                                 gameon=1;
2607                                 OPENAL_SetPaused(channels[stream_music3], true);
2608                         }
2609                         if(Button()&&!oldbutton&&selected==4){
2610                                 float gLoc[3]={0,0,0};
2611                                 float vel[3]={0,0,0};
2612                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2613                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2614                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2615                                 OPENAL_SetVolume(channels[fireendsound], 256);
2616                                 OPENAL_SetPaused(channels[fireendsound], false);
2617                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2618
2619                                 flashr=1;
2620                                 flashg=0;
2621                                 flashb=0;
2622                                 flashamount=1;
2623                                 flashdelay=1;
2624
2625                                 if(mainmenu==5&&gameon)mainmenu=2;
2626                                 if(mainmenu==5&&!gameon)mainmenu=1;
2627                         }
2628                         if(Button()&&!oldbutton&&selected==5){
2629                                 float gLoc[3]={0,0,0};
2630                                 float vel[3]={0,0,0};
2631                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2632                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2633                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2634                                 OPENAL_SetVolume(channels[fireendsound], 256);
2635                                 OPENAL_SetPaused(channels[fireendsound], false);
2636                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2637
2638                                 flashr=1;
2639                                 flashg=0;
2640                                 flashb=0;
2641                                 flashamount=1;
2642                                 flashdelay=1;
2643
2644                                 mainmenu=7;
2645                         }
2646                         if(Button()&&!oldbutton&&selected==3){
2647                                 float gLoc[3]={0,0,0};
2648                                 float vel[3]={0,0,0};
2649                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2650                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2651                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2652                                 OPENAL_SetVolume(channels[firestartsound], 256);
2653                                 OPENAL_SetPaused(channels[firestartsound], false);
2654                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2655
2656                                 flashr=1;
2657                                 flashg=0;
2658                                 flashb=0;
2659                                 flashamount=1;
2660                                 flashdelay=1;
2661
2662                                 mainmenu=6;
2663                         }
2664                         if(Button()&&!oldbutton&&selected==2){
2665                                 float gLoc[3]={0,0,0};
2666                                 float vel[3]={0,0,0};
2667                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2668                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2669                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2670                                 OPENAL_SetVolume(channels[firestartsound], 256);
2671                                 OPENAL_SetPaused(channels[firestartsound], false);
2672                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2673
2674                                 flashr=1;
2675                                 flashg=0;
2676                                 flashb=0;
2677                                 flashamount=1;
2678                                 flashdelay=1;
2679
2680                                 mainmenu=9;
2681                         }
2682                         if(Button())oldbutton=1;
2683                         else oldbutton=0;
2684                 }
2685                 if(mainmenu==9){
2686                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2687                                 float gLoc[3]={0,0,0};
2688                                 float vel[3]={0,0,0};
2689                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2690                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2691                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2692                                 OPENAL_SetVolume(channels[firestartsound], 256);
2693                                 OPENAL_SetPaused(channels[firestartsound], false);
2694                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2695
2696                                 flashr=1;
2697                                 flashg=0;
2698                                 flashb=0;
2699                                 flashamount=1;
2700                                 flashdelay=1;
2701
2702                                 startbonustotal=0;
2703
2704                                 loading=2;
2705                                 loadtime=0;
2706                                 targetlevel=selected;
2707                                 if(firstload)TickOnceAfter();
2708                                 if(!firstload)LoadStuff();
2709                                 else {
2710                                         Loadlevel(selected);
2711                                 }
2712                                 campaign=0;
2713
2714                                 mainmenu=0;
2715                                 gameon=1;
2716                                 OPENAL_SetPaused(channels[stream_music3], true);
2717                         }
2718                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2719                                 float gLoc[3]={0,0,0};
2720                                 float vel[3]={0,0,0};
2721                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2722                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2723                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2724                                 OPENAL_SetVolume(channels[fireendsound], 256);
2725                                 OPENAL_SetPaused(channels[fireendsound], false);
2726                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2727
2728                                 flashr=1;
2729                                 flashg=0;
2730                                 flashb=0;
2731                                 flashamount=1;
2732                                 flashdelay=1;
2733
2734                                 mainmenu=5;
2735                         }
2736                         if(Button())oldbutton=1;
2737                         else oldbutton=0;
2738                 }
2739                 if(mainmenu==11){
2740                         if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
2741                                 float gLoc[3]={0,0,0};
2742                                 float vel[3]={0,0,0};
2743                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2744                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2745                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2746                                 OPENAL_SetVolume(channels[firestartsound], 256);
2747                                 OPENAL_SetPaused(channels[firestartsound], false);
2748                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2749
2750                                 flashr=1;
2751                                 flashg=0;
2752                                 flashb=0;
2753                                 flashamount=1;
2754                                 flashdelay=1;
2755
2756                                 startbonustotal=0;
2757
2758                                 loading=2;
2759                                 loadtime=0;
2760                                 targetlevel=selected;
2761                                 if(firstload)TickOnceAfter();
2762                                 if(!firstload)LoadStuff();
2763                                 else {
2764                                         Loadlevel(selected);
2765                                 }
2766                                 campaign=0;
2767
2768                                 mainmenu=0;
2769                                 gameon=1;
2770                                 OPENAL_SetPaused(channels[stream_music3], true);
2771                         }
2772                         if(Button()&&!oldbutton&&selected==numchallengelevels){
2773                                 float gLoc[3]={0,0,0};
2774                                 float vel[3]={0,0,0};
2775                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2776                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2777                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2778                                 OPENAL_SetVolume(channels[fireendsound], 256);
2779                                 OPENAL_SetPaused(channels[fireendsound], false);
2780                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2781
2782                                 flashr=1;
2783                                 flashg=0;
2784                                 flashb=0;
2785                                 flashamount=1;
2786                                 flashdelay=1;
2787
2788                                 mainmenu=5;
2789                         }
2790                         if(Button())oldbutton=1;
2791                         else oldbutton=0;
2792                 }
2793                 if(mainmenu==10){
2794                         endgame=2;
2795                         if(Button()&&!oldbutton&&selected==3){
2796                                 float gLoc[3]={0,0,0};
2797                                 float vel[3]={0,0,0};
2798                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2799                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2800                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2801                                 OPENAL_SetVolume(channels[fireendsound], 256);
2802                                 OPENAL_SetPaused(channels[fireendsound], false);
2803                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2804
2805                                 flashr=1;
2806                                 flashg=0;
2807                                 flashb=0;
2808                                 flashamount=1;
2809                                 flashdelay=1;
2810
2811                                 mainmenu=5;
2812                         }
2813                         if(Button())oldbutton=1;
2814                         else oldbutton=0;
2815                 }
2816
2817                 if(mainmenu==15||mainmenu==16){
2818                         if(Button()&&!oldbutton&&selected==1){
2819                                 float gLoc[3]={0,0,0};
2820                                 float vel[3]={0,0,0};
2821                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2822                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2823                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2824                                 OPENAL_SetVolume(channels[fireendsound], 256);
2825                                 OPENAL_SetPaused(channels[fireendsound], false);
2826                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2827
2828                                 flashr=1;
2829                                 flashg=0;
2830                                 flashb=0;
2831                                 flashamount=1;
2832                                 flashdelay=1;
2833
2834                                 if(mainmenu==15)mainmenu=5;
2835                                 else mainmenu=12;
2836                         }
2837                         if(Button())oldbutton=1;
2838                         else oldbutton=0;
2839                 }
2840
2841                 if(mainmenu==12){
2842                         endgame=2;
2843                         if(Button()&&!oldbutton&&selected==3){
2844                                 if(tryquit)quit=1;
2845                                 float gLoc[3]={0,0,0};
2846                                 float vel[3]={0,0,0};
2847                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2848                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2849                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2850                                 OPENAL_SetVolume(channels[fireendsound], 256);
2851                                 OPENAL_SetPaused(channels[fireendsound], false);
2852                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2853
2854                                 flashr=1;
2855                                 flashg=0;
2856                                 flashb=0;
2857                                 flashamount=1;
2858                                 flashdelay=1;
2859
2860                                 mainmenu=5;
2861                         }
2862
2863                         if(Button()&&!oldbutton&&selected==4){
2864                                 registernow=1;
2865                                 quit=1;
2866                                 float gLoc[3]={0,0,0};
2867                                 float vel[3]={0,0,0};
2868                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2869                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2870                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2871                                 OPENAL_SetVolume(channels[fireendsound], 256);
2872                                 OPENAL_SetPaused(channels[fireendsound], false);
2873                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2874
2875                                 flashr=1;
2876                                 flashg=0;
2877                                 flashb=0;
2878                                 flashamount=1;
2879                                 flashdelay=1;
2880                         }
2881
2882
2883                         if(Button()&&!oldbutton&&selected==5){
2884                                 tryquit=0;
2885                                 float gLoc[3]={0,0,0};
2886                                 float vel[3]={0,0,0};
2887                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2888                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2889                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2890                                 OPENAL_SetVolume(channels[fireendsound], 256);
2891                                 OPENAL_SetPaused(channels[fireendsound], false);
2892                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2893
2894                                 flashr=1;
2895                                 flashg=0;
2896                                 flashb=0;
2897                                 flashamount=1;
2898                                 flashdelay=1;
2899
2900                                 mainmenu=13;
2901                         }
2902                         if(Button())oldbutton=1;
2903                         else oldbutton=0;
2904                 }
2905                 if(mainmenu==6){
2906                         if(Button()&&!oldbutton&&selected!=-1){
2907                                 float gLoc[3]={0,0,0};
2908                                 float vel[3]={0,0,0};
2909                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2910                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2911                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2912                                 OPENAL_SetVolume(channels[firestartsound], 256);
2913                                 OPENAL_SetPaused(channels[firestartsound], false);
2914                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2915                         }
2916                         if(Button()&&!oldbutton&&selected==1){
2917                                 float gLoc[3]={0,0,0};
2918                                 float vel[3]={0,0,0};
2919                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2920                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2921                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2922                                 OPENAL_SetVolume(channels[fireendsound], 256);
2923                                 OPENAL_SetPaused(channels[fireendsound], false);
2924                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2925
2926                                 flashr=1;
2927                                 flashg=0;
2928                                 flashb=0;
2929                                 flashamount=1;
2930                                 flashdelay=1;
2931
2932                                 for(i=accountactive;i<numaccounts-1;i++){
2933                                         accountdifficulty[i]=accountdifficulty[i+1];
2934                                         accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
2935                                         for(j=0;j<accountcampaignchoicesmade[i+1];j++){
2936                                                 accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
2937                                         }
2938                                         accountpoints[i]=accountpoints[i+1];
2939                                         for(j=0;j<50;j++){
2940                                                 accounthighscore[i][j]=accounthighscore[i+1][j];
2941                                                 accountfasttime[i][j]=accountfasttime[i+1][j];
2942                                         }
2943                                         for(j=0;j<60;j++){
2944                                                 accountunlocked[i][j]=accountunlocked[i+1][j];
2945                                         }
2946                                         for(j=0;j<256;j++){
2947                                                 accountname[i][j]=accountname[i+1][j];
2948                                         }
2949                                         accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
2950                                         accountprogress[i]=accountprogress[i+1];
2951                                         accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
2952                                         accountcampaignscore[i]=accountcampaignscore[i+1];
2953                                         accountcampaigntime[i]=accountcampaigntime[i+1];
2954                                 }
2955
2956                                 numaccounts--;
2957                                 accountactive=-1;
2958
2959
2960                                 mainmenu=7;
2961                         }
2962                         if(Button()&&!oldbutton&&selected==2){
2963                                 float gLoc[3]={0,0,0};
2964                                 float vel[3]={0,0,0};
2965                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
2966                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
2967                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
2968                                 OPENAL_SetVolume(channels[fireendsound], 256);
2969                                 OPENAL_SetPaused(channels[fireendsound], false);
2970                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
2971
2972                                 flashr=1;
2973                                 flashg=0;
2974                                 flashb=0;
2975                                 flashamount=1;
2976                                 flashdelay=1;
2977
2978                                 mainmenu=5;
2979                         }
2980                         if(Button())oldbutton=1;
2981                         else oldbutton=0;
2982                 }
2983                 if(mainmenu==7){
2984                         if(Button()&&!oldbutton&&selected!=-1){
2985                                 float gLoc[3]={0,0,0};
2986                                 float vel[3]={0,0,0};
2987                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
2988                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
2989                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
2990                                 OPENAL_SetVolume(channels[firestartsound], 256);
2991                                 OPENAL_SetPaused(channels[firestartsound], false);
2992                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
2993                         }
2994                         if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
2995                                 entername=1;
2996                         }
2997                         if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
2998                                 accountactive=selected-1;
2999                                 mainmenu=5;
3000                                 flashr=1;
3001                                 flashg=0;
3002                                 flashb=0;
3003                                 flashamount=1;
3004                                 flashdelay=1;
3005                         }
3006                         if(Button()&&!oldbutton&&selected==numaccounts+1){
3007                                 float gLoc[3]={0,0,0};
3008                                 float vel[3]={0,0,0};
3009                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
3010                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
3011                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
3012                                 OPENAL_SetVolume(channels[fireendsound], 256);
3013                                 OPENAL_SetPaused(channels[fireendsound], false);
3014                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
3015
3016                                 flashr=1;
3017                                 flashg=0;
3018                                 flashb=0;
3019                                 flashamount=1;
3020                                 flashdelay=1;
3021
3022                                 mainmenu=1;
3023
3024                                 for(j=0;j<255;j++){
3025                                         displaytext[0][j]=' ';
3026                                 }
3027                                 displaychars[0]=0;
3028                                 displayselected=0;
3029                                 entername=0;
3030                         }
3031                         if(Button())oldbutton=1;
3032                         else oldbutton=0;
3033                 }
3034                 if(mainmenu==8){
3035                         if(Button()&&!oldbutton&&selected!=-1){
3036                                 float gLoc[3]={0,0,0};
3037                                 float vel[3]={0,0,0};
3038                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3039                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3040                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3041                                 OPENAL_SetVolume(channels[firestartsound], 256);
3042                                 OPENAL_SetPaused(channels[firestartsound], false);
3043                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3044
3045                                 if(selected==0)accountdifficulty[accountactive]=0;
3046                                 if(selected==1)accountdifficulty[accountactive]=1;
3047                                 if(selected==2)accountdifficulty[accountactive]=2;
3048
3049                                 mainmenu=5;
3050
3051                                 flashr=1;
3052                                 flashg=0;
3053                                 flashb=0;
3054                                 flashamount=1;
3055                                 flashdelay=1;
3056
3057                         }
3058                         if(Button())oldbutton=1;
3059                         else oldbutton=0;
3060                 }
3061
3062
3063                 if(Button())oldbutton=1;
3064                 else oldbutton=0;
3065
3066                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
3067                         tryquit=1;
3068                         if(mainmenu==3){
3069                                 if(newdetail>2)newdetail=detail;
3070                                 if(newdetail<0)newdetail=detail;
3071 #if !USE_SDL  // we'll take anything that works.
3072                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
3073                                 if(newscreenheight>3000)newscreenheight=screenheight;
3074 #endif
3075                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
3076                                 if(newscreenheight<0)newscreenheight=screenheight;
3077
3078                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
3079                                 opstream << "Screenwidth:\n";
3080                                 opstream << newscreenwidth;
3081                                 opstream << "\nScreenheight:\n";
3082                                 opstream << newscreenheight;
3083                                 opstream << "\nMouse sensitivity:\n";
3084                                 opstream << usermousesensitivity;
3085                                 opstream << "\nBlur(0,1):\n";
3086                                 opstream << ismotionblur;
3087                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
3088                                 opstream << newdetail;
3089                                 opstream << "\nFloating jump:\n";
3090                                 opstream << floatjump;
3091                                 opstream << "\nMouse jump:\n";
3092                                 opstream << mousejump;
3093                                 opstream << "\nAmbient sound:\n";
3094                                 opstream << ambientsound;
3095                                 opstream << "\nBlood (0,1,2):\n";
3096                                 opstream << bloodtoggle;
3097                                 opstream << "\nAuto slomo:\n";
3098                                 opstream << autoslomo;
3099                                 opstream << "\nFoliage:\n";
3100                                 opstream << foliage;
3101                                 opstream << "\nMusic:\n";
3102                                 opstream << musictoggle;
3103                                 opstream << "\nTrilinear:\n";
3104                                 opstream << trilinear;
3105                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
3106                                 opstream << decals;
3107                                 opstream << "\nInvert mouse:\n";
3108                                 opstream << invertmouse;
3109                                 opstream << "\nGamespeed:\n";
3110                                 if(oldgamespeed==0)oldgamespeed=1;
3111                                 opstream << oldgamespeed;
3112                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
3113                                 opstream << difficulty;
3114                                 opstream << "\nDamage effects(blackout, doublevision):\n";
3115                                 opstream << damageeffects;
3116                                 opstream << "\nText:\n";
3117                                 opstream << texttoggle;
3118                                 opstream << "\nDebug:\n";
3119                                 opstream << debugmode;
3120                                 opstream << "\nVBL Sync:\n";
3121                                 opstream << vblsync;
3122                                 opstream << "\nShow Points:\n";
3123                                 opstream << showpoints;
3124                                 opstream << "\nAlways Blur:\n";
3125                                 opstream << alwaysblur;
3126                                 opstream << "\nImmediate mode (turn on on G5):\n";
3127                                 opstream << immediate;
3128                                 opstream << "\nVelocity blur:\n";
3129                                 opstream << velocityblur;
3130                             opstream << "\nVolume:\n";
3131                         opstream << volume;
3132                                 opstream << "\nForward key:\n";
3133                                 opstream << KeyToChar(forwardkey);
3134                                 opstream << "\nBack key:\n";
3135                                 opstream << KeyToChar(backkey);
3136                                 opstream << "\nLeft key:\n";
3137                                 opstream << KeyToChar(leftkey);
3138                                 opstream << "\nRight key:\n";
3139                                 opstream << KeyToChar(rightkey);
3140                                 opstream << "\nJump key:\n";
3141                                 opstream << KeyToChar(jumpkey);
3142                                 opstream << "\nCrouch key:\n";
3143                                 opstream << KeyToChar(crouchkey);
3144                                 opstream << "\nDraw key:\n";
3145                                 opstream << KeyToChar(drawkey);
3146                                 opstream << "\nThrow key:\n";
3147                                 opstream << KeyToChar(throwkey);
3148                                 opstream << "\nAttack key:\n";
3149                                 opstream << KeyToChar(attackkey);
3150                                 opstream << "\nChat key:\n";
3151                                 opstream << KeyToChar(chatkey);
3152                                 opstream.close();
3153                         }
3154                 }
3155
3156                 if(mainmenu==1||mainmenu==2){
3157                         if(loaddistrib>4)transition+=multiplier/8;
3158                         if(transition>1){
3159                                 transition=0;
3160                                 anim++;
3161                                 if(anim>4)anim=0;
3162                                 loaddistrib=0;
3163                         }
3164                 }
3165                 OPENAL_SetFrequency(channels[stream_music3], 22050);
3166
3167                 if(entername||mainmenu==13||mainmenu==14){
3168                         for(i=0;i<140;i++){
3169                                 if(IsKeyDown(theKeyMap, i)){
3170                                         togglekeydelay[i]+=multiplier;
3171                                         if(togglekeydelay[i]>.4){
3172                                                 togglekey[i]=0;
3173                                                 togglekeydelay[i]=.36;
3174                                         }
3175                                         if(!togglekey[i]){
3176                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3177                                                         for(j=255;j>=displayselected+1;j--){
3178                                                                 displaytext[0][j]=displaytext[0][j-1];
3179                                                         }
3180                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3181                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3182                                                         displayselected++;
3183                                                         displaychars[0]++;
3184                                                 }
3185                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3186                                                         for(j=displayselected-1;j<255;j++){
3187                                                                 displaytext[0][j]=displaytext[0][j+1];
3188                                                         }
3189                                                         displaytext[0][255]=' ';
3190                                                         displayselected--;
3191                                                         displaychars[0]--;
3192                                                 }
3193                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3194                                                         displayselected--;
3195                                                 }
3196                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3197                                                         displayselected++;
3198                                                 }
3199                                                 if(i==MAC_RETURN_KEY&&entername){
3200                                                         if(displaychars[0]){
3201                                                                 numaccounts++;
3202                                                                 strcpy(accountname[numaccounts-1],displaytext[0]);
3203                                                                 accountactive=numaccounts-1;
3204                                                                 accountdifficulty[accountactive]=1;
3205                                                                 accountprogress[accountactive]=0;
3206                                                                 accountpoints[accountactive]=0;
3207                                                                 accountcampaigntime[accountactive]=0;
3208                                                                 accountcampaignscore[accountactive]=0;
3209                                                                 accountcampaignfasttime[accountactive]=0;
3210                                                                 accountcampaignhighscore[accountactive]=0;
3211                                                                 for(j=0;j<50;j++){
3212                                                                         accounthighscore[accountactive][j]=0;
3213                                                                         accountfasttime[accountactive][j]=0;
3214                                                                 }
3215                                                                 for(j=0;j<60;j++){
3216                                                                         accountunlocked[accountactive][j]=0;
3217                                                                 }
3218                                                                 accountcampaignchoicesmade[accountactive]=0;
3219
3220                                                                 for(j=0;j<255;j++){
3221                                                                         displaytext[0][j]=' ';
3222                                                                 }
3223                                                                 displaychars[0]=0;
3224                                                                 displayselected=0;
3225                                                                 entername=0;
3226
3227                                                                 mainmenu=8;
3228
3229                                                                 flashr=1;
3230                                                                 flashg=0;
3231                                                                 flashb=0;
3232                                                                 flashamount=1;
3233                                                                 flashdelay=1;
3234
3235                                                                 float gLoc[3]={0,0,0};
3236                                                                 float vel[3]={0,0,0};
3237                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3238                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3239                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3240                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3241                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3242                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3243
3244                                                                 for(j=0;j<255;j++){
3245                                                                         displaytext[0][j]=' ';
3246                                                                 }
3247                                                                 displaychars[0]=0;
3248
3249
3250                                                                 displayselected=0;
3251                                                         }}
3252
3253                                                 if(i==MAC_RETURN_KEY&&mainmenu==14){
3254                                                         if(displaychars[0]){
3255                                                                 char serialstring[256];
3256                                                                 char tempstring[256];
3257                                                                 #if defined(__APPLE__)
3258                                                                 sprintf (tempstring, "%s", registrationname);
3259                                                                 #elif defined(_WIN32) || defined(__linux__)
3260                                                                 sprintf (tempstring, "%s-windows", registrationname);
3261                                                                 #else
3262                                                                 #error Please make sure you have the right registration key stuff here!
3263                                                                 #endif
3264                                                                 long num1;
3265                                                                 long num2;
3266                                                                 long num3;
3267                                                                 long num4;
3268                                                                 long long longnum;
3269                                                                 longnum = MD5_string ( tempstring);
3270                                                                 //longnum = 1111111111111111;
3271                                                                 num1 = longnum/100000000;
3272                                                                 num2 = longnum%100000000;
3273                                                                 sprintf (tempstring, "%d-%d-%d-%d\0\0\0\0\0", num1/10000, num1%10000, num2/10000, num2%10000);
3274
3275                                                                 int goodcode=3;
3276                                                                 int numchars=3;
3277                                                                 if(num1/10000>999)numchars+=4;
3278                                                                 else if(num1/10000>99)numchars+=3;
3279                                                                 else if(num1/10000>9)numchars+=2;
3280                                                                 else numchars+=1;
3281                                                                 if(num1%10000>999)numchars+=4;
3282                                                                 else if(num1%10000>99)numchars+=3;
3283                                                                 else if(num1%10000>9)numchars+=2;
3284                                                                 else numchars+=1;
3285                                                                 if(num2/10000>999)numchars+=4;
3286                                                                 else if(num2/10000>99)numchars+=3;
3287                                                                 else if(num2/10000>9)numchars+=2;
3288                                                                 else numchars+=1;
3289                                                                 if(num2%10000>999)numchars+=4;
3290                                                                 else if(num2%10000>99)numchars+=3;
3291                                                                 else if(num2%10000>9)numchars+=2;
3292                                                                 else numchars+=1;
3293
3294                                                                 //numchars=12;
3295
3296                                                                 for(j=0;j<numchars;j++){
3297                                                                         if(displaytext[0][j]!=tempstring[j]&&tempstring[j]!=' '&&tempstring[j]!='\0')goodcode--;
3298                                                                 }
3299
3300                                                                 if(longnum==LONGLONGCONST(5077041556214789))goodcode=-1;
3301
3302                                                                 if(goodcode<0)goodcode=0;
3303
3304                                                                 if(goodcode){
3305                                                                         registered=1;
3306                                                                         mainmenu=15;
3307
3308                                                                         FILE                    *tfile;
3309                                                                         tfile=fopen( ":Data:Sounds:flame.ogg", "wb" );
3310                                                                         if (tfile)
3311                                                                         {
3312                                                                                 int numchars;
3313                                                                                 numchars=strlen(registrationname);
3314                                                                                 fpackf(tfile, "Bb", registered);
3315                                                                                 fpackf(tfile, "Bi", numchars);
3316                                                                                 if(numchars>0)
3317                                                                                 {
3318                                                                                         for(j=0;j<numchars;j++)
3319                                                                                         {
3320                                                                                                 fpackf(tfile, "Bb",  registrationname[j]);
3321                                                                                         }
3322                                                                                 }
3323                                                                                 fpackf(tfile, "Bi", num1);
3324                                                                                 fpackf(tfile, "Bi", num2);
3325                                                                                 fclose(tfile);
3326                                                                         }
3327                                                                 }
3328                                                                 else
3329                                                                 {
3330                                                                         mainmenu=16;
3331                                                                 }
3332                                                                 flashr=1;
3333                                                                 flashg=0;
3334                                                                 flashb=0;
3335                                                                 flashamount=1;
3336                                                                 flashdelay=1;
3337
3338                                                                 float gLoc[3]={0,0,0};
3339                                                                 float vel[3]={0,0,0};
3340                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3341                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3342                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3343                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3344                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3345                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3346
3347                                                                 for(j=0;j<255;j++){
3348                                                                         displaytext[0][j]=' ';
3349                                                                 }
3350                                                                 displaychars[0]=0;
3351                                                                 displayselected=0;
3352                                                         }}
3353
3354                                                 if(i==MAC_RETURN_KEY&&mainmenu==13){
3355                                                         if(displaychars[0]){
3356                                                                 sprintf (registrationname, "%s", displaytext[0]);
3357                                                                 if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
3358
3359                                                                 mainmenu=14;
3360
3361                                                                 flashr=1;
3362                                                                 flashg=0;
3363                                                                 flashb=0;
3364                                                                 flashamount=1;
3365                                                                 flashdelay=1;
3366
3367                                                                 float gLoc[3]={0,0,0};
3368                                                                 float vel[3]={0,0,0};
3369                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
3370                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
3371                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
3372                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
3373                                                                 OPENAL_SetPaused(channels[firestartsound], false);
3374                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
3375
3376                                                                 for(j=0;j<255;j++){
3377                                                                         displaytext[0][j]=' ';
3378                                                                 }
3379                                                                 displaychars[0]=0;
3380
3381                                                                 /*char tempstring[50];
3382                                                                 sprintf (tempstring, registrationname);
3383                                                                 long num1;
3384                                                                 long num2;
3385                                                                 long num3;
3386                                                                 long num4;
3387                                                                 long long longnum;
3388                                                                 longnum = MD5_string ( tempstring);
3389                                                                 num1 = longnum/100000000;
3390                                                                 num2 = longnum%100000000;
3391                                                                 sprintf (displaytext[0], "%d-%d-%d-%d", num1/10000, num1%10000, num2/10000, num2%10000);
3392
3393                                                                 displaychars[0]=strlen(displaytext[0]);
3394                                                                 */
3395                                                                 displayselected=0;
3396                                                         }}
3397                                         }
3398                                         togglekey[i]=1;
3399                                 }
3400                                 else {
3401                                         togglekey[i]=0;
3402                                         togglekeydelay[i]=0;
3403                                 }
3404                         }
3405
3406                         displayblinkdelay-=multiplier;
3407                         if(displayblinkdelay<=0){
3408                                 displayblinkdelay=.3;
3409                                 displayblink=1-displayblink;
3410                         }
3411                 }
3412         }
3413
3414         if(!mainmenu){
3415                 if(hostile==1)hostiletime+=multiplier;
3416                 else hostiletime=0;
3417                 if(!winfreeze)leveltime+=multiplier;
3418                 if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
3419                         chatting=0;
3420                         console=0;
3421                         freeze=0;
3422                         displaychars[0]=0;
3423                 }
3424
3425                 if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
3426                         chatting=1;
3427                         chattogglekeydown=1;
3428                         togglekey[chatkey]=1;
3429                         togglekeydelay[chatkey]=-20;
3430                 }
3431
3432                 if(!IsKeyDown(theKeyMap, chatkey)){
3433                         chattogglekeydown=0;
3434                 }
3435
3436                 if(chatting){
3437                         for(i=0;i<140;i++){
3438                                 if(IsKeyDown(theKeyMap, i)){
3439                                         togglekeydelay[i]+=multiplier;
3440                                         if(togglekeydelay[i]>.4){
3441                                                 togglekey[i]=0;
3442                                                 togglekeydelay[i]=.36;
3443                                         }
3444                                         if(!togglekey[i]){
3445                                                 if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
3446                                                         for(j=255;j>=displayselected+1;j--){
3447                                                                 displaytext[0][j]=displaytext[0][j-1];
3448                                                         }
3449                                                         displaytext[0][displayselected]=KeyToSingleChar(i);
3450                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
3451                                                         displayselected++;
3452                                                         displaychars[0]++;
3453                                                 }
3454                                                 if(i==MAC_DELETE_KEY&&displayselected!=0){
3455                                                         for(j=displayselected-1;j<255;j++){
3456                                                                 displaytext[0][j]=displaytext[0][j+1];
3457                                                         }
3458                                                         displaytext[0][255]=' ';
3459                                                         displayselected--;
3460                                                         displaychars[0]--;
3461                                                 }
3462                                                 if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
3463                                                         displayselected--;
3464                                                 }
3465                                                 if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
3466                                                         displayselected++;
3467                                                 }
3468                                                 if(i==MAC_RETURN_KEY){
3469                                                         if(displaychars[0]){
3470                                                                 /*for(j=0;j<displaychars[0];j++){
3471                                                                 talkname[j]=displaytext[0][j];
3472                                                                 }
3473                                                                 talkname[displaychars[0]]='\0';
3474                                                                 sprintf (chatname, "%s: %s",playerName,talkname);
3475                                                                 //NetworkSendInformation(chatname);
3476                                                                 */
3477                                                                 for(j=0;j<255;j++){
3478                                                                         displaytext[0][j]=' ';
3479                                                                 }
3480                                                                 displaychars[0]=0;
3481                                                                 displayselected=0;
3482                                                                 chatting=0;
3483                                                         }
3484                                                 }
3485                                         }
3486                                         togglekey[i]=1;
3487                                 }
3488                                 else {
3489                                         togglekey[i]=0;
3490                                         togglekeydelay[i]=0;
3491                                 }
3492                         }
3493
3494                         displayblinkdelay-=multiplier;
3495                         if(displayblinkdelay<=0){
3496                                 displayblinkdelay=.3;
3497                                 displayblink=1-displayblink;
3498                         }
3499                 }
3500
3501                 if(chatting)keyboardfrozen=1;
3502
3503                 if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
3504                         freeze=1-freeze;
3505                         if(freeze){
3506                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3507                         }
3508                         freezetogglekeydown=1;
3509                 }
3510
3511                 if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
3512                         freezetogglekeydown=0;
3513                 }
3514
3515                 if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
3516                         console=1-console;
3517                         if(!console)freeze=0;
3518                         if(console){
3519                                 OPENAL_SetFrequency(OPENAL_ALL, 0.001);
3520                         }
3521                         consoletogglekeydown=1;
3522                 }
3523
3524                 if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
3525                         consoletogglekeydown=0;
3526                 }
3527
3528                 if(console)freeze=1;
3529
3530                 if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
3531                         for(i=0;i<140;i++){
3532                                 if(IsKeyDown(theKeyMap, i)){
3533                                         togglekeydelay[i]+=multiplier;
3534                                         if(togglekeydelay[i]>.4){
3535                                                 togglekey[i]=0;
3536                                                 togglekeydelay[i]=.36;
3537                                         }
3538                                         if(!togglekey[i]){
3539                                                 if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
3540                                                         for(j=255;j>=consoleselected+1;j--){
3541                                                                 consoletext[0][j]=consoletext[0][j-1];
3542                                                         }
3543                                                         consoletext[0][consoleselected]=KeyToSingleChar(i);
3544                                                         if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
3545                                                         consoleselected++;
3546                                                         consolechars[0]++;
3547                                                 }
3548                                                 else if(i==MAC_ENTER_KEY){
3549                                                         for(j=255;j>=consoleselected+1;j--){
3550                                                                 consoletext[0][j]=consoletext[0][j-1];
3551                                                         }
3552                                                         consoletext[0][consoleselected]='\n';
3553                                                         consoleselected++;
3554                                                         consolechars[0]++;
3555                                                 }
3556                                                 if(i==MAC_DELETE_KEY&&consoleselected!=0){
3557                                                         for(j=consoleselected-1;j<255;j++){
3558                                                                 consoletext[0][j]=consoletext[0][j+1];
3559                                                         }
3560                                                         consoletext[0][255]=' ';
3561                                                         consoleselected--;
3562                                                         consolechars[0]--;
3563                                                 }
3564                                                 if(i==MAC_ARROW_UP_KEY){
3565                                                         if(archiveselected<14)archiveselected++;
3566                                                         for(j=0;j<255;j++){
3567                                                                 consolechars[0]=consolechars[archiveselected];
3568                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3569                                                                 consoleselected=consolechars[0];
3570                                                         }
3571                                                 }
3572                                                 if(i==MAC_ARROW_DOWN_KEY){
3573                                                         if(archiveselected>0)archiveselected--;
3574                                                         for(j=0;j<255;j++){
3575                                                                 consolechars[0]=consolechars[archiveselected];
3576                                                                 consoletext[0][j]=consoletext[archiveselected][j];
3577                                                                 consoleselected=consolechars[0];
3578                                                         }
3579                                                 }
3580                                                 if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
3581                                                         consoleselected--;
3582                                                 }
3583                                                 if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
3584                                                         consoleselected++;
3585                                                 }
3586                                                 if(i==MAC_RETURN_KEY){
3587                                                         archiveselected=0;
3588                                                         donesomething=0;
3589                                                         if(Compare(consoletext[0],"quit ",0,4)||Compare(consoletext[0],"exit ",0,4)){
3590                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3591                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3592                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3593                                                                 donesomething=1;
3594                                                                 tryquit=1;
3595                                                         }
3596                                                         /*if(Compare(consoletext[0],"send ",0,4)){
3597                                                         for(j=5;j<consolechars[0];j++){
3598                                                         talkname[j-5]=consoletext[0][j];
3599                                                         }
3600                                                         talkname[consolechars[0]-5]='\0';
3601                                                         sprintf (chatname, "%s: %s",playerName,talkname);
3602                                                         //NetworkSendInformation(chatname);
3603                                                         donesomething=1;
3604                                                         }
3605                                                         if(Compare(consoletext[0],"name ",0,4)){
3606                                                         int numchars;
3607                                                         numchars=consolechars[0]-5;
3608                                                         if(numchars>32)numchars=32;
3609                                                         for(j=5;j<numchars+5;j++){
3610                                                         talkname[j-5]=consoletext[0][j];
3611                                                         }
3612                                                         talkname[numchars]='\0';
3613                                                         sprintf (chatname, "Player %s is now known as %s.",playerName,talkname);
3614                                                         //NetworkSendInformation(chatname);
3615                                                         sprintf (playerName, "%s",talkname);
3616                                                         //NetworkSendName(playerName);
3617                                                         donesomething=1;
3618                                                         }*/
3619                                                         if(Compare(consoletext[0],"map ",0,3)){
3620                                                                 mapname[0]=':';
3621                                                                 mapname[1]='D';
3622                                                                 mapname[2]='a';
3623                                                                 mapname[3]='t';
3624                                                                 mapname[4]='a';
3625                                                                 mapname[5]=':';
3626                                                                 mapname[6]='M';
3627                                                                 mapname[7]='a';
3628                                                                 mapname[8]='p';
3629                                                                 mapname[9]='s';
3630                                                                 mapname[10]=':';
3631                                                                 for(j=4;j<consolechars[0];j++){
3632                                                                         mapname[j-4+11]=consoletext[0][j];
3633                                                                 }
3634                                                                 mapname[consolechars[0]-4+11]='\0';
3635                                                                 Loadlevel(mapname);
3636                                                                 whichlevel=-2;
3637                                                                 campaign=0;
3638                                                                 donesomething=1;
3639                                                         }
3640                                                         /*if(Compare(consoletext[0],"connect ",0,7)&&!ishost){
3641                                                         int v;
3642                                                         unsigned char playerNameStr[32];
3643                                                         char theIPAddress[256];
3644                                                         char thePort[32];
3645                                                         NMUInt32 port = 25710;
3646
3647                                                         strcpy(playerName, "Client");
3648                                                         GameC2PStr( playerName, playerNameStr );
3649
3650                                                         for(j=0;j<consolechars[0]-8;j++){
3651                                                         theIPAddress[j]=consoletext[0][j+8];
3652                                                         }
3653                                                         theIPAddress[consolechars[0]-8]='\0';
3654
3655                                                         sprintf( thePort, "%li", port );
3656                                                         v=NetworkStartClient( theIPAddress, thePort, playerNameStr );
3657                                                         if(v)
3658                                                         {
3659                                                         if(consolechars[0]>0){
3660                                                         for(k=14;k>=1;k--){
3661                                                         for(j=0;j<255;j++){
3662                                                         consoletext[k][j]=consoletext[k-1][j];
3663                                                         }
3664                                                         consolechars[k]=consolechars[k-1];
3665                                                         }
3666                                                         for(j=0;j<255;j++){
3667                                                         consoletext[0][j]=' ';
3668                                                         }
3669                                                         if(v!=-4994)sprintf (consoletext[0], "Error #%d!!!",v);
3670                                                         else sprintf (consoletext[0], "Could not open connection");
3671
3672                                                         consolechars[0]=255;
3673                                                         consoleselected=0;
3674                                                         }
3675                                                         }
3676                                                         else
3677                                                         {
3678                                                         donesomething=1;
3679                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3680                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3681                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3682
3683                                                         if(consolechars[0]>0){
3684                                                         for(k=14;k>=1;k--){
3685                                                         for(j=0;j<255;j++){
3686                                                         consoletext[k][j]=consoletext[k-1][j];
3687                                                         }
3688                                                         consolechars[k]=consolechars[k-1];
3689                                                         }
3690                                                         for(j=0;j<255;j++){
3691                                                         consoletext[0][j]=' ';
3692                                                         }
3693                                                         sprintf (consoletext[0], "Connected to %s",theIPAddress);
3694
3695                                                         consolechars[0]=255;
3696                                                         consoleselected=0;
3697                                                         }
3698                                                         }
3699                                                         }
3700
3701                                                         if(Compare(consoletext[0],"host ",0,4)){
3702                                                         unsigned char gameNameStr[32], playerNameStr[32];
3703                                                         char gameName[32];//, playerName[32];
3704                                                         NMUInt32 port;
3705                                                         int players;
3706                                                         int v;
3707
3708                                                         port = 25710;
3709                                                         players =4;
3710
3711                                                         strcpy(gameName, "Host's game");
3712                                                         strcpy(playerName, "Host");
3713                                                         GameC2PStr( gameName, gameNameStr );
3714                                                         GameC2PStr( playerName, playerNameStr );
3715
3716                                                         v=NetworkStartServer( (NMUInt16)port, players, gameNameStr, playerNameStr );
3717                                                         if(v)
3718                                                         {
3719                                                         if(consolechars[0]>0){
3720                                                         for(k=14;k>=1;k--){
3721                                                         for(j=0;j<255;j++){
3722                                                         consoletext[k][j]=consoletext[k-1][j];
3723                                                         }
3724                                                         consolechars[k]=consolechars[k-1];
3725                                                         }
3726                                                         for(j=0;j<255;j++){
3727                                                         consoletext[0][j]=' ';
3728                                                         }
3729                                                         sprintf (consoletext[0], "Error #%d!!!",v);
3730
3731                                                         consolechars[0]=255;
3732                                                         consoleselected=0;
3733                                                         }
3734                                                         }
3735                                                         else
3736                                                         {
3737                                                         donesomething=1;
3738                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3739                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
3740                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
3741
3742                                                         if(consolechars[0]>0){
3743                                                         for(k=14;k>=1;k--){
3744                                                         for(j=0;j<255;j++){
3745                                                         consoletext[k][j]=consoletext[k-1][j];
3746                                                         }
3747                                                         consolechars[k]=consolechars[k-1];
3748                                                         }
3749                                                         for(j=0;j<255;j++){
3750                                                         consoletext[0][j]=' ';
3751                                                         }
3752                                                         sprintf (consoletext[0], "Game hosted");
3753
3754                                                         consolechars[0]=255;
3755                                                         consoleselected=0;
3756                                                         }
3757                                                         }
3758                                                         }
3759                                                         */
3760                                                         if(Compare(consoletext[0],"save ",0,4)){
3761                                                                 mapname[0]=':';
3762                                                                 mapname[1]='D';
3763                                                                 mapname[2]='a';
3764                                                                 mapname[3]='t';
3765                                                                 mapname[4]='a';
3766                                                                 mapname[5]=':';
3767                                                                 mapname[6]='M';
3768                                                                 mapname[7]='a';
3769                                                                 mapname[8]='p';
3770                                                                 mapname[9]='s';
3771                                                                 mapname[10]=':';
3772                                                                 for(j=5;j<consolechars[0];j++){
3773                                                                         mapname[j-5+11]=consoletext[0][j];
3774                                                                 }
3775                                                                 mapname[consolechars[0]-5+11]='\0';
3776
3777                                                                 PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
3778                                                                 OPENAL_SetVolume(channels[consolesuccesssound], 256);
3779                                                                 OPENAL_SetPaused(channels[consolesuccesssound], false);
3780
3781                                                                 int mapvers;
3782                                                                 mapvers=12;
3783
3784
3785                                                                 FILE                    *tfile;
3786                                                                 tfile=fopen( mapname, "wb" );
3787                                                                 fpackf(tfile, "Bi", mapvers);
3788                                                                 //fpackf(tfile, "Bi", indemo);
3789                                                                 fpackf(tfile, "Bi", maptype);
3790                                                                 fpackf(tfile, "Bi", hostile);
3791                                                                 fpackf(tfile, "Bf Bf", viewdistance, fadestart);
3792                                                                 fpackf(tfile, "Bb Bf Bf Bf", skyboxtexture, skyboxr, skyboxg, skyboxb);
3793                                                                 fpackf(tfile, "Bf Bf Bf", skyboxlightr, skyboxlightg, skyboxlightb);
3794                                                                 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);
3795                                                                 if(player[0].num_weapons>0&&player[0].num_weapons<5)
3796                                                                         for(j=0;j<player[0].num_weapons;j++){
3797                                                                                 fpackf(tfile, "Bi", weapons.type[player[0].weaponids[j]]);
3798                                                                         }
3799
3800                                                                         fpackf(tfile, "Bf Bf Bf", player[0].armorhead, player[0].armorhigh, player[0].armorlow);
3801                                                                         fpackf(tfile, "Bf Bf Bf", player[0].protectionhead, player[0].protectionhigh, player[0].protectionlow);
3802                                                                         fpackf(tfile, "Bf Bf Bf", player[0].metalhead, player[0].metalhigh, player[0].metallow);
3803                                                                         fpackf(tfile, "Bf Bf", player[0].power, player[0].speedmult);
3804
3805                                                                         fpackf(tfile, "Bi", player[0].numclothes);
3806
3807                                                                         fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
3808
3809                                                                         fpackf(tfile, "Bi", numdialogues);
3810                                                                         if(numdialogues)
3811                                                                                 for(k=0;k<numdialogues;k++){
3812                                                                                         fpackf(tfile, "Bi", numdialogueboxes[k]);
3813                                                                                         fpackf(tfile, "Bi", dialoguetype[k]);
3814                                                                                         for(l=0;l<10;l++){
3815                                                                                                 fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
3816                                                                                                 fpackf(tfile, "Bf", participantrotation[k][l]);
3817                                                                                         }
3818                                                                                         if(numdialogueboxes)
3819                                                                                                 for(l=0;l<numdialogueboxes[k];l++){
3820                                                                                                         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
3821                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
3822                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
3823                                                                                                         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
3824                                                                                                         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
3825
3826                                                                                                         templength=strlen(dialoguetext[k][l]);
3827                                                                                                         fpackf(tfile, "Bi",(templength));
3828                                                                                                         for(m=0;m<templength;m++){
3829                                                                                                                 fpackf(tfile, "Bb", dialoguetext[k][l][m]);
3830                                                                                                                 if(dialoguetext[k][l][m]=='\0')break;
3831                                                                                                         }
3832
3833                                                                                                         templength=strlen(dialoguename[k][l]);
3834                                                                                                         fpackf(tfile, "Bi",templength);
3835                                                                                                         for(m=0;m<templength;m++){
3836                                                                                                                 fpackf(tfile, "Bb", dialoguename[k][l][m]);
3837                                                                                                                 if(dialoguename[k][l][m]=='\0')break;
3838                                                                                                         }
3839
3840                                                                                                         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
3841                                                                                                         fpackf(tfile, "Bi", participantfocus[k][l]);
3842                                                                                                         fpackf(tfile, "Bi", participantaction[k][l]);
3843
3844                                                                                                         for(m=0;m<10;m++)
3845                                                                                                                 fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
3846
3847                                                                                                         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
3848                                                                                                 }
3849                                                                                 }
3850
3851                                                                                 if(player[0].numclothes)
3852                                                                                         for(k=0;k<player[0].numclothes;k++){
3853                                                                                                 templength=strlen(player[0].clothes[k]);
3854                                                                                                 fpackf(tfile, "Bi", templength);
3855                                                                                                 for(l=0;l<templength;l++)
3856                                                                                                         fpackf(tfile, "Bb", player[0].clothes[k][l]);
3857                                                                                                 fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
3858                                                                                         }
3859
3860                                                                                         fpackf(tfile, "Bi", environment);
3861
3862                                                                                         fpackf(tfile, "Bi", objects.numobjects);
3863
3864                                                                                         if(objects.numobjects)
3865                                                                                                 for(k=0;k<objects.numobjects;k++){
3866                                                                                                         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]);
3867                                                                                                 }
3868
3869                                                                                                 fpackf(tfile, "Bi", numhotspots);
3870                                                                                                 if(numhotspots)
3871                                                                                                         for(i=0;i<numhotspots;i++){
3872                                                                                                                 fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
3873                                                                                                                 templength=strlen(hotspottext[i]);
3874                                                                                                                 fpackf(tfile, "Bi",templength);
3875                                                                                                                 for(l=0;l<templength;l++)
3876                                                                                                                         fpackf(tfile, "Bb", hotspottext[i][l]);
3877                                                                                                         }
3878
3879                                                                                                         fpackf(tfile, "Bi", numplayers);
3880                                                                                                         if(numplayers>1&&numplayers<maxplayers)
3881                                                                                                                 for(j=1;j<numplayers;j++){
3882                                                                                                                         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);
3883                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
3884                                                                                                                                 for(k=0;k<player[j].num_weapons;k++){
3885                                                                                                                                         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
3886                                                                                                                                 }
3887                                                                                                                                 if(player[j].numwaypoints<30){
3888                                                                                                                                         fpackf(tfile, "Bi", player[j].numwaypoints);
3889                                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
3890                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].x);
3891                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].y);
3892                                                                                                                                                 fpackf(tfile, "Bf", player[j].waypoints[k].z);
3893                                                                                                                                                 fpackf(tfile, "Bi", player[j].waypointtype[k]);
3894                                                                                                                                         }
3895                                                                                                                                         fpackf(tfile, "Bi", player[j].waypoint);
3896                                                                                                                                 }
3897                                                                                                                                 else{
3898                                                                                                                                         player[j].numwaypoints=0;
3899                                                                                                                                         player[j].waypoint=0;
3900                                                                                                                                         fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
3901                                                                                                                                 }
3902
3903                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
3904                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
3905                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
3906                                                                                                                                 fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
3907
3908                                                                                                                                 if(player[j].creature==wolftype){
3909                                                                                                                                         headprop=player[j].proportionhead.x/1.1;
3910                                                                                                                                         bodyprop=player[j].proportionbody.x/1.1;
3911                                                                                                                                         armprop=player[j].proportionarms.x/1.1;
3912                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3913                                                                                                                                 }
3914
3915                                                                                                                                 if(player[j].creature==rabbittype){
3916                                                                                                                                         headprop=player[j].proportionhead.x/1.2;
3917                                                                                                                                         bodyprop=player[j].proportionbody.x/1.05;
3918                                                                                                                                         armprop=player[j].proportionarms.x/1.00;
3919                                                                                                                                         legprop=player[j].proportionlegs.x/1.1;
3920                                                                                                                                 }
3921
3922                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
3923
3924
3925
3926                                                                                                                                 fpackf(tfile, "Bi", player[j].numclothes);
3927                                                                                                                                 if(player[j].numclothes)
3928                                                                                                                                         for(k=0;k<player[j].numclothes;k++){
3929                                                                                                                                                 int templength;
3930                                                                                                                                                 templength=strlen(player[j].clothes[k]);
3931                                                                                                                                                 fpackf(tfile, "Bi", templength);
3932                                                                                                                                                 for(l=0;l<templength;l++)
3933                                                                                                                                                         fpackf(tfile, "Bb", player[j].clothes[k][l]);
3934                                                                                                                                                 fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
3935                                                                                                                                         }
3936                                                                                                                 }
3937
3938                                                                                                                 fpackf(tfile, "Bi", numpathpoints);
3939                                                                                                                 if(numpathpoints)
3940                                                                                                                         for(j=0;j<numpathpoints;j++){
3941                                                                                                                                 fpackf(tfile, "Bf Bf Bf Bi", pathpoint[j].x, pathpoint[j].y, pathpoint[j].z, numpathpointconnect[j]);
3942                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
3943                                                                                                                                         fpackf(tfile, "Bi", pathpointconnect[j][k]);
3944                                                                                                                                 }
3945                                                                                                                         }
3946
3947                                                                                                                         fpackf(tfile, "Bf Bf Bf Bf", mapcenter.x, mapcenter.y, mapcenter.z, mapradius);
3948
3949
3950                                                                                                                         fclose(tfile);
3951                                                                                                                         donesomething=1;
3952
3953                                                                                                                         /*
3954                                                                                                                         FILE                    *tfile;
3955                                                                                                                         tfile=fopen( mapname, "wb" );
3956                                                                                                                         fwrite( &mapvers, 1, sizeof(int), tfile );
3957                                                                                                                         fwrite( &player[0].coords.x, 1, sizeof(float), tfile );
3958                                                                                                                         fwrite( &player[0].coords.y, 1, sizeof(float), tfile );
3959                                                                                                                         fwrite( &player[0].coords.z, 1, sizeof(float), tfile );
3960                                                                                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
3961                                                                                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
3962                                                                                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
3963                                                                                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
3964                                                                                                                         for(j=0;j<player[0].num_weapons;j++){
3965                                                                                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
3966                                                                                                                         }
3967
3968                                                                                                                         fwrite( &player[0].armorhead, 1, sizeof(int), tfile );
3969                                                                                                                         fwrite( &player[0].armorhigh, 1, sizeof(int), tfile );
3970                                                                                                                         fwrite( &player[0].armorlow, 1, sizeof(int), tfile );
3971                                                                                                                         fwrite( &player[0].protectionhead, 1, sizeof(int), tfile );
3972                                                                                                                         fwrite( &player[0].protectionhigh, 1, sizeof(int), tfile );
3973                                                                                                                         fwrite( &player[0].protectionlow, 1, sizeof(int), tfile );
3974                                                                                                                         fwrite( &player[0].metalhead, 1, sizeof(int), tfile );
3975                                                                                                                         fwrite( &player[0].metalhigh, 1, sizeof(int), tfile );
3976                                                                                                                         fwrite( &player[0].metallow, 1, sizeof(int), tfile );
3977                                                                                                                         fwrite( &player[0].power, 1, sizeof(int), tfile );
3978                                                                                                                         fwrite( &player[0].speedmult, 1, sizeof(int), tfile );
3979
3980                                                                                                                         fwrite( &player[0].numclothes, 1, sizeof(int), tfile );
3981                                                                                                                         if(player[0].numclothes)
3982                                                                                                                         for(k=0;k<player[0].numclothes;k++){
3983                                                                                                                         int templength;
3984                                                                                                                         templength=strlen(player[0].clothes[k]);
3985                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
3986                                                                                                                         for(l=0;l<templength;l++)
3987                                                                                                                         fwrite( &player[0].clothes[k][l],1,sizeof(char),tfile);
3988                                                                                                                         fwrite( &player[0].clothestintr[k],1,sizeof(float),tfile);
3989                                                                                                                         fwrite( &player[0].clothestintg[k],1,sizeof(float),tfile);
3990                                                                                                                         fwrite( &player[0].clothestintb[k],1,sizeof(float),tfile);
3991                                                                                                                         }
3992
3993                                                                                                                         fwrite( &environment, 1, sizeof(int), tfile );
3994
3995                                                                                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
3996
3997                                                                                                                         for(k=0;k<objects.numobjects;k++){
3998                                                                                                                         fwrite( &objects.type[k], 1, sizeof(int), tfile );
3999                                                                                                                         fwrite( &objects.rotation[k], 1, sizeof(float), tfile );
4000                                                                                                                         fwrite( &objects.rotation2[k], 1, sizeof(float), tfile );
4001                                                                                                                         fwrite( &objects.position[k].x, 1, sizeof(float), tfile );
4002                                                                                                                         fwrite( &objects.position[k].y, 1, sizeof(float), tfile );
4003                                                                                                                         fwrite( &objects.position[k].z, 1, sizeof(float), tfile );
4004                                                                                                                         fwrite( &objects.scale[k], 1, sizeof(float), tfile );
4005                                                                                                                         }
4006
4007                                                                                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4008                                                                                                                         if(numplayers>1&&numplayers<maxplayers)
4009                                                                                                                         for(j=1;j<numplayers;j++){
4010                                                                                                                         fwrite( &player[j].whichskin, 1, sizeof(int), tfile );
4011                                                                                                                         fwrite( &player[j].creature, 1, sizeof(int), tfile );
4012                                                                                                                         fwrite( &player[j].coords.x, 1, sizeof(float), tfile );
4013                                                                                                                         fwrite( &player[j].coords.y, 1, sizeof(float), tfile );
4014                                                                                                                         fwrite( &player[j].coords.z, 1, sizeof(float), tfile );
4015                                                                                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4016                                                                                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4017                                                                                                                         for(k=0;k<player[j].num_weapons;k++){
4018                                                                                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4019                                                                                                                         }
4020                                                                                                                         if(player[j].numwaypoints<30){
4021                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4022                                                                                                                         for(k=0;k<player[j].numwaypoints;k++){
4023                                                                                                                         fwrite( &player[j].waypoints[k].x, 1, sizeof(float), tfile );
4024                                                                                                                         fwrite( &player[j].waypoints[k].y, 1, sizeof(float), tfile );
4025                                                                                                                         fwrite( &player[j].waypoints[k].z, 1, sizeof(float), tfile );
4026                                                                                                                         }
4027                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4028                                                                                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4029                                                                                                                         }
4030                                                                                                                         else{
4031                                                                                                                         player[j].numwaypoints=0;
4032                                                                                                                         player[j].waypoint=0;
4033                                                                                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4034                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4035                                                                                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4036                                                                                                                         }
4037                                                                                                                         fwrite( &player[j].armorhead, 1, sizeof(int), tfile );
4038                                                                                                                         fwrite( &player[j].armorhigh, 1, sizeof(int), tfile );
4039                                                                                                                         fwrite( &player[j].armorlow, 1, sizeof(int), tfile );
4040                                                                                                                         fwrite( &player[j].protectionhead, 1, sizeof(int), tfile );
4041                                                                                                                         fwrite( &player[j].protectionhigh, 1, sizeof(int), tfile );
4042                                                                                                                         fwrite( &player[j].protectionlow, 1, sizeof(int), tfile );
4043                                                                                                                         fwrite( &player[j].metalhead, 1, sizeof(int), tfile );
4044                                                                                                                         fwrite( &player[j].metalhigh, 1, sizeof(int), tfile );
4045                                                                                                                         fwrite( &player[j].metallow, 1, sizeof(int), tfile );
4046                                                                                                                         fwrite( &player[j].power, 1, sizeof(int), tfile );
4047                                                                                                                         fwrite( &player[j].speedmult, 1, sizeof(int), tfile );
4048
4049                                                                                                                         fwrite( &player[j].numclothes, 1, sizeof(int), tfile );
4050                                                                                                                         if(player[j].numclothes)
4051                                                                                                                         for(k=0;k<player[j].numclothes;k++){
4052                                                                                                                         int templength;
4053                                                                                                                         templength=strlen(player[j].clothes[k]);
4054                                                                                                                         fwrite( &templength,1,sizeof(int),tfile);
4055                                                                                                                         for(l=0;l<templength;l++)
4056                                                                                                                         fwrite( &player[j].clothes[k][l],1,sizeof(char),tfile);
4057                                                                                                                         fwrite( &player[j].clothestintr[k],1,sizeof(float),tfile);
4058                                                                                                                         fwrite( &player[j].clothestintg[k],1,sizeof(float),tfile);
4059                                                                                                                         fwrite( &player[j].clothestintb[k],1,sizeof(float),tfile);
4060                                                                                                                         }
4061                                                                                                                         }
4062                                                                                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4063                                                                                                                         if(numpathpoints)
4064                                                                                                                         for(j=0;j<numpathpoints;j++){
4065                                                                                                                         fwrite( &pathpoint[j].x, 1, sizeof(float), tfile );
4066                                                                                                                         fwrite( &pathpoint[j].y, 1, sizeof(float), tfile );
4067                                                                                                                         fwrite( &pathpoint[j].z, 1, sizeof(float), tfile );
4068                                                                                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4069                                                                                                                         for(k=0;k<numpathpointconnect[j];k++){
4070                                                                                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4071                                                                                                                         }
4072                                                                                                                         }
4073
4074                                                                                                                         fwrite( &mapcenter.x, 1, sizeof(float), tfile );
4075                                                                                                                         fwrite( &mapcenter.y, 1, sizeof(float), tfile );
4076                                                                                                                         fwrite( &mapcenter.z, 1, sizeof(float), tfile );
4077
4078                                                                                                                         fwrite( &mapradius, 1, sizeof(float), tfile );
4079
4080                                                                                                                         fclose(tfile);
4081                                                                                                                         donesomething=1;*/
4082                                                         }
4083                                                         /*
4084                                                         if(Compare(consoletext[0],"save ",0,4)){
4085                                                         mapname[0]=':';
4086                                                         mapname[1]='D';
4087                                                         mapname[2]='a';
4088                                                         mapname[3]='t';
4089                                                         mapname[4]='a';
4090                                                         mapname[5]=':';
4091                                                         mapname[6]='M';
4092                                                         mapname[7]='a';
4093                                                         mapname[8]='p';
4094                                                         mapname[9]='s';
4095                                                         mapname[10]=':';
4096                                                         for(j=5;j<consolechars[0];j++){
4097                                                         mapname[j-5+11]=consoletext[0][j];
4098                                                         }
4099                                                         mapname[consolechars[0]-5+11]='\0';
4100
4101                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
4102                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
4103                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
4104
4105                                                         FILE                    *tfile;
4106                                                         tfile=fopen( mapname, "wb" );
4107                                                         fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
4108                                                         fwrite( &player[0].rotation, 1, sizeof(float), tfile );
4109                                                         fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
4110                                                         fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
4111                                                         if(player[0].num_weapons>0&&player[0].num_weapons<5)
4112                                                         for(j=0;j<player[0].num_weapons;j++){
4113                                                         fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
4114                                                         }
4115                                                         fwrite( &environment, 1, sizeof(int), tfile );
4116
4117                                                         fwrite( &objects.numobjects, 1, sizeof(int), tfile );
4118                                                         fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
4119                                                         fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
4120                                                         fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
4121                                                         fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
4122
4123                                                         fwrite( &numplayers, 1, sizeof(int), tfile );
4124                                                         if(numplayers>1&&numplayers<maxplayers)
4125                                                         for(j=1;j<numplayers;j++){
4126                                                         fwrite( &player[j].coords, 1, sizeof(XYZ), tfile );
4127                                                         fwrite( &player[j].num_weapons, 1, sizeof(int), tfile );
4128                                                         if(player[j].num_weapons>0&&player[j].num_weapons<5)
4129                                                         for(k=0;k<player[j].num_weapons;k++){
4130                                                         fwrite( &weapons.type[player[j].weaponids[k]], 1, sizeof(int), tfile );
4131                                                         }
4132                                                         if(player[j].numwaypoints<30){
4133                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4134                                                         fwrite( &player[j].waypoints, 1, sizeof(XYZ)*player[j].numwaypoints, tfile );
4135                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4136                                                         //fwrite( &player[j].jumppath, 1, sizeof(bool), tfile );
4137                                                         }
4138                                                         else{
4139                                                         player[j].numwaypoints=0;
4140                                                         player[j].waypoint=0;
4141                                                         fwrite( &player[j].numwaypoints, 1, sizeof(int), tfile );
4142                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4143                                                         fwrite( &player[j].waypoint, 1, sizeof(int), tfile );
4144                                                         }
4145                                                         }
4146                                                         fwrite( &numpathpoints, 1, sizeof(int), tfile );
4147                                                         if(numpathpoints)
4148                                                         for(j=0;j<numpathpoints;j++){
4149                                                         fwrite( &pathpoint[j], 1, sizeof(XYZ), tfile );
4150                                                         fwrite( &numpathpointconnect[j], 1, sizeof(int), tfile );
4151                                                         for(k=0;k<numpathpointconnect[j];k++){
4152                                                         fwrite( &pathpointconnect[j][k], 1, sizeof(int), tfile );
4153                                                         }
4154                                                         }
4155                                                         fclose(tfile);
4156                                                         donesomething=1;
4157                                                         }*/
4158                                                         if(Compare(consoletext[0],"cellar door ",0,11)||Compare(consoletext[0],"cellardoor ",0,10)){
4159                                                                 LoadTextureSave(":Data:Textures:Furdarko.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4160                                                                 donesomething=1;
4161                                                         }
4162                                                         /*if(Compare(consoletext[0],"Pants ",0,5)){
4163                                                         AddClothes(":Data:Textures:Pants.png",0,1,&player[i].skeleton.skinText[0],&player[i].skeleton.skinsize);
4164                                                         player[i].DoMipmaps(5,0,0,player[i].skeleton.skinsize,player[i].skeleton.skinsize);
4165                                                         donesomething=1;
4166                                                         }*/
4167
4168                                                         if(Compare(consoletext[0],"tintr ",0,5)||Compare(consoletext[0],"Tintr ",0,5)){
4169                                                                 for(j=6;j<consolechars[0];j++){
4170                                                                         mapname[j-6]=consoletext[0][j];
4171                                                                 }
4172
4173                                                                 tintr=atof(mapname);
4174
4175                                                                 donesomething=1;
4176                                                         }
4177
4178                                                         if(Compare(consoletext[0],"speed ",0,5)||Compare(consoletext[0],"Speed ",0,5)){
4179                                                                 for(j=6;j<consolechars[0];j++){
4180                                                                         mapname[j-6]=consoletext[0][j];
4181                                                                 }
4182
4183                                                                 player[0].speedmult=atof(mapname);
4184
4185                                                                 donesomething=1;
4186                                                         }
4187
4188                                                         if(Compare(consoletext[0],"strength ",0,8)||Compare(consoletext[0],"Strength ",0,8)){
4189                                                                 for(j=9;j<consolechars[0];j++){
4190                                                                         mapname[j-9]=consoletext[0][j];
4191                                                                 }
4192
4193                                                                 player[0].power=atof(mapname);
4194
4195                                                                 donesomething=1;
4196                                                         }
4197
4198                                                         if(Compare(consoletext[0],"viewdistance ",0,12)||Compare(consoletext[0],"Viewdistance ",0,12)){
4199                                                                 for(j=13;j<consolechars[0];j++){
4200                                                                         mapname[j-13]=consoletext[0][j];
4201                                                                 }
4202
4203                                                                 viewdistance=atof(mapname)*100;
4204
4205                                                                 donesomething=1;
4206                                                         }
4207
4208                                                         if(Compare(consoletext[0],"fadestart ",0,9)||Compare(consoletext[0],"Fadestart ",0,9)){
4209                                                                 for(j=10;j<consolechars[0];j++){
4210                                                                         mapname[j-10]=consoletext[0][j];
4211                                                                 }
4212
4213                                                                 fadestart=atof(mapname);
4214
4215                                                                 donesomething=1;
4216                                                         }
4217
4218                                                         if(Compare(consoletext[0],"power ",0,5)||Compare(consoletext[0],"Power ",0,5)){
4219                                                                 for(j=6;j<consolechars[0];j++){
4220                                                                         mapname[j-6]=consoletext[0][j];
4221                                                                 }
4222
4223                                                                 player[0].power=atof(mapname);
4224
4225                                                                 donesomething=1;
4226                                                         }
4227
4228                                                         if(Compare(consoletext[0],"slomo ",0,5)||Compare(consoletext[0],"Slomo ",0,5)){
4229                                                                 for(j=6;j<consolechars[0];j++){
4230                                                                         mapname[j-6]=consoletext[0][j];
4231                                                                 }
4232
4233                                                                 slomospeed=atof(mapname);
4234                                                                 slomo=1-slomo;
4235                                                                 slomodelay=1000;
4236
4237                                                                 donesomething=1;
4238                                                         }
4239
4240                                                         if(Compare(consoletext[0],"slofreq ",0,7)||Compare(consoletext[0],"Slofreq ",0,7)){
4241                                                                 for(j=8;j<consolechars[0];j++){
4242                                                                         mapname[j-8]=consoletext[0][j];
4243                                                                 }
4244
4245                                                                 slomofreq=atoi(mapname);
4246
4247                                                                 donesomething=1;
4248                                                         }
4249
4250                                                         if(Compare(consoletext[0],"size ",0,4)||Compare(consoletext[0],"Size ",0,4)){
4251                                                                 for(j=5;j<consolechars[0];j++){
4252                                                                         mapname[j-5]=consoletext[0][j];
4253                                                                 }
4254
4255                                                                 player[0].scale=atof(mapname)*.2;
4256
4257                                                                 donesomething=1;
4258                                                         }
4259
4260                                                         if(Compare(consoletext[0],"sizenear ",0,8)||Compare(consoletext[0],"Sizenear ",0,8)){
4261                                                                 int closest=-1;
4262                                                                 float closestdist=-1;
4263                                                                 float distance;
4264                                                                 if(numplayers>1)
4265                                                                         for(i=1;i<numplayers;i++){
4266                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4267                                                                                 if(closestdist==-1||distance<closestdist){
4268                                                                                         closestdist=distance;
4269                                                                                         closest=i;
4270                                                                                 }
4271                                                                         }
4272
4273                                                                         for(j=9;j<consolechars[0];j++){
4274                                                                                 mapname[j-9]=consoletext[0][j];
4275                                                                         }
4276
4277                                                                         player[closest].scale=atof(mapname)*.2;
4278
4279                                                                         donesomething=1;
4280                                                         }
4281
4282                                                         if(Compare(consoletext[0],"proportionnear ",0,14)||Compare(consoletext[0],"Proportionnear ",0,14)){
4283                                                                 int startpoint;
4284                                                                 int alldone;
4285
4286                                                                 int closest=-1;
4287                                                                 float closestdist=-1;
4288                                                                 float distance;
4289                                                                 if(numplayers>1)
4290                                                                         for(i=1;i<numplayers;i++){
4291                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
4292                                                                                 if(closestdist==-1||distance<closestdist){
4293                                                                                         closestdist=distance;
4294                                                                                         closest=i;
4295                                                                                 }
4296                                                                         }
4297
4298                                                                         alldone=0;
4299                                                                         startpoint=15;
4300                                                                         j=startpoint;
4301                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4302                                                                                 mapname[j-startpoint]=consoletext[0][j];
4303                                                                                 j++;
4304                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4305                                                                         }
4306                                                                         mapname[j-startpoint]='\0';
4307
4308                                                                         headprop=atof(mapname);
4309
4310                                                                         j++;
4311                                                                         startpoint=j;
4312                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4313                                                                                 mapname[j-startpoint]=consoletext[0][j];
4314                                                                                 j++;
4315                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4316                                                                         }
4317                                                                         mapname[j-startpoint]='\0';
4318
4319                                                                         bodyprop=atof(mapname);
4320
4321                                                                         j++;
4322                                                                         startpoint=j;
4323                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4324                                                                                 mapname[j-startpoint]=consoletext[0][j];
4325                                                                                 j++;
4326                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4327                                                                         }
4328                                                                         mapname[j-startpoint]='\0';
4329
4330                                                                         armprop=atof(mapname);
4331
4332                                                                         j++;
4333                                                                         startpoint=j;
4334                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4335                                                                                 mapname[j-startpoint]=consoletext[0][j];
4336                                                                                 j++;
4337                                                                                 if(consoletext[0][j]=='\0')alldone=1;
4338                                                                         }
4339                                                                         mapname[j-startpoint]='\0';
4340
4341                                                                         legprop=atof(mapname);
4342
4343                                                                         if(player[closest].creature==wolftype){
4344                                                                                 player[closest].proportionhead=1.1*headprop;
4345                                                                                 player[closest].proportionbody=1.1*bodyprop;
4346                                                                                 player[closest].proportionarms=1.1*armprop;
4347                                                                                 player[closest].proportionlegs=1.1*legprop;
4348                                                                         }
4349
4350                                                                         if(player[closest].creature==rabbittype){
4351                                                                                 player[closest].proportionhead=1.2*headprop;
4352                                                                                 player[closest].proportionbody=1.05*bodyprop;
4353                                                                                 player[closest].proportionarms=1.00*armprop;
4354                                                                                 player[closest].proportionlegs=1.1*legprop;
4355                                                                                 player[closest].proportionlegs.y=1.05*legprop;
4356                                                                         }
4357
4358                                                                         donesomething=1;
4359                                                         }
4360
4361
4362                                                         if(Compare(consoletext[0],"sizemin ",0,7)||Compare(consoletext[0],"Sizemin ",0,7)){
4363                                                                 for(i=1;i<numplayers;i++){
4364                                                                         if(player[i].scale<0.8*0.2)player[i].scale=0.8*0.2;
4365                                                                 }
4366
4367                                                                 donesomething=1;
4368                                                         }
4369
4370                                                         if(Compare(consoletext[0],"tutorial ",0,8)||Compare(consoletext[0],"Tutorial ",0,8)){
4371                                                                 for(j=9;j<consolechars[0];j++){
4372                                                                         mapname[j-9]=consoletext[0][j];
4373                                                                 }
4374
4375                                                                 tutoriallevel=atoi(mapname);
4376
4377                                                                 donesomething=1;
4378                                                         }
4379
4380
4381                                                         if(Compare(consoletext[0],"tintg ",0,5)||Compare(consoletext[0],"Tintg ",0,5)){
4382                                                                 for(j=6;j<consolechars[0];j++){
4383                                                                         mapname[j-6]=consoletext[0][j];
4384                                                                 }
4385
4386                                                                 tintg=atof(mapname);
4387
4388                                                                 donesomething=1;
4389                                                         }
4390
4391                                                         if(Compare(consoletext[0],"tintb ",0,5)||Compare(consoletext[0],"Tintb ",0,5)){
4392                                                                 for(j=6;j<consolechars[0];j++){
4393                                                                         mapname[j-6]=consoletext[0][j];
4394                                                                 }
4395
4396                                                                 tintb=atof(mapname);
4397
4398                                                                 donesomething=1;
4399                                                         }
4400
4401                                                         if(Compare(consoletext[0],"hostile ",0,7)){
4402                                                                 for(j=8;j<consolechars[0];j++){
4403                                                                         mapname[j-8]=consoletext[0][j];
4404                                                                 }
4405
4406                                                                 hostile=atoi(mapname);
4407
4408                                                                 donesomething=1;
4409                                                         }
4410
4411
4412                                                         if(Compare(consoletext[0],"type active ",0,11)){
4413                                                                 editoractive=typeactive;
4414
4415                                                                 donesomething=1;
4416                                                         }
4417
4418                                                         if(Compare(consoletext[0],"indemo ",0,6)){
4419                                                                 indemo=1;
4420                                                                 hotspot[numhotspots]=player[0].coords;
4421                                                                 hotspotsize[numhotspots]=0;
4422                                                                 hotspottype[numhotspots]=-111;
4423                                                                 mapname[0]='\0';
4424                                                                 strcpy(hotspottext[numhotspots],"mapname");
4425                                                                 numhotspots++;
4426
4427                                                                 donesomething=1;
4428                                                         }
4429
4430                                                         if(Compare(consoletext[0],"notindemo ",0,9)){
4431                                                                 indemo=0;
4432                                                                 numhotspots--;
4433
4434                                                                 donesomething=1;
4435                                                         }
4436
4437                                                         if(Compare(consoletext[0],"type sitting ",0,12)){
4438                                                                 editoractive=typesitting;
4439
4440                                                                 donesomething=1;
4441                                                         }
4442
4443                                                         if(Compare(consoletext[0],"type sitting wall ",0,17)){
4444                                                                 editoractive=typesittingwall;
4445
4446                                                                 donesomething=1;
4447                                                         }
4448
4449                                                         if(Compare(consoletext[0],"type sleeping ",0,13)){
4450                                                                 editoractive=typesleeping;
4451
4452                                                                 donesomething=1;
4453                                                         }
4454                                                         if(Compare(consoletext[0],"type dead1 ",0,10)){
4455                                                                 editoractive=typedead1;
4456
4457                                                                 donesomething=1;
4458                                                         }
4459                                                         if(Compare(consoletext[0],"type dead2 ",0,10)){
4460                                                                 editoractive=typedead2;
4461
4462                                                                 donesomething=1;
4463                                                         }
4464                                                         if(Compare(consoletext[0],"type dead3 ",0,10)){
4465                                                                 editoractive=typedead3;
4466                                                                 donesomething=1;
4467                                                         }
4468                                                         if(Compare(consoletext[0],"type dead4 ",0,10)){
4469                                                                 editoractive=typedead4;
4470
4471                                                                 donesomething=1;
4472                                                         }
4473
4474                                                         if(Compare(consoletext[0],"path keepwalking ",0,16)){
4475                                                                 editorpathtype=wpkeepwalking;
4476
4477                                                                 donesomething=1;
4478                                                         }
4479
4480                                                         if(Compare(consoletext[0],"path pause ",0,10)){
4481                                                                 editorpathtype=wppause;
4482
4483                                                                 donesomething=1;
4484                                                         }
4485
4486                                                         if(Compare(consoletext[0],"mapkilleveryone ",0,15)){
4487                                                                 maptype=mapkilleveryone;
4488
4489                                                                 donesomething=1;
4490                                                         }
4491
4492                                                         if(Compare(consoletext[0],"mapgosomewhere ",0,14)){
4493                                                                 maptype=mapgosomewhere;
4494
4495                                                                 donesomething=1;
4496                                                         }
4497
4498                                                         if(Compare(consoletext[0],"mapkillsomeone ",0,14)){
4499                                                                 maptype=mapkillsomeone;
4500
4501                                                                 donesomething=1;
4502
4503                                                         }
4504
4505                                                         if(Compare(consoletext[0],"mapkillmost ",0,11)){
4506                                                                 maptype=mapkillmost;
4507
4508                                                                 donesomething=1;
4509
4510                                                         }
4511
4512                                                         if(Compare(consoletext[0],"hs ",0,2)){
4513                                                                 int startpoint;
4514                                                                 int alldone;
4515
4516                                                                 hotspot[numhotspots]=player[0].coords;
4517
4518                                                                 alldone=0;
4519                                                                 startpoint=3;
4520                                                                 j=startpoint;
4521                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4522                                                                         mapname[j-startpoint]=consoletext[0][j];
4523                                                                         j++;
4524                                                                         if(consoletext[0][j]=='\0')alldone=1;
4525                                                                 }
4526                                                                 mapname[j-startpoint]='\0';
4527
4528                                                                 hotspotsize[numhotspots]=atof(mapname);
4529
4530                                                                 j++;
4531                                                                 startpoint=j;
4532                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4533                                                                         mapname[j-startpoint]=consoletext[0][j];
4534                                                                         j++;
4535                                                                         if(consoletext[0][j]=='\0')alldone=1;
4536                                                                 }
4537                                                                 mapname[j-startpoint]='\0';
4538
4539                                                                 hotspottype[numhotspots]=atoi(mapname);
4540
4541                                                                 j++;
4542                                                                 startpoint=j;
4543                                                                 while(consoletext[0][j]!='\0'&&!alldone&&j<255){
4544                                                                         mapname[j-startpoint]=consoletext[0][j];
4545                                                                         j++;
4546                                                                         if(consoletext[0][j]=='\0')alldone=1;
4547                                                                 }
4548                                                                 mapname[j-startpoint]='\n';
4549                                                                 mapname[j-startpoint+1]='\0';
4550
4551                                                                 strcpy(hotspottext[numhotspots],mapname);
4552
4553                                                                 numhotspots++;
4554
4555                                                                 donesomething=1;
4556                                                         }
4557
4558                                                         if(Compare(consoletext[0],"dialogue ",0,8)){
4559                                                                 int startpoint;
4560                                                                 int alldone;
4561
4562                                                                 alldone=0;
4563                                                                 startpoint=9;
4564                                                                 j=startpoint;
4565                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4566                                                                         mapname[j-startpoint]=consoletext[0][j];
4567                                                                         j++;
4568                                                                         if(consoletext[0][j]=='\0')alldone=1;
4569                                                                 }
4570                                                                 mapname[j-startpoint]='\0';
4571                                                                 startpoint=j+1;
4572
4573                                                                 dialoguetype[numdialogues]=atoi(mapname);
4574
4575                                                                 mapname[0]=':';
4576                                                                 mapname[1]='D';
4577                                                                 mapname[2]='a';
4578                                                                 mapname[3]='t';
4579                                                                 mapname[4]='a';
4580                                                                 mapname[5]=':';
4581                                                                 mapname[6]='D';
4582                                                                 mapname[7]='i';
4583                                                                 mapname[8]='a';
4584                                                                 mapname[9]='l';
4585                                                                 mapname[10]='o';
4586                                                                 mapname[11]='g';
4587                                                                 mapname[12]='u';
4588                                                                 mapname[13]='e';
4589                                                                 mapname[14]='s';
4590                                                                 mapname[15]=':';
4591                                                                 for(j=startpoint;j<consolechars[0];j++){
4592                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4593                                                                 }
4594                                                                 mapname[consolechars[0]-startpoint+16]='.';
4595                                                                 mapname[consolechars[0]-startpoint+17]='t';
4596                                                                 mapname[consolechars[0]-startpoint+18]='x';
4597                                                                 mapname[consolechars[0]-startpoint+19]='t';
4598                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4599
4600                                                                 for(j=0;j<max_dialoguelength;j++){
4601                                                                         for(k=0;k<128;k++){
4602                                                                                 dialoguetext[numdialogues][j][k]='\0';
4603                                                                         }
4604                                                                         for(k=0;k<64;k++){
4605                                                                                 dialoguename[numdialogues][j][k]='\0';
4606                                                                         }
4607                                                                 }
4608
4609                                                                 ifstream ipstream(ConvertFileName(mapname));
4610                                                                 ipstream.ignore(256,':');
4611                                                                 ipstream >> numdialogueboxes[numdialogues];
4612                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4613                                                                         ipstream.ignore(256,':');
4614                                                                         ipstream.ignore(256,':');
4615                                                                         ipstream.ignore(256,' ');
4616                                                                         ipstream >> dialogueboxlocation[numdialogues][i];
4617                                                                         ipstream.ignore(256,':');
4618                                                                         ipstream >> dialogueboxcolor[numdialogues][i][0];
4619                                                                         ipstream >> dialogueboxcolor[numdialogues][i][1];
4620                                                                         ipstream >> dialogueboxcolor[numdialogues][i][2];
4621                                                                         ipstream.ignore(256,':');
4622                                                                         ipstream.getline(dialoguename[numdialogues][i],64);
4623                                                                         ipstream.ignore(256,':');
4624                                                                         ipstream.ignore(256,' ');
4625                                                                         ipstream.getline(dialoguetext[numdialogues][i],128);
4626                                                                         for(j=0;j<128;j++){
4627                                                                                 if(dialoguetext[numdialogues][i][j]=='\\')dialoguetext[numdialogues][i][j]='\n';
4628                                                                         }
4629                                                                         ipstream.ignore(256,':');
4630                                                                         ipstream >> dialogueboxsound[numdialogues][i];
4631                                                                 }
4632
4633                                                                 for(i=0;i<numdialogueboxes[numdialogues];i++){
4634                                                                         for(j=0;j<numplayers;j++){
4635                                                                                 participantfacing[numdialogues][i][j]=player[j].facing;
4636                                                                         }
4637                                                                 }
4638                                                                 ipstream.close();
4639
4640                                                                 directing=1;
4641                                                                 indialogue=0;
4642                                                                 whichdialogue=numdialogues;
4643
4644
4645                                                                 numdialogues++;
4646
4647                                                                 donesomething=1;
4648                                                         }
4649
4650                                                         if(Compare(consoletext[0],"fixdialogue ",0,11)){
4651                                                                 int startpoint;
4652                                                                 int alldone;
4653                                                                 int whichdi;
4654
4655                                                                 alldone=0;
4656                                                                 startpoint=12;
4657                                                                 j=startpoint;
4658                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4659                                                                         mapname[j-startpoint]=consoletext[0][j];
4660                                                                         j++;
4661                                                                         if(consoletext[0][j]=='\0')alldone=1;
4662                                                                 }
4663                                                                 mapname[j-startpoint]='\0';
4664                                                                 startpoint=j+1;
4665
4666                                                                 whichdi=atoi(mapname);
4667
4668                                                                 mapname[0]=':';
4669                                                                 mapname[1]='D';
4670                                                                 mapname[2]='a';
4671                                                                 mapname[3]='t';
4672                                                                 mapname[4]='a';
4673                                                                 mapname[5]=':';
4674                                                                 mapname[6]='D';
4675                                                                 mapname[7]='i';
4676                                                                 mapname[8]='a';
4677                                                                 mapname[9]='l';
4678                                                                 mapname[10]='o';
4679                                                                 mapname[11]='g';
4680                                                                 mapname[12]='u';
4681                                                                 mapname[13]='e';
4682                                                                 mapname[14]='s';
4683                                                                 mapname[15]=':';
4684                                                                 for(j=startpoint;j<consolechars[0];j++){
4685                                                                         mapname[j-startpoint+16]=consoletext[0][j];
4686                                                                 }
4687                                                                 mapname[consolechars[0]-startpoint+16]='.';
4688                                                                 mapname[consolechars[0]-startpoint+17]='t';
4689                                                                 mapname[consolechars[0]-startpoint+18]='x';
4690                                                                 mapname[consolechars[0]-startpoint+19]='t';
4691                                                                 mapname[consolechars[0]-startpoint+20]='\0';
4692
4693                                                                 for(j=0;j<max_dialoguelength;j++){
4694                                                                         for(k=0;k<128;k++){
4695                                                                                 dialoguetext[whichdi][j][k]='\0';
4696                                                                         }
4697                                                                         for(k=0;k<64;k++){
4698                                                                                 dialoguename[whichdi][j][k]='\0';
4699                                                                         }
4700                                                                 }
4701
4702                                                                 ifstream ipstream(ConvertFileName(mapname));
4703                                                                 ipstream.ignore(256,':');
4704                                                                 ipstream >> numdialogueboxes[whichdi];
4705                                                                 for(i=0;i<numdialogueboxes[whichdi];i++){
4706                                                                         ipstream.ignore(256,':');
4707                                                                         ipstream.ignore(256,':');
4708                                                                         ipstream.ignore(256,' ');
4709                                                                         ipstream >> dialogueboxlocation[whichdi][i];
4710                                                                         ipstream.ignore(256,':');
4711                                                                         ipstream >> dialogueboxcolor[whichdi][i][0];
4712                                                                         ipstream >> dialogueboxcolor[whichdi][i][1];
4713                                                                         ipstream >> dialogueboxcolor[whichdi][i][2];
4714                                                                         ipstream.ignore(256,':');
4715                                                                         ipstream.getline(dialoguename[whichdi][i],64);
4716                                                                         ipstream.ignore(256,':');
4717                                                                         ipstream.ignore(256,' ');
4718                                                                         ipstream.getline(dialoguetext[whichdi][i],128);
4719                                                                         for(j=0;j<128;j++){
4720                                                                                 if(dialoguetext[whichdi][i][j]=='\\')dialoguetext[whichdi][i][j]='\n';
4721                                                                         }
4722                                                                         ipstream.ignore(256,':');
4723                                                                         ipstream >> dialogueboxsound[whichdi][i];
4724                                                                 }
4725
4726                                                                 ipstream.close();
4727
4728                                                                 donesomething=1;
4729                                                         }
4730
4731                                                         if(Compare(consoletext[0],"fixtype ",0,7)){
4732                                                                 int startpoint;
4733                                                                 int alldone;
4734                                                                 int whichdi;
4735
4736                                                                 alldone=0;
4737                                                                 startpoint=8;
4738                                                                 j=startpoint;
4739                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4740                                                                         mapname[j-startpoint]=consoletext[0][j];
4741                                                                         j++;
4742                                                                         if(consoletext[0][j]=='\0')alldone=1;
4743                                                                 }
4744                                                                 mapname[j-startpoint]='\0';
4745                                                                 dialoguetype[0]=atoi(mapname);
4746
4747                                                                 startpoint=j+1;
4748
4749                                                                 donesomething=1;
4750                                                         }
4751
4752
4753                                                         if(Compare(consoletext[0],"fixrotation ",0,11)){
4754                                                                 participantrotation[whichdialogue][participantfocus[whichdialogue][indialogue]]=player[participantfocus[whichdialogue][indialogue]].rotation;
4755
4756                                                                 donesomething=1;
4757                                                         }
4758
4759                                                         if(Compare(consoletext[0],"ddialogue ",0,9)){
4760                                                                 numdialogues--;
4761                                                                 if(numdialogues<0)numdialogues=0;
4762
4763                                                                 donesomething=1;
4764                                                         }
4765
4766                                                         if(Compare(consoletext[0],"immobile ",0,8)){
4767                                                                 player[0].immobile=1;
4768                                                                 donesomething=1;
4769                                                         }
4770
4771                                                         if(Compare(consoletext[0],"mobile ",0,6)){
4772                                                                 player[0].immobile=0;
4773                                                                 donesomething=1;
4774                                                         }
4775
4776                                                         if(Compare(consoletext[0],"play ",0,4)){
4777                                                                 int startpoint;
4778                                                                 int alldone;
4779
4780                                                                 alldone=0;
4781                                                                 startpoint=5;
4782                                                                 j=startpoint;
4783                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4784                                                                         mapname[j-startpoint]=consoletext[0][j];
4785                                                                         j++;
4786                                                                         if(consoletext[0][j]=='\0')alldone=1;
4787                                                                 }
4788                                                                 mapname[j-startpoint]='\0';
4789                                                                 startpoint=j+1;
4790
4791                                                                 whichdialogue=atoi(mapname);
4792
4793                                                                 if(numdialogues>whichdialogue){
4794                                                                         for(i=0;i<numdialogueboxes[whichdialogue];i++){
4795                                                                                 player[participantfocus[whichdialogue][i]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][i]];
4796                                                                                 player[participantfocus[whichdialogue][i]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4797                                                                                 player[participantfocus[whichdialogue][i]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][i]];
4798                                                                                 player[participantfocus[whichdialogue][i]].velocity=0;
4799                                                                                 player[participantfocus[whichdialogue][i]].targetanimation=player[participantfocus[whichdialogue][i]].getIdle();
4800                                                                                 player[participantfocus[whichdialogue][i]].targetframe=0;
4801                                                                         }
4802
4803                                                                         directing=0;
4804                                                                         indialogue=0;
4805
4806                                                                         donesomething=1;
4807
4808                                                                         //if(dialogueboxsound[whichdialogue][indialogue]!=0){
4809                                                                         float gLoc[3];
4810                                                                         float vel[3];
4811                                                                         XYZ temppos;
4812                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
4813                                                                         temppos=temppos-viewer;
4814                                                                         Normalise(&temppos);
4815                                                                         temppos+=viewer;
4816
4817                                                                         gLoc[0]=temppos.x;
4818                                                                         gLoc[1]=temppos.y;
4819                                                                         gLoc[2]=temppos.z;
4820                                                                         vel[0]=0;
4821                                                                         vel[1]=0;
4822                                                                         vel[2]=0;
4823                                                                         int whichsoundplay;
4824                                                                         whichsoundplay=rabbitchitter;
4825                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
4826                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
4827                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
4828                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
4829                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
4830                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
4831                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
4832                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
4833                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
4834                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
4835                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
4836                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
4837                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
4838                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
4839                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
4840                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
4841                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
4842                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
4843                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
4844                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
4845                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
4846                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
4847                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
4848                                                                         //}
4849                                                                 }
4850                                                         }
4851
4852
4853
4854
4855                                                         if(Compare(consoletext[0],"dhs ",0,3)){
4856                                                                 numhotspots--;
4857                                                                 if(numhotspots<0)numhotspots=0;
4858                                                                 donesomething=1;
4859                                                         }
4860
4861
4862                                                         if(Compare(consoletext[0],"proportion ",0,10)||Compare(consoletext[0],"Proportion ",0,4)){
4863                                                                 int startpoint;
4864                                                                 int alldone;
4865
4866                                                                 alldone=0;
4867                                                                 startpoint=11;
4868                                                                 j=startpoint;
4869                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
4870                                                                         mapname[j-startpoint]=consoletext[0][j];
4871                                                                         j++;
4872                                                                         if(consoletext[0][j]=='\0')alldone=1;
4873                                                                 }
4874                                                                 mapname[j-startpoint]='\0';
4875
4876                                                                 headprop=atof(mapname);
4877
4878                                                                 j++;
4879                                                                 startpoint=j;
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                                                                 bodyprop=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                                                                 armprop=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                                                                 legprop=atof(mapname);
4910
4911                                                                 if(player[0].creature==wolftype){
4912                                                                         player[0].proportionhead=1.1*headprop;
4913                                                                         player[0].proportionbody=1.1*bodyprop;
4914                                                                         player[0].proportionarms=1.1*armprop;
4915                                                                         player[0].proportionlegs=1.1*legprop;
4916                                                                 }
4917
4918                                                                 if(player[0].creature==rabbittype){
4919                                                                         player[0].proportionhead=1.2*headprop;
4920                                                                         player[0].proportionbody=1.05*bodyprop;
4921                                                                         player[0].proportionarms=1.00*armprop;
4922                                                                         player[0].proportionlegs=1.1*legprop;
4923                                                                         player[0].proportionlegs.y=1.05*legprop;
4924                                                                 }
4925
4926                                                                 donesomething=1;
4927                                                         }
4928
4929                                                         if(Compare(consoletext[0],"allimmobile ",0,11)||Compare(consoletext[0],"Allimmobile ",0,11)){
4930                                                                 for(i=0;i<numplayers;i++){
4931                                                                         if(i>0)player[i].immobile=1;
4932                                                                 }
4933                                                                 donesomething=1;
4934                                                         }
4935
4936
4937                                                         if(Compare(consoletext[0],"default ",0,7)||Compare(consoletext[0],"Default ",0,7)){
4938                                                                 player[0].armorhead=1;
4939                                                                 player[0].armorhigh=1;
4940                                                                 player[0].armorlow=1;
4941                                                                 player[0].protectionhead=1;
4942                                                                 player[0].protectionhigh=1;
4943                                                                 player[0].protectionlow=1;
4944                                                                 player[0].metalhead=1;
4945                                                                 player[0].metalhigh=1;
4946                                                                 player[0].metallow=1;
4947                                                                 player[0].power=1;
4948                                                                 player[0].speedmult=1;
4949                                                                 player[0].scale=1;
4950
4951                                                                 if(player[0].creature==wolftype){
4952                                                                         player[0].proportionhead=1.1;
4953                                                                         player[0].proportionbody=1.1;
4954                                                                         player[0].proportionarms=1.1;
4955                                                                         player[0].proportionlegs=1.1;
4956                                                                 }
4957
4958                                                                 if(player[0].creature==rabbittype){
4959                                                                         player[0].proportionhead=1.2;
4960                                                                         player[0].proportionbody=1.05;
4961                                                                         player[0].proportionarms=1.00;
4962                                                                         player[0].proportionlegs=1.1;
4963                                                                         player[0].proportionlegs.y=1.05;
4964                                                                 }
4965
4966                                                                 player[0].numclothes=0;
4967                                                                 if(player[0].whichskin==0){
4968                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4969                                                                 }
4970                                                                 else if(player[0].whichskin==1){
4971                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4972                                                                 }
4973                                                                 else if(player[0].whichskin==2){
4974                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4975                                                                 }
4976                                                                 else if(player[0].whichskin==3){
4977                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4978                                                                 }
4979                                                                 else if(player[0].whichskin==4){
4980                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4981                                                                 }
4982                                                                 else if(player[0].whichskin==5){
4983                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4984                                                                 }
4985                                                                 else if(player[0].whichskin==6){
4986                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4987                                                                 }
4988                                                                 else if(player[0].whichskin==7){
4989                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4990                                                                 }
4991                                                                 else if(player[0].whichskin==8){
4992                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4993                                                                 }
4994                                                                 else if(player[0].whichskin==9){
4995                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
4996                                                                 }
4997
4998                                                                 editoractive=typeactive;
4999                                                                 player[0].immobile=0;
5000
5001
5002
5003                                                                 donesomething=1;
5004                                                         }
5005
5006                                                         if(Compare(consoletext[0],"tint ",0,4)||Compare(consoletext[0],"Tint ",0,4)){
5007                                                                 int startpoint;
5008                                                                 int alldone;
5009                                                                 alldone=0;
5010                                                                 startpoint=5;
5011                                                                 j=startpoint;
5012                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5013                                                                         mapname[j-startpoint]=consoletext[0][j];
5014                                                                         j++;
5015                                                                         if(consoletext[0][j]=='\0')alldone=1;
5016                                                                 }
5017                                                                 mapname[j-startpoint]='\0';
5018
5019                                                                 tintr=atof(mapname);
5020
5021                                                                 j++;
5022                                                                 startpoint=j;
5023                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5024                                                                         mapname[j-startpoint]=consoletext[0][j];
5025                                                                         j++;
5026                                                                         if(consoletext[0][j]=='\0')alldone=1;
5027                                                                 }
5028                                                                 mapname[j-startpoint]='\0';
5029
5030                                                                 tintg=atof(mapname);
5031
5032                                                                 j++;
5033                                                                 startpoint=j;
5034                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5035                                                                         mapname[j-startpoint]=consoletext[0][j];
5036                                                                         j++;
5037                                                                         if(consoletext[0][j]=='\0')alldone=1;
5038                                                                 }
5039                                                                 mapname[j-startpoint]='\0';
5040
5041                                                                 tintb=atof(mapname);
5042
5043                                                                 donesomething=1;
5044                                                         }
5045
5046                                                         if(Compare(consoletext[0],"sky tint ",0,8)||Compare(consoletext[0],"Sky Tint ",0,8)){
5047                                                                 int startpoint;
5048                                                                 int alldone;
5049                                                                 alldone=0;
5050                                                                 startpoint=9;
5051                                                                 j=startpoint;
5052                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5053                                                                         mapname[j-startpoint]=consoletext[0][j];
5054                                                                         j++;
5055                                                                         if(consoletext[0][j]=='\0')alldone=1;
5056                                                                 }
5057                                                                 mapname[j-startpoint]='\0';
5058
5059                                                                 skyboxr=atof(mapname);
5060
5061                                                                 j++;
5062                                                                 startpoint=j;
5063                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5064                                                                         mapname[j-startpoint]=consoletext[0][j];
5065                                                                         j++;
5066                                                                         if(consoletext[0][j]=='\0')alldone=1;
5067                                                                 }
5068                                                                 mapname[j-startpoint]='\0';
5069
5070                                                                 skyboxg=atof(mapname);
5071
5072                                                                 j++;
5073                                                                 startpoint=j;
5074                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5075                                                                         mapname[j-startpoint]=consoletext[0][j];
5076                                                                         j++;
5077                                                                         if(consoletext[0][j]=='\0')alldone=1;
5078                                                                 }
5079                                                                 mapname[j-startpoint]='\0';
5080
5081                                                                 skyboxb=atof(mapname);
5082
5083                                                                 skyboxlightr=skyboxr;
5084                                                                 skyboxlightg=skyboxg;
5085                                                                 skyboxlightb=skyboxb;
5086
5087                                                                 SetUpLighting();
5088
5089                                                                 //if(skyboxtexture){
5090                                                                 terrain.DoShadows();
5091                                                                 objects.DoShadows();
5092                                                                 /*}
5093                                                                 else terrain.DoLighting();
5094                                                                 */
5095                                                                 donesomething=1;
5096                                                         }
5097
5098                                                         if(Compare(consoletext[0],"sky light ",0,9)||Compare(consoletext[0],"Sky Light ",0,9)){
5099                                                                 int startpoint;
5100                                                                 int alldone;
5101                                                                 alldone=0;
5102                                                                 startpoint=10;
5103                                                                 j=startpoint;
5104                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5105                                                                         mapname[j-startpoint]=consoletext[0][j];
5106                                                                         j++;
5107                                                                         if(consoletext[0][j]=='\0')alldone=1;
5108                                                                 }
5109                                                                 mapname[j-startpoint]='\0';
5110
5111                                                                 skyboxlightr=atof(mapname);
5112
5113                                                                 j++;
5114                                                                 startpoint=j;
5115                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5116                                                                         mapname[j-startpoint]=consoletext[0][j];
5117                                                                         j++;
5118                                                                         if(consoletext[0][j]=='\0')alldone=1;
5119                                                                 }
5120                                                                 mapname[j-startpoint]='\0';
5121
5122                                                                 skyboxlightg=atof(mapname);
5123
5124                                                                 j++;
5125                                                                 startpoint=j;
5126                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5127                                                                         mapname[j-startpoint]=consoletext[0][j];
5128                                                                         j++;
5129                                                                         if(consoletext[0][j]=='\0')alldone=1;
5130                                                                 }
5131                                                                 mapname[j-startpoint]='\0';
5132
5133                                                                 skyboxlightb=atof(mapname);
5134
5135                                                                 SetUpLighting();
5136
5137                                                                 //if(skyboxtexture){
5138                                                                 terrain.DoShadows();
5139                                                                 objects.DoShadows();
5140                                                                 /*}
5141                                                                 else terrain.DoLighting();
5142                                                                 */
5143                                                                 donesomething=1;
5144                                                         }
5145
5146                                                         if(Compare(consoletext[0],"skybox ",0,6)||Compare(consoletext[0],"Skybox ",0,6)){
5147                                                                 skyboxtexture=1-skyboxtexture;
5148
5149                                                                 SetUpLighting();
5150                                                                 //if(skyboxtexture){
5151                                                                 terrain.DoShadows();
5152                                                                 objects.DoShadows();
5153                                                                 /*}
5154                                                                 else terrain.DoLighting();
5155                                                                 */
5156                                                                 donesomething=1;
5157                                                         }
5158
5159                                                         if(Compare(consoletext[0],"protection ",0,10)||Compare(consoletext[0],"Protection ",0,10)){
5160                                                                 int startpoint;
5161                                                                 int alldone;
5162                                                                 alldone=0;
5163                                                                 startpoint=11;
5164                                                                 j=startpoint;
5165                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5166                                                                         mapname[j-startpoint]=consoletext[0][j];
5167                                                                         j++;
5168                                                                         if(consoletext[0][j]=='\0')alldone=1;
5169                                                                 }
5170                                                                 mapname[j-startpoint]='\0';
5171
5172                                                                 player[0].protectionhead=atof(mapname);
5173
5174                                                                 j++;
5175                                                                 startpoint=j;
5176                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5177                                                                         mapname[j-startpoint]=consoletext[0][j];
5178                                                                         j++;
5179                                                                         if(consoletext[0][j]=='\0')alldone=1;
5180                                                                 }
5181                                                                 mapname[j-startpoint]='\0';
5182
5183                                                                 player[0].protectionhigh=atof(mapname);
5184
5185                                                                 j++;
5186                                                                 startpoint=j;
5187                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5188                                                                         mapname[j-startpoint]=consoletext[0][j];
5189                                                                         j++;
5190                                                                         if(consoletext[0][j]=='\0')alldone=1;
5191                                                                 }
5192                                                                 mapname[j-startpoint]='\0';
5193
5194                                                                 player[0].protectionlow=atof(mapname);
5195
5196                                                                 donesomething=1;
5197                                                         }
5198
5199                                                         if(Compare(consoletext[0],"armor ",0,5)||Compare(consoletext[0],"Armor ",0,5)){
5200                                                                 int startpoint;
5201                                                                 int alldone;
5202                                                                 alldone=0;
5203                                                                 startpoint=6;
5204                                                                 j=startpoint;
5205                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5206                                                                         mapname[j-startpoint]=consoletext[0][j];
5207                                                                         j++;
5208                                                                         if(consoletext[0][j]=='\0')alldone=1;
5209                                                                 }
5210                                                                 mapname[j-startpoint]='\0';
5211
5212                                                                 player[0].armorhead=atof(mapname);
5213
5214                                                                 j++;
5215                                                                 startpoint=j;
5216                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5217                                                                         mapname[j-startpoint]=consoletext[0][j];
5218                                                                         j++;
5219                                                                         if(consoletext[0][j]=='\0')alldone=1;
5220                                                                 }
5221                                                                 mapname[j-startpoint]='\0';
5222
5223                                                                 player[0].armorhigh=atof(mapname);
5224
5225                                                                 j++;
5226                                                                 startpoint=j;
5227                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5228                                                                         mapname[j-startpoint]=consoletext[0][j];
5229                                                                         j++;
5230                                                                         if(consoletext[0][j]=='\0')alldone=1;
5231                                                                 }
5232                                                                 mapname[j-startpoint]='\0';
5233
5234                                                                 player[0].armorlow=atof(mapname);
5235
5236                                                                 donesomething=1;
5237                                                         }
5238
5239                                                         if(Compare(consoletext[0],"protectionreset ",0,15)||Compare(consoletext[0],"Protectionreset ",0,15)){
5240                                                                 for(i=0;i<numplayers;i++){
5241                                                                         player[i].protectionhead=1.0;
5242                                                                         player[i].protectionhigh=1.0;
5243                                                                         player[i].protectionlow=1.0;
5244                                                                         player[i].armorhead=1.0;
5245                                                                         player[i].armorhigh=1.0;
5246                                                                         player[i].armorlow=1.0;
5247                                                                 }
5248
5249                                                                 donesomething=1;
5250                                                         }
5251
5252                                                         if(Compare(consoletext[0],"protectionnear ",0,14)||Compare(consoletext[0],"Protectionnear ",0,14)){
5253                                                                 int closest=-1;
5254                                                                 float closestdist=-1;
5255                                                                 float distance;
5256                                                                 if(numplayers>1)
5257                                                                         for(i=1;i<numplayers;i++){
5258                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5259                                                                                 if(closestdist==-1||distance<closestdist){
5260                                                                                         closestdist=distance;
5261                                                                                         closest=i;
5262                                                                                 }
5263                                                                         }
5264
5265                                                                         int startpoint;
5266                                                                         int alldone;
5267                                                                         alldone=0;
5268                                                                         startpoint=15;
5269                                                                         j=startpoint;
5270                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5271                                                                                 mapname[j-startpoint]=consoletext[0][j];
5272                                                                                 j++;
5273                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5274                                                                         }
5275                                                                         mapname[j-startpoint]='\0';
5276
5277                                                                         player[closest].protectionhead=atof(mapname);
5278
5279                                                                         j++;
5280                                                                         startpoint=j;
5281                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5282                                                                                 mapname[j-startpoint]=consoletext[0][j];
5283                                                                                 j++;
5284                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5285                                                                         }
5286                                                                         mapname[j-startpoint]='\0';
5287
5288                                                                         player[closest].protectionhigh=atof(mapname);
5289
5290                                                                         j++;
5291                                                                         startpoint=j;
5292                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5293                                                                                 mapname[j-startpoint]=consoletext[0][j];
5294                                                                                 j++;
5295                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5296                                                                         }
5297                                                                         mapname[j-startpoint]='\0';
5298
5299                                                                         player[closest].protectionlow=atof(mapname);
5300
5301                                                                         donesomething=1;
5302                                                         }
5303
5304                                                         if(Compare(consoletext[0],"armornear ",0,9)||Compare(consoletext[0],"Armornear ",0,9)){
5305                                                                 int closest=-1;
5306                                                                 float closestdist=-1;
5307                                                                 float distance;
5308                                                                 if(numplayers>1)
5309                                                                         for(i=1;i<numplayers;i++){
5310                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5311                                                                                 if(closestdist==-1||distance<closestdist){
5312                                                                                         closestdist=distance;
5313                                                                                         closest=i;
5314                                                                                 }
5315                                                                         }
5316                                                                         int startpoint;
5317                                                                         int alldone;
5318                                                                         alldone=0;
5319                                                                         startpoint=10;
5320                                                                         j=startpoint;
5321                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5322                                                                                 mapname[j-startpoint]=consoletext[0][j];
5323                                                                                 j++;
5324                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5325                                                                         }
5326                                                                         mapname[j-startpoint]='\0';
5327
5328                                                                         player[closest].armorhead=atof(mapname);
5329
5330                                                                         j++;
5331                                                                         startpoint=j;
5332                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5333                                                                                 mapname[j-startpoint]=consoletext[0][j];
5334                                                                                 j++;
5335                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5336                                                                         }
5337                                                                         mapname[j-startpoint]='\0';
5338
5339                                                                         player[closest].armorhigh=atof(mapname);
5340
5341                                                                         j++;
5342                                                                         startpoint=j;
5343                                                                         while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5344                                                                                 mapname[j-startpoint]=consoletext[0][j];
5345                                                                                 j++;
5346                                                                                 if(consoletext[0][j]=='\0')alldone=1;
5347                                                                         }
5348                                                                         mapname[j-startpoint]='\0';
5349
5350                                                                         player[closest].armorlow=atof(mapname);
5351
5352                                                                         donesomething=1;
5353                                                         }
5354
5355
5356                                                         if(Compare(consoletext[0],"metal ",0,5)||Compare(consoletext[0],"Metal ",0,5)){
5357                                                                 int startpoint;
5358                                                                 int alldone;
5359                                                                 alldone=0;
5360                                                                 startpoint=6;
5361                                                                 j=startpoint;
5362                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5363                                                                         mapname[j-startpoint]=consoletext[0][j];
5364                                                                         j++;
5365                                                                         if(consoletext[0][j]=='\0')alldone=1;
5366                                                                 }
5367                                                                 mapname[j-startpoint]='\0';
5368
5369                                                                 player[0].metalhead=atof(mapname);
5370
5371                                                                 j++;
5372                                                                 startpoint=j;
5373                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5374                                                                         mapname[j-startpoint]=consoletext[0][j];
5375                                                                         j++;
5376                                                                         if(consoletext[0][j]=='\0')alldone=1;
5377                                                                 }
5378                                                                 mapname[j-startpoint]='\0';
5379
5380                                                                 player[0].metalhigh=atof(mapname);
5381
5382                                                                 j++;
5383                                                                 startpoint=j;
5384                                                                 while(consoletext[0][j]!='\0'&&consoletext[0][j]!=' '&&!alldone&&j<255){
5385                                                                         mapname[j-startpoint]=consoletext[0][j];
5386                                                                         j++;
5387                                                                         if(consoletext[0][j]=='\0')alldone=1;
5388                                                                 }
5389
5390                                                                 mapname[j-startpoint]='\0';
5391
5392                                                                 player[0].metallow=atof(mapname);
5393
5394                                                                 donesomething=1;
5395                                                         }
5396
5397                                                         if(Compare(consoletext[0],"noclothesnear ",0,13)||Compare(consoletext[0],"Noclothesnear ",0,13)){
5398                                                                 int closest=-1;
5399                                                                 float closestdist=-1;
5400                                                                 float distance;
5401                                                                 if(numplayers>1)
5402                                                                         for(i=1;i<numplayers;i++){
5403                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5404                                                                                 if(closestdist==-1||distance<closestdist){
5405                                                                                         closestdist=distance;
5406                                                                                         closest=i;
5407                                                                                 }
5408                                                                         }
5409                                                                         player[closest].numclothes=0;
5410                                                                         if(player[closest].whichskin==0){
5411                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5412                                                                         }
5413                                                                         else if(player[closest].whichskin==1){
5414                                                                                 LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5415                                                                         }
5416                                                                         else if(player[closest].whichskin==2){
5417                                                                                 LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5418                                                                         }
5419                                                                         else if(player[closest].whichskin==3){
5420                                                                                 LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5421                                                                         }
5422                                                                         else if(player[closest].whichskin==4){
5423                                                                                 LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5424                                                                         }
5425                                                                         else if(player[closest].whichskin==5){
5426                                                                                 LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5427                                                                         }
5428                                                                         else if(player[closest].whichskin==6){
5429                                                                                 LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5430                                                                         }
5431                                                                         else if(player[closest].whichskin==7){
5432                                                                                 LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5433                                                                         }
5434                                                                         else if(player[closest].whichskin==8){
5435                                                                                 LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5436                                                                         }
5437                                                                         else if(player[closest].whichskin==9){
5438                                                                                 LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5439                                                                         }
5440
5441                                                                         donesomething=1;
5442                                                         }
5443
5444                                                         if(Compare(consoletext[0],"noclothes ",0,9)||Compare(consoletext[0],"Noclothes ",0,9)){
5445                                                                 int closest=0;
5446
5447                                                                 player[closest].numclothes=0;
5448                                                                 if(player[closest].whichskin==0){
5449                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5450                                                                 }
5451                                                                 else if(player[closest].whichskin==1){
5452                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5453                                                                 }
5454                                                                 else if(player[closest].whichskin==2){
5455                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5456                                                                 }
5457                                                                 else if(player[closest].whichskin==3){
5458                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5459                                                                 }
5460                                                                 else if(player[closest].whichskin==4){
5461                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5462                                                                 }
5463                                                                 else if(player[closest].whichskin==5){
5464                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5465                                                                 }
5466                                                                 else if(player[closest].whichskin==6){
5467                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5468                                                                 }
5469                                                                 else if(player[closest].whichskin==7){
5470                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5471                                                                 }
5472                                                                 else if(player[closest].whichskin==8){
5473                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5474                                                                 }
5475                                                                 else if(player[closest].whichskin==9){
5476                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
5477                                                                 }
5478
5479                                                                 donesomething=1;
5480                                                         }
5481
5482                                                         if((Compare(consoletext[0],"Clothes ",0,7)||Compare(consoletext[0],"clothes ",0,7))){
5483                                                                 mapname[0]=':';
5484                                                                 mapname[1]='D';
5485                                                                 mapname[2]='a';
5486                                                                 mapname[3]='t';
5487                                                                 mapname[4]='a';
5488                                                                 mapname[5]=':';
5489                                                                 mapname[6]='T';
5490                                                                 mapname[7]='e';
5491                                                                 mapname[8]='x';
5492                                                                 mapname[9]='t';
5493                                                                 mapname[10]='u';
5494                                                                 mapname[11]='r';
5495                                                                 mapname[12]='e';
5496                                                                 mapname[13]='s';
5497                                                                 mapname[14]=':';
5498                                                                 for(j=8;j<consolechars[0];j++){
5499                                                                         mapname[j-8+15]=consoletext[0][j];
5500                                                                 }
5501                                                                 mapname[consolechars[0]-8+15]='.';
5502                                                                 mapname[consolechars[0]-8+16]='p';
5503                                                                 mapname[consolechars[0]-8+17]='n';
5504                                                                 mapname[consolechars[0]-8+18]='g';
5505                                                                 mapname[consolechars[0]-8+19]='\0';
5506
5507                                                                 //:Data:Textures:Pants.png
5508
5509                                                                 if(AddClothes((char *)mapname,0,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize)){
5510                                                                         player[0].DoMipmaps(5,0,0,player[0].skeleton.skinsize,player[0].skeleton.skinsize);
5511                                                                         strcpy(player[0].clothes[player[0].numclothes],mapname);
5512                                                                         player[0].clothestintr[player[0].numclothes]=tintr;
5513                                                                         player[0].clothestintg[player[0].numclothes]=tintg;
5514                                                                         player[0].clothestintb[player[0].numclothes]=tintb;
5515                                                                         player[0].numclothes++;
5516                                                                 }
5517
5518                                                                 donesomething=1;
5519                                                         }
5520
5521                                                         if(Compare(consoletext[0],"belt ",0,4)||Compare(consoletext[0],"belt ",0,4)){
5522                                                                 player[0].skeleton.clothes = 1-player[0].skeleton.clothes;
5523
5524                                                                 donesomething=1;
5525                                                         }
5526
5527                                                         if(Compare(consoletext[0],"Cellophane ",0,10)||Compare(consoletext[0],"cellophane ",0,10)){
5528                                                                 cellophane=1-cellophane;
5529
5530                                                                 if(cellophane){
5531                                                                         for(i=0;i<numplayers;i++){
5532                                                                                 player[i].proportionhead.z=0;
5533                                                                                 player[i].proportionbody.z=0;
5534                                                                                 player[i].proportionarms.z=0;
5535                                                                                 player[i].proportionlegs.z=0;
5536                                                                         }
5537                                                                 }
5538
5539                                                                 if(!cellophane){
5540                                                                         for(i=0;i<numplayers;i++){
5541                                                                                 player[i].proportionhead.z=player[i].proportionhead.x;
5542                                                                                 player[i].proportionbody.z=player[i].proportionbody.x;
5543                                                                                 player[i].proportionarms.z=player[i].proportionarms.x;
5544                                                                                 player[i].proportionlegs.z=player[i].proportionlegs.x;
5545                                                                         }
5546                                                                 }
5547
5548                                                                 donesomething=1;
5549                                                         }
5550
5551                                                         if((Compare(consoletext[0],"Clothesnear ",0,11)||Compare(consoletext[0],"clothesnear ",0,11))){
5552                                                                 mapname[0]=':';
5553                                                                 mapname[1]='D';
5554                                                                 mapname[2]='a';
5555                                                                 mapname[3]='t';
5556                                                                 mapname[4]='a';
5557                                                                 mapname[5]=':';
5558                                                                 mapname[6]='T';
5559                                                                 mapname[7]='e';
5560                                                                 mapname[8]='x';
5561                                                                 mapname[9]='t';
5562                                                                 mapname[10]='u';
5563                                                                 mapname[11]='r';
5564                                                                 mapname[12]='e';
5565                                                                 mapname[13]='s';
5566                                                                 mapname[14]=':';
5567                                                                 for(j=12;j<consolechars[0];j++){
5568                                                                         mapname[j-12+15]=consoletext[0][j];
5569                                                                 }
5570                                                                 mapname[consolechars[0]-12+15]='.';
5571                                                                 mapname[consolechars[0]-12+16]='p';
5572                                                                 mapname[consolechars[0]-12+17]='n';
5573                                                                 mapname[consolechars[0]-12+18]='g';
5574                                                                 mapname[consolechars[0]-12+19]='\0';
5575
5576                                                                 //:Data:Textures:Pants.png
5577                                                                 int closest=-1;
5578                                                                 float closestdist=-1;
5579                                                                 float distance;
5580                                                                 if(numplayers>1)
5581                                                                         for(i=1;i<numplayers;i++){
5582                                                                                 distance=findDistancefast(&player[i].coords,&player[0].coords);
5583                                                                                 if(closestdist==-1||distance<closestdist){
5584                                                                                         closestdist=distance;
5585                                                                                         closest=i;
5586                                                                                 }
5587                                                                         }
5588
5589                                                                         if(AddClothes((char *)mapname,0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize)){
5590                                                                                 player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
5591                                                                                 strcpy(player[closest].clothes[player[closest].numclothes],mapname);
5592                                                                                 player[closest].clothestintr[player[closest].numclothes]=tintr;
5593                                                                                 player[closest].clothestintg[player[closest].numclothes]=tintg;
5594                                                                                 player[closest].clothestintb[player[closest].numclothes]=tintb;
5595                                                                                 player[closest].numclothes++;
5596                                                                         }
5597
5598                                                                         donesomething=1;
5599                                                         }
5600
5601                                                         if(Compare(consoletext[0],"funnybunny ",0,10)||Compare(consoletext[0],"funny bunny ",0,11)){
5602                                                                 player[0].skeleton.id=0;
5603                                                                 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);
5604                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5605                                                                 player[0].creature=rabbittype;
5606                                                                 player[0].scale=.2;
5607
5608                                                                 player[0].proportionhead=1.2;
5609                                                                 player[0].proportionbody=1.05;
5610                                                                 player[0].proportionarms=1.00;
5611                                                                 player[0].proportionlegs=1.1;
5612                                                                 player[0].proportionlegs.y=1.05;
5613                                                                 player[0].headless=0;
5614
5615                                                                 player[0].damagetolerance=200;
5616
5617                                                                 donesomething=1;
5618                                                         }
5619                                                         if(Compare(consoletext[0],"wolfieisgod ",0,11)||Compare(consoletext[0],"wolfie is god ",0,12)){
5620                                                                 player[0].skeleton.id=0;
5621                                                                 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);
5622                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5623                                                                 player[0].creature=wolftype;
5624
5625                                                                 player[0].proportionhead=1.1;
5626                                                                 player[0].proportionbody=1.1;
5627                                                                 player[0].proportionarms=1.1;
5628                                                                 player[0].proportionlegs=1.1;
5629                                                                 player[0].proportionlegs.y=1.1;
5630                                                                 player[0].scale=.23;
5631
5632                                                                 player[0].damagetolerance=300;
5633
5634                                                                 donesomething=1;
5635                                                         }
5636                                                         /*if(Compare(consoletext[0],"kungfu ",0,6)||Compare(consoletext[0],"kung fu ",0,7)){
5637                                                         LoadTextureSave(":Data:Textures:Kungfu.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5638                                                         donesomething=1;
5639                                                         }
5640                                                         if(Compare(consoletext[0],"rambo ",0,5)){
5641                                                         LoadTextureSave(":Data:Textures:Leather.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5642                                                         donesomething=1;
5643                                                         }
5644                                                         if(Compare(consoletext[0],"david ",0,5)){
5645                                                         LoadTextureSave(":Data:Textures:David.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5646                                                         donesomething=1;
5647                                                         }*/
5648                                                         if(Compare(consoletext[0],"wolf ",0,4)){
5649                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5650                                                                 donesomething=1;
5651                                                         }
5652                                                         if(Compare(consoletext[0],"darkwolf ",0,8)){
5653                                                                 LoadTextureSave(":Data:Textures:DarkWolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5654                                                                 donesomething=1;
5655                                                         }
5656                                                         if(Compare(consoletext[0],"snowwolf ",0,8)){
5657                                                                 LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5658                                                                 donesomething=1;
5659                                                         }/*
5660                                                          if(Compare(consoletext[0],"lizardwolf ",0,10)){
5661                                                          LoadTextureSave(":Data:Textures:Lizardwolf.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5662                                                          donesomething=1;
5663                                                          }*/
5664                                                         if(Compare(consoletext[0],"white ",0,5)){
5665                                                                 LoadTextureSave(":Data:Textures:fur.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5666                                                                 donesomething=1;
5667                                                         }
5668                                                         if(Compare(consoletext[0],"brown ",0,5)){
5669                                                                 LoadTextureSave(":Data:Textures:fur3.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5670                                                                 donesomething=1;
5671                                                         }
5672                                                         if(Compare(consoletext[0],"black ",0,5)){
5673                                                                 LoadTextureSave(":Data:Textures:fur2.jpg",&player[0].skeleton.drawmodel.textureptr,1,&player[0].skeleton.skinText[0],&player[0].skeleton.skinsize);
5674                                                                 donesomething=1;
5675                                                         }
5676                                                         if(consolechars[0]>0){
5677                                                                 for(k=14;k>=1;k--){
5678                                                                         for(j=0;j<255;j++){
5679                                                                                 consoletext[k][j]=consoletext[k-1][j];
5680                                                                         }
5681                                                                         consolechars[k]=consolechars[k-1];
5682                                                                 }
5683                                                                 for(j=0;j<255;j++){
5684                                                                         consoletext[0][j]=' ';
5685                                                                 }
5686                                                                 consolechars[0]=0;
5687                                                                 consoleselected=0;
5688
5689                                                                 if(!donesomething){
5690                                                                         PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
5691                                                                         OPENAL_SetVolume(channels[consolefailsound], 256);
5692                                                                         OPENAL_SetPaused(channels[consolefailsound], false);
5693                                                                 }
5694                                                         }
5695                                                 }
5696                                         }
5697                                         togglekey[i]=1;
5698                                 }
5699                                 else {
5700                                         togglekey[i]=0;
5701                                         togglekeydelay[i]=0;
5702                                 }
5703                         }
5704
5705                         consoleblinkdelay-=multiplier;
5706                         if(consoleblinkdelay<=0){
5707                                 consoleblinkdelay=.3;
5708                                 consoleblink=1-consoleblink;
5709                         }
5710                 }
5711
5712                 if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
5713                         tryquit=1;
5714                         if(mainmenu==3){
5715                                 if(newdetail>2)newdetail=detail;
5716                                 if(newdetail<0)newdetail=detail;
5717 #if !USE_SDL  // we'll take anything that works.
5718                                 if(newscreenwidth>3000)newscreenwidth=screenwidth;
5719                                 if(newscreenheight>3000)newscreenheight=screenheight;
5720 #endif
5721                                 if(newscreenwidth<0)newscreenwidth=screenwidth;
5722                                 if(newscreenheight<0)newscreenheight=screenheight;
5723
5724                                 ofstream opstream(ConvertFileName(":Data:config.txt", "w"));
5725                                 opstream << "Screenwidth:\n";
5726                                 opstream << newscreenwidth;
5727                                 opstream << "\nScreenheight:\n";
5728                                 opstream << newscreenheight;
5729                                 opstream << "\nMouse sensitivity:\n";
5730                                 opstream << usermousesensitivity;
5731                                 opstream << "\nBlur(0,1):\n";
5732                                 opstream << ismotionblur;
5733                                 opstream << "\nOverall Detail(0,1,2) higher=better:\n";
5734                                 opstream << newdetail;
5735                                 opstream << "\nFloating jump:\n";
5736                                 opstream << floatjump;
5737                                 opstream << "\nMouse jump:\n";
5738                                 opstream << mousejump;
5739                                 opstream << "\nAmbient sound:\n";
5740                                 opstream << ambientsound;
5741                                 opstream << "\nBlood (0,1,2):\n";
5742                                 opstream << bloodtoggle;
5743                                 opstream << "\nAuto slomo:\n";
5744                                 opstream << autoslomo;
5745                                 opstream << "\nFoliage:\n";
5746                                 opstream << foliage;
5747                                 opstream << "\nMusic:\n";
5748                                 opstream << musictoggle;
5749                                 opstream << "\nTrilinear:\n";
5750                                 opstream << trilinear;
5751                                 opstream << "\nDecals(shadows,blood puddles,etc):\n";
5752                                 opstream << decals;
5753                                 opstream << "\nInvert mouse:\n";
5754                                 opstream << invertmouse;
5755                                 opstream << "\nGamespeed:\n";
5756                                 if(oldgamespeed==0)oldgamespeed=1;
5757                                 opstream << oldgamespeed;
5758                                 opstream << "\nDifficulty(0,1,2) higher=harder:\n";
5759                                 opstream << difficulty;
5760                                 opstream << "\nDamage effects(blackout, doublevision):\n";
5761                                 opstream << damageeffects;
5762                                 opstream << "\nText:\n";
5763                                 opstream << texttoggle;
5764                                 opstream << "\nDebug:\n";
5765                                 opstream << debugmode;
5766                                 opstream << "\nVBL Sync:\n";
5767                                 opstream << vblsync;
5768                                 opstream << "\nShow Points:\n";
5769                                 opstream << showpoints;
5770                                 opstream << "\nAlways Blur:\n";
5771                                 opstream << alwaysblur;
5772                                 opstream << "\nImmediate mode (turn on on G5):\n";
5773                                 opstream << immediate;
5774                                 opstream << "\nVelocity blur:\n";
5775                                 opstream << velocityblur;
5776                             opstream << "\nVolume:\n";
5777                         opstream << volume;
5778                                 opstream << "\nForward key:\n";
5779                                 opstream << KeyToChar(forwardkey);
5780                                 opstream << "\nBack key:\n";
5781                                 opstream << KeyToChar(backkey);
5782                                 opstream << "\nLeft key:\n";
5783                                 opstream << KeyToChar(leftkey);
5784                                 opstream << "\nRight key:\n";
5785                                 opstream << KeyToChar(rightkey);
5786                                 opstream << "\nJump key:\n";
5787                                 opstream << KeyToChar(jumpkey);
5788                                 opstream << "\nCrouch key:\n";
5789                                 opstream << KeyToChar(crouchkey);
5790                                 opstream << "\nDraw key:\n";
5791                                 opstream << KeyToChar(drawkey);
5792                                 opstream << "\nThrow key:\n";
5793                                 opstream << KeyToChar(throwkey);
5794                                 opstream << "\nAttack key:\n";
5795                                 opstream << KeyToChar(attackkey);
5796                                 opstream << "\nChat key:\n";
5797                                 opstream << KeyToChar(chatkey);
5798                                 opstream.close();
5799                         }
5800                 }
5801
5802                 static int oldwinfreeze;
5803                 if(winfreeze&&!oldwinfreeze){
5804                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
5805                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
5806                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
5807                         OPENAL_SetPaused(channels[consolesuccesssound], false);
5808                 }
5809                 if(winfreeze==0)oldwinfreeze=winfreeze;
5810                 else oldwinfreeze++;
5811
5812                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
5813                         if(winfreeze)winfreeze=0;
5814                         oldjumpkeydown=1;
5815                 }
5816                 if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
5817                         if(winfreeze){
5818                                 mainmenu=9;
5819                                 gameon=0;
5820                         }
5821                 }
5822                 if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
5823                         oldjumpkeydown=1;
5824                 }
5825                 if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
5826
5827                 if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
5828
5829                         static bool oldbuttondialogue;
5830
5831                         if(indialogue!=-1)talkdelay=1;
5832                         talkdelay-=multiplier;
5833
5834                         if(talkdelay<=0)
5835                                 if(indialogue==-1&&(animation[player[0].targetanimation].height!=highheight)/*&&!hostile*/)
5836                                         for(i=0;i<numdialogues;i++){
5837                                                 int realdialoguetype;
5838                                                 bool special;
5839                                                 if(dialoguetype[i]>49){
5840                                                         realdialoguetype=dialoguetype[i]-50;
5841                                                         special=1;
5842                                                 }
5843                                                 else if(dialoguetype[i]>39){
5844                                                         realdialoguetype=dialoguetype[i]-40;
5845                                                         special=1;
5846                                                 }
5847                                                 else if(dialoguetype[i]>29){
5848                                                         realdialoguetype=dialoguetype[i]-30;
5849                                                         special=1;
5850                                                 }
5851                                                 else if(dialoguetype[i]>19){
5852                                                         realdialoguetype=dialoguetype[i]-20;
5853                                                         special=1;
5854                                                 }
5855                                                 else if(dialoguetype[i]>9){
5856                                                         realdialoguetype=dialoguetype[i]-10;
5857                                                         special=1;
5858                                                 }
5859                                                 else {
5860                                                         realdialoguetype=dialoguetype[i];
5861                                                         special=0;
5862                                                 }
5863                                                 if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
5864                                                         if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
5865                                                                 whichdialogue=i;
5866                                                                 for(j=0;j<numdialogueboxes[whichdialogue];j++){
5867                                                                         player[participantfocus[whichdialogue][j]].coords=participantlocation[whichdialogue][participantfocus[whichdialogue][j]];
5868                                                                         player[participantfocus[whichdialogue][j]].rotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5869                                                                         player[participantfocus[whichdialogue][j]].targetrotation=participantrotation[whichdialogue][participantfocus[whichdialogue][j]];
5870                                                                         player[participantfocus[whichdialogue][j]].velocity=0;
5871                                                                         player[participantfocus[whichdialogue][j]].targetanimation=player[participantfocus[whichdialogue][j]].getIdle();
5872                                                                         player[participantfocus[whichdialogue][j]].targetframe=0;
5873                                                                 }
5874                                                                 directing=0;
5875                                                                 indialogue=0;
5876                                                                 dialoguetime=0;
5877                                                                 dialoguegonethrough[i]++;
5878                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
5879                                                                         static float gLoc[3];
5880                                                                         static float vel[3];
5881                                                                         XYZ temppos;
5882                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
5883                                                                         temppos=temppos-viewer;
5884                                                                         Normalise(&temppos);
5885                                                                         temppos+=viewer;
5886
5887                                                                         gLoc[0]=temppos.x;
5888                                                                         gLoc[1]=temppos.y;
5889                                                                         gLoc[2]=temppos.z;vel[0]=0;
5890                                                                         vel[1]=0;
5891                                                                         vel[2]=0;
5892                                                                         int whichsoundplay;
5893                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
5894                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
5895                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
5896                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
5897                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
5898                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
5899                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
5900                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
5901                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
5902                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
5903                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
5904                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
5905                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
5906                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
5907                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
5908                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
5909                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
5910                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
5911                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
5912                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
5913                                                                         PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
5914                                                                         OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
5915                                                                         OPENAL_SetVolume(channels[whichsoundplay], 256);
5916                                                                         OPENAL_SetPaused(channels[whichsoundplay], false);
5917                                                                 }
5918                                                                 if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
5919                                                         }
5920                                                 }
5921                                         }
5922
5923                                         windvar+=multiplier;
5924                                         smoketex+=multiplier;
5925                                         tutorialstagetime+=multiplier;
5926
5927                                         static float hotspotvisual[40];
5928                                         if(numhotspots){
5929                                                 XYZ hotspotsprite;
5930                                                 if(editorenabled)
5931                                                         for(i=0;i<numhotspots;i++)
5932                                                                 hotspotvisual[i]-=multiplier/320;
5933
5934                                                 for(i=0;i<numhotspots;i++){
5935                                                         //if(hotspottype[i]<=10)
5936                                                         while(hotspotvisual[i]<0){
5937                                                                 hotspotsprite=0;
5938                                                                 hotspotsprite.x=float(abs(Random()%100000))/100000*hotspotsize[i];
5939                                                                 hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
5940                                                                 hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
5941                                                                 hotspotsprite+=hotspot[i];
5942                                                                 sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
5943                                                                 hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
5944                                                         }
5945                                                 }
5946
5947                                                 for(i=0;i<numhotspots;i++){
5948                                                         if(hotspottype[i]<=10&&hotspottype[i]>0){
5949                                                                 hotspot[i]=player[hotspottype[i]].coords;
5950                                                         }
5951                                                 }
5952                                         }
5953
5954                                         //Tutorial
5955                                         if(tutoriallevel&&tutorialstagetime>tutorialmaxtime){
5956                                                 tutorialstage++;
5957                                                 tutorialsuccess=0;
5958                                                 if(tutorialstage<=1){
5959                                                         canattack=0;
5960                                                         cananger=0;
5961                                                         reversaltrain=0;
5962                                                 }
5963                                                 if(tutorialstage==1){
5964                                                         tutorialmaxtime=5;
5965                                                 }
5966                                                 if(tutorialstage==2){
5967                                                         tutorialmaxtime=2;
5968                                                 }
5969                                                 if(tutorialstage==3){
5970                                                         tutorialmaxtime=600;
5971                                                 }
5972                                                 if(tutorialstage==4){
5973                                                         tutorialmaxtime=1000;
5974                                                 }
5975                                                 if(tutorialstage==5){
5976                                                         tutorialmaxtime=600;
5977                                                 }
5978                                                 if(tutorialstage==6){
5979                                                         tutorialmaxtime=600;
5980                                                 }
5981                                                 if(tutorialstage==7){
5982                                                         tutorialmaxtime=600;
5983                                                 }
5984                                                 if(tutorialstage==8){
5985                                                         tutorialmaxtime=600;
5986                                                 }
5987                                                 if(tutorialstage==9){
5988                                                         tutorialmaxtime=600;
5989                                                 }
5990                                                 if(tutorialstage==10){
5991                                                         tutorialmaxtime=2;
5992                                                 }
5993                                                 if(tutorialstage==11){
5994                                                         tutorialmaxtime=1000;
5995                                                 }
5996                                                 if(tutorialstage==12){
5997                                                         tutorialmaxtime=1000;
5998                                                 }
5999                                                 if(tutorialstage==13){
6000                                                         tutorialmaxtime=2;
6001                                                 }
6002                                                 if(tutorialstage==14){
6003                                                         tutorialmaxtime=3;
6004
6005                                                         XYZ temp,temp2;
6006
6007                                                         temp.x=1011;
6008                                                         temp.y=84;
6009                                                         temp.z=491;
6010                                                         temp2.x=1025;
6011                                                         temp2.y=75;
6012                                                         temp2.z=447;
6013
6014                                                         player[1].coords=(temp+temp2)/2;
6015
6016                                                         float gLoc[3];
6017                                                         float vel[3];
6018                                                         gLoc[0]=player[1].coords.x;
6019                                                         gLoc[1]=player[1].coords.y;
6020                                                         gLoc[2]=player[1].coords.z;
6021                                                         vel[0]=0;
6022                                                         vel[1]=0;
6023                                                         vel[2]=0;
6024                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6025                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6026                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6027                                                         OPENAL_SetPaused(channels[fireendsound], false);
6028
6029                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6030                                                                 if(Random()%2==0){
6031                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6032                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6033                                                                         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;
6034                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6035                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6036                                                                 }
6037                                                         }
6038
6039                                                 }
6040                                                 if(tutorialstage==15){
6041                                                         tutorialmaxtime=500;
6042                                                 }
6043                                                 if(tutorialstage==16){
6044                                                         tutorialmaxtime=500;
6045                                                 }
6046                                                 if(tutorialstage==17){
6047                                                         tutorialmaxtime=500;
6048                                                 }
6049                                                 if(tutorialstage==18){
6050                                                         tutorialmaxtime=500;
6051                                                 }
6052                                                 if(tutorialstage==19){
6053                                                         tutorialstage=20;
6054                                                         //tutorialmaxtime=500;
6055                                                 }
6056                                                 if(tutorialstage==20){
6057                                                         tutorialmaxtime=500;
6058                                                 }
6059                                                 if(tutorialstage==21){
6060                                                         tutorialmaxtime=500;
6061                                                         if(bonus==cannon){
6062                                                                 bonus=Slicebonus;
6063                                                                 againbonus=1;
6064                                                         }
6065                                                         else againbonus=0;
6066                                                 }
6067                                                 if(tutorialstage==22){
6068                                                         tutorialmaxtime=500;
6069                                                 }
6070                                                 if(tutorialstage==23){
6071                                                         tutorialmaxtime=500;
6072                                                 }
6073                                                 if(tutorialstage==24){
6074                                                         tutorialmaxtime=500;
6075                                                 }
6076                                                 if(tutorialstage==25){
6077                                                         tutorialmaxtime=500;
6078                                                 }
6079                                                 if(tutorialstage==26){
6080                                                         tutorialmaxtime=2;
6081                                                 }
6082                                                 if(tutorialstage==27){
6083                                                         tutorialmaxtime=4;
6084                                                         reversaltrain=1;
6085                                                         cananger=1;
6086                                                         player[1].aitype=attacktypecutoff;
6087                                                 }
6088                                                 if(tutorialstage==28){
6089                                                         tutorialmaxtime=400;
6090                                                 }
6091                                                 if(tutorialstage==29){
6092                                                         tutorialmaxtime=400;
6093                                                         player[0].escapednum=0;
6094                                                 }
6095                                                 if(tutorialstage==30){
6096                                                         tutorialmaxtime=4;
6097                                                         reversaltrain=0;
6098                                                         cananger=0;
6099                                                         player[1].aitype=passivetype;
6100                                                 }
6101                                                 if(tutorialstage==31){
6102                                                         tutorialmaxtime=13;
6103                                                 }
6104                                                 if(tutorialstage==32){
6105                                                         tutorialmaxtime=8;
6106                                                 }
6107                                                 if(tutorialstage==33){
6108                                                         tutorialmaxtime=400;
6109                                                         cananger=1;
6110                                                         canattack=1;
6111                                                         player[1].aitype=attacktypecutoff;
6112                                                 }
6113                                                 if(tutorialstage==34){
6114                                                         tutorialmaxtime=400;
6115                                                 }
6116                                                 if(tutorialstage==35){
6117                                                         tutorialmaxtime=400;
6118                                                 }
6119                                                 if(tutorialstage==36){
6120                                                         tutorialmaxtime=2;
6121                                                         reversaltrain=0;
6122                                                         cananger=0;
6123                                                         player[1].aitype=passivetype;
6124                                                 }
6125                                                 if(tutorialstage==37){
6126                                                         damagedealt=0;
6127                                                         damagetaken=0;
6128                                                         tutorialmaxtime=50;
6129                                                         cananger=1;
6130                                                         canattack=1;
6131                                                         player[1].aitype=attacktypecutoff;
6132                                                 }
6133                                                 if(tutorialstage==38){
6134                                                         tutorialmaxtime=4;
6135                                                         canattack=0;
6136                                                         cananger=0;
6137                                                         player[1].aitype=passivetype;
6138                                                 }
6139                                                 if(tutorialstage==39){
6140                                                         XYZ temp,temp2;
6141
6142                                                         temp.x=1011;
6143                                                         temp.y=84;
6144                                                         temp.z=491;
6145                                                         temp2.x=1025;
6146                                                         temp2.y=75;
6147                                                         temp2.z=447;
6148
6149
6150                                                         weapons.owner[weapons.numweapons]=-1;
6151                                                         weapons.type[weapons.numweapons]=knife;
6152                                                         weapons.damage[weapons.numweapons]=0;
6153                                                         weapons.mass[weapons.numweapons]=1;
6154                                                         weapons.tipmass[weapons.numweapons]=1.2;
6155                                                         weapons.length[weapons.numweapons]=.25;
6156                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6157                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6158
6159                                                         weapons.velocity[weapons.numweapons]=0.1;
6160                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6161                                                         weapons.missed[weapons.numweapons]=1;
6162                                                         weapons.hitsomething[weapons.numweapons]=0;
6163                                                         weapons.freetime[weapons.numweapons]=0;
6164                                                         weapons.firstfree[weapons.numweapons]=1;
6165                                                         weapons.physics[weapons.numweapons]=1;
6166
6167                                                         weapons.numweapons++;
6168                                                 }
6169                                                 if(tutorialstage==40){
6170                                                         tutorialmaxtime=300;
6171                                                 }
6172                                                 if(tutorialstage==41){
6173                                                         tutorialmaxtime=300;
6174                                                 }
6175                                                 if(tutorialstage==42){
6176                                                         tutorialmaxtime=8;
6177                                                 }
6178                                                 if(tutorialstage==43){
6179                                                         tutorialmaxtime=300;
6180                                                 }
6181                                                 if(tutorialstage==44){
6182                                                         weapons.owner[0]=1;
6183                                                         player[0].weaponactive=-1;
6184                                                         player[0].num_weapons=0;
6185                                                         player[1].weaponactive=0;
6186                                                         player[1].num_weapons=1;
6187                                                         player[1].weaponids[0]=0;
6188
6189                                                         cananger=1;
6190                                                         canattack=1;
6191                                                         player[1].aitype=attacktypecutoff;
6192
6193                                                         tutorialmaxtime=300;
6194                                                 }
6195                                                 if(tutorialstage==45){
6196                                                         weapons.owner[0]=1;
6197                                                         player[0].weaponactive=-1;
6198                                                         player[0].num_weapons=0;
6199                                                         player[1].weaponactive=0;
6200                                                         player[1].num_weapons=1;
6201                                                         player[1].weaponids[0]=0;
6202
6203                                                         tutorialmaxtime=300;
6204                                                 }
6205                                                 if(tutorialstage==46){
6206                                                         weapons.owner[0]=1;
6207                                                         player[0].weaponactive=-1;
6208                                                         player[0].num_weapons=0;
6209                                                         player[1].weaponactive=0;
6210                                                         player[1].num_weapons=1;
6211                                                         player[1].weaponids[0]=0;
6212
6213                                                         weapons.type[0]=sword;
6214
6215                                                         tutorialmaxtime=300;
6216                                                 }
6217
6218                                                 if(tutorialstage==47){
6219                                                         tutorialmaxtime=10;
6220
6221                                                         XYZ temp,temp2;
6222
6223                                                         temp.x=1011;
6224                                                         temp.y=84;
6225                                                         temp.z=491;
6226                                                         temp2.x=1025;
6227                                                         temp2.y=75;
6228                                                         temp2.z=447;
6229
6230                                                         weapons.owner[weapons.numweapons]=-1;
6231                                                         weapons.type[weapons.numweapons]=sword;
6232                                                         weapons.damage[weapons.numweapons]=0;
6233                                                         weapons.mass[weapons.numweapons]=1;
6234                                                         weapons.tipmass[weapons.numweapons]=1.2;
6235                                                         weapons.length[weapons.numweapons]=.25;
6236                                                         weapons.position[weapons.numweapons]=(temp+temp2)/2;
6237                                                         weapons.tippoint[weapons.numweapons]=(temp+temp2)/2;
6238
6239                                                         weapons.velocity[weapons.numweapons]=0.1;
6240                                                         weapons.tipvelocity[weapons.numweapons]=0.1;
6241                                                         weapons.missed[weapons.numweapons]=1;
6242                                                         weapons.hitsomething[weapons.numweapons]=0;
6243                                                         weapons.freetime[weapons.numweapons]=0;
6244                                                         weapons.firstfree[weapons.numweapons]=1;
6245                                                         weapons.physics[weapons.numweapons]=1;
6246
6247                                                         weapons.owner[0]=1;
6248                                                         weapons.owner[1]=0;
6249                                                         player[0].weaponactive=0;
6250                                                         player[0].num_weapons=1;
6251                                                         player[0].weaponids[0]=1;
6252                                                         player[1].weaponactive=0;
6253                                                         player[1].num_weapons=1;
6254                                                         player[1].weaponids[0]=0;
6255
6256                                                         weapons.numweapons++;
6257                                                 }
6258                                                 if(tutorialstage==48){
6259                                                         canattack=0;
6260                                                         cananger=0;
6261                                                         player[1].aitype=passivetype;
6262
6263                                                         tutorialmaxtime=15;
6264
6265                                                         weapons.owner[0]=1;
6266                                                         weapons.owner[1]=0;
6267                                                         player[0].weaponactive=0;
6268                                                         player[0].num_weapons=1;
6269                                                         player[0].weaponids[0]=1;
6270                                                         player[1].weaponactive=0;
6271                                                         player[1].num_weapons=1;
6272                                                         player[1].weaponids[0]=0;
6273
6274                                                         if(player[0].weaponactive!=-1)weapons.type[player[0].weaponids[player[0].weaponactive]]=staff;
6275                                                         else weapons.type[0]=staff;
6276
6277                                                         weapons.numweapons++;
6278                                                 }
6279                                                 if(tutorialstage==49){
6280                                                         canattack=0;
6281                                                         cananger=0;
6282                                                         player[1].aitype=passivetype;
6283
6284                                                         tutorialmaxtime=200;
6285
6286                                                         weapons.position[1]=1000;
6287                                                         weapons.tippoint[1]=1000;
6288
6289                                                         weapons.numweapons=1;
6290                                                         weapons.owner[0]=0;
6291                                                         player[1].weaponactive=-1;
6292                                                         player[1].num_weapons=0;
6293                                                         player[0].weaponactive=0;
6294                                                         player[0].num_weapons=1;
6295                                                         player[0].weaponids[0]=0;
6296
6297                                                         weapons.type[0]=knife;
6298
6299                                                         weapons.numweapons++;
6300                                                 }
6301                                                 if(tutorialstage==50){
6302                                                         tutorialmaxtime=8;
6303
6304                                                         XYZ temp,temp2;
6305                                                         float gLoc[3];
6306                                                         float vel[3];
6307                                                         gLoc[0]=player[1].coords.x;
6308                                                         gLoc[1]=player[1].coords.y;
6309                                                         gLoc[2]=player[1].coords.z;
6310                                                         vel[0]=0;
6311                                                         vel[1]=0;
6312                                                         vel[2]=0;
6313                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6314                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
6315                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6316                                                         OPENAL_SetPaused(channels[fireendsound], false);
6317
6318                                                         for(i=0;i<player[1].skeleton.num_joints;i++){
6319                                                                 if(Random()%2==0){
6320                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
6321                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
6322                                                                         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;
6323                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
6324                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
6325                                                                 }
6326                                                         }
6327
6328                                                         player[1].num_weapons=0;
6329                                                         player[1].weaponstuck=-1;
6330                                                         player[1].weaponactive=-1;
6331
6332                                                         weapons.numweapons=0;
6333
6334                                                         weapons.owner[0]=-1;
6335                                                         weapons.velocity[0]=0.1;
6336                                                         weapons.tipvelocity[0]=-0.1;
6337                                                         weapons.missed[0]=1;
6338                                                         weapons.hitsomething[0]=0;
6339                                                         weapons.freetime[0]=0;
6340                                                         weapons.firstfree[0]=1;
6341                                                         weapons.physics[0]=1;
6342                                                 }
6343                                                 if(tutorialstage==51){
6344                                                         tutorialmaxtime=80000;
6345                                                 }
6346                                                 if(tutorialstage<=51)tutorialstagetime=0;
6347                                         }
6348
6349                                         //Tutorial success
6350                                         if(tutoriallevel&&tutorialstagetime<tutorialmaxtime-3){
6351                                                 if(tutorialstage==3){
6352                                                         if(deltah||deltav)tutorialsuccess+=multiplier;
6353                                                 }
6354                                                 if(tutorialstage==4){
6355                                                         if(player[0].forwardkeydown||player[0].backkeydown||player[0].leftkeydown||player[0].rightkeydown)tutorialsuccess+=multiplier;
6356                                                 }
6357                                                 if(tutorialstage==5){
6358                                                         if(player[0].jumpkeydown)tutorialsuccess=1;
6359                                                 }
6360                                                 if(tutorialstage==6){
6361                                                         if(player[0].isCrouch())tutorialsuccess=1;
6362                                                 }
6363                                                 if(tutorialstage==7){
6364                                                         if(player[0].targetanimation==rollanim)tutorialsuccess=1;
6365                                                 }
6366                                                 if(tutorialstage==8){
6367                                                         if(player[0].targetanimation==sneakanim)tutorialsuccess+=multiplier;
6368                                                 }
6369                                                 if(tutorialstage==9){
6370                                                         if(player[0].targetanimation==rabbitrunninganim||player[0].targetanimation==wolfrunninganim)tutorialsuccess+=multiplier;
6371                                                 }
6372                                                 if(tutorialstage==11){
6373                                                         if(player[0].isWallJump())tutorialsuccess=1;
6374                                                 }
6375                                                 if(tutorialstage==12){
6376                                                         if(player[0].targetanimation==flipanim)tutorialsuccess=1;
6377                                                 }
6378                                                 if(tutorialstage==15){
6379                                                         if(player[0].targetanimation==upunchanim||player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6380                                                 }
6381                                                 if(tutorialstage==16){
6382                                                         if(player[0].targetanimation==winduppunchanim)tutorialsuccess=1;
6383                                                 }
6384                                                 if(tutorialstage==17){
6385                                                         if(player[0].targetanimation==spinkickanim)tutorialsuccess=1;
6386                                                 }
6387                                                 if(tutorialstage==18){
6388                                                         if(player[0].targetanimation==sweepanim)tutorialsuccess=1;
6389                                                 }
6390                                                 if(tutorialstage==19){
6391                                                         if(player[0].targetanimation==dropkickanim)tutorialsuccess=1;
6392                                                 }
6393                                                 if(tutorialstage==20){
6394                                                         if(player[0].targetanimation==rabbitkickanim)tutorialsuccess=1;
6395                                                 }
6396                                                 if(tutorialstage==21){
6397                                                         if(bonus==cannon)tutorialsuccess=1;
6398                                                 }
6399                                                 if(tutorialstage==22){
6400                                                         if(bonus==spinecrusher)tutorialsuccess=1;
6401                                                 }
6402                                                 if(tutorialstage==23){
6403                                                         if(player[0].targetanimation==walljumprightkickanim||player[0].targetanimation==walljumpleftkickanim)tutorialsuccess=1;
6404                                                 }
6405                                                 if(tutorialstage==24){
6406                                                         if(player[0].targetanimation==rabbittacklinganim)tutorialsuccess=1;
6407                                                 }
6408                                                 if(tutorialstage==25){
6409                                                         if(player[0].targetanimation==backhandspringanim)tutorialsuccess=1;
6410                                                 }
6411                                                 if(tutorialstage==28){
6412                                                         if(animation[player[0].targetanimation].attack==reversed&&player[0].feint)tutorialsuccess=1;
6413                                                 }
6414                                                 if(tutorialstage==29){
6415                                                         if(player[0].escapednum==2){
6416                                                                 tutorialsuccess=1;
6417                                                                 reversaltrain=0;
6418                                                                 cananger=0;
6419                                                                 player[1].aitype=passivetype;
6420                                                         }
6421                                                 }
6422                                                 if(tutorialstage==33){
6423                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6424                                                 }
6425                                                 if(tutorialstage==34){
6426                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6427                                                 }
6428                                                 if(tutorialstage==35){
6429                                                         if(animation[player[0].targetanimation].attack==reversal){
6430                                                                 tutorialsuccess=1;
6431                                                                 reversaltrain=0;
6432                                                                 cananger=0;
6433                                                                 player[1].aitype=passivetype;
6434                                                         }
6435                                                 }
6436                                                 if(tutorialstage==40){
6437                                                         if(player[0].num_weapons>0)tutorialsuccess=1;
6438                                                 }
6439                                                 if(tutorialstage==41){
6440                                                         if(player[0].weaponactive==-1&&player[0].num_weapons>0)tutorialsuccess=1;
6441                                                 }
6442                                                 if(tutorialstage==43){
6443                                                         if(player[0].targetanimation==knifeslashstartanim)tutorialsuccess=1;
6444                                                 }
6445                                                 if(tutorialstage==44){
6446                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6447                                                 }
6448                                                 if(tutorialstage==45){
6449                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6450                                                 }
6451                                                 if(tutorialstage==46){
6452                                                         if(animation[player[0].targetanimation].attack==reversal)tutorialsuccess=1;
6453                                                 }
6454                                                 if(tutorialstage==49){
6455                                                         if(player[1].weaponstuck!=-1)tutorialsuccess=1;
6456                                                 }
6457                                                 if(tutorialsuccess>=1)tutorialstagetime=tutorialmaxtime-3;
6458
6459
6460                                                 if(tutorialstagetime==tutorialmaxtime-3){
6461                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6462                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6463                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6464                                                 }
6465
6466                                                 if(tutorialsuccess>=1){
6467                                                         if(tutorialstage==34||tutorialstage==35)
6468                                                                 tutorialstagetime=tutorialmaxtime-1;
6469                                                 }
6470                                         }
6471
6472                                         if(tutoriallevel){
6473                                                 if(tutorialstage<14||tutorialstage>=50){
6474                                                         player[1].coords.y=300;
6475                                                         player[1].velocity=0;
6476                                                 }
6477                                         }
6478
6479                                         if(tutoriallevel!=1){
6480                                                 if(bonustime==0&&bonus!=solidhit&&bonus!=spinecrusher&&bonus!=tracheotomy&&bonus!=backstab&&bonusvalue>10){
6481                                                         PlaySoundEx( consolesuccesssound, samp[consolesuccesssound], NULL, true);
6482                                                         OPENAL_SetVolume(channels[consolesuccesssound], 256);
6483                                                         OPENAL_SetPaused(channels[consolesuccesssound], false);
6484                                                 }
6485                                         }
6486                                         else
6487                                                 if(bonustime==0){
6488                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
6489                                                         OPENAL_SetVolume(channels[fireendsound], 256);
6490                                                         OPENAL_SetPaused(channels[fireendsound], false);
6491                                                 }
6492                                                 if(bonustime==0){
6493                                                         if(bonus!=solidhit&&bonus!=twoxcombo&&bonus!=threexcombo&&bonus!=fourxcombo&&bonus!=megacombo)bonusnum[bonus]++;
6494                                                         else bonusnum[bonus]+=0.15;
6495                                                         if(tutoriallevel)bonusvalue=0;
6496                                                         bonusvalue/=bonusnum[bonus];
6497                                                         bonustotal+=bonusvalue;
6498                                                 }
6499                                                 bonustime+=multiplier;
6500
6501                                                 if(environment==snowyenvironment){
6502                                                         precipdelay-=multiplier;
6503                                                         while(precipdelay<0){
6504                                                                 precipdelay+=.04;
6505                                                                 if(!detail)precipdelay+=.04;
6506                                                                 XYZ footvel,footpoint;
6507
6508                                                                 footvel=0;
6509                                                                 footpoint=viewer+viewerfacing*6;
6510                                                                 footpoint.y+=((float)abs(Random()%1200))/100-6;
6511                                                                 footpoint.x+=((float)abs(Random()%1200))/100-6;
6512                                                                 footpoint.z+=((float)abs(Random()%1200))/100-6;
6513                                                                 sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
6514                                                         }
6515                                                 }
6516                                                 for(k=0;k<numplayers;k++){
6517                                                         if(player[k].aitype==playercontrolled)player[k].turnspeed=500;
6518                                                         if(player[k].aitype!=playercontrolled)player[k].turnspeed=500;
6519
6520                                                         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){
6521                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6522                                                                 else if(player[k].rotation>player[k].targetrotation){
6523                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6524                                                                 }
6525                                                                 else if(player[k].rotation<player[k].targetrotation){
6526                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6527                                                                 }
6528                                                         }
6529
6530
6531                                                         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))){
6532                                                                 player[k].turnspeed*=2;
6533                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6534                                                                 else if(player[k].rotation>player[k].targetrotation){
6535                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6536                                                                 }
6537                                                                 else if(player[k].rotation<player[k].targetrotation){
6538                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6539                                                                 }
6540                                                                 player[k].turnspeed/=2;
6541                                                         }
6542
6543                                                         if(player[k].targetanimation==sneakanim&&player[k].currentanimation!=sneakanim){
6544                                                                 player[k].turnspeed*=4;
6545                                                                 if(abs(player[k].rotation-player[k].targetrotation)<multiplier*player[k].turnspeed)player[k].rotation=player[k].targetrotation;
6546                                                                 else if(player[k].rotation>player[k].targetrotation){
6547                                                                         player[k].rotation-=multiplier*player[k].turnspeed;
6548                                                                 }
6549                                                                 else if(player[k].rotation<player[k].targetrotation){
6550                                                                         player[k].rotation+=multiplier*player[k].turnspeed;
6551                                                                 }
6552                                                                 player[k].turnspeed/=4;
6553                                                         }
6554
6555                                                         /*if(player[k].aitype!=passivetype||(findDistancefast(&player[k].coords,&viewer)<viewdistance*viewdistance))*/  player[k].DoStuff();
6556                                                         if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
6557
6558                                                         if(findDistancefast(&player[k].coords,&player[k].realoldcoords)>0){
6559                                                                 if(!player[k].skeleton.free&&player[k].targetanimation!=climbanim&&player[k].targetanimation!=hanganim){
6560                                                                         bool tempcollide=0;
6561
6562                                                                         if(player[k].collide<-.3)player[k].collide=-.3;
6563                                                                         if(player[k].collide>1)player[k].collide=1;
6564                                                                         player[k].collide-=multiplier*30;
6565
6566                                                                         if(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z)){
6567                                                                                 player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6568                                                                         }
6569                                                                         if(terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz])
6570                                                                                 for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6571                                                                                         i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6572                                                                                         if(objects.type[i]!=rocktype||(((objects.scale[i]>.5&&player[k].aitype==playercontrolled)||objects.position[i].y>player[k].coords.y))){
6573                                                                                                 lowpoint=player[k].coords;
6574                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip())lowpoint.y+=1.25;
6575                                                                                                 else lowpoint.y+=1.3;
6576                                                                                                 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){
6577                                                                                                         player[k].coords.y=terrain.getHeight(player[k].coords.x,player[k].coords.z);
6578                                                                                                 }
6579                                                                                                 /*while(player[k].coords.y<terrain.getHeight(player[k].coords.x,player[k].coords.z))
6580                                                                                                 player[k].coords+=terrain.getNormal(player[k].coords.x,player[k].coords.z)/50;
6581                                                                                                 */
6582                                                                                                 if(player[k].SphereCheck(&lowpoint, 1.3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6583                                                                                                         flatfacing=lowpoint-player[k].coords;
6584                                                                                                         player[k].coords=lowpoint;
6585                                                                                                         player[k].coords.y-=1.3;
6586                                                                                                         player[k].collide=1;
6587                                                                                                         tempcollide=1;
6588                                                                                                         if(player[k].aitype==playercontrolled&&(player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].jumptogglekeydown&&player[k].jumpkeydown){
6589                                                                                                                 lowpointtarget=lowpoint+DoRotation(player[k].facing,0,-90,0)*1.5;
6590                                                                                                                 tempcoords1=lowpoint;
6591                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6592                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6593                                                                                                                         player[k].target=0;
6594                                                                                                                         player[k].targetanimation=walljumpleftanim;
6595                                                                                                                         player[k].targetframe=0;
6596                                                                                                                         float gLoc[3];
6597                                                                                                                         float vel[3];
6598                                                                                                                         gLoc[0]=player[k].coords.x;
6599                                                                                                                         gLoc[1]=player[k].coords.y;
6600                                                                                                                         gLoc[2]=player[k].coords.z;
6601                                                                                                                         vel[0]=0;
6602                                                                                                                         vel[1]=0;
6603                                                                                                                         vel[2]=0;
6604                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6605                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6606                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6607                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6608                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6609
6610                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6611                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6612                                                                                                                         player[k].rotation*=360/6.28;
6613                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6614                                                                                                                         player[k].targetrotation=player[k].rotation;
6615                                                                                                                         player[k].lowrotation=player[k].rotation;
6616                                                                                                                         if(k==0)numwallflipped++;
6617                                                                                                                 }
6618                                                                                                                 else
6619                                                                                                                 {
6620                                                                                                                         lowpoint=tempcoords1;
6621                                                                                                                         lowpointtarget=lowpoint+DoRotation(player[k].facing,0,90,0)*1.5;
6622                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6623                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6624                                                                                                                                 player[k].target=0;
6625                                                                                                                                 player[k].targetanimation=walljumprightanim;
6626                                                                                                                                 player[k].targetframe=0;
6627                                                                                                                                 float gLoc[3];
6628                                                                                                                                 float vel[3];
6629                                                                                                                                 gLoc[0]=player[k].coords.x;
6630                                                                                                                                 gLoc[1]=player[k].coords.y;
6631                                                                                                                                 gLoc[2]=player[k].coords.z;
6632                                                                                                                                 vel[0]=0;
6633                                                                                                                                 vel[1]=0;
6634                                                                                                                                 vel[2]=0;
6635                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6636                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6637                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6638                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6639                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6640
6641                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6642                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6643                                                                                                                                 player[k].rotation*=360/6.28;
6644                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6645                                                                                                                                 player[k].targetrotation=player[k].rotation;
6646                                                                                                                                 player[k].lowrotation=player[k].rotation;
6647                                                                                                                                 if(k==0)numwallflipped++;
6648                                                                                                                         }
6649                                                                                                                         else
6650                                                                                                                         {
6651                                                                                                                                 lowpoint=tempcoords1;
6652                                                                                                                                 lowpointtarget=lowpoint+player[k].facing*2;
6653                                                                                                                                 whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6654                                                                                                                                 if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6655                                                                                                                                         player[k].target=0;
6656                                                                                                                                         player[k].targetanimation=walljumpbackanim;
6657                                                                                                                                         player[k].targetframe=0;
6658                                                                                                                                         float gLoc[3];
6659                                                                                                                                         float vel[3];
6660                                                                                                                                         gLoc[0]=player[k].coords.x;
6661                                                                                                                                         gLoc[1]=player[k].coords.y;
6662                                                                                                                                         gLoc[2]=player[k].coords.z;
6663                                                                                                                                         vel[0]=0;
6664                                                                                                                                         vel[1]=0;
6665                                                                                                                                         vel[2]=0;
6666                                                                                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6667                                                                                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6668                                                                                                                                         OPENAL_SetVolume(channels[movewhooshsound], 256);
6669                                                                                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
6670                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6671
6672                                                                                                                                         lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6673                                                                                                                                         player[k].rotation=-asin(0-lowpointtarget.x);
6674                                                                                                                                         player[k].rotation*=360/6.28;
6675                                                                                                                                         if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6676                                                                                                                                         player[k].targetrotation=player[k].rotation;
6677                                                                                                                                         player[k].lowrotation=player[k].rotation;
6678                                                                                                                                         if(k==0)numwallflipped++;
6679                                                                                                                                 }
6680                                                                                                                                 else
6681                                                                                                                                 {
6682                                                                                                                                         lowpoint=tempcoords1;
6683                                                                                                                                         lowpointtarget=lowpoint-player[k].facing*2;
6684                                                                                                                                         whichhit=objects.model[i].LineCheck(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6685                                                                                                                                         if(whichhit!=-1&&abs(objects.model[i].facenormals[whichhit].y)<.3){
6686                                                                                                                                                 player[k].target=0;
6687                                                                                                                                                 player[k].targetanimation=walljumpfrontanim;
6688                                                                                                                                                 player[k].targetframe=0;
6689                                                                                                                                                 float gLoc[3];
6690                                                                                                                                                 float vel[3];
6691                                                                                                                                                 gLoc[0]=player[k].coords.x;
6692                                                                                                                                                 gLoc[1]=player[k].coords.y;
6693                                                                                                                                                 gLoc[2]=player[k].coords.z;
6694                                                                                                                                                 vel[0]=0;
6695                                                                                                                                                 vel[1]=0;
6696                                                                                                                                                 vel[2]=0;
6697                                                                                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
6698                                                                                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
6699                                                                                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 256);
6700                                                                                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
6701                                                                                                                                                 if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6702
6703                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6704                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6705                                                                                                                                                 player[k].rotation*=360/6.28;
6706                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6707                                                                                                                                                 player[k].rotation+=180;
6708                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6709                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6710                                                                                                                                                 if(k==0)numwallflipped++;
6711                                                                                                                                         }
6712                                                                                                                                 }
6713                                                                                                                         }
6714                                                                                                                 }
6715                                                                                                         }
6716                                                                                                 }
6717                                                                                         }
6718                                                                                         else if(objects.type[i]==rocktype){
6719                                                                                                 lowpoint2=player[k].coords;
6720                                                                                                 lowpoint=player[k].coords;
6721                                                                                                 lowpoint.y+=2;
6722                                                                                                 if(objects.model[i].LineCheck(&lowpoint,&lowpoint2,&colpoint,&objects.position[i],&objects.rotation[i])!=-1){
6723                                                                                                         player[k].coords=colpoint;
6724                                                                                                         player[k].collide=1;
6725                                                                                                         tempcollide=1;
6726
6727                                                                                                         if((player[k].targetanimation==jumpdownanim||player[k].isFlip())){
6728                                                                                                                 if(player[k].isFlip()&&animation[player[k].targetanimation].label[player[k].targetframe]==7)player[k].RagDoll(0);
6729
6730                                                                                                                 if(player[k].targetanimation==jumpupanim){player[k].jumppower=-4;player[k].targetanimation=player[k].getIdle();}
6731                                                                                                                 player[k].target=0;
6732                                                                                                                 player[k].targetframe=0;
6733                                                                                                                 player[k].onterrain=1;
6734
6735                                                                                                                 if(player[k].id==0){
6736                                                                                                                         OPENAL_SetPaused(channels[whooshsound], true);
6737                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6738                                                                                                                 }
6739
6740                                                                                                                 if((player[k].targetanimation==jumpdownanim||player[k].isFlip())&&!player[k].wasLanding()){
6741                                                                                                                         if(player[k].isFlip())player[k].jumppower=-4;
6742                                                                                                                         player[k].targetanimation=player[k].getLanding();
6743                                                                                                                         float gLoc[3];
6744                                                                                                                         float vel[3];
6745                                                                                                                         gLoc[0]=player[k].coords.x;
6746                                                                                                                         gLoc[1]=player[k].coords.y;
6747                                                                                                                         gLoc[2]=player[k].coords.z;
6748                                                                                                                         vel[0]=player[k].velocity.x;
6749                                                                                                                         vel[1]=player[k].velocity.y;
6750                                                                                                                         vel[2]=player[k].velocity.z;
6751                                                                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6752                                                                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6753                                                                                                                         OPENAL_SetVolume(channels[landsound], 128);
6754                                                                                                                         OPENAL_SetPaused(channels[landsound], false);
6755                                                                                                                         if(k==0){
6756                                                                                                                                 envsound[numenvsounds]=player[k].coords;
6757                                                                                                                                 envsoundvol[numenvsounds]=16;
6758                                                                                                                                 envsoundlife[numenvsounds]=.4;
6759                                                                                                                                 numenvsounds++;
6760                                                                                                                         }
6761
6762                                                                                                                 }
6763                                                                                                         }
6764                                                                                                 }
6765                                                                                         }
6766                                                                                 }
6767                                                                                 if(tempcollide&&terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz]&&(/*player[k].jumptogglekeydown*/1==1||player[k].aitype!=playercontrolled))
6768                                                                                         for(l=0;l<terrain.patchobjectnum[player[k].whichpatchx][player[k].whichpatchz];l++){
6769                                                                                                 i=terrain.patchobjects[player[k].whichpatchx][player[k].whichpatchz][l];
6770                                                                                                 lowpoint=player[k].coords;
6771                                                                                                 lowpoint.y+=1.35;
6772                                                                                                 if(objects.type[i]!=rocktype)
6773                                                                                                         if(player[k].SphereCheck(&lowpoint, 1.33, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
6774                                                                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim&&player[k].onterrain)player[k].avoidcollided=1;
6775                                                                                                                 player[k].coords=lowpoint;
6776                                                                                                                 player[k].coords.y-=1.35;
6777                                                                                                                 player[k].collide=1;
6778
6779                                                                                                                 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)){
6780                                                                                                                         lowpoint=player[k].coords;
6781                                                                                                                         objects.model[i].SphereCheckPossible(&lowpoint, 1.5, &objects.position[i], &objects.rotation[i]);
6782                                                                                                                         lowpoint=player[k].coords;
6783                                                                                                                         lowpoint.y+=.05;
6784                                                                                                                         facing=0;
6785                                                                                                                         facing.z=-1;
6786                                                                                                                         facing=DoRotation(facing,0,player[k].targetrotation+180,0);
6787                                                                                                                         lowpointtarget=lowpoint+facing*1.4;
6788                                                                                                                         whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6789                                                                                                                         if(whichhit!=-1){
6790                                                                                                                                 lowpoint=player[k].coords;
6791                                                                                                                                 lowpoint.y+=.1;
6792                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6793                                                                                                                                 lowpoint2=lowpoint;
6794                                                                                                                                 lowpointtarget2=lowpointtarget;
6795                                                                                                                                 lowpoint3=lowpoint;
6796                                                                                                                                 lowpointtarget3=lowpointtarget;
6797                                                                                                                                 lowpoint4=lowpoint;
6798                                                                                                                                 lowpointtarget4=lowpointtarget;
6799                                                                                                                                 lowpoint5=lowpoint;
6800                                                                                                                                 lowpointtarget5=lowpointtarget;
6801                                                                                                                                 lowpoint6=lowpoint;
6802                                                                                                                                 lowpointtarget6=lowpointtarget;
6803                                                                                                                                 lowpoint7=lowpoint;
6804                                                                                                                                 lowpointtarget7=lowpoint;
6805                                                                                                                                 lowpoint2.x+=.1;
6806                                                                                                                                 lowpointtarget2.x+=.1;
6807                                                                                                                                 lowpoint3.z+=.1;
6808                                                                                                                                 lowpointtarget3.z+=.1;
6809                                                                                                                                 lowpoint4.x-=.1;
6810                                                                                                                                 lowpointtarget4.x-=.1;
6811                                                                                                                                 lowpoint5.z-=.1;
6812                                                                                                                                 lowpointtarget5.z-=.1;
6813                                                                                                                                 lowpoint6.y+=45/13;
6814                                                                                                                                 lowpointtarget6.y+=45/13;
6815                                                                                                                                 lowpointtarget6+=facing*.6;
6816                                                                                                                                 lowpointtarget7.y+=90/13;
6817                                                                                                                                 whichhit=objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint,&objects.position[i],&objects.rotation[i]);
6818                                                                                                                                 if(objects.friction[i]>.5)
6819                                                                                                                                         if(whichhit!=-1){
6820                                                                                                                                                 //if(k==0){
6821                                                                                                                                                 if(whichhit!=-1)if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=jumpdownanim)player[k].collided=1;
6822                                                                                                                                                 if(checkcollide(lowpoint7,lowpointtarget7)==-1)
6823                                                                                                                                                         if(checkcollide(lowpoint6,lowpointtarget6)==-1)
6824                                                                                                                                                                 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)
6825                                                                                                                                                                         for(j=0;j<45;j++){
6826                                                                                                                                                                                 lowpoint=player[k].coords;
6827                                                                                                                                                                                 lowpoint.y+=(float)j/13;
6828                                                                                                                                                                                 lowpointtarget=lowpoint+facing*1.4;
6829                                                                                                                                                                                 if(objects.model[i].LineCheckPossible(&lowpoint,&lowpointtarget,&colpoint2,&objects.position[i],&objects.rotation[i])==-1){
6830                                                                                                                                                                                         if(j<=6){
6831                                                                                                                                                                                                 j=100;
6832                                                                                                                                                                                         }
6833                                                                                                                                                                                         /*if(j>=25&&(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)){
6834                                                                                                                                                                                         j=100;
6835                                                                                                                                                                                         }*/
6836                                                                                                                                                                                         if(j<=25&&player[k].targetanimation==jumpdownanim){
6837                                                                                                                                                                                                 j=100;
6838                                                                                                                                                                                         }
6839                                                                                                                                                                                         if(j!=100&&(/*j>25||(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim)){
6840                                                                                                                                                                                                 lowpoint=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0);
6841                                                                                                                                                                                                 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)*/){
6842                                                                                                                                                                                                         lowpoint=player[k].coords;
6843                                                                                                                                                                                                         lowpoint.y+=(float)j/13;
6844                                                                                                                                                                                                         lowpointtarget=lowpoint+facing*1.3;
6845                                                                                                                                                                                                         flatfacing=player[k].coords;
6846                                                                                                                                                                                                         player[k].coords=colpoint-DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[k],0)*.01;
6847                                                                                                                                                                                                         player[k].coords.y=lowpointtarget.y-.07;
6848                                                                                                                                                                                                         player[k].currentoffset=(flatfacing-player[k].coords)/player[k].scale;
6849
6850                                                                                                                                                                                                         if(j>10||!player[k].isRun()){
6851                                                                                                                                                                                                                 if(player[k].targetanimation==jumpdownanim||player[k].targetanimation==jumpupanim){
6852                                                                                                                                                                                                                         if(k==0)OPENAL_SetPaused(channels[whooshsound], true);
6853                                                                                                                                                                                                                 }
6854                                                                                                                                                                                                                 float gLoc[3];
6855                                                                                                                                                                                                                 float vel[3];
6856                                                                                                                                                                                                                 gLoc[0]=player[k].coords.x;
6857                                                                                                                                                                                                                 gLoc[1]=player[k].coords.y;
6858                                                                                                                                                                                                                 gLoc[2]=player[k].coords.z;
6859                                                                                                                                                                                                                 vel[0]=player[k].velocity.x;
6860                                                                                                                                                                                                                 vel[1]=player[k].velocity.y;
6861                                                                                                                                                                                                                 vel[2]=player[k].velocity.z;
6862                                                                                                                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
6863                                                                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
6864                                                                                                                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
6865                                                                                                                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
6866
6867                                                                                                                                                                                                                 lowpointtarget=DoRotation(objects.model[i].facenormals[whichhit],0,objects.rotation[i],0);
6868                                                                                                                                                                                                                 player[k].rotation=-asin(0-lowpointtarget.x);
6869                                                                                                                                                                                                                 player[k].rotation*=360/6.28;
6870                                                                                                                                                                                                                 if(lowpointtarget.z<0)player[k].rotation=180-player[k].rotation;
6871                                                                                                                                                                                                                 player[k].targetrotation=player[k].rotation;
6872                                                                                                                                                                                                                 player[k].lowrotation=player[k].rotation;
6873
6874                                                                                                                                                                                                                 //player[k].velocity=lowpointtarget*.03;
6875                                                                                                                                                                                                                 player[k].velocity=0;
6876
6877                                                                                                                                                                                                                 if(/*(player[k].isRun()||player[k].targetanimation==sneakanim||player[k].targetanimation==walkanim)||*/player[k].targetanimation==jumpupanim){
6878                                                                                                                                                                                                                         //player[k].currentanimation=climbanim;
6879                                                                                                                                                                                                                         player[k].targetanimation=climbanim;
6880                                                                                                                                                                                                                         player[k].jumppower=0;
6881                                                                                                                                                                                                                         player[k].jumpclimb=1;
6882                                                                                                                                                                                                                 }
6883                                                                                                                                                                                                                 player[k].transspeed=6;
6884                                                                                                                                                                                                                 player[k].target=0;
6885
6886                                                                                                                                                                                                                 //player[k].currentframe=1;
6887                                                                                                                                                                                                                 player[k].targetframe=1;
6888                                                                                                                                                                                                                 if(j>25){
6889                                                                                                                                                                                                                         //player[k].currentframe=0;
6890                                                                                                                                                                                                                         player[k].targetframe=0;
6891                                                                                                                                                                                                                         //player[k].currentanimation=hanganim;
6892                                                                                                                                                                                                                         player[k].targetanimation=hanganim;
6893                                                                                                                                                                                                                         player[k].jumppower=0;
6894                                                                                                                                                                                                                 }
6895                                                                                                                                                                                                         }
6896                                                                                                                                                                                                         j=100;
6897                                                                                                                                                                                                 }
6898                                                                                                                                                                                         }
6899                                                                                                                                                                                 }
6900                                                                                                                                                                         }
6901                                                                                                                                                                         //}
6902                                                                                                                                         }
6903                                                                                                                         }
6904                                                                                                                 }
6905                                                                                                         }
6906                                                                                         }
6907                                                                                         if(player[k].collide<=0){
6908                                                                                                 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()){
6909                                                                                                         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)){
6910                                                                                                                 if(player[k].targetanimation==staggerbackhighanim||player[k].targetanimation==staggerbackhardanim)player[k].RagDoll(0);
6911                                                                                                                 player[k].targetanimation=jumpdownanim;
6912                                                                                                                 player[k].targetframe=0;
6913                                                                                                                 player[k].target=0;
6914
6915                                                                                                                 float gLoc[3];
6916                                                                                                                 float vel[3];
6917                                                                                                                 gLoc[0]=player[k].coords.x;
6918                                                                                                                 gLoc[1]=player[k].coords.y;
6919                                                                                                                 gLoc[2]=player[k].coords.z;
6920                                                                                                                 vel[0]=player[k].velocity.x;
6921                                                                                                                 vel[1]=player[k].velocity.y;
6922                                                                                                                 vel[2]=player[k].velocity.z;
6923                                                                                                                 if(k==0){
6924                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
6925                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
6926                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
6927                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
6928                                                                                                                 }
6929                                                                                                         }
6930                                                                                                         player[k].velocity.y+=gravity;
6931                                                                                                 }
6932                                                                                         }
6933                                                                 }
6934                                                         }
6935                                                         player[k].realoldcoords=player[k].coords;
6936                                                 }
6937
6938                                                 static XYZ oldviewer;
6939
6940                                                 if(indialogue==-1){
6941                                                         player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
6942                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
6943                                                         player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
6944                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
6945                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
6946                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
6947                                                         player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
6948                                                         player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
6949                                                 }
6950                                                 else
6951                                                 {
6952                                                         player[0].forwardkeydown=0;
6953                                                         player[0].leftkeydown=0;
6954                                                         player[0].backkeydown=0;
6955                                                         player[0].rightkeydown=0;
6956                                                         player[0].jumpkeydown=0;
6957                                                         player[0].crouchkeydown=0;
6958                                                         player[0].drawkeydown=0;
6959                                                         player[0].throwkeydown=0;
6960                                                 }
6961
6962                                                 if(!player[0].jumpkeydown)player[0].jumpclimb=0;
6963
6964
6965                                                 static bool endkeydown;
6966                                                 if(indialogue!=-1){
6967                                                         cameramode=1;
6968                                                         if(directing){
6969                                                                 facing=0;
6970                                                                 facing.z=-1;
6971
6972                                                                 facing=DoRotation(facing,-rotation2,0,0);
6973                                                                 facing=DoRotation(facing,0,0-rotation,0);
6974
6975                                                                 flatfacing=0;
6976                                                                 flatfacing.z=-1;
6977
6978                                                                 flatfacing=DoRotation(flatfacing,0,-rotation,0);
6979
6980                                                                 if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
6981                                                                 if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
6982                                                                 if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
6983                                                                 if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
6984                                                                 if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
6985                                                                 if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
6986                                                                 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)
6987                                                                         ||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)
6988                                                                         ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
6989                                                                                 int whichend;
6990                                                                                 if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
6991                                                                                 if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
6992                                                                                 if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
6993                                                                                 if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
6994                                                                                 if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
6995                                                                                 if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
6996                                                                                 if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
6997                                                                                 if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
6998                                                                                 if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
6999                                                                                 if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
7000                                                                                 if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
7001                                                                                 if(whichend!=-1){
7002                                                                                         participantfocus[whichdialogue][indialogue]=whichend;
7003                                                                                         participantlocation[whichdialogue][whichend]=player[whichend].coords;
7004                                                                                         participantrotation[whichdialogue][whichend]=player[whichend].rotation;
7005                                                                                 }
7006                                                                                 if(whichend==-1){
7007                                                                                         participantfocus[whichdialogue][indialogue]=-1;
7008                                                                                 }
7009                                                                                 if(player[participantfocus[whichdialogue][indialogue]].dead){
7010                                                                                         indialogue=-1;
7011                                                                                         directing=0;
7012                                                                                         cameramode=0;
7013                                                                                 }
7014                                                                                 dialoguecamera[whichdialogue][indialogue]=viewer;
7015                                                                                 dialoguecamerarotation[whichdialogue][indialogue]=rotation;
7016                                                                                 dialoguecamerarotation2[whichdialogue][indialogue]=rotation2;
7017                                                                                 indialogue++;
7018                                                                                 if(indialogue<numdialogueboxes[whichdialogue]){
7019                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=0){
7020                                                                                                 static float gLoc[3];
7021                                                                                                 static float vel[3];
7022                                                                                                 XYZ temppos;
7023                                                                                                 temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7024                                                                                                 temppos=temppos-viewer;
7025                                                                                                 Normalise(&temppos);
7026                                                                                                 temppos+=viewer;
7027
7028                                                                                                 gLoc[0]=temppos.x;
7029                                                                                                 gLoc[1]=temppos.y;
7030                                                                                                 gLoc[2]=temppos.z;vel[0]=0;
7031                                                                                                 vel[1]=0;
7032                                                                                                 vel[2]=0;
7033                                                                                                 int whichsoundplay;
7034                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7035                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7036                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7037                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7038                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7039                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7040                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7041                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7042                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7043                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7044                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7045                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7046                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7047                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7048                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7049                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7050                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7051                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7052                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7053                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7054                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
7055                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7056                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
7057                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
7058                                                                                         }
7059                                                                                 }
7060
7061                                                                                 for(j=0;j<numplayers;j++){
7062                                                                                         participantfacing[whichdialogue][indialogue][j]=participantfacing[whichdialogue][indialogue-1][j];
7063                                                                                 }
7064
7065                                                                                 endkeydown=1;
7066                                                                         }
7067                                                                         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)
7068                                                                                 ||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)
7069                                                                                 )){
7070                                                                                         int whichend;
7071                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
7072                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
7073                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
7074                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
7075                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
7076                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
7077                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
7078                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
7079                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
7080                                                                                         if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
7081                                                                                         participantfacing[whichdialogue][indialogue][whichend]=facing;
7082                                                                                 }
7083                                                                                 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)
7084                                                                                         &&!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)
7085                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7086                                                                                                 endkeydown=0;
7087                                                                                         }
7088                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7089                                                                                                 indialogue=-1;
7090                                                                                                 directing=0;
7091                                                                                                 cameramode=0;
7092                                                                                         }
7093                                                         }
7094                                                         if(!directing){
7095                                                                 OPENAL_SetPaused(channels[whooshsound], true);
7096                                                                 viewer=dialoguecamera[whichdialogue][indialogue];
7097                                                                 if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.1){
7098                                                                         viewer.y=terrain.getHeight(viewer.x,viewer.z)+.1;
7099                                                                 }
7100                                                                 rotation=dialoguecamerarotation[whichdialogue][indialogue];
7101                                                                 rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
7102                                                                 if(dialoguetime>0.5)
7103                                                                         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)
7104                                                                                 ||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)
7105                                                                                 ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
7106                                                                                         indialogue++;
7107                                                                                         endkeydown=1;
7108                                                                                         if(indialogue<numdialogueboxes[whichdialogue]){
7109                                                                                                 if(dialogueboxsound[whichdialogue][indialogue]!=0){
7110                                                                                                         static float gLoc[3];
7111                                                                                                         static float vel[3];
7112                                                                                                         XYZ temppos;
7113                                                                                                         temppos=player[participantfocus[whichdialogue][indialogue]].coords;
7114                                                                                                         temppos=temppos-viewer;
7115                                                                                                         Normalise(&temppos);
7116                                                                                                         temppos+=viewer;
7117
7118                                                                                                         gLoc[0]=temppos.x;
7119                                                                                                         gLoc[1]=temppos.y;
7120                                                                                                         gLoc[2]=temppos.z;vel[0]=0;
7121                                                                                                         vel[1]=0;
7122                                                                                                         vel[2]=0;
7123                                                                                                         int whichsoundplay;
7124                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==1)whichsoundplay=rabbitchitter;
7125                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==2)whichsoundplay=rabbitchitter2;
7126                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==3)whichsoundplay=rabbitpainsound;
7127                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==4)whichsoundplay=rabbitpain1sound;
7128                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==5)whichsoundplay=rabbitattacksound;
7129                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==6)whichsoundplay=rabbitattack2sound;
7130                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==7)whichsoundplay=rabbitattack3sound;
7131                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==8)whichsoundplay=rabbitattack4sound;
7132                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==9)whichsoundplay=growlsound;
7133                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==10)whichsoundplay=growl2sound;
7134                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==11)whichsoundplay=snarlsound;
7135                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==12)whichsoundplay=snarl2sound;
7136                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==13)whichsoundplay=barksound;
7137                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==14)whichsoundplay=bark2sound;
7138                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==15)whichsoundplay=bark3sound;
7139                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==16)whichsoundplay=barkgrowlsound;
7140                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-1)whichsoundplay=fireendsound;
7141                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-2)whichsoundplay=firestartsound;
7142                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-3)whichsoundplay=consolesuccesssound;
7143                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-4)whichsoundplay=consolefailsound;
7144                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6)whichsoundplay=alarmsound;
7145                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]!=-5){
7146                                                                                                                 PlaySoundEx( whichsoundplay, samp[whichsoundplay], NULL, true);
7147                                                                                                                 OPENAL_3D_SetAttributes(channels[whichsoundplay], gLoc, vel);
7148                                                                                                                 OPENAL_SetVolume(channels[whichsoundplay], 256);
7149                                                                                                                 OPENAL_SetPaused(channels[whichsoundplay], false);
7150                                                                                                         }
7151                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-5){
7152                                                                                                                 hotspot[numhotspots]=player[0].coords;
7153                                                                                                                 hotspotsize[numhotspots]=10;
7154                                                                                                                 hotspottype[numhotspots]=-1;
7155
7156                                                                                                                 numhotspots++;
7157                                                                                                         }
7158                                                                                                         if(dialogueboxsound[whichdialogue][indialogue]==-6){
7159                                                                                                                 hostile=1;
7160                                                                                                         }
7161
7162                                                                                                         if(player[participantfocus[whichdialogue][indialogue]].dead){
7163                                                                                                                 indialogue=-1;
7164                                                                                                                 directing=0;
7165                                                                                                                 cameramode=0;
7166                                                                                                         }
7167                                                                                                 }
7168                                                                                         }
7169                                                                                 }
7170                                                                                 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)
7171                                                                                         &&!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)
7172                                                                                         &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
7173                                                                                                 endkeydown=0;
7174                                                                                         }
7175                                                                                         if(indialogue>=numdialogueboxes[whichdialogue]){
7176                                                                                                 indialogue=-1;
7177                                                                                                 directing=0;
7178                                                                                                 cameramode=0;
7179                                                                                                 if(dialoguetype[whichdialogue]>19&&dialoguetype[whichdialogue]<30){
7180                                                                                                         hostile=1;
7181                                                                                                 }
7182                                                                                                 if(dialoguetype[whichdialogue]>29&&dialoguetype[whichdialogue]<40){
7183                                                                                                         windialogue=1;
7184                                                                                                 }
7185                                                                                                 if(dialoguetype[whichdialogue]>49&&dialoguetype[whichdialogue]<60){
7186                                                                                                         hostile=1;
7187                                                                                                         for(i=1;i<numplayers;i++){
7188                                                                                                                 player[i].aitype = attacktypecutoff;
7189                                                                                                         }
7190                                                                                                 }
7191                                                                                         }
7192                                                         }
7193                                                 }
7194
7195                                                 if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
7196                                                 else oldbuttondialogue=1;
7197
7198                                                 static float keyrefreshdelay=0,bigrefreshdelay=0;
7199
7200                                                 //Net updates
7201
7202                                                 /*keyrefreshdelay-=multiplier;
7203                                                 bigrefreshdelay-=multiplier;
7204
7205                                                 if(keyrefreshdelay<=0){
7206                                                 static int concat[4];
7207
7208                                                 concat[0]=player[0].forwardkeydown;
7209                                                 concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
7210                                                 concat[0]=concat[0]*2+player[0].rightkeydown;
7211                                                 concat[0]=concat[0]*2+player[0].leftkeydown;
7212                                                 concat[0]=concat[0]*2+player[0].backkeydown;
7213                                                 concat[0]=concat[0]*2+player[0].jumpkeydown;
7214                                                 concat[0]=concat[0]*2+player[0].jumptogglekeydown;
7215                                                 concat[0]=concat[0]*2+player[0].crouchkeydown;
7216
7217                                                 concat[1]=player[0].crouchtogglekeydown;
7218                                                 concat[1]=concat[1]*2+player[0].drawkeydown;
7219                                                 concat[1]=concat[1]*2+player[0].drawtogglekeydown;
7220                                                 concat[1]=concat[1]*2+player[0].throwkeydown;
7221                                                 concat[1]=concat[1]*2+player[0].throwtogglekeydown;
7222                                                 concat[1]=concat[1]*2+player[0].attackkeydown;
7223
7224                                                 //concat[2]=(char)((int)(rotation/2)%180);
7225
7226                                                 //concat[3]=(char)((int)(rotation2/2)%180);
7227
7228                                                 chatname[0]=concat[0]-128;
7229                                                 chatname[1]=concat[1]-128;
7230                                                 //chatname[2]=concat[2]-128;
7231                                                 //chatname[3]=concat[3]-128;
7232                                                 int temppoint=2;
7233                                                 memcpy(chatname+temppoint,&rotation,sizeof(float));
7234                                                 temppoint+=sizeof(float);
7235                                                 memcpy(chatname+temppoint,&rotation2,sizeof(float));
7236                                                 temppoint+=sizeof(float);
7237
7238                                                 chatname[temppoint]='\0';
7239
7240                                                 //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
7241                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
7242                                                 //keyrefreshdelay=.01;
7243                                                 keyrefreshdelay=.03;
7244                                                 }
7245
7246                                                 if(bigrefreshdelay<=0){
7247                                                 for(i=0;i<1;i++){
7248                                                 /*int temppoint=0;
7249                                                 memcpy(chatname+temppoint,&i,sizeof(int));
7250                                                 temppoint+=sizeof(int);
7251                                                 memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
7252                                                 temppoint+=sizeof(float);
7253                                                 memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
7254                                                 temppoint+=sizeof(float);
7255                                                 memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
7256                                                 temppoint+=sizeof(float);
7257                                                 memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
7258                                                 temppoint+=sizeof(float);
7259                                                 memcpy(chatname+temppoint,&player[i].target,sizeof(float));
7260                                                 temppoint+=sizeof(float);
7261                                                 memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
7262                                                 temppoint+=sizeof(int);
7263                                                 memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
7264                                                 temppoint+=sizeof(int);
7265                                                 memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
7266                                                 temppoint+=sizeof(float);
7267                                                 memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
7268                                                 temppoint+=sizeof(float);
7269                                                 memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
7270                                                 temppoint+=sizeof(float);
7271                                                 memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
7272                                                 temppoint+=sizeof(int);
7273                                                 memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
7274                                                 temppoint+=sizeof(int);
7275                                                 memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
7276                                                 temppoint+=sizeof(float);
7277                                                 memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
7278                                                 temppoint+=sizeof(float);
7279                                                 memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
7280                                                 temppoint+=sizeof(float);
7281                                                 memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
7282                                                 temppoint+=sizeof(int);
7283                                                 memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
7284                                                 temppoint+=sizeof(int);
7285                                                 memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
7286                                                 temppoint+=sizeof(int);
7287                                                 memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
7288                                                 temppoint+=sizeof(int);
7289                                                 memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
7290                                                 temppoint+=sizeof(int);
7291                                                 memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
7292                                                 temppoint+=sizeof(int);
7293                                                 chatname[temppoint]='\0';
7294
7295                                                 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);
7296                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
7297                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
7298
7299                                                 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);
7300
7301                                                 //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
7302                                                 //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
7303                                                 }
7304                                                 //bigrefreshdelay=.02;
7305                                                 bigrefreshdelay=.1;
7306                                                 }
7307                                                 }*/
7308
7309                                                 if(!player[0].jumpkeydown){
7310                                                         player[0].jumptogglekeydown=0;
7311                                                 }
7312                                                 if(player[0].jumpkeydown&&player[0].targetanimation!=jumpupanim&&player[0].targetanimation!=jumpdownanim&&!player[0].isFlip())player[0].jumptogglekeydown=1;
7313
7314
7315                                                 dialoguetime+=multiplier;
7316                                                 skybox.cloudmove+=multiplier;
7317                                                 hawkrotation+=multiplier*25;
7318                                                 realhawkcoords=0;
7319                                                 realhawkcoords.x=25;
7320                                                 realhawkcoords=DoRotation(realhawkcoords,0,hawkrotation,0)+hawkcoords;
7321                                                 hawkcalldelay-=multiplier/2;
7322
7323                                                 if(hawkcalldelay<=0)
7324                                                 {
7325                                                         static float gLoc[3];
7326                                                         static float vel[3];
7327                                                         gLoc[0]=realhawkcoords.x;
7328                                                         gLoc[1]=realhawkcoords.y;
7329                                                         gLoc[2]=realhawkcoords.z;
7330                                                         vel[0]=0;
7331                                                         vel[1]=0;
7332                                                         vel[2]=0;
7333                                                         PlaySoundEx( hawksound, samp[hawksound], NULL, true);
7334                                                         OPENAL_3D_SetAttributes(channels[hawksound], gLoc, vel);
7335                                                         OPENAL_SetVolume(channels[hawksound], 128);
7336                                                         OPENAL_SetPaused(channels[hawksound], false);
7337
7338                                                         hawkcalldelay=16+abs(Random()%8);
7339                                                 }
7340                                                 static float temptexdetail;
7341
7342
7343                                                 if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
7344                                                         player[0].damagetolerance=200000;
7345                                                         player[0].damage=0;
7346                                                         player[0].burnt=0;
7347                                                         player[0].permanentdamage=0;
7348                                                         player[0].superpermanentdamage=0;
7349                                                         /*
7350                                                         int whichchar;
7351                                                         whichchar = abs(Random()%7);
7352                                                         registrationname[whichchar]+=1;
7353                                                         */
7354                                                 }
7355
7356                                                 if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
7357                                                         environment++;
7358                                                         if(environment>2)environment=0;
7359                                                         Setenvironment(environment);
7360
7361                                                         envtogglekeydown=1;
7362                                                 }
7363
7364
7365                                                 if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
7366                                                         envtogglekeydown=0;
7367                                                 }
7368
7369                                                 if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
7370                                                         cameramode=1-cameramode;
7371                                                         cameratogglekeydown=1;
7372                                                 }
7373
7374                                                 if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
7375                                                         cameratogglekeydown=0;
7376                                                 }
7377
7378                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7379                                                         if(player[0].num_weapons>0){
7380                                                                 if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
7381                                                                 else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
7382                                                                 else weapons.type[player[0].weaponids[0]]=sword;
7383                                                                 if(weapons.type[player[0].weaponids[0]]==sword){
7384                                                                         weapons.mass[player[0].weaponids[0]]=1.5;
7385                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7386                                                                         weapons.length[player[0].weaponids[0]]=.8;
7387                                                                 }
7388                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7389                                                                         weapons.mass[player[0].weaponids[0]]=2;
7390                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7391                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7392                                                                 }
7393
7394                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
7395                                                                         weapons.mass[player[0].weaponids[0]]=1;
7396                                                                         weapons.tipmass[player[0].weaponids[0]]=1.2;
7397                                                                         weapons.length[player[0].weaponids[0]]=.25;
7398                                                                 }
7399                                                         }
7400
7401                                                         /*for(i=0;i<objects.numobjects;i++){
7402                                                         if(objects.type[i]==treeleavestype){
7403                                                         for(j=0;j<objects.numobjects;j++){
7404                                                         if(objects.type[j]==treetrunktype)
7405                                                         if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
7406                                                         objects.scale[i]=objects.scale[j];
7407                                                         }
7408                                                         }
7409                                                         }*/
7410                                                         detailtogglekeydown=1;
7411                                                 }
7412
7413                                                 if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
7414                                                         int closest=-1;
7415                                                         float closestdist=-1;
7416                                                         float distance;
7417                                                         if(numplayers>1)
7418                                                                 for(i=1;i<numplayers;i++){
7419                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7420                                                                         if(closestdist==-1||distance<closestdist){
7421                                                                                 closestdist=distance;
7422                                                                                 closest=i;
7423                                                                         }
7424                                                                 }
7425                                                                 if(closest!=-1){
7426                                                                         if(player[closest].num_weapons)
7427                                                                         {
7428                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword)weapons.type[player[closest].weaponids[0]]=staff;
7429                                                                                 else if(weapons.type[player[closest].weaponids[0]]==staff)weapons.type[player[closest].weaponids[0]]=knife;
7430                                                                                 else weapons.type[player[closest].weaponids[0]]=sword;
7431                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7432                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7433                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7434                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7435                                                                                 }
7436                                                                                 if(weapons.type[player[0].weaponids[0]]==staff){
7437                                                                                         weapons.mass[player[0].weaponids[0]]=2;
7438                                                                                         weapons.tipmass[player[0].weaponids[0]]=1;
7439                                                                                         weapons.length[player[0].weaponids[0]]=1.5;
7440                                                                                 }
7441                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7442                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7443                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7444                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7445                                                                                 }
7446                                                                         }
7447                                                                         if(!player[closest].num_weapons)
7448                                                                         {
7449                                                                                 player[closest].weaponids[0]=weapons.numweapons;
7450                                                                                 weapons.owner[weapons.numweapons]=closest;
7451                                                                                 weapons.type[weapons.numweapons]=knife;
7452                                                                                 weapons.damage[weapons.numweapons]=0;
7453                                                                                 weapons.numweapons++;
7454                                                                                 player[closest].num_weapons=1;
7455                                                                                 if(weapons.type[player[closest].weaponids[0]]==sword){
7456                                                                                         weapons.mass[player[closest].weaponids[0]]=1.5;
7457                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1;
7458                                                                                         weapons.length[player[closest].weaponids[0]]=.8;
7459                                                                                 }
7460                                                                                 if(weapons.type[player[closest].weaponids[0]]==knife){
7461                                                                                         weapons.mass[player[closest].weaponids[0]]=1;
7462                                                                                         weapons.tipmass[player[closest].weaponids[0]]=1.2;
7463                                                                                         weapons.length[player[closest].weaponids[0]]=.25;
7464                                                                                 }
7465                                                                         }
7466                                                                 }
7467                                                                 detailtogglekeydown=1;
7468                                                 }
7469
7470                                                 if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
7471                                                         int closest=-1;
7472                                                         float closestdist=-1;
7473                                                         float distance;
7474                                                         if(numplayers>1)
7475                                                                 for(i=1;i<numplayers;i++){
7476                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7477                                                                         if(closestdist==-1||distance<closestdist){
7478                                                                                 closestdist=distance;
7479                                                                                 closest=i;
7480                                                                         }
7481                                                                 }
7482
7483                                                                 player[closest].rotation+=multiplier*50;
7484                                                                 player[closest].targetrotation=player[closest].rotation;
7485                                                 }
7486
7487
7488                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7489                                                         int closest=-1;
7490                                                         float closestdist=-1;
7491                                                         float distance;
7492                                                         if(numplayers>1)
7493                                                                 for(i=1;i<numplayers;i++){
7494                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7495                                                                         if(closestdist==-1||distance<closestdist){
7496                                                                                 closestdist=distance;
7497                                                                                 closest=i;
7498                                                                         }
7499                                                                 }
7500                                                                 if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
7501
7502                                                                 if(closest!=-1){
7503                                                                         player[closest].whichskin++;
7504                                                                         if(player[closest].whichskin>9)player[closest].whichskin=0;
7505                                                                         if(player[closest].whichskin>2&&player[closest].creature==wolftype)player[closest].whichskin=0;
7506
7507                                                                         if(player[closest].creature==rabbittype){
7508                                                                                 if(player[closest].whichskin==0){
7509                                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7510                                                                                 }
7511                                                                                 else if(player[closest].whichskin==1){
7512                                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7513                                                                                 }
7514                                                                                 else if(player[closest].whichskin==2){
7515                                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7516                                                                                 }
7517                                                                                 else if(player[closest].whichskin==3){
7518                                                                                         LoadTextureSave(":Data:Textures:Lynx.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7519                                                                                 }
7520                                                                                 else if(player[closest].whichskin==4){
7521                                                                                         LoadTextureSave(":Data:Textures:Otter.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7522                                                                                 }
7523                                                                                 else if(player[closest].whichskin==5){
7524                                                                                         LoadTextureSave(":Data:Textures:Opal.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7525                                                                                 }
7526                                                                                 else if(player[closest].whichskin==6){
7527                                                                                         LoadTextureSave(":Data:Textures:Sable.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7528                                                                                 }
7529                                                                                 else if(player[closest].whichskin==7){
7530                                                                                         LoadTextureSave(":Data:Textures:Chocolate.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7531                                                                                 }
7532                                                                                 else if(player[closest].whichskin==8){
7533                                                                                         LoadTextureSave(":Data:Textures:BW2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7534                                                                                 }
7535                                                                                 else if(player[closest].whichskin==9){
7536                                                                                         LoadTextureSave(":Data:Textures:WB2.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7537                                                                                 }
7538                                                                         }
7539                                                                         if(player[closest].creature==wolftype){
7540                                                                                 k=abs(Random()%3);
7541                                                                                 if(player[closest].whichskin==0){
7542                                                                                         LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7543                                                                                 }
7544                                                                                 else if(player[closest].whichskin==1){
7545                                                                                         LoadTextureSave(":Data:Textures:Darkwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7546                                                                                 }
7547                                                                                 else if(player[closest].whichskin==2){
7548                                                                                         LoadTextureSave(":Data:Textures:Snowwolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7549                                                                                 }
7550                                                                         }
7551                                                                 }
7552
7553                                                                 if(player[closest].numclothes){
7554                                                                         for(i=0;i<player[closest].numclothes;i++){
7555                                                                                 tintr=player[closest].clothestintr[i];
7556                                                                                 tintg=player[closest].clothestintg[i];
7557                                                                                 tintb=player[closest].clothestintb[i];
7558                                                                                 AddClothes((char *)player[closest].clothes[i],0,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7559                                                                         }
7560                                                                         player[closest].DoMipmaps(5,0,0,player[closest].skeleton.skinsize,player[closest].skeleton.skinsize);
7561                                                                 }
7562
7563                                                                 detailtogglekeydown=1;
7564                                                 }
7565
7566                                                 if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7567                                                         int closest=-1;
7568                                                         float closestdist=-1;
7569                                                         float distance;
7570                                                         if(numplayers>1)
7571                                                                 for(i=1;i<numplayers;i++){
7572                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7573                                                                         if(closestdist==-1||distance<closestdist){
7574                                                                                 closestdist=distance;
7575                                                                                 closest=i;
7576                                                                         }
7577                                                                 }
7578                                                                 if(closest!=-1){
7579                                                                         if(player[closest].creature==wolftype){
7580                                                                                 headprop=player[closest].proportionhead.x/1.1;
7581                                                                                 bodyprop=player[closest].proportionbody.x/1.1;
7582                                                                                 armprop=player[closest].proportionarms.x/1.1;
7583                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7584                                                                         }
7585
7586                                                                         if(player[closest].creature==rabbittype){
7587                                                                                 headprop=player[closest].proportionhead.x/1.2;
7588                                                                                 bodyprop=player[closest].proportionbody.x/1.05;
7589                                                                                 armprop=player[closest].proportionarms.x/1.00;
7590                                                                                 legprop=player[closest].proportionlegs.x/1.1;
7591                                                                         }
7592
7593
7594                                                                         if(player[closest].creature==rabbittype){
7595                                                                                 player[closest].skeleton.id=closest;
7596                                                                                 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);
7597                                                                                 LoadTextureSave(":Data:Textures:Wolf.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[closest],&player[closest].skeleton.skinsize);
7598                                                                                 player[closest].whichskin=0;
7599                                                                                 player[closest].creature=wolftype;
7600
7601                                                                                 player[closest].proportionhead=1.1;
7602                                                                                 player[closest].proportionbody=1.1;
7603                                                                                 player[closest].proportionarms=1.1;
7604                                                                                 player[closest].proportionlegs=1.1;
7605                                                                                 player[closest].proportionlegs.y=1.1;
7606                                                                                 player[closest].scale=.23*5*player[0].scale;
7607
7608                                                                                 player[closest].damagetolerance=300;
7609                                                                         }
7610                                                                         else
7611                                                                         {
7612                                                                                 player[closest].skeleton.id=closest;
7613                                                                                 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);
7614                                                                                 LoadTextureSave(":Data:Textures:Fur3.jpg",&player[closest].skeleton.drawmodel.textureptr,1,&player[closest].skeleton.skinText[0],&player[closest].skeleton.skinsize);
7615                                                                                 player[closest].whichskin=0;
7616                                                                                 player[closest].creature=rabbittype;
7617
7618                                                                                 player[closest].proportionhead=1.2;
7619                                                                                 player[closest].proportionbody=1.05;
7620                                                                                 player[closest].proportionarms=1.00;
7621                                                                                 player[closest].proportionlegs=1.1;
7622                                                                                 player[closest].proportionlegs.y=1.05;
7623                                                                                 player[closest].scale=.2*5*player[0].scale;
7624
7625                                                                                 player[closest].damagetolerance=200;
7626                                                                         }
7627
7628                                                                         if(player[closest].creature==wolftype){
7629                                                                                 player[closest].proportionhead=1.1*headprop;
7630                                                                                 player[closest].proportionbody=1.1*bodyprop;
7631                                                                                 player[closest].proportionarms=1.1*armprop;
7632                                                                                 player[closest].proportionlegs=1.1*legprop;
7633                                                                         }
7634
7635                                                                         if(player[closest].creature==rabbittype){
7636                                                                                 player[closest].proportionhead=1.2*headprop;
7637                                                                                 player[closest].proportionbody=1.05*bodyprop;
7638                                                                                 player[closest].proportionarms=1.00*armprop;
7639                                                                                 player[closest].proportionlegs=1.1*legprop;
7640                                                                                 player[closest].proportionlegs.y=1.05*legprop;
7641                                                                         }
7642
7643                                                                 }
7644                                                                 detailtogglekeydown=1;
7645                                                 }
7646
7647                                                 if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
7648                                                         detailtogglekeydown=0;
7649                                                 }
7650
7651                                                 if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
7652                                                         slomo=1-slomo;
7653                                                         slomodelay=1000;
7654                                                         slomotogglekeydown=1;
7655                                                 }
7656
7657
7658                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
7659                                                         int closest=-1;
7660                                                         float closestdist=-1;
7661                                                         float distance;
7662                                                         XYZ flatfacing2,flatvelocity2;
7663                                                         XYZ blah;
7664                                                         if(numplayers>1)
7665                                                                 for(i=1;i<numplayers;i++){
7666                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7667                                                                         if(distance<144&&!player[i].headless)
7668                                                                                 if(closestdist==-1||distance<closestdist){
7669                                                                                         closestdist=distance;
7670                                                                                         closest=i;
7671                                                                                         blah = player[i].coords;
7672                                                                                 }
7673                                                                 }
7674
7675                                                                 if(closest!=-1){
7676                                                                         XYZ headspurtdirection;
7677                                                                         int i = player[closest].skeleton.jointlabels[head];
7678                                                                         for(k=0;k<player[closest].skeleton.num_joints; k++){
7679                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7680                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7681                                                                                 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;
7682                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7683                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7684                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7685                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7686                                                                                 headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
7687                                                                                 Normalise(&headspurtdirection);
7688                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
7689                                                                                 flatvelocity2+=headspurtdirection*8;
7690                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
7691                                                                         }
7692                                                                         sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7693
7694                                                                         float gLoc[3];
7695                                                                         float vel[3];
7696                                                                         gLoc[0]=blah.x;
7697                                                                         gLoc[1]=blah.y;
7698                                                                         gLoc[2]=blah.z;
7699                                                                         vel[0]=0;
7700                                                                         vel[1]=0;
7701                                                                         vel[2]=0;
7702                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7703                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7704                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7705                                                                         OPENAL_SetPaused(channels[splattersound], false);
7706
7707                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7708                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7709                                                                         OPENAL_SetVolume(channels[breaksound2], 100);
7710                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7711
7712                                                                         if(player[closest].skeleton.free==2)player[closest].skeleton.free=0;
7713                                                                         player[closest].RagDoll(0);
7714                                                                         player[closest].dead=2;
7715                                                                         player[closest].headless=1;
7716                                                                         player[closest].DoBloodBig(3,165);
7717
7718                                                                         camerashake+=.3;
7719                                                                 }
7720
7721                                                                 explodetogglekeydown=1;
7722                                                 }
7723
7724                                                 if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
7725                                                         int closest=-1;
7726                                                         float closestdist=-1;
7727                                                         float distance;
7728                                                         XYZ flatfacing2,flatvelocity2;
7729                                                         XYZ blah;
7730                                                         if(numplayers>1)
7731                                                                 for(i=1;i<numplayers;i++){
7732                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7733                                                                         if(distance<144)
7734                                                                                 if(closestdist==-1||distance<closestdist){
7735                                                                                         closestdist=distance;
7736                                                                                         closest=i;
7737                                                                                         blah=player[i].coords;
7738                                                                                 }
7739                                                                 }
7740
7741                                                                 if(closest!=-1){
7742                                                                         float gLoc[3];
7743                                                                         float vel[3];
7744                                                                         gLoc[0]=blah.x;
7745                                                                         gLoc[1]=blah.y;
7746                                                                         gLoc[2]=blah.z;
7747                                                                         vel[0]=0;
7748                                                                         vel[1]=0;
7749                                                                         vel[2]=0;
7750
7751                                                                         PlaySoundEx( splattersound, samp[splattersound], NULL, true);
7752                                                                         OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
7753                                                                         OPENAL_SetVolume(channels[splattersound], 256);
7754                                                                         OPENAL_SetPaused(channels[splattersound], false);
7755
7756                                                                         PlaySoundEx( breaksound2, samp[breaksound2], NULL, true);
7757                                                                         OPENAL_3D_SetAttributes(channels[breaksound2], gLoc, vel);
7758                                                                         OPENAL_SetVolume(channels[breaksound2], 600);
7759                                                                         OPENAL_SetPaused(channels[breaksound2], false);
7760
7761                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7762                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7763                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7764                                                                                 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;
7765                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7766                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7767                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7768                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7769                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7770                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
7771                                                                                 sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
7772                                                                         }
7773
7774                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7775                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7776                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7777                                                                                 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;
7778                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7779                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7780                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7781                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7782                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
7783                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
7784                                                                         }
7785
7786                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7787                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7788                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7789                                                                                 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;
7790                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7791                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7792                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7793                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7794                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7795                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7796                                                                         }
7797
7798                                                                         for(i=0;i<player[closest].skeleton.num_joints; i++){
7799                                                                                 if(!player[closest].skeleton.free)flatvelocity2=player[closest].velocity;
7800                                                                                 if(player[closest].skeleton.free)flatvelocity2=player[closest].skeleton.joints[i].velocity;
7801                                                                                 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;
7802                                                                                 if(player[closest].skeleton.free)flatfacing2=player[closest].skeleton.joints[i].position*player[closest].scale+player[closest].coords;
7803                                                                                 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
7804                                                                                 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
7805                                                                                 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
7806                                                                                 sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
7807                                                                                 sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
7808                                                                         }
7809
7810                                                                         XYZ temppos;
7811                                                                         for(j=0;j<numplayers; j++){
7812                                                                                 if(j!=closest){
7813                                                                                         if(findDistancefast(&player[j].coords,&player[closest].coords)<25){
7814                                                                                                 player[j].DoDamage((25-findDistancefast(&player[j].coords,&player[closest].coords))*60);
7815                                                                                                 if(player[j].skeleton.free==2)player[j].skeleton.free=1;
7816                                                                                                 player[j].skeleton.longdead=0;
7817                                                                                                 player[j].RagDoll(0);
7818                                                                                                 for(i=0;i<player[j].skeleton.num_joints; i++){
7819                                                                                                         temppos=player[j].skeleton.joints[i].position+player[j].coords;
7820                                                                                                         if(findDistancefast(&temppos,&player[closest].coords)<25){
7821                                                                                                                 flatvelocity2=temppos-player[closest].coords;
7822                                                                                                                 Normalise(&flatvelocity2);
7823                                                                                                                 player[j].skeleton.joints[i].velocity+=flatvelocity2*((20-findDistancefast(&temppos,&player[closest].coords))*20);
7824                                                                                                         }
7825                                                                                                 }
7826                                                                                         }
7827                                                                                 }
7828                                                                         }
7829
7830                                                                         player[closest].DoDamage(10000);
7831                                                                         player[closest].RagDoll(0);
7832                                                                         player[closest].dead=2;
7833                                                                         player[closest].coords=20;
7834                                                                         player[closest].skeleton.free=2;
7835
7836                                                                         camerashake+=.6;
7837
7838                                                                 }
7839
7840                                                                 explodetogglekeydown=1;
7841                                                 }
7842
7843                                                 if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
7844                                                         explodetogglekeydown=0;
7845                                                 }
7846
7847                                                 /*
7848                                                 if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
7849                                                 FILE                    *tfile;
7850                                                 //tfile=fopen( ":Data:Maps:mapsave", "wb" );
7851                                                 if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
7852                                                 else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
7853                                                 else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
7854                                                 else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
7855                                                 else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
7856                                                 else tfile=fopen( ":Data:Maps:mapsave", "wb" );
7857
7858                                                 fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
7859                                                 fwrite( &player[0].rotation, 1, sizeof(float), tfile );
7860                                                 fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
7861                                                 fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
7862                                                 for(j=0;j<player[0].num_weapons;j++){
7863                                                 fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
7864                                                 }
7865                                                 fwrite( &environment, 1, sizeof(int), tfile );
7866
7867                                                 fwrite( &objects.numobjects, 1, sizeof(int), tfile );
7868                                                 fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
7869                                                 fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
7870                                                 fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
7871                                                 fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
7872
7873                                                 fwrite( &numplayers, 1, sizeof(int), tfile );
7874                                                 if(numplayers>1&&numplayers<maxplayers)
7875                                                 for(i=1;i<numplayers;i++){
7876                                                 fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
7877                                                 fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
7878                                                 for(j=0;j<player[i].num_weapons;j++){
7879                                                 fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
7880                                                 }
7881                                                 if(player[i].numwaypoints<30){
7882                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7883                                                 fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
7884                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7885                                                 //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
7886                                                 }
7887                                                 else{
7888                                                 player[i].numwaypoints=0;
7889                                                 player[i].waypoint=0;
7890                                                 fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
7891                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7892                                                 fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
7893                                                 }
7894                                                 }
7895
7896                                                 fclose(tfile);
7897
7898                                                 slomotogglekeydown=1;
7899                                                 }*/
7900
7901                                                 if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
7902                                                         slomotogglekeydown=0;
7903                                                 }
7904
7905
7906                                                 if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
7907                                                         player[0].onfire=1-player[0].onfire;
7908                                                         if(player[0].onfire){
7909                                                                 player[0].CatchFire();
7910                                                         }
7911                                                         if(!player[0].onfire){
7912                                                                 float gLoc[3];
7913                                                                 float vel[3];
7914                                                                 gLoc[0]=player[0].coords.x;
7915                                                                 gLoc[1]=player[0].coords.y;
7916                                                                 gLoc[2]=player[0].coords.z;
7917                                                                 vel[0]=0;
7918                                                                 vel[1]=0;
7919                                                                 vel[2]=0;
7920                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
7921                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
7922                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
7923                                                                 OPENAL_SetPaused(channels[fireendsound], false);
7924                                                                 OPENAL_SetPaused(channels[stream_firesound], true);
7925                                                         }
7926                                                         slomotogglekeydown=1;
7927                                                 }
7928                                                 /*
7929                                                 if(IsKeyDown(theKeyMap, MAC_L_KEY)){
7930                                                 if(player[0].bleeding<=0)
7931                                                 player[0].DoBlood(1,255);
7932                                                 }*/
7933
7934
7935                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
7936                                                         int closest=-1;
7937                                                         float closestdist=-1;
7938                                                         float distance;
7939                                                         if(numplayers>1)
7940                                                                 for(i=1;i<numplayers;i++){
7941                                                                         distance=findDistancefast(&player[i].coords,&player[0].coords);
7942                                                                         if(closestdist==-1||distance<closestdist){
7943                                                                                 closestdist=distance;
7944                                                                                 closest=i;
7945                                                                         }
7946                                                                 }
7947                                                                 if(closestdist>0&&closest>=0){
7948                                                                         //player[closest]=player[numplayers-1];
7949                                                                         //player[closest].skeleton=player[numplayers-1].skeleton;
7950                                                                         numplayers--;
7951                                                                 }
7952                                                                 drawmodetogglekeydown=1;
7953                                                 }
7954
7955                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
7956                                                         int closest=-1;
7957                                                         float closestdist=-1;
7958                                                         float distance;
7959                                                         if(max_objects>1)
7960                                                                 for(i=1;i<max_objects;i++){
7961                                                                         distance=findDistancefast(&objects.position[i],&player[0].coords);
7962                                                                         if(closestdist==-1||distance<closestdist){
7963                                                                                 closestdist=distance;
7964                                                                                 closest=i;
7965                                                                         }
7966                                                                 }
7967                                                                 if(closestdist>0&&closest>=0){
7968                                                                         objects.position[closest].y-=500;
7969                                                                 }
7970                                                                 drawmodetogglekeydown=1;
7971                                                 }
7972
7973                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
7974                                                         //drawmode++;
7975                                                         //if(drawmode>2)drawmode=0;
7976                                                         if(objects.numobjects<max_objects-1){
7977                                                                 XYZ boxcoords;
7978                                                                 boxcoords.x=player[0].coords.x;
7979                                                                 boxcoords.z=player[0].coords.z;
7980                                                                 boxcoords.y=player[0].coords.y-3;
7981                                                                 if(editortype==bushtype)boxcoords.y=player[0].coords.y-.5;
7982                                                                 if(editortype==firetype)boxcoords.y=player[0].coords.y-.5;
7983                                                                 //objects.MakeObject(abs(Random()%3),boxcoords,Random()%360);
7984                                                                 float temprotat,temprotat2;
7985                                                                 temprotat=editorrotation;
7986                                                                 temprotat2=editorrotation2;
7987                                                                 if(temprotat<0||editortype==bushtype)temprotat=Random()%360;
7988                                                                 if(temprotat2<0)temprotat2=Random()%360;
7989
7990                                                                 objects.MakeObject(editortype,boxcoords,(int)temprotat-((int)temprotat)%30,(int)temprotat2,editorsize);
7991                                                                 if(editortype==treetrunktype)
7992                                                                         objects.MakeObject(treeleavestype,boxcoords,Random()%360*(temprotat2<2)+(int)editorrotation-((int)editorrotation)%30,editorrotation2,editorsize);
7993                                                         }
7994
7995                                                         drawmodetogglekeydown=1;
7996                                                 }
7997
7998                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
7999                                                         if(numplayers<maxplayers-1){
8000                                                                 player[numplayers].scale=.2*5*player[0].scale;
8001                                                                 player[numplayers].creature=rabbittype;
8002                                                                 player[numplayers].howactive=editoractive;
8003                                                                 player[numplayers].skeleton.id=numplayers;
8004                                                                 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);
8005
8006                                                                 //texsize=512*512*3/texdetail/texdetail;
8007                                                                 //if(!player[numplayers].loaded)player[numplayers].skeleton.skinText = new GLubyte[texsize];
8008                                                                 //player[numplayers].skeleton.skinText.resize(texsize);
8009
8010                                                                 k=abs(Random()%2)+1;
8011                                                                 if(k==0){
8012                                                                         LoadTextureSave(":Data:Textures:Fur3.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8013                                                                         player[numplayers].whichskin=0;
8014                                                                 }
8015                                                                 else if(k==1){
8016                                                                         LoadTextureSave(":Data:Textures:Fur.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8017                                                                         player[numplayers].whichskin=1;
8018                                                                 }
8019                                                                 else {
8020                                                                         LoadTextureSave(":Data:Textures:Fur2.jpg",&player[numplayers].skeleton.drawmodel.textureptr,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8021                                                                         player[numplayers].whichskin=2;
8022                                                                 }
8023
8024                                                                 LoadTexture(":Data:Textures:Belt.png",&player[numplayers].skeleton.drawmodelclothes.textureptr,1,1);
8025                                                                 player[numplayers].power=1;
8026                                                                 player[numplayers].speedmult=1;
8027                                                                 player[numplayers].currentanimation=bounceidleanim;
8028                                                                 player[numplayers].targetanimation=bounceidleanim;
8029                                                                 player[numplayers].currentframe=0;
8030                                                                 player[numplayers].targetframe=1;
8031                                                                 player[numplayers].target=0;
8032                                                                 player[numplayers].bled=0;
8033                                                                 player[numplayers].speed=1+(float)(Random()%100)/1000;
8034
8035                                                                 player[numplayers].targetrotation=player[0].targetrotation;
8036                                                                 player[numplayers].rotation=player[0].rotation;
8037
8038                                                                 player[numplayers].velocity=0;
8039                                                                 player[numplayers].coords=player[0].coords;
8040                                                                 player[numplayers].oldcoords=player[numplayers].coords;
8041                                                                 player[numplayers].realoldcoords=player[numplayers].coords;
8042
8043                                                                 player[numplayers].id=numplayers;
8044                                                                 player[numplayers].skeleton.id=numplayers;
8045                                                                 player[numplayers].updatedelay=0;
8046                                                                 player[numplayers].normalsupdatedelay=0;
8047
8048                                                                 player[numplayers].aitype=passivetype;
8049                                                                 player[numplayers].aitarget=0;
8050
8051                                                                 if(player[0].creature==wolftype){
8052                                                                         headprop=player[0].proportionhead.x/1.1;
8053                                                                         bodyprop=player[0].proportionbody.x/1.1;
8054                                                                         armprop=player[0].proportionarms.x/1.1;
8055                                                                         legprop=player[0].proportionlegs.x/1.1;
8056                                                                 }
8057
8058                                                                 if(player[0].creature==rabbittype){
8059                                                                         headprop=player[0].proportionhead.x/1.2;
8060                                                                         bodyprop=player[0].proportionbody.x/1.05;
8061                                                                         armprop=player[0].proportionarms.x/1.00;
8062                                                                         legprop=player[0].proportionlegs.x/1.1;
8063                                                                 }
8064
8065                                                                 if(player[numplayers].creature==wolftype){
8066                                                                         player[numplayers].proportionhead=1.1*headprop;
8067                                                                         player[numplayers].proportionbody=1.1*bodyprop;
8068                                                                         player[numplayers].proportionarms=1.1*armprop;
8069                                                                         player[numplayers].proportionlegs=1.1*legprop;
8070                                                                 }
8071
8072                                                                 if(player[numplayers].creature==rabbittype){
8073                                                                         player[numplayers].proportionhead=1.2*headprop;
8074                                                                         player[numplayers].proportionbody=1.05*bodyprop;
8075                                                                         player[numplayers].proportionarms=1.00*armprop;
8076                                                                         player[numplayers].proportionlegs=1.1*legprop;
8077                                                                         player[numplayers].proportionlegs.y=1.05*legprop;
8078                                                                 }
8079
8080                                                                 player[numplayers].headless=0;
8081                                                                 player[numplayers].onfire=0;
8082
8083                                                                 if(cellophane){
8084                                                                         player[numplayers].proportionhead.z=0;
8085                                                                         player[numplayers].proportionbody.z=0;
8086                                                                         player[numplayers].proportionarms.z=0;
8087                                                                         player[numplayers].proportionlegs.z=0;
8088                                                                 }
8089
8090                                                                 player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
8091
8092                                                                 player[numplayers].damagetolerance=200;
8093
8094                                                                 player[numplayers].protectionhead=player[0].protectionhead;
8095                                                                 player[numplayers].protectionhigh=player[0].protectionhigh;
8096                                                                 player[numplayers].protectionlow=player[0].protectionlow;
8097                                                                 player[numplayers].armorhead=player[0].armorhead;
8098                                                                 player[numplayers].armorhigh=player[0].armorhigh;
8099                                                                 player[numplayers].armorlow=player[0].armorlow;
8100                                                                 player[numplayers].metalhead=player[0].metalhead;
8101                                                                 player[numplayers].metalhigh=player[0].metalhigh;
8102                                                                 player[numplayers].metallow=player[0].metallow;
8103
8104                                                                 player[numplayers].immobile=player[0].immobile;
8105
8106                                                                 player[numplayers].numclothes=player[0].numclothes;
8107                                                                 if(player[numplayers].numclothes)
8108                                                                         for(i=0;i<player[numplayers].numclothes;i++){
8109                                                                                 strcpy(player[numplayers].clothes[i], player[0].clothes[i]);
8110                                                                                 player[numplayers].clothestintr[i]=player[0].clothestintr[i];
8111                                                                                 player[numplayers].clothestintg[i]=player[0].clothestintg[i];
8112                                                                                 player[numplayers].clothestintb[i]=player[0].clothestintb[i];
8113                                                                                 tintr=player[numplayers].clothestintr[i];
8114                                                                                 tintg=player[numplayers].clothestintg[i];
8115                                                                                 tintb=player[numplayers].clothestintb[i];
8116                                                                                 AddClothes((char *)player[numplayers].clothes[i],0,1,&player[numplayers].skeleton.skinText[0],&player[numplayers].skeleton.skinsize);
8117                                                                         }
8118                                                                         if(player[numplayers].numclothes){
8119                                                                                 player[numplayers].DoMipmaps(5,0,0,player[numplayers].skeleton.skinsize,player[numplayers].skeleton.skinsize);
8120                                                                         }
8121
8122                                                                         player[numplayers].power=player[0].power;
8123                                                                         player[numplayers].speedmult=player[0].speedmult;
8124
8125                                                                         player[numplayers].damage=0;
8126                                                                         player[numplayers].permanentdamage=0;
8127                                                                         player[numplayers].superpermanentdamage=0;
8128                                                                         player[numplayers].deathbleeding=0;
8129                                                                         player[numplayers].bleeding=0;
8130                                                                         player[numplayers].numwaypoints=0;
8131                                                                         player[numplayers].waypoint=0;
8132                                                                         player[numplayers].jumppath=0;
8133                                                                         player[numplayers].weaponstuck=-1;
8134                                                                         player[numplayers].weaponactive=-1;
8135                                                                         player[numplayers].num_weapons=0;
8136                                                                         player[numplayers].bloodloss=0;
8137                                                                         player[numplayers].dead=0;
8138
8139                                                                         player[numplayers].loaded=1;
8140
8141                                                                         numplayers++;
8142                                                         }
8143                                                         drawmodetogglekeydown=1;
8144                                                 }
8145
8146                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
8147                                                         if(player[numplayers-1].numwaypoints<90){
8148                                                                 player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
8149                                                                 player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
8150                                                                 player[numplayers-1].numwaypoints++;
8151                                                         }
8152                                                         drawmodetogglekeydown=1;
8153                                                 }
8154
8155                                                 if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
8156                                                         if(numpathpoints<30){
8157                                                                 bool connected,alreadyconnected;
8158                                                                 connected=0;
8159                                                                 if(numpathpoints>1)
8160                                                                         for(i=0;i<numpathpoints;i++){
8161                                                                                 if(findDistancefast(&pathpoint[i],&player[0].coords)<.5&&i!=pathpointselected&&!connected){
8162                                                                                         alreadyconnected=0;
8163                                                                                         for(j=0;j<numpathpointconnect[pathpointselected];j++){
8164                                                                                                 if(pathpointconnect[pathpointselected][j]==i)alreadyconnected=1;
8165                                                                                         }
8166                                                                                         if(!alreadyconnected){
8167                                                                                                 numpathpointconnect[pathpointselected]++;
8168                                                                                                 connected=1;
8169                                                                                                 pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=i;
8170                                                                                         }
8171                                                                                 }
8172                                                                         }
8173                                                                         if(!connected){
8174                                                                                 numpathpoints++;
8175                                                                                 pathpoint[numpathpoints-1]=player[0].coords;
8176                                                                                 numpathpointconnect[numpathpoints-1]=0;
8177                                                                                 if(numpathpoints>1&&pathpointselected!=-1){
8178                                                                                         numpathpointconnect[pathpointselected]++;
8179                                                                                         pathpointconnect[pathpointselected][numpathpointconnect[pathpointselected]-1]=numpathpoints-1;
8180                                                                                 }
8181                                                                                 pathpointselected=numpathpoints-1;
8182                                                                         }
8183                                                         }
8184                                                         drawmodetogglekeydown=1;
8185                                                 }
8186
8187                                                 if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
8188                                                         pathpointselected++;
8189                                                         if(pathpointselected>=numpathpoints)pathpointselected=-1;
8190                                                         drawmodetogglekeydown=1;
8191                                                 }
8192                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8193                                                         pathpointselected--;
8194                                                         if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
8195                                                         drawmodetogglekeydown=1;
8196                                                 }
8197                                                 if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
8198                                                         if(pathpointselected!=-1){
8199                                                                 numpathpoints--;
8200                                                                 pathpoint[pathpointselected]=pathpoint[numpathpoints];
8201                                                                 numpathpointconnect[pathpointselected]=numpathpointconnect[numpathpoints];
8202                                                                 for(i=0;i<numpathpointconnect[pathpointselected];i++){
8203                                                                         pathpointconnect[pathpointselected][i]=pathpointconnect[numpathpoints][i];
8204                                                                 }
8205                                                                 for(i=0;i<numpathpoints;i++){
8206                                                                         for(j=0;j<numpathpointconnect[i];j++){
8207                                                                                 if(pathpointconnect[i][j]==pathpointselected){
8208                                                                                         pathpointconnect[i][j]=pathpointconnect[i][numpathpointconnect[i]-1];
8209                                                                                         numpathpointconnect[i]--;
8210                                                                                 }
8211                                                                                 if(pathpointconnect[i][j]==numpathpoints){
8212                                                                                         pathpointconnect[i][j]=pathpointselected;
8213                                                                                 }
8214                                                                         }
8215                                                                 }
8216                                                                 pathpointselected=numpathpoints-1;
8217                                                         }
8218                                                         drawmodetogglekeydown=1;
8219                                                 }
8220
8221                                                 if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
8222                                                         editorenabled=1-editorenabled;
8223                                                         if(editorenabled){
8224                                                                 player[0].damagetolerance=100000;
8225                                                                 player[0].damage=0;
8226                                                                 player[0].superpermanentdamage=0;
8227                                                                 player[0].bloodloss=0;
8228                                                                 player[0].deathbleeding=0;
8229                                                         }
8230                                                         if(!editorenabled){
8231                                                                 player[0].damagetolerance=200;
8232                                                                 player[0].damage=0;
8233                                                                 player[0].permanentdamage=0;
8234                                                                 player[0].superpermanentdamage=0;
8235                                                                 player[0].bloodloss=0;
8236                                                                 player[0].deathbleeding=0;
8237                                                         }
8238                                                         drawmodetogglekeydown=1;
8239                                                 }
8240
8241                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8242                                                         editortype--;
8243                                                         if(editortype==treeleavestype||editortype==10)editortype--;
8244                                                         if(editortype<0)editortype=firetype;
8245                                                         drawmodetogglekeydown=1;
8246                                                 }
8247
8248                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8249                                                         editortype++;
8250                                                         if(editortype==treeleavestype||editortype==10)editortype++;
8251                                                         if(editortype>firetype)editortype=0;
8252                                                         drawmodetogglekeydown=1;
8253                                                 }
8254
8255                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8256                                                         editorrotation-=multiplier*100;
8257                                                         if(editorrotation<-.01)editorrotation=-.01;
8258                                                         drawmodetogglekeydown=1;
8259                                                 }
8260
8261                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8262                                                         editorrotation+=multiplier*100;
8263                                                         drawmodetogglekeydown=1;
8264                                                 }
8265
8266                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8267                                                         editorsize+=multiplier;
8268                                                         drawmodetogglekeydown=1;
8269                                                 }
8270
8271                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8272                                                         editorsize-=multiplier;
8273                                                         if(editorsize<.1)editorsize=.1;
8274                                                         drawmodetogglekeydown=1;
8275                                                 }
8276
8277
8278                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8279                                                         mapradius-=multiplier*10;
8280                                                 }
8281
8282                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8283                                                         mapradius+=multiplier*10;
8284                                                 }
8285                                                 /*
8286                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8287                                                 mapcenter.x+=multiplier*20;
8288                                                 }
8289
8290                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8291                                                 mapcenter.x-=multiplier*20;
8292                                                 }
8293
8294                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8295                                                 mapcenter.z+=multiplier*20;
8296                                                 }
8297
8298                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8299                                                 mapcenter.z-=multiplier*20;
8300                                                 }
8301                                                 */
8302                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8303                                                         editorrotation2+=multiplier*100;
8304                                                 }
8305
8306                                                 if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
8307                                                         editorrotation2-=multiplier*100;
8308                                                         if(editorrotation2<-.01)editorrotation2=-.01;
8309                                                 }
8310                                                 if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
8311                                                         int closest=-1;
8312                                                         float closestdist=-1;
8313                                                         float distance;
8314                                                         for(i=0;i<objects.numobjects;i++){
8315                                                                 distance=findDistancefast(&objects.position[i],&player[0].coords);
8316                                                                 if(closestdist==-1||distance<closestdist){
8317                                                                         closestdist=distance;
8318                                                                         closest=i;
8319                                                                 }
8320                                                         }
8321                                                         if(closestdist>0&&closest>=0)objects.DeleteObject(closest);
8322                                                         drawmodetogglekeydown=1;
8323                                                 }
8324
8325
8326                                                 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)){
8327                                                         drawmodetogglekeydown=0;
8328                                                 }
8329
8330                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8331                                                         //if(!player[0].skeleton.free)player[0].damage+=500;
8332                                                         player[0].RagDoll(0);
8333                                                         //player[0].spurt=1;
8334                                                         //player[0].DoDamage(1000);
8335
8336                                                         float gLoc[3];
8337                                                         float vel[3];
8338                                                         gLoc[0]=player[0].coords.x;
8339                                                         gLoc[1]=player[0].coords.y;
8340                                                         gLoc[2]=player[0].coords.z;
8341                                                         vel[0]=player[0].velocity.x;
8342                                                         vel[1]=player[0].velocity.y;
8343                                                         vel[2]=player[0].velocity.z;
8344                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
8345                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
8346                                                         OPENAL_SetVolume(channels[whooshsound], 128);
8347                                                         OPENAL_SetPaused(channels[whooshsound], false);
8348                                                         //OPENAL_SetPaused(channels[whooshsound], true);
8349
8350                                                         texturesizetogglekeydown=1;
8351                                                 }
8352
8353                                                 if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
8354
8355                                                         int closest=-1;
8356                                                         float closestdist=-1;
8357                                                         float distance;
8358                                                         for(i=0;i<objects.numobjects;i++){
8359                                                                 if(objects.type[i]==treeleavestype){
8360                                                                         objects.scale[i]*=.9;
8361                                                                 }
8362                                                         }
8363                                                         texturesizetogglekeydown=1;
8364                                                 }
8365
8366                                                 static XYZ relative;
8367                                                 static int randattack;
8368                                                 //Attack
8369                                                 static bool playerrealattackkeydown=0;
8370
8371                                                 if(!buttons[0])oldbutton=0;
8372                                                 if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
8373                                                 if(oldattackkey)player[0].attackkeydown=0;
8374                                                 if(oldattackkey)playerrealattackkeydown=0;
8375                                                 if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
8376                                                 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);
8377                                                 if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
8378                                                         for(k=0;k<numplayers;k++){
8379                                                                 if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
8380                                                                         player[k].Reverse();
8381                                                         }
8382                                                 }
8383
8384                                                 if(!hostile||indialogue!=-1)player[0].attackkeydown=0;
8385
8386                                                 for(k=0;k<numplayers;k++){
8387                                                         if(indialogue!=-1)player[k].attackkeydown=0;
8388                                                         if(player[k].targetanimation!=rabbitrunninganim&&player[k].targetanimation!=wolfrunninganim){
8389                                                                 if(player[k].aitype!=playercontrolled)player[k].victim=&player[0];
8390                                                                 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)){
8391                                                                         player[k].jumppower-=2;
8392                                                                 }
8393                                                                 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)){
8394                                                                         for(i=0;i<numplayers;i++){
8395                                                                                 if(i==k)i++;
8396                                                                                 if(player[i].targetanimation==swordslashanim||player[i].targetanimation==knifeslashstartanim||player[i].targetanimation==staffhitanim||player[i].targetanimation==staffspinhitanim)
8397                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<6.5&&!player[i].skeleton.free){
8398                                                                                                 player[k].targetanimation=dodgebackanim;
8399                                                                                                 player[k].target=0;
8400                                                                                                 player[k].targetframe=0;
8401                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8402                                                                                                 Normalise(&rotatetarget);
8403                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8404                                                                                                 player[k].targetrotation*=360/6.28;
8405                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8406
8407                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;
8408                                                                                         }
8409                                                                         }
8410                                                                         if(player[k].targetanimation!=dodgebackanim){
8411                                                                                 if(k==0)numflipped++;
8412                                                                                 player[k].targetanimation=backhandspringanim;
8413                                                                                 player[k].target=0;
8414                                                                                 player[k].targetframe=0;
8415                                                                                 player[k].targetrotation=-rotation+180;
8416                                                                                 if(player[k].leftkeydown)player[k].targetrotation-=45;
8417                                                                                 if(player[k].rightkeydown)player[k].targetrotation+=45;
8418                                                                                 player[k].rotation=player[k].targetrotation;
8419                                                                                 player[k].jumppower-=2;
8420                                                                         }
8421                                                                 }
8422                                                                 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())){
8423                                                                         player[k].hasvictim=0;
8424                                                                         if(numplayers>1)
8425                                                                                 for(i=0;i<numplayers;i++){
8426                                                                                         if(i==k)i++;
8427                                                                                         if(!player[k].hasvictim)
8428                                                                                                 if((k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack!=reversal){
8429                                                                                                         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){
8430                                                                                                                 player[k].victim=&player[i];
8431                                                                                                                 player[k].hasvictim=1;
8432                                                                                                                 if(player[k].aitype==playercontrolled){
8433                                                                                                                         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;
8434                                                                                                                         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;
8435                                                                                                                         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;
8436                                                                                                                         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;
8437                                                                                                                         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;
8438                                                                                                                         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;
8439                                                                                                                         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;
8440                                                                                                                         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;
8441                                                                                                                         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;
8442                                                                                                                         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;
8443                                                                                                                 }
8444                                                                                                                 else {
8445                                                                                                                         if(findDistancefast(&player[k].coords,&player[i].coords)<4.5*(player[k].scale*5)*(player[k].scale*5)){
8446                                                                                                                                 if(player[k].weaponactive==-1)randattack=abs(Random()%5);
8447                                                                                                                                 else randattack=abs(Random()%5);
8448                                                                                                                                 if(player[k].weaponactive==-1&&findDistancefast(&player[k].coords,&player[i].coords)<2.5*(player[k].scale*5)*(player[k].scale*5)){
8449                                                                                                                                         if(randattack==0&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=sweepanim;
8450                                                                                                                                         else if(randattack==1&&animation[player[i].targetanimation].height!=lowheight&&player[k].weaponactive==-1)player[k].targetanimation=upunchanim;
8451                                                                                                                                         else if(randattack==2&&animation[player[i].targetanimation].height!=lowheight)player[k].targetanimation=spinkickanim;
8452                                                                                                                                         else if(animation[player[i].targetanimation].height==lowheight)player[k].targetanimation=lowkickanim;
8453                                                                                                                                 }
8454                                                                                                                                 if(player[k].weaponactive!=-1){
8455                                                                                                                                         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;
8456                                                                                                                                         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;
8457                                                                                                                                         //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;
8458                                                                                                                                         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;
8459                                                                                                                                         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;
8460                                                                                                                                         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;
8461                                                                                                                                         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;
8462                                                                                                                                         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;
8463                                                                                                                                 }
8464                                                                                                                         }
8465                                                                                                                 }
8466                                                                                                                 if(player[k].targetanimation==upunchanim&&player[k].creature==wolftype)player[k].targetanimation=wolfslapanim;
8467                                                                                                         }
8468                                                                                                         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)){
8469                                                                                                                 if(player[k].weaponactive==-1){
8470                                                                                                                         player[i].targetanimation=sneakattackedanim;
8471                                                                                                                         player[i].currentanimation=sneakattackedanim;
8472                                                                                                                         player[k].currentanimation=sneakattackanim;
8473                                                                                                                         player[k].targetanimation=sneakattackanim;
8474                                                                                                                         player[k].oldcoords=player[k].coords;
8475                                                                                                                         player[k].coords=player[i].coords;
8476                                                                                                                 }
8477                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==knife){
8478                                                                                                                         player[i].targetanimation=knifesneakattackedanim;
8479                                                                                                                         player[i].currentanimation=knifesneakattackedanim;
8480                                                                                                                         player[k].currentanimation=knifesneakattackanim;
8481                                                                                                                         player[k].targetanimation=knifesneakattackanim;
8482                                                                                                                         player[i].oldcoords=player[i].coords;
8483                                                                                                                         player[i].coords=player[k].coords;
8484                                                                                                                 }
8485                                                                                                                 if(player[k].weaponactive!=-1&&weapons.type[player[k].weaponids[player[k].weaponactive]]==sword){
8486                                                                                                                         player[i].targetanimation=swordsneakattackedanim;
8487                                                                                                                         player[i].currentanimation=swordsneakattackedanim;
8488                                                                                                                         player[k].currentanimation=swordsneakattackanim;
8489                                                                                                                         player[k].targetanimation=swordsneakattackanim;
8490                                                                                                                         player[i].oldcoords=player[i].coords;
8491                                                                                                                         player[i].coords=player[k].coords;
8492                                                                                                                 }
8493                                                                                                                 if(player[k].weaponactive==-1||weapons.type[player[k].weaponids[player[k].weaponactive]]!=staff){
8494                                                                                                                         player[k].victim=&player[i];
8495                                                                                                                         player[k].hasvictim=1;
8496                                                                                                                         player[i].targettilt2=0;
8497                                                                                                                         player[i].targetframe=1;
8498                                                                                                                         player[i].currentframe=0;
8499                                                                                                                         player[i].target=0;
8500                                                                                                                         player[i].velocity=0;
8501                                                                                                                         player[k].targettilt2=player[i].targettilt2;
8502                                                                                                                         player[k].currentframe=player[i].currentframe;
8503                                                                                                                         player[k].targetframe=player[i].targetframe;
8504                                                                                                                         player[k].target=player[i].target;
8505                                                                                                                         player[k].velocity=0;
8506                                                                                                                         player[k].targetrotation=player[i].rotation;
8507                                                                                                                         player[k].rotation=player[i].rotation;
8508                                                                                                                         player[i].targetrotation=player[i].rotation;
8509                                                                                                                 }
8510                                                                                                         }
8511                                                                                                         if(animation[player[k].targetanimation].attack==normalattack&&player[k].victim==&player[i]&&(!player[i].skeleton.free)){
8512                                                                                                                 oldattackkey=1;
8513                                                                                                                 player[k].targetframe=0;
8514                                                                                                                 player[k].target=0;
8515                                                                                                                 //player[k].velocity=0;
8516
8517                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8518                                                                                                                 Normalise(&rotatetarget);
8519                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8520                                                                                                                 player[k].targetrotation*=360/6.28;
8521                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8522
8523                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8524
8525                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8526                                                                                                                 player[k].lastattack2=player[k].lastattack;
8527                                                                                                                 player[k].lastattack=player[k].targetanimation;
8528                                                                                                                 //player[k].targettilt2=0;
8529                                                                                                                 //slomo=1;
8530                                                                                                                 //slomodelay=.2;
8531                                                                                                         }
8532                                                                                                         if(player[k].targetanimation==knifefollowanim&&player[k].victim==&player[i]){
8533                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8534                                                                                                                 Normalise(&rotatetarget);
8535                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8536                                                                                                                 player[k].targetrotation*=360/6.28;
8537                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8538                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8539                                                                                                                 oldattackkey=1;
8540                                                                                                                 player[k].victim=&player[i];
8541                                                                                                                 player[k].hasvictim=1;
8542                                                                                                                 player[i].targetanimation=knifefollowedanim;
8543                                                                                                                 player[i].currentanimation=knifefollowedanim;
8544                                                                                                                 player[i].targettilt2=0;
8545                                                                                                                 player[i].targettilt2=player[k].targettilt2;
8546                                                                                                                 player[i].targetframe=1;
8547                                                                                                                 player[i].currentframe=0;
8548                                                                                                                 player[i].target=0;
8549                                                                                                                 player[i].velocity=0;
8550                                                                                                                 player[k].currentanimation=knifefollowanim;
8551                                                                                                                 player[k].targetanimation=knifefollowanim;
8552                                                                                                                 player[k].targettilt2=player[i].targettilt2;
8553                                                                                                                 player[k].currentframe=player[i].currentframe;
8554                                                                                                                 player[k].targetframe=player[i].targetframe;
8555                                                                                                                 player[k].target=player[i].target;
8556                                                                                                                 player[k].velocity=0;
8557                                                                                                                 player[k].oldcoords=player[k].coords;
8558                                                                                                                 player[i].coords=player[k].coords;
8559                                                                                                                 player[i].targetrotation=player[k].targetrotation;
8560                                                                                                                 player[i].rotation=player[k].targetrotation;
8561                                                                                                                 player[k].rotation=player[k].targetrotation;
8562                                                                                                                 player[i].rotation=player[k].targetrotation;
8563                                                                                                         }
8564                                                                                                 }
8565                                                                                 }
8566                                                                                 bool hasstaff=0;
8567                                                                                 if(player[k].weaponactive!=-1){
8568                                                                                         if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)hasstaff=1;
8569                                                                                 }
8570                                                                                 if(numplayers>1)
8571                                                                                         for(i=0;i<numplayers;i++){
8572                                                                                                 if(i==k)i++;
8573                                                                                                 if((playerrealattackkeydown||player[i].dead||!hasstaff)&&(k==0||i==0)&&i!=k&&i<numplayers&&k<numplayers&&animation[player[k].targetanimation].attack==neutral&&k==0){
8574                                                                                                         if(!player[i].dead||!realthreat||(player[k].weaponactive==-1&&player[k].crouchkeydown))
8575                                                                                                                 if(player[i].skeleton.free)
8576                                                                                                                         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)))){
8577                                                                                                                                 player[k].victim=&player[i];
8578                                                                                                                                 player[k].hasvictim=1;
8579                                                                                                                                 if(player[k].weaponactive!=-1&&tutoriallevel!=1){
8580                                                                                                                                         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;
8581                                                                                                                                         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;
8582                                                                                                                                         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;
8583                                                                                                                                 }
8584                                                                                                                                 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){
8585                                                                                                                                         player[k].targetanimation=killanim;
8586                                                                                                                                         for(j=0;j<terrain.numdecals;j++){
8587                                                                                                                                                 if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8588                                                                                                                                                         terrain.DeleteDecal(j);
8589                                                                                                                                                 }
8590                                                                                                                                         }
8591                                                                                                                                         for(l=0;l<objects.numobjects;l++){
8592                                                                                                                                                 if(objects.model[l].type==decalstype)
8593                                                                                                                                                         for(j=0;j<objects.model[l].numdecals;j++){
8594                                                                                                                                                                 if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8595                                                                                                                                                                         objects.model[l].DeleteDecal(j);
8596                                                                                                                                                                 }
8597                                                                                                                                                         }
8598                                                                                                                                         }
8599                                                                                                                                 }
8600                                                                                                                                 if(!player[i].dead||musictype!=2)
8601                                                                                                                                         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)){
8602                                                                                                                                                 player[k].targetanimation=dropkickanim;
8603                                                                                                                                                 for(j=0;j<terrain.numdecals;j++){
8604                                                                                                                                                         if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&terrain.decalalivetime[j]<2){
8605                                                                                                                                                                 terrain.DeleteDecal(j);
8606                                                                                                                                                         }
8607                                                                                                                                                 }
8608                                                                                                                                                 for(l=0;l<objects.numobjects;l++){
8609                                                                                                                                                         if(objects.model[l].type==decalstype)
8610                                                                                                                                                                 for(j=0;j<objects.model[l].numdecals;j++){
8611                                                                                                                                                                         if((objects.model[l].decaltype[j]==blooddecal||objects.model[l].decaltype[j]==blooddecalslow)&&objects.model[l].decalalivetime[j]<2){
8612                                                                                                                                                                                 objects.model[l].DeleteDecal(j);
8613                                                                                                                                                                         }
8614                                                                                                                                                                 }
8615                                                                                                                                                 }
8616                                                                                                                                         }
8617                                                                                                                         }
8618                                                                                                                         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)){
8619                                                                                                                                 oldattackkey=1;
8620                                                                                                                                 player[k].targetframe=0;
8621                                                                                                                                 player[k].target=0;
8622                                                                                                                                 //player[k].velocity=0;
8623
8624                                                                                                                                 rotatetarget=player[i].coords-player[k].coords;
8625                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim||player[k].targetanimation==staffgroundsmashanim){
8626                                                                                                                                         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;
8627                                                                                                                                 }
8628                                                                                                                                 Normalise(&rotatetarget);
8629                                                                                                                                 player[k].targetrotation=-asin(0-rotatetarget.x);
8630                                                                                                                                 player[k].targetrotation*=360/6.28;
8631                                                                                                                                 if(rotatetarget.z<0)player[k].targetrotation=180-player[k].targetrotation;
8632
8633                                                                                                                                 if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
8634                                                                                                                                         player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
8635                                                                                                                                 }
8636
8637                                                                                                                                 player[k].targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
8638                                                                                                                                 if(player[k].targetanimation==staffgroundsmashanim)player[k].targettilt2+=10;
8639
8640                                                                                                                                 player[k].lastattack3=player[k].lastattack2;
8641                                                                                                                                 player[k].lastattack2=player[k].lastattack;
8642                                                                                                                                 player[k].lastattack=player[k].targetanimation;
8643
8644                                                                                                                                 if(player[k].targetanimation==swordgroundstabanim){
8645                                                                                                                                         player[k].targetrotation+=30;
8646                                                                                                                                 }
8647                                                                                                                                 //player[k].targettilt2=0;
8648                                                                                                                                 //slomo=1;
8649                                                                                                                                 //slomodelay=.2;
8650                                                                                                                         }
8651                                                                                                 }
8652                                                                                         }
8653                                                                                         if(!player[k].hasvictim){
8654                                                                                                 for(i=0;i<numplayers;i++){
8655                                                                                                         if((player[k].hasvictim==0)&&i!=k&&(i==0||k==0)&&!player[i].skeleton.free){
8656                                                                                                                 player[k].victim=&player[i];
8657                                                                                                                 player[k].hasvictim=1;
8658                                                                                                         }
8659                                                                                                         if(player[k].hasvictim&&!player[i].skeleton.free)
8660                                                                                                                 if(findDistancefast(&player[k].coords,&player[i].coords)<findDistancefast(&player[k].coords,&player[k].victim->coords)&&i!=k&&(i==0||k==0)){
8661                                                                                                                         player[k].victim=&player[i];
8662                                                                                                                 }
8663                                                                                                 }
8664                                                                                         }
8665                                                                                         if(player[k].aitype==playercontrolled)
8666                                                                                                 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)){
8667                                                                                                         oldattackkey=1;
8668                                                                                                         player[k].targetanimation=rabbitkickanim;
8669                                                                                                         player[k].targetframe=0;
8670                                                                                                         player[k].target=0;
8671                                                                                                 }
8672                                                                                                 if(animation[player[k].targetanimation].attack&&k==0){
8673                                                                                                         numattacks++;
8674                                                                                                         bool armedstaff=0;
8675                                                                                                         if(player[k].weaponactive!=-1){
8676                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==staff)armedstaff=1;
8677                                                                                                         }
8678                                                                                                         bool armedsword=0;
8679                                                                                                         if(player[k].weaponactive!=-1){
8680                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==sword)armedsword=1;
8681                                                                                                         }
8682                                                                                                         bool armedknife=0;
8683                                                                                                         if(player[k].weaponactive!=-1){
8684                                                                                                                 if(weapons.type[player[k].weaponids[player[k].weaponactive]]==knife)armedknife=1;
8685                                                                                                         }
8686                                                                                                         if(armedstaff)numstaffattack++;
8687                                                                                                         else if(armedsword)numswordattack++;
8688                                                                                                         else if(armedknife)numknifeattack++;
8689                                                                                                         else numunarmedattack++;
8690                                                                                                 }
8691                                                                 }
8692                                                         }
8693                                                 }
8694
8695                                                 //Collisions
8696                                                 static float collisionradius;
8697                                                 if(numplayers>1)
8698                                                         for(k=0;k<numplayers;k++){
8699                                                                 for(i=k;i<numplayers;i++){
8700                                                                         if(i==k)i++;
8701                                                                         if(i<numplayers)
8702                                                                                 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))
8703                                                                                         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))
8704                                                                                                 if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
8705                                                                                                         if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
8706                                                                                                                 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)
8707                                                                                                                         if(player[i].coords.y>player[k].coords.y-3)
8708                                                                                                                                 if(player[i].coords.y<player[k].coords.y+3)
8709                                                                                                                                         if(player[i].coords.x>player[k].coords.x-3)
8710                                                                                                                                                 if(player[i].coords.x<player[k].coords.x+3)
8711                                                                                                                                                         if(player[i].coords.z>player[k].coords.z-3)
8712                                                                                                                                                                 if(player[i].coords.z<player[k].coords.z+3){
8713                                                                                                                                                                         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)){
8714                                                                                                                                                                                 if(player[i].onfire||player[k].onfire){
8715                                                                                                                                                                                         if(!player[i].onfire)player[i].CatchFire();
8716                                                                                                                                                                                         if(!player[k].onfire)player[k].CatchFire();
8717                                                                                                                                                                                 }
8718                                                                                                                                                                         }
8719
8720                                                                                                                                                                         tempcoords1=player[i].coords;
8721                                                                                                                                                                         tempcoords2=player[k].coords;
8722                                                                                                                                                                         if(!player[i].skeleton.oldfree)tempcoords1.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[abdomen]].position.y*player[i].scale;
8723                                                                                                                                                                         if(!player[k].skeleton.oldfree)tempcoords2.y+=player[k].skeleton.joints[player[k].skeleton.jointlabels[abdomen]].position.y*player[k].scale;
8724                                                                                                                                                                         collisionradius=1.2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8725                                                                                                                                                                         if(player[0].hasvictim)
8726                                                                                                                                                                                 if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)collisionradius=3;
8727                                                                                                                                                                         if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&(findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
8728                                                                                                                                                                                 if(k==0)
8729                                                                                                                                                                                         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)){
8730                                                                                                                                                                                                 player[k].coords.y=player[i].coords.y;
8731                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8732                                                                                                                                                                                                 player[i].skeleton.free=0;
8733                                                                                                                                                                                                 player[i].rotation=0;
8734                                                                                                                                                                                                 player[i].RagDoll(0);
8735                                                                                                                                                                                                 player[i].DoDamage(20);
8736                                                                                                                                                                                                 if(k==0)camerashake+=.3;
8737                                                                                                                                                                                                 player[i].skeleton.longdead=0;
8738                                                                                                                                                                                                 player[k].lastcollide=1;
8739                                                                                                                                                                                         }
8740                                                                                                                                                                                         if(i==0)
8741                                                                                                                                                                                                 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)){
8742                                                                                                                                                                                                         player[i].coords.y=player[k].coords.y;
8743                                                                                                                                                                                                         player[k].velocity=player[i].velocity;
8744                                                                                                                                                                                                         player[k].skeleton.free=0;
8745                                                                                                                                                                                                         player[k].rotation=0;
8746                                                                                                                                                                                                         player[k].RagDoll(0);
8747                                                                                                                                                                                                         player[k].DoDamage(20);
8748                                                                                                                                                                                                         if(i==0)camerashake+=.3;
8749                                                                                                                                                                                                         player[k].skeleton.longdead=0;
8750                                                                                                                                                                                                         player[i].lastcollide=1;
8751                                                                                                                                                                                                 }
8752
8753                                                                                                                                                                                                 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)){
8754                                                                                                                                                                                                         rotatetarget=player[k].velocity-player[i].velocity;
8755                                                                                                                                                                                                         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))
8756                                                                                                                                                                                                                 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))){
8757                                                                                                                                                                                                                         //If hit by body
8758                                                                                                                                                                                                                         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)){
8759                                                                                                                                                                                                                                 static float gLoc[3];
8760                                                                                                                                                                                                                                 static float vel[3];
8761                                                                                                                                                                                                                                 gLoc[0]=player[i].coords.x;
8762                                                                                                                                                                                                                                 gLoc[1]=player[i].coords.y;
8763                                                                                                                                                                                                                                 gLoc[2]=player[i].coords.z;
8764                                                                                                                                                                                                                                 vel[0]=player[i].velocity.x;
8765                                                                                                                                                                                                                                 vel[1]=player[i].velocity.y;
8766                                                                                                                                                                                                                                 vel[2]=player[i].velocity.z;
8767                                                                                                                                                                                                                                 if(tutoriallevel!=1){
8768                                                                                                                                                                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
8769                                                                                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
8770                                                                                                                                                                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 256);
8771                                                                                                                                                                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
8772                                                                                                                                                                                                                                 }
8773                                                                                                                                                                                                                                 //player[i].velocity=player[k].velocity;
8774                                                                                                                                                                                                                                 //player[k].velocity=player[i].velocity;
8775
8776                                                                                                                                                                                                                                 player[i].RagDoll(0);
8777                                                                                                                                                                                                                                 if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
8778                                                                                                                                                                                                                                         bonus=aimbonus;
8779                                                                                                                                                                                                                                         bonustime=0;
8780                                                                                                                                                                                                                                         bonusvalue=150;
8781                                                                                                                                                                                                                                 }
8782                                                                                                                                                                                                                                 player[i].DoDamage(findLengthfast(&rotatetarget)/4);
8783                                                                                                                                                                                                                                 player[k].RagDoll(0);
8784                                                                                                                                                                                                                                 if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
8785                                                                                                                                                                                                                                         bonus=aimbonus;
8786                                                                                                                                                                                                                                         bonustime=0;
8787                                                                                                                                                                                                                                         bonusvalue=150;
8788                                                                                                                                                                                                                                 }
8789                                                                                                                                                                                                                                 player[k].DoDamage(findLengthfast(&rotatetarget)/4);
8790
8791                                                                                                                                                                                                                                 //if(player[i].skeleton.oldfree){
8792                                                                                                                                                                                                                                 for(j=0;j<player[i].skeleton.num_joints;j++){
8793                                                                                                                                                                                                                                         player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
8794                                                                                                                                                                                                                                 }
8795                                                                                                                                                                                                                                 //}
8796                                                                                                                                                                                                                                 //if(player[k].skeleton.oldfree){
8797                                                                                                                                                                                                                                 for(j=0;j<player[k].skeleton.num_joints;j++){
8798                                                                                                                                                                                                                                         player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
8799                                                                                                                                                                                                                                 }
8800                                                                                                                                                                                                                                 //}
8801
8802                                                                                                                                                                                                                         }
8803                                                                                                                                                                                                                 }
8804                                                                                                                                                                                                                 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)){
8805                                                                                                                                                                                                                         //If bumped
8806                                                                                                                                                                                                                         if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
8807                                                                                                                                                                                                                                 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)){
8808                                                                                                                                                                                                                                         rotatetarget=player[k].coords-player[i].coords;
8809                                                                                                                                                                                                                                         Normalise(&rotatetarget);
8810                                                                                                                                                                                                                                         player[k].coords=(player[k].coords+player[i].coords)/2;
8811                                                                                                                                                                                                                                         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);
8812                                                                                                                                                                                                                                         player[k].coords+=rotatetarget*fast_sqrt(.6)/2*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5);
8813                                                                                                                                                                                                                                         if(player[k].howactive==typeactive||hostile)
8814                                                                                                                                                                                                                                                 if(player[k].isIdle()){
8815                                                                                                                                                                                                                                                         if(player[k].howactive<typesleeping){
8816                                                                                                                                                                                                                                                                 player[k].targetanimation=player[k].getStop();
8817                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8818                                                                                                                                                                                                                                                                 player[k].target=0;
8819                                                                                                                                                                                                                                                         }
8820                                                                                                                                                                                                                                                         else if(player[k].howactive==typesleeping)
8821                                                                                                                                                                                                                                                         {
8822                                                                                                                                                                                                                                                                 player[k].targetanimation=getupfromfrontanim;
8823                                                                                                                                                                                                                                                                 player[k].targetframe=0;
8824                                                                                                                                                                                                                                                                 player[k].target=0;
8825                                                                                                                                                                                                                                                         }
8826                                                                                                                                                                                                                                                         if(!editorenabled)player[k].howactive=typeactive;
8827                                                                                                                                                                                                                                                 }
8828                                                                                                                                                                                                                                                 if(player[i].howactive==typeactive||hostile)
8829                                                                                                                                                                                                                                                         if(player[i].isIdle()){
8830                                                                                                                                                                                                                                                                 if(player[i].howactive<typesleeping){
8831                                                                                                                                                                                                                                                                         player[i].targetanimation=player[i].getStop();
8832                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8833                                                                                                                                                                                                                                                                         player[i].target=0;
8834                                                                                                                                                                                                                                                                 }
8835                                                                                                                                                                                                                                                                 else
8836                                                                                                                                                                                                                                                                 {
8837                                                                                                                                                                                                                                                                         player[i].targetanimation=getupfromfrontanim;
8838                                                                                                                                                                                                                                                                         player[i].targetframe=0;
8839                                                                                                                                                                                                                                                                         player[i].target=0;
8840                                                                                                                                                                                                                                                                 }
8841                                                                                                                                                                                                                                                                 if(!editorenabled)player[i].howactive=typeactive;
8842                                                                                                                                                                                                                                                         }
8843                                                                                                                                                                                                                                 }
8844                                                                                                                                                                                                                                 if(hostile){
8845                                                                                                                                                                                                                                         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){
8846                                                                                                                                                                                                                                                 player[i].velocity=player[k].velocity;
8847                                                                                                                                                                                                                                                 player[k].velocity=player[k].velocity*-.5;
8848                                                                                                                                                                                                                                                 //player[i].velocity.y-=10;
8849                                                                                                                                                                                                                                                 player[k].velocity.y=player[i].velocity.y;
8850                                                                                                                                                                                                                                                 player[i].DoDamage(20);
8851                                                                                                                                                                                                                                                 player[i].RagDoll(0);
8852                                                                                                                                                                                                                                                 player[k].lastcollide=1;
8853                                                                                                                                                                                                                                                 if(k==0){
8854                                                                                                                                                                                                                                                         bonus=AboveBonus;
8855                                                                                                                                                                                                                                                         bonustime=0;
8856                                                                                                                                                                                                                                                         bonusvalue=50;
8857                                                                                                                                                                                                                                                 }
8858                                                                                                                                                                                                                                         }
8859                                                                                                                                                                                                                                         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){
8860                                                                                                                                                                                                                                                 player[k].velocity=player[i].velocity;
8861                                                                                                                                                                                                                                                 player[i].velocity=player[i].velocity*-.3;
8862                                                                                                                                                                                                                                                 //player[k].velocity.y-=10;
8863                                                                                                                                                                                                                                                 player[i].velocity.y=player[k].velocity.y;
8864                                                                                                                                                                                                                                                 player[k].DoDamage(20);
8865                                                                                                                                                                                                                                                 player[k].RagDoll(0);
8866                                                                                                                                                                                                                                                 player[i].lastcollide=1;
8867                                                                                                                                                                                                                                                 if(i==0){
8868                                                                                                                                                                                                                                                         bonus=AboveBonus;
8869                                                                                                                                                                                                                                                         bonustime=0;
8870                                                                                                                                                                                                                                                         bonusvalue=50;
8871                                                                                                                                                                                                                                                 }
8872                                                                                                                                                                                                                                         }
8873                                                                                                                                                                                                                                 }
8874                                                                                                                                                                                                                         }
8875                                                                                                                                                                                                                 }
8876                                                                                                                                                                                                 }
8877                                                                                                                                                                                                 player[i].CheckKick();
8878                                                                                                                                                                                                 player[k].CheckKick();
8879                                                                                                                                                                         }
8880                                                                                                                                                                 }
8881                                                                 }
8882                                                         }
8883
8884                                                         for(k=0;k<numplayers;k++){
8885                                                                 for(i=k;i<numplayers;i++){
8886                                                                         if(i==k)i++;
8887                                                                         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))){
8888                                                                                 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)){
8889                                                                                         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)){
8890                                                                                                 player[i].victim=&player[k];
8891                                                                                                 player[i].targetanimation=jumpreversedanim;
8892                                                                                                 player[i].currentanimation=jumpreversedanim;
8893                                                                                                 player[k].currentanimation=jumpreversalanim;
8894                                                                                                 player[k].targetanimation=jumpreversalanim;
8895                                                                                                 player[i].targettilt2=0;
8896                                                                                                 player[i].currentframe=0;
8897                                                                                                 player[i].targetframe=1;
8898                                                                                                 player[k].currentframe=0;
8899                                                                                                 player[k].targetframe=1;
8900                                                                                                 if(player[i].coords.y<player[k].coords.y+1){
8901                                                                                                         player[i].targetanimation=rabbitkickreversedanim;
8902                                                                                                         player[i].currentanimation=rabbitkickreversedanim;
8903                                                                                                         player[k].currentanimation=rabbitkickreversalanim;
8904                                                                                                         player[k].targetanimation=rabbitkickreversalanim;
8905                                                                                                         player[k].currentframe=1;
8906                                                                                                         player[k].targetframe=2;
8907                                                                                                         player[i].currentframe=1;
8908                                                                                                         player[i].targetframe=2;
8909                                                                                                 }
8910                                                                                                 player[k].targettilt2=0;
8911                                                                                                 player[i].target=0;
8912                                                                                                 player[i].velocity=0;
8913                                                                                                 player[k].velocity=0;
8914                                                                                                 player[k].oldcoords=player[k].coords;
8915                                                                                                 player[i].coords=player[k].coords;
8916                                                                                                 player[k].targetrotation=player[i].targetrotation;
8917                                                                                                 player[k].rotation=player[i].targetrotation;
8918                                                                                                 player[k].victim=&player[i];
8919                                                                                                 if(player[k].aitype==attacktypecutoff)player[k].stunned=.5;
8920                                                                                         }
8921                                                                                         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)){
8922                                                                                                 player[k].victim=&player[i];
8923                                                                                                 player[k].targetanimation=jumpreversedanim;
8924                                                                                                 player[k].currentanimation=jumpreversedanim;
8925                                                                                                 player[i].currentanimation=jumpreversalanim;
8926                                                                                                 player[i].targetanimation=jumpreversalanim;
8927                                                                                                 player[k].targettilt2=0;
8928                                                                                                 player[i].targettilt2=0;
8929                                                                                                 player[k].currentframe=0;
8930                                                                                                 player[k].targetframe=1;
8931                                                                                                 player[i].currentframe=0;
8932                                                                                                 player[i].targetframe=1;
8933                                                                                                 if(player[k].coords.y<player[i].coords.y+1){
8934                                                                                                         player[k].targetanimation=rabbitkickreversedanim;
8935                                                                                                         player[k].currentanimation=rabbitkickreversedanim;
8936                                                                                                         player[i].currentanimation=rabbitkickreversalanim;
8937                                                                                                         player[i].targetanimation=rabbitkickreversalanim;
8938                                                                                                         player[k].currentframe=1;
8939                                                                                                         player[k].targetframe=2;
8940                                                                                                         player[i].currentframe=1;
8941                                                                                                         player[i].targetframe=2;
8942                                                                                                 }
8943                                                                                                 player[k].target=0;
8944                                                                                                 player[k].velocity=0;
8945                                                                                                 player[i].velocity=0;
8946                                                                                                 player[i].oldcoords=player[i].coords;
8947                                                                                                 player[k].coords=player[i].coords;
8948                                                                                                 player[i].targetrotation=player[k].targetrotation;
8949                                                                                                 player[i].rotation=player[k].targetrotation;
8950                                                                                                 player[i].victim=&player[k];
8951                                                                                                 if(player[i].aitype==attacktypecutoff)player[i].stunned=.5;
8952                                                                                         }
8953                                                                                 }
8954                                                                         }
8955                                                                 }
8956                                                         }
8957
8958                                                         for(k=0;k<numplayers;k++)
8959                                                                 if(player[k].immobile&&k!=0)player[k].coords=player[k].realoldcoords;
8960
8961
8962                                                         //pile
8963                                                         /*
8964                                                         XYZ tempdiff;
8965                                                         XYZ tempoldpos;
8966                                                         XYZ temp1,temp2;
8967                                                         bool isgood;
8968                                                         static float checkdelay;
8969                                                         checkdelay-=multiplier;
8970                                                         int m;
8971                                                         static bool checkedcoll[maxplayers][maxplayers];
8972                                                         static bool above[maxplayers];
8973
8974                                                         for(i=0;i<maxplayers;i++){
8975                                                         for(j=0;j<maxplayers;j++){
8976                                                         checkedcoll[i][j]=0;
8977                                                         }
8978                                                         }
8979
8980                                                         if(numplayers>1&&checkdelay<=0){
8981                                                         checkdelay=.015;
8982                                                         for(k=0;k<numplayers;k++){
8983                                                         if(player[k].skeleton.free!=2)above[k]=-1;
8984
8985                                                         for(i=k;i<numplayers;i++){
8986                                                         if(i==k)i++;
8987                                                         if(i<numplayers)
8988                                                         if(!checkedcoll[i][k]){
8989                                                         checkedcoll[i][k]=1;
8990                                                         checkedcoll[k][i]=1;
8991                                                         if(player[i].skeleton.free&&player[k].skeleton.free)
8992                                                         if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
8993                                                         if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
8994                                                         if(player[i].coords.y>player[k].coords.y-3)
8995                                                         if(player[i].coords.y<player[k].coords.y+3)
8996                                                         if(player[i].coords.x>player[k].coords.x-3)
8997                                                         if(player[i].coords.x<player[k].coords.x+3)
8998                                                         if(player[i].coords.z>player[k].coords.z-3)
8999                                                         if(player[i].coords.z<player[k].coords.z+3)
9000                                                         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)){
9001                                                         int stuck,moving;
9002                                                         if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
9003                                                         stuck=i;
9004                                                         moving=k;
9005                                                         }
9006                                                         else
9007                                                         {
9008                                                         moving=i;
9009                                                         stuck=k;
9010                                                         }
9011                                                         isgood=1;
9012
9013                                                         if(isgood){
9014                                                         above[moving]=stuck;
9015                                                         for(l=0;l<player[moving].skeleton.num_joints;l++){
9016                                                         for(m=0;m<player[stuck].skeleton.num_joints;m++){
9017                                                         while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
9018                                                         {
9019                                                         player[moving].skeleton.joints[l].position.y+=.003;
9020                                                         if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
9021
9022                                                         }
9023                                                         }
9024                                                         }
9025                                                         }
9026                                                         }
9027                                                         }
9028                                                         }
9029                                                         }
9030                                                         }
9031
9032                                                         */
9033
9034                                                         if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
9035                                                                 texturesizetogglekeydown=0;
9036                                                         }
9037
9038                                                         for(k=0;k<numplayers;k++){
9039                                                                 if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9040                                                                         if(!isnormal(player[k].coords.x)||!isnormal(player[k].coords.y)||!isnormal(player[k].coords.z)){
9041                                                                                 player[k].DoDamage(1000);
9042                                                                         }
9043                                                                 }
9044                                                         }
9045
9046                                                         static bool respawnkeydown;
9047                                                         if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
9048                                                                 targetlevel=whichlevel;
9049                                                                 loading=1;
9050                                                                 leveltime=5;
9051                                                         }
9052                                                         if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
9053                                                         if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
9054
9055
9056
9057
9058                                                         if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
9059                                                                 targetlevel++;
9060                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
9061                                                                 loading=1;
9062                                                                 leveltime=5;
9063                                                                 slomotogglekeydown=1;
9064                                                         }
9065
9066                                                         /*
9067                                                         if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
9068                                                         //Respawn
9069                                                         OPENAL_SetPaused(channels[whooshsound], true);
9070                                                         changedelay=0;
9071                                                         for(k=0;k<numplayers;k++){
9072                                                         player[k].dead=0;
9073                                                         player[k].damage=0;
9074                                                         player[k].permanentdamage=0;
9075                                                         if(player[k].skeleton.free==2)player[k].skeleton.free=1;
9076                                                         player[k].aitype=passivetype;
9077                                                         }
9078                                                         player[0].aitype=playercontrolled;
9079                                                         }
9080                                                         */
9081
9082                                                         static bool movekey;
9083                                                         static bool connected;
9084                                                         /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
9085                                                         player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
9086                                                         player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
9087                                                         player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
9088                                                         player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
9089                                                         player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
9090
9091                                                         //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
9092
9093                 for(int i=0;i<numplayers;i++){
9094                                                                 if(!player[i].skeleton.free){
9095                                                                         oldtargetrotation=player[i].targetrotation;
9096                                                                         if(i==0&&indialogue==-1){
9097                                                                                 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){
9098                                                                                         if(!cameramode)player[0].targetrotation=-rotation+180;
9099                                                                                         if(cameramode)player[0].targetrotation=0;
9100                                                                                 }
9101
9102                                                                                 facing=0;
9103                                                                                 facing.z=-1;
9104
9105                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9106                                                                                 if(cameramode){facing=flatfacing;}
9107                                                                                 else{
9108                                                                                         facing=DoRotation(facing,-rotation2,0,0);
9109                                                                                         facing=DoRotation(facing,0,0-rotation,0);
9110                                                                                 }
9111
9112                                                                                 player[0].lookrotation=-rotation;
9113
9114                                                                                 player[i].targetheadrotation=rotation;
9115                                                                                 player[i].targetheadrotation2=rotation2;
9116                                                                         }
9117                                                                         if(i!=0&&player[i].aitype==playercontrolled&&indialogue==-1){
9118                                                                                 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){
9119                                                                                         player[i].targetrotation=-player[i].lookrotation+180;
9120                                                                                 }
9121
9122                                                                                 facing=0;
9123                                                                                 facing.z=-1;
9124
9125                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
9126
9127                                                                                 facing=DoRotation(facing,-player[i].lookrotation2,0,0);
9128                                                                                 facing=DoRotation(facing,0,0-player[i].lookrotation,0);
9129
9130                                                                                 player[i].targetheadrotation=player[i].lookrotation;
9131                                                                                 player[i].targetheadrotation2=player[i].lookrotation2;
9132                                                                         }
9133                                                                         if(indialogue!=-1){
9134                                                                                 rotatetarget=participantfacing[whichdialogue][indialogue][i];
9135                                                                                 Normalise(&rotatetarget);
9136                                                                                 player[i].targetheadrotation=-asin(0-rotatetarget.x);
9137                                                                                 player[i].targetheadrotation*=360/6.28;
9138                                                                                 if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
9139
9140                                                                                 player[i].targetheadrotation*=-1;
9141                                                                                 player[i].targetheadrotation+=180;
9142                                                                                 player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
9143                                                                         }
9144
9145                                                                         bool pause;
9146
9147                                                                         if(leveltime<.5)
9148                                                                                 numenvsounds=0;
9149
9150                                                                         player[i].avoidsomething=0;
9151
9152                                                                         for(j=0;j<objects.numobjects;j++){
9153                                                                                 if(objects.onfire[j]){
9154                                                                                         if(findDistancefast(&objects.position[j],&player[i].coords)<objects.scale[j]*objects.scale[j]*200)
9155                                                                                         {
9156                                                                                                 if(findDistancefast(&player[i].coords,&objects.position[j])<findDistancefast(&player[i].coords,&player[0].coords)){
9157                                                                                                         player[i].collided=0;
9158                                                                                                         player[i].avoidcollided=1;
9159                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&objects.position[j],&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9160                                                                                                                 player[i].avoidwhere=objects.position[j];
9161                                                                                                 }
9162                                                                                         }
9163                                                                                 }
9164                                                                         }
9165
9166                                                                         //Add avoidwhere to players
9167
9168                                                                         for(j=0;j<numplayers;j++){
9169                                                                                 if(player[j].onfire){
9170                                                                                         if(findDistancefast(&player[j].coords,&player[i].coords)<0.3*0.3*200)
9171                                                                                         {
9172                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<findDistancefast(&player[i].coords,&player[0].coords)){
9173                                                                                                         player[i].collided=0;
9174                                                                                                         player[i].avoidcollided=1;
9175                                                                                                         if(player[i].avoidsomething==0||findDistancefast(&player[j].coords,&player[i].coords)<findDistancefast(&player[i].coords,&player[i].avoidwhere))
9176                                                                                                                 player[i].avoidwhere=objects.position[j];
9177                                                                                                 }
9178                                                                                         }
9179                                                                                 }
9180                                                                         }
9181
9182                                                                         if(player[i].collided>.8)player[i].avoidcollided=0;
9183                                                                         if(player[i].aitype!=playercontrolled&&indialogue==-1){
9184                                                                                 player[i].jumpclimb=0;
9185                                                                                 //AI
9186                                                                                 if(editorenabled)player[i].stunned=1;
9187
9188                                                                                 player[i].pause=0;
9189                                                                                 //if(findDistancefastflat(&player[i].coords,&player[0].coords)<3/*&&player[0].coords.y>player[i].coords.y+.1*/)player[i].pause=1;
9190                                                                                 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;
9191
9192                                                                                 /*if(player[i].aitype==passivetype&&player[i].numwaypoints<=1){
9193                                                                                 player[i].forwardkeydown=0;
9194                                                                                 player[i].leftkeydown=0;
9195                                                                                 player[i].backkeydown=0;
9196                                                                                 player[i].rightkeydown=0;
9197                                                                                 player[i].crouchkeydown=0;
9198                                                                                 player[i].attackkeydown=0;
9199                                                                                 player[i].jumpkeydown=0;
9200                                                                                 player[i].throwkeydown=0;
9201                                                                                 }*/
9202
9203                                                                                 if(player[i].aitype==pathfindtype){
9204                                                                                         if(player[i].finalpathfindpoint==-1){
9205                                                                                                 float closestdistance;
9206                                                                                                 float tempdist;
9207                                                                                                 int closest;
9208                                                                                                 XYZ colpoint;
9209                                                                                                 closest=-1;
9210                                                                                                 closestdistance=-1;
9211                                                                                                 for(j=0;j<numpathpoints;j++){
9212                                                                                                         if(closest==-1||findDistancefast(&player[i].finalfinaltarget,&pathpoint[j])<closestdistance){
9213                                                                                                                 closestdistance=findDistancefast(&player[i].finalfinaltarget,&pathpoint[j]);
9214                                                                                                                 closest=j;
9215                                                                                                                 player[i].finaltarget=pathpoint[j];
9216                                                                                                         }
9217                                                                                                 }
9218                                                                                                 player[i].finalpathfindpoint=closest;
9219                                                                                                 for(j=0;j<numpathpoints;j++){
9220                                                                                                         if(numpathpointconnect[j])
9221                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9222                                                                                                                         DistancePointLine(&player[i].finalfinaltarget, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9223                                                                                                                         if(tempdist*tempdist<closestdistance){
9224                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9225                                                                                                                                         closestdistance=tempdist*tempdist;
9226                                                                                                                                         closest=j;
9227                                                                                                                                         player[i].finaltarget=colpoint;
9228                                                                                                                                 }
9229                                                                                                                         }
9230                                                                                                                 }
9231                                                                                                 }
9232                                                                                                 player[i].finalpathfindpoint=closest;
9233
9234                                                                                         }
9235                                                                                         if(player[i].targetpathfindpoint==-1){
9236                                                                                                 float closestdistance;
9237                                                                                                 float tempdist;
9238                                                                                                 int closest;
9239                                                                                                 XYZ colpoint;
9240                                                                                                 closest=-1;
9241                                                                                                 closestdistance=-1;
9242                                                                                                 if(player[i].lastpathfindpoint==-1){
9243                                                                                                         for(j=0;j<numpathpoints;j++){
9244                                                                                                                 if(j!=player[i].lastpathfindpoint)
9245                                                                                                                         if(closest==-1||(findDistancefast(&player[i].coords,&pathpoint[j])<closestdistance/*&&findDistancefast(&player[i].finaltarget,&pathpoint[j])<findDistancefast(&player[i].finaltarget,&player[i].coords)*/)){
9246                                                                                                                                 closestdistance=findDistancefast(&player[i].coords,&pathpoint[j]);
9247                                                                                                                                 closest=j;
9248                                                                                                                         }
9249                                                                                                         }
9250                                                                                                         player[i].targetpathfindpoint=closest;
9251                                                                                                         for(j=0;j<numpathpoints;j++){
9252                                                                                                                 if(j!=player[i].lastpathfindpoint)
9253                                                                                                                         if(numpathpointconnect[j])
9254                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9255                                                                                                                                         DistancePointLine(&player[i].coords, &pathpoint[j], &pathpoint[pathpointconnect[j][k]], &tempdist,&colpoint );
9256                                                                                                                                         if(tempdist*tempdist<closestdistance){
9257                                                                                                                                                 if(findDistance(&colpoint,&pathpoint[j])+findDistance(&colpoint,&pathpoint[pathpointconnect[j][k]])<findDistance(&pathpoint[j],&pathpoint[pathpointconnect[j][k]])+.1){
9258                                                                                                                                                         //if(findDistancefast(&player[i].finaltarget,&colpoint)<findDistancefast(&player[i].finaltarget,&player[i].coords)){
9259                                                                                                                                                         closestdistance=tempdist*tempdist;
9260                                                                                                                                                         closest=j;
9261                                                                                                                                                         //}
9262                                                                                                                                                 }
9263                                                                                                                                         }
9264                                                                                                                                 }
9265                                                                                                         }
9266                                                                                                         player[i].targetpathfindpoint=closest;
9267                                                                                                 }
9268                                                                                                 else
9269                                                                                                 {
9270                                                                                                         for(j=0;j<numpathpoints;j++){
9271                                                                                                                 if(j!=player[i].lastpathfindpoint&&j!=player[i].lastpathfindpoint2&&j!=player[i].lastpathfindpoint3&&j!=player[i].lastpathfindpoint4)
9272                                                                                                                 {
9273                                                                                                                         connected=0;
9274                                                                                                                         if(numpathpointconnect[j])
9275                                                                                                                                 for(k=0;k<numpathpointconnect[j];k++){
9276                                                                                                                                         if(pathpointconnect[j][k]==player[i].lastpathfindpoint)connected=1;
9277                                                                                                                                 }
9278                                                                                                                                 if(!connected)
9279                                                                                                                                         if(numpathpointconnect[player[i].lastpathfindpoint])
9280                                                                                                                                                 for(k=0;k<numpathpointconnect[player[i].lastpathfindpoint];k++){
9281                                                                                                                                                         if(pathpointconnect[player[i].lastpathfindpoint][k]==j)connected=1;
9282                                                                                                                                                 }
9283                                                                                                                                                 if(connected){
9284                                                                                                                                                         tempdist=findPathDist(j,player[i].finalpathfindpoint);
9285                                                                                                                                                         if(closest==-1||tempdist<closestdistance){
9286                                                                                                                                                                 closestdistance=tempdist;
9287                                                                                                                                                                 closest=j;
9288                                                                                                                                                         }
9289                                                                                                                                                 }
9290                                                                                                                 }
9291                                                                                                         }
9292                                                                                                         player[i].targetpathfindpoint=closest;
9293                                                                                                 }
9294                                                                                         }
9295                                                                                         player[i].losupdatedelay-=multiplier;
9296
9297                                                                                         rotatetarget=pathpoint[player[i].targetpathfindpoint]-player[i].coords;
9298                                                                                         Normalise(&rotatetarget);
9299                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9300                                                                                         player[i].targetrotation*=360/6.28;
9301                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9302                                                                                         player[i].lookrotation=player[i].targetrotation;
9303                                                                                         //player[i].aiupdatedelay=.05;
9304
9305                                                                                         if(findDistancefastflat(&player[i].coords,&pathpoint[player[i].targetpathfindpoint])<.6){
9306                                                                                                 player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9307                                                                                                 player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9308                                                                                                 player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9309                                                                                                 player[i].lastpathfindpoint=player[i].targetpathfindpoint;
9310                                                                                                 if(player[i].lastpathfindpoint2==-1)player[i].lastpathfindpoint2=player[i].lastpathfindpoint;
9311                                                                                                 if(player[i].lastpathfindpoint3==-1)player[i].lastpathfindpoint3=player[i].lastpathfindpoint2;
9312                                                                                                 if(player[i].lastpathfindpoint4==-1)player[i].lastpathfindpoint4=player[i].lastpathfindpoint3;
9313                                                                                                 player[i].targetpathfindpoint=-1;
9314                                                                                         }
9315                                                                                         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){
9316                                                                                                 player[i].aitype=passivetype;
9317                                                                                         }
9318
9319                                                                                         player[i].forwardkeydown=1;
9320                                                                                         player[i].leftkeydown=0;
9321                                                                                         player[i].backkeydown=0;
9322                                                                                         player[i].rightkeydown=0;
9323                                                                                         player[i].crouchkeydown=0;
9324                                                                                         player[i].attackkeydown=0;
9325                                                                                         player[i].throwkeydown=0;
9326
9327                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9328
9329                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9330                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9331
9332                                                                                         if((tutoriallevel!=1||cananger)&&hostile&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9333                                                                                                 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))
9334                                                                                                         player[i].aitype=attacktypecutoff;
9335                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9336                                                                                                         player[i].aitype=attacktypecutoff;
9337
9338                                                                                                 if(player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9339                                                                                                         player[i].losupdatedelay=.2;
9340                                                                                                         for(j=0;j<numplayers;j++){
9341                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9342                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9343                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9344                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9345                                                                                                                                                 if(player[j].coords.y<player[i].coords.y+5||player[j].onterrain)
9346                                                                                                                                                         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)){
9347                                                                                                                                                                 player[i].aitype=searchtype;
9348                                                                                                                                                                 player[i].lastchecktime=12;
9349                                                                                                                                                                 player[i].lastseen=player[j].coords;
9350                                                                                                                                                                 player[i].lastseentime=12;
9351                                                                                                                                                         }
9352                                                                                                                 }
9353                                                                                                         }
9354                                                                                                 }
9355                                                                                         }
9356                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9357                                                                                                 if(player[i].creature!=wolftype){
9358                                                                                                         player[i].stunned=.6;
9359                                                                                                         player[i].surprised=.6;
9360                                                                                                 }
9361                                                                                         }
9362                                                                                 }
9363
9364                                                                                 if(player[i].aitype!=passivetype&&leveltime>.5){
9365                                                                                         player[i].howactive=typeactive;
9366                                                                                 }
9367
9368                                                                                 if(player[i].aitype==passivetype){
9369                                                                                         player[i].aiupdatedelay-=multiplier;
9370                                                                                         player[i].losupdatedelay-=multiplier;
9371                                                                                         player[i].lastseentime+=multiplier;
9372                                                                                         player[i].pausetime-=multiplier;
9373                                                                                         if(player[i].lastseentime>1)player[i].lastseentime=1;
9374
9375                                                                                         if(player[i].aiupdatedelay<0){
9376                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0){
9377                                                                                                         rotatetarget=player[i].waypoints[player[i].waypoint]-player[i].coords;
9378                                                                                                         Normalise(&rotatetarget);
9379                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9380                                                                                                         player[i].targetrotation*=360/6.28;
9381                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9382                                                                                                         player[i].lookrotation=player[i].targetrotation;
9383                                                                                                         player[i].aiupdatedelay=.05;
9384
9385                                                                                                         if(findDistancefastflat(&player[i].coords,&player[i].waypoints[player[i].waypoint])<1){
9386                                                                                                                 if(player[i].waypointtype[player[i].waypoint]==wppause)player[i].pausetime=4;
9387                                                                                                                 player[i].waypoint++;
9388                                                                                                                 if(player[i].waypoint>player[i].numwaypoints-1)player[i].waypoint=0;
9389
9390                                                                                                         }
9391                                                                                                 }
9392
9393                                                                                                 if(player[i].numwaypoints>1&&player[i].howactive==typeactive&&player[i].pausetime<=0)player[i].forwardkeydown=1;
9394                                                                                                 else player[i].forwardkeydown=0;
9395                                                                                                 player[i].leftkeydown=0;
9396                                                                                                 player[i].backkeydown=0;
9397                                                                                                 player[i].rightkeydown=0;
9398                                                                                                 player[i].crouchkeydown=0;
9399                                                                                                 player[i].attackkeydown=0;
9400                                                                                                 player[i].throwkeydown=0;
9401
9402                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9403                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9404                                                                                                         else{
9405                                                                                                                 XYZ leftpos,rightpos;
9406                                                                                                                 float leftdist,rightdist;
9407                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9408                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9409                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9410                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9411                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9412                                                                                                                 else player[i].targetrotation-=90;
9413                                                                                                         }
9414                                                                                                 }
9415                                                                                         }
9416                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9417                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9418
9419
9420                                                                                         if(!editorenabled){
9421                                                                                                 if(player[i].howactive<typesleeping)
9422                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9423                                                                                                                 for(j=0;j<numenvsounds;j++){
9424                                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9425                                                                                                                                 player[i].aitype=attacktypecutoff;
9426                                                                                                                         }
9427                                                                                                                 }
9428
9429                                                                                                                 if(player[i].howactive==typesleeping)
9430                                                                                                                         if(numenvsounds>0&&(tutoriallevel!=1||cananger)&&hostile)
9431                                                                                                                                 for(j=0;j<numenvsounds;j++){
9432                                                                                                                                         if(envsoundvol[j]>14)
9433                                                                                                                                                 if(findDistancefast(&player[i].coords,&envsound[j])<2*((envsoundvol[j]-14)+(envsoundvol[j]-14)*(player[i].creature==rabbittype)*3)){
9434                                                                                                                                                         player[i].aitype=attacktypecutoff;
9435                                                                                                                                                 }
9436                                                                                                                                 }
9437
9438                                                                                                                                 if(player[i].aitype!=passivetype){
9439                                                                                                                                         if(player[i].howactive==typesleeping){
9440                                                                                                                                                 player[i].targetanimation=getupfromfrontanim;
9441                                                                                                                                                 player[i].targetframe=0;
9442                                                                                                                                                 player[i].target=0;
9443                                                                                                                                         }
9444
9445                                                                                                                                         player[i].howactive=typeactive;
9446                                                                                                                                 }
9447                                                                                         }
9448
9449                                                                                         if(player[i].howactive<typesleeping&&((tutoriallevel!=1||cananger)&&hostile)&&!player[0].dead&&findDistancefast(&player[i].coords,&player[0].coords)<400&&player[i].occluded<25){
9450                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<12&&animation[player[0].targetanimation].height!=lowheight&&!editorenabled)
9451                                                                                                         player[i].aitype=attacktypecutoff;
9452                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<30&&animation[player[0].targetanimation].height==highheight&&!editorenabled)
9453                                                                                                         player[i].aitype=attacktypecutoff;
9454
9455                                                                                                 if(player[i].creature==wolftype){
9456                                                                                                         XYZ windsmell;
9457                                                                                                         float smelldistance;
9458                                                                                                         smelldistance=50;
9459                                                                                                         for(j=0;j<numplayers;j++){
9460                                                                                                                 if(j==0||(player[j].dead&&player[j].bloodloss>0)){
9461                                                                                                                         if(j==0&&player[j].num_weapons>0){
9462                                                                                                                                 if(weapons.bloody[player[j].weaponids[0]])smelldistance=100;
9463                                                                                                                                 if(player[j].num_weapons==2)
9464                                                                                                                                         if(weapons.bloody[player[j].weaponids[1]])smelldistance=100;
9465                                                                                                                         }
9466                                                                                                                         if(j!=0){
9467                                                                                                                                 smelldistance=100;
9468                                                                                                                         }
9469                                                                                                                         windsmell=windvector;
9470                                                                                                                         Normalise(&windsmell);
9471                                                                                                                         windsmell=windsmell*2+player[j].coords;
9472                                                                                                                         if(findDistancefast(&player[i].coords,&windsmell)<smelldistance&&!editorenabled)
9473                                                                                                                                 player[i].aitype=attacktypecutoff;
9474                                                                                                                 }
9475                                                                                                         }
9476                                                                                                 }
9477
9478                                                                                                 if(player[i].howactive<typesleeping&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2){
9479                                                                                                         player[i].losupdatedelay=.2;
9480                                                                                                         for(j=0;j<numplayers;j++){
9481                                                                                                                 if(j==0||player[j].skeleton.free||player[j].aitype!=passivetype){
9482                                                                                                                         if(abs(Random()%2)||animation[player[j].targetanimation].height!=lowheight||j!=0)
9483                                                                                                                                 if(findDistancefast(&player[i].coords,&player[j].coords)<400)
9484                                                                                                                                         if(normaldotproduct(player[i].facing,player[j].coords-player[i].coords)>0)
9485                                                                                                                                                 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)){
9486                                                                                                                                                         player[i].lastseentime-=.2;
9487                                                                                                                                                         if(j==0&&animation[player[j].targetanimation].height==lowheight)player[i].lastseentime-=.4;
9488                                                                                                                                                         else player[i].lastseentime-=.6;
9489                                                                                                                                                 }
9490                                                                                                                                                 if(player[i].lastseentime<=0){
9491                                                                                                                                                         player[i].aitype=searchtype;
9492                                                                                                                                                         player[i].lastchecktime=12;
9493                                                                                                                                                         player[i].lastseen=player[j].coords;
9494                                                                                                                                                         player[i].lastseentime=12;
9495                                                                                                                                                 }
9496                                                                                                                 }
9497                                                                                                         }
9498                                                                                                 }
9499                                                                                         }
9500                                                                                         if(player[i].aitype==attacktypecutoff&&musictype!=2){
9501                                                                                                 if(player[i].creature!=wolftype){
9502                                                                                                         player[i].stunned=.6;
9503                                                                                                         player[i].surprised=.6;
9504                                                                                                 }
9505                                                                                                 if(player[i].creature==wolftype){
9506                                                                                                         player[i].stunned=.47;
9507                                                                                                         player[i].surprised=.47;
9508                                                                                                 }
9509                                                                                                 numseen++;
9510                                                                                         }
9511                                                                                 }
9512
9513                                                                                 if(player[i].aitype==searchtype){
9514                                                                                         player[i].aiupdatedelay-=multiplier;
9515                                                                                         player[i].losupdatedelay-=multiplier;
9516                                                                                         if(!player[i].pause)player[i].lastseentime-=multiplier;
9517                                                                                         player[i].lastchecktime-=multiplier;
9518
9519                                                                                         if(player[i].isRun()&&!player[i].onground){
9520                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9521                                                                                                         test2=player[i].coords+player[i].facing;
9522                                                                                                         test2.y+=5;
9523                                                                                                         test=player[i].coords+player[i].facing;
9524                                                                                                         test.y-=10;
9525                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9526                                                                                                         if(j==-1)j=checkcollide(test2,test);
9527                                                                                                         if(j==-1){
9528                                                                                                                 player[i].velocity=0;
9529                                                                                                                 player[i].targetanimation=player[i].getStop();
9530                                                                                                                 player[i].targetframe=0;
9531                                                                                                                 player[i].target=0;
9532                                                                                                                 player[i].targetrotation+=180;
9533                                                                                                                 player[i].stunned=.5;
9534                                                                                                                 //player[i].aitype=passivetype;
9535                                                                                                                 player[i].aitype=pathfindtype;
9536                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9537                                                                                                                 player[i].finalpathfindpoint=-1;
9538                                                                                                                 player[i].targetpathfindpoint=-1;
9539                                                                                                                 player[i].lastpathfindpoint=-1;
9540                                                                                                                 player[i].lastpathfindpoint2=-1;
9541                                                                                                                 player[i].lastpathfindpoint3=-1;
9542                                                                                                                 player[i].lastpathfindpoint4=-1;
9543                                                                                                         }
9544                                                                                                         else player[i].laststanding=j;
9545                                                                                                 }
9546                                                                                         }
9547                                                                                         if(player[i].aiupdatedelay<0){
9548                                                                                                 rotatetarget=player[i].lastseen-player[i].coords;
9549                                                                                                 Normalise(&rotatetarget);
9550                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9551                                                                                                 player[i].targetrotation*=360/6.28;
9552                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9553                                                                                                 player[i].lookrotation=player[i].targetrotation;
9554                                                                                                 player[i].aiupdatedelay=.05;
9555                                                                                                 player[i].forwardkeydown=1;
9556
9557                                                                                                 if(findDistancefastflat(&player[i].coords,&player[i].lastseen)<1*(player[i].scale*5)*(player[i].scale*5)||player[i].lastchecktime<0){
9558                                                                                                         player[i].forwardkeydown=0;
9559                                                                                                         player[i].aiupdatedelay=1;
9560                                                                                                         player[i].lastseen.x+=(float(Random()%100)-50)/25;
9561                                                                                                         player[i].lastseen.z+=(float(Random()%100)-50)/25;
9562                                                                                                         player[i].lastchecktime=3;
9563                                                                                                 }
9564
9565                                                                                                 player[i].leftkeydown=0;
9566                                                                                                 player[i].backkeydown=0;
9567                                                                                                 player[i].rightkeydown=0;
9568                                                                                                 player[i].crouchkeydown=0;
9569                                                                                                 player[i].attackkeydown=0;
9570                                                                                                 player[i].throwkeydown=0;
9571
9572                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9573                                                                                                         if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9574                                                                                                         else{
9575                                                                                                                 XYZ leftpos,rightpos;
9576                                                                                                                 float leftdist,rightdist;
9577                                                                                                                 leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9578                                                                                                                 rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9579                                                                                                                 leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9580                                                                                                                 rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9581                                                                                                                 if(leftdist<rightdist)player[i].targetrotation+=90;
9582                                                                                                                 else player[i].targetrotation-=90;
9583                                                                                                         }
9584                                                                                                 }
9585                                                                                         }
9586                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9587                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9588
9589                                                                                         if(numenvsounds>0&&((tutoriallevel!=1||cananger)&&hostile))
9590                                                                                                 for(j=0;j<numenvsounds;j++){
9591                                                                                                         if(findDistancefast(&player[i].coords,&envsound[j])<2*(envsoundvol[j]+envsoundvol[j]*(player[i].creature==rabbittype)*3)){
9592                                                                                                                 player[i].aitype=attacktypecutoff;
9593                                                                                                         }
9594                                                                                                 }
9595
9596                                                                                                 if(!player[0].dead&&player[i].losupdatedelay<0&&!editorenabled&&player[i].occluded<2&&((tutoriallevel!=1||cananger)&&hostile)){
9597                                                                                                         player[i].losupdatedelay=.2;
9598                                                                                                         if(findDistancefast(&player[i].coords,&player[0].coords)<4&&animation[player[i].targetanimation].height!=lowheight)
9599                                                                                                         {player[i].aitype=attacktypecutoff;
9600                                                                                                         player[i].lastseentime=1;}
9601                                                                                                         if(abs(Random()%2)||animation[player[i].targetanimation].height!=lowheight)
9602                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)<400)
9603                                                                                                                         if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9604                                                                                                                                 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)){
9605                                                                                                                                         player[i].aitype=attacktypecutoff;
9606                                                                                                                                         player[i].lastseentime=1;
9607                                                                                                                                 }
9608                                                                                                 }
9609                                                                                                 if(player[i].lastseentime<0){
9610                                                                                                         //player[i].aitype=passivetype;
9611                                                                                                         numescaped++;
9612                                                                                                         player[i].aitype=pathfindtype;
9613                                                                                                         player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9614                                                                                                         player[i].finalpathfindpoint=-1;
9615                                                                                                         player[i].targetpathfindpoint=-1;
9616                                                                                                         player[i].lastpathfindpoint=-1;
9617                                                                                                         player[i].lastpathfindpoint2=-1;
9618                                                                                                         player[i].lastpathfindpoint3=-1;
9619                                                                                                         player[i].lastpathfindpoint4=-1;
9620                                                                                                 }
9621                                                                                 }
9622
9623                                                                                 if(player[i].aitype!=gethelptype){
9624                                                                                         player[i].runninghowlong=0;
9625                                                                                 }
9626
9627                                                                                 if(player[i].aitype==gethelptype){
9628                                                                                         player[i].runninghowlong+=multiplier;
9629                                                                                         player[i].aiupdatedelay-=multiplier;
9630
9631                                                                                         if(player[i].aiupdatedelay<0||player[i].ally==0){
9632                                                                                                 player[i].aiupdatedelay=.2;
9633
9634                                                                                                 int closest;
9635                                                                                                 float closestdist;
9636                                                                                                 closest=-1;
9637                                                                                                 closestdist=-1;
9638                                                                                                 float distance;
9639
9640                                                                                                 if(!player[i].ally){
9641                                                                                                         for(j=0;j<numplayers;j++){
9642                                                                                                                 if(j!=i&&j!=0&&!player[j].dead&&player[j].howactive<typedead1&&!player[j].skeleton.free&&player[j].aitype==passivetype){
9643                                                                                                                         distance=findDistancefast(&player[i].coords,&player[j].coords);
9644                                                                                                                         if(closestdist==-1||distance<closestdist){
9645                                                                                                                                 closestdist=distance;
9646                                                                                                                                 closest=j;
9647                                                                                                                         }
9648                                                                                                                         closest=j;
9649                                                                                                                 }
9650                                                                                                         }
9651                                                                                                         if(closest!=-1)player[i].ally=closest;
9652                                                                                                         else player[i].ally=0;
9653                                                                                                         player[i].lastseen=player[0].coords;
9654                                                                                                         player[i].lastseentime=12;
9655                                                                                                 }
9656
9657
9658                                                                                                 player[i].lastchecktime=12;
9659                                                                                                 //player[i].lastseentime-=.5;
9660
9661                                                                                                 facing=player[i].coords;
9662                                                                                                 flatfacing=player[player[i].ally].coords;
9663                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9664                                                                                                 flatfacing.y+=player[player[i].ally].skeleton.joints[player[player[i].ally].skeleton.jointlabels[head]].position.y*player[player[i].ally].scale;
9665                                                                                                 if(-1!=checkcollide(facing,flatfacing))
9666                                                                                                         player[i].lastseentime-=.1;
9667
9668                                                                                                 if(player[i].ally<=0||player[player[i].ally].skeleton.free||player[player[i].ally].aitype!=passivetype||player[i].lastseentime<=0){
9669                                                                                                         player[i].aitype=searchtype;
9670                                                                                                         player[i].lastseentime=12;
9671                                                                                                 }
9672
9673                                                                                                 if(player[i].ally>0){
9674                                                                                                         rotatetarget=player[player[i].ally].coords-player[i].coords;
9675                                                                                                         Normalise(&rotatetarget);
9676                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9677                                                                                                         player[i].targetrotation*=360/6.28;
9678                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9679                                                                                                         player[i].lookrotation=player[i].targetrotation;
9680                                                                                                         player[i].aiupdatedelay=.05;
9681                                                                                                         player[i].forwardkeydown=1;
9682
9683                                                                                                         if(findDistancefastflat(&player[i].coords,&player[player[i].ally].coords)<3){
9684                                                                                                                 player[i].aitype=searchtype;
9685                                                                                                                 player[i].lastseentime=12;
9686                                                                                                                 player[player[i].ally].aitype=searchtype;
9687                                                                                                                 if(player[player[i].ally].lastseentime<player[i].lastseentime){
9688                                                                                                                         player[player[i].ally].lastseen=player[i].lastseen;
9689                                                                                                                         player[player[i].ally].lastseentime=player[i].lastseentime;
9690                                                                                                                         player[player[i].ally].lastchecktime=player[i].lastchecktime;
9691                                                                                                                 }
9692                                                                                                         }
9693
9694                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9695                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9696                                                                                                                 else{
9697                                                                                                                         XYZ leftpos,rightpos;
9698                                                                                                                         float leftdist,rightdist;
9699                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9700                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9701                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9702                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9703                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9704                                                                                                                         else player[i].targetrotation-=90;
9705                                                                                                                 }
9706                                                                                                         }
9707                                                                                                 }
9708
9709                                                                                                 player[i].leftkeydown=0;
9710                                                                                                 player[i].backkeydown=0;
9711                                                                                                 player[i].rightkeydown=0;
9712                                                                                                 player[i].crouchkeydown=0;
9713                                                                                                 player[i].attackkeydown=0;
9714                                                                                         }
9715                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9716                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9717                                                                                 }
9718
9719                                                                                 if(player[i].aitype==getweapontype){
9720                                                                                         player[i].aiupdatedelay-=multiplier;
9721                                                                                         player[i].lastchecktime-=multiplier;
9722
9723                                                                                         if(player[i].aiupdatedelay<0){
9724                                                                                                 player[i].aiupdatedelay=.2;
9725
9726                                                                                                 int closest;
9727                                                                                                 float closestdist;
9728                                                                                                 closest=-1;
9729                                                                                                 closestdist=-1;
9730                                                                                                 float distance;
9731
9732                                                                                                 if(player[i].ally<0){
9733                                                                                                         for(j=0;j<weapons.numweapons;j++){
9734                                                                                                                 if(weapons.owner[j]==-1){
9735                                                                                                                         distance=findDistancefast(&player[i].coords,&weapons.position[j]);
9736                                                                                                                         if(closestdist==-1||distance<closestdist){
9737                                                                                                                                 closestdist=distance;
9738                                                                                                                                 closest=j;
9739                                                                                                                         }
9740                                                                                                                         closest=j;
9741                                                                                                                 }
9742                                                                                                         }
9743                                                                                                         if(closest!=-1)player[i].ally=closest;
9744                                                                                                         else player[i].ally=-1;
9745                                                                                                 }
9746
9747                                                                                                 player[i].lastseentime=12;
9748
9749                                                                                                 if(!player[0].dead&&((tutoriallevel!=1||cananger)&&hostile))
9750                                                                                                         if(player[i].ally<0||player[i].weaponactive!=-1||player[i].lastchecktime<=0){
9751                                                                                                                 player[i].aitype=attacktypecutoff;
9752                                                                                                                 player[i].lastseentime=1;
9753                                                                                                         }
9754                                                                                                         if(!player[0].dead)
9755                                                                                                                 if(player[i].ally>=0){
9756                                                                                                                         if(weapons.owner[player[i].ally]!=-1||findDistancefast(&player[i].coords,&weapons.position[player[i].ally])>16){
9757                                                                                                                                 player[i].aitype=attacktypecutoff;
9758                                                                                                                                 player[i].lastseentime=1;
9759                                                                                                                         }
9760                                                                                                                         rotatetarget=weapons.position[player[i].ally]-player[i].coords;
9761                                                                                                                         Normalise(&rotatetarget);
9762                                                                                                                         player[i].targetrotation=-asin(0-rotatetarget.x);
9763                                                                                                                         player[i].targetrotation*=360/6.28;
9764                                                                                                                         if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9765                                                                                                                         player[i].lookrotation=player[i].targetrotation;
9766                                                                                                                         player[i].aiupdatedelay=.05;
9767                                                                                                                         player[i].forwardkeydown=1;
9768
9769
9770                                                                                                                         if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8){
9771                                                                                                                                 if(!player[i].avoidsomething)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9772                                                                                                                                 else{
9773                                                                                                                                         XYZ leftpos,rightpos;
9774                                                                                                                                         float leftdist,rightdist;
9775                                                                                                                                         leftpos = player[i].coords+DoRotation(player[i].facing,0,90,0);
9776                                                                                                                                         rightpos = player[i].coords-DoRotation(player[i].facing,0,90,0);
9777                                                                                                                                         leftdist = findDistancefast(&leftpos, &player[i].avoidwhere);
9778                                                                                                                                         rightdist = findDistancefast(&rightpos, &player[i].avoidwhere);
9779                                                                                                                                         if(leftdist<rightdist)player[i].targetrotation+=90;
9780                                                                                                                                         else player[i].targetrotation-=90;
9781                                                                                                                                 }
9782                                                                                                                         }
9783                                                                                                                         /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
9784                                                                                                                         if(abs(Random()%6)){
9785                                                                                                                         player[i].crouchkeydown=1;
9786                                                                                                                         if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
9787                                                                                                                         if(player[i].isRun()){
9788                                                                                                                         player[i].targetframe=0;
9789                                                                                                                         player[i].target=0;
9790                                                                                                                         player[i].targetanimation=sneakanim;
9791                                                                                                                         }
9792                                                                                                                         }
9793                                                                                                                         else player[i].forwardkeydown=0;
9794                                                                                                                         }
9795                                                                                                                         else player[i].crouchkeydown=0;
9796                                                                                                                         }
9797                                                                                                                         else player[i].crouchkeydown=0;*/
9798                                                                                                                 }
9799
9800                                                                                                                 player[i].leftkeydown=0;
9801                                                                                                                 player[i].backkeydown=0;
9802                                                                                                                 player[i].rightkeydown=0;
9803                                                                                                                 player[i].attackkeydown=0;
9804                                                                                                                 player[i].throwkeydown=1;
9805                                                                                                                 player[i].crouchkeydown=0;
9806                                                                                                                 if(player[i].targetanimation!=crouchremoveknifeanim&&player[i].targetanimation!=removeknifeanim)player[i].throwtogglekeydown=0;
9807                                                                                                                 player[i].drawkeydown=0;
9808                                                                                         }
9809                                                                                         if(player[i].collided<1||player[i].targetanimation!=jumpupanim)player[i].jumpkeydown=0;
9810                                                                                         if((player[i].collided>.8&&player[i].jumppower>=5))player[i].jumpkeydown=1;
9811                                                                                 }
9812
9813                                                                                 if(player[i].aitype==attacktypecutoff){
9814                                                                                         player[i].aiupdatedelay-=multiplier;
9815                                                                                         if(player[i].damage<player[i].damagetolerance*2/3)
9816                                                                                                 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)){
9817                                                                                                         player[i].attackkeydown=0;
9818                                                                                                         if(player[i].isIdle())player[i].crouchkeydown=1;
9819                                                                                                         if(player[0].targetanimation!=rabbitkickanim&&player[0].weaponactive!=-1){
9820                                                                                                                 if(weapons.type[player[0].weaponids[0]]==knife){
9821                                                                                                                         if(player[i].isIdle()||player[i].isCrouch()||player[i].isRun()||player[i].isFlip()){
9822                                                                                                                                 if(abs(Random()%2==0))player[i].targetanimation=backhandspringanim;
9823                                                                                                                                 else player[i].targetanimation=rollanim;
9824                                                                                                                                 player[i].target=0;
9825                                                                                                                                 player[i].targetframe=0;
9826                                                                                                                                 player[i].targetrotation+=90*(abs(Random()%2)*2-1);
9827                                                                                                                                 player[i].wentforweapon=0;
9828                                                                                                                         }
9829                                                                                                                         if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim){
9830                                                                                                                                 player[i].targetanimation=flipanim;
9831                                                                                                                                 player[i].target=0;
9832                                                                                                                                 player[i].targetframe=0;
9833                                                                                                                         }
9834                                                                                                                 }
9835                                                                                                         }
9836                                                                                                         player[i].forwardkeydown=0;
9837                                                                                                         player[i].aiupdatedelay=.02;
9838                                                                                                 }
9839                                                                                                 if(player[0].isFlip()&&!player[0].skeleton.free&&player[0].targetanimation!=walljumprightkickanim&&player[0].targetanimation!=walljumpleftkickanim){
9840                                                                                                         if(findDistancefast(&player[0].coords,&player[i].coords)<25)
9841                                                                                                                 if((1-player[i].damage/player[i].damagetolerance)>.5)player[i].stunned=1;
9842                                                                                                 }
9843                                                                                                 if(player[i].wentforweapon<3)
9844                                                                                                         for(j=0;j<weapons.numweapons;j++){
9845                                                                                                                 if(player[i].creature!=wolftype)
9846                                                                                                                         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){
9847                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<16){
9848                                                                                                                                         player[i].wentforweapon++;
9849                                                                                                                                         player[i].lastchecktime=6;
9850                                                                                                                                         player[i].aitype=getweapontype;
9851                                                                                                                                         player[i].ally=-1;
9852                                                                                                                                 }
9853                                                                                                                         }
9854                                                                                                         }
9855                                                                                                         if(player[i].damage<player[i].damagetolerance/2)
9856                                                                                                                 if(animation[player[i].targetanimation].height!=highheight)
9857                                                                                                                         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)))){
9858                                                                                                                                 player[i].crouchkeydown=1;
9859                                                                                                                         }
9860                                                                                                                         if(player[i].isRun()&&!player[i].onground){
9861                                                                                                                                 if(player[i].coords.y>terrain.getHeight(player[i].coords.x,player[i].coords.z)+10){
9862                                                                                                                                         test2=player[i].coords+player[i].facing;
9863                                                                                                                                         test2.y+=5;
9864                                                                                                                                         test=player[i].coords+player[i].facing;
9865                                                                                                                                         test.y-=10;
9866                                                                                                                                         j=checkcollide(test2,test,player[i].laststanding);
9867                                                                                                                                         if(j==-1)j=checkcollide(test2,test);
9868                                                                                                                                         if(j==-1){
9869                                                                                                                                                 player[i].velocity=0;
9870                                                                                                                                                 player[i].targetanimation=player[i].getStop();
9871                                                                                                                                                 player[i].targetframe=0;
9872                                                                                                                                                 player[i].target=0;
9873                                                                                                                                                 player[i].targetrotation+=180;
9874                                                                                                                                                 player[i].stunned=.5;
9875                                                                                                                                                 //player[i].aitype=passivetype;
9876                                                                                                                                                 player[i].aitype=pathfindtype;
9877                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9878                                                                                                                                                 player[i].finalpathfindpoint=-1;
9879                                                                                                                                                 player[i].targetpathfindpoint=-1;
9880                                                                                                                                                 player[i].lastpathfindpoint=-1;
9881                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9882                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9883                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9884                                                                                                                                         }
9885                                                                                                                                         else player[i].laststanding=j;
9886                                                                                                                                 }
9887                                                                                                                         }
9888                                                                                                                         if(player[0].coords.y>player[i].coords.y+5&&animation[player[0].targetanimation].height!=highheight&&!player[0].onterrain){
9889                                                                                                                                 player[i].aitype=pathfindtype;
9890                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9891                                                                                                                                 player[i].finalpathfindpoint=-1;
9892                                                                                                                                 player[i].targetpathfindpoint=-1;
9893                                                                                                                                 player[i].lastpathfindpoint=-1;
9894                                                                                                                                 player[i].lastpathfindpoint2=-1;
9895                                                                                                                                 player[i].lastpathfindpoint3=-1;
9896                                                                                                                                 player[i].lastpathfindpoint4=-1;
9897                                                                                                                         }
9898                                                                                                                         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){
9899                                                                                                                                 if(player[i].weaponactive==-1&&player[i].num_weapons>0)player[i].drawkeydown=Random()%2;
9900                                                                                                                                 else player[i].drawkeydown=0;
9901                                                                                                                                 player[i].rabbitkickenabled=Random()%2;
9902                                                                                                                                 rotatetarget=player[player[i].aitarget].coords+player[player[i].aitarget].velocity;
9903                                                                                                                                 if(findDistancefast(&player[player[i].aitarget].coords,&player[i].coords)<findDistancefast(&rotatetarget,&player[i].coords))
9904                                                                                                                                         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;
9905                                                                                                                                 else rotatetarget=player[player[i].aitarget].coords-player[i].coords;
9906                                                                                                                                 Normalise(&rotatetarget);
9907                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
9908                                                                                                                                 player[i].targetrotation*=360/6.28;
9909                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
9910                                                                                                                                 player[i].lookrotation=player[i].targetrotation;
9911                                                                                                                                 player[i].aiupdatedelay=.2+abs((float)(Random()%100)/1000);
9912
9913                                                                                                                                 oldkey=player[i].forwardkeydown;
9914                                                                                                                                 if(findDistancefast(&player[i].coords,&player[0].coords)>5&&(player[0].weaponactive==-1||player[i].weaponactive!=-1))player[i].forwardkeydown=1;
9915                                                                                                                                 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;
9916                                                                                                                                 else if(Random()%6==0||(player[i].creature==wolftype&&Random()%3==0))player[i].forwardkeydown=1;
9917                                                                                                                                 else player[i].forwardkeydown=0;
9918                                                                                                                                 if(player[0].dead){
9919                                                                                                                                         player[i].forwardkeydown=0;
9920                                                                                                                                         if(Random()%10==0)player[i].forwardkeydown=1;
9921                                                                                                                                         if(Random()%100==0){
9922                                                                                                                                                 player[i].aitype=pathfindtype;
9923                                                                                                                                                 player[i].finalfinaltarget=player[i].waypoints[player[i].waypoint];
9924                                                                                                                                                 player[i].finalpathfindpoint=-1;
9925                                                                                                                                                 player[i].targetpathfindpoint=-1;
9926                                                                                                                                                 player[i].lastpathfindpoint=-1;
9927                                                                                                                                                 player[i].lastpathfindpoint2=-1;
9928                                                                                                                                                 player[i].lastpathfindpoint3=-1;
9929                                                                                                                                                 player[i].lastpathfindpoint4=-1;
9930                                                                                                                                         }
9931                                                                                                                                 }
9932                                                                                                                                 player[i].leftkeydown=0;
9933                                                                                                                                 player[i].backkeydown=0;
9934                                                                                                                                 player[i].rightkeydown=0;
9935                                                                                                                                 player[i].crouchkeydown=0;
9936                                                                                                                                 player[i].throwkeydown=0;
9937
9938                                                                                                                                 if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
9939                                                                                                                                 /*for(j=0;j<numplayers;j++){
9940                                                                                                                                 if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
9941                                                                                                                                 player[i].crouchkeydown=1;
9942                                                                                                                                 }
9943                                                                                                                                 }*/
9944                                                                                                                                 if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
9945                                                                                                                                 else player[i].attackkeydown=0;
9946                                                                                                                                 if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
9947                                                                                                                                 //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
9948                                                                                                                                 /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
9949                                                                                                                                 player[i].attackkeydown=0;
9950                                                                                                                                 if(player[i].isIdle())player[i].crouchkeydown=1;
9951                                                                                                                                 player[i].forwardkeydown=0;
9952                                                                                                                                 player[i].aiupdatedelay=.02;
9953                                                                                                                                 }*/
9954
9955                                                                                                                                 if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
9956                                                                                                                                         target=-2;
9957                                                                                                                                         for(j=0;j<numplayers;j++){
9958                                                                                                                                                 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)){
9959                                                                                                                                                         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))))){
9960                                                                                                                                                                 if(target>=0)target=-1;
9961                                                                                                                                                                 else target=j;
9962                                                                                                                                                         }
9963                                                                                                                                                 }
9964                                                                                                                                         }
9965                                                                                                                                         if(target>=0)player[target].Reverse();
9966                                                                                                                                 }
9967
9968                                                                                                                                 if(player[i].collided<1)player[i].jumpkeydown=0;
9969                                                                                                                                 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;
9970                                                                                                                                 if(normaldotproduct(player[i].facing,player[0].coords-player[i].coords)>0)
9971                                                                                                                                         player[0].jumpkeydown=0;
9972                                                                                                                                 if(player[0].targetanimation==jumpdownanim&&findDistancefast(&player[0].coords,&player[i].coords)<40)player[i].crouchkeydown=1;
9973                                                                                                                                 if(player[i].jumpkeydown)player[i].attackkeydown=0;
9974                                                                                                                                 //if(animation[player[i].targetanimation].attack==reversed)player[i].crouchkeydown=1;
9975
9976                                                                                                                                 if(tutoriallevel==1){
9977                                                                                                                                         if(!canattack)player[i].attackkeydown=0;
9978                                                                                                                                 }
9979
9980
9981                                                                                                                                 facing=player[i].coords;
9982                                                                                                                                 flatfacing=player[0].coords;
9983                                                                                                                                 facing.y+=player[i].skeleton.joints[player[i].skeleton.jointlabels[head]].position.y*player[i].scale;
9984                                                                                                                                 flatfacing.y+=player[0].skeleton.joints[player[0].skeleton.jointlabels[head]].position.y*player[0].scale;
9985                                                                                                                                 if(player[i].occluded>=2)
9986                                                                                                                                         if(-1!=checkcollide(facing,flatfacing)){
9987                                                                                                                                                 if(!player[i].pause)player[i].lastseentime-=.2;
9988                                                                                                                                                 if(player[i].lastseentime<=0&&(player[i].creature!=wolftype||player[i].weaponstuck==-1)){
9989                                                                                                                                                         player[i].aitype=searchtype;
9990                                                                                                                                                         player[i].lastchecktime=12;
9991                                                                                                                                                         player[i].lastseen=player[0].coords;
9992                                                                                                                                                         player[i].lastseentime=12;
9993                                                                                                                                                 }
9994                                                                                                                                         }
9995                                                                                                                                         else player[i].lastseentime=1;
9996                                                                                                                         }
9997                                                                                 }
9998                                                                                 if(animation[player[0].targetanimation].height==highheight&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype)){
9999                                                                                         if(player[0].coords.y>terrain.getHeight(player[0].coords.x,player[0].coords.z)+10){
10000                                                                                                 test=player[0].coords;
10001                                                                                                 test.y-=40;
10002                                                                                                 if(-1==checkcollide(player[0].coords,test))player[i].stunned=1;
10003                                                                                         }
10004                                                                                 }
10005                                                                                 // NOTE: Ask about logic of this call : NOTE
10006                                                                                 if((player[i].aitype==passivetype && !(player[i].numwaypoints>1)) ||
10007                                                                                         player[i].stunned>0 ||
10008                                                                                         (player[i].pause && (player[i].damage > player[i].superpermanentdamage)))
10009                                                                                 {
10010                                                                                         if(/*player[i].aitype==attacktypecutoff&&*/player[i].pause)player[i].lastseentime=1;
10011                                                                                         player[i].targetrotation=player[i].rotation;
10012                                                                                         player[i].forwardkeydown=0;
10013                                                                                         player[i].leftkeydown=0;
10014                                                                                         player[i].backkeydown=0;
10015                                                                                         player[i].rightkeydown=0;
10016                                                                                         player[i].jumpkeydown=0;
10017                                                                                         player[i].attackkeydown=0;
10018                                                                                         player[i].crouchkeydown=0;
10019                                                                                         player[i].throwkeydown=0;
10020                                                                                 }
10021
10022
10023                                                                                 facing=0;
10024                                                                                 facing.z=-1;
10025
10026                                                                                 flatfacing=DoRotation(facing,0,player[i].rotation+180,0);
10027                                                                                 facing=flatfacing;
10028
10029                                                                                 if(player[i].aitype==attacktypecutoff){
10030                                                                                         rotatetarget=player[0].coords-player[i].coords;
10031                                                                                         Normalise(&rotatetarget);
10032                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10033                                                                                         player[i].targetheadrotation*=360/6.28;
10034                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10035
10036                                                                                         player[i].targetheadrotation*=-1;
10037                                                                                         player[i].targetheadrotation+=180;
10038                                                                                         //player[i].targetheadrotation2=0;
10039                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10040                                                                                 }
10041                                                                                 else if(player[i].howactive>=typesleeping){
10042                                                                                         player[i].targetheadrotation=player[i].targetrotation;
10043                                                                                         player[i].targetheadrotation2=0;
10044                                                                                 }
10045                                                                                 else {
10046                                                                                         if(player[i].interestdelay<=0){
10047                                                                                                 player[i].interestdelay=.7+(float)(abs(Random()%100))/100;
10048                                                                                                 player[i].headtarget=player[i].coords;
10049                                                                                                 player[i].headtarget.x+=(float)(abs(Random()%200)-100)/100;
10050                                                                                                 player[i].headtarget.z+=(float)(abs(Random()%200)-100)/100;
10051                                                                                                 player[i].headtarget.y+=(float)(abs(Random()%200)-100)/300;
10052                                                                                                 player[i].headtarget+=player[i].facing*1.5;
10053                                                                                         }
10054                                                                                         rotatetarget=player[i].headtarget-player[i].coords;
10055                                                                                         Normalise(&rotatetarget);
10056                                                                                         player[i].targetheadrotation=-asin(0-rotatetarget.x);
10057                                                                                         player[i].targetheadrotation*=360/6.28;
10058                                                                                         if(rotatetarget.z<0)player[i].targetheadrotation=180-player[i].targetheadrotation;
10059
10060                                                                                         player[i].targetheadrotation*=-1;
10061                                                                                         player[i].targetheadrotation+=180;
10062                                                                                         player[i].targetheadrotation2=-asin(rotatetarget.y)*360/6.28;
10063                                                                                 }
10064                                                                                 //if(whichlevel==2)player[i].jumpkeydown=0;
10065                                                                         }
10066                                                                         if(animation[player[i].targetanimation].attack==reversed){
10067                                                                                 //player[i].targetrotation=player[i].rotation;
10068                                                                                 player[i].forwardkeydown=0;
10069                                                                                 player[i].leftkeydown=0;
10070                                                                                 player[i].backkeydown=0;
10071                                                                                 player[i].rightkeydown=0;
10072                                                                                 player[i].jumpkeydown=0;
10073                                                                                 player[i].attackkeydown=0;
10074                                                                                 //player[i].crouchkeydown=0;
10075                                                                                 player[i].throwkeydown=0;
10076                                                                         }
10077
10078                                                                         if(indialogue!=-1){
10079                                                                                 player[i].forwardkeydown=0;
10080                                                                                 player[i].leftkeydown=0;
10081                                                                                 player[i].backkeydown=0;
10082                                                                                 player[i].rightkeydown=0;
10083                                                                                 player[i].jumpkeydown=0;
10084                                                                                 player[i].crouchkeydown=0;
10085                                                                                 player[i].drawkeydown=0;
10086                                                                                 player[i].throwkeydown=0;
10087                                                                         }
10088
10089                                                                         if(player[i].collided<-.3)player[i].collided=-.3;
10090                                                                         if(player[i].collided>1)player[i].collided=1;
10091                                                                         player[i].collided-=multiplier*4;
10092                                                                         player[i].whichdirectiondelay-=multiplier;
10093                                                                         if(player[i].avoidcollided<-.3||player[i].whichdirectiondelay<=0){
10094                                                                                 player[i].avoidcollided=-.3;
10095                                                                                 player[i].whichdirection=abs(Random()%2);
10096                                                                                 player[i].whichdirectiondelay=.4;
10097                                                                         }
10098                                                                         if(player[i].avoidcollided>1)player[i].avoidcollided=1;
10099                                                                         player[i].avoidcollided-=multiplier/4;
10100                                                                         if(!player[i].skeleton.free)player[i].stunned-=multiplier;
10101                                                                         if(!player[i].skeleton.free)player[i].surprised-=multiplier;
10102                                                                         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;
10103
10104                                                                         if(!player[i].throwkeydown){
10105                                                                                 player[i].throwtogglekeydown=0;
10106                                                                         }
10107                                                                         if(player[i].throwkeydown&&!player[i].throwtogglekeydown){
10108                                                                                 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)){
10109                                                                                         for(j=0;j<weapons.numweapons;j++){
10110                                                                                                 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)
10111                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2){
10112                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<2){
10113                                                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].aitype!=playercontrolled){
10114                                                                                                                                 player[i].throwtogglekeydown=1;
10115                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10116                                                                                                                                 player[i].target=0;
10117                                                                                                                                 player[i].targetframe=0;
10118                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10119                                                                                                                                 Normalise(&rotatetarget);
10120                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10121                                                                                                                                 player[i].targetrotation*=360/6.28;
10122                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10123                                                                                                                                 player[i].hasvictim=0;
10124                                                                                                                         }
10125                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10126                                                                                                                                 player[i].throwtogglekeydown=1;
10127                                                                                                                                 player[i].hasvictim=0;
10128
10129                                                                                                                                 //for(i=0;i<weapons.numweapons;i++){
10130                                                                                                                                 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))
10131                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[j])<2&&player[i].weaponactive==-1){
10132                                                                                                                                                 if(findDistancefast(&player[i].coords,&weapons.position[j])<1||player[i].victim){
10133                                                                                                                                                         float gLoc[3];
10134                                                                                                                                                         float vel[3];
10135                                                                                                                                                         gLoc[0]=player[i].coords.x;
10136                                                                                                                                                         gLoc[1]=player[i].coords.y;
10137                                                                                                                                                         gLoc[2]=player[i].coords.z;
10138                                                                                                                                                         vel[0]=player[i].velocity.x;
10139                                                                                                                                                         vel[1]=player[i].velocity.y;
10140                                                                                                                                                         vel[2]=player[i].velocity.z;
10141                                                                                                                                                         if(weapons.type[j]!=staff){
10142                                                                                                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10143                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10144                                                                                                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
10145                                                                                                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
10146                                                                                                                                                         }
10147
10148                                                                                                                                                         player[i].weaponactive=0;
10149                                                                                                                                                         weapons.owner[j]=player[i].id;
10150                                                                                                                                                         if(player[i].num_weapons>0){
10151                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10152                                                                                                                                                         }
10153                                                                                                                                                         player[i].num_weapons++;
10154                                                                                                                                                         player[i].weaponids[0]=j;
10155                                                                                                                                                 }
10156                                                                                                                                         }
10157                                                                                                                                         //}
10158                                                                                                                         }
10159                                                                                                                 }
10160                                                                                                                 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){
10161                                                                                                                         if(!player[i].isFlip()){
10162                                                                                                                                 player[i].throwtogglekeydown=1;
10163                                                                                                                                 player[i].targetanimation=removeknifeanim;
10164                                                                                                                                 player[i].target=0;
10165                                                                                                                                 player[i].targetframe=0;
10166                                                                                                                                 rotatetarget=weapons.position[j]-player[i].coords;
10167                                                                                                                                 Normalise(&rotatetarget);
10168                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10169                                                                                                                                 player[i].targetrotation*=360/6.28;
10170                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10171                                                                                                                         }
10172                                                                                                                         if(player[i].isFlip()){
10173                                                                                                                                 player[i].throwtogglekeydown=1;
10174                                                                                                                                 player[i].hasvictim=0;
10175
10176                                                                                                                                 for(k=0;k<weapons.numweapons;k++){
10177                                                                                                                                         if(player[i].weaponactive==-1)
10178                                                                                                                                                 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))
10179                                                                                                                                                         if(findDistancefastflat(&player[i].coords,&weapons.position[k])<3&&player[i].weaponactive==-1){
10180                                                                                                                                                                 float gLoc[3];
10181                                                                                                                                                                 float vel[3];
10182                                                                                                                                                                 gLoc[0]=player[i].coords.x;
10183                                                                                                                                                                 gLoc[1]=player[i].coords.y;
10184                                                                                                                                                                 gLoc[2]=player[i].coords.z;
10185                                                                                                                                                                 vel[0]=player[i].velocity.x;
10186                                                                                                                                                                 vel[1]=player[i].velocity.y;
10187                                                                                                                                                                 vel[2]=player[i].velocity.z;
10188                                                                                                                                                                 if(weapons.type[k]!=staff){
10189                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10190                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10191                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
10192                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
10193                                                                                                                                                                 }
10194
10195                                                                                                                                                                 player[i].weaponactive=0;
10196                                                                                                                                                                 weapons.owner[k]=player[i].id;
10197                                                                                                                                                                 if(player[i].num_weapons>0){
10198                                                                                                                                                                         player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10199                                                                                                                                                                 }
10200                                                                                                                                                                 player[i].num_weapons++;
10201                                                                                                                                                                 player[i].weaponids[0]=k;
10202                                                                                                                                                         }
10203                                                                                                                                 }
10204                                                                                                                         }
10205                                                                                                                 }
10206                                                                                                         }
10207                                                                                         }
10208                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isRun()||player[i].isIdle()||player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10209                                                                                                 if(numplayers>1)
10210                                                                                                         for(j=0;j<numplayers;j++){
10211                                                                                                                 if(player[i].weaponactive==-1)
10212                                                                                                                         if(j!=i)
10213                                                                                                                                 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)){
10214                                                                                                                                         if(player[i].targetanimation!=rollanim&&player[i].targetanimation!=backhandspringanim){
10215                                                                                                                                                 player[i].throwtogglekeydown=1;
10216                                                                                                                                                 player[i].victim=&player[j];
10217                                                                                                                                                 player[i].hasvictim=1;
10218                                                                                                                                                 player[i].targetanimation=crouchremoveknifeanim;
10219                                                                                                                                                 player[i].target=0;
10220                                                                                                                                                 player[i].targetframe=0;
10221                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10222                                                                                                                                                 Normalise(&rotatetarget);
10223                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10224                                                                                                                                                 player[i].targetrotation*=360/6.28;
10225                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10226                                                                                                                                         }
10227                                                                                                                                         if(player[i].targetanimation==rollanim||player[i].targetanimation==backhandspringanim){
10228                                                                                                                                                 player[i].throwtogglekeydown=1;
10229                                                                                                                                                 player[i].victim=&player[j];
10230                                                                                                                                                 player[i].hasvictim=1;
10231                                                                                                                                                 int k = player[j].weaponids[0];
10232                                                                                                                                                 if(player[i].hasvictim){
10233                                                                                                                                                         float gLoc[3];
10234                                                                                                                                                         float vel[3];
10235                                                                                                                                                         gLoc[0]=player[i].coords.x;
10236                                                                                                                                                         gLoc[1]=player[i].coords.y;
10237                                                                                                                                                         gLoc[2]=player[i].coords.z;
10238                                                                                                                                                         vel[0]=player[i].velocity.x;
10239                                                                                                                                                         vel[1]=player[i].velocity.y;
10240                                                                                                                                                         vel[2]=player[i].velocity.z;
10241                                                                                                                                                         bool fleshstuck;
10242                                                                                                                                                         fleshstuck=0;
10243                                                                                                                                                         if(player[i].victim->weaponstuck!=-1){
10244                                                                                                                                                                 if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10245                                                                                                                                                                         fleshstuck=1;
10246                                                                                                                                                                 }
10247                                                                                                                                                         }
10248                                                                                                                                                         if(!fleshstuck){
10249                                                                                                                                                                 if(weapons.type[k]!=staff){
10250                                                                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
10251                                                                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
10252                                                                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
10253                                                                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
10254                                                                                                                                                                 }
10255                                                                                                                                                         }
10256                                                                                                                                                         if(fleshstuck){
10257                                                                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
10258                                                                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
10259                                                                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
10260                                                                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
10261                                                                                                                                                         }
10262
10263                                                                                                                                                         player[i].weaponactive=0;
10264                                                                                                                                                         if(weapons.owner[k]!=-1){
10265                                                                                                                                                                 if(player[i].victim->num_weapons==1)player[i].victim->num_weapons=0;
10266                                                                                                                                                                 else player[i].victim->num_weapons=1;
10267
10268                                                                                                                                                                 player[i].victim->skeleton.longdead=0;
10269                                                                                                                                                                 player[i].victim->skeleton.free=1;
10270                                                                                                                                                                 player[i].victim->skeleton.broken=0;
10271
10272                                                                                                                                                                 for(int l=0;l<player[i].victim->skeleton.num_joints;l++){
10273                                                                                                                                                                         player[i].victim->skeleton.joints[l].velchange=0;
10274                                                                                                                                                                         player[i].victim->skeleton.joints[l].locked=0;
10275                                                                                                                                                                 }
10276
10277                                                                                                                                                                 XYZ relative;
10278                                                                                                                                                                 relative=0;
10279                                                                                                                                                                 relative.y=10;
10280                                                                                                                                                                 Normalise(&relative);
10281                                                                                                                                                                 XYZ footvel,footpoint;
10282                                                                                                                                                                 footvel=0;
10283                                                                                                                                                                 footpoint=weapons.position[k];
10284                                                                                                                                                                 if(player[i].victim->weaponstuck!=-1){
10285                                                                                                                                                                         if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
10286                                                                                                                                                                                 if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
10287                                                                                                                                                                                 weapons.bloody[k]=2;
10288                                                                                                                                                                                 weapons.blooddrip[k]=5;
10289                                                                                                                                                                                 player[i].victim->weaponstuck=-1;
10290                                                                                                                                                                                 player[i].victim->bloodloss+=2000;
10291                                                                                                                                                                                 player[i].victim->DoDamage(2000);
10292                                                                                                                                                                         }
10293                                                                                                                                                                 }
10294                                                                                                                                                                 if(player[i].victim->num_weapons>0){
10295                                                                                                                                                                         if(player[i].victim->weaponstuck!=0&&player[i].victim->weaponstuck!=-1)player[i].victim->weaponstuck=0;
10296                                                                                                                                                                         if(player[i].victim->weaponids[0]==k)
10297                                                                                                                                                                                 player[i].victim->weaponids[0]=player[i].victim->weaponids[player[i].victim->num_weapons];
10298                                                                                                                                                                 }
10299
10300                                                                                                                                                                 player[i].victim->weaponactive=-1;
10301
10302                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
10303                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[neck]].velocity+=relative*6;
10304                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
10305                                                                                                                                                                 player[i].victim->skeleton.joints[player[i].victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
10306                                                                                                                                                         }
10307                                                                                                                                                         weapons.owner[k]=i;
10308                                                                                                                                                         if(player[i].num_weapons>0){
10309                                                                                                                                                                 player[i].weaponids[player[i].num_weapons]=player[i].weaponids[0];
10310                                                                                                                                                         }
10311                                                                                                                                                         player[i].num_weapons++;
10312                                                                                                                                                         player[i].weaponids[0]=k;
10313                                                                                                                                                 }
10314                                                                                                                                         }
10315                                                                                                                                 }
10316                                                                                                         }
10317                                                                                         }
10318                                                                                 }
10319                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10320                                                                                         if(weapons.type[player[i].weaponids[0]]==knife){
10321                                                                                                 if(player[i].isIdle()||player[i].isRun()||player[i].isCrouch()||player[i].targetanimation==sneakanim||player[i].isFlip())
10322                                                                                                         if(numplayers>1)
10323                                                                                                                 for(j=0;j<numplayers;j++){
10324                                                                                                                         if(i!=j)
10325                                                                                                                                 if(tutoriallevel!=1||tutorialstage==49)
10326                                                                                                                                         if(hostile)
10327                                                                                                                                                 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)){
10328                                                                                                                                                         if(!player[i].isFlip()){
10329                                                                                                                                                                 player[i].throwtogglekeydown=1;
10330                                                                                                                                                                 player[i].victim=&player[j];
10331                                                                                                                                                                 player[i].targetanimation=knifethrowanim;
10332                                                                                                                                                                 player[i].target=0;
10333                                                                                                                                                                 player[i].targetframe=0;
10334                                                                                                                                                                 rotatetarget=player[j].coords-player[i].coords;
10335                                                                                                                                                                 Normalise(&rotatetarget);
10336                                                                                                                                                                 player[i].targetrotation=-asin(0-rotatetarget.x);
10337                                                                                                                                                                 player[i].targetrotation*=360/6.28;
10338                                                                                                                                                                 if(rotatetarget.z<0)player[i].targetrotation=180-player[i].targetrotation;
10339
10340                                                                                                                                                                 player[i].targettilt2=-asin(rotatetarget.y)*360/6.28;
10341                                                                                                                                                         }
10342                                                                                                                                                         if(player[i].isFlip()){
10343                                                                                                                                                                 if(player[i].weaponactive!=-1){
10344                                                                                                                                                                         player[i].throwtogglekeydown=1;
10345                                                                                                                                                                         player[i].victim=&player[j];
10346                                                                                                                                                                         XYZ aim;
10347                                                                                                                                                                         weapons.owner[player[i].weaponids[0]]=-1;
10348                                                                                                                                                                         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);
10349                                                                                                                                                                         Normalise(&aim);
10350
10351                                                                                                                                                                         aim=DoRotation(aim,(float)abs(Random()%30)-15,(float)abs(Random()%30)-15,0);
10352
10353                                                                                                                                                                         weapons.velocity[player[i].weaponids[0]]=aim*50;
10354                                                                                                                                                                         weapons.tipvelocity[player[i].weaponids[0]]=aim*50;
10355                                                                                                                                                                         weapons.missed[player[i].weaponids[0]]=0;
10356                                                                                                                                                                         weapons.freetime[player[i].weaponids[0]]=0;
10357                                                                                                                                                                         weapons.firstfree[player[i].weaponids[0]]=1;
10358                                                                                                                                                                         weapons.physics[player[i].weaponids[0]]=0;
10359                                                                                                                                                                         player[i].num_weapons--;
10360                                                                                                                                                                         if(player[i].num_weapons){
10361                                                                                                                                                                                 player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10362                                                                                                                                                                         }
10363                                                                                                                                                                         player[i].weaponactive=-1;
10364                                                                                                                                                                 }
10365                                                                                                                                                         }
10366                                                                                                                                                 }
10367                                                                                                                 }
10368                                                                                         }
10369                                                                                 }
10370                                                                                 if(player[i].weaponactive!=-1&&player[i].aitype==playercontrolled){
10371                                                                                         if(player[i].isCrouch()||player[i].targetanimation==sneakanim)
10372                                                                                         {
10373                                                                                                 player[i].throwtogglekeydown=1;
10374                                                                                                 weapons.owner[player[i].weaponids[0]]=-1;
10375                                                                                                 weapons.velocity[player[i].weaponids[0]]=player[i].velocity*.2;
10376                                                                                                 if(weapons.velocity[player[i].weaponids[0]].x==0)weapons.velocity[player[i].weaponids[0]].x=.1;
10377                                                                                                 weapons.tipvelocity[player[i].weaponids[0]]=weapons.velocity[player[i].weaponids[0]];
10378                                                                                                 weapons.missed[player[i].weaponids[0]]=1;
10379                                                                                                 weapons.freetime[player[i].weaponids[0]]=0;
10380                                                                                                 weapons.firstfree[player[i].weaponids[0]]=1;
10381                                                                                                 weapons.physics[player[i].weaponids[0]]=1;
10382                                                                                                 player[i].num_weapons--;
10383                                                                                                 if(player[i].num_weapons){
10384                                                                                                         player[i].weaponids[0]=player[i].weaponids[player[i].num_weapons];
10385                                                                                                         if(player[i].weaponstuck==player[i].num_weapons)player[i].weaponstuck=0;
10386                                                                                                 }
10387
10388                                                                                                 player[i].weaponactive=-1;
10389                                                                                                 for(j=0;j<numplayers;j++){
10390                                                                                                         player[j].wentforweapon=0;
10391                                                                                                 }
10392                                                                                         }
10393                                                                                 }
10394
10395                                                                         }
10396
10397                                                                         if(i==0||!player[0].dead||player[i].weaponactive!=-1)
10398                                                                                 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)){
10399                                                                                         //Setenvironment(1-environment);
10400                                                                                         bool isgood;
10401                                                                                         isgood=1;
10402                                                                                         if(player[i].weaponactive!=-1){
10403                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==staff)isgood=0;
10404                                                                                         }
10405                                                                                         if(/*(player[i].weaponactive==-1||player[i].num_weapons==1)&&*/isgood&&player[i].creature!=wolftype){
10406                                                                                                 if(player[i].isIdle()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10407                                                                                                         player[i].targetanimation=drawrightanim;
10408                                                                                                         player[i].targetframe=0;
10409                                                                                                         player[i].target=0;
10410                                                                                                         player[i].drawtogglekeydown=1;
10411                                                                                                 }
10412                                                                                                 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){
10413                                                                                                         player[i].targetanimation=drawleftanim;
10414                                                                                                         player[i].targetframe=0;
10415                                                                                                         player[i].target=0;
10416                                                                                                         player[i].drawtogglekeydown=1;
10417                                                                                                 }
10418                                                                                                 if(player[i].isCrouch()&&player[i].num_weapons&&weapons.type[player[i].weaponids[0]]==knife){
10419                                                                                                         player[i].targetanimation=crouchdrawrightanim;
10420                                                                                                         player[i].targetframe=0;
10421                                                                                                         player[i].target=0;
10422                                                                                                         player[i].drawtogglekeydown=1;
10423                                                                                                 }
10424                                                                                         }
10425                                                                                 }
10426                                                                                 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){
10427                                                                                         if(weapons.bloody[player[i].weaponids[player[i].weaponactive]]&&player[i].onterrain&&bloodtoggle&&musictype!=stream_music2){
10428                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==knife)player[i].targetanimation=crouchstabanim;
10429                                                                                                 if(weapons.type[player[i].weaponids[player[i].weaponactive]]==sword)player[i].targetanimation=swordgroundstabanim;
10430                                                                                                 player[i].targetframe=0;
10431                                                                                                 player[i].target=0;
10432                                                                                                 player[i].hasvictim=0;
10433                                                                                                 //player[i].attacktogglekeydown=1;
10434                                                                                         }
10435                                                                                 }
10436
10437                                                                                 if(!player[i].drawkeydown){
10438                                                                                         player[i].drawtogglekeydown=0;
10439                                                                                 }
10440
10441                                                                                 if(i==0){
10442                                                                                         absflatfacing=0;
10443                                                                                         absflatfacing.z=-1;
10444
10445                                                                                         absflatfacing=DoRotation(absflatfacing,0,-rotation,0);
10446                                                                                 }
10447                                                                                 else absflatfacing=flatfacing;
10448
10449                                                                                 if(indialogue!=-1){
10450                                                                                         player[i].forwardkeydown=0;
10451                                                                                         player[i].leftkeydown=0;
10452                                                                                         player[i].backkeydown=0;
10453                                                                                         player[i].rightkeydown=0;
10454                                                                                         player[i].jumpkeydown=0;
10455                                                                                         player[i].crouchkeydown=0;
10456                                                                                         player[i].drawkeydown=0;
10457                                                                                         player[i].throwkeydown=0;
10458                                                                                 }
10459                                                                                 movekey=0;
10460                                                                                 //Do controls
10461                                                                                 if(!animation[player[i].targetanimation].attack&&player[i].targetanimation!=staggerbackhighanim&&player[i].targetanimation!=staggerbackhardanim&&player[i].targetanimation!=backhandspringanim&&player[i].targetanimation!=dodgebackanim){
10462                                                                                         if(!player[i].forwardkeydown){
10463                                                                                                 player[i].forwardstogglekeydown=0;
10464                                                                                         }
10465                                                                                         if(player[i].crouchkeydown){
10466                                                                                                 //Crouch
10467                                                                                                 target=-2;
10468                                                                                                 if(i==0){
10469                                                                                                         player[i].superruntoggle=1;
10470                                                                                                         if(numplayers>1)
10471                                                                                                                 for(j=0;j<numplayers;j++){
10472                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].aitype==passivetype){
10473                                                                                                                                 if(findDistancefast(&player[j].coords,&player[i].coords)<16){
10474                                                                                                                                         player[i].superruntoggle=0;
10475                                                                                                                                 }
10476                                                                                                                         }
10477                                                                                                                 }
10478                                                                                                 }
10479
10480                                                                                                 if(numplayers>1)
10481                                                                                                         for(j=0;j<numplayers;j++){
10482                                                                                                                 if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].lowreversaldelay<=0){
10483                                                                                                                         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))){
10484                                                                                                                                 if(target>=0)target=-1;
10485                                                                                                                                 else target=j;
10486                                                                                                                         }
10487                                                                                                                 }
10488                                                                                                         }
10489                                                                                                         if(target>=0)player[target].Reverse();
10490                                                                                                         player[i].lowreversaldelay=.5;
10491
10492                                                                                                         if(player[i].isIdle()){
10493                                                                                                                 player[i].targetanimation=player[i].getCrouch();
10494                                                                                                                 player[i].target=0;
10495                                                                                                                 player[i].targetframe=0;
10496                                                                                                                 player[i].transspeed=10;
10497                                                                                                         }
10498                                                                                                         if(player[i].isRun()||(player[i].isStop()&&(player[i].leftkeydown||player[i].rightkeydown||player[i].forwardkeydown||player[i].backkeydown))){
10499                                                                                                                 player[i].targetanimation=rollanim;
10500                                                                                                                 player[i].target=0;
10501                                                                                                                 player[i].targetframe=0;
10502                                                                                                                 player[i].transspeed=20;
10503                                                                                                         }
10504                                                                                         }
10505                                                                                         if(!player[i].crouchkeydown){
10506                                                                                                 //Uncrouch
10507                                                                                                 if(!player[i].isRun()&&player[i].targetanimation!=sneakanim&&i==0)player[i].superruntoggle=0;
10508                                                                                                 target=-2;
10509                                                                                                 if(player[i].isCrouch()){
10510                                                                                                         if(numplayers>1)
10511                                                                                                                 for(j=0;j<numplayers;j++){
10512                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim&&player[i].highreversaldelay<=0){
10513                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==spinkickanim)&&player[i].isCrouch()){
10514                                                                                                                                         if(target>=0)target=-1;
10515                                                                                                                                         else target=j;
10516                                                                                                                                 }
10517                                                                                                                         }
10518                                                                                                                 }
10519                                                                                                                 if(target>=0)player[target].Reverse();
10520                                                                                                                 player[i].highreversaldelay=.5;
10521
10522                                                                                                                 if(player[i].isCrouch()){
10523                                                                                                                         if(!player[i].wasCrouch()){
10524                                                                                                                                 player[i].currentanimation=player[i].getCrouch();
10525                                                                                                                                 player[i].currentframe=0;
10526                                                                                                                         }
10527                                                                                                                         player[i].target=0;
10528                                                                                                                         player[i].targetanimation=player[i].getIdle();
10529                                                                                                                         player[i].targetframe=0;
10530                                                                                                                         player[i].transspeed=10;
10531                                                                                                                 }
10532                                                                                                 }
10533                                                                                                 if(player[i].targetanimation==sneakanim){
10534                                                                                                         player[i].targetanimation=player[i].getIdle();
10535                                                                                                         player[i].target=0;
10536                                                                                                         player[i].targetframe=0;
10537                                                                                                         player[i].transspeed=10;
10538                                                                                                 }
10539                                                                                         }
10540                                                                                         if(player[i].forwardkeydown){
10541                                                                                                 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)){
10542                                                                                                         if(player[i].aitype==passivetype)player[i].targetanimation=walkanim;
10543                                                                                                         else player[i].targetanimation=player[i].getRun();
10544                                                                                                         player[i].target=0;
10545                                                                                                         player[i].targetframe=0;
10546                                                                                                 }
10547                                                                                                 if(player[i].isCrouch()){
10548                                                                                                         player[i].targetanimation=sneakanim;
10549                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10550                                                                                                         player[i].targetframe=0;
10551                                                                                                 }
10552                                                                                                 if(player[i].targetanimation==hanganim/*&&(!player[i].forwardstogglekeydown||player[i].aitype!=playercontrolled)*/){
10553                                                                                                         player[i].targetanimation=climbanim;
10554                                                                                                         player[i].target=0;
10555                                                                                                         player[i].targetframe=1;
10556                                                                                                         player[i].jumpclimb=1;
10557                                                                                                 }
10558                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10559                                                                                                         player[i].velocity+=absflatfacing*5*multiplier;
10560                                                                                                 }
10561                                                                                                 player[i].forwardstogglekeydown=1;
10562                                                                                                 movekey=1;
10563                                                                                         }
10564                                                                                         if (player[i].rightkeydown){
10565                                                                                                 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)){
10566                                                                                                         player[i].targetanimation=player[i].getRun();
10567                                                                                                         player[i].target=0;
10568                                                                                                         player[i].targetframe=0;
10569                                                                                                 }
10570                                                                                                 if(player[i].isCrouch()){
10571                                                                                                         player[i].targetanimation=sneakanim;
10572                                                                                                         if(player[i].wasCrouch()) player[i].target=0;
10573                                                                                                         player[i].targetframe=0;
10574                                                                                                 }
10575                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10576                                                                                                         player[i].velocity+=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10577                                                                                                 }
10578                                                                                                 player[i].targetrotation-=90;
10579                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation+=45;
10580                                                                                                 if(player[i].backkeydown)player[i].targetrotation-=45;
10581                                                                                                 movekey=1;
10582                                                                                         }
10583                                                                                         if ( player[i].leftkeydown){
10584                                                                                                 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)){
10585                                                                                                         player[i].targetanimation=player[i].getRun();
10586                                                                                                         player[i].target=0;
10587                                                                                                         player[i].targetframe=0;
10588                                                                                                 }
10589                                                                                                 if(player[i].isCrouch()){
10590                                                                                                         player[i].targetanimation=sneakanim;
10591                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10592                                                                                                         player[i].targetframe=0;
10593                                                                                                 }
10594                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10595                                                                                                         player[i].velocity-=DoRotation(absflatfacing*5*multiplier,0,-90,0);
10596                                                                                                 }
10597                                                                                                 player[i].targetrotation+=90;
10598                                                                                                 if(player[i].forwardkeydown)player[i].targetrotation-=45;
10599                                                                                                 if(player[i].backkeydown)player[i].targetrotation+=45;
10600                                                                                                 movekey=1;
10601                                                                                         }
10602                                                                                         if(player[i].backkeydown){
10603                                                                                                 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)){
10604                                                                                                         player[i].targetanimation=player[i].getRun();
10605                                                                                                         player[i].target=0;
10606                                                                                                         player[i].targetframe=0;
10607                                                                                                 }
10608                                                                                                 if(player[i].isCrouch()){
10609                                                                                                         player[i].targetanimation=sneakanim;
10610                                                                                                         if(player[i].wasCrouch())player[i].target=0;
10611                                                                                                         player[i].targetframe=0;
10612                                                                                                 }
10613                                                                                                 if(player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip()){
10614                                                                                                         player[i].velocity-=absflatfacing*5*multiplier;
10615                                                                                                 }
10616                                                                                                 if(player[i].targetanimation==hanganim){
10617                                                                                                         player[i].currentanimation=jumpdownanim;
10618                                                                                                         player[i].targetanimation=jumpdownanim;
10619                                                                                                         player[i].target=0;
10620                                                                                                         player[i].currentframe=0;
10621                                                                                                         player[i].targetframe=1;
10622                                                                                                         player[i].velocity=0;
10623                                                                                                         player[i].velocity.y+=gravity;
10624                                                                                                         player[i].coords.y-=1.4;
10625                                                                                                         player[i].grabdelay=1;
10626                                                                                                 }
10627                                                                                                 if ( !player[i].leftkeydown&&!player[i].rightkeydown)
10628                                                                                                         player[i].targetrotation+=180;
10629                                                                                                 movekey=1;
10630                                                                                         }
10631                                                                                         if((player[i].jumpkeydown&&!player[i].jumpclimb)||player[i].jumpstart){
10632                                                                                                 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)){
10633                                                                                                         player[i].jumpstart=0;
10634                                                                                                         player[i].targetanimation=jumpupanim;
10635                                                                                                         player[i].target=0;
10636                                                                                                         player[i].targetframe=0;
10637                                                                                                         player[i].rotation=player[i].targetrotation;
10638                                                                                                         player[i].transspeed=20;
10639                                                                                                         player[i].FootLand(0,1);
10640                                                                                                         player[i].FootLand(1,1);
10641
10642                                                                                                         facing=0;
10643                                                                                                         facing.z=-1;
10644                                                                                                         flatfacing=DoRotation(facing,0,player[i].targetrotation+180,0);
10645
10646                                                                                                         if(movekey)player[i].velocity=flatfacing*player[i].speed*45*player[i].scale;
10647                                                                                                         if(!movekey)player[i].velocity=0;
10648
10649                                                                                                         //Dodge sweep?
10650                                                                                                         target=-2;
10651                                                                                                         if(numplayers>1)
10652                                                                                                                 for(j=0;j<numplayers;j++){
10653                                                                                                                         if(j!=i&&!player[j].skeleton.free&&player[j].victim){
10654                                                                                                                                 if(findDistancefast(&player[j].coords,&player[j].victim->coords)<3&&player[j].victim==&player[i]&&(player[j].targetanimation==sweepanim)){
10655                                                                                                                                         if(target>=0)target=-1;
10656                                                                                                                                         else target=j;
10657                                                                                                                                 }
10658                                                                                                                         }
10659                                                                                                                 }
10660                                                                                                                 if(target>=0)player[i].velocity.y=1;
10661                                                                                                                 else if(player[i].crouchkeydown||player[i].aitype!=playercontrolled){
10662                                                                                                                         player[i].velocity.y=7;
10663                                                                                                                         player[i].crouchtogglekeydown=1;
10664                                                                                                                 }
10665                                                                                                                 else player[i].velocity.y=5;
10666
10667                                                                                                                 if(mousejump&&i==0&&debugmode){
10668                                                                                                                         if(!player[i].isLanding())player[i].tempdeltav=deltav;
10669                                                                                                                         if(player[i].tempdeltav<0)player[i].velocity.y-=(float)(player[i].tempdeltav)/multiplier/1000;
10670                                                                                                                 }
10671
10672                                                                                                                 player[i].coords.y+=.2;
10673                                                                                                                 player[i].jumppower-=1;
10674
10675                                                                                                                 static float gLoc[3];
10676                                                                                                                 static float vel[3];
10677                                                                                                                 gLoc[0]=player[i].coords.x;
10678                                                                                                                 gLoc[1]=player[i].coords.y;
10679                                                                                                                 gLoc[2]=player[i].coords.z;
10680                                                                                                                 vel[0]=player[i].velocity.x;
10681                                                                                                                 vel[1]=player[i].velocity.y;
10682                                                                                                                 vel[2]=player[i].velocity.z;
10683
10684                                                                                                                 if(i==0){
10685                                                                                                                         PlaySoundEx( whooshsound, samp[whooshsound], NULL, true);
10686                                                                                                                         OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
10687                                                                                                                         OPENAL_SetVolume(channels[whooshsound], 128);
10688                                                                                                                         OPENAL_SetPaused(channels[whooshsound], false);
10689                                                                                                                 }
10690
10691                                                                                                                 PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
10692                                                                                                                 OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
10693                                                                                                                 OPENAL_SetVolume(channels[jumpsound], 128);
10694                                                                                                                 OPENAL_SetPaused(channels[jumpsound], false);
10695                                                                                                 }
10696                                                                                                 if((player[i].isIdle())&&player[i].jumppower>1){
10697                                                                                                         player[i].targetanimation=player[i].getLanding();
10698                                                                                                         player[i].landhard=0;
10699                                                                                                         player[i].target=0;
10700                                                                                                         player[i].targetframe=2;
10701                                                                                                         player[i].jumpstart=1;
10702                                                                                                         player[i].tempdeltav=deltav;
10703                                                                                                 }
10704                                                                                                 if(player[i].targetanimation==jumpupanim&&(((!floatjump&&!editorenabled)||!debugmode)||player[i].aitype!=playercontrolled)){
10705                                                                                                         if(player[i].jumppower>multiplier*6){
10706                                                                                                                 player[i].velocity.y+=multiplier*6;
10707                                                                                                                 player[i].jumppower-=multiplier*6;
10708                                                                                                         }
10709                                                                                                         if(player[i].jumppower<=multiplier*6){
10710                                                                                                                 player[i].velocity.y+=player[i].jumppower;
10711                                                                                                                 player[i].jumppower=0;
10712                                                                                                         }
10713                                                                                                 }
10714                                                                                                 if(((floatjump||editorenabled)&&debugmode)&&i==0)player[i].velocity.y+=multiplier*30;
10715                                                                                         }
10716
10717                                                                                         if(!movekey){
10718                                                                                                 if(player[i].isRun()||player[i].targetanimation==walkanim){
10719                                                                                                         player[i].targetanimation=player[i].getStop();
10720                                                                                                         player[i].target=0;
10721                                                                                                         player[i].targetframe=0;
10722                                                                                                 }
10723                                                                                                 if(player[i].targetanimation==sneakanim){
10724                                                                                                         player[i].targetanimation=player[i].getCrouch();
10725                                                                                                         if(player[i].currentanimation==sneakanim)player[i].target=0;
10726                                                                                                         player[i].targetframe=0;
10727                                                                                                 }
10728                                                                                         }
10729                                                                                         if(player[i].targetanimation==walkanim&&(player[i].aitype==attacktypecutoff||player[i].aitype==searchtype||(player[i].aitype==passivetype&&player[i].numwaypoints<=1))){
10730                                                                                                 player[i].targetanimation=player[i].getStop();
10731                                                                                                 player[i].target=0;
10732                                                                                                 player[i].targetframe=0;
10733                                                                                         }
10734                                                                                         if(player[i].isRun()&&(player[i].aitype==passivetype)){
10735                                                                                                 player[i].targetanimation=player[i].getStop();
10736                                                                                                 player[i].target=0;
10737                                                                                                 player[i].targetframe=0;
10738                                                                                         }
10739                                                                                 }
10740                                                                 }
10741                                                                 if(player[i].targetanimation==rollanim)player[i].targetrotation=oldtargetrotation;
10742                                                         }
10743
10744                                                         //Rotation
10745                                                         for(k=0;k<numplayers;k++){
10746                                                                 if(abs(player[k].rotation-player[k].targetrotation)>180){
10747                                                                         if(player[k].rotation>player[k].targetrotation)player[k].rotation-=360;
10748                                                                         else player[k].rotation+=360;
10749                                                                 }
10750
10751                                                                 if(abs(player[k].rotation-player[k].targetrotation)>90&&(player[k].isRun()||player[k].targetanimation==walkanim)){
10752                                                                         player[k].targetanimation=player[k].getStop();
10753                                                                         player[k].targetframe=0;
10754                                                                         player[k].target=0;
10755                                                                 }
10756
10757                                                                 if(player[k].targetanimation==backhandspringanim||player[k].targetanimation==dodgebackanim){
10758                                                                         player[k].targettilt=0;
10759                                                                 }
10760                                                                 if(player[k].targetanimation!=jumpupanim&&player[k].targetanimation!=backhandspringanim&&player[k].targetanimation!=jumpdownanim&&!player[k].isFlip()){
10761                                                                         player[k].targettilt=0;
10762                                                                         if(player[k].jumppower<0&&!player[k].jumpkeydown)player[k].jumppower=0;
10763                                                                         player[k].jumppower+=multiplier*7;
10764                                                                         if(player[k].isCrouch())player[k].jumppower+=multiplier*7;
10765                                                                         //*(1-(player[k].damage/player[k].damagetolerance))
10766                                                                         if(player[k].jumppower>5)player[k].jumppower=5;
10767                                                                 }
10768
10769                                                                 if(player[k].isRun()){
10770                                                                         player[k].targettilt=(player[k].rotation-player[k].targetrotation)/4;
10771                                                                 }
10772
10773                                                                 if(abs(player[k].tilt-player[k].targettilt)<multiplier*150)player[k].tilt=player[k].targettilt;
10774                                                                 else if(player[k].tilt>player[k].targettilt){
10775                                                                         player[k].tilt-=multiplier*150;
10776                                                                 }
10777                                                                 else if(player[k].tilt<player[k].targettilt){
10778                                                                         player[k].tilt+=multiplier*150;
10779                                                                 }
10780
10781                                                                 player[k].grabdelay-=multiplier;
10782                                                         }
10783
10784                                                         for(k=0;k<numplayers;k++){
10785                                                                 player[k].DoAnimations();
10786                                                                 player[k].whichpatchx=player[k].coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
10787                                                                 player[k].whichpatchz=player[k].coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
10788                                                         }
10789
10790                                                         objects.DoStuff();
10791                                                         /*
10792                                                         player[0].righthandmorphstart=0;
10793                                                         player[0].righthandmorphend=1;
10794                                                         player[0].lefthandmorphstart=0;
10795                                                         player[0].lefthandmorphend=1;
10796                                                         player[0].headmorphstart=0;
10797                                                         player[0].headmorphend=2;*/
10798
10799                                                         /*
10800                                                         if(IsKeyDown( theKeyMap, MAC_P_KEY )){
10801                                                         if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
10802                                                         player[0].righthandmorphend=1;
10803                                                         player[0].targetrighthandmorphness=1;
10804
10805                                                         if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
10806                                                         player[0].lefthandmorphend=0;
10807                                                         player[0].targetlefthandmorphness=1;
10808
10809                                                         if(player[0].headmorphend!=2)player[0].headmorphness=0;
10810                                                         player[0].headmorphend=2;
10811                                                         player[0].targetheadmorphness=1;
10812                                                         }
10813                                                         if(IsKeyDown( theKeyMap, MAC_L_KEY )){
10814                                                         if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
10815                                                         player[0].righthandmorphend=0;
10816                                                         player[0].targetrighthandmorphness=1;
10817
10818                                                         if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
10819                                                         player[0].lefthandmorphend=1;
10820                                                         player[0].targetlefthandmorphness=1;
10821
10822                                                         if(player[0].headmorphend!=0)player[0].headmorphness=0;
10823                                                         player[0].headmorphend=0;
10824                                                         player[0].targetheadmorphness=1;
10825                                                         }
10826                                                         */
10827                                                         if(numenvsounds!=0)
10828                                                                 for(j=numenvsounds-1;j>=0;j--){
10829                                                                         envsoundlife[j]-=multiplier;
10830                                                                         if(envsoundlife[j]<0){
10831                                                                                 numenvsounds--;
10832                                                                                 envsoundlife[j]=envsoundlife[numenvsounds];
10833                                                                                 envsound[j]=envsound[numenvsounds];
10834                                                                         }
10835                                                                 }
10836                                                                 if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
10837                                                                 if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
10838
10839                                                                 if(tutoriallevel==1){
10840                                                                         XYZ temp;
10841                                                                         XYZ temp2;
10842                                                                         XYZ temp3;
10843                                                                         XYZ oldtemp;
10844                                                                         XYZ oldtemp2;
10845                                                                         temp.x=1011;
10846                                                                         temp.y=84;
10847                                                                         temp.z=491;
10848                                                                         temp2.x=1025;
10849                                                                         temp2.y=75;
10850                                                                         temp2.z=447;
10851                                                                         temp3.x=1038;
10852                                                                         temp3.y=76;
10853                                                                         temp3.z=453;
10854                                                                         oldtemp=temp;
10855                                                                         oldtemp2=temp2;
10856                                                                         if(tutorialstage>=51)
10857                                                                                 if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10858                                                     OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
10859                                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
10860
10861                                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
10862                                                                                         OPENAL_SetPaused(channels[stream_music3], false);
10863                                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
10864
10865                                                                                         gameon=0;
10866                                                                                         mainmenu=5;
10867
10868                                                                                         float gLoc[3]={0,0,0};
10869                                                                                         float vel[3]={0,0,0};
10870                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
10871                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10872                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10873                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10874                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10875                                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
10876
10877                                                                                         flashr=1;
10878                                                                                         flashg=0;
10879                                                                                         flashb=0;
10880                                                                                         flashamount=1;
10881                                                                                         flashdelay=1;
10882                                                                                 }
10883                                                                                 if(tutorialstage<51)
10884                                                                                         if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
10885                                                                                                 float gLoc[3];
10886                                                                                                 float vel[3];
10887                                                                                                 gLoc[0]=player[0].coords.x;
10888                                                                                                 gLoc[1]=player[0].coords.y;
10889                                                                                                 gLoc[2]=player[0].coords.z;
10890                                                                                                 vel[0]=0;
10891                                                                                                 vel[1]=0;
10892                                                                                                 vel[2]=0;
10893                                                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10894                                                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10895                                                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
10896                                                                                                 OPENAL_SetPaused(channels[fireendsound], false);
10897
10898                                                                                                 player[0].coords=(oldtemp+oldtemp2)/2;
10899
10900                                                                                                 flashr=1;
10901                                                                                                 flashg=1;
10902                                                                                                 flashb=1;
10903                                                                                                 flashamount=1;
10904                                                                                                 flashdelay=1;
10905                                                                                         }
10906                                                                                         if(tutorialstage>=14&&tutorialstage<50)
10907                                                                                                 if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
10908                                                                                                         float gLoc[3];
10909                                                                                                         float vel[3];
10910                                                                                                         gLoc[0]=player[1].coords.x;
10911                                                                                                         gLoc[1]=player[1].coords.y;
10912                                                                                                         gLoc[2]=player[1].coords.z;
10913                                                                                                         vel[0]=0;
10914                                                                                                         vel[1]=0;
10915                                                                                                         vel[2]=0;
10916                                                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
10917                                                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
10918                                                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
10919                                                                                                         OPENAL_SetPaused(channels[fireendsound], false);
10920
10921                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10922                                                                                                                 if(Random()%2==0){
10923                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10924                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10925                                                                                                                         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;
10926                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10927                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10928                                                                                                                 }
10929                                                                                                         }
10930
10931                                                                                                         player[1].coords=(oldtemp+oldtemp2)/2;
10932                                                                                                         for(int i=0;i<player[1].skeleton.num_joints;i++){
10933                                                                                                                 player[1].skeleton.joints[i].velocity=0;
10934                                                                                                                 if(Random()%2==0){
10935                                                                                                                         if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
10936                                                                                                                         if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
10937                                                                                                                         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;
10938                                                                                                                         if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
10939                                                                                                                         sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
10940                                                                                                                 }
10941                                                                                                         }
10942                                                                                                 }
10943                                                                 }
10944
10945
10946                                                                 //3d sound
10947                                                                 static float gLoc[3];
10948                                                                 gLoc[0]=viewer.x;
10949                                                                 gLoc[1]=viewer.y;
10950                                                                 gLoc[2]=viewer.z;
10951                                                                 static float vel[3];
10952                                                                 vel[0]=(viewer.x-oldviewer.x)/multiplier;
10953                                                                 vel[1]=(viewer.y-oldviewer.y)/multiplier;
10954                                                                 vel[2]=(viewer.z-oldviewer.z)/multiplier;
10955
10956                                                                 //Set orientation with forward and up vectors
10957                                                                 static XYZ upvector;
10958                                                                 upvector=0;
10959                                                                 upvector.z=-1;
10960
10961                                                                 upvector=DoRotation(upvector,-rotation2+90,0,0);
10962                                                                 upvector=DoRotation(upvector,0,0-rotation,0);
10963
10964                                                                 facing=0;
10965                                                                 facing.z=-1;
10966
10967                                                                 facing=DoRotation(facing,-rotation2,0,0);
10968                                                                 facing=DoRotation(facing,0,0-rotation,0);
10969
10970
10971                                                                 static float ori[6];
10972                                                                 ori[0] = -facing.x;
10973                                                                 ori[1] = facing.y;
10974                                                                 ori[2] = -facing.z;
10975                                                                 ori[3] = -upvector.x;
10976                                                                 ori[4] = upvector.y;
10977                                                                 ori[5] = -upvector.z;
10978
10979                                                                 OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
10980                                                                 OPENAL_Update();
10981
10982                                                                 oldviewer=viewer;
10983                 }
10984         }
10985
10986         if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
10987                 Screenshot();
10988                 freezetogglekeydown=1;
10989         }
10990 }
10991
10992 void    Game::TickOnce(){
10993         //if(!console){
10994         if(!mainmenu)
10995                 if(directing||indialogue==-1){
10996                         rotation+=deltah*.7;
10997                         if(!invertmouse)rotation2+=deltav*.7;
10998                         if(invertmouse)rotation2-=deltav*.7;
10999                         if(rotation2>90)rotation2=90;
11000                         if(rotation2<-70)rotation2=-70;
11001                 }
11002                 if(mainmenu)rotation+=multiplier*5;
11003                 if(!mainmenu&&!indemo&&!registered){
11004                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
11005                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11006                         OPENAL_SetPaused(channels[stream_music3], false);
11007                         OPENAL_SetVolume(channels[stream_music3], 256);
11008
11009                         gameon=0;
11010                         mainmenu=12;
11011
11012                         float gLoc[3]={0,0,0};
11013                         float vel[3]={0,0,0};
11014                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11015                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11016                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11017                         OPENAL_SetVolume(channels[fireendsound], 256);
11018                         OPENAL_SetPaused(channels[fireendsound], false);
11019                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11020
11021                         flashr=1;
11022                         flashg=0;
11023                         flashb=0;
11024                         flashamount=1;
11025                         flashdelay=1;
11026                 }
11027
11028                 if(tryquit==1&&!registered&&mainmenu!=12){
11029                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
11030                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11031                         OPENAL_SetPaused(channels[stream_music3], false);
11032                         OPENAL_SetVolume(channels[stream_music3], 256);
11033
11034                         gameon=0;
11035                         mainmenu=12;
11036
11037                         float gLoc[3]={0,0,0};
11038                         float vel[3]={0,0,0};
11039                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11040                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11041                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11042                         OPENAL_SetVolume(channels[fireendsound], 256);
11043                         OPENAL_SetPaused(channels[fireendsound], false);
11044                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11045
11046                         flashr=1;
11047                         flashg=0;
11048                         flashb=0;
11049                         flashamount=1;
11050                         flashdelay=1;
11051                 }
11052                 //}
11053 }
11054
11055 void    Game::TickOnceAfter(){
11056         static XYZ colviewer;
11057         static XYZ coltarget;
11058         static XYZ target;
11059         static XYZ col;
11060         static float brotate;
11061         static XYZ facing;
11062         static int i,j;
11063         static float changedelay;
11064         static bool alldead;
11065         static float unseendelay;
11066         static float cameraspeed;
11067
11068         if(!mainmenu){
11069
11070                 if(environment==snowyenvironment)music1=stream_music1snow;
11071                 if(environment==grassyenvironment)music1=stream_music1grass;
11072                 if(environment==desertenvironment)music1=stream_music1desert;
11073
11074                 realthreat=0;
11075
11076                 musictype=music1;
11077                 for(i=0;i<numplayers;i++){
11078                         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)){
11079                                 musictype=stream_music2;
11080                                 realthreat=1;
11081                         }
11082                 }
11083                 if(player[0].dead)musictype=stream_music3;
11084
11085
11086                 if(musictype==stream_music2){
11087                         unseendelay=1;
11088                 }
11089
11090                 if(oldmusictype==stream_music2&&musictype!=stream_music2){
11091                         unseendelay-=multiplier;
11092                         if(unseendelay>0){
11093                                 musictype=stream_music2;
11094                         }
11095                 }
11096
11097
11098                 if(loading==2){
11099                         musictype=stream_music3;
11100                         musicvolume[2]=512;
11101                         musicvolume[0]=0;
11102                         musicvolume[1]=0;
11103                         musicvolume[3]=0;
11104                 }
11105
11106                 if(musictoggle){
11107                         if(musictype!=oldmusictype&&musictype==stream_music2){
11108                                 static float gLoc[3];
11109                                 static float vel[3];
11110                                 gLoc[0]=cameraloc.x;
11111                                 gLoc[1]=cameraloc.y;
11112                                 gLoc[2]=cameraloc.z;
11113                                 vel[0]=0;
11114                                 vel[1]=0;
11115                                 vel[2]=0;
11116                                 PlaySoundEx( alarmsound, samp[alarmsound], NULL, true);
11117                                 OPENAL_SetVolume(channels[alarmsound], 512);
11118                                 OPENAL_SetPaused(channels[alarmsound], false);
11119
11120                         }
11121                 }
11122                 musicselected=musictype;
11123
11124                 if(musicselected==music1)musicvolume[0]+=multiplier*450;
11125                 else musicvolume[0]-=multiplier*450;
11126                 if(musicselected==stream_music2)musicvolume[1]+=multiplier*450;
11127                 else musicvolume[1]-=multiplier*450;
11128                 if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
11129                 else musicvolume[2]-=multiplier*450;
11130                 /*
11131                 if(musicselected==music1)musicvolume[0]+=multiplier*100;
11132                 else musicvolume[0]-=multiplier*450;
11133                 if(musicselected==music2)musicvolume[1]+=multiplier*150;
11134                 else if(player[0].dead)musicvolume[1]-=multiplier*450;
11135                 else musicvolume[1]-=multiplier*100;
11136                 if(musicselected==music3)musicvolume[2]+=multiplier*450;
11137                 else musicvolume[2]-=multiplier*450;*/
11138
11139                 for(i=0;i<3;i++){
11140                         if(musicvolume[i]<0)musicvolume[i]=0;
11141                         if(musicvolume[i]>512)musicvolume[i]=512;
11142                 }
11143
11144                 if(musicvolume[2]>128&&!loading&&!mainmenu)musicvolume[2]=128;
11145
11146                 if(musictoggle){
11147                         if(musicvolume[0]>0&&oldmusicvolume[0]<=0){
11148                                 PlayStreamEx( music1, strm[music1], NULL, true);
11149                                 OPENAL_SetPaused(channels[music1], false);
11150                         }
11151                         if(musicvolume[1]>0&&oldmusicvolume[1]<=0){
11152                                 PlayStreamEx( stream_music2, strm[stream_music2], NULL, true);
11153                                 OPENAL_SetPaused(channels[stream_music2], false);
11154                         }
11155                         if(musicvolume[2]>0&&oldmusicvolume[2]<=0){
11156                                 PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11157                                 OPENAL_SetPaused(channels[stream_music3], false);
11158                         }
11159                 }
11160
11161                 if(!musictoggle){
11162                         OPENAL_SetPaused(channels[music1], true);
11163                         OPENAL_SetPaused(channels[stream_music2], true);
11164                         OPENAL_SetPaused(channels[stream_music3], true);
11165
11166                         for(i=0;i<4;i++){
11167                                 oldmusicvolume[i]=0;
11168                                 musicvolume[i]=0;
11169                         }
11170                 }
11171
11172                 if(musictoggle){
11173                         if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
11174                                 OPENAL_SetPaused(channels[music1], true);
11175                         }
11176                         if(musicvolume[1]<=0&&oldmusicvolume[1]>0){
11177                                 OPENAL_SetPaused(channels[stream_music2], true);
11178                         }
11179                         if(musicvolume[2]<=0&&oldmusicvolume[2]>0){
11180                                 OPENAL_SetPaused(channels[stream_music3], true);
11181                         }
11182
11183                         if(musicvolume[0]!=oldmusicvolume[0]){
11184                                 OPENAL_SetVolume(channels[music1], musicvolume[0]);
11185                         }
11186                         if(musicvolume[1]!=oldmusicvolume[1]){
11187                                 OPENAL_SetVolume(channels[stream_music2], musicvolume[1]);
11188                         }
11189                         if(musicvolume[2]!=oldmusicvolume[2]){
11190                                 OPENAL_SetVolume(channels[stream_music3], musicvolume[2]);
11191                         }
11192
11193                         for(i=0;i<3;i++){
11194                                 oldmusicvolume[i]=musicvolume[i];
11195                         }
11196                 }
11197
11198                 killhotspot=2;
11199                 if(numhotspots)
11200                         for(i=0;i<numhotspots;i++){
11201                                 if(hotspottype[i]>10&&hotspottype[i]<20){
11202                                         if(player[hotspottype[i]-10].dead==0){
11203                                                 killhotspot=0;
11204                                         }
11205                                         else if(killhotspot==2)
11206                                                 killhotspot=1;
11207                                 }
11208                         }
11209                         if(killhotspot==2)killhotspot=0;
11210
11211
11212                         winhotspot=0;
11213                         if(numhotspots)
11214                                 for(i=0;i<numhotspots;i++){
11215                                         if(hotspottype[i]==-1){
11216                                                 if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
11217                                                         winhotspot=1;
11218                                         }
11219                                 }
11220
11221                                 int numalarmed=0;
11222                                 if(numplayers>1)
11223                                         for(i=1;i<numplayers;i++){
11224                                                 if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
11225                                         }
11226                                         if(numalarmed>maxalarmed)maxalarmed=numalarmed;
11227
11228                                         if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
11229                                                 if(player[0].dead&&changedelay<=0){
11230                                                         changedelay=1;
11231                                                         targetlevel=whichlevel;
11232                                                 }
11233                                                 alldead=1;
11234                                                 if(numplayers>1)
11235                                                         for(i=1;i<numplayers;i++){
11236                                                                 if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
11237                                                         }
11238
11239
11240                                                         if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
11241                                                                 changedelay=1;
11242                                                                 targetlevel=whichlevel+1;
11243                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11244                                                         }
11245                                                         if(winhotspot||windialogue){
11246                                                                 changedelay=0.1;
11247                                                                 targetlevel=whichlevel+1;
11248                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11249                                                         }
11250
11251
11252                                                         if(killhotspot){
11253                                                                 changedelay=1;
11254                                                                 targetlevel=whichlevel+1;
11255                                                                 if(targetlevel>numchallengelevels-1)targetlevel=0;
11256                                                         }
11257
11258                                                         if(changedelay>0&&!player[0].dead&&!won){
11259                                                                 //high scores, awards, win
11260                                                                 if(campaign){
11261                                                                         won=1;
11262                                                                         accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11263                                                                         accountcampaignchoicesmade[accountactive]++;
11264                                                                         accountcampaignscore[accountactive]+=bonustotal;
11265                                                                         scoreadded=1;
11266                                                                         accountcampaigntime[accountactive]+=leveltime;
11267                                                                         if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
11268
11269                                                                         //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11270                                                                 }
11271                                                                 else
11272                                                                 {
11273                                                                         won=1;
11274                                                                         if(!debugmode){
11275                                                                                 if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
11276                                                                                 if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
11277                                                                         }
11278                                                                         if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
11279
11280                                                                 }
11281                                                         }
11282                                         }
11283
11284                                         if(!winfreeze){
11285
11286                                                 if(leveltime<1){
11287                                                         loading=0;
11288                                                         changedelay=.1;
11289                                                         alldead=0;
11290                                                         winhotspot=0;
11291                                                         killhotspot=0;
11292                                                 }
11293
11294                                                 if(!editorenabled&&gameon&&!mainmenu){
11295                                                         if(changedelay!=-999)changedelay-=multiplier/7;
11296                                                         if(player[0].dead)targetlevel=whichlevel;
11297                                                         if(loading==2&&!campaign){
11298                                                                 flashr=1;
11299                                                                 flashg=0;
11300                                                                 flashb=0;
11301                                                                 flashamount=1;
11302                                                                 flashdelay=1;
11303                                                                 loadtime=0;
11304
11305                                                                 float gLoc[3]={0,0,0};
11306                                                                 float vel[3]={0,0,0};
11307                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11308                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11309                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11310                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
11311                                                                 OPENAL_SetPaused(channels[firestartsound], false);
11312                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11313
11314                                                                 if(!player[0].dead&&targetlevel!=whichlevel){
11315                                                                         startbonustotal=bonustotal;
11316                                                                 }
11317                                                                 if(!player[0].dead)Loadlevel(targetlevel);
11318                                                                 if(player[0].dead)Loadlevel(whichlevel);
11319
11320                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11321                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11322                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11323                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
11324                                                                 OPENAL_SetPaused(channels[fireendsound], false);
11325                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11326
11327                                                                 loading=3;
11328                                                         }
11329                                                         if(loading==2&&targetlevel==whichlevel){
11330                                                                 flashr=1;
11331                                                                 flashg=0;
11332                                                                 flashb=0;
11333                                                                 flashamount=1;
11334                                                                 flashdelay=1;
11335                                                                 loadtime=0;
11336
11337                                                                 float gLoc[3]={0,0,0};
11338                                                                 float vel[3]={0,0,0};
11339                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11340                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11341                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11342                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
11343                                                                 OPENAL_SetPaused(channels[firestartsound], false);
11344                                                                 OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11345
11346                                                                 for(i=0;i<255;i++){
11347                                                                         mapname[i]='\0';
11348                                                                 }
11349                                                                 mapname[0]=':';
11350                                                                 mapname[1]='D';
11351                                                                 mapname[2]='a';
11352                                                                 mapname[3]='t';
11353                                                                 mapname[4]='a';
11354                                                                 mapname[5]=':';
11355                                                                 mapname[6]='M';
11356                                                                 mapname[7]='a';
11357                                                                 mapname[8]='p';
11358                                                                 mapname[9]='s';
11359                                                                 mapname[10]=':';
11360                                                                 strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
11361                                                                 Loadlevel(mapname);
11362
11363                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11364                                                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11365                                                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11366                                                                 OPENAL_SetVolume(channels[fireendsound], 256);
11367                                                                 OPENAL_SetPaused(channels[fireendsound], false);
11368                                                                 OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11369
11370                                                                 loading=3;
11371                                                         }
11372                                                         if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
11373                                                         if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
11374                                                                 if(accountprogress[accountactive]>3&&!registered){
11375                                                                         OPENAL_SetFrequency(OPENAL_ALL, 0.001);
11376                                                                         PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
11377                                                                         OPENAL_SetPaused(channels[stream_music3], false);
11378                                                                         OPENAL_SetVolume(channels[stream_music3], 256);
11379
11380                                                                         gameon=0;
11381                                                                         mainmenu=12;
11382                                                                         accountprogress[accountactive]=3;
11383
11384                                                                         float gLoc[3]={0,0,0};
11385                                                                         float vel[3]={0,0,0};
11386                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
11387                                                                         PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
11388                                                                         OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
11389                                                                         OPENAL_SetVolume(channels[fireendsound], 256);
11390                                                                         OPENAL_SetPaused(channels[fireendsound], false);
11391                                                                         OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
11392
11393                                                                         flashr=1;
11394                                                                         flashg=0;
11395                                                                         flashb=0;
11396                                                                         flashamount=1;
11397                                                                         flashdelay=1;
11398                                                                 }
11399                                                                 else{
11400                                                                         if(whichlevel!=-2&&!loading&&!player[0].dead){
11401                                                                                 winfreeze=1;
11402                                                                                 changedelay=-999;
11403                                                                         }
11404                                                                         if(player[0].dead)loading=1;
11405                                                                 }
11406                                                         }
11407                                                 }
11408
11409                                                 if(campaign)
11410                                                         if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
11411                                                                 if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
11412                                                                         endgame=1;
11413                                                                 }
11414                                                         }
11415                                                         else if(mainmenu==0&&winfreeze){
11416                                                                 if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
11417                                                                         stealthloading=1;
11418                                                                 else stealthloading=0;
11419
11420                                                                 if(!stealthloading){
11421                                                                         float gLoc[3]={0,0,0};
11422                                                                         float vel[3]={0,0,0};
11423                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
11424                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
11425                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
11426                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
11427                                                                         OPENAL_SetPaused(channels[firestartsound], false);
11428                                                                         OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
11429
11430                                                                         flashr=1;
11431                                                                         flashg=0;
11432                                                                         flashb=0;
11433                                                                         flashamount=1;
11434                                                                         flashdelay=1;
11435                                                                 }
11436
11437                                                                 startbonustotal=0;
11438
11439                                                                 ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
11440                                                                 //campaignnumlevels=0;
11441                                                                 //accountcampaignchoicesmade[accountactive]=0;
11442                                                                 ipstream.ignore(256,':');
11443                                                                 ipstream >> campaignnumlevels;
11444                                                                 for(i=0;i<campaignnumlevels;i++){
11445                                                                         ipstream.ignore(256,':');
11446                                                                         ipstream.ignore(256,':');
11447                                                                         ipstream.ignore(256,' ');
11448                                                                         ipstream >> campaignmapname[i];
11449                                                                         ipstream.ignore(256,':');
11450                                                                         ipstream >> campaigndescription[i];
11451                                                                         for(j=0;j<256;j++){
11452                                                                                 if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
11453                                                                         }
11454                                                                         ipstream.ignore(256,':');
11455                                                                         ipstream >> campaignchoosenext[i];
11456                                                                         ipstream.ignore(256,':');
11457                                                                         ipstream >> campaignnumnext[i];
11458                                                                         if(campaignnumnext[i])
11459                                                                                 for(j=0;j<campaignnumnext[i];j++){
11460                                                                                         ipstream.ignore(256,':');
11461                                                                                         ipstream >> campaignnextlevel[i][j];
11462                                                                                         campaignnextlevel[i][j]-=1;
11463                                                                                 }
11464                                                                                 ipstream.ignore(256,':');
11465                                                                                 ipstream >> campaignlocationx[i];
11466                                                                                 ipstream.ignore(256,':');
11467                                                                                 ipstream >> campaignlocationy[i];
11468                                                                 }
11469                                                                 ipstream.close();
11470
11471                                                                 for(i=0;i<campaignnumlevels;i++){
11472                                                                         levelvisible[i]=0;
11473                                                                         levelhighlight[i]=0;
11474                                                                 }
11475
11476
11477                                                                 for(i=0;i<campaignnumlevels;i++){
11478                                                                         levelvisible[i]=0;
11479                                                                         levelhighlight[i]=0;
11480                                                                 }
11481
11482                                                                 levelorder[0]=0;
11483                                                                 levelvisible[0]=1;
11484                                                                 if(accountcampaignchoicesmade[accountactive])
11485                                                                         for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
11486                                                                                 levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
11487                                                                                 levelvisible[levelorder[i+1]]=1;
11488                                                                         }
11489                                                                         int whichlevelstart;
11490                                                                         whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
11491                                                                         if(whichlevelstart<0){
11492                                                                                 campaignchoicenum=1;
11493                                                                                 campaignchoicewhich[0]=0;
11494                                                                         }
11495                                                                         else
11496                                                                         {
11497                                                                                 campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
11498                                                                                 if(campaignchoicenum)
11499                                                                                         for(i=0;i<campaignchoicenum;i++){
11500                                                                                                 campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
11501                                                                                                 levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11502                                                                                                 levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
11503                                                                                         }
11504                                                                         }
11505
11506                                                                         loading=2;
11507                                                                         loadtime=0;
11508                                                                         targetlevel=7;
11509                                                                         //if(firstload)TickOnceAfter();
11510                                                                         if(!firstload)LoadStuff();
11511                                                                         //else {
11512                                                                         for(i=0;i<255;i++){
11513                                                                                 mapname[i]='\0';
11514                                                                         }
11515                                                                         mapname[0]=':';
11516                                                                         mapname[1]='D';
11517                                                                         mapname[2]='a';
11518                                                                         mapname[3]='t';
11519                                                                         mapname[4]='a';
11520                                                                         mapname[5]=':';
11521                                                                         mapname[6]='M';
11522                                                                         mapname[7]='a';
11523                                                                         mapname[8]='p';
11524                                                                         mapname[9]='s';
11525                                                                         mapname[10]=':';
11526
11527                                                                         //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
11528                                                                         //accountcampaignchoicesmade[accountactive]++;
11529
11530
11531                                                                         strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
11532                                                                         whichchoice=0;
11533                                                                         visibleloading=1;
11534                                                                         stillloading=1;
11535                                                                         Loadlevel(mapname);
11536                                                                         campaign=1;
11537                                                                         mainmenu=0;
11538                                                                         gameon=1;
11539                                                                         OPENAL_SetPaused(channels[stream_music3], true);
11540
11541                                                                         stealthloading=0;
11542                                                         }
11543
11544                                                         if(loading==3)loading=0;
11545
11546                                         }
11547
11548                                         oldmusictype=musictype;
11549         }
11550
11551         facing=0;
11552         facing.z=-1;
11553
11554         facing=DoRotation(facing,-rotation2,0,0);
11555         facing=DoRotation(facing,0,0-rotation,0);
11556         viewerfacing=facing;
11557
11558         brotate=0;
11559         if(!cameramode){
11560                 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;
11561                 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;
11562                 target.y+=.1;
11563                 if(player[0].skeleton.free){
11564                         for(i=0;i<player[0].skeleton.num_joints;i++){
11565                                 if(player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y>target.y)
11566                                         target.y=player[0].skeleton.joints[i].position.y*player[0].scale+player[0].coords.y;
11567                         }
11568                         target.y+=.1;
11569                 }
11570                 if(player[0].skeleton.free!=2&&!autocam){
11571                         cameraspeed=20;
11572                         if(findLengthfast(&player[0].velocity)>400){
11573                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11574                         }
11575                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11576                         coltarget=target-cameraloc;
11577                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11578                         else {
11579                                 Normalise(&coltarget);
11580                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11581                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11582                         }
11583                         if(editorenabled)cameraloc=target;
11584                         cameradist+=multiplier*5;
11585                         if(cameradist>2.3)cameradist=2.3;
11586                         viewer=cameraloc-facing*cameradist;
11587                         colviewer=viewer;
11588                         coltarget=cameraloc;
11589                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11590                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11591                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11592                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11593                                         colviewer=viewer;
11594                                         coltarget=cameraloc;
11595                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11596                                 }
11597                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11598                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11599                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11600                                                 colviewer=viewer;
11601                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11602                                                         viewer=colviewer;
11603                                                 }
11604                                         }
11605                                         cameradist=findDistance(&viewer,&target);
11606                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11607                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11608                                         }
11609                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11610                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11611                                         }
11612                 }
11613                 if(player[0].skeleton.free!=2&&autocam){
11614                         cameraspeed=20;
11615                         if(findLengthfast(&player[0].velocity)>400){
11616                                 cameraspeed=20+(findLength(&player[0].velocity)-20)*.96;
11617                         }
11618                         if(player[0].skeleton.free==0&&player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim)target.y+=1.4;
11619                         cameradist+=multiplier*5;
11620                         if(cameradist>3.3)cameradist=3.3;
11621                         coltarget=target-cameraloc;
11622                         if(findLengthfast(&coltarget)<multiplier*multiplier*400)cameraloc=target;
11623                         else if(findLengthfast(&coltarget)>1)
11624                         {
11625                                 Normalise(&coltarget);
11626                                 if(player[0].targetanimation!=hanganim&&player[0].targetanimation!=climbanim&&player[0].currentanimation!=climbanim&&player[0].currentoffset.x==0)cameraloc=cameraloc+coltarget*multiplier*cameraspeed;
11627                                 else cameraloc=cameraloc+coltarget*multiplier*8;
11628                         }
11629                         if(editorenabled)cameraloc=target;
11630                         viewer=cameraloc;
11631                         colviewer=viewer;
11632                         coltarget=cameraloc;
11633                         objects.SphereCheckPossible(&colviewer, findDistance(&colviewer,&coltarget));
11634                         if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11635                                 for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11636                                         i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11637                                         colviewer=viewer;
11638                                         coltarget=cameraloc;
11639                                         if(objects.model[i].LineCheckPossible(&colviewer,&coltarget,&col,&objects.position[i],&objects.rotation[i])!=-1)viewer=col;
11640                                 }
11641                                 if(terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz])
11642                                         for(j=0;j<terrain.patchobjectnum[player[0].whichpatchx][player[0].whichpatchz];j++){
11643                                                 i=terrain.patchobjects[player[0].whichpatchx][player[0].whichpatchz][j];
11644                                                 colviewer=viewer;
11645                                                 if(objects.model[i].SphereCheck(&colviewer,.15,&col,&objects.position[i],&objects.rotation[i])!=-1){
11646                                                         viewer=colviewer;
11647                                                 }
11648                                         }
11649                                         cameradist=findDistance(&viewer,&target);
11650                                         if(viewer.y<terrain.getHeight(viewer.x,viewer.z)+.6){
11651                                                 viewer.y=terrain.getHeight(viewer.x,viewer.z)+.6;
11652                                         }
11653                                         if(cameraloc.y<terrain.getHeight(cameraloc.x,cameraloc.z)){
11654                                                 cameraloc.y=terrain.getHeight(cameraloc.x,cameraloc.z);
11655                                         }
11656                 }
11657                 if(camerashake>.8)camerashake=.8;
11658                 //if(woozy>10)woozy=10;
11659                 //woozy+=multiplier;
11660                 woozy+=multiplier;
11661                 if(player[0].dead)camerashake=0;
11662                 if(player[0].dead)woozy=0;
11663                 camerashake-=multiplier*2;
11664                 blackout-=multiplier*2;
11665                 //if(player[0].isCrouch())woozy-=multiplier*8;
11666                 if(camerashake<0)camerashake=0;
11667                 if(blackout<0)blackout=0;
11668                 //if(woozy<0)woozy=0;
11669                 if(camerashake){
11670                         viewer.x+=(float)(Random()%100)*.0005*camerashake;
11671                         viewer.y+=(float)(Random()%100)*.0005*camerashake;
11672                         viewer.z+=(float)(Random()%100)*.0005*camerashake;
11673                 }
11674         }
11675 }