]> git.jsancho.org Git - lugaru.git/blob - Source/Person.cpp
05eeb5f7218bc9fa9bb48a02b4fbdc25dbdd59cc
[lugaru.git] / Source / Person.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 /**> HEADER FILES <**/
23 #include "Person.h"
24 #include "openal_wrapper.h"
25 #include "Animation.h"
26 #include "Sounds.h"
27 #include "Awards.h"
28 #include "Game.h"
29
30 extern float multiplier;
31 extern int channels[100];
32 extern Terrain terrain;
33 extern float gravity;
34 extern int environment;
35 extern int detail;
36 extern FRUSTUM frustum;
37 extern XYZ viewer;
38 extern float realmultiplier;
39 extern int slomo;
40 extern float slomodelay;
41 extern bool cellophane;
42 extern float texdetail;
43 extern float realtexdetail;
44 extern GLubyte bloodText[512*512*3];
45 extern GLubyte wolfbloodText[512*512*3];
46 extern int bloodtoggle;
47 extern Objects objects;
48 extern bool osx;
49 extern bool autoslomo;
50 extern float camerashake;
51 extern float woozy;
52 extern float terraindetail;
53 extern float viewdistance;
54 extern float blackout;
55 extern int difficulty;
56 extern bool decals;
57 extern float fadestart;
58 extern bool freeze;
59 extern bool winfreeze;
60 extern float flashamount,flashr,flashg,flashb;
61 extern int flashdelay;
62 extern bool showpoints;
63 extern bool immediate;
64 extern int test;
65 extern bool tilt2weird;
66 extern bool tiltweird;
67 extern bool midweird;
68 extern bool proportionweird;
69 extern bool vertexweird[6];
70 extern GLubyte texturearray[512*512*3];
71 extern XYZ envsound[30];
72 extern float envsoundvol[30];
73 extern float envsoundlife[30];
74 extern int numenvsounds;
75 extern int bonus;
76 extern float bonusvalue;
77 extern float bonustotal;
78 extern float bonustime;
79 extern int tutoriallevel;
80 extern float smoketex;
81 extern int tutorialstage;
82 extern bool reversaltrain;
83 extern bool canattack;
84 extern bool cananger;
85 extern float damagedealt;
86 extern float damagetaken;
87 extern int hostile;
88 extern float hostiletime;
89
90 extern int numfalls;
91 extern int numflipfail;
92 extern int numseen;
93 extern int numswordattack;
94 extern int numknifeattack;
95 extern int numunarmedattack;
96 extern int numescaped;
97 extern int numflipped;
98 extern int numwallflipped;
99 extern int numthrowkill;
100 extern int numafterkill;
101 extern int numreversals;
102 extern int numattacks;
103 extern int maxalarmed;
104 extern int indialogue;
105
106 extern bool gamestarted;
107
108 extern "C"      void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
109 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
110
111 void Person::CheckKick(){
112         static XYZ relative;
113         static int i;
114
115         float damagemult=1*power;
116         if(creature==wolftype)damagemult=2.5*power;
117         damagemult*=power;
118
119         if(hasvictim)
120                 if(targetanimation==rabbitkickanim&&victim&&victim!=this&&currentframe>=2&&currentanimation==rabbitkickanim){
121                         if(findDistancefast(&coords,&victim->coords)<1.2){
122                                 if(!victim->skeleton.free){
123                                         relative=velocity;
124                                         Normalise(&relative);
125                                         relative=coords+relative*1;
126                                         if(animation[victim->targetanimation].height!=lowheight){
127                                                 victim->spurt=1;
128                                                 DoBlood(.2,250);
129                                                 float gLoc[3];
130                                                 float vel[3];
131                                                 gLoc[0]=victim->coords.x;
132                                                 gLoc[1]=victim->coords.y;
133                                                 gLoc[2]=victim->coords.z;
134                                                 vel[0]=velocity.x;
135                                                 vel[1]=velocity.y;
136                                                 vel[2]=velocity.z;
137                                                 if(tutoriallevel!=1){
138                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
139                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
140                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
141                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
142                                                 }
143                                                 victim->RagDoll(0);
144                                                 relative=velocity;
145                                                 relative.y=0;
146                                                 Normalise(&relative);
147                                                 for(i=0;i<victim->skeleton.num_joints;i++){
148                                                         victim->skeleton.joints[i].velocity+=relative*120*damagemult;
149                                                 }
150                                                 victim->Puff(neck);
151                                                 victim->DoDamage(100*damagemult/victim->protectionhigh);
152                                                 if(id==0)camerashake+=.4;
153
154                                                 target=0;
155                                                 currentframe=3;
156                                                 targetanimation=backflipanim;
157                                                 targetframe=4;
158                                                 velocity=facing*-10;
159                                                 velocity.y=5;
160                                                 skeleton.free=0;
161                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
162
163                                                 //if(victim->damage>victim->damagetolerance){
164                                                 if(id==0){
165                                                         bonus=cannon;
166                                                         bonustime=0;
167                                                         bonusvalue=100;
168                                                 }
169                                                 //}
170                                         }
171                                         else if (victim->isCrouch()){
172                                                 targetanimation=rabbitkickreversedanim;
173                                                 currentanimation=rabbitkickreversedanim;
174                                                 victim->currentanimation=rabbitkickreversalanim;
175                                                 victim->targetanimation=rabbitkickreversalanim;
176                                                 targettilt2=0;
177                                                 currentframe=0;
178                                                 targetframe=1;
179                                                 target=0;
180                                                 velocity=0;
181                                                 victim->oldcoords=victim->coords;
182                                                 coords=victim->coords;
183                                                 victim->targetrotation=targetrotation;
184                                                 victim->victim=this;
185                                         }
186                                 }
187                         }
188                 }
189 }
190
191 void Person::CatchFire(){
192         XYZ flatfacing,flatvelocity;
193         int howmany;
194         for(int i=0;i<10;i++){
195                 howmany=abs(Random()%(skeleton.num_joints));
196                 if(!skeleton.free)flatvelocity=velocity;
197                 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity;
198                 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
199                 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
200                 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, 2, 1);
201         }
202
203         onfiredelay=0.5;
204
205         float gLoc[3];
206         float vel[3];
207         gLoc[0]=coords.x;
208         gLoc[1]=coords.y;
209         gLoc[2]=coords.z;
210         vel[0]=0;
211         vel[1]=0;
212         vel[2]=0;
213         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
214         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
215         OPENAL_SetVolume(channels[firestartsound], 256);
216         OPENAL_SetPaused(channels[firestartsound], false);
217
218         vel[0]=velocity.x;
219         vel[1]=velocity.y;
220         vel[2]=velocity.z;
221         //PlaySoundEx( firesound, samp[firesound], NULL, true);
222         PlayStreamEx( stream_firesound, samp[stream_firesound], NULL, true);
223         OPENAL_3D_SetAttributes(channels[stream_firesound], gLoc, vel);
224         OPENAL_SetVolume(channels[stream_firesound], 256);
225         OPENAL_SetPaused(channels[stream_firesound], false);
226
227         flamedelay=0;
228
229         onfire=1;
230 }
231
232 bool Person::isIdle(){
233         if(targetanimation==sleepanim||targetanimation==sitanim||targetanimation==talkidleanim||targetanimation==hurtidleanim||targetanimation==bounceidleanim||targetanimation==talkidleanim||targetanimation==fightidleanim||targetanimation==knifefightidleanim||targetanimation==swordfightidleanim||targetanimation==swordfightidlebothanim||targetanimation==fightsidestep||targetanimation==wolfidle)return 1;
234         else return 0;
235 }
236
237 bool Person::isSitting(){
238         if(targetanimation==sitanim)return 1;
239         if(targetanimation==sitwallanim)return 1;
240         else return 0;
241 }
242
243 bool Person::isSleeping(){
244         if(targetanimation==sleepanim)return 1;
245         if(targetanimation==dead1anim)return 1;
246         if(targetanimation==dead2anim)return 1;
247         if(targetanimation==dead3anim)return 1;
248         if(targetanimation==dead4anim)return 1;
249         else return 0;
250 }
251
252 bool Person::wasIdle(){
253         if(currentanimation==sleepanim||currentanimation==talkidleanim||currentanimation==sitanim||currentanimation==hurtidleanim||currentanimation==bounceidleanim||currentanimation==fightidleanim||currentanimation==swordfightidleanim||currentanimation==swordfightidlebothanim||currentanimation==knifefightidleanim||currentanimation==fightsidestep||currentanimation==wolfidle)return 1;
254         else return 0;
255 }
256 int Person::getIdle(){
257         if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
258         if(hasvictim&&victim!=this/*||(id==0&&attackkeydown)*/)if(/*(id==0&&attackkeydown)||*/(!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers)){
259                 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
260                         if(creature==rabbittype)return fightidleanim;
261                         if(creature==wolftype)return wolfidle;
262                 }
263                 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
264                         if(weapons.type[weaponids[weaponactive]]==knife)return knifefightidleanim;
265                         if(weapons.type[weaponids[weaponactive]]==sword&&victim->weaponactive!=-1)return swordfightidlebothanim;
266                         if(weapons.type[weaponids[weaponactive]]==sword)return swordfightidleanim;
267                         if(weapons.type[weaponids[weaponactive]]==staff)return swordfightidleanim;
268                 }
269                 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
270         }
271         if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
272         if(howactive==typesitting)return sitanim;
273         if(howactive==typesittingwall)return sitwallanim;
274         if(howactive==typesleeping)return sleepanim;
275         if(howactive==typedead1)return dead1anim;
276         if(howactive==typedead2)return dead2anim;
277         if(howactive==typedead3)return dead3anim;
278         if(howactive==typedead4)return dead4anim;
279         if(creature==rabbittype)return bounceidleanim;
280         if(creature==wolftype)return wolfidle;
281         return 0;
282 }
283
284 bool Person::isCrouch(){
285         if(targetanimation==crouchanim||targetanimation==wolfcrouchanim)return 1;
286         else return 0;
287 }
288
289
290 bool Person::wasCrouch(){
291         if(currentanimation==crouchanim||currentanimation==wolfcrouchanim)return 1;
292         else return 0;
293 }
294 int Person::getCrouch(){
295         if(creature==rabbittype)return crouchanim;
296         if(creature==wolftype)return wolfcrouchanim;
297         return 0;
298 }
299
300 bool Person::isRun(){
301         if(targetanimation==runanim||targetanimation==wolfrunanim||targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)return 1;
302         else return 0;
303 }
304
305
306 bool Person::wasRun(){
307         if(currentanimation==runanim||currentanimation==wolfrunanim||currentanimation==wolfrunninganim||currentanimation==rabbitrunninganim)return 1;
308         else return 0;
309 }
310 int Person::getRun(){
311         if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
312         if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
313
314         if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
315         if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
316         return 0;
317 }
318
319 bool Person::isStop(){
320         if(targetanimation==stopanim||targetanimation==wolfstopanim)return 1;
321         else return 0;
322 }
323
324
325 bool Person::wasStop(){
326         if(currentanimation==stopanim||currentanimation==wolfstopanim)return 1;
327         else return 0;
328 }
329 int Person::getStop(){
330         if(creature==rabbittype)return stopanim;
331         if(creature==wolftype)return wolfstopanim;
332         return 0;
333 }
334
335
336 bool Person::isLanding(){
337         if(targetanimation==landanim||targetanimation==wolflandanim)return 1;
338         else return 0;
339 }
340
341
342 bool Person::wasLanding(){
343         if(currentanimation==landanim||currentanimation==wolflandanim)return 1;
344         else return 0;
345 }
346 int Person::getLanding(){
347         if(creature==rabbittype)return landanim;
348         if(creature==wolftype)return wolflandanim;
349         return 0;
350 }
351
352
353 bool Person::isLandhard(){
354         if(targetanimation==landhardanim||targetanimation==wolflandhardanim)return 1;
355         else return 0;
356 }
357
358
359 bool Person::wasLandhard(){
360         if(currentanimation==landhardanim||currentanimation==wolflandhardanim)return 1;
361         else return 0;
362 }
363 int Person::getLandhard(){
364         if(creature==rabbittype)return landhardanim;
365         if(creature==wolftype)return wolflandhardanim;
366         return 0;
367 }
368
369
370 bool Person::isFlip(){
371         if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==backflipanim||targetanimation==rightflipanim||targetanimation==leftflipanim||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)return 1;
372         else return 0;
373 }
374
375 bool Person::wasFlip(){
376         if(currentanimation==flipanim||currentanimation==frontflipanim||currentanimation==backflipanim||currentanimation==rightflipanim||currentanimation==leftflipanim||currentanimation==walljumprightkickanim||currentanimation==walljumpleftkickanim)return 1;
377         else return 0;
378 }
379
380 bool Person::isWallJump(){
381         if(targetanimation==walljumpfrontanim||targetanimation==walljumpbackanim||targetanimation==walljumpleftanim||targetanimation==walljumprightanim)return 1;
382         else return 0;
383 }
384
385 void SolidHitBonus();
386 void SolidHitBonus(){
387         if(bonustime<1.5&&(bonus==fourxcombo||bonus==megacombo)){
388                 bonus=megacombo;
389                 bonustime=0;
390                 bonusvalue=160;
391         }
392         else if(bonustime<1.5&&bonus==threexcombo){
393                 bonus=fourxcombo;
394                 bonustime=0;
395                 bonusvalue=80;
396         }
397         else if(bonustime<1.5&&bonus==twoxcombo){
398                 bonus=threexcombo;
399                 bonustime=0;
400                 bonusvalue=40;
401         }
402         else if(bonustime<1.5&&bonus==solidhit){
403                 bonus=twoxcombo;
404                 bonustime=0;
405                 bonusvalue=20;
406         }
407         else {
408                 bonus=solidhit;
409                 bonustime=0;
410                 bonusvalue=10;
411         }
412 }
413
414 void Person::DoBlood(float howmuch,int which){
415         static int bleedxint,bleedyint;
416         static XYZ bloodvel;
417         //if(howmuch&&id==0)blooddimamount=1;
418         if(bloodtoggle&&tutoriallevel!=1){
419                 if(bleeding<=0&&spurt){
420                         spurt=0;
421                         for(int i=0;i<3;i++){
422                                 bloodvel=0;
423                                 if(!skeleton.free){
424                                         bloodvel.z=10;
425                                         bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
426                                 }
427                                 if(skeleton.free){
428                                         bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
429                                 }
430                                 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
431                                 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
432                                 if(skeleton.free){
433                                         Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
434                                         Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
435                                 }
436                                 if(!skeleton.free){
437                                         Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
438                                         Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
439                                 }
440                         }
441                         if(Random()%2==0)
442                                 for(int i=0;i<3;i++){
443                                         if(Random()%2!=0){
444                                                 bloodvel=0;
445                                                 if(skeleton.free) {
446                                                         bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
447                                                         bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
448                                                 } else {
449                                                         bloodvel.z=10;
450                                                         bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
451                                                         bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
452                                                 }
453                                                 bloodvel*=.2;
454                                                 if(skeleton.free){
455                                                         Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
456                                                 } else {
457                                                         Sprite::MakeSprite(splintersprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
458                                                 }
459                                                 Sprite::setLastSpriteSpecial(3);
460                                         }
461                                 }
462                 }
463                 if(decals){
464                         bleeding=howmuch+(float)abs(Random()%100)/200-.25;
465                         bleedxint=0;
466                         bleedyint=0;
467                         int texdetailint=realtexdetail;
468                         if(creature==rabbittype)
469                                 while(bloodText[bleedxint*512*3+bleedyint*3+0]>which+4||bloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
470                                         bleedxint=abs(Random()%512);
471                                         bleedyint=abs(Random()%512);
472                                 }
473                         if(creature==wolftype)
474                                 while(wolfbloodText[bleedxint*512*3+bleedyint*3+0]>which+4||wolfbloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
475                                         bleedxint=abs(Random()%512);
476                                         bleedyint=abs(Random()%512);
477                                 }
478                         bleedy=bleedxint;
479                         bleedx=bleedyint;
480                         bleedy/=realtexdetail;
481                         bleedx/=realtexdetail;
482                         direction=abs(Random()%2)*2-1;
483                 }
484
485         }
486         if(bleeding>2)bleeding=2;
487 }
488
489 void Person::DoBloodBig(float howmuch,int which){
490         static int bleedxint,bleedyint,i,j;
491         static XYZ bloodvel;
492         if(howmuch&&id==0)blooddimamount=1;
493
494         if(tutoriallevel!=1||id==0)
495                 if(aitype!=playercontrolled&&howmuch>0){
496                         int whichsound=-1;
497                         float gLoc[3];
498                         float vel[3];
499                         gLoc[0]=coords.x;
500                         gLoc[1]=coords.y;
501                         gLoc[2]=coords.z;
502                         vel[0]=velocity.x;
503                         vel[1]=velocity.y;
504                         vel[2]=velocity.z;
505
506                         if(creature==wolftype){
507                                 int i=abs(Random()%2);
508                                 if(i==0)whichsound=snarlsound;
509                                 if(i==1)whichsound=snarl2sound;
510                                 envsound[numenvsounds]=coords;
511                                 envsoundvol[numenvsounds]=16;
512                                 envsoundlife[numenvsounds]=.4;
513                                 numenvsounds++;
514                         }
515                         if(creature==rabbittype){
516                                 int i=abs(Random()%2);
517                                 if(i==0)whichsound=rabbitpainsound;
518                                 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
519                                 envsound[numenvsounds]=coords;
520                                 envsoundvol[numenvsounds]=16;
521                                 envsoundlife[numenvsounds]=.4;
522                                 numenvsounds++;
523                                 //if(i==2)whichsound=rabbitpain2sound;
524                         }
525
526                         if(whichsound!=-1){
527                                 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
528                                 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
529                                 OPENAL_SetVolume(channels[whichsound], 512);
530                                 OPENAL_SetPaused(channels[whichsound], false);
531                         }
532                 }
533
534                 if(id==0&&howmuch>0){
535                         flashamount=.5;
536                         flashr=1;
537                         flashg=0;
538                         flashb=0;
539                         flashdelay=0;
540                 }
541
542                 if(bloodtoggle&&decals&&tutoriallevel!=1){
543                         if(bleeding<=0&&spurt){
544                                 spurt=0;
545                                 for(int i=0;i<3;i++){
546                                         bloodvel=0;
547                                         if(!skeleton.free){
548                                                 bloodvel.z=10;
549                                                 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
550                                         }
551                                         if(skeleton.free){
552                                                 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
553                                         }
554                                         if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
555                                         if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
556                                         if(skeleton.free){
557                                                 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
558                                                 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
559                                         }
560                                         if(!skeleton.free){
561                                                 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
562                                                 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
563                                         }
564                                 }
565                         }
566                         int offsetx=0,offsety=0;
567                         if(which==225){
568                                 offsety=Random()%40;
569                                 offsetx=abs(Random()%60);
570                         }
571                         if(which==190||which==185){
572                                 offsety=Random()%40;
573                                 offsetx=abs(Random()%100)-20;
574                         }
575                         if(which==175){
576                                 offsety=Random()%10;
577                                 offsetx=Random()%10;
578                         }
579                         if(which==170){
580                                 offsety=Random()%20;
581                                 offsetx=Random()%20;
582                         }
583                         if(which==220||which==215){
584                                 //offsety=Random()%20;
585                                 offsetx=20;
586                                 //offsetx=abs(Random()%80);
587                         }
588
589
590                         int startx=512;
591                         int starty=512;
592                         int endx=0;
593                         int endy=0;
594                         GLubyte color;
595                         if(creature==rabbittype)
596                                 for(i=0;i<512;i++){
597                                         for(j=0;j<512;j++){
598                                                 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
599                                                         if(i<startx)startx=i;
600                                                         if(j<starty)starty=j;
601                                                         if(i>endx)endx=i;
602                                                         if(j>endy)endy=j;
603                                                 }
604                                         }
605                                 }
606                                 if(creature==wolftype)
607                                         for(i=0;i<512;i++){
608                                                 for(j=0;j<512;j++){
609                                                         if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
610                                                                 if(i<startx)startx=i;
611                                                                 if(j<starty)starty=j;
612                                                                 if(i>endx)endx=i;
613                                                                 if(j>endy)endy=j;
614                                                         }
615                                                 }
616                                         }
617
618                                         startx+=offsetx;
619                                         endx+=offsetx;
620                                         starty+=offsety;
621                                         endy+=offsety;
622
623                                         if(startx<0)startx=0;
624                                         if(starty<0)starty=0;
625                                         if(endx>512-1)endx=512-1;
626                                         if(endy>512-1)endy=512-1;
627                                         if(endx<startx)endx=startx;
628                                         if(endy<starty)endy=starty;
629
630                                         startx/=realtexdetail;
631                                         starty/=realtexdetail;
632                                         endx/=realtexdetail;
633                                         endy/=realtexdetail;
634
635                                         int texdetailint=realtexdetail;
636                                         int where;
637                                         if(creature==rabbittype)
638                                                 for(i=startx;i<endx;i++){
639                                                         for(j=starty;j<endy;j++){
640                                                                 if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
641                                                                         color=Random()%85+170;
642                                                                         where=i*skeleton.skinsize*3+j*3;
643                                                                         if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
644                                                                         skeleton.skinText[where+1]=0;
645                                                                         skeleton.skinText[where+2]=0;
646                                                                 }
647                                                         }
648                                                 }
649                                                 if(creature==wolftype)
650                                                         for(i=startx;i<endx;i++){
651                                                                 for(j=starty;j<endy;j++){
652                                                                         if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
653                                                                                 color=Random()%85+170;
654                                                                                 where=i*skeleton.skinsize*3+j*3;
655                                                                                 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
656                                                                                 skeleton.skinText[where+1]=0;
657                                                                                 skeleton.skinText[where+2]=0;
658                                                                         }
659                                                                 }
660                                                         }
661                                                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
662                                                         if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
663                                                         else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
664
665                                                         bleedxint=0;
666                                                         bleedyint=0;
667                                                         if(creature==rabbittype)
668                                                                 while(bloodText[bleedxint*512*3+bleedyint*3+0]>which+4||bloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
669                                                                         bleedxint=abs(Random()%512);
670                                                                         bleedyint=abs(Random()%512);
671                                                                 }
672                                                                 if(creature==wolftype)
673                                                                         while(wolfbloodText[bleedxint*512*3+bleedyint*3+0]>which+4||wolfbloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
674                                                                                 bleedxint=abs(Random()%512);
675                                                                                 bleedyint=abs(Random()%512);
676                                                                         }
677                                                                         bleedy=bleedxint+offsetx;
678                                                                         bleedx=bleedyint+offsety;
679                                                                         bleedy/=realtexdetail;
680                                                                         bleedx/=realtexdetail;
681                                                                         if(bleedx<0)bleedx=0;
682                                                                         if(bleedy<0)bleedy=0;
683                                                                         if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
684                                                                         if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
685                                                                         direction=abs(Random()%2)*2-1;
686
687                 }
688                 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
689                 deathbleeding+=bleeding;
690                 bloodloss+=bleeding*3;
691
692                 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
693                         if(abs(Random()%2)==0){aitype=gethelptype;
694                         lastseentime=12;
695                         }
696                         else aitype=attacktypecutoff;
697                         ally=0;
698                 }
699                 if(bleeding>2)bleeding=2;
700 }
701
702 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
703         static int bleedxint,bleedyint,i,j;
704         static XYZ bloodvel;
705         static XYZ startpoint,endpoint,colpoint,movepoint;
706         static float rotationpoint;
707         static int whichtri;
708         static XYZ p1,p2,p3,p0;
709         static XYZ N,temp;
710         XYZ bary;
711         XYZ gxx,gyy;
712         float coordsx,coordsy;
713         float total;
714
715         if(bloodtoggle&&decals&&tutoriallevel!=1){
716                 where-=coords;
717                 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
718                 //where=scale;
719                 startpoint=where;
720                 startpoint.y+=100;
721                 endpoint=where;
722                 endpoint.y-=100;
723                 movepoint=0;
724                 rotationpoint=0;
725                 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
726                 if(whichtri!=-1){
727                         p0=colpoint;
728                         p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
729                         p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
730                         p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
731                         /*
732                         CrossProduct(p2-p1,p3-p1,&N);
733                         CrossProduct(p0-p1,p3-p1,&temp);
734                         s =  dotproduct(&temp,&N)/findLength(&N);
735                         CrossProduct(p2-p1,p1-p0,&temp);
736                         t = dotproduct(&temp,&N)/findLength(&N);
737                         r = 1 - (s + t);*/
738
739                         bary.x=findDistancefast(&p0,&p1);
740                         bary.y=findDistancefast(&p0,&p2);
741                         bary.z=findDistancefast(&p0,&p3);
742
743                         total=bary.x+bary.y+bary.z;
744                         bary.x/=total;
745                         bary.y/=total;
746                         bary.z/=total;
747
748                         bary.x=1-bary.x;
749                         bary.y=1-bary.y;
750                         bary.z=1-bary.z;
751
752                         total=bary.x+bary.y+bary.z;
753                         bary.x/=total;
754                         bary.y/=total;
755                         bary.z/=total;
756
757
758                         gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
759                         gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
760                         gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
761                         gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
762                         gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
763                         gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
764                         coordsx=skeleton.drawmodel.Triangles[whichtri].gx[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gx[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gx[2]*bary.z;
765                         coordsy=skeleton.drawmodel.Triangles[whichtri].gy[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gy[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gy[2]*bary.z;
766
767                         //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
768                         //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
769
770                         if(bleeding<=0&&spurt){
771                                 spurt=0;
772                                 for(int i=0;i<3;i++){
773                                         bloodvel=0;
774                                         if(!skeleton.free){
775                                                 bloodvel.z=10;
776                                                 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
777                                         }
778                                         if(skeleton.free){
779                                                 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
780                                         }
781                                         if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
782                                         if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
783                                         if(skeleton.free){
784                                                 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
785                                                 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
786                                         }
787                                         if(!skeleton.free){
788                                                 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
789                                                 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
790                                         }
791                                 }
792                         }
793                         int offsetx=0,offsety=0;
794                         /*if(which==225){
795                         offsety=Random()%40;
796                         offsetx=abs(Random()%120);
797                         }
798                         if(which==220||which==215){
799                         offsety=Random()%20;
800                         offsetx=abs(Random()%80);
801                         }*/
802                         //which=220;
803                         offsetx=(1+coordsy)*512-291;
804                         offsety=coordsx*512-437;
805
806                         int startx=512;
807                         int starty=512;
808                         int endx=0;
809                         int endy=0;
810                         GLubyte color;
811                         if(creature==rabbittype)
812                                 for(i=0;i<512;i++){
813                                         for(j=0;j<512;j++){
814                                                 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
815                                                         if(i<startx)startx=i;
816                                                         if(j<starty)starty=j;
817                                                         if(i>endx)endx=i;
818                                                         if(j>endy)endy=j;
819                                                 }
820                                         }
821                                 }
822                                 if(creature==wolftype)
823                                         for(i=0;i<512;i++){
824                                                 for(j=0;j<512;j++){
825                                                         if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
826                                                                 if(i<startx)startx=i;
827                                                                 if(j<starty)starty=j;
828                                                                 if(i>endx)endx=i;
829                                                                 if(j>endy)endy=j;
830                                                         }
831                                                 }
832                                         }
833                                         startx+=offsetx;
834                                         endx+=offsetx;
835                                         starty+=offsety;
836                                         endy+=offsety;
837
838                                         if(startx<0)startx=0;
839                                         if(starty<0)starty=0;
840                                         if(endx>512-1)endx=512-1;
841                                         if(endy>512-1)endy=512-1;
842                                         if(endx<startx)endx=startx;
843                                         if(endy<starty)endy=starty;
844
845                                         startx/=realtexdetail;
846                                         starty/=realtexdetail;
847                                         endx/=realtexdetail;
848                                         endy/=realtexdetail;
849
850                                         int texdetailint=realtexdetail;
851                                         int where;
852                                         if(creature==rabbittype)
853                                                 for(i=startx;i<endx;i++){
854                                                         for(j=starty;j<endy;j++){
855                                                                 if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
856                                                                         color=Random()%85+170;
857                                                                         where=i*skeleton.skinsize*3+j*3;
858                                                                         if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
859                                                                         skeleton.skinText[where+1]=0;
860                                                                         skeleton.skinText[where+2]=0;
861                                                                 }
862                                                                 else if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
863                                                                         color=Random()%85+170;
864                                                                         where=i*skeleton.skinsize*3+j*3;
865                                                                         if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
866                                                                         skeleton.skinText[where+1]=0;
867                                                                         skeleton.skinText[where+2]=0;
868                                                                 }
869                                                         }
870                                                 }
871                                                 if(creature==wolftype)
872                                                         for(i=startx;i<endx;i++){
873                                                                 for(j=starty;j<endy;j++){
874                                                                         if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
875                                                                                 color=Random()%85+170;
876                                                                                 where=i*skeleton.skinsize*3+j*3;
877                                                                                 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
878                                                                                 skeleton.skinText[where+1]=0;
879                                                                                 skeleton.skinText[where+2]=0;
880                                                                         }
881                                                                         else if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
882                                                                                 color=Random()%85+170;
883                                                                                 where=i*skeleton.skinsize*3+j*3;
884                                                                                 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
885                                                                                 skeleton.skinText[where+1]=0;
886                                                                                 skeleton.skinText[where+2]=0;
887                                                                         }
888                                                                 }
889                                                         }
890                                                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
891                                                         if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
892                                                         else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
893
894                                                         bleedy=(1+coordsy)*512;
895                                                         bleedx=coordsx*512;
896                                                         bleedy/=realtexdetail;
897                                                         bleedx/=realtexdetail;
898                                                         if(bleedx<0)bleedx=0;
899                                                         if(bleedy<0)bleedy=0;
900                                                         if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
901                                                         if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
902                                                         direction=abs(Random()%2)*2-1;
903                 }
904                 if(whichtri==-1)return 0;
905         }
906         bleeding=howmuch+(float)abs(Random()%100)/200-.25;
907         deathbleeding+=bleeding;
908         bloodloss+=bleeding*3;
909
910         if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
911                 if(abs(Random()%2)==0){aitype=gethelptype;
912                 lastseentime=12;
913                 }
914                 else aitype=attacktypecutoff;
915                 ally=0;
916         }
917         if(bleeding>2)bleeding=2;
918         return 1;
919 }
920
921
922 void Person::DoMipmaps(int howmanylevels,float startx, float endx, float starty, float endy){
923         int i,j,k;
924         static float temp;
925         static int bytesPerPixel=3;
926         static int newsize,totalsize,rowsize,bigstep,smallstep,sum;
927         static int newstartx,newstarty,newendx,newendy;
928         static int newnewstartx,newnewstarty,newnewendx,newnewendy;
929         static int which;
930         static float sizemult;
931         /*
932         for(i=0;i<skeleton.skinsize*skeleton.skinsize*bytesPerPixel;i++){
933         texture[i]=skeleton.skinText[i];
934         }
935         */
936         if((!osx||howmanylevels)){
937
938                 if(startx<0)startx=0;
939                 if(starty<0)starty=0;
940                 if(endx>skeleton.skinsize-1)endx=skeleton.skinsize-1;
941                 if(endy>skeleton.skinsize-1)endy=skeleton.skinsize-1;
942                 if((endx>startx&&endy>starty)||howmanylevels){
943
944                         newstartx=startx;
945                         newstarty=starty;
946                         newendx=endx;
947                         newendy=endy;
948
949                         for(i=startx;i<endx;i++){
950                                 for(j=starty;j<endy;j++){
951                                         texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+0]=skeleton.skinText[i*skeleton.skinsize*3+j*3+0];
952                                         texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+1]=skeleton.skinText[i*skeleton.skinsize*3+j*3+1];
953                                         texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+2]=skeleton.skinText[i*skeleton.skinsize*3+j*3+2];
954                                 }
955                         }
956
957                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
958
959                         if(!howmanylevels){
960                                 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
961                                 glTexSubImage2D(GL_TEXTURE_2D,0,starty,startx,endy-starty,endx-startx,GL_RGB,GL_UNSIGNED_BYTE,texturearray);
962                                 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
963                         }
964
965                         newsize=skeleton.skinsize;
966
967                         if(howmanylevels)
968                                 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, skeleton.skinsize, skeleton.skinsize, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0] );
969                 }
970                 /*for(j=1;j<=howmanylevels;j++){
971                 if(j==1)texpointer=&skeleton.skinText[0];
972                 else texpointer=&texture[0];
973
974                 totalsize=int( newsize*newsize*bytesPerPixel);
975                 rowsize=int( newsize*bytesPerPixel );
976                 bigstep=bytesPerPixel*newsize*2;
977                 smallstep=bytesPerPixel*2;
978
979                 which=0;
980
981
982
983                 glTexSubImage2D(GL_TEXTURE_2D,j,0,0,newsize/2,newsize/2,GL_RGB,GL_UNSIGNED_BYTE,texture);
984                 newsize/=2;
985                 }*/
986         }
987 }
988
989
990 void Person::Reverse(){
991         if(victim->aitype==playercontrolled||hostiletime>1)
992                 if(victim->targetanimation!=jumpupanim&&victim->targetanimation!=jumpdownanim&&((tutoriallevel!=1||cananger)&&hostile)){
993                         if(normaldotproduct(victim->facing,victim->coords-coords)>0&&!(victim->id==0&&difficulty<2)&&(creature!=wolftype||victim->creature==wolftype))return;
994                         if(victim->aitype!=playercontrolled&&staggerdelay>0)return;
995                         if(targetanimation==sweepanim){
996                                 targetanimation=sweepreversedanim;
997                                 currentanimation=sweepreversedanim;
998                                 victim->currentanimation=sweepreversalanim;
999                                 victim->targetanimation=sweepreversalanim;
1000                         }
1001                         if(targetanimation==spinkickanim){
1002                                 targetanimation=spinkickreversedanim;
1003                                 currentanimation=spinkickreversedanim;
1004                                 victim->currentanimation=spinkickreversalanim;
1005                                 victim->targetanimation=spinkickreversalanim;
1006                         }
1007                         if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
1008                                 if(targetanimation==rabbittacklinganim){
1009                                         currentframe=6;
1010                                         targetframe=7;
1011                                         victim->currentframe=6;
1012                                         victim->targetframe=7;
1013                                 }
1014                                 targetanimation=upunchreversedanim;
1015                                 currentanimation=upunchreversedanim;
1016                                 victim->currentanimation=upunchreversalanim;
1017                                 victim->targetanimation=upunchreversalanim;
1018                         }
1019                         if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
1020                                 if(victim->weaponactive!=-1){
1021                                         victim->throwtogglekeydown=1;
1022                                         weapons.owner[victim->weaponids[0]]=-1;
1023                                         weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
1024                                         if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
1025                                         weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
1026                                         weapons.missed[victim->weaponids[0]]=1;
1027                                         weapons.freetime[victim->weaponids[0]]=0;
1028                                         weapons.firstfree[victim->weaponids[0]]=1;
1029                                         weapons.physics[victim->weaponids[0]]=1;
1030                                         victim->num_weapons--;
1031                                         if(victim->num_weapons){
1032                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1033                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1034                                  }
1035
1036                                         victim->weaponactive=-1;
1037                                         for(int j=0;j<numplayers;j++){
1038                                                 player[j].wentforweapon=0;
1039                                  }
1040                                 }
1041
1042                                 targetanimation=staffhitreversedanim;
1043                                 currentanimation=staffhitreversedanim;
1044                                 victim->currentanimation=staffhitreversalanim;
1045                                 victim->targetanimation=staffhitreversalanim;
1046                         }
1047                         if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
1048                                 if(victim->weaponactive!=-1){
1049                                         victim->throwtogglekeydown=1;
1050                                         weapons.owner[victim->weaponids[0]]=-1;
1051                                         weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
1052                                         if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
1053                                         weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
1054                                         weapons.missed[victim->weaponids[0]]=1;
1055                                         weapons.freetime[victim->weaponids[0]]=0;
1056                                         weapons.firstfree[victim->weaponids[0]]=1;
1057                                         weapons.physics[victim->weaponids[0]]=1;
1058                                         victim->num_weapons--;
1059                                         if(victim->num_weapons){
1060                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1061                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1062                                  }
1063
1064                                         victim->weaponactive=-1;
1065                                         for(int j=0;j<numplayers;j++){
1066                                                 player[j].wentforweapon=0;
1067                                  }
1068                                 }
1069                                 targetanimation=staffspinhitreversedanim;
1070                                 currentanimation=staffspinhitreversedanim;
1071                                 victim->currentanimation=staffspinhitreversalanim;
1072                                 victim->targetanimation=staffspinhitreversalanim;
1073                         }
1074                         if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
1075                                 if(victim->weaponactive!=-1){
1076                                         victim->throwtogglekeydown=1;
1077                                         weapons.owner[victim->weaponids[0]]=-1;
1078                                         weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
1079                                         if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
1080                                         weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
1081                                         weapons.missed[victim->weaponids[0]]=1;
1082                                         weapons.freetime[victim->weaponids[0]]=0;
1083                                         weapons.firstfree[victim->weaponids[0]]=1;
1084                                         weapons.physics[victim->weaponids[0]]=1;
1085                                         victim->num_weapons--;
1086                                         if(victim->num_weapons){
1087                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1088                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1089                                  }
1090
1091                                         victim->weaponactive=-1;
1092                                         for(int j=0;j<numplayers;j++){
1093                                                 player[j].wentforweapon=0;
1094                                  }
1095                                 }
1096                                 targetanimation=swordslashreversedanim;
1097                                 currentanimation=swordslashreversedanim;
1098                                 victim->currentanimation=swordslashreversalanim;
1099                                 victim->targetanimation=swordslashreversalanim;
1100                         }
1101                         if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
1102                                 if(victim->weaponactive!=-1){
1103                                         victim->throwtogglekeydown=1;
1104                                         weapons.owner[victim->weaponids[0]]=-1;
1105                                         weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
1106                                         if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
1107                                         weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
1108                                         weapons.missed[victim->weaponids[0]]=1;
1109                                         weapons.freetime[victim->weaponids[0]]=0;
1110                                         weapons.firstfree[victim->weaponids[0]]=1;
1111                                         weapons.physics[victim->weaponids[0]]=1;
1112                                         victim->num_weapons--;
1113                                         if(victim->num_weapons){
1114                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1115                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1116                                  }
1117
1118                                         victim->weaponactive=-1;
1119                                         for(int j=0;j<numplayers;j++){
1120                                                 player[j].wentforweapon=0;
1121                                  }
1122                                 }
1123                                 targetanimation=knifeslashreversedanim;
1124                                 currentanimation=knifeslashreversedanim;
1125                                 victim->currentanimation=knifeslashreversalanim;
1126                                 victim->targetanimation=knifeslashreversalanim;
1127                         }
1128                         if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
1129                                 victim->targettilt2=targettilt2;
1130                                 victim->currentframe=currentframe;
1131                                 victim->targetframe=targetframe;
1132                                 victim->target=target;
1133                                 victim->velocity=0;
1134                                 victim->oldcoords=victim->coords;
1135                                 victim->coords=coords;
1136                                 victim->targetrotation=targetrotation;
1137                                 victim->rotation=targetrotation;
1138                                 victim->victim=this;
1139                         }
1140                         if(targetanimation==winduppunchanim){
1141                                 targetanimation=winduppunchblockedanim;
1142                                 victim->targetanimation=blockhighleftanim;
1143                                 victim->targetframe=1;
1144                                 victim->target=.5;
1145                                 victim->victim=this;
1146                                 victim->targetrotation=targetrotation+180;
1147                         }
1148                         if(targetanimation==wolfslapanim){
1149                                 targetanimation=winduppunchblockedanim;
1150                                 victim->targetanimation=blockhighleftanim;
1151                                 victim->targetframe=1;
1152                                 victim->target=.5;
1153                                 victim->victim=this;
1154                                 victim->targetrotation=targetrotation+180;
1155                         }
1156                         if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
1157                                 targetanimation=swordslashparriedanim;
1158                                 parriedrecently=.4;
1159                                 victim->parriedrecently=0;
1160                                 victim->targetanimation=swordslashparryanim;
1161                                 victim->targetframe=1;
1162                                 victim->target=.5;
1163                                 victim->victim=this;
1164                                 victim->targetrotation=targetrotation+180;
1165
1166                                 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
1167                                         float gLoc[3];
1168                                         float vel[3];
1169                                         gLoc[0]=victim->coords.x;
1170                                         gLoc[1]=victim->coords.y;
1171                                         gLoc[2]=victim->coords.z;
1172                                         vel[0]=velocity.x;
1173                                         vel[1]=velocity.y;
1174                                         vel[2]=velocity.z;
1175                                         if(victim->weaponactive!=-1){
1176                                                 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1177                                                         if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1178                                                         if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1179
1180                                                         PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
1181                                                         OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
1182                                                         OPENAL_SetVolume(channels[swordstaffsound], 512);
1183                                                         OPENAL_SetPaused(channels[swordstaffsound], false);
1184                                                 }
1185                                                 else{
1186                                                         PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1187                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1188                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
1189                                                         OPENAL_SetPaused(channels[metalhitsound], false);
1190                                                 }
1191                                         }
1192                                         XYZ aim;
1193                                         victim->Puff(righthand);
1194                                         victim->target=0;
1195                                         victim->targetframe=0;
1196                                         victim->targetanimation=staggerbackhighanim;
1197                                         victim->targetrotation=targetrotation+180;
1198                                         victim->target=0;
1199                                         weapons.owner[victim->weaponids[0]]=-1;
1200                                         aim=DoRotation(facing,0,90,0)*21;
1201                                         aim.y+=7;
1202                                         weapons.velocity[victim->weaponids[0]]=aim*-.2;
1203                                         weapons.tipvelocity[victim->weaponids[0]]=aim;
1204                                         weapons.missed[victim->weaponids[0]]=1;
1205                                         weapons.hitsomething[victim->weaponids[0]]=0;
1206                                         weapons.freetime[victim->weaponids[0]]=0;
1207                                         weapons.firstfree[victim->weaponids[0]]=1;
1208                                         weapons.physics[victim->weaponids[0]]=1;
1209                                         victim->num_weapons--;
1210                                         if(victim->num_weapons){
1211                                                 victim->weaponids[0]=victim->weaponids[num_weapons];
1212                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1213                                  }
1214                                         victim->weaponactive=-1;
1215                                         for(int i=0;i<numplayers;i++){
1216                                                 player[i].wentforweapon=0;
1217                                  }
1218
1219
1220
1221
1222
1223                                         /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1224                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1225                                         OPENAL_SetVolume(channels[metalhitsound], 512);
1226                                         OPENAL_SetPaused(channels[metalhitsound], false);*/
1227                                 }
1228
1229                                 if(abs(Random()%20)==0){
1230                                         float gLoc[3];
1231                                         float vel[3];
1232                                         gLoc[0]=coords.x;
1233                                         gLoc[1]=coords.y;
1234                                         gLoc[2]=coords.z;
1235                                         vel[0]=velocity.x;
1236                                         vel[1]=velocity.y;
1237                                         vel[2]=velocity.z;
1238                                         if(weaponactive!=-1){
1239                                                 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1240                                                         if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1241                                                         if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1242
1243                                                         PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
1244                                                         OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
1245                                                         OPENAL_SetVolume(channels[swordstaffsound], 512);
1246                                                         OPENAL_SetPaused(channels[swordstaffsound], false);
1247                                                 }
1248                                                 else{
1249                                                         PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1250                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1251                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
1252                                                         OPENAL_SetPaused(channels[metalhitsound], false);
1253                                                 }
1254                                         }
1255
1256                                         XYZ aim;
1257                                         Puff(righthand);
1258                                         target=0;
1259                                         targetframe=0;
1260                                         targetanimation=staggerbackhighanim;
1261                                         targetrotation=targetrotation+180;
1262                                         target=0;
1263                                         weapons.owner[weaponids[0]]=-1;
1264                                         aim=DoRotation(facing,0,90,0)*21;
1265                                         aim.y+=7;
1266                                         weapons.velocity[weaponids[0]]=aim*-.2;
1267                                         weapons.tipvelocity[weaponids[0]]=aim;
1268                                         weapons.hitsomething[weaponids[0]]=0;
1269                                         weapons.missed[weaponids[0]]=1;
1270                                         weapons.freetime[weaponids[0]]=0;
1271                                         weapons.firstfree[weaponids[0]]=1;
1272                                         weapons.physics[weaponids[0]]=1;
1273                                         num_weapons--;
1274                                         if(num_weapons){
1275                                                 weaponids[0]=weaponids[num_weapons];
1276                                                 if(weaponstuck==num_weapons)weaponstuck=0;
1277                                  }
1278                                         weaponactive=-1;
1279                                         for(int i=0;i<numplayers;i++){
1280                                                 player[i].wentforweapon=0;
1281                                  }
1282
1283
1284                                         /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1285                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1286                                         OPENAL_SetVolume(channels[metalhitsound], 512);
1287                                         OPENAL_SetPaused(channels[metalhitsound], false);*/
1288                                 }
1289                         }
1290                         if(hasvictim)
1291                                 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1292                                         if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1293                                                 //victim->targetanimation=sweepanim;
1294                                                 victim->targetanimation=dodgebackanim;
1295                                                 victim->targetframe=0;
1296                                                 victim->target=0;
1297                                                 //victim->velocity=0;
1298
1299                                                 XYZ rotatetarget;
1300                                                 rotatetarget=coords-victim->coords;
1301                                                 Normalise(&rotatetarget);
1302                                                 victim->targetrotation=-asin(0-rotatetarget.x);
1303                                                 victim->targetrotation*=360/6.28;
1304                                                 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1305
1306                                                 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1307
1308                                                 victim->lastattack3=victim->lastattack2;
1309                                                 victim->lastattack2=victim->lastattack;
1310                                                 victim->lastattack=victim->targetanimation;
1311                                         }
1312                                         else
1313                                         {
1314                                                 victim->targetanimation=sweepanim;
1315                                                 victim->targetframe=0;
1316                                                 victim->target=0;
1317
1318                                                 XYZ rotatetarget;
1319                                                 rotatetarget=coords-victim->coords;
1320                                                 Normalise(&rotatetarget);
1321                                                 victim->targetrotation=-asin(0-rotatetarget.x);
1322                                                 victim->targetrotation*=360/6.28;
1323                                                 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1324
1325                                                 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1326
1327                                                 victim->lastattack3=victim->lastattack2;
1328                                                 victim->lastattack2=victim->lastattack;
1329                                                 victim->lastattack=victim->targetanimation;
1330                                         }
1331                                 }
1332
1333                                 velocity=0;
1334                                 victim->velocity=0;
1335
1336                                 if(aitype!=playercontrolled)feint=0;
1337                                 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1338                                 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1339                                 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1340
1341                                 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1342                 }
1343 }
1344
1345 void Person::DoDamage(float howmuch){
1346         if(tutoriallevel!=1)damage+=howmuch/power;
1347         if(id!=0)damagedealt+=howmuch/power;
1348         if(id==0)damagetaken+=howmuch/power;
1349
1350         if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1351         if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1352         if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1353         if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1354         if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1355         spurt=0;
1356         if(id==0)camerashake+=howmuch/100;
1357         if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1358         if(blackout>1)blackout=1;
1359
1360         if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1361         if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1362                 if(abs(Random()%2)==0){aitype=gethelptype;
1363                 lastseentime=12;
1364                 }
1365                 else aitype=attacktypecutoff;
1366                 ally=0;
1367         }
1368
1369         if(howmuch>damagetolerance*50&&skeleton.free!=2){
1370                 XYZ flatvelocity2;
1371                 XYZ flatfacing2;
1372                 for(int i=0;i<skeleton.num_joints; i++){
1373                         if(!skeleton.free)flatvelocity2=velocity;
1374                         if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1375                         if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1376                         if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1377                         flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1378                         flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1379                         flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1380                         Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1381                         Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1382                         Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1383                 }
1384
1385                 float gLoc[3];
1386                 float vel[3];
1387                 gLoc[0]=coords.x;
1388                 gLoc[1]=coords.y;
1389                 gLoc[2]=coords.z;
1390                 vel[0]=0;
1391                 vel[1]=0;
1392                 vel[2]=0;
1393                 PlaySoundEx( splattersound, samp[splattersound], NULL, true);
1394                 OPENAL_3D_SetAttributes(channels[splattersound], gLoc, vel);
1395                 OPENAL_SetVolume(channels[splattersound], 256);
1396                 OPENAL_SetPaused(channels[splattersound], false);
1397
1398                 skeleton.free=2;
1399                 DoDamage(10000);
1400                 RagDoll(0);
1401                 /*if(autoslomo){
1402                 slomo=1;
1403                 slomodelay=.2;
1404                 }*/
1405                 if(!dead&&creature==wolftype){
1406                         bonus=Wolfbonus;
1407                         bonustime=0;
1408                         bonusvalue=300;
1409                 }
1410                 dead=2;
1411                 coords=20;
1412         }
1413
1414         if(tutoriallevel!=1||id==0)
1415                 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1416                         int whichsound=-1;
1417                         float gLoc[3];
1418                         float vel[3];
1419                         gLoc[0]=coords.x;
1420                         gLoc[1]=coords.y;
1421                         gLoc[2]=coords.z;
1422                         vel[0]=velocity.x;
1423                         vel[1]=velocity.y;
1424                         vel[2]=velocity.z;
1425
1426                         if(creature==wolftype){
1427                                 int i=abs(Random()%2);
1428                                 if(i==0)whichsound=snarlsound;
1429                                 if(i==1)whichsound=snarl2sound;
1430                                 envsound[numenvsounds]=coords;
1431                                 envsoundvol[numenvsounds]=16;
1432                                 envsoundlife[numenvsounds]=.4;
1433                                 numenvsounds++;
1434                         }
1435                         if(creature==rabbittype){
1436                                 int i=abs(Random()%2);
1437                                 if(i==0)whichsound=rabbitpainsound;
1438                                 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1439                                 envsound[numenvsounds]=coords;
1440                                 envsoundvol[numenvsounds]=16;
1441                                 envsoundlife[numenvsounds]=.4;
1442                                 numenvsounds++;
1443                                 //if(i==2)whichsound=rabbitpain2sound;
1444                         }
1445
1446                         if(whichsound!=-1){
1447                                 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1448                                 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1449                                 OPENAL_SetVolume(channels[whichsound], 512);
1450                                 OPENAL_SetPaused(channels[whichsound], false);
1451                         }
1452                 }
1453                 speechdelay=.3;
1454
1455                 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1456                 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1457 }
1458
1459 void Person::DoHead(){
1460         static XYZ rotatearound;
1461         static XYZ facing;
1462         static float lookspeed=500;
1463
1464         if(!freeze&&!winfreeze){
1465
1466                 //head facing
1467                 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1468                 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1469
1470                 while(targetheadrotation>180)targetheadrotation-=360;
1471                 while(targetheadrotation<-180)targetheadrotation+=360;
1472
1473                 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1474                 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1475                 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1476                 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1477
1478                 if(targetheadrotation2>120)targetheadrotation2=120;
1479                 if(targetheadrotation2<-120)targetheadrotation2=-120;
1480                 if(targetheadrotation>120)targetheadrotation=120;
1481                 if(targetheadrotation<-120)targetheadrotation=-120;
1482
1483                 if(!isIdle())targetheadrotation2=0;
1484                 if(isIdle()){
1485                         if(targetheadrotation>80)targetheadrotation=80;
1486                         if(targetheadrotation<-80)targetheadrotation=-80;
1487                         if(targetheadrotation2>50)targetheadrotation2=50;
1488                         if(targetheadrotation2<-50)targetheadrotation2=-50;
1489                 }
1490
1491                 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1492                 else if(headrotation>targetheadrotation){
1493                         headrotation-=multiplier*lookspeed;
1494                 }
1495                 else if(headrotation<targetheadrotation){
1496                         headrotation+=multiplier*lookspeed;
1497                 }
1498
1499                 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1500                 else if(headrotation2>targetheadrotation2){
1501                         headrotation2-=multiplier*lookspeed/2;
1502                 }
1503                 else if(headrotation2<targetheadrotation2){
1504                         headrotation2+=multiplier*lookspeed/2;
1505                 }
1506
1507                 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1508                 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1509
1510                 facing=0;
1511                 facing.z=-1;
1512                 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1513                         facing=DoRotation(facing,headrotation2*.4,0,0);
1514                         facing=DoRotation(facing,0,headrotation*.4,0);
1515                 }
1516
1517                 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1518                         facing=DoRotation(facing,headrotation2*.8,0,0);
1519                         facing=DoRotation(facing,0,headrotation*.8,0);
1520                 }
1521
1522                 if(targetanimation==walkanim){
1523                         facing=DoRotation(facing,headrotation2*.6,0,0);
1524                         facing=DoRotation(facing,0,headrotation*.6,0);
1525                 }
1526
1527                 skeleton.specialforward[0]=facing;
1528                 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1529                 static int i;
1530                 for(i=0;i<skeleton.num_muscles;i++){
1531                         if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1532                         {
1533                                 skeleton.FindRotationMuscle(i,targetanimation);
1534                         }
1535                 }
1536         }
1537 }
1538
1539 void Person::RagDoll(bool checkcollision){
1540         static XYZ change;
1541         static int l,i,j;
1542         static float speed;
1543         if(!skeleton.free){
1544                 if(id==0)numfalls++;
1545                 if(id==0&&isFlip())numflipfail++;
1546
1547                 escapednum=0;
1548
1549                 facing=0;
1550                 facing.z=1;
1551                 facing=DoRotation(facing,0,rotation,0);
1552
1553                 skeleton.freetime=0;
1554
1555                 skeleton.longdead=0;
1556
1557                 skeleton.free=1;
1558                 skeleton.broken=0;
1559                 skeleton.spinny=1;
1560                 freefall=1;
1561                 skeleton.freefall=1;
1562
1563                 if(!isnormal(velocity.x))velocity.x=0;
1564                 if(!isnormal(velocity.y))velocity.y=0;
1565                 if(!isnormal(velocity.z))velocity.z=0;
1566                 if(!isnormal(rotation))rotation=0;
1567                 if(!isnormal(coords.x))coords=0;
1568                 if(!isnormal(tilt))tilt=0;
1569                 if(!isnormal(tilt2))tilt2=0;
1570
1571                 for(i=0;i<skeleton.num_joints;i++){
1572                         skeleton.joints[i].delay=0;
1573                         skeleton.joints[i].locked=0;
1574                         skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1575                         if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1576                         if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1577                         if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1578                         skeleton.joints[i].position.y+=.1;
1579                         skeleton.joints[i].oldposition=skeleton.joints[i].position;
1580                         skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1581                 }
1582
1583                 for(i=0;i<skeleton.num_joints;i++){
1584                         skeleton.joints[i].velocity=0;
1585                         skeleton.joints[i].velchange=0;
1586                 }
1587                 skeleton.DoConstraints(&coords,&scale);
1588                 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1589                 {
1590                         skeleton.DoConstraints(&coords,&scale);
1591                         skeleton.DoConstraints(&coords,&scale);
1592                         skeleton.DoConstraints(&coords,&scale);
1593                         skeleton.DoConstraints(&coords,&scale);
1594                 }
1595
1596                 speed=animation[targetanimation].speed[targetframe]*2;
1597                 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1598                         speed=animation[currentanimation].speed[currentframe]*2;
1599                 }
1600                 if(transspeed)speed=transspeed*2;
1601
1602                 speed*=speedmult;
1603
1604                 for(i=0;i<skeleton.num_joints;i++){
1605                         if((animation[currentanimation].attack!=reversed||currentanimation==swordslashreversedanim)&&currentanimation!=rabbitkickanim&&!isLanding()&&!wasLanding()&&animation[currentanimation].height==animation[targetanimation].height)skeleton.joints[i].velocity=velocity/scale+facing*5+DoRotation(DoRotation(DoRotation((animation[targetanimation].position[i][targetframe]-animation[currentanimation].position[i][currentframe])*speed,0,0,tilt),tilt2,0,0),0,rotation,0);
1606                         else skeleton.joints[i].velocity=velocity/scale+facing*5;
1607                         change.x=(float)(Random()%100)/100;
1608                         change.y=(float)(Random()%100)/100;
1609                         change.z=(float)(Random()%100)/100;
1610                         skeleton.joints[i].velocity+=change;
1611                         skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1612
1613                         change.x=(float)(Random()%100)/100;
1614                         change.y=(float)(Random()%100)/100;
1615                         change.z=(float)(Random()%100)/100;
1616                         skeleton.joints[i].velchange+=change;
1617                         skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1618                 }
1619
1620                 if(checkcollision){
1621                         XYZ average;
1622                         XYZ lowpoint;
1623                         XYZ colpoint;
1624                         int howmany;
1625                         average=0;
1626                         howmany=0;
1627                         for(j=0;j<skeleton.num_joints;j++){
1628                                 average+=skeleton.joints[j].position;
1629                                 howmany++;
1630                         }
1631                         average/=howmany;
1632                         coords+=average*scale;
1633                         for(j=0;j<skeleton.num_joints;j++){
1634                                 skeleton.joints[j].position-=average;
1635                         }
1636
1637                         whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1638                         whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1639                         if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1640                                 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1641                                         i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1642                                         lowpoint=coords;
1643                                         lowpoint.y+=1;
1644                                         if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1645                                                 coords.x=lowpoint.x;
1646                                                 coords.z=lowpoint.z;
1647                                         }
1648                                 }
1649                 }
1650
1651                 rotation=0;
1652                 updatedelay=0;
1653
1654                 velocity=0;
1655                 for(i=0;i<skeleton.num_joints;i++){
1656                         velocity+=skeleton.joints[i].velocity*scale;
1657                 }
1658                 velocity/=skeleton.num_joints;
1659
1660                 if(Random()%2==0){
1661                         if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1662                                 weapons.owner[weaponids[0]]=-1;
1663                                 weapons.hitsomething[weaponids[0]]=0;
1664                                 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1665                                 weapons.velocity[weaponids[0]].x+=.01;
1666                                 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1667                                 weapons.missed[weaponids[0]]=1;
1668                                 weapons.freetime[weaponids[0]]=0;
1669                                 weapons.firstfree[weaponids[0]]=1;
1670                                 weapons.physics[weaponids[0]]=1;
1671                                 num_weapons--;
1672                                 if(num_weapons){
1673                                         weaponids[0]=weaponids[num_weapons];
1674                                         if(weaponstuck==num_weapons)weaponstuck=0;
1675                                 }
1676                                 weaponactive=-1;
1677                                 for(i=0;i<numplayers;i++){
1678                                         player[i].wentforweapon=0;
1679                                 }
1680                         }
1681                 }
1682
1683                 targetanimation=bounceidleanim;
1684                 currentanimation=bounceidleanim;
1685                 targetframe=0;
1686                 currentframe=0;
1687         }
1688 }
1689
1690
1691
1692 void Person::FootLand(int which, float opacity){
1693         static XYZ terrainlight;
1694         static XYZ footvel,footpoint;
1695         if(opacity>=1||skiddelay<=0)
1696                 if(opacity>1)
1697                 {
1698                         footvel=0;
1699                         if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1700                         if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1701                         //footpoint.y=coords.y;
1702                         if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1703                 }
1704                 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1705                         footvel=velocity/5;
1706                         if(footvel.y<.8)footvel.y=.8;
1707                         if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1708                         if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1709                         footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1710                         terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1711                         if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1712                         if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1713                 }
1714                 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1715                         footvel=velocity/5;
1716                         if(footvel.y<.8)footvel.y=.8;
1717                         if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1718                         if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1719                         footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1720                         terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1721                         if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5*opacity);
1722                 }
1723                 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1724                         footvel=velocity/5;
1725                         if(footvel.y<.8)footvel.y=.8;
1726                         if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1727                         if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1728                         footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1729                         terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1730                         if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7*opacity);
1731                         if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1732                 }
1733                 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1734                 {
1735                         footvel=velocity/5;
1736                         if(footvel.y<.8)footvel.y=.8;
1737                         if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1738                         if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1739                         //footpoint.y=coords.y;
1740                         if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1741                 }
1742 }
1743
1744 void Person::Puff(int whichlabel){
1745         static XYZ footvel,footpoint;
1746
1747         footvel=0;
1748         footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1749         Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1750 }
1751
1752
1753 void    Person::DoAnimations(){
1754         if(!skeleton.free){
1755                 int i = 0;
1756                 static float oldtarget;
1757
1758                 if(isIdle()&&currentanimation!=getIdle())normalsupdatedelay=0;
1759
1760                 if(targetanimation==tempanim||currentanimation==tempanim){
1761                         animation[tempanim]=tempanimation;
1762                 }
1763                 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1764                         float gLoc[3];
1765                         float vel[3];
1766                         gLoc[0]=coords.x;
1767                         gLoc[1]=coords.y;
1768                         gLoc[2]=coords.z;
1769                         vel[0]=velocity.x;
1770                         vel[1]=velocity.y;
1771                         vel[2]=velocity.z;
1772
1773                         if(id==0){
1774                                 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1775                                 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1776                         }
1777                         if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1778                         if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1779                 }
1780                 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1781                         XYZ targfacing;
1782                         targfacing=0;
1783                         targfacing.z=1;
1784
1785                         targfacing=DoRotation(targfacing,0,targetrotation,0);
1786
1787                         if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1788                         else targetanimation=backflipanim;
1789                         crouchtogglekeydown=1;
1790                         targetframe=0;
1791                         target=0;
1792
1793                         if(id==0)numflipped++;
1794                 }
1795
1796                 if(animation[targetanimation].attack!=reversed)feint=0;
1797                 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1798                         crouchtogglekeydown=0;
1799                         if(aitype==playercontrolled)feint=0;
1800                 }
1801                 else
1802                 {
1803                         if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1804                         if(!isFlip())crouchtogglekeydown=1;
1805                 }
1806
1807
1808                 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1809                         if(detail)normalsupdatedelay=0;
1810                 }
1811
1812                 if(target>=1){
1813                         if(targetanimation==rollanim&&targetframe==3&&onfire){
1814                                 onfire=0;
1815                                 float gLoc[3];
1816                                 float vel[3];
1817                                 gLoc[0]=coords.x;
1818                                 gLoc[1]=coords.y;
1819                                 gLoc[2]=coords.z;
1820                                 vel[0]=0;
1821                                 vel[1]=0;
1822                                 vel[2]=0;
1823                                 PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
1824                                 OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
1825                                 OPENAL_SetVolume(channels[fireendsound], 256);
1826                                 OPENAL_SetPaused(channels[fireendsound], false);
1827                                 OPENAL_SetPaused(channels[stream_firesound], true);
1828                                 deathbleeding=0;
1829                         }
1830
1831                         if(targetanimation==rabbittacklinganim&&targetframe==1){
1832                                 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1833                                 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1834                                 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1835                                         if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1836                                         else victim->targetanimation=rabbittackledfrontanim;
1837                                         victim->targetframe=2;
1838                                         victim->target=0;
1839                                         victim->rotation=rotation;
1840                                         victim->targetrotation=rotation;
1841                                         if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1842                                         //victim->DoDamage(30);
1843                                         if(creature==wolftype){
1844                                                 DoBloodBig(0,255);
1845                                                 float gLoc[3];
1846                                                 float vel[3];
1847                                                 gLoc[0]=victim->coords.x;
1848                                                 gLoc[1]=victim->coords.y;
1849                                                 gLoc[2]=victim->coords.z;
1850                                                 vel[0]=velocity.x;
1851                                                 vel[1]=velocity.y;
1852                                                 vel[2]=velocity.z;
1853                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
1854                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
1855                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
1856                                                 OPENAL_SetPaused(channels[clawslicesound], false);
1857                                                 victim->spurt=1;
1858                                                 victim->DoBloodBig(1/victim->armorhead,210);
1859                                         }
1860                                         if(id==0){
1861                                                 bonus=TackleBonus;
1862                                                 bonustime=0;
1863                                                 bonusvalue=5;
1864                                                 if(victim->aitype==gethelptype)bonusvalue=50;
1865                                         }
1866                                 }
1867                         }
1868
1869                         if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&&currentanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1870                                 if(weapons.type[weaponids[0]]==knife){
1871                                         if(weaponactive==-1)weaponactive=0;
1872                                         else if(weaponactive==0)weaponactive=-1;
1873
1874                                         if(weaponactive==-1){
1875                                                 float gLoc[3];
1876                                                 float vel[3];
1877                                                 gLoc[0]=coords.x;
1878                                                 gLoc[1]=coords.y;
1879                                                 gLoc[2]=coords.z;
1880                                                 vel[0]=velocity.x;
1881                                                 vel[1]=velocity.y;
1882                                                 vel[2]=velocity.z;
1883
1884                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
1885                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
1886                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
1887                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
1888                                         }
1889                                         if(weaponactive!=-1){
1890                                                 float gLoc[3];
1891                                                 float vel[3];
1892                                                 gLoc[0]=coords.x;
1893                                                 gLoc[1]=coords.y;
1894                                                 gLoc[2]=coords.z;
1895                                                 vel[0]=velocity.x;
1896                                                 vel[1]=velocity.y;
1897                                                 vel[2]=velocity.z;
1898
1899                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
1900                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
1901                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
1902                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
1903                                         }
1904                                 }
1905                                 drawtogglekeydown=1;
1906                         }
1907                         //Footstep sounds
1908                         if(tutoriallevel!=1||id==0)
1909                                 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1910                                         int whichsound;
1911                                         float gLoc[3];
1912                                         float vel[3];
1913                                         gLoc[0]=coords.x;
1914                                         gLoc[1]=coords.y;
1915                                         gLoc[2]=coords.z;
1916                                         vel[0]=velocity.x;
1917                                         vel[1]=velocity.y;
1918                                         vel[2]=velocity.z;
1919                                         if(onterrain){
1920                                                 if(terrain.getOpacity(coords.x,coords.z)<.2){
1921                                                         if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1922                                                         else whichsound=footstepsound2;
1923                                                         if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1924                                                         if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1925                                                         if(animation[targetanimation].label[targetframe]==3&&isRun()){
1926                                                                 FootLand(1,1);
1927                                                                 FootLand(0,1);
1928                                                         }
1929
1930                                                 }
1931                                                 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1932                                                         if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1933                                                         else whichsound=footstepsound4;
1934                                                 }
1935                                         }
1936                                         if(!onterrain){
1937                                                 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1938                                                 else whichsound=footstepsound4;
1939                                         }
1940                                         if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1941                                                 if(animation[targetanimation].attack!=neutral){
1942                                                         i=abs(Random()%3);
1943                                                         if(i==0)whichsound=lowwhooshsound;
1944                                                         if(i==1)whichsound=midwhooshsound;
1945                                                         if(i==2)whichsound=highwhooshsound;
1946                                                 }
1947                                                 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1948                                         }
1949                                         else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1950                                         if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1951
1952                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1953                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1954                                         if(whichsound!=knifeswishsound)OPENAL_SetVolume(channels[whichsound], 128);
1955                                         if(whichsound!=knifeswishsound&&(targetanimation==staffhitanim||targetanimation==staffgroundsmashanim||targetanimation==staffspinhitanim))OPENAL_SetVolume(channels[whichsound], 256);
1956                                         if(whichsound==knifeswishsound)OPENAL_SetVolume(channels[whichsound], 512);
1957                                         OPENAL_SetPaused(channels[whichsound], false);
1958
1959                                         if(id==0)
1960                                                 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1961                                                         envsound[numenvsounds]=coords;
1962                                                         if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1963                                                         else envsoundvol[numenvsounds]=6;
1964                                                         envsoundlife[numenvsounds]=.4;
1965                                                         numenvsounds++;
1966                                                 }
1967
1968                                                 if(animation[targetanimation].label[targetframe]==3){
1969                                                         whichsound--;
1970                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1971                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1972                                                         OPENAL_SetVolume(channels[whichsound], 128);
1973                                                         OPENAL_SetPaused(channels[whichsound], false);
1974                                                 }
1975                                 }
1976
1977                                 //Combat sounds
1978                                 if(tutoriallevel!=1||id==0)
1979                                         if(speechdelay<=0)
1980                                                 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1981                                                         if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1982                                                                 int whichsound=-1;
1983                                                                 float gLoc[3];
1984                                                                 float vel[3];
1985                                                                 gLoc[0]=coords.x;
1986                                                                 gLoc[1]=coords.y;
1987                                                                 gLoc[2]=coords.z;
1988                                                                 vel[0]=velocity.x;
1989                                                                 vel[1]=velocity.y;
1990                                                                 vel[2]=velocity.z;
1991                                                                 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1992                                                                         if(animation[targetanimation].attack!=neutral){
1993                                                                                 i=abs(Random()%4);
1994                                                                                 if(creature==rabbittype){
1995                                                                                         if(i==0)whichsound=rabbitattacksound;
1996                                                                                         if(i==1)whichsound=rabbitattack2sound;
1997                                                                                         if(i==2)whichsound=rabbitattack3sound;
1998                                                                                         if(i==3)whichsound=rabbitattack4sound;
1999                                                                                 }
2000                                                                                 if(creature==wolftype){
2001                                                                                         if(i==0)whichsound=barksound;
2002                                                                                         if(i==1)whichsound=bark2sound;
2003                                                                                         if(i==2)whichsound=bark3sound;
2004                                                                                         if(i==3)whichsound=barkgrowlsound;
2005                                                                                 }
2006                                                                                 speechdelay=.3;
2007                                                                         }
2008                                                                         //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
2009                                                                 }
2010                                                                 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
2011                                                                 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
2012
2013                                                                 if(whichsound!=-1){
2014                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
2015                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
2016                                                                         OPENAL_SetVolume(channels[whichsound], 512);
2017                                                                         OPENAL_SetPaused(channels[whichsound], false);
2018                                                                 }
2019                                                         }
2020
2021
2022
2023                                                         if((!wasLanding()&&!wasLandhard())&&currentanimation!=getIdle()&&(isLanding()||isLandhard())){
2024                                                                 FootLand(0,1);
2025                                                                 FootLand(1,1);
2026                                                         }
2027
2028                                                         transspeed=0;
2029                                                         currentoffset=targetoffset;
2030                                                         targetframe=currentframe;
2031                                                         currentanimation=targetanimation;
2032                                                         targetframe++;
2033
2034                                                         if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
2035                                                                 for(i=0;i<weapons.numweapons;i++){
2036                                                                         if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
2037                                                                                 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
2038                                                                                         if(findDistancefast(&coords,&weapons.position[i])>=1){
2039                                                                                                 if(weapons.type[i]!=staff){
2040                                                                                                         float gLoc[3];
2041                                                                                                         float vel[3];
2042                                                                                                         gLoc[0]=coords.x;
2043                                                                                                         gLoc[1]=coords.y;
2044                                                                                                         gLoc[2]=coords.z;
2045                                                                                                         vel[0]=velocity.x;
2046                                                                                                         vel[1]=velocity.y;
2047                                                                                                         vel[2]=velocity.z;
2048                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2049                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2050                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2051                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2052                                                                                                 }
2053
2054                                                                                                 weaponactive=0;
2055                                                                                                 weapons.owner[i]=id;
2056                                                                                                 if(num_weapons>0){
2057                                                                                                         weaponids[num_weapons]=weaponids[0];
2058                                                                                                 }
2059                                                                                                 num_weapons++;
2060                                                                                                 weaponids[0]=i;
2061                                                                                         }
2062                                                                                 }
2063                                                                 }
2064                                                         }
2065
2066                                                         static bool willwork;
2067                                                         if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
2068                                                                 for(i=0;i<weapons.numweapons;i++){
2069                                                                         bool willwork=1;
2070                                                                         if(weapons.owner[i]!=-1)
2071                                                                                 if(player[weapons.owner[i]].weaponstuck!=-1)
2072                                                                                         if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
2073                                                                                                 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
2074                                                                         if((/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)||(hasvictim&&weapons.owner[i]==victim->id&&victim->skeleton.free))
2075                                                                                 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
2076                                                                                         if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
2077                                                                                                 float gLoc[3];
2078                                                                                                 float vel[3];
2079                                                                                                 gLoc[0]=coords.x;
2080                                                                                                 gLoc[1]=coords.y;
2081                                                                                                 gLoc[2]=coords.z;
2082                                                                                                 vel[0]=velocity.x;
2083                                                                                                 vel[1]=velocity.y;
2084                                                                                                 vel[2]=velocity.z;
2085                                                                                                 bool fleshstuck=0;
2086                                                                                                 if(weapons.owner[i]!=-1)
2087                                                                                                         if(victim->weaponstuck!=-1){
2088                                                                                                                 if(victim->weaponids[victim->weaponstuck]==i){
2089                                                                                                                         fleshstuck=1;
2090                                                                                                                 }
2091                                                                                                         }
2092                                                                                                         if(!fleshstuck){
2093                                                                                                                 if(weapons.type[i]!=staff){
2094                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2095                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2096                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2097                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2098                                                                                                                 }
2099                                                                                                         }
2100                                                                                                         if(fleshstuck){
2101                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
2102                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
2103                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
2104                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
2105                                                                                                         }
2106                                                                                                         weaponactive=0;
2107                                                                                                         if(weapons.owner[i]!=-1){
2108
2109                                                                                                                 victim=&player[weapons.owner[i]];
2110                                                                                                                 if(victim->num_weapons==1)victim->num_weapons=0;
2111                                                                                                                 else victim->num_weapons=1;
2112
2113                                                                                                                 //victim->weaponactive=-1;
2114                                                                                                                 victim->skeleton.longdead=0;
2115                                                                                                                 victim->skeleton.free=1;
2116                                                                                                                 victim->skeleton.broken=0;
2117
2118                                                                                                                 for(int j=0;j<victim->skeleton.num_joints;j++){
2119                                                                                                                         victim->skeleton.joints[j].velchange=0;
2120                                                                                                                         victim->skeleton.joints[j].locked=0;
2121                                                                                                                 }
2122
2123                                                                                                                 XYZ relative;
2124                                                                                                                 relative=0;
2125                                                                                                                 relative.y=10;
2126                                                                                                                 Normalise(&relative);
2127                                                                                                                 XYZ footvel,footpoint;
2128                                                                                                                 footvel=0;
2129                                                                                                                 footpoint=weapons.position[i];
2130                                                                                                                 if(victim->weaponstuck!=-1){
2131                                                                                                                         if(victim->weaponids[victim->weaponstuck]==i){
2132                                                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2133                                                                                                                                 weapons.bloody[i]=2;
2134                                                                                                                                 weapons.blooddrip[i]=5;
2135                                                                                                                                 victim->weaponstuck=-1;
2136                                                                                                                         }
2137                                                                                                                 }
2138                                                                                                                 if(victim->num_weapons>0){
2139                                                                                                                         if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
2140                                                                                                                         if(victim->weaponids[0]==i)
2141                                                                                                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
2142                                                                                                                 }
2143
2144                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
2145                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
2146                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
2147                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
2148                                                                                                         }
2149                                                                                                         weapons.owner[i]=id;
2150                                                                                                         if(num_weapons>0){
2151                                                                                                                 weaponids[num_weapons]=weaponids[0];
2152                                                                                                         }
2153                                                                                                         num_weapons++;
2154                                                                                                         weaponids[0]=i;
2155                                                                                         }
2156                                                                                 }
2157                                                                 }
2158                                                         }
2159
2160                                                         if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
2161                                                                 if(weaponactive==-1)weaponactive=0;
2162                                                                 else if(weaponactive==0){
2163                                                                         weaponactive=-1;
2164                                                                         if(num_weapons==2){
2165                                                                                 int buffer;
2166                                                                                 buffer=weaponids[0];
2167                                                                                 weaponids[0]=weaponids[1];
2168                                                                                 weaponids[1]=buffer;
2169                                                                         }
2170                                                                 }
2171                                                                 if(weaponactive==-1){
2172                                                                         float gLoc[3];
2173                                                                         float vel[3];
2174                                                                         gLoc[0]=coords.x;
2175                                                                         gLoc[1]=coords.y;
2176                                                                         gLoc[2]=coords.z;
2177                                                                         vel[0]=velocity.x;
2178                                                                         vel[1]=velocity.y;
2179                                                                         vel[2]=velocity.z;
2180
2181                                                                         PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2182                                                                         OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2183                                                                         OPENAL_SetVolume(channels[knifesheathesound], 128);
2184                                                                         OPENAL_SetPaused(channels[knifesheathesound], false);
2185                                                                 }
2186                                                                 if(weaponactive!=-1){
2187                                                                         float gLoc[3];
2188                                                                         float vel[3];
2189                                                                         gLoc[0]=coords.x;
2190                                                                         gLoc[1]=coords.y;
2191                                                                         gLoc[2]=coords.z;
2192                                                                         vel[0]=velocity.x;
2193                                                                         vel[1]=velocity.y;
2194                                                                         vel[2]=velocity.z;
2195
2196                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2197                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2198                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2199                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2200                                                                 }
2201                                                         }
2202
2203
2204                                                         if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
2205                                                                 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
2206                                                                 Normalise(&rotatetarget);
2207                                                                 targetrotation=-asin(0-rotatetarget.x);
2208                                                                 targetrotation*=360/6.28;
2209                                                                 if(rotatetarget.z<0)targetrotation=180-targetrotation;
2210
2211                                                                 if(targetanimation==walljumprightkickanim)targetrotation+=40;
2212                                                                 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
2213                                                         }
2214
2215                                                         bool dojumpattack;
2216                                                         dojumpattack=0;
2217                                                         if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
2218                                                         if(hasvictim)
2219                         if(findDistancefast(&victim->coords,&/*player[i].*/coords)<5&&victim->aitype==gethelptype&&(attackkeydown)&&!victim->skeleton.free&&victim->isRun()&&victim->runninghowlong>=1)dojumpattack=1;                                                  if(!hostile)dojumpattack=0;
2220                                                         if(dojumpattack){
2221                                                                 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
2222                                                                         targetanimation=rabbittackleanim;
2223                                                                         targetframe=0;
2224                                                                         float gLoc[3];
2225                                                                         float vel[3];
2226                                                                         gLoc[0]=coords.x;
2227                                                                         gLoc[1]=coords.y;
2228                                                                         gLoc[2]=coords.z;
2229                                                                         vel[0]=velocity.x;
2230                                                                         vel[1]=velocity.y;
2231                                                                         vel[2]=velocity.z;
2232
2233                                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
2234                                                                         OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
2235                                                                         OPENAL_SetVolume(channels[jumpsound], 128);
2236                                                                         OPENAL_SetPaused(channels[jumpsound], false);
2237                                                                 }
2238
2239                                                                 float closestdist;
2240                                                                 closestdist=0;
2241                                                                 int closestid;
2242                                                                 closestid=-1;
2243                                                                 XYZ targetloc;
2244                                                                 targetloc=velocity;
2245                                                                 Normalise(&targetloc);
2246                                                                 targetloc+=coords;
2247                                                                 for(i=0;i<numplayers;i++){
2248                                                                         if(i!=id)
2249                                                                                 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
2250                                                                                         closestdist=findDistancefast(&targetloc,&player[i].coords);
2251                                                                                         closestid=i;
2252                                                                                 }
2253                                                                 }
2254                                                                 if(closestid!=-1)
2255                                                                         if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
2256                                                                                 hasvictim=1;
2257                                                                                 victim=&player[closestid];
2258                                                                                 coords=victim->coords;
2259                                                                                 currentanimation=rabbittacklinganim;
2260                                                                                 targetanimation=rabbittacklinganim;
2261                                                                                 currentframe=0;
2262                                                                                 targetframe=1;
2263                                                                                 XYZ rotatetarget;
2264                                                                                 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
2265                                                                                         rotatetarget=coords-victim->coords;
2266                                                                                         Normalise(&rotatetarget);
2267                                                                                         targetrotation=-asin(0-rotatetarget.x);
2268                                                                                         targetrotation*=360/6.28;
2269                                                                                         if(rotatetarget.z<0)targetrotation=180-targetrotation;
2270                                                                                 }
2271                                                                                 if(targetanimation!=rabbitrunninganim){
2272                                                                                         float gLoc[3];
2273                                                                                         float vel[3];
2274                                                                                         gLoc[0]=coords.x;
2275                                                                                         gLoc[1]=coords.y;
2276                                                                                         gLoc[2]=coords.z;
2277                                                                                         vel[0]=velocity.x;
2278                                                                                         vel[1]=velocity.y;
2279                                                                                         vel[2]=velocity.z;
2280
2281                                                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
2282                                                                                         OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
2283                                                                                         OPENAL_SetVolume(channels[jumpsound], 128);
2284                                                                                         OPENAL_SetPaused(channels[jumpsound], false);
2285                                                                                 }
2286                                                                         }
2287                                                         }
2288
2289                                                         //Move impacts
2290                                                         float damagemult=1*power;
2291                                                         if(creature==wolftype)damagemult=2.5*power;
2292                                                         if(hasvictim){damagemult/=victim->damagetolerance/200;}
2293                                                         //if(onfire)damagemult=3;
2294                                                         if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
2295                                                                 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
2296                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2297                                                                                 escapednum=0;
2298                                                                                 if(id==0)camerashake+=.4;
2299                                                                                 if(Random()%2||creature==wolftype){
2300                                                                                         victim->spurt=1;
2301                                                                                         DoBlood(.2,250);
2302                                                                                         if(creature==wolftype)DoBloodBig(0,250);
2303                                                                                 }
2304                                                                                 float gLoc[3];
2305                                                                                 float vel[3];
2306                                                                                 gLoc[0]=victim->coords.x;
2307                                                                                 gLoc[1]=victim->coords.y;
2308                                                                                 gLoc[2]=victim->coords.z;
2309                                                                                 vel[0]=velocity.x;
2310                                                                                 vel[1]=velocity.y;
2311                                                                                 vel[2]=velocity.z;
2312                                                                                 if(tutoriallevel!=1){
2313                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2314                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2315                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
2316                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2317                                                                                 }
2318                                                                                 if(creature==wolftype){
2319                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2320                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2321                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2322                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2323                                                                                         victim->spurt=1;
2324                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2325                                                                                 }
2326                                                                                 victim->RagDoll(0);
2327                                                                                 XYZ relative;
2328                                                                                 relative=victim->coords-coords;
2329                                                                                 relative.y=0;
2330                                                                                 Normalise(&relative);
2331                                                                                 relative=DoRotation(relative,0,-90,0);
2332                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2333                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2334                                                                                 }
2335                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2336                                                                                 //FootLand(1,2);
2337                                                                                 victim->Puff(head);
2338                                                                                 victim->DoDamage(damagemult*100/victim->protectionhead);
2339
2340                                                                                 if(id==0){
2341                                                                                         SolidHitBonus();
2342                                                                                 }
2343                                                                         }
2344                                                                 }
2345
2346                                                                 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
2347                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2348                                                                                 escapednum=0;
2349                                                                                 if(id==0)camerashake+=.4;
2350                                                                                 if(Random()%2||creature==wolftype){
2351                                                                                         victim->spurt=1;
2352                                                                                         if(creature==wolftype)DoBloodBig(0,235);
2353                                                                                 }
2354                                                                                 float gLoc[3];
2355                                                                                 float vel[3];
2356                                                                                 gLoc[0]=victim->coords.x;
2357                                                                                 gLoc[1]=victim->coords.y;
2358                                                                                 gLoc[2]=victim->coords.z;
2359                                                                                 vel[0]=velocity.x;
2360                                                                                 vel[1]=velocity.y;
2361                                                                                 vel[2]=velocity.z;
2362                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2363                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2364                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2365                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2366                                                                                 if(creature==wolftype){
2367                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2368                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2369                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2370                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2371                                                                                         victim->spurt=1;
2372                                                                                         victim->DoBloodBig(2,175);
2373                                                                                 }
2374                                                                                 victim->RagDoll(0);
2375                                                                                 XYZ relative;
2376                                                                                 relative=victim->coords-coords;
2377                                                                                 relative.y=0;
2378                                                                                 Normalise(&relative);
2379                                                                                 relative.y-=1;
2380                                                                                 Normalise(&relative);
2381                                                                                 relative=DoRotation(relative,0,90,0);
2382                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2383                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2384                                                                                 }
2385                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2386                                                                                 //FootLand(1,2);
2387                                                                                 victim->Puff(head);
2388                                                                                 victim->DoDamage(damagemult*50/victim->protectionhead);
2389                                                                         }
2390                                                                 }
2391
2392                                                                 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
2393                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2394                                                                                 escapednum=0;
2395                                                                                 if(id==0)camerashake+=.4;
2396                                                                                 victim->spurt=1;
2397                                                                                 DoBlood(.2,250);
2398                                                                                 float gLoc[3];
2399                                                                                 float vel[3];
2400                                                                                 gLoc[0]=victim->coords.x;
2401                                                                                 gLoc[1]=victim->coords.y;
2402                                                                                 gLoc[2]=victim->coords.z;
2403                                                                                 vel[0]=velocity.x;
2404                                                                                 vel[1]=velocity.y;
2405                                                                                 vel[2]=velocity.z;
2406                                                                                 if(tutoriallevel!=1){
2407                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2408                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2409                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 160);
2410                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2411                                                                                 }
2412                                                                                 if(creature==wolftype){
2413                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2414                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2415                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2416                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2417                                                                                         victim->spurt=1;
2418                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2419                                                                                 }
2420                                                                                 victim->RagDoll(0);
2421                                                                                 XYZ relative;
2422                                                                                 relative=facing;
2423                                                                                 relative.y=0;
2424                                                                                 Normalise(&relative);
2425                                                                                 relative=DoRotation(relative,0,-90,0);
2426                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2427                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2428                                                                                 }
2429                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2430                                                                                 //FootLand(1,2);
2431                                                                                 victim->Puff(head);
2432                                                                                 victim->DoDamage(damagemult*150/victim->protectionhead);
2433
2434                                                                                 if(victim->damage>victim->damagetolerance){
2435                                                                                         if(id==0){
2436                                                                                                 bonus=style;
2437                                                                                                 bonustime=0;
2438                                                                                                 bonusvalue=150;
2439                                                                                         }
2440                                                                                 }
2441                                                                                 else if(id==0){
2442                                                                                         SolidHitBonus();
2443                                                                                 }
2444                                                                         }
2445                                                                 }
2446
2447                                                                 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2448                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2449                                                                                 escapednum=0;
2450                                                                                 if(id==0)camerashake+=.4;
2451                                                                                 victim->spurt=1;
2452                                                                                 DoBlood(.2,250);
2453                                                                                 float gLoc[3];
2454                                                                                 float vel[3];
2455                                                                                 gLoc[0]=victim->coords.x;
2456                                                                                 gLoc[1]=victim->coords.y;
2457                                                                                 gLoc[2]=victim->coords.z;
2458                                                                                 vel[0]=velocity.x;
2459                                                                                 vel[1]=velocity.y;
2460                                                                                 vel[2]=velocity.z;
2461                                                                                 if(tutoriallevel!=1){
2462                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2463                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2464                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 160);
2465                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2466                                                                                 }
2467                                                                                 if(creature==wolftype){
2468                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2469                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2470                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2471                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2472                                                                                         victim->spurt=1;
2473                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2474                                                                                 }
2475                                                                                 victim->RagDoll(0);
2476                                                                                 XYZ relative;
2477                                                                                 relative=facing;
2478                                                                                 relative.y=0;
2479                                                                                 Normalise(&relative);
2480                                                                                 relative=DoRotation(relative,0,90,0);
2481                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2482                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2483                                                                                 }
2484                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2485                                                                                 //FootLand(1,2);
2486                                                                                 victim->Puff(head);
2487                                                                                 victim->DoDamage(damagemult*150/victim->protectionhead);
2488
2489                                                                                 if(victim->damage>victim->damagetolerance){
2490                                                                                         if(id==0){
2491                                                                                                 bonus=style;
2492                                                                                                 bonustime=0;
2493                                                                                                 bonusvalue=150;
2494                                                                                         }
2495                                                                                 }
2496                                                                                 else if(id==0){
2497                                                                                         SolidHitBonus();
2498                                                                                 }
2499                                                                         }
2500                                                                 }
2501
2502                                                                 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2503                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2504                                                                                 escapednum=0;
2505                                                                                 if(id==0)camerashake+=.4;
2506                                                                                 if(Random()%2){
2507                                                                                         victim->spurt=1;
2508                                                                                         DoBlood(.2,235);
2509                                                                                 }
2510                                                                                 float gLoc[3];
2511                                                                                 float vel[3];
2512                                                                                 gLoc[0]=victim->coords.x;
2513                                                                                 gLoc[1]=victim->coords.y;
2514                                                                                 gLoc[2]=victim->coords.z;
2515                                                                                 vel[0]=velocity.x;
2516                                                                                 vel[1]=velocity.y;
2517                                                                                 vel[2]=velocity.z;
2518                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2519                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2520                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2521                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2522                                                                                 victim->RagDoll(0);
2523                                                                                 XYZ relative;
2524                                                                                 relative=victim->coords-coords;
2525                                                                                 relative.y=0;
2526                                                                                 Normalise(&relative);
2527                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2528                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2529                                                                                 }
2530                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2531                                                                                 //FootLand(1,2);
2532                                                                                 victim->Puff(head);
2533                                                                                 victim->DoDamage(damagemult*50/victim->protectionhead);
2534                                                                         }
2535                                                                 }
2536
2537                                                                 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2538                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2539                                                                                 escapednum=0;
2540                                                                                 if(id==0)camerashake+=.2;
2541                                                                                 float gLoc[3];
2542                                                                                 float vel[3];
2543                                                                                 gLoc[0]=victim->coords.x;
2544                                                                                 gLoc[1]=victim->coords.y;
2545                                                                                 gLoc[2]=victim->coords.z;
2546                                                                                 vel[0]=velocity.x;
2547                                                                                 vel[1]=velocity.y;
2548                                                                                 vel[2]=velocity.z;
2549                                                                                 /*PlaySoundEx( landsound2, samp[landsound2], NULL, true);
2550                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
2551                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
2552                                                                                 OPENAL_SetPaused(channels[landsound2], false);
2553                                                                                 */
2554                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
2555                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
2556                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 128);
2557                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
2558
2559                                                                                 victim->skeleton.longdead=0;
2560                                                                                 victim->skeleton.free=1;
2561                                                                                 victim->skeleton.broken=0;
2562                                                                                 victim->skeleton.spinny=1;
2563
2564                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2565                                                                                         victim->skeleton.joints[i].velchange=0;
2566                                                                                         victim->skeleton.joints[i].delay=0;
2567                                                                                         victim->skeleton.joints[i].locked=0;
2568                                                                                         //victim->skeleton.joints[i].velocity=0;
2569                                                                                 }
2570
2571                                                                                 XYZ relative;
2572                                                                                 relative=0;
2573                                                                                 relative.y=1;
2574                                                                                 Normalise(&relative);
2575                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2576                                                                                         victim->skeleton.joints[i].velocity.y=relative.y*10;
2577                                                                                         victim->skeleton.joints[i].position.y+=relative.y*.3;
2578                                                                                         victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2579                                                                                         victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2580                                                                                 }
2581                                                                                 victim->Puff(abdomen);
2582                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2583                                                                         }
2584                                                                 }
2585
2586                                                                 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2587                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2588                                                                                 escapednum=0;
2589                                                                                 if(id==0)camerashake+=.4;
2590                                                                                 float gLoc[3];
2591                                                                                 float vel[3];
2592                                                                                 gLoc[0]=coords.x;
2593                                                                                 gLoc[1]=coords.y;
2594                                                                                 gLoc[2]=coords.z;
2595                                                                                 vel[0]=velocity.x;
2596                                                                                 vel[1]=velocity.y;
2597                                                                                 vel[2]=velocity.z;
2598                                                                                 if(tutoriallevel!=1){
2599                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2600                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2601                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
2602                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2603                                                                                 }
2604                                                                                 XYZ relative;
2605                                                                                 relative=victim->coords-coords;
2606                                                                                 relative.y=0;
2607                                                                                 Normalise(&relative);
2608                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2609                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2610                                                                                 }
2611                                                                                 victim->Puff(abdomen);
2612                                                                                 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2613                                                                                         slomo=1;
2614                                                                                         slomodelay=.2;
2615                                                                                 }
2616                                                                                 victim->DoDamage(damagemult*500/victim->protectionhigh);
2617                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2618                                                                         }
2619                                                                 }
2620
2621                                                                 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2622                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2623                                                                                 escapednum=0;
2624                                                                                 if(id==0)camerashake+=.4;
2625                                                                                 float gLoc[3];
2626                                                                                 float vel[3];
2627                                                                                 gLoc[0]=coords.x;
2628                                                                                 gLoc[1]=coords.y;
2629                                                                                 gLoc[2]=coords.z;
2630                                                                                 vel[0]=velocity.x;
2631                                                                                 vel[1]=velocity.y;
2632                                                                                 vel[2]=velocity.z;
2633                                                                                 if(tutoriallevel!=1){
2634                                                                                         PlaySoundEx( thudsound, samp[thudsound], NULL, true);
2635                                                                                         OPENAL_3D_SetAttributes(channels[thudsound], gLoc, vel);
2636                                                                                         OPENAL_SetVolume(channels[thudsound], 400);
2637                                                                                         OPENAL_SetPaused(channels[thudsound], false);
2638                                                                                 }
2639
2640                                                                                 victim->skeleton.longdead=0;
2641                                                                                 victim->skeleton.free=1;
2642                                                                                 victim->skeleton.broken=0;
2643                                                                                 victim->skeleton.spinny=1;
2644
2645                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2646                                                                                         victim->skeleton.joints[i].velchange=0;
2647                                                                                         //victim->skeleton.joints[i].delay=0;
2648                                                                                         victim->skeleton.joints[i].locked=0;
2649                                                                                 }
2650                                                                                 XYZ relative;
2651                                                                                 relative=victim->coords-coords;
2652                                                                                 Normalise(&relative);
2653                                                                                 relative.y+=.3;
2654                                                                                 Normalise(&relative);
2655                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2656                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2657                                                                                 }
2658                                                                                 if(id==0&&!victim->dead){
2659                                                                                         SolidHitBonus();
2660                                                                                 }
2661
2662                                                                                 victim->Puff(abdomen);
2663                                                                                 victim->DoDamage(damagemult*20/victim->protectionhigh);
2664                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2665                                                                                 staggerdelay=.5;
2666                                                                                 if(!victim->dead)staggerdelay=1.2;
2667
2668
2669                                                                         }
2670                                                                 }
2671
2672                                                                 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2673                                                                         // if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9){
2674                                                                         //if(id==0)camerashake+=.4;
2675                                                                         float gLoc[3];
2676                                                                         float vel[3];
2677                                                                         gLoc[0]=coords.x;
2678                                                                         gLoc[1]=coords.y;
2679                                                                         gLoc[2]=coords.z;
2680                                                                         vel[0]=velocity.x;
2681                                                                         vel[1]=velocity.y;
2682                                                                         vel[2]=velocity.z;
2683
2684                                                                         if(hasvictim)
2685                                                                                 if(!victim->skeleton.free)hasvictim=0;
2686
2687                                                                         if(!hasvictim){
2688                                                                                 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2689                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2690                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2691                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
2692                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
2693                                                                         }
2694
2695                                                                         if(victim&&hasvictim){
2696                                                                                 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2697
2698                                                                                         XYZ where,startpoint,endpoint,movepoint,colpoint;
2699                                                                                         float rotationpoint;
2700                                                                                         int whichtri;
2701                                                                                         if(weapons.type[weaponids[weaponactive]]==knife){
2702                                                                                                 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2703                                                                                                 where-=victim->coords;
2704                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2705                                                                                                 //where=scale;
2706                                                                                                 startpoint=where;
2707                                                                                                 startpoint.y+=100;
2708                                                                                                 endpoint=where;
2709                                                                                                 endpoint.y-=100;
2710                                                                                         }
2711                                                                                         if(weapons.type[weaponids[weaponactive]]==sword){
2712                                                                                                 where=weapons.position[weaponids[weaponactive]];
2713                                                                                                 where-=victim->coords;
2714                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2715                                                                                                 startpoint=where;
2716                                                                                                 where=weapons.tippoint[weaponids[weaponactive]];
2717                                                                                                 where-=victim->coords;
2718                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2719                                                                                                 endpoint=where;
2720                                                                                         }
2721                                                                                         if(weapons.type[weaponids[weaponactive]]==staff){
2722                                                                                                 where=weapons.position[weaponids[weaponactive]];
2723                                                                                                 where-=victim->coords;
2724                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2725                                                                                                 startpoint=where;
2726                                                                                                 where=weapons.tippoint[weaponids[weaponactive]];
2727                                                                                                 where-=victim->coords;
2728                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2729                                                                                                 endpoint=where;
2730                                                                                         }
2731                                                                                         movepoint=0;
2732                                                                                         rotationpoint=0;
2733                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2734
2735                                                                                         if(whichtri!=-1){
2736                                                                                                 if(victim->dead!=2){
2737                                                                                                         victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2738                                                                                                         if(id==0&&!victim->dead){
2739                                                                                                                 bonus=FinishedBonus;
2740                                                                                                                 bonustime=0;
2741                                                                                                                 bonusvalue=200;
2742                                                                                                         }
2743                                                                                                 }
2744                                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2745
2746                                                                                                 victim->skeleton.longdead=0;
2747                                                                                                 victim->skeleton.free=1;
2748                                                                                                 victim->skeleton.broken=0;
2749
2750                                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2751                                                                                                         victim->skeleton.joints[i].velchange=0;
2752                                                                                                         victim->skeleton.joints[i].locked=0;
2753                                                                                                         //victim->skeleton.joints[i].velocity=0;
2754                                                                                                 }
2755                                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
2756                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
2757                                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 128);
2758                                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
2759
2760                                                                                         }
2761                                                                                         if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2762                                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
2763                                                                                                 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2764                                                                                         }
2765                                                                                         if(whichtri==-1){
2766                                                                                                 hasvictim=0;
2767                                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2768                                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2769                                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
2770                                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
2771                                                                                         }
2772                                                                                 }
2773                                                                         }
2774                                                                 }
2775
2776                                                                 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2777                                                                         // if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9){
2778                                                                         //if(id==0)camerashake+=.4;
2779                                                                         float gLoc[3];
2780                                                                         float vel[3];
2781                                                                         gLoc[0]=coords.x;
2782                                                                         gLoc[1]=coords.y;
2783                                                                         gLoc[2]=coords.z;
2784                                                                         vel[0]=velocity.x;
2785                                                                         vel[1]=velocity.y;
2786                                                                         vel[2]=velocity.z;
2787                                                                         if(!hasvictim){
2788                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2789                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2790                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
2791                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
2792                                                                         }
2793
2794                                                                         if(victim&&hasvictim){
2795                                                                                 XYZ footvel,footpoint;
2796
2797                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
2798                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
2799                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
2800                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
2801
2802                                                                                 footvel=0;
2803                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2804
2805                                                                                 if(weapons.type[weaponids[weaponactive]]==sword){
2806                                                                                         XYZ where,startpoint,endpoint,movepoint;
2807                                                                                         float rotationpoint;
2808                                                                                         int whichtri;
2809
2810                                                                                         where=weapons.position[weaponids[weaponactive]];
2811                                                                                         where-=victim->coords;
2812                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2813                                                                                         startpoint=where;
2814                                                                                         where=weapons.tippoint[weaponids[weaponactive]];
2815                                                                                         where-=victim->coords;
2816                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2817                                                                                         endpoint=where;
2818
2819                                                                                         movepoint=0;
2820                                                                                         rotationpoint=0;
2821                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2822                                                                                         footpoint+=victim->coords;
2823
2824                                                                                         if(whichtri==-1){
2825                                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2826                                                                                         }
2827                                                                                 }
2828                                                                                 if(weapons.type[weaponids[weaponactive]]==staff){
2829                                                                                         XYZ where,startpoint,endpoint,movepoint;
2830                                                                                         float rotationpoint;
2831                                                                                         int whichtri;
2832
2833                                                                                         where=weapons.position[weaponids[weaponactive]];
2834                                                                                         where-=victim->coords;
2835                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2836                                                                                         startpoint=where;
2837                                                                                         where=weapons.tippoint[weaponids[weaponactive]];
2838                                                                                         where-=victim->coords;
2839                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2840                                                                                         endpoint=where;
2841
2842                                                                                         movepoint=0;
2843                                                                                         rotationpoint=0;
2844                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2845                                                                                         footpoint+=victim->coords;
2846
2847                                                                                         if(whichtri==-1){
2848                                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2849                                                                                         }
2850                                                                                 }
2851                                                                                 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2852                                                                                 if(hasvictim){
2853                                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2854                                                                                                 victim->skeleton.longdead=0;
2855                                                                                                 victim->skeleton.free=1;
2856                                                                                                 victim->skeleton.broken=0;
2857
2858                                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2859                                                                                                         victim->skeleton.joints[i].velchange=0;
2860                                                                                                         victim->skeleton.joints[i].locked=0;
2861                                                                                                         //victim->skeleton.joints[i].velocity=0;
2862                                                                                                 }
2863
2864                                                                                                 XYZ relative;
2865                                                                                                 relative=0;
2866                                                                                                 relative.y=10;
2867                                                                                                 Normalise(&relative);
2868                                                                                                 //victim->Puff(abdomen);
2869                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2870
2871                                                                                                 if(victim->bloodloss<victim->damagetolerance){
2872                                                                                                         victim->bloodloss+=1000;
2873                                                                                                         victim->bled=0;
2874                                                                                                 }
2875
2876                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2877                                                                                         }
2878                                                                                 }
2879                                                                         }
2880                                                                         if(!hasvictim&&onterrain){
2881                                                                                 weapons.bloody[weaponids[weaponactive]]=0;
2882                                                                                 weapons.blooddrip[weaponids[weaponactive]]=0;
2883                                                                         }
2884                                                                 }
2885
2886                                                                 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2887                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2888                                                                                 escapednum=0;
2889                                                                                 if(id==0)camerashake+=.4;
2890                                                                                 if(Random()%2){
2891                                                                                         victim->spurt=1;
2892                                                                                         DoBlood(.2,235);
2893                                                                                 }
2894                                                                                 float gLoc[3];
2895                                                                                 float vel[3];
2896                                                                                 gLoc[0]=victim->coords.x;
2897                                                                                 gLoc[1]=victim->coords.y;
2898                                                                                 gLoc[2]=victim->coords.z;
2899                                                                                 vel[0]=velocity.x;
2900                                                                                 vel[1]=velocity.y;
2901                                                                                 vel[2]=velocity.z;
2902                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60){
2903                                                                                 if(1==1){
2904                                                                                         if(tutoriallevel!=1){
2905                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2906                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2907                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
2908                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
2909                                                                                         }
2910                                                                                 }
2911                                                                                 else {
2912                                                                                         if(tutoriallevel!=1){
2913                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
2914                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
2915                                                                                                 OPENAL_SetVolume(channels[landsound2], 256);
2916                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
2917                                                                                         }
2918                                                                                 }
2919
2920                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60)
2921                                                                                 victim->RagDoll(0);
2922                                                                                 XYZ relative;
2923                                                                                 relative=victim->coords-coords;
2924                                                                                 relative.y=0;
2925                                                                                 Normalise(&relative);
2926                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2927                                                                                         victim->skeleton.joints[i].velocity=relative*30;
2928                                                                                 }
2929                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2930
2931                                                                                 victim->targetframe=0;
2932                                                                                 victim->targetanimation=staggerbackhardanim;
2933                                                                                 victim->targetrotation=targetrotation+180;
2934                                                                                 victim->target=0;
2935                                                                                 victim->stunned=1;
2936
2937                                                                                 victim->Puff(head);
2938                                                                                 victim->Puff(abdomen);
2939                                                                                 victim->DoDamage(damagemult*60/victim->protectionhigh);
2940
2941                                                                                 if(id==0){
2942                                                                                         SolidHitBonus();
2943                                                                                 }
2944                                                                         }
2945                                                                 }
2946
2947
2948                                                                 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2949                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2950                                                                                 escapednum=0;
2951                                                                                 if(id==0)camerashake+=.4;
2952                                                                                 float gLoc[3];
2953                                                                                 float vel[3];
2954                                                                                 gLoc[0]=victim->coords.x;
2955                                                                                 gLoc[1]=victim->coords.y;
2956                                                                                 gLoc[2]=victim->coords.z;
2957                                                                                 vel[0]=velocity.x;
2958                                                                                 vel[1]=velocity.y;
2959                                                                                 vel[2]=velocity.z;
2960                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60){
2961                                                                                 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2962                                                                                         if(tutoriallevel!=1){
2963                                                                                                 PlaySoundEx( thudsound, samp[thudsound], NULL, true);
2964                                                                                                 OPENAL_3D_SetAttributes(channels[thudsound], gLoc, vel);
2965                                                                                                 OPENAL_SetVolume(channels[thudsound], 512);
2966                                                                                                 OPENAL_SetPaused(channels[thudsound], false);
2967                                                                                         }
2968                                                                                 }
2969                                                                                 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2970                                                                                         if(tutoriallevel!=1){
2971                                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2972                                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2973                                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2974                                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2975                                                                                         }
2976                                                                                 }
2977                                                                                 else {
2978                                                                                         if(tutoriallevel!=1){
2979                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2980                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2981                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 256);
2982                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
2983                                                                                         }
2984                                                                                 }
2985
2986                                                                                 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2987                                                                                         victim->RagDoll(0);
2988                                                                                 XYZ relative;
2989                                                                                 relative=victim->coords-coords;
2990                                                                                 relative.y=0;
2991                                                                                 Normalise(&relative);
2992                                                                                 relative.y=.3;
2993                                                                                 Normalise(&relative);
2994                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2995                                                                                         victim->skeleton.joints[i].velocity=relative*5;
2996                                                                                 }
2997                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2998
2999                                                                                 victim->targetframe=0;
3000                                                                                 victim->targetanimation=staggerbackhardanim;
3001                                                                                 victim->targetrotation=targetrotation+180;
3002                                                                                 victim->target=0;
3003                                                                                 victim->stunned=1;
3004
3005                                                                                 victim->Puff(abdomen);
3006                                                                                 victim->DoDamage(damagemult*60/victim->protectionhigh);
3007
3008                                                                                 if(id==0){
3009                                                                                         SolidHitBonus();
3010                                                                                 }
3011                                                                         }
3012                                                                 }
3013
3014                                                                 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
3015                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
3016                                                                                 if(victim->id==0)camerashake+=.4;
3017                                                                                 float gLoc[3];
3018                                                                                 float vel[3];
3019                                                                                 gLoc[0]=victim->coords.x;
3020                                                                                 gLoc[1]=victim->coords.y;
3021                                                                                 gLoc[2]=victim->coords.z;
3022                                                                                 vel[0]=velocity.x;
3023                                                                                 vel[1]=velocity.y;
3024                                                                                 vel[2]=velocity.z;
3025
3026                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3027                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3028                                                                                 OPENAL_SetVolume(channels[landsound2], 256);
3029                                                                                 OPENAL_SetPaused(channels[landsound2], false);
3030
3031                                                                                 Puff(righthand);
3032                                                                         }
3033                                                                 }
3034
3035                                                                 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
3036                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
3037                                                                                 if(victim->id==0)camerashake+=.4;
3038                                                                                 float gLoc[3];
3039                                                                                 float vel[3];
3040                                                                                 gLoc[0]=victim->coords.x;
3041                                                                                 gLoc[1]=victim->coords.y;
3042                                                                                 gLoc[2]=victim->coords.z;
3043                                                                                 vel[0]=velocity.x;
3044                                                                                 vel[1]=velocity.y;
3045                                                                                 vel[2]=velocity.z;
3046
3047                                                                                 if(weaponactive!=-1){
3048                                                                                         if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
3049                                                                                                 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3050                                                                                                 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3051
3052                                                                                                 PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
3053                                                                                                 OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
3054                                                                                                 OPENAL_SetVolume(channels[swordstaffsound], 512);
3055                                                                                                 OPENAL_SetPaused(channels[swordstaffsound], false);
3056                                                                                         }
3057                                                                                         else{
3058                                                                                                 PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3059                                                                                                 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3060                                                                                                 OPENAL_SetVolume(channels[metalhitsound], 512);
3061                                                                                                 OPENAL_SetPaused(channels[metalhitsound], false);
3062                                                                                         }
3063                                                                                 }
3064
3065                                                                                 //Puff(righthand);
3066                                                                         }
3067                                                                 }
3068
3069                                                                 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
3070                                                                         if(weaponactive!=-1){
3071                                                                                 escapednum=0;
3072                                                                                 XYZ aim;
3073                                                                                 weapons.owner[weaponids[0]]=-1;
3074                                                                                 aim=victim->coords+DoRotation(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position,0,victim->rotation,0)*victim->scale+victim->velocity*findDistance(&victim->coords,&coords)/50-(coords+DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,rotation,0)*scale);
3075                                                                                 Normalise(&aim);
3076                                                                                 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
3077                                                                                 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
3078                                                                                 }*/
3079                                                                                 weapons.velocity[weaponids[0]]=aim*50;
3080                                                                                 weapons.tipvelocity[weaponids[0]]=aim*50;
3081                                                                                 weapons.missed[weaponids[0]]=0;
3082                                                                                 weapons.hitsomething[weaponids[0]]=0;
3083                                                                                 weapons.freetime[weaponids[0]]=0;
3084                                                                                 weapons.firstfree[weaponids[0]]=1;
3085                                                                                 weapons.physics[weaponids[0]]=0;
3086                                                                                 num_weapons--;
3087                                                                                 if(num_weapons){
3088                                                                                         weaponids[0]=weaponids[num_weapons];
3089                                                                                 }
3090                                                                                 weaponactive=-1;
3091                                                                         }
3092                                                                 }
3093
3094                                                                 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
3095                                                                         if(hasvictim)
3096                                                                                 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
3097                                                                                         escapednum=0;
3098                                                                                         //if(Random()%2){
3099                                                                                         if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
3100                                                                                         //}
3101
3102                                                                                         if(id==0){
3103                                                                                                 bonus=Slicebonus;
3104                                                                                                 bonustime=0;
3105                                                                                                 bonusvalue=10;
3106                                                                                         }
3107                                                                                         if(tutoriallevel!=1){
3108                                                                                                 float gLoc[3];
3109                                                                                                 float vel[3];
3110                                                                                                 gLoc[0]=victim->coords.x;
3111                                                                                                 gLoc[1]=victim->coords.y;
3112                                                                                                 gLoc[2]=victim->coords.z;
3113                                                                                                 vel[0]=velocity.x;
3114                                                                                                 vel[1]=velocity.y;
3115                                                                                                 vel[2]=velocity.z;
3116                                                                                                 PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3117                                                                                                 OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3118                                                                                                 OPENAL_SetVolume(channels[knifeslicesound], 512);
3119                                                                                                 OPENAL_SetPaused(channels[knifeslicesound], false);
3120                                                                                         }
3121                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3122                                                                                         if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
3123                                                                                                 if(victim->id != 0 || difficulty==2){
3124                                                                                                         victim->targetframe=0;
3125                                                                                                         victim->targetanimation=staggerbackhardanim;
3126                                                                                                         victim->targetrotation=targetrotation+180;
3127                                                                                                         victim->target=0;
3128                                                                                                 }
3129                                                                                         }
3130                                                                                         victim->lowreversaldelay=0;
3131                                                                                         victim->highreversaldelay=0;
3132                                                                                         if(aitype!=playercontrolled)weaponmissdelay=.6;
3133
3134                                                                                         if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3135                                                                                         if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
3136
3137                                                                                         XYZ footvel,footpoint;
3138                                                                                         footvel=0;
3139                                                                                         if(skeleton.free){
3140                                                                                                 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
3141                                                                                         }
3142                                                                                         if(!skeleton.free){
3143                                                                                                 footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->rotation,0)*victim->scale+victim->coords;
3144                                                                                         }
3145                                                                                         if(tutoriallevel!=1){
3146                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
3147                                                                                                 footvel=DoRotation(facing,0,90,0)*.8;
3148                                                                                                 //footvel.y-=.3;
3149                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3150                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3151                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3152                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3153                                                                                         }
3154                                                                                         if(tutoriallevel==1){
3155                                                                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
3156                                                                                         }
3157                                                                                         victim->DoDamage(damagemult*0);
3158                                                                                 }
3159                                                                 }
3160                                                                 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3161                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
3162                                                                                 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
3163                                                                                         if(id==0){
3164                                                                                                 bonus=Slashbonus;
3165                                                                                                 bonustime=0;
3166                                                                                                 bonusvalue=40;
3167                                                                                         }
3168                                                                                         escapednum=0;
3169                                                                                         if(tutoriallevel!=1){
3170                                                                                                 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
3171                                                                                                 else victim->DoBloodBig(2/victim->armorhigh,185);
3172                                                                                                 victim->deathbleeding=1;
3173                                                                                                 float gLoc[3];
3174                                                                                                 float vel[3];
3175                                                                                                 gLoc[0]=victim->coords.x;
3176                                                                                                 gLoc[1]=victim->coords.y;
3177                                                                                                 gLoc[2]=victim->coords.z;
3178                                                                                                 vel[0]=velocity.x;
3179                                                                                                 vel[1]=velocity.y;
3180                                                                                                 vel[2]=velocity.z;
3181                                                                                                 PlaySoundEx( swordslicesound, samp[swordslicesound], NULL, true);
3182                                                                                                 OPENAL_3D_SetAttributes(channels[swordslicesound], gLoc, vel);
3183                                                                                                 OPENAL_SetVolume(channels[swordslicesound], 512);
3184                                                                                                 OPENAL_SetPaused(channels[swordslicesound], false);
3185                                                                                         }
3186                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3187                                                                                         //if(animation[victim->targetanimation].attack){
3188                                                                                         //if(victim->creature==rabbittype){
3189                                                                                         if(tutoriallevel!=1){
3190                                                                                                 victim->targetframe=0;
3191                                                                                                 victim->targetanimation=staggerbackhardanim;
3192                                                                                                 victim->targetrotation=targetrotation+180;
3193                                                                                                 victim->target=0;
3194                                                                                         }
3195                                                                                         //}
3196                                                                                         //}
3197
3198                                                                                         if(tutoriallevel!=1){
3199                                                                                                 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3200                                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=3;
3201
3202                                                                                                 float bloodlossamount;
3203                                                                                                 bloodlossamount=200+abs((float)(Random()%40))-20;
3204                                                                                                 victim->bloodloss+=bloodlossamount/victim->armorhigh;
3205                                                                                                 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
3206                                                                                                 victim->DoDamage(damagemult*0);
3207
3208                                                                                                 XYZ footvel,footpoint;
3209                                                                                                 footvel=0;
3210                                                                                                 if(skeleton.free){
3211                                                                                                         footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
3212                                                                                                 }
3213                                                                                                 if(!skeleton.free){
3214                                                                                                         footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->rotation,0)*victim->scale+victim->coords;
3215                                                                                                 }
3216                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3217                                                                                                 footvel=DoRotation(facing,0,90,0)*.8;
3218                                                                                                 footvel.y-=.3;
3219                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3220                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3221                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3222                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3223                                                                                         }
3224                                                                                 }
3225                                                                                 else {
3226
3227
3228                                                                                         float gLoc[3];
3229                                                                                         float vel[3];
3230                                                                                         gLoc[0]=victim->coords.x;
3231                                                                                         gLoc[1]=victim->coords.y;
3232                                                                                         gLoc[2]=victim->coords.z;
3233                                                                                         vel[0]=velocity.x;
3234                                                                                         vel[1]=velocity.y;
3235                                                                                         vel[2]=velocity.z;
3236                                                                                         if(victim->weaponactive!=-1){
3237                                                                                                 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
3238                                                                                                         if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3239                                                                                                         if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3240
3241                                                                                                         PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
3242                                                                                                         OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
3243                                                                                                         OPENAL_SetVolume(channels[swordstaffsound], 512);
3244                                                                                                         OPENAL_SetPaused(channels[swordstaffsound], false);
3245                                                                                                 }
3246                                                                                                 else{
3247                                                                                                         PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3248                                                                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3249                                                                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
3250                                                                                                         OPENAL_SetPaused(channels[metalhitsound], false);
3251                                                                                                 }
3252                                                                                         }
3253
3254
3255                                                                                         XYZ aim;
3256                                                                                         victim->Puff(righthand);
3257                                                                                         victim->target=0;
3258                                                                                         victim->targetframe=0;
3259                                                                                         victim->targetanimation=staggerbackhighanim;
3260                                                                                         victim->targetrotation=targetrotation+180;
3261                                                                                         victim->target=0;
3262                                                                                         weapons.owner[victim->weaponids[0]]=-1;
3263                                                                                         aim=DoRotation(facing,0,90,0)*21;
3264                                                                                         aim.y+=7;
3265                                                                                         weapons.velocity[victim->weaponids[0]]=aim*-.2;
3266                                                                                         weapons.tipvelocity[victim->weaponids[0]]=aim;
3267                                                                                         weapons.missed[victim->weaponids[0]]=1;
3268                                                                                         weapons.hitsomething[weaponids[0]]=0;
3269                                                                                         weapons.freetime[victim->weaponids[0]]=0;
3270                                                                                         weapons.firstfree[victim->weaponids[0]]=1;
3271                                                                                         weapons.physics[victim->weaponids[0]]=1;
3272                                                                                         victim->num_weapons--;
3273                                                                                         if(victim->num_weapons){
3274                                                                                                 victim->weaponids[0]=victim->weaponids[num_weapons];
3275                                                                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3276                                                                                         }
3277                                                                                         victim->weaponactive=-1;
3278                                                                                         for(i=0;i<numplayers;i++){
3279                                                                                                 player[i].wentforweapon=0;
3280                                                                                         }
3281
3282                                                                                         /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3283                                                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3284                                                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
3285                                                                                         OPENAL_SetPaused(channels[metalhitsound], false);*/
3286
3287                                                                                 }
3288                                                                         }
3289                                                                 }
3290
3291                                                                 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3292                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
3293                                                                                 if(tutoriallevel!=1){
3294                                                                                         weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
3295                                                                                         escapednum=0;
3296                                                                                         if(id==0)camerashake+=.4;
3297                                                                                         if(Random()%2||creature==wolftype){
3298                                                                                                 victim->spurt=1;
3299                                                                                         }
3300                                                                                         float gLoc[3];
3301                                                                                         float vel[3];
3302                                                                                         gLoc[0]=victim->coords.x;
3303                                                                                         gLoc[1]=victim->coords.y;
3304                                                                                         gLoc[2]=victim->coords.z;
3305                                                                                         vel[0]=velocity.x;
3306                                                                                         vel[1]=velocity.y;
3307                                                                                         vel[2]=velocity.z;
3308                                                                                         PlaySoundEx( staffheadsound, samp[staffheadsound], NULL, true);
3309                                                                                         OPENAL_3D_SetAttributes(channels[staffheadsound], gLoc, vel);
3310                                                                                         OPENAL_SetVolume(channels[staffheadsound], 256);
3311                                                                                         OPENAL_SetPaused(channels[staffheadsound], false);
3312                                                                                 }
3313                                                                                 victim->RagDoll(0);
3314                                                                                 XYZ relative;
3315                                                                                 relative=victim->coords-coords;
3316                                                                                 relative.y=0;
3317                                                                                 Normalise(&relative);
3318                                                                                 relative=DoRotation(relative,0,90,0);
3319                                                                                 relative.y-=1;
3320                                                                                 Normalise(&relative);
3321                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3322                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*60;
3323                                                                                 }
3324                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
3325                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
3326                                                                                 //FootLand(1,2);
3327                                                                                 victim->Puff(head);
3328                                                                                 if(tutoriallevel!=1){
3329                                                                                         victim->DoDamage(damagemult*120/victim->protectionhigh);
3330
3331                                                                                         if(id==0){
3332                                                                                                 bonus=solidhit;
3333                                                                                                 bonustime=0;
3334                                                                                                 bonusvalue=30;
3335                                                                                         }
3336                                                                                 }
3337                                                                         }
3338                                                                 }
3339
3340                                                                 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3341                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
3342                                                                                 if(tutoriallevel!=1){
3343                                                                                         weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
3344                                                                                         escapednum=0;
3345                                                                                         if(id==0)camerashake+=.4;
3346                                                                                         if(Random()%2||creature==wolftype){
3347                                                                                                 victim->spurt=1;
3348                                                                                         }
3349                                                                                         float gLoc[3];
3350                                                                                         float vel[3];
3351                                                                                         gLoc[0]=victim->coords.x;
3352                                                                                         gLoc[1]=victim->coords.y;
3353                                                                                         gLoc[2]=victim->coords.z;
3354                                                                                         vel[0]=velocity.x;
3355                                                                                         vel[1]=velocity.y;
3356                                                                                         vel[2]=velocity.z;
3357                                                                                         PlaySoundEx( staffheadsound, samp[staffheadsound], NULL, true);
3358                                                                                         OPENAL_3D_SetAttributes(channels[staffheadsound], gLoc, vel);
3359                                                                                         OPENAL_SetVolume(channels[staffheadsound], 256);
3360                                                                                         OPENAL_SetPaused(channels[staffheadsound], false);
3361                                                                                 }
3362                                                                                 victim->RagDoll(0);
3363                                                                                 XYZ relative;
3364                                                                                 relative=victim->coords-coords;
3365                                                                                 relative.y=0;
3366                                                                                 Normalise(&relative);
3367                                                                                 relative=DoRotation(relative,0,-90,0);
3368                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3369                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3370                                                                                 }
3371                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
3372                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
3373                                                                                 //FootLand(1,2);
3374                                                                                 victim->Puff(head);
3375                                                                                 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
3376
3377                                                                                 if(id==0){
3378                                                                                         bonus=solidhit;
3379                                                                                         bonustime=0;
3380                                                                                         bonusvalue=60;
3381                                                                                 }
3382                                                                                 }
3383                                                                         }
3384                                                                 }
3385
3386                                                                 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
3387                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
3388                                                                                 escapednum=0;
3389                                                                                 if(tutoriallevel!=1){
3390                                                                                         if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
3391                                                                                         if(id==0)camerashake+=.4;
3392                                                                                         if(Random()%2||creature==wolftype){
3393                                                                                                 victim->spurt=1;
3394                                                                                         }
3395                                                                                         float gLoc[3];
3396                                                                                         float vel[3];
3397                                                                                         gLoc[0]=victim->coords.x;
3398                                                                                         gLoc[1]=victim->coords.y;
3399                                                                                         gLoc[2]=victim->coords.z;
3400                                                                                         vel[0]=velocity.x;
3401                                                                                         vel[1]=velocity.y;
3402                                                                                         vel[2]=velocity.z;
3403                                                                                         PlaySoundEx( staffbodysound, samp[staffbodysound], NULL, true);
3404                                                                                         OPENAL_3D_SetAttributes(channels[staffbodysound], gLoc, vel);
3405                                                                                         OPENAL_SetVolume(channels[staffbodysound], 256);
3406                                                                                         OPENAL_SetPaused(channels[staffbodysound], false);
3407                                                                                 }
3408                                                                                 victim->skeleton.longdead=0;
3409                                                                                 victim->skeleton.free=1;
3410                                                                                 victim->skeleton.broken=0;
3411
3412                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3413                                                                                         victim->skeleton.joints[i].velchange=0;
3414                                                                                         victim->skeleton.joints[i].locked=0;
3415                                                                                         //victim->skeleton.joints[i].velocity=0;
3416                                                                                 }
3417
3418                                                                                 victim->RagDoll(0);
3419                                                                                 XYZ relative;
3420                                                                                 relative=0;
3421                                                                                 /*relative=victim->coords-coords;
3422                                                                                 relative.y=0;
3423                                                                                 Normalise(&relative);
3424                                                                                 relative=DoRotation(relative,0,90,0);*/
3425                                                                                 relative.y=-1;
3426                                                                                 Normalise(&relative);
3427                                                                                 if(!victim->dead){
3428                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3429                                                                                                 victim->skeleton.joints[i].velocity=relative*damagemult*40;
3430                                                                                         }
3431                                                                                         //FootLand(1,2);
3432                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
3433                                                                                 }
3434                                                                                 if(victim->dead){
3435                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3436                                                                                                 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
3437                                                                                         }
3438                                                                                         //FootLand(1,2);
3439                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
3440                                                                                 }
3441                                                                                 victim->Puff(abdomen);
3442                                                                                 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
3443
3444                                                                                 if(!victim->dead){
3445                                                                                         if(id==0){
3446                                                                                                 bonus=solidhit;
3447                                                                                                 bonustime=0;
3448                                                                                                 bonusvalue=40;
3449                                                                                         }
3450                                                                                 }
3451                                                                                 }
3452                                                                         }
3453                                                                 }
3454
3455                                                                 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
3456                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
3457                                                                                 escapednum=0;
3458                                                                                 if(id==0)camerashake+=.4;
3459                                                                                 float gLoc[3];
3460                                                                                 float vel[3];
3461                                                                                 gLoc[0]=victim->coords.x;
3462                                                                                 gLoc[1]=victim->coords.y;
3463                                                                                 gLoc[2]=victim->coords.z;
3464                                                                                 vel[0]=velocity.x;
3465                                                                                 vel[1]=velocity.y;
3466                                                                                 vel[2]=velocity.z;
3467                                                                                 XYZ relative;
3468                                                                                 relative=victim->coords-coords;
3469                                                                                 relative.y=0;
3470                                                                                 Normalise(&relative);
3471
3472                                                                                 if(id==0){
3473                                                                                         SolidHitBonus();
3474                                                                                 }
3475
3476                                                                                 if(animation[victim->targetanimation].height==lowheight){
3477                                                                                         if(Random()%2){
3478                                                                                                 victim->spurt=1;
3479                                                                                                 DoBlood(.2,250);
3480                                                                                         }
3481                                                                                         victim->RagDoll(0);
3482                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3483                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3484                                                                                         }
3485                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3486                                                                                         if(tutoriallevel!=1){
3487                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3488                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3489                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3490                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3491                                                                                         }
3492                                                                                         victim->Puff(head);
3493                                                                                         victim->DoDamage(damagemult*100/victim->protectionhead);
3494                                                                                         if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
3495                                                                                         if(creature==wolftype){
3496                                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3497                                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3498                                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3499                                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3500                                                                                                 victim->spurt=1;
3501                                                                                                 victim->DoBloodBig(2/victim->armorhead,175);
3502                                                                                         }
3503                                                                                 }
3504                                                                                 else{
3505                                                                                         if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
3506                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3507                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
3508                                                                                         }
3509                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3510                                                                                         victim->targetframe=0;
3511                                                                                         victim->targetanimation=staggerbackhighanim;
3512                                                                                         victim->targetrotation=targetrotation+180;
3513                                                                                         victim->target=0;
3514                                                                                         if(tutoriallevel!=1){
3515                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3516                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3517                                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
3518                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
3519                                                                                         }
3520                                                                                         victim->Puff(abdomen);
3521                                                                                         victim->DoDamage(damagemult*30/victim->protectionhigh);
3522                                                                                         if(creature==wolftype){
3523                                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3524                                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3525                                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3526                                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3527                                                                                                 victim->spurt=1;
3528                                                                                                 victim->DoBloodBig(2/victim->armorhigh,170);
3529                                                                                         }
3530                                                                                 }
3531
3532                                                                         }
3533                                                                 }
3534
3535                                                                 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
3536                                                                         if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
3537                                                                                 escapednum=0;
3538                                                                                 if(id==0)camerashake+=.2;
3539                                                                                 float gLoc[3];
3540                                                                                 float vel[3];
3541                                                                                 gLoc[0]=victim->coords.x;
3542                                                                                 gLoc[1]=victim->coords.y;
3543                                                                                 gLoc[2]=victim->coords.z;
3544                                                                                 vel[0]=velocity.x;
3545                                                                                 vel[1]=velocity.y;
3546                                                                                 vel[2]=velocity.z;
3547                                                                                 if(tutoriallevel!=1){
3548                                                                                         PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3549                                                                                         OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3550                                                                                         OPENAL_SetVolume(channels[landsound2], 128);
3551                                                                                         OPENAL_SetPaused(channels[landsound2], false);
3552                                                                                 }
3553                                                                                 XYZ relative;
3554                                                                                 relative=victim->coords-coords;
3555                                                                                 relative.y=0;
3556                                                                                 Normalise(&relative);
3557
3558                                                                                 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
3559                                                                                         victim->RagDoll(0);
3560
3561                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3562                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
3563                                                                                         }
3564                                                                                         relative=DoRotation(relative,0,-90,0);
3565                                                                                         relative.y+=.1;
3566                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3567                                                                                                 if(victim->skeleton.joints[i].label==leftfoot||victim->skeleton.joints[i].label==rightfoot||victim->skeleton.joints[i].label==leftankle||victim->skeleton.joints[i].label==rightankle)
3568                                                                                                         victim->skeleton.joints[i].velocity=relative*80;
3569                                                                                         }
3570                                                                                         victim->Puff(rightankle);
3571                                                                                         victim->Puff(leftankle);
3572                                                                                         victim->DoDamage(damagemult*40/victim->protectionlow);
3573                                                                                 }
3574                                                                                 else{
3575                                                                                         if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
3576                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3577                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
3578                                                                                         }
3579                                                                                         relative=DoRotation(relative,0,-90,0);
3580                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3581                                                                                                 if(victim->skeleton.joints[i].label==leftfoot||victim->skeleton.joints[i].label==rightfoot||victim->skeleton.joints[i].label==leftankle||victim->skeleton.joints[i].label==rightankle)
3582                                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*80;
3583                                                                                         }
3584                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3585                                                                                         victim->targetframe=0;
3586                                                                                         victim->targetanimation=staggerbackhighanim;
3587                                                                                         victim->targetrotation=targetrotation+180;
3588                                                                                         victim->target=0;
3589                                                                                         if(tutoriallevel!=1){
3590                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3591                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3592                                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
3593                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
3594                                                                                         }
3595                                                                                         victim->Puff(abdomen);
3596                                                                                         victim->DoDamage(damagemult*30/victim->protectionlow);
3597                                                                                 }
3598
3599                                                                                 if(id==0){
3600                                                                                         SolidHitBonus();
3601                                                                                 }
3602
3603                                                                         }
3604                                                                 }
3605                                                         }
3606                                                         if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
3607                                                                 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
3608                                                                         escapednum=0;
3609                                                                         if(id==0)camerashake+=.4;
3610                                                                         if(Random()%2){
3611                                                                                 victim->spurt=1;
3612                                                                                 DoBlood(.2,230);
3613                                                                         }
3614                                                                         float gLoc[3];
3615                                                                         float vel[3];
3616                                                                         gLoc[0]=victim->coords.x;
3617                                                                         gLoc[1]=victim->coords.y;
3618                                                                         gLoc[2]=victim->coords.z;
3619                                                                         vel[0]=velocity.x;
3620                                                                         vel[1]=velocity.y;
3621                                                                         vel[2]=velocity.z;
3622                                                                         if(tutoriallevel!=1){
3623                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3624                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3625                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3626                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3627                                                                         }
3628                                                                         if(creature==wolftype){
3629                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3630                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3631                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3632                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3633                                                                                 victim->spurt=1;
3634                                                                                 victim->DoBloodBig(2/victim->armorhigh,170);
3635                                                                         }
3636                                                                         victim->RagDoll(0);
3637                                                                         XYZ relative;
3638                                                                         relative=victim->coords-oldcoords;
3639                                                                         relative.y=0;
3640                                                                         Normalise(&relative);
3641                                                                         //relative=DoRotation(relative,0,-90,0);
3642                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3643                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3644                                                                         }
3645                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3646                                                                         //FootLand(1,2);
3647                                                                         victim->Puff(abdomen);
3648                                                                         victim->DoDamage(damagemult*150/victim->protectionhigh);
3649
3650                                                                         if(id==0){
3651                                                                                 bonus=Reversal;
3652                                                                                 bonustime=0;
3653                                                                                 bonusvalue=60;
3654                                                                         }
3655                                                                 }
3656
3657                                                                 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
3658                                                                         if(victim->weaponactive!=-1&&victim->num_weapons>0){
3659                                                                                 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
3660                                                                                         weapons.owner[victim->weaponids[victim->weaponactive]]=id;
3661                                                                                         weaponactive=0;
3662                                                                                         if(num_weapons>0){
3663                                                                                                 weaponids[num_weapons]=weaponids[victim->weaponactive];
3664                                                                                         }
3665                                                                                         num_weapons++;
3666                                                                                         weaponids[0]=victim->weaponids[victim->weaponactive];
3667                                                                                         victim->num_weapons--;
3668                                                                                         if(victim->num_weapons>0){
3669                                                                                                 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
3670                                                                                                 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3671                                                                                         }
3672                                                                                         victim->weaponactive=-1;
3673                                                                                 }
3674                                                                         }
3675                                                                 }
3676
3677                                                                 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
3678                                                                         escapednum=0;
3679                                                                         if(id==0)camerashake+=.4;
3680                                                                         if(Random()%2){
3681                                                                                 victim->spurt=1;
3682                                                                                 DoBlood(.2,230);
3683                                                                         }
3684                                                                         float gLoc[3];
3685                                                                         float vel[3];
3686                                                                         gLoc[0]=victim->coords.x;
3687                                                                         gLoc[1]=victim->coords.y;
3688                                                                         gLoc[2]=victim->coords.z;
3689                                                                         vel[0]=velocity.x;
3690                                                                         vel[1]=velocity.y;
3691                                                                         vel[2]=velocity.z;
3692                                                                         PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
3693                                                                         OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
3694                                                                         OPENAL_SetVolume(channels[whooshhitsound], 128);
3695                                                                         OPENAL_SetPaused(channels[whooshhitsound], false);
3696                                                                         victim->RagDoll(0);
3697                                                                         XYZ relative;
3698                                                                         relative=victim->coords-oldcoords;
3699                                                                         relative.y=0;
3700                                                                         Normalise(&relative);
3701                                                                         //relative=DoRotation(relative,0,-90,0);
3702                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3703                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3704                                                                         }
3705                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3706                                                                         //FootLand(1,2);
3707                                                                         victim->Puff(head);
3708                                                                         victim->DoDamage(damagemult*70/victim->protectionhigh);
3709                                                                 }
3710
3711                                                                 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
3712                                                                         escapednum=0;
3713                                                                         if(id==0)camerashake+=.4;
3714                                                                         if(Random()%2){
3715                                                                                 victim->spurt=1;
3716                                                                                 DoBlood(.2,230);
3717                                                                         }
3718                                                                         float gLoc[3];
3719                                                                         float vel[3];
3720                                                                         gLoc[0]=victim->coords.x;
3721                                                                         gLoc[1]=victim->coords.y;
3722                                                                         gLoc[2]=victim->coords.z;
3723                                                                         vel[0]=velocity.x;
3724                                                                         vel[1]=velocity.y;
3725                                                                         vel[2]=velocity.z;
3726
3727                                                                         if(id==0){
3728                                                                                 bonus=staffreversebonus;
3729                                                                                 bonustime=0;
3730                                                                                 bonusvalue=100;
3731                                                                         }
3732
3733                                                                         if(tutoriallevel!=1){
3734                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3735                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3736                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3737                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3738                                                                         }
3739                                                                         victim->RagDoll(0);
3740                                                                         if(id==0){
3741                                                                                 bonus=staffreversebonus;
3742                                                                                 bonustime=0;
3743                                                                                 bonusvalue=100;
3744                                                                         }
3745
3746                                                                         XYZ relative;
3747                                                                         relative=victim->coords-oldcoords;
3748                                                                         relative.y=0;
3749                                                                         Normalise(&relative);
3750                                                                         //relative=DoRotation(relative,0,-90,0);
3751                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3752                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3753                                                                         }
3754                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3755                                                                         //FootLand(1,2);
3756                                                                         victim->Puff(head);
3757                                                                         victim->DoDamage(damagemult*70/victim->protectionhigh);
3758                                                                 }
3759
3760                                                                 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
3761                                                                         escapednum=0;
3762                                                                         victim->RagDoll(1);
3763                                                                         XYZ relative;
3764                                                                         relative=facing;
3765                                                                         relative.y=0;
3766                                                                         Normalise(&relative);
3767                                                                         //relative*=-1;
3768                                                                         relative.y-=.1;
3769                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3770                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3771                                                                         }
3772                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
3773                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
3774                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
3775                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
3776                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
3777                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
3778                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
3779                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
3780
3781                                                                         victim->Puff(abdomen);
3782                                                                         victim->DoDamage(damagemult*90/victim->protectionhigh);
3783
3784                                                                         if(id==0){
3785                                                                                 bonus=Reversal;
3786                                                                                 bonustime=0;
3787                                                                                 bonusvalue=60;
3788                                                                         }
3789
3790                                                                         bool doslice;
3791                                                                         doslice=0;
3792                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
3793                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3794                                                                         if(doslice){
3795                                                                                 float gLoc[3];
3796                                                                                 float vel[3];
3797                                                                                 gLoc[0]=victim->coords.x;
3798                                                                                 gLoc[1]=victim->coords.y;
3799                                                                                 gLoc[2]=victim->coords.z;
3800                                                                                 vel[0]=velocity.x;
3801                                                                                 vel[1]=velocity.y;
3802                                                                                 vel[2]=velocity.z;
3803                                                                                 if(weaponactive!=-1){
3804                                                                                         victim->DoBloodBig(2/victim->armorhigh,225);
3805                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3806                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3807                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
3808                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
3809                                                                                         if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3810                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=3;
3811                                                                                 }
3812                                                                                 if(weaponactive==-1&&creature==wolftype){
3813                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3814                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3815                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
3816                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
3817                                                                                         victim->spurt=1;
3818                                                                                         victim->DoBloodBig(2/victim->armorhigh,175);
3819                                                                                 }
3820                                                                         }
3821                                                                 }
3822
3823
3824
3825                                                                 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3826                                                                         escapednum=0;
3827                                                                         victim->RagDoll(1);
3828                                                                         XYZ relative;
3829                                                                         relative=facing;
3830                                                                         relative.y=0;
3831                                                                         Normalise(&relative);
3832                                                                         //relative*=-1;
3833                                                                         relative.y-=.1;
3834                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3835                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3836                                                                         }
3837                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3838                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3839                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3840                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3841                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3842                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3843                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3844                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3845
3846                                                                         if(id==0){
3847                                                                                 bonus=swordreversebonus;
3848                                                                                 bonustime=0;
3849                                                                                 bonusvalue=100;
3850                                                                         }
3851                                                                         //victim->DoDamage(90);
3852
3853                                                                         /*if(weaponactive!=-1){
3854                                                                         float gLoc[3];
3855                                                                         float vel[3];
3856                                                                         gLoc[0]=victim->coords.x;
3857                                                                         gLoc[1]=victim->coords.y;
3858                                                                         gLoc[2]=victim->coords.z;
3859                                                                         vel[0]=velocity.x;
3860                                                                         vel[1]=velocity.y;
3861                                                                         vel[2]=velocity.z;
3862                                                                         victim->DoBloodBig(2,225);
3863                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3864                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3865                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
3866                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
3867                                                                         if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3868                                                                         weapons.blooddrip[weaponids[weaponactive]]+=3;
3869                                                                         }*/
3870                                                                 }
3871
3872                                                                 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3873                                                                         escapednum=0;
3874                                                                         if(id==0)camerashake+=.4;
3875                                                                         if(Random()%2){
3876                                                                                 victim->spurt=1;
3877                                                                                 DoBlood(.2,230);
3878                                                                         }
3879                                                                         float gLoc[3];
3880                                                                         float vel[3];
3881                                                                         gLoc[0]=victim->coords.x;
3882                                                                         gLoc[1]=victim->coords.y;
3883                                                                         gLoc[2]=victim->coords.z;
3884                                                                         vel[0]=velocity.x;
3885                                                                         vel[1]=velocity.y;
3886                                                                         vel[2]=velocity.z;
3887                                                                         if(tutoriallevel!=1){
3888                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3889                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3890                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3891                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3892                                                                         }
3893                                                                         victim->RagDoll(0);
3894                                                                         XYZ relative;
3895                                                                         relative=victim->coords-oldcoords;
3896                                                                         relative.y=0;
3897                                                                         Normalise(&relative);
3898                                                                         relative=DoRotation(relative,0,-90,0);
3899                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3900                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3901                                                                         }
3902                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3903                                                                         //FootLand(1,2);
3904                                                                         victim->Puff(abdomen);
3905                                                                         victim->DoDamage(damagemult*30/victim->protectionhigh);
3906
3907                                                                         if(id==0){
3908                                                                                 bonus=Reversal;
3909                                                                                 bonustime=0;
3910                                                                                 bonusvalue=60;
3911                                                                         }
3912                                                                 }
3913
3914                                                                 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3915                                                                         escapednum=0;
3916                                                                         victim->RagDoll(0);
3917                                                                         victim->skeleton.spinny=0;
3918                                                                         XYZ relative;
3919                                                                         relative=facing*-1;
3920                                                                         relative.y=-3;
3921                                                                         Normalise(&relative);
3922                                                                         if(victim->id==0)relative/=30;
3923                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3924                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3925                                                                         }
3926                                                                         //victim->DoDamage(1000);
3927                                                                         victim->damage=victim->damagetolerance;
3928                                                                         victim->permanentdamage=victim->damagetolerance-1;
3929                                                                         bool doslice;
3930                                                                         doslice=0;
3931                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
3932                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3933                                                                         if(doslice){
3934                                                                                 float gLoc[3];
3935                                                                                 float vel[3];
3936                                                                                 gLoc[0]=victim->coords.x;
3937                                                                                 gLoc[1]=victim->coords.y;
3938                                                                                 gLoc[2]=victim->coords.z;
3939                                                                                 vel[0]=velocity.x;
3940                                                                                 vel[1]=velocity.y;
3941                                                                                 vel[2]=velocity.z;
3942                                                                                 if(weaponactive!=-1){
3943                                                                                         victim->DoBloodBig(200,225);
3944                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3945                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3946                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
3947                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
3948                                                                                         if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3949                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=5;
3950                                                                                 }
3951
3952                                                                                 if(creature==wolftype&&weaponactive==-1){
3953                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3954                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3955                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
3956                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
3957                                                                                         victim->spurt=1;
3958                                                                                         victim->DoBloodBig(2,175);
3959                                                                                 }
3960                                                                         }
3961                                                                         if(id==0){
3962                                                                                 bonus=spinecrusher;
3963                                                                                 bonustime=0;
3964                                                                                 bonusvalue=100;
3965                                                                         }
3966                                                                 }
3967
3968                                                                 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3969                                                                         if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3970                                                                                 escapednum=0;
3971                                                                                 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3972                                                                                 if(targetanimation==knifesneakattackanim){
3973                                                                                         /*victim->DoBloodBig(200,195);
3974                                                                                         XYZ bloodvel;
3975                                                                                         bloodvel=0;
3976                                                                                         bloodvel.z=20;
3977                                                                                         bloodvel.y=5;
3978                                                                                         bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3979                                                                                         Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3980                                                                                         */
3981                                                                                         XYZ footvel,footpoint;
3982                                                                                         footvel=0;
3983                                                                                         footpoint=weapons.tippoint[weaponids[0]];
3984                                                                                         if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3985                                                                                         footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3986                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3987                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3988                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3989                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3990                                                                                         victim->DoBloodBig(200,195);
3991                                                                                         if(id==0){
3992                                                                                                 bonus=tracheotomy;
3993                                                                                                 bonustime=0;
3994                                                                                                 bonusvalue=100;
3995                                                                                         }
3996
3997                                                                                         //victim->neckspurtamount=5;
3998                                                                                 }
3999                                                                                 if(targetanimation==knifefollowanim){
4000                                                                                         if(id==0){
4001                                                                                                 bonus=Stabbonus;
4002                                                                                                 bonustime=0;
4003                                                                                                 bonusvalue=40;
4004                                                                                         }
4005                                                                                         XYZ footvel,footpoint;
4006                                                                                         footvel=0;
4007                                                                                         footpoint=weapons.tippoint[weaponids[0]];
4008                                                                                         if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
4009                                                                                         footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
4010                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4011                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4012                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
4013                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
4014
4015                                                                                 }
4016                                                                                 victim->bloodloss+=10000;
4017                                                                                 victim->velocity=0;
4018                                                                                 float gLoc[3];
4019                                                                                 float vel[3];
4020                                                                                 gLoc[0]=victim->coords.x;
4021                                                                                 gLoc[1]=victim->coords.y;
4022                                                                                 gLoc[2]=victim->coords.z;
4023                                                                                 vel[0]=velocity.x;
4024                                                                                 vel[1]=velocity.y;
4025                                                                                 vel[2]=velocity.z;
4026                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
4027                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
4028                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 512);
4029                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
4030                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
4031                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
4032                                                                         }
4033                                                                 }
4034
4035                                                                 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
4036                                                                         escapednum=0;
4037                                                                         victim->velocity=0;
4038                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4039                                                                                 victim->skeleton.joints[i].velocity=0;
4040                                                                         }
4041                                                                         if(targetanimation==knifefollowanim){
4042                                                                                 victim->RagDoll(0);
4043                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
4044                                                                                         victim->skeleton.joints[i].velocity=0;
4045                                                                                 }
4046                                                                         }
4047                                                                         if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
4048                                                                                 float gLoc[3];
4049                                                                                 float vel[3];
4050                                                                                 gLoc[0]=victim->coords.x;
4051                                                                                 gLoc[1]=victim->coords.y;
4052                                                                                 gLoc[2]=victim->coords.z;
4053                                                                                 vel[0]=velocity.x;
4054                                                                                 vel[1]=velocity.y;
4055                                                                                 vel[2]=velocity.z;
4056                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
4057                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
4058                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 512);
4059                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
4060                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
4061                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
4062
4063                                                                                 XYZ footvel,footpoint;
4064                                                                                 footvel=0;
4065                                                                                 footpoint=weapons.tippoint[weaponids[0]];
4066                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
4067                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
4068                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4069                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4070                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
4071                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
4072                                                                         }
4073                                                                 }
4074
4075                                                                 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
4076                                                                         if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
4077                                                                                 if(id==0){
4078                                                                                         bonus=backstab;
4079                                                                                         bonustime=0;
4080                                                                                         bonusvalue=100;
4081                                                                                 }
4082
4083                                                                                 escapednum=0;
4084
4085                                                                                 XYZ footvel,footpoint;
4086                                                                                 footvel=0;
4087                                                                                 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
4088                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
4089                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
4090                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4091                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4092                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
4093                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
4094                                                                                 victim->DoBloodBig(200,180);
4095                                                                                 victim->DoBloodBig(200,215);
4096                                                                                 victim->bloodloss+=10000;
4097                                                                                 victim->velocity=0;
4098                                                                                 float gLoc[3];
4099                                                                                 float vel[3];
4100                                                                                 gLoc[0]=victim->coords.x;
4101                                                                                 gLoc[1]=victim->coords.y;
4102                                                                                 gLoc[2]=victim->coords.z;
4103                                                                                 vel[0]=velocity.x;
4104                                                                                 vel[1]=velocity.y;
4105                                                                                 vel[2]=velocity.z;
4106                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
4107                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
4108                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 512);
4109                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
4110                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
4111                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
4112                                                                         }
4113                                                                 }
4114
4115                                                                 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
4116                                                                         escapednum=0;
4117                                                                         victim->velocity=0;
4118                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4119                                                                                 victim->skeleton.joints[i].velocity=0;
4120                                                                         }
4121                                                                         if(weaponactive!=-1){
4122                                                                                 float gLoc[3];
4123                                                                                 float vel[3];
4124                                                                                 gLoc[0]=victim->coords.x;
4125                                                                                 gLoc[1]=victim->coords.y;
4126                                                                                 gLoc[2]=victim->coords.z;
4127                                                                                 vel[0]=velocity.x;
4128                                                                                 vel[1]=velocity.y;
4129                                                                                 vel[2]=velocity.z;
4130                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
4131                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
4132                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 512);
4133                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
4134                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
4135                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
4136
4137                                                                                 XYZ footvel,footpoint;
4138                                                                                 footvel=0;
4139                                                                                 footpoint=weapons.tippoint[weaponids[0]];
4140                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
4141                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
4142                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4143                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4144                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
4145                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
4146                                                                         }
4147                                                                 }
4148
4149                                                                 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
4150                                                                         escapednum=0;
4151                                                                         if(id==0)camerashake+=.4;
4152                                                                         if(Random()%2){
4153                                                                                 victim->spurt=1;
4154                                                                                 DoBlood(.2,240);
4155                                                                         }
4156                                                                         float gLoc[3];
4157                                                                         float vel[3];
4158                                                                         gLoc[0]=victim->coords.x;
4159                                                                         gLoc[1]=victim->coords.y;
4160                                                                         gLoc[2]=victim->coords.z;
4161                                                                         vel[0]=velocity.x;
4162                                                                         vel[1]=velocity.y;
4163                                                                         vel[2]=velocity.z;
4164                                                                         if(weaponactive==-1){
4165                                                                                 if(tutoriallevel!=1){
4166                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
4167                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
4168                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
4169                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
4170                                                                                 }
4171                                                                         }
4172                                                                         bool doslice;
4173                                                                         doslice=0;
4174                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
4175                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
4176                                                                         if(doslice){
4177                                                                                 if(weaponactive!=-1){
4178                                                                                         victim->DoBloodBig(2/victim->armorhead,225);
4179                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
4180                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
4181                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
4182                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
4183                                                                                         if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
4184                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=3;
4185                                                                                 }
4186                                                                                 if(weaponactive==-1&&creature==wolftype){
4187                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
4188                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
4189                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
4190                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
4191                                                                                         victim->spurt=1;
4192                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
4193                                                                                 }
4194                                                                         }
4195
4196                                                                         if(id==0){
4197                                                                                 bonus=Reversal;
4198                                                                                 bonustime=0;
4199                                                                                 bonusvalue=60;
4200                                                                         }
4201
4202                                                                         victim->Puff(neck);
4203
4204                                                                         XYZ relative;
4205                                                                         //relative=victim->coords-oldcoords;
4206                                                                         relative=facing*-1;
4207                                                                         relative.y=0;
4208                                                                         Normalise(&relative);
4209                                                                         relative=DoRotation(relative,0,90,0);
4210                                                                         relative.y=.5;
4211                                                                         Normalise(&relative);
4212                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4213                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
4214                                                                         }
4215                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
4216                                                                         if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
4217                                                                         victim->DoDamage(damagemult*100/victim->protectionhead);
4218                                                                         victim->velocity=0;
4219                                                                 }
4220
4221                                                                 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
4222                                                                         escapednum=0;
4223                                                                         victim->RagDoll(0);
4224                                                                         XYZ relative;
4225                                                                         //relative=victim->coords-oldcoords;
4226                                                                         relative=facing*-1;
4227                                                                         relative.y=0;
4228                                                                         Normalise(&relative);
4229                                                                         relative=DoRotation(relative,0,90,0);
4230                                                                         relative.y=.5;
4231                                                                         Normalise(&relative);
4232                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4233                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
4234                                                                         }
4235                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
4236                                                                 }
4237
4238                                                                 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
4239                                                                         if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
4240                                                                                 if(id==0){
4241                                                                                         bonus=reverseko;
4242                                                                                         bonustime=0;
4243                                                                                         bonusvalue=100;
4244                                                                                 }
4245                                                                         }
4246                                                         }
4247
4248
4249                                                         //Animation end
4250                                                         if(targetframe>animation[currentanimation].numframes-1){
4251                                                                 targetframe=0;
4252                                                                 if(wasStop()){
4253                                                                         targetanimation=getIdle();
4254                                                                         FootLand(0,1);
4255                                                                         FootLand(1,1);
4256                                                                 }
4257                                                                 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
4258                                                                         targetanimation=rollanim;
4259                                                                         targetframe=3;
4260                                                                         float gLoc[3];
4261                                                                         float vel[3];
4262                                                                         gLoc[0]=coords.x;
4263                                                                         gLoc[1]=coords.y;
4264                                                                         gLoc[2]=coords.z;
4265                                                                         vel[0]=velocity.x;
4266                                                                         vel[1]=velocity.y;
4267                                                                         vel[2]=velocity.z;
4268
4269                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
4270                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
4271                                                                         OPENAL_SetVolume(channels[movewhooshsound], 128);
4272                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
4273                                                                 }
4274                                                                 if(currentanimation==staggerbackhighanim){
4275                                                                         targetanimation=getIdle();
4276                                                                 }
4277                                                                 if(currentanimation==staggerbackhardanim){
4278                                                                         targetanimation=getIdle();
4279                                                                 }
4280                                                                 if(currentanimation==removeknifeanim){
4281                                                                         targetanimation=getIdle();
4282                                                                 }
4283                                                                 if(currentanimation==crouchremoveknifeanim){
4284                                                                         targetanimation=getCrouch();
4285                                                                 }
4286                                                                 if(currentanimation==backhandspringanim){
4287                                                                         targetanimation=getIdle();
4288                                                                 }
4289                                                                 if(currentanimation==dodgebackanim){
4290                                                                         targetanimation=getIdle();
4291                                                                 }
4292                                                                 if(currentanimation==drawleftanim){
4293                                                                         targetanimation=getIdle();
4294                                                                 }
4295                                                                 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
4296                                                                         targetanimation=getIdle();
4297                                                                         if(currentanimation==crouchdrawrightanim){
4298                                                                                 targetanimation=getCrouch();
4299                                                                         }
4300                                                                         if(weaponactive==-1)weaponactive=0;
4301                                                                         else if(weaponactive==0){
4302                                                                                 weaponactive=-1;
4303                                                                                 if(num_weapons==2){
4304                                                                                         int buffer;
4305                                                                                         buffer=weaponids[0];
4306                                                                                         weaponids[0]=weaponids[1];
4307                                                                                         weaponids[1]=buffer;
4308                                                                                 }
4309                                                                         }
4310
4311                                                                         if(weaponactive==-1){
4312                                                                                 float gLoc[3];
4313                                                                                 float vel[3];
4314                                                                                 gLoc[0]=coords.x;
4315                                                                                 gLoc[1]=coords.y;
4316                                                                                 gLoc[2]=coords.z;
4317                                                                                 vel[0]=velocity.x;
4318                                                                                 vel[1]=velocity.y;
4319                                                                                 vel[2]=velocity.z;
4320
4321                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
4322                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
4323                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
4324                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
4325                                                                         }
4326                                                                         if(weaponactive!=-1){
4327                                                                                 float gLoc[3];
4328                                                                                 float vel[3];
4329                                                                                 gLoc[0]=coords.x;
4330                                                                                 gLoc[1]=coords.y;
4331                                                                                 gLoc[2]=coords.z;
4332                                                                                 vel[0]=velocity.x;
4333                                                                                 vel[1]=velocity.y;
4334                                                                                 vel[2]=velocity.z;
4335
4336                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
4337                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
4338                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
4339                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
4340                                                                         }
4341                                                                 }
4342                                                                 if(currentanimation==rollanim){
4343                                                                         targetanimation=getCrouch();
4344                                                                         FootLand(0,1);
4345                                                                         FootLand(1,1);
4346                                                                 }
4347                                                                 if(isFlip()){
4348                                                                         if(targetanimation==walljumprightkickanim){
4349                                                                                 targetrot=-190;
4350                                                                         }
4351                                                                         if(targetanimation==walljumpleftkickanim){
4352                                                                                 targetrot=190;
4353                                                                         }
4354                                                                         targetanimation=jumpdownanim;
4355                                                                 }
4356                                                                 if(currentanimation==climbanim){
4357                                                                         targetanimation=getCrouch();
4358                                                                         targetframe=1;
4359                                                                         coords+=facing*.1;
4360                                                                         if(!isnormal(coords.x))
4361                                                                                 coords=oldcoords;
4362                                                                         oldcoords=coords;
4363                                                                         collided=0;
4364                                                                         targetoffset=0;
4365                                                                         currentoffset=0;
4366                                                                         grabdelay=1;
4367                                                                         velocity=0;
4368                                                                         collided=0;
4369                                                                         avoidcollided=0;
4370                                                                 }
4371                                                                 if(targetanimation==rabbitkickreversalanim){
4372                                                                         targetanimation=getCrouch();
4373                                                                         lastfeint=0;
4374                                                                 }
4375                                                                 if(targetanimation==jumpreversalanim){
4376                                                                         targetanimation=getCrouch();
4377                                                                         lastfeint=0;
4378                                                                 }
4379                                                                 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
4380                                                                         if(attackkeydown&&targetanimation!=walljumpfrontanim){
4381                                                                                 int closest=-1;
4382                                                                                 float closestdist=-1;
4383                                                                                 float distance;
4384                                                                                 if(numplayers>1)
4385                                                                                         for(i=0;i<numplayers;i++){
4386                                                                                                 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
4387                                                                                                         distance=findDistancefast(&player[i].coords,&coords);
4388                                                                                                         if(closestdist==-1||distance<closestdist){
4389                                                                                                                 closestdist=distance;
4390                                                                                                                 closest=i;
4391                                                                                                         }
4392                                                                                                 }
4393                                                                                         }
4394                                                                                         if(closestdist>0&&closest>=0&&closestdist<16){
4395                                                                                                 victim=&player[closest];
4396                                                                                                 targetanimation=walljumprightkickanim;
4397                                                                                                 targetframe=0;
4398                                                                                                 XYZ rotatetarget=victim->coords-coords;
4399                                                                                                 Normalise(&rotatetarget);
4400                                                                                                 rotation=-asin(0-rotatetarget.x);
4401                                                                                                 rotation*=360/6.28;
4402                                                                                                 if(rotatetarget.z<0)rotation=180-rotation;
4403                                                                                                 targettilt2=-asin(rotatetarget.y)*360/6.28;
4404                                                                                                 velocity=(victim->coords-coords)*4;
4405                                                                                                 velocity.y+=2;
4406                                                                                                 transspeed=40;
4407                                                                                         }
4408                                                                         }
4409                                                                         if(targetanimation==walljumpbackanim){
4410                                                                                 targetanimation=backflipanim;
4411                                                                                 targetframe=3;
4412                                                                                 velocity=facing*-8;
4413                                                                                 velocity.y=4;
4414                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4415                                                                         }
4416                                                                         if(targetanimation==walljumprightanim){
4417                                                                                 targetanimation=rightflipanim;
4418                                                                                 targetframe=4;
4419                                                                                 targetrotation-=90;
4420                                                                                 rotation-=90;
4421                                                                                 velocity=DoRotation(facing,0,30,0)*-8;
4422                                                                                 velocity.y=4;
4423                                                                         }
4424                                                                         if(targetanimation==walljumpfrontanim){
4425                                                                                 targetanimation=frontflipanim;
4426                                                                                 targetframe=2;
4427                                                                                 //targetrotation-=180;
4428                                                                                 ////rotation-=180;
4429                                                                                 velocity=facing*8;
4430                                                                                 velocity.y=4;
4431                                                                         }
4432                                                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4433                                                                 }
4434                                                                 if(targetanimation==walljumpleftanim){
4435                                                                         if(attackkeydown){
4436                                                                                 int closest=-1;
4437                                                                                 float closestdist=-1;
4438                                                                                 float distance;
4439                                                                                 if(numplayers>1)
4440                                                                                         for(i=0;i<numplayers;i++){
4441                                                                                                 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
4442                                                                                                         distance=findDistancefast(&player[i].coords,&coords);
4443                                                                                                         if(closestdist==-1||distance<closestdist){
4444                                                                                                                 closestdist=distance;
4445                                                                                                                 closest=i;
4446                                                                                                         }
4447                                                                                                 }
4448                                                                                         }
4449                                                                                         if(closestdist>0&&closest>=0&&closestdist<16){
4450                                                                                                 victim=&player[closest];
4451                                                                                                 targetanimation=walljumpleftkickanim;
4452                                                                                                 targetframe=0;
4453                                                                                                 XYZ rotatetarget=victim->coords-coords;
4454                                                                                                 Normalise(&rotatetarget);
4455                                                                                                 rotation=-asin(0-rotatetarget.x);
4456                                                                                                 rotation*=360/6.28;
4457                                                                                                 if(rotatetarget.z<0)rotation=180-rotation;
4458                                                                                                 targettilt2=-asin(rotatetarget.y)*360/6.28;
4459                                                                                                 velocity=(victim->coords-coords)*4;
4460                                                                                                 velocity.y+=2;
4461                                                                                                 transspeed=40;
4462                                                                                         }
4463                                                                         }
4464                                                                         if(targetanimation!=walljumpleftkickanim){
4465                                                                                 targetanimation=leftflipanim;
4466                                                                                 targetframe=4;
4467                                                                                 targetrotation+=90;
4468                                                                                 rotation+=90;
4469                                                                                 velocity=DoRotation(facing,0,-30,0)*-8;
4470                                                                                 velocity.y=4;
4471                                                                         }
4472                                                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4473                                                                 }
4474                                                                 if(targetanimation==sneakattackanim){
4475                                                                         float ycoords=oldcoords.y;
4476                                                                         currentanimation=getCrouch();
4477                                                                         targetanimation=getCrouch();
4478                                                                         targetframe=1;
4479                                                                         currentframe=0;
4480                                                                         targetrotation+=180;
4481                                                                         rotation+=180;
4482                                                                         targettilt2*=-1;
4483                                                                         tilt2*=-1;
4484                                                                         transspeed=1000000;
4485                                                                         targetheadrotation+=180;
4486                                                                         coords-=facing*.7;
4487                                                                         if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
4488
4489                                                                         lastfeint=0;
4490                                                                 }
4491                                                                 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
4492                                                                         float ycoords=oldcoords.y;
4493                                                                         targetanimation=getIdle();
4494                                                                         targetframe=0;
4495                                                                         if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
4496
4497                                                                         lastfeint=0;
4498                                                                 }
4499                                                                 if(currentanimation==knifefollowanim){
4500                                                                         targetanimation=getIdle();
4501                                                                         lastfeint=0;
4502                                                                 }
4503                                                                 if(animation[targetanimation].attack==reversal&&currentanimation!=sneakattackanim&&currentanimation!=knifesneakattackanim&&currentanimation!=swordsneakattackanim&&currentanimation!=knifefollowanim){
4504                                                                         float ycoords=oldcoords.y;
4505                                                                         targetanimation=getStop();
4506                                                                         targetrotation+=180;
4507                                                                         rotation+=180;
4508                                                                         targettilt2*=-1;
4509                                                                         tilt2*=-1;
4510                                                                         transspeed=1000000;
4511                                                                         targetheadrotation+=180;
4512                                                                         if(!isnormal(coords.x))
4513                                                                                 coords=oldcoords;
4514                                                                         if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
4515                                                                                 oldcoords=coords+facing*.5;
4516                                                                         else if(currentanimation==sweepreversalanim)
4517                                                                                 oldcoords=coords+facing*1.1;
4518                                                                         else if(currentanimation==upunchreversalanim){
4519                                                                                 oldcoords=coords+facing*1.5;
4520                                                                                 targetrotation+=180;
4521                                                                                 rotation+=180;
4522                                                                                 targetheadrotation+=180;
4523                                                                                 targettilt2*=-1;
4524                                                                                 tilt2*=-1;
4525                                                                         }
4526                                                                         else if(currentanimation==knifeslashreversalanim){
4527                                                                                 oldcoords=coords+facing*.5;
4528                                                                                 targetrotation+=90;
4529                                                                                 rotation+=90;
4530                                                                                 targetheadrotation+=90;
4531                                                                                 targettilt2=0;
4532                                                                                 tilt2=0;
4533                                                                         }
4534                                                                         else if(currentanimation==staffspinhitreversalanim){
4535                                                                                 targetrotation+=180;
4536                                                                                 rotation+=180;
4537                                                                                 targetheadrotation+=180;
4538                                                                                 targettilt2=0;
4539                                                                                 tilt2=0;
4540                                                                         }
4541                                                                         if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
4542                                                                         else oldcoords.y=ycoords;
4543                                                                         currentoffset=coords-oldcoords;
4544                                                                         targetoffset=0;
4545                                                                         coords=oldcoords;
4546
4547                                                                         lastfeint=0;
4548                                                                 }
4549                                                                 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
4550                                                                         velocity=0;
4551                                                                         velocity.y=-5;
4552                                                                         RagDoll(0);
4553                                                                 }
4554                                                                 if(animation[targetanimation].attack==reversed){
4555                                                                         escapednum++;
4556                                                                         if(targetanimation==sweepreversedanim)targetrotation+=90;
4557                                                                         targetanimation=backhandspringanim;
4558                                                                         targetframe=2;
4559                                                                         float gLoc[3];
4560                                                                         float vel[3];
4561                                                                         gLoc[0]=coords.x;
4562                                                                         gLoc[1]=coords.y;
4563                                                                         gLoc[2]=coords.z;
4564                                                                         vel[0]=velocity.x;
4565                                                                         vel[1]=velocity.y;
4566                                                                         vel[2]=velocity.z;
4567                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
4568                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
4569                                                                         OPENAL_SetVolume(channels[landsound], 128);
4570                                                                         OPENAL_SetPaused(channels[landsound], false);
4571
4572                                                                         if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
4573                                                                                 targetanimation=rollanim;
4574                                                                                 targetframe=5;
4575                                                                                 oldcoords=coords;
4576                                                                                 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4577                                                                                 coords.y=oldcoords.y;
4578                                                                         }
4579                                                                         if(currentanimation==knifeslashreversedanim){
4580                                                                                 targetanimation=rollanim;
4581                                                                                 targetframe=0;
4582                                                                                 targetrotation+=90;
4583                                                                                 rotation+=90;
4584                                                                                 oldcoords=coords;
4585                                                                                 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4586                                                                                 coords.y=oldcoords.y;
4587                                                                         }
4588                                                                 }
4589                                                                 if(wasFlip()){
4590                                                                         targetanimation=jumpdownanim;
4591                                                                 }
4592                                                                 if(wasLanding())targetanimation=getIdle();
4593                                                                 if(wasLandhard())targetanimation=getIdle();
4594                                                                 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
4595                                                                         targetanimation=getIdle();
4596                                                                         oldcoords=coords;
4597                                                                         coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4598                                                                         coords.y=oldcoords.y;
4599                                                                         //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
4600                                                                         targetoffset.y=coords.y;
4601                                                                         if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
4602                                                                         currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
4603                                                                         currentoffset.y-=(coords.y-targetoffset.y);
4604                                                                         coords.y=targetoffset.y;
4605                                                                         targetoffset=0;
4606                                                                         normalsupdatedelay=0;
4607                                                                 }
4608                                                                 if(currentanimation==upunchanim){
4609                                                                         targetanimation=getStop();
4610                                                                         normalsupdatedelay=0;
4611                                                                         lastfeint=0;
4612                                                                 }
4613                                                                 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
4614                                                                         targetrotation=rotation;
4615                                                                         bool hasstaff;
4616                                                                         hasstaff=0;
4617                                                                         if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4618                                                                         if(!hasstaff)DoDamage(35);
4619                                                                         RagDoll(0);
4620                                                                         lastfeint=0;
4621                                                                         rabbitkickragdoll=1;
4622                                                                 }
4623                                                                 if(currentanimation==rabbitkickreversedanim){
4624                                                                         if(!feint){
4625                                                                                 velocity=0;
4626                                                                                 velocity.y=-10;
4627                                                                                 //DoDamage(100);
4628                                                                                 RagDoll(0);
4629                                                                                 skeleton.spinny=0;
4630                                                                                 if(id!=0)SolidHitBonus();
4631                                                                         }
4632                                                                         if(feint){
4633                                                                                 escapednum++;
4634                                                                                 targetanimation=rollanim;
4635                                                                                 coords+=facing;
4636                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4637                                                                         }
4638                                                                         lastfeint=0;
4639                                                                 }
4640                                                                 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
4641                                                                         velocity=0;
4642                                                                         velocity.y=-10;
4643                                                                         RagDoll(0);
4644                                                                         skeleton.spinny=0;
4645                                                                 }
4646                                                                 if(currentanimation==jumpreversedanim){
4647                                                                         if(!feint){
4648                                                                                 velocity=0;
4649                                                                                 velocity.y=-10;
4650                                                                                 //DoDamage(100);
4651                                                                                 RagDoll(0);
4652                                                                                 skeleton.spinny=0;
4653                                                                                 if(id!=0)SolidHitBonus();
4654                                                                         }
4655                                                                         if(feint){
4656                                                                                 escapednum++;
4657                                                                                 targetanimation=rollanim;
4658                                                                                 coords+=facing*2;
4659                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4660                                                                         }
4661                                                                         lastfeint=0;
4662                                                                 }
4663
4664                                                                 if(animation[currentanimation].attack==normalattack&&!victim->skeleton.free&&victim->targetanimation!=staggerbackhighanim&&victim->targetanimation!=staggerbackhardanim&&targetanimation!=winduppunchblockedanim&&targetanimation!=blockhighleftanim&&targetanimation!=swordslashparryanim&&targetanimation!=swordslashparriedanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim){
4665                                                                         targetanimation=getupfromfrontanim;
4666                                                                         lastfeint=0;
4667                                                                 }
4668                                                                 else if(animation[currentanimation].attack==normalattack){
4669                                                                         targetanimation=getIdle();
4670                                                                         lastfeint=0;
4671                                                                 }
4672                                                                 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
4673                                                                         targetanimation=blockhighleftstrikeanim;
4674                                                                 }
4675                                                                 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
4676                                                                         targetanimation=getIdle();
4677                                                                         lastfeint=0;
4678                                                                 }
4679                                                                 if(currentanimation==spinkickanim&&victim->skeleton.free){
4680                                                                         if(creature==rabbittype)targetanimation=fightidleanim;
4681                                                                 }
4682                                                         }
4683                                                         target=0;
4684
4685                                                         if(isIdle()&&!wasIdle())normalsupdatedelay=0;
4686
4687                                                         if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
4688                                                                 targetanimation=jumpdownanim;
4689                                                         }
4690                 }
4691                 if(!skeleton.free){
4692                         oldtarget=target;
4693                         if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
4694                                 if(!isRun()||!wasRun()){
4695                                         if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
4696                                                 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
4697                                         if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
4698                                                 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
4699                                 }
4700                                 if(isRun()&&wasRun()){
4701                                         float tempspeed;
4702                                         tempspeed=velspeed;
4703                                         if(tempspeed<10*speedmult)tempspeed=10*speedmult;
4704                                         target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
4705                                 }
4706                         }
4707                         else if(transspeed)target+=multiplier*transspeed*speed*2;
4708                         else{
4709                                 if(!isRun()||!wasRun()){
4710                                         if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
4711                                                 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
4712                                         if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
4713                                                 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
4714                                 }
4715                         }
4716
4717                         if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
4718
4719                         if(target>1){currentframe=targetframe; target=1;}
4720                         oldrot=rot;
4721                         rot=targetrot*target;
4722                         rotation+=rot-oldrot;
4723                         if(target==1){
4724                                 rot=0;
4725                                 oldrot=0;
4726                                 targetrot=0;
4727                         }
4728                         if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
4729                                 //Old rotates
4730                                 for(i=0;i<skeleton.num_joints;i++){
4731                                         skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
4732                                 }
4733
4734                                 skeleton.FindForwards();
4735
4736                                 for(i=0;i<skeleton.num_muscles;i++){
4737                                         if(skeleton.muscles[i].visible)
4738                                         {
4739                                                 skeleton.FindRotationMuscle(i,targetanimation);
4740                                         }
4741                                 }
4742                                 for(i=0;i<skeleton.num_muscles;i++){
4743                                         if(skeleton.muscles[i].visible)
4744                                         {
4745                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
4746                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
4747                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
4748                                         }
4749                                 }
4750
4751                                 //New rotates
4752                                 for(i=0;i<skeleton.num_joints;i++){
4753                                         skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
4754                                 }
4755
4756                                 skeleton.FindForwards();
4757
4758                                 for(i=0;i<skeleton.num_muscles;i++){
4759                                         if(skeleton.muscles[i].visible)
4760                                         {
4761                                                 skeleton.FindRotationMuscle(i,targetanimation);
4762                                         }
4763                                 }
4764                                 for(i=0;i<skeleton.num_muscles;i++){
4765                                         if(skeleton.muscles[i].visible)
4766                                         {
4767                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
4768                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
4769                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
4770                                                 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
4771                                                 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
4772                                                 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
4773                                                 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
4774                                                 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
4775                                                 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
4776                                         }
4777                                 }
4778                         }
4779                         if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
4780
4781                         oldcurrentanimation=currentanimation;
4782                         oldtargetanimation=targetanimation;
4783                         oldtargetframe=targetframe;
4784                         oldcurrentframe=currentframe;
4785
4786                         for(i=0;i<skeleton.num_joints;i++){
4787                                 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
4788                                 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
4789                         }
4790                         offset=currentoffset*(1-target)+targetoffset*target;
4791                         for(i=0;i<skeleton.num_muscles;i++){
4792                                 if(skeleton.muscles[i].visible)
4793                                 {
4794                                         skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
4795                                         skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
4796                                         skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
4797                                 }
4798                         }
4799                 }
4800
4801                 if(isLanding()&&landhard){
4802                         //if(abs(velocity.y)>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z)){
4803                         if(id==0)camerashake+=.4;
4804                         targetanimation=getLandhard();
4805                         targetframe=0;
4806                         target=0;
4807                         landhard=0;
4808                         transspeed=15;
4809                         //}
4810                 }
4811         }
4812         //skeleton.DoConstraints();
4813 }
4814
4815 void    Person::DoStuff(){
4816         static XYZ terrainnormal;
4817         static XYZ flatfacing;
4818         static XYZ flatvelocity;
4819         static float flatvelspeed;
4820         static int i,j,l;
4821         static XYZ average;
4822         static int howmany;
4823         static int bloodsize;
4824         static int startx,starty,endx,endy;
4825         static int texdetailint;
4826         static GLubyte color;
4827         static XYZ bloodvel;
4828
4829         onfiredelay-=multiplier;
4830         if(onfiredelay<0&&onfire)
4831         {
4832                 if(Random()%2==0){
4833                         crouchkeydown=1;
4834                 }
4835                 onfiredelay=0.3;
4836         }
4837
4838         crouchkeydowntime+=multiplier;
4839         if(!crouchkeydown)crouchkeydowntime=0;
4840         jumpkeydowntime+=multiplier;
4841         if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
4842
4843         if(hostile||damage>0||bloodloss>0)immobile=0;
4844
4845         if(isIdle()||isRun())targetoffset=0;
4846
4847         if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
4848
4849         if(id==0)blooddimamount-=multiplier*.3;
4850         speechdelay-=multiplier;
4851         texupdatedelay-=multiplier;
4852         interestdelay-=multiplier;
4853         flamedelay-=multiplier;
4854         parriedrecently-=multiplier;
4855         if(!victim){
4856                 victim=this;
4857                 hasvictim=0;
4858         }
4859
4860         if(id==0)speed=1.1*speedmult;
4861         else speed=1.0*speedmult;
4862         if(!skeleton.free)rabbitkickragdoll=0;
4863
4864         speed*=speedmult;
4865
4866         if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
4867         if(id!=0&&creature==wolftype&&difficulty==2){
4868                 superruntoggle=0;
4869                 if(aitype!=passivetype){
4870                         superruntoggle=1;
4871                         if(aitype==attacktypecutoff&&(player[0].isIdle()||player[0].isCrouch()||player[0].skeleton.free||player[0].targetanimation==getupfrombackanim||player[0].targetanimation==getupfromfrontanim||player[0].targetanimation==sneakanim)&&findDistancefast(&coords,&player[0].coords)<16){
4872                                 superruntoggle=0;
4873                         }
4874                 }
4875                 if(scale<0.2)superruntoggle=0;
4876                 if(targetanimation==wolfrunninganim&&!superruntoggle){
4877                         targetanimation=getRun();
4878                         targetframe=0;
4879                 }
4880         }
4881         if(weaponactive==-1&&num_weapons>0){
4882                 if(weapons.type[weaponids[0]]==staff){
4883                         weaponactive=0;
4884                 }
4885         }
4886
4887         if(onfire){
4888                 burnt+=multiplier;
4889                 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4890                 /*if(aitype!=playercontrolled)*/
4891                 deathbleeding=1;
4892                 if(burnt>.6)burnt=.6;
4893                 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
4894
4895                 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
4896                         float gLoc[3];
4897                         float vel[3];
4898                         gLoc[0]=coords.x;
4899                         gLoc[1]=coords.y;
4900                         gLoc[2]=coords.z;
4901                         vel[0]=velocity.x;
4902                         vel[1]=velocity.y;
4903                         vel[2]=velocity.z;
4904
4905                         if(id==0){
4906                                 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4907                                 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
4908                         }
4909                 }
4910         }
4911         while(flamedelay<0&&onfire){
4912                 flamedelay+=.006;
4913                 howmany=abs(Random()%(skeleton.num_joints));
4914                 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4915                 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4916                 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4917                 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4918                 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
4919         }
4920
4921         while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
4922                 flamedelay+=.05;
4923                 howmany=abs(Random()%(skeleton.num_joints));
4924                 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4925                 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4926                 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4927                 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4928                 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
4929         }
4930
4931         if(bleeding>0){
4932                 bleeding-=multiplier*.3;
4933                 if(bloodtoggle==2){
4934                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4935                         if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
4936                 }
4937         }
4938
4939         if(neckspurtamount>0){
4940                 neckspurtamount-=multiplier;
4941                 neckspurtdelay-=multiplier*3;
4942                 neckspurtparticledelay-=multiplier*3;
4943                 if(neckspurtparticledelay<0&&neckspurtdelay>2){
4944                         spurt=0;
4945                         bloodvel=0;
4946                         if(!skeleton.free){
4947                                 bloodvel.z=5*neckspurtamount;
4948                                 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4949                         }
4950                         if(skeleton.free){
4951                                 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
4952                         }
4953                         if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4954                         if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
4955                         if(skeleton.free)Sprite::MakeSprite(bloodsprite, (skeleton.joints[skeleton.jointlabels[neck]].position+(skeleton.joints[skeleton.jointlabels[neck]].position-skeleton.joints[skeleton.jointlabels[head]].position)/5)*scale+coords,bloodvel, 1,1,1, .05, .9);
4956                         if(!skeleton.free)Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position+(skeleton.joints[skeleton.jointlabels[neck]].position-skeleton.joints[skeleton.jointlabels[head]].position)/5,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, .9);
4957                         neckspurtparticledelay=.05;
4958                 }
4959                 if(neckspurtdelay<0){
4960                         neckspurtdelay=3;
4961                 }
4962         }
4963
4964         if(deathbleeding>0&&dead!=2){
4965                 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
4966                 else bleeddelay-=5*multiplier/4;
4967                 if(bleeddelay<0&&bloodtoggle){
4968                         bleeddelay=1;
4969                         XYZ bloodvel;
4970                         if(bloodtoggle){
4971                                 bloodvel=0;
4972                                 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
4973                                 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
4974                                 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
4975                                 if(!skeleton.free)Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
4976                         }
4977                 }
4978                 bloodloss+=deathbleeding*multiplier*80;
4979                 deathbleeding-=multiplier*1.6;
4980                 //if(id==0)deathbleeding-=multiplier*.2;
4981                 if(deathbleeding<0)deathbleeding=0;
4982                 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
4983                         if(weaponactive!=-1){
4984                                 weapons.owner[weaponids[0]]=-1;
4985                                 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4986                                 weapons.velocity[weaponids[0]].x+=.01;
4987                                 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4988                                 weapons.missed[weaponids[0]]=1;
4989                                 weapons.hitsomething[weaponids[0]]=0;
4990                                 weapons.freetime[weaponids[0]]=0;
4991                                 weapons.firstfree[weaponids[0]]=1;
4992                                 weapons.physics[weaponids[0]]=1;
4993                                 num_weapons--;
4994                                 if(num_weapons){
4995                                         weaponids[0]=weaponids[num_weapons];
4996                                         if(weaponstuck==num_weapons)weaponstuck=0;
4997                                 }
4998                                 weaponactive=-1;
4999                                 for(i=0;i<numplayers;i++){
5000                                         player[i].wentforweapon=0;
5001                                 }
5002
5003                                 if(id==0){
5004                                         flashamount=.5;
5005                                         flashr=1;
5006                                         flashg=0;
5007                                         flashb=0;
5008                                         flashdelay=0;
5009                                 }
5010                         }
5011
5012                         if(!dead&&creature==wolftype){
5013                                 bonus=Wolfbonus;
5014                                 bonustime=0;
5015                                 bonusvalue=300;
5016                         }
5017                         dead=2;
5018                         if(targetanimation==knifefollowedanim&&!skeleton.free){
5019                                 for(i=0;i<skeleton.num_joints;i++){
5020                                         skeleton.joints[i].velocity=0;
5021                                         skeleton.joints[i].velocity.y=-2;
5022                                 }
5023                         }
5024                         if(id!=0&&unconscioustime>.1){
5025                                 numafterkill++;
5026                         }
5027
5028                         RagDoll(0);
5029                 }
5030         }
5031
5032         if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
5033                 texupdatedelay=.12;
5034
5035                 bloodsize=5-realtexdetail;
5036
5037                 startx=0;
5038                 starty=0;
5039                 texdetailint=realtexdetail;
5040                 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
5041                 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
5042                 endx=startx+bloodsize;
5043                 endy=starty+bloodsize;
5044
5045                 if(startx<0){startx=0;bleeding=0;}
5046                 if(starty<0){starty=0;bleeding=0;}
5047                 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
5048                 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
5049                 if(endx<startx)endx=startx;
5050                 if(endy<starty)endy=starty;
5051
5052                 for(i=startx;i<endx;i++){
5053                         for(j=starty;j<endy;j++){
5054                                 if(Random()%2==0){
5055                                         color=Random()%85+170;
5056                                         if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
5057                                         skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
5058                                         skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
5059                                 }
5060                         }
5061                 }
5062                 if(!osx&&detail>1){
5063                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
5064                         DoMipmaps(0,startx,endx,starty,endy);
5065                 }
5066
5067                 if(!skeleton.free){
5068                         bleedy-=4/realtexdetail;
5069                         if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
5070                         else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
5071                 }
5072                 if(skeleton.free){
5073                         bleedx+=4*direction/realtexdetail;
5074                         if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
5075                         else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
5076                 }
5077         }
5078
5079         if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
5080                 righthandmorphness=targetrighthandmorphness;
5081                 righthandmorphstart=righthandmorphend;
5082         }
5083         else if(righthandmorphness>targetrighthandmorphness){
5084                 righthandmorphness-=multiplier*4;
5085         }
5086         else if(righthandmorphness<targetrighthandmorphness){
5087                 righthandmorphness+=multiplier*4;
5088         }
5089
5090         if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
5091                 lefthandmorphness=targetlefthandmorphness;
5092                 lefthandmorphstart=lefthandmorphend;
5093         }
5094         else if(lefthandmorphness>targetlefthandmorphness){
5095                 lefthandmorphness-=multiplier*4;
5096         }
5097         else if(lefthandmorphness<targetlefthandmorphness){
5098                 lefthandmorphness+=multiplier*4;
5099         }
5100
5101         if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
5102                 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
5103                         tailmorphness=targettailmorphness;
5104                         tailmorphstart=tailmorphend;
5105                 }
5106                 else if(tailmorphness>targettailmorphness){
5107                         tailmorphness-=multiplier*10;
5108                 }
5109                 else if(tailmorphness<targettailmorphness){
5110                         tailmorphness+=multiplier*10;
5111                 }
5112         }
5113
5114         if(creature==wolftype){
5115                 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
5116                         tailmorphness=targettailmorphness;
5117                         tailmorphstart=tailmorphend;
5118                 }
5119                 else if(tailmorphness>targettailmorphness){
5120                         tailmorphness-=multiplier*2;
5121                 }
5122                 else if(tailmorphness<targettailmorphness){
5123                         tailmorphness+=multiplier*2;
5124                 }
5125         }
5126
5127         if(headmorphend==3||headmorphstart==3){
5128                 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
5129                         headmorphness=targetheadmorphness;
5130                         headmorphstart=headmorphend;
5131                 }
5132                 else if(headmorphness>targetheadmorphness){
5133                         headmorphness-=multiplier*7;
5134                 }
5135                 else if(headmorphness<targetheadmorphness){
5136                         headmorphness+=multiplier*7;
5137                 }
5138         }
5139         else if(headmorphend==5||headmorphstart==5){
5140                 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
5141                         headmorphness=targetheadmorphness;
5142                         headmorphstart=headmorphend;
5143                 }
5144                 else if(headmorphness>targetheadmorphness){
5145                         headmorphness-=multiplier*10;
5146                 }
5147                 else if(headmorphness<targetheadmorphness){
5148                         headmorphness+=multiplier*10;
5149                 }
5150         }
5151         else{
5152                 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
5153                         headmorphness=targetheadmorphness;
5154                         headmorphstart=headmorphend;
5155                 }
5156                 else if(headmorphness>targetheadmorphness){
5157                         headmorphness-=multiplier*4;
5158                 }
5159                 else if(headmorphness<targetheadmorphness){
5160                         headmorphness+=multiplier*4;
5161                 }
5162         }
5163
5164         if(abs(chestmorphness-targetchestmorphness)<multiplier){
5165                 chestmorphness=targetchestmorphness;
5166                 chestmorphstart=chestmorphend;
5167         }
5168         else if(chestmorphness>targetchestmorphness){
5169                 chestmorphness-=multiplier;
5170         }
5171         else if(chestmorphness<targetchestmorphness){
5172                 chestmorphness+=multiplier;
5173         }
5174
5175         if(dead!=2&&howactive<=typesleeping){
5176                 if(chestmorphstart==0&&chestmorphend==0){
5177                         chestmorphness=0;
5178                         targetchestmorphness=1;
5179                         chestmorphend=3;
5180                 }
5181                 if(chestmorphstart!=0&&chestmorphend!=0){
5182                         chestmorphness=0;
5183                         targetchestmorphness=1;
5184                         chestmorphend=0;
5185                         if(environment==snowyenvironment){
5186                                 XYZ footpoint;
5187                                 XYZ footvel;
5188                                 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
5189                                 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
5190                                 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
5191                                 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
5192                                 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
5193                                 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
5194                         }
5195                 }
5196
5197                 if(!dead&&howactive<typesleeping){
5198                         blinkdelay-=multiplier*2;
5199                         if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
5200                                 headmorphness=0;
5201                                 targetheadmorphness=1;
5202                                 headmorphend=3;
5203                                 blinkdelay=(float)(abs(Random()%40))/5;
5204                         }
5205                         if(headmorphstart==3&&headmorphend==3){
5206                                 headmorphness=0;
5207                                 targetheadmorphness=1;
5208                                 headmorphend=0;
5209                         }
5210                 }
5211                 if(!dead){
5212                         twitchdelay-=multiplier*1.5;
5213                         if(targetanimation!=hurtidleanim){
5214                                 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
5215                                         headmorphness=0;
5216                                         targetheadmorphness=1;
5217                                         headmorphend=5;
5218                                         twitchdelay=(float)(abs(Random()%40))/5;
5219                                 }
5220                                 if(headmorphstart==5&&headmorphend==5){
5221                                         headmorphness=0;
5222                                         targetheadmorphness=1;
5223                                         headmorphend=0;
5224                                 }
5225                         }
5226                         if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
5227                                 twitchdelay3-=multiplier*1;
5228                                 if(Random()%2==0){
5229                                         if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
5230                                                 righthandmorphness=0;
5231                                                 targetrighthandmorphness=1;
5232                                                 righthandmorphend=1;
5233                                                 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
5234                                         }
5235                                         if(righthandmorphstart==1&&righthandmorphend==1){
5236                                                 righthandmorphness=0;
5237                                                 targetrighthandmorphness=1;
5238                                                 righthandmorphend=0;
5239                                         }
5240                                 }
5241                                 if(Random()%2==0){
5242                                         if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
5243                                                 lefthandmorphness=0;
5244                                                 targetlefthandmorphness=1;
5245                                                 lefthandmorphend=1;
5246                                                 twitchdelay3=(float)(abs(Random()%40))/5;
5247                                         }
5248                                         if(lefthandmorphstart==1&&lefthandmorphend==1){
5249                                                 lefthandmorphness=0;
5250                                                 targetlefthandmorphness=1;
5251                                                 lefthandmorphend=0;
5252                                         }
5253                                 }
5254                         }
5255                 }
5256                 if(!dead){
5257                         if(creature==rabbittype){
5258                                 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
5259                                 else twitchdelay2-=multiplier*0.5;
5260                                 if(howactive<=typesleeping){
5261                                         if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
5262                                                 tailmorphness=0;
5263                                                 targettailmorphness=1;
5264                                                 tailmorphend=1;
5265                                                 twitchdelay2=(float)(abs(Random()%40))/5;
5266                                         }
5267                                         if(tailmorphstart==1&&tailmorphend==1){
5268                                                 tailmorphness=0;
5269                                                 targettailmorphness=1;
5270                                                 tailmorphend=2;
5271                                         }
5272                                         if(tailmorphstart==2&&tailmorphend==2){
5273                                                 tailmorphness=0;
5274                                                 targettailmorphness=1;
5275                                                 tailmorphend=0;
5276                                         }
5277                                 }
5278                         }
5279                 }
5280         }
5281         if(creature==wolftype){
5282                 twitchdelay2-=multiplier*1.5;
5283                 if(tailmorphend!=0)
5284                         if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
5285                                 tailmorphness=0;
5286                                 targettailmorphness=1;
5287                                 tailmorphend=0;
5288                                 twitchdelay2=.1;
5289                         }
5290                         if(tailmorphend!=5)
5291                                 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
5292                                         tailmorphness=0;
5293                                         targettailmorphness=1;
5294                                         tailmorphend=5;
5295                                         twitchdelay2=.1;
5296                                 }
5297                                 if(twitchdelay2<=0){
5298                                         if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
5299                                                 tailmorphness=0;
5300                                                 targettailmorphness=1;
5301                                                 tailmorphend=1;
5302                                         }
5303                                         if(tailmorphstart==1&&tailmorphend==1){
5304                                                 tailmorphness=0;
5305                                                 targettailmorphness=1;
5306                                                 tailmorphend=2;
5307                                         }
5308                                         if(tailmorphstart==2&&tailmorphend==2){
5309                                                 tailmorphness=0;
5310                                                 targettailmorphness=1;
5311                                                 tailmorphend=3;
5312                                         }
5313                                         if(tailmorphstart==3&&tailmorphend==3){
5314                                                 tailmorphness=0;
5315                                                 targettailmorphness=1;
5316                                                 tailmorphend=4;
5317                                         }
5318                                         if(tailmorphstart==4&&tailmorphend==4){
5319                                                 tailmorphness=0;
5320                                                 targettailmorphness=1;
5321                                                 tailmorphend=1;
5322                                         }
5323                                 }
5324         }
5325
5326         if(dead!=1)unconscioustime=0;
5327
5328         if(dead==1||howactive==typesleeping){
5329                 unconscioustime+=multiplier;
5330                 //If unconscious, close eyes and mouth
5331                 if(righthandmorphend!=0)righthandmorphness=0;
5332                 righthandmorphend=0;
5333                 targetrighthandmorphness=1;
5334
5335                 if(lefthandmorphend!=0)lefthandmorphness=0;
5336                 lefthandmorphend=0;
5337                 targetlefthandmorphness=1;
5338
5339                 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
5340                 headmorphend=3;
5341                 targetheadmorphness=1;
5342         }
5343
5344
5345         if(howactive>typesleeping){
5346                 XYZ headpoint;
5347                 headpoint=coords;
5348                 if(bloodtoggle&&!bled){
5349                         terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
5350                 }
5351                 if(bloodtoggle&&!bled)
5352                         for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5353                                 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5354                                 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5355                                 float size=.8;
5356                                 float opacity=.6;
5357                                 float rotation=0;
5358                                 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
5359                         }
5360                         bled=1;
5361         }
5362
5363         if(dead==2||howactive>typesleeping){
5364                 //If dead, open mouth and hands
5365                 if(righthandmorphend!=0)righthandmorphness=0;
5366                 righthandmorphend=0;
5367                 targetrighthandmorphness=1;
5368
5369                 if(lefthandmorphend!=0)lefthandmorphness=0;
5370                 lefthandmorphend=0;
5371                 targetlefthandmorphness=1;
5372
5373                 if(headmorphend!=2)headmorphness=0;
5374                 headmorphend=2;
5375                 targetheadmorphness=1;
5376         }
5377
5378         if(stunned>0&&!dead&&headmorphend!=2){
5379                 if(headmorphend!=4)headmorphness=0;
5380                 headmorphend=4;
5381                 targetheadmorphness=1;
5382         }
5383
5384         if(damage>damagetolerance&&!dead){
5385
5386                 dead=1;
5387                 unconscioustime=0;
5388
5389                 if(creature==wolftype){
5390                         bonus=Wolfbonus;
5391                         bonustime=0;
5392                         bonusvalue=300;
5393                 }
5394
5395                 RagDoll(0);
5396
5397                 if(weaponactive!=-1){
5398                         weapons.owner[weaponids[0]]=-1;
5399                         weapons.velocity[weaponids[0]]=velocity*scale*-.3;
5400                         weapons.velocity[weaponids[0]].x+=.01;
5401                         weapons.tipvelocity[weaponids[0]]=velocity*scale;
5402                         weapons.missed[weaponids[0]]=1;
5403                         weapons.hitsomething[weaponids[0]]=0;
5404                         weapons.freetime[weaponids[0]]=0;
5405                         weapons.firstfree[weaponids[0]]=1;
5406                         weapons.physics[weaponids[0]]=1;
5407                         num_weapons--;
5408                         if(num_weapons){
5409                                 weaponids[0]=weaponids[num_weapons];
5410                                 if(weaponstuck==num_weapons)weaponstuck=0;
5411                         }
5412                         weaponactive=-1;
5413                         for(i=0;i<numplayers;i++){
5414                                 player[i].wentforweapon=0;
5415                         }
5416                 }
5417
5418
5419
5420                 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
5421                         slomo=1;
5422                         slomodelay=.2;
5423                 }
5424
5425                 damage+=20;
5426         }
5427
5428         //if(dead)damage-=multiplier/4;
5429         if(!dead)damage-=multiplier*13;
5430         //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
5431         if(!dead)permanentdamage-=multiplier*4;
5432         if(isIdle()||isCrouch()){
5433                 if(!dead)permanentdamage-=multiplier*4;
5434                 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
5435         }
5436         if(damage<0)damage=0;
5437         if(permanentdamage<0)permanentdamage=0;
5438         if(superpermanentdamage<0)superpermanentdamage=0;
5439         if(permanentdamage<superpermanentdamage){
5440                 permanentdamage=superpermanentdamage;
5441         }
5442         if(damage<permanentdamage){
5443                 damage=permanentdamage;
5444         }
5445         if(dead==1&&damage<damagetolerance){
5446                 dead=0;
5447                 skeleton.free=1;
5448                 damage-=20;
5449                 for(i=0;i<skeleton.num_joints;i++){
5450                         skeleton.joints[i].velocity=0;
5451                 }
5452         }
5453         if(permanentdamage>damagetolerance&&dead!=2){
5454                 DoBlood(1,255);
5455
5456                 if(weaponactive!=-1){
5457                         weapons.owner[weaponids[0]]=-1;
5458                         weapons.velocity[weaponids[0]]=velocity*scale*-.3;
5459                         weapons.velocity[weaponids[0]].x+=.01;
5460                         weapons.tipvelocity[weaponids[0]]=velocity*scale;
5461                         weapons.missed[weaponids[0]]=1;
5462                         weapons.hitsomething[weaponids[0]]=0;
5463                         weapons.freetime[weaponids[0]]=0;
5464                         weapons.firstfree[weaponids[0]]=1;
5465                         weapons.physics[weaponids[0]]=1;
5466                         num_weapons--;
5467                         if(num_weapons){
5468                                 weaponids[0]=weaponids[num_weapons];
5469                                 if(weaponstuck==num_weapons)weaponstuck=0;
5470                         }
5471                         weaponactive=-1;
5472                         for(i=0;i<numplayers;i++){
5473                                 player[i].wentforweapon=0;
5474                         }
5475                 }
5476
5477                 bled=0;
5478
5479                 if(!dead&&creature==wolftype){
5480                         bonus=Wolfbonus;
5481                         bonustime=0;
5482                         bonusvalue=300;
5483                 }
5484
5485                 if(id!=0&&unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance){
5486                         bonus=touchofdeath;
5487                         bonustime=0;
5488                         bonusvalue=150;
5489                 }
5490                 if(id!=0&&unconscioustime>.1){
5491                         numafterkill++;
5492                 }
5493
5494                 dead=2;
5495
5496                 skeleton.free=1;
5497
5498                 float gLoc[3];
5499                 float vel[3];
5500                 gLoc[0]=coords.x;
5501                 gLoc[1]=coords.y;
5502                 gLoc[2]=coords.z;
5503                 vel[0]=velocity.x;
5504                 vel[1]=velocity.y;
5505                 vel[2]=velocity.z;
5506                 PlaySoundEx( breaksound, samp[breaksound], NULL, true);
5507                 OPENAL_3D_SetAttributes(channels[breaksound], gLoc, vel);
5508                 OPENAL_SetVolume(channels[breaksound], 512);
5509                 OPENAL_SetPaused(channels[breaksound], false);
5510                 /*if(id==0||findDistancefast(&coords,&viewer)<50){
5511                 slomo=1;
5512                 slomodelay=.2;
5513                 }*/
5514         }
5515
5516         if(skeleton.free==1){
5517                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5518
5519                 if(!dead){
5520                         //If knocked over, open hands and close mouth
5521                         if(righthandmorphend!=0)righthandmorphness=0;
5522                         righthandmorphend=0;
5523                         targetrighthandmorphness=1;
5524
5525                         if(lefthandmorphend!=0)lefthandmorphness=0;
5526                         lefthandmorphend=0;
5527                         targetlefthandmorphness=1;
5528
5529                         if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
5530                                 if(headmorphend!=0)headmorphness=0;
5531                                 headmorphend=0;
5532                                 targetheadmorphness=1;
5533                         }
5534                 }
5535
5536                 skeleton.DoGravity(&scale);
5537                 float damageamount;
5538                 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
5539                 if(id!=0&&damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1)){
5540                         bonus=deepimpact;
5541                         bonustime=0;
5542                         bonusvalue=50;
5543                 }
5544                 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
5545
5546                 average=0;
5547                 howmany=0;
5548                 for(j=0;j<skeleton.num_joints;j++){
5549                         average+=skeleton.joints[j].position;
5550                         howmany++;
5551                 }
5552                 average/=howmany;
5553                 coords+=average*scale;
5554                 for(j=0;j<skeleton.num_joints;j++){
5555                         skeleton.joints[j].position-=average;
5556                 }
5557                 average/=multiplier;
5558
5559                 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
5560                 velocity=0;
5561                 for(i=0;i<skeleton.num_joints;i++){
5562                         velocity+=skeleton.joints[i].velocity*scale;
5563                 }
5564                 velocity/=skeleton.num_joints;
5565
5566                 if(!isnormal(velocity.x)&&velocity.x){
5567                         velocity=0;
5568                 }
5569
5570                 float gLoc[3];
5571                 float vel[3];
5572                 gLoc[0]=coords.x;
5573                 gLoc[1]=coords.y;
5574                 gLoc[2]=coords.z;
5575                 vel[0]=velocity.x;
5576                 vel[1]=velocity.y;
5577                 vel[2]=velocity.z;
5578
5579                 if(findLength(&average)<10&&dead&&skeleton.free){
5580                         skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
5581                         if(skeleton.longdead>2000){
5582                                 if(skeleton.longdead>6000){
5583                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5584                                         skeleton.free=3;
5585                                         DrawSkeleton();
5586                                         skeleton.free=2;
5587                                 }
5588                                 if(dead==2&&bloodloss<damagetolerance){
5589                                         XYZ headpoint;
5590                                         headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
5591                                         DoBlood(1,255);
5592                                         if(bloodtoggle&&!bled){
5593                                                 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
5594                                         }
5595                                         if(bloodtoggle&&!bled)
5596                                                 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5597                                                         j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5598                                                         XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5599                                                         float size=.2*1.2;
5600                                                         float opacity=.6;
5601                                                         float rotation=0;
5602                                                         objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
5603                                                 }
5604                                                 bled=1;
5605                                 }
5606                                 if(dead==2&&bloodloss>=damagetolerance){
5607                                         XYZ headpoint;
5608                                         headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
5609                                         if(bleeding<=0)DoBlood(1,255);
5610                                         if(bloodtoggle&&!bled){
5611                                                 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
5612                                         }
5613                                         if(bloodtoggle&&!bled)
5614                                                 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5615                                                         j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5616                                                         XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5617                                                         float size=.8;
5618                                                         float opacity=.6;
5619                                                         float rotation=0;
5620                                                         objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
5621                                                 }
5622                                                 bled=1;
5623                                 }
5624                         }
5625                 }
5626
5627                 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
5628                         bool canrecover=1;
5629                         XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
5630                         startpoint=coords;
5631                         endpoint=coords;
5632                         endpoint.y-=.7;
5633                         if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
5634                         if(velocity.y<-30)canrecover=0;
5635                         for(i=0;i<objects.numobjects;i++){
5636                                 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
5637                                         colviewer=startpoint;
5638                                         coltarget=endpoint;
5639                                         if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
5640                                 }
5641                         }
5642                         if(canrecover){
5643                                 skeleton.free=0;
5644                                 XYZ middle;
5645                                 middle=0;
5646
5647                                 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5648                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
5649                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5650                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5651                                 }
5652                                 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5653                                         terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5654                                         middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5655                                 }
5656                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5657                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5658                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
5659                                 }
5660                                 Normalise(&terrainnormal);
5661
5662                                 targetrotation=-asin(0-terrainnormal.x);
5663                                 targetrotation*=360/6.28;
5664                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5665                                 rotation=targetrotation;
5666
5667                                 //if(skeleton.forward.y<0){
5668                                 targetframe=0;
5669                                 //}
5670                                 //if(skeleton.forward.y>-.3){
5671                                 //      targetframe=2;
5672                                 //}
5673                                 targetanimation=flipanim;
5674                                 crouchtogglekeydown=1;
5675                                 target=0;
5676                                 tilt2=0;
5677                                 targettilt2=0;
5678
5679                                 currentanimation=tempanim;
5680                                 currentframe=0;
5681                                 target=0;
5682                                 //tilt2=targettilt2;
5683
5684                                 //if(middle.y>0)targetoffset.y=middle.y+1;
5685
5686                                 for(i=0;i<skeleton.num_joints;i++){
5687                                         tempanimation.position[i][0]=skeleton.joints[i].position;
5688                                         tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
5689                                 }
5690                         }
5691                 }
5692
5693                 if(findLength(&average)<10&&!dead&&skeleton.free){
5694                         skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
5695                         if(skeleton.longdead>(damage+500)*1.5){
5696                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5697                                 skeleton.free=0;
5698                                 velocity=0;
5699                                 XYZ middle;
5700                                 middle=0;
5701
5702                                 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5703                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
5704                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5705                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5706                                 }
5707                                 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5708                                         terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5709                                         middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5710                                 }
5711                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5712                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5713                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
5714                                 }
5715                                 Normalise(&terrainnormal);
5716
5717                                 targetrotation=-asin(0-terrainnormal.x);
5718                                 targetrotation*=360/6.28;
5719                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5720                                 rotation=targetrotation;
5721
5722                                 /*if(onterrain){
5723                                 terrainnormal=terrain.getNormal(coords.x,coords.z);
5724                                 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
5725                                 }
5726                                 else*/
5727
5728                                 /*XYZ otherterrainnormal;
5729                                 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
5730                                 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
5731                                 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
5732                                 targettilt2=asin(otherterrainnormal.y)*180/3.14;
5733                                 */
5734
5735                                 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
5736
5737
5738
5739                                 if(skeleton.forward.y<0){
5740                                         targetanimation=getupfrombackanim;
5741                                         targetframe=0;
5742                                         targettilt2=0;
5743                                 }
5744                                 if(skeleton.forward.y>-.3){
5745                                         targetanimation=getupfromfrontanim;
5746                                         rotation+=180;
5747                                         targetrotation+=180;
5748                                         targettilt2*=-1;
5749                                         targetframe=0;
5750                                         targettilt2=0;
5751                                 }
5752
5753                                 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
5754                                         targetanimation=rollanim;
5755                                         targetrotation=lookrotation;
5756                                         if(id==0){
5757                                                 if(rightkeydown){
5758                                                         targetrotation-=90;
5759                                                         if(forwardkeydown)targetrotation+=45;
5760                                                         if(backkeydown)targetrotation-=45;
5761                                                 }
5762                                                 if(leftkeydown){
5763                                                         targetrotation+=90;
5764                                                         if(forwardkeydown)targetrotation-=45;
5765                                                         if(backkeydown)targetrotation+=45;
5766                                                 }
5767                                                 if(backkeydown){
5768                                                         if ( !leftkeydown&&!rightkeydown)
5769                                                                 targetrotation+=180;
5770                                                 }
5771                                                 targetrotation+=180;
5772                                         }
5773                                 }
5774
5775                                 if(abs(targettilt2)>50)targettilt2=0;
5776                                 currentanimation=tempanim;
5777                                 currentframe=0;
5778                                 target=0;
5779                                 tilt2=targettilt2;
5780
5781                                 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
5782
5783                                 for(i=0;i<skeleton.num_joints;i++){
5784                                         tempanimation.position[i][0]=skeleton.joints[i].position;
5785                                         tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
5786                                 }
5787                         }
5788                 }
5789
5790                 bool hasstaff;
5791                 hasstaff=0;
5792                 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
5793                 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
5794                         if(velocity.y>-30){
5795                                 XYZ tempvelocity;
5796                                 tempvelocity=velocity;
5797                                 Normalise(&tempvelocity);
5798                                 targetrotation=-asin(0-tempvelocity.x);
5799                                 targetrotation*=360/6.28;
5800                                 if(velocity.z<0)targetrotation=180-targetrotation;
5801                                 //targetrotation+=180;
5802
5803                                 skeleton.free=0;
5804                                 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
5805                                         targetanimation=rollanim;
5806                                         targetframe=2;
5807                                 }
5808                                 else{
5809                                         targetanimation=backhandspringanim;
5810                                         targetrotation+=180;
5811                                         targetframe=6;
5812                                 }
5813                                 target=0;
5814
5815                                 float gLoc[3];
5816                                 float vel[3];
5817                                 gLoc[0]=coords.x;
5818                                 gLoc[1]=coords.y;
5819                                 gLoc[2]=coords.z;
5820                                 vel[0]=velocity.x;
5821                                 vel[1]=velocity.y;
5822                                 vel[2]=velocity.z;
5823                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
5824                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
5825                                 OPENAL_SetVolume(channels[movewhooshsound], 128);
5826                                 OPENAL_SetPaused(channels[movewhooshsound], false);
5827
5828                                 currentanimation=targetanimation;
5829                                 currentframe=targetframe-1;
5830                                 target=0;
5831
5832                                 velocity=0;
5833
5834                                 rotation=targetrotation;
5835                                 tilt=0;
5836                                 targettilt=0;
5837                                 tilt2=0;
5838                                 targettilt2=0;
5839                         }
5840                 }
5841                 if(skeleton.freefall==0)freefall=0;
5842
5843                 if(!isnormal(velocity.x)&&velocity.x){
5844                         int xy=1;
5845                 }
5846         }
5847
5848         if(aitype!=passivetype||skeleton.free==1)
5849                 if(findLengthfast(&velocity)>.1)
5850                         for(i=0;i<objects.numobjects;i++){
5851                                 if(objects.type[i]==firetype)
5852                                         if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
5853                                                 if(onfire){
5854                                                         if(!objects.onfire[i]){
5855                                                                 float gLoc[3];
5856                                                                 float vel[3];
5857                                                                 gLoc[0]=objects.position[i].x;
5858                                                                 gLoc[1]=objects.position[i].y;
5859                                                                 gLoc[2]=objects.position[i].z;
5860                                                                 vel[0]=0;
5861                                                                 vel[1]=0;
5862                                                                 vel[2]=0;
5863                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
5864                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
5865                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
5866                                                                 OPENAL_SetPaused(channels[firestartsound], false);
5867                                                         }
5868                                                         objects.onfire[i]=1;
5869                                                 }
5870                                                 if(!onfire){
5871                                                         if(objects.onfire[i]){
5872                                                                 CatchFire();
5873                                                         }
5874                                                 }
5875                                         }
5876                                         if(objects.type[i]==bushtype)
5877                                                 if(findDistancefastflat(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*12&&findDistancefast(&coords,&objects.position[i])<objects.scale[i]*objects.scale[i]*49){
5878                                                         if(onfire){
5879                                                                 if(!objects.onfire[i]){
5880                                                                         float gLoc[3];
5881                                                                         float vel[3];
5882                                                                         gLoc[0]=objects.position[i].x;
5883                                                                         gLoc[1]=objects.position[i].y;
5884                                                                         gLoc[2]=objects.position[i].z;
5885                                                                         vel[0]=0;
5886                                                                         vel[1]=0;
5887                                                                         vel[2]=0;
5888                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
5889                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
5890                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
5891                                                                         OPENAL_SetPaused(channels[firestartsound], false);
5892                                                                 }
5893                                                                 objects.onfire[i]=1;
5894                                                         }
5895
5896                                                         if(!onfire){
5897                                                                 if(objects.onfire[i]){
5898                                                                         CatchFire();
5899                                                                 }
5900                                                         }
5901                                                         if(objects.messedwith[i]<=0){
5902                                                                 XYZ tempvel;
5903                                                                 XYZ pos;
5904
5905                                                                 float gLoc[3];
5906                                                                 float vel[3];
5907                                                                 gLoc[0]=coords.x;
5908                                                                 gLoc[1]=coords.y;
5909                                                                 gLoc[2]=coords.z;
5910                                                                 vel[0]=velocity.x;
5911                                                                 vel[1]=velocity.y;
5912                                                                 vel[2]=velocity.z;
5913                                                                 PlaySoundEx( bushrustle, samp[bushrustle], NULL, true);
5914                                                                 OPENAL_3D_SetAttributes(channels[bushrustle], gLoc, vel);
5915                                                                 OPENAL_SetVolume(channels[bushrustle], 40*findLength(&velocity));
5916                                                                 OPENAL_SetPaused(channels[bushrustle], false);
5917
5918                                                                 if(id==0){
5919                                                                         envsound[numenvsounds]=coords;
5920                                                                         envsoundvol[numenvsounds]=4*findLength(&velocity);
5921                                                                         envsoundlife[numenvsounds]=.4;
5922                                                                         numenvsounds++;
5923                                                                 }
5924
5925                                                                 int howmany;
5926                                                                 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
5927                                                                 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
5928                                                                 if(detail==2)
5929                                                                         if(environment!=desertenvironment)
5930                                                                                 for(j=0;j<howmany;j++){
5931                                                                                         tempvel.x=float(abs(Random()%100)-50)/20;
5932                                                                                         tempvel.y=float(abs(Random()%100)-50)/20;
5933                                                                                         tempvel.z=float(abs(Random()%100)-50)/20;
5934                                                                                         pos=coords;
5935                                                                                         pos.y+=1;
5936                                                                                         pos.x+=float(abs(Random()%100)-50)/200;
5937                                                                                         pos.y+=float(abs(Random()%100)-50)/200;
5938                                                                                         pos.z+=float(abs(Random()%100)-50)/200;
5939                                                                                         Sprite::MakeSprite(splintersprite, pos,tempvel*.5+velocity*float(abs(Random()%100))/100, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1);
5940                                                                                         Sprite::setLastSpriteSpecial(1);
5941                                                                                 }
5942                                                                                 howmany=findLength(&velocity)*4;
5943                                                                                 if(detail==2)
5944                                                                                         if(environment==snowyenvironment)
5945                                                                                                 for(j=0;j<howmany;j++){
5946                                                                                                         tempvel.x=float(abs(Random()%100)-50)/20;
5947                                                                                                         tempvel.y=float(abs(Random()%100)-50)/20;
5948                                                                                                         tempvel.z=float(abs(Random()%100)-50)/20;
5949                                                                                                         pos=coords;
5950                                                                                                         pos.y+=1;
5951                                                                                                         pos.x+=float(abs(Random()%100)-50)/200;
5952                                                                                                         pos.y+=float(abs(Random()%100)-50)/200;
5953                                                                                                         pos.z+=float(abs(Random()%100)-50)/200;
5954                                                                                                         Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
5955                                                                                                         Sprite::setLastSpriteSpecial(2);
5956                                                                                                 }
5957                                                         }
5958                                                         objects.rotx[i]+=velocity.x*multiplier*6;
5959                                                         objects.roty[i]+=velocity.z*multiplier*6;
5960                                                         objects.messedwith[i]=.5;
5961                                                 }
5962                                                 XYZ tempcoord;
5963                                                 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
5964                                                         if(objects.rotation2[i]==0)tempcoord=coords;
5965                                                         else{
5966                                                                 tempcoord=coords-objects.position[i];
5967                                                                 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
5968                                                                 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
5969                                                                 tempcoord+=objects.position[i];
5970                                                         }
5971                                                         if(findDistancefastflat(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*8&&findDistancefast(&tempcoord,&objects.position[i])<objects.scale[i]*objects.scale[i]*300&&tempcoord.y>objects.position[i].y+3*objects.scale[i]){
5972                                                                 if(objects.messedwith[i]<=0){
5973                                                                         XYZ tempvel;
5974                                                                         XYZ pos;
5975
5976                                                                         float gLoc[3];
5977                                                                         float vel[3];
5978                                                                         gLoc[0]=coords.x;
5979                                                                         gLoc[1]=coords.y;
5980                                                                         gLoc[2]=coords.z;
5981                                                                         vel[0]=velocity.x;
5982                                                                         vel[1]=velocity.y;
5983                                                                         vel[2]=velocity.z;
5984                                                                         PlaySoundEx( bushrustle, samp[bushrustle], NULL, true);
5985                                                                         OPENAL_3D_SetAttributes(channels[bushrustle], gLoc, vel);
5986                                                                         OPENAL_SetVolume(channels[bushrustle], 40*findLength(&velocity));
5987                                                                         OPENAL_SetPaused(channels[bushrustle], false);
5988
5989                                                                         if(id==0){
5990                                                                                 envsound[numenvsounds]=coords;
5991                                                                                 envsoundvol[numenvsounds]=4*findLength(&velocity);
5992                                                                                 envsoundlife[numenvsounds]=.4;
5993                                                                                 numenvsounds++;
5994                                                                         }
5995
5996                                                                         int howmany;
5997                                                                         if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
5998                                                                         if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
5999                                                                         if(detail==2)
6000                                                                                 if(environment!=desertenvironment)
6001                                                                                         for(j=0;j<howmany;j++){
6002                                                                                                 tempvel.x=float(abs(Random()%100)-50)/20;
6003                                                                                                 tempvel.y=float(abs(Random()%100)-50)/20;
6004                                                                                                 tempvel.z=float(abs(Random()%100)-50)/20;
6005                                                                                                 pos=coords;
6006                                                                                                 pos+=velocity*.1;
6007                                                                                                 pos.y+=1;
6008                                                                                                 pos.x+=float(abs(Random()%100)-50)/150;
6009                                                                                                 pos.y+=float(abs(Random()%100)-50)/150;
6010                                                                                                 pos.z+=float(abs(Random()%100)-50)/150;
6011                                                                                                 Sprite::MakeSprite(splintersprite, pos,tempvel*.5+velocity*float(abs(Random()%100))/100, 165/255+float(abs(Random()%100)-50)/400,0,0, .2+float(abs(Random()%100)-50)/1300, 1);
6012                                                                                                 Sprite::setLastSpriteSpecial(1);
6013                                                                                         }
6014                                                                                         howmany=findLength(&velocity)*4;
6015                                                                                         if(detail==2)
6016                                                                                                 if(environment==snowyenvironment)
6017                                                                                                         for(j=0;j<howmany;j++){
6018                                                                                                                 tempvel.x=float(abs(Random()%100)-50)/20;
6019                                                                                                                 tempvel.y=float(abs(Random()%100)-50)/20;
6020                                                                                                                 tempvel.z=float(abs(Random()%100)-50)/20;
6021                                                                                                                 pos=coords;
6022                                                                                                                 pos+=velocity*.1;
6023                                                                                                                 pos.y+=1;
6024                                                                                                                 pos.x+=float(abs(Random()%100)-50)/150;
6025                                                                                                                 pos.y+=float(abs(Random()%100)-50)/150;
6026                                                                                                                 pos.z+=float(abs(Random()%100)-50)/150;
6027                                                                                                                 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
6028                                                                                                                 Sprite::setLastSpriteSpecial(2);
6029                                                                                                         }
6030                                                                 }
6031                                                                 objects.messedwith[i]=.5;
6032                                                         }
6033                                                 }
6034                         }
6035
6036                         if(!skeleton.free){
6037                                 bool play;
6038                                 play=0;
6039                                 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
6040                                 if(hasvictim)
6041                                         if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
6042                                 if(tutoriallevel==1&&id!=0)play=0;
6043                                 if(play&&aitype!=playercontrolled){
6044                                         int whichsound=-1;
6045                                         float gLoc[3];
6046                                         float vel[3];
6047                                         gLoc[0]=coords.x;
6048                                         gLoc[1]=coords.y;
6049                                         gLoc[2]=coords.z;
6050                                         vel[0]=velocity.x;
6051                                         vel[1]=velocity.y;
6052                                         vel[2]=velocity.z;
6053                                         i=abs(Random()%4);
6054                                         if(speechdelay<=0){
6055                                                 if(creature==rabbittype){
6056                                                         if(i==0)whichsound=rabbitchitter;
6057                                                         if(i==1)whichsound=rabbitchitter2;
6058                                                 }
6059                                                 if(creature==wolftype){
6060                                                         if(i==0)whichsound=growlsound;
6061                                                         if(i==1)whichsound=growl2sound;
6062                                                 }
6063                                         }
6064                                         speechdelay=.3;
6065
6066                                         if(whichsound!=-1){
6067                                                 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
6068                                                 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
6069                                                 OPENAL_SetVolume(channels[whichsound], 512);
6070                                                 OPENAL_SetPaused(channels[whichsound], false);
6071                                         }
6072                                 }
6073
6074                                 if(targetanimation==staggerbackhighanim)staggerdelay=1;
6075                                 if(targetanimation==staggerbackhardanim)staggerdelay=1;
6076                                 staggerdelay-=multiplier;
6077                                 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
6078                                 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
6079                                 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
6080                                         targetanimation=getIdle();
6081                                         targetframe=0;
6082                                         target=0;
6083                                 }
6084                                 weaponmissdelay-=multiplier;
6085                                 highreversaldelay-=multiplier;
6086                                 lowreversaldelay-=multiplier;
6087                                 lastcollide-=multiplier;
6088                                 skiddelay-=multiplier;
6089                                 if(!isnormal(velocity.x)&&velocity.x){
6090                                         velocity=0;
6091                                 }
6092                                 if(!isnormal(targettilt)&&targettilt){
6093                                         targettilt=0;
6094                                 }
6095                                 if(!isnormal(targettilt2)&&targettilt2){
6096                                         targettilt2=0;
6097                                 }
6098                                 if(!isnormal(targetrotation)&&targetrotation){
6099                                         targetrotation=0;
6100                                 }
6101
6102                                 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
6103                                         //open hands and close mouth
6104                                         //if(targetanimation!=wolfidle){
6105                                         if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
6106                                                 righthandmorphness=0;
6107                                                 righthandmorphend=0;
6108                                                 targetrighthandmorphness=1;
6109                                         }
6110
6111                                         if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
6112                                                 lefthandmorphness=0;
6113                                                 lefthandmorphend=0;
6114                                                 targetlefthandmorphness=1;
6115                                         }
6116                                         //s}
6117
6118                                         if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
6119                                                 headmorphness=0;
6120                                                 headmorphend=0;
6121                                                 targetheadmorphness=1;
6122                                         }
6123                                 }
6124
6125                                 if(targetanimation==rollanim||targetanimation==dodgebackanim||targetanimation==removeknifeanim||targetanimation==knifefightidleanim||targetanimation==swordfightidleanim||targetanimation==blockhighleftstrikeanim||targetanimation==crouchremoveknifeanim||targetanimation==sneakanim||targetanimation==sweepanim||targetanimation==spinkickreversedanim||targetanimation==jumpdownanim||isWallJump()||isFlip()||targetanimation==climbanim||isRun()||targetanimation==getupfrombackanim||targetanimation==getupfromfrontanim){
6126                                         //open hands and mouth
6127                                         if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
6128                                                 righthandmorphness=0;
6129                                                 righthandmorphend=0;
6130                                                 targetrighthandmorphness=1;
6131                                         }
6132
6133                                         if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
6134                                                 lefthandmorphness=0;
6135                                                 lefthandmorphend=0;
6136                                                 targetlefthandmorphness=1;
6137                                         }
6138
6139                                         if(headmorphend!=1&&headmorphness==targetheadmorphness){
6140                                                 headmorphness=0;
6141                                                 headmorphend=1;
6142                                                 targetheadmorphness=1;
6143                                         }
6144                                 }
6145
6146                                 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
6147                                         //close hands and mouth
6148                                         if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
6149                                                 righthandmorphness=0;
6150                                                 righthandmorphend=1;
6151                                                 targetrighthandmorphness=1;
6152                                         }
6153
6154                                         if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
6155                                                 lefthandmorphness=0;
6156                                                 lefthandmorphend=1;
6157                                                 targetlefthandmorphness=1;
6158                                         }
6159
6160                                         if(headmorphend!=0&&headmorphness==targetheadmorphness){
6161                                                 headmorphness=0;
6162                                                 headmorphend=0;
6163                                                 targetheadmorphness=1;
6164                                         }
6165                                 }
6166
6167                                 if(targetanimation==spinkickanim||targetanimation==staffspinhitreversalanim||targetanimation==staffspinhitreversedanim||targetanimation==staffhitreversalanim||targetanimation==staffhitreversedanim||targetanimation==hurtidleanim||targetanimation==winduppunchanim||targetanimation==swordslashreversalanim||targetanimation==swordslashreversedanim||targetanimation==knifeslashreversalanim||targetanimation==knifeslashreversedanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==knifefollowedanim||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==upunchanim||targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim||targetanimation==staffgroundsmashanim||targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==lowkickanim||targetanimation==sweepreversedanim||targetanimation==rabbitkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversalanim||targetanimation==jumpreversedanim){
6168                                         //close hands and yell
6169                                         if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
6170                                                 righthandmorphness=0;
6171                                                 righthandmorphend=1;
6172                                                 targetrighthandmorphness=1;
6173                                         }
6174
6175                                         if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
6176                                                 lefthandmorphness=0;
6177                                                 lefthandmorphend=1;
6178                                                 targetlefthandmorphness=1;
6179                                         }
6180
6181                                         if(headmorphend!=2&&headmorphness==targetheadmorphness){
6182                                                 headmorphness=1;
6183                                                 headmorphend=2;
6184                                                 targetheadmorphness=1;
6185                                         }
6186                                 }
6187                                 /*
6188                                 if(speechdelay>.25){
6189                                 if(headmorphend!=2)headmorphness=0;
6190                                 headmorphend=2;
6191                                 targetheadmorphness=1;
6192                                 }
6193                                 */
6194                                 bool behind;
6195                                 behind=0;
6196                                 if(hasvictim){
6197                                         if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
6198                                                 behind=(normaldotproduct(facing,coords-victim->coords)>0);
6199                                         }
6200                                 }
6201
6202                                 if(!dead&&targetanimation!=hurtidleanim)
6203                                         if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
6204                                                 if(headmorphend!=4||headmorphness==targetheadmorphness){
6205                                                         headmorphend=4;
6206                                                         //headmorphness=1;
6207                                                         targetheadmorphness=1;
6208                                                 }
6209                                         }
6210
6211                                         if(weaponactive!=-1){
6212                                                 if(weapons.type[weaponids[weaponactive]]!=staff){
6213                                                         righthandmorphstart=1;
6214                                                         righthandmorphend=1;
6215                                                 }
6216                                                 if(weapons.type[weaponids[weaponactive]]==staff){
6217                                                         righthandmorphstart=2;
6218                                                         righthandmorphend=2;
6219                                                 }
6220                                                 targetrighthandmorphness=1;
6221                                         }
6222
6223                                         terrainnormal=terrain.getNormal(coords.x,coords.z);
6224
6225                                         if(animation[targetanimation].attack!=reversal){
6226                                                 if(!isnormal(coords.x))
6227                                                         coords=oldcoords;
6228                                                 oldcoords=coords;
6229                                         }
6230
6231                                         flatfacing=0;
6232                                         flatfacing.z=1;
6233
6234                                         flatfacing=DoRotation(flatfacing,0,rotation,0);
6235                                         facing=flatfacing;
6236                                         ReflectVector(&facing,terrainnormal);
6237                                         Normalise(&facing);
6238
6239                                         if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
6240                                                 if(onterrain)targettilt2=-facing.y*20;
6241                                                 else targettilt2=0;
6242                                         }
6243                                         onterrain=0;
6244                                         if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
6245                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6246                                                 flatvelocity=velocity;
6247                                                 flatvelocity.y=0;
6248                                                 flatvelspeed=findLength(&flatvelocity);
6249                                                 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
6250                                                 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
6251                                                 if(velocity.y<0)targettilt2*=-1;
6252                                                 if(velocity.y<0)targettilt*=-1;
6253                                                 if(targettilt>25)targettilt=25;
6254                                                 if(targettilt<-25)targettilt=-25;
6255                                         }
6256
6257                                         if(targettilt2>45)targettilt2=45;
6258                                         if(targettilt2<-45)targettilt2=-45;
6259                                         if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
6260                                         else if(tilt2>targettilt2){
6261                                                 tilt2-=multiplier*400;
6262                                         }
6263                                         else if(tilt2<targettilt2){
6264                                                 tilt2+=multiplier*400;
6265                                         }
6266                                         if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
6267                                                 if(tilt2>25)tilt2=25;
6268                                                 if(tilt2<-25)tilt2=-25;
6269                                         }
6270
6271                                         if(!isnormal(targettilt)&&targettilt){
6272                                                 targettilt=0;
6273                                         }
6274                                         if(!isnormal(targettilt2)&&targettilt2){
6275                                                 targettilt2=0;
6276                                         }
6277
6278                                         //Running velocity
6279                                         //if(!creature==wolftype||targetanimation==rabbitkickanim)
6280                                         if(targetanimation==rabbittackleanim){
6281                                                 velocity+=facing*multiplier*speed*700*scale;
6282                                                 velspeed=findLength(&velocity);
6283                                                 if(velspeed>speed*65*scale){
6284                                                         velocity/=velspeed;
6285                                                         velspeed=speed*65*scale;
6286                                                         velocity*=velspeed;
6287                                                 }
6288                                                 velocity.y+=gravity*multiplier*20;
6289                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6290                                                 velspeed=findLength(&velocity);
6291                                                 velocity=flatfacing*velspeed;
6292                                         }
6293                                         if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
6294                                                 if(isRun()||targetanimation==rabbitkickanim){
6295                                                         velocity+=facing*multiplier*speed*700*scale;
6296                                                         velspeed=findLength(&velocity);
6297                                                         if(velspeed>speed*45*scale){
6298                                                                 velocity/=velspeed;
6299                                                                 velspeed=speed*45*scale;
6300                                                                 velocity*=velspeed;
6301                                                         }
6302                                                         velocity.y+=gravity*multiplier*20;
6303                                                         ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6304                                                         velspeed=findLength(&velocity);
6305                                                         if(velspeed<speed*30*scale)velspeed=speed*30*scale;
6306                                                         velocity=flatfacing*velspeed;
6307                                                 }
6308                                         }
6309                                         else if(isRun()){
6310                                                 velocity+=facing*multiplier*speed*700*scale;
6311                                                 velspeed=findLength(&velocity);
6312                                                 if(creature==rabbittype){
6313                                                         if(velspeed>speed*55*scale){
6314                                                                 velocity/=velspeed;
6315                                                                 velspeed=speed*55*scale;
6316                                                                 velocity*=velspeed;
6317                                                         }
6318                                                 }
6319                                                 if(creature==wolftype){
6320                                                         if(velspeed>speed*75*scale){
6321                                                                 velocity/=velspeed;
6322                                                                 velspeed=speed*75*scale;
6323                                                                 velocity*=velspeed;
6324                                                         }
6325                                                 }
6326                                                 velocity.y+=gravity*multiplier*20;
6327                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6328                                                 velspeed=findLength(&velocity);
6329                                                 velocity=flatfacing*velspeed;
6330                                         }
6331
6332                                         if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
6333                                                 velocity+=facing*multiplier*speed*700*scale;
6334                                                 velspeed=findLength(&velocity);
6335                                                 if(velspeed>speed*45*scale){
6336                                                         velocity/=velspeed;
6337                                                         velspeed=speed*45*scale;
6338                                                         velocity*=velspeed;
6339                                                 }
6340                                                 velocity.y+=gravity*multiplier*20;
6341                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6342                                                 velspeed=findLength(&velocity);
6343                                                 velocity=flatfacing*velspeed;
6344                                         }
6345
6346
6347                                         /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
6348                                         velocity+=facing*multiplier*speed*700*scale;
6349                                         velspeed=findLength(&velocity);
6350                                         if(velspeed>speed*25*scale){
6351                                         velocity/=velspeed;
6352                                         velspeed=speed*25*scale;
6353                                         velocity*=velspeed;
6354                                         }
6355                                         velocity.y+=gravity*multiplier*20;
6356                                         ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6357                                         velspeed=findLength(&velocity);
6358                                         velocity=flatfacing*velspeed;
6359                                         }*/
6360
6361                                         if(targetanimation==sneakanim||targetanimation==walkanim){
6362                                                 velocity+=facing*multiplier*speed*700*scale;
6363                                                 velspeed=findLength(&velocity);
6364                                                 if(velspeed>speed*12*scale){
6365                                                         velocity/=velspeed;
6366                                                         velspeed=speed*12*scale;
6367                                                         velocity*=velspeed;
6368                                                 }
6369                                                 velocity.y+=gravity*multiplier*20;
6370                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6371                                                 velspeed=findLength(&velocity);
6372                                                 velocity=flatfacing*velspeed;
6373                                         }
6374
6375                                         if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
6376                                                 velocity+=facing*multiplier*speed*700*scale;
6377                                                 velspeed=findLength(&velocity);
6378                                                 if(velspeed>speed*2*scale){
6379                                                         velocity/=velspeed;
6380                                                         velspeed=speed*2*scale;
6381                                                         velocity*=velspeed;
6382                                                 }
6383                                                 velocity.y+=gravity*multiplier*20;
6384                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6385                                                 velspeed=findLength(&velocity);
6386                                                 velocity=flatfacing*velspeed;
6387                                         }
6388
6389
6390                                         if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
6391                                                 velocity-=facing*multiplier*speed*700*scale;
6392                                                 velspeed=findLength(&velocity);
6393                                                 if(velspeed>speed*2*scale){
6394                                                         velocity/=velspeed;
6395                                                         velspeed=speed*2*scale;
6396                                                         velocity*=velspeed;
6397                                                 }
6398                                                 velocity.y+=gravity*multiplier*20;
6399                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6400                                                 velspeed=findLength(&velocity);
6401                                                 velocity=flatfacing*velspeed*-1;
6402                                         }
6403
6404                                         if(targetanimation==fightsidestep){
6405                                                 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
6406                                                 velspeed=findLength(&velocity);
6407                                                 if(velspeed>speed*12*scale){
6408                                                         velocity/=velspeed;
6409                                                         velspeed=speed*12*scale;
6410                                                         velocity*=velspeed;
6411                                                 }
6412                                                 velocity.y+=gravity*multiplier*20;
6413                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6414                                                 velspeed=findLength(&velocity);
6415                                                 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
6416                                         }
6417
6418                                         if(targetanimation==staggerbackhighanim){
6419                                                 coords-=facing*multiplier*speed*16*scale;
6420                                                 velocity=0;
6421                                         }
6422                                         if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
6423                                                 coords-=facing*multiplier*speed*20*scale;
6424                                                 velocity=0;
6425                                         }
6426
6427                                         if(targetanimation==backhandspringanim){
6428                                                 //coords-=facing*multiplier*50*scale;
6429                                                 velocity+=facing*multiplier*speed*700*scale*-1;
6430                                                 velspeed=findLength(&velocity);
6431                                                 if(velspeed>speed*50*scale){
6432                                                         velocity/=velspeed;
6433                                                         velspeed=speed*50*scale;
6434                                                         velocity*=velspeed;
6435                                                 }
6436                                                 velocity.y+=gravity*multiplier*20;
6437                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6438                                                 velspeed=findLength(&velocity);
6439                                                 velocity=flatfacing*velspeed*-1;
6440                                         }
6441                                         if(targetanimation==dodgebackanim){
6442                                                 //coords-=facing*multiplier*50*scale;
6443                                                 velocity+=facing*multiplier*speed*700*scale*-1;
6444                                                 velspeed=findLength(&velocity);
6445                                                 if(velspeed>speed*60*scale){
6446                                                         velocity/=velspeed;
6447                                                         velspeed=speed*60*scale;
6448                                                         velocity*=velspeed;
6449                                                 }
6450                                                 velocity.y+=gravity*multiplier*20;
6451                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6452                                                 velspeed=findLength(&velocity);
6453                                                 velocity=flatfacing*velspeed*-1;
6454                                         }
6455
6456                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6457                                                 velspeed=findLength(&velocity);
6458                                         }
6459
6460
6461                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6462                                                 velocity.y+=gravity*multiplier;
6463                                         }
6464
6465                                         if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
6466
6467                                         if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6468                                                 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
6469
6470                                                 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6471                                                 target=0;
6472                                                 targetframe=0;
6473                                                 onterrain=1;
6474
6475                                                 if(id==0){
6476                                                         OPENAL_SetPaused(channels[whooshsound], true);
6477                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6478                                                 }
6479
6480                                                 if(targetanimation==jumpdownanim||isFlip()){
6481                                                         if(isFlip())jumppower=-4;
6482                                                         targetanimation=getLanding();
6483                                                         float gLoc[3];
6484                                                         float vel[3];
6485                                                         gLoc[0]=coords.x;
6486                                                         gLoc[1]=coords.y;
6487                                                         gLoc[2]=coords.z;
6488                                                         vel[0]=velocity.x;
6489                                                         vel[1]=velocity.y;
6490                                                         vel[2]=velocity.z;
6491                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6492                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6493                                                         OPENAL_SetVolume(channels[landsound], 128);
6494                                                         OPENAL_SetPaused(channels[landsound], false);
6495
6496                                                         if(id==0){
6497                                                                 envsound[numenvsounds]=coords;
6498                                                                 envsoundvol[numenvsounds]=16;
6499                                                                 envsoundlife[numenvsounds]=.4;
6500                                                                 numenvsounds++;
6501                                                         }
6502                                                 }
6503                                         }
6504
6505                                         if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
6506                                         if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
6507                                                 coords.y=terrain.getHeight(coords.x,coords.z);
6508                                                 onterrain=1;
6509                                         }
6510
6511
6512                                         if(isIdle()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||isStop()||targetanimation==removeknifeanim||targetanimation==crouchremoveknifeanim||isLanding()||isCrouch()||animation[targetanimation].attack||(targetanimation==rollanim&&animation[targetanimation].label[targetframe]==6)){
6513                                                 velspeed=findLength(&velocity);
6514                                                 velocity.y=0;
6515                                                 if(velspeed<multiplier*300*scale){
6516                                                         velocity=0;
6517                                                 } else velocity-=velocity/velspeed*multiplier*300*scale;
6518                                                 if(velspeed>5&&(isLanding()||isLandhard())){
6519                                                         skiddingdelay+=multiplier;
6520                                                         if(skiddelay<=0){
6521                                                                 FootLand(0,.5);
6522                                                                 FootLand(1,.5);
6523                                                                 skiddelay=.02;
6524                                                         }
6525                                                 }
6526                                                 else skiddingdelay=0;
6527                                         }
6528
6529                                         if(isLandhard()){
6530                                                 velspeed=findLength(&velocity);
6531                                                 velocity.y=0;
6532                                                 if(velspeed<multiplier*600*scale){
6533                                                         velocity=0;
6534                                                 } else velocity-=velocity/velspeed*multiplier*600*scale;
6535                                                 velocity=0;
6536                                                 if(velspeed>5&&(isLanding()||isLandhard())){
6537                                                         skiddingdelay+=multiplier;
6538                                                         if(skiddelay<=0){
6539                                                                 FootLand(0,.5);
6540                                                                 FootLand(1,.5);
6541                                                                 skiddelay=.02;
6542                                                         }
6543                                                 }
6544                                                 else skiddingdelay=0;
6545                                         }
6546
6547                                         if(skiddingdelay<0)skiddingdelay+=multiplier;
6548                                         if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
6549                                                 skiddingdelay=-1;
6550                                                 float gLoc[3];
6551                                                 float vel[3];
6552                                                 gLoc[0]=coords.x;
6553                                                 gLoc[1]=coords.y;
6554                                                 gLoc[2]=coords.z;
6555                                                 vel[0]=velocity.x;
6556                                                 vel[1]=velocity.y;
6557                                                 vel[2]=velocity.z;
6558                                                 if(!onterrain||environment==grassyenvironment){
6559                                                         PlaySoundEx( skidsound, samp[skidsound], NULL, true);
6560                                                         OPENAL_3D_SetAttributes(channels[skidsound], gLoc, vel);
6561                                                         OPENAL_SetVolume(channels[skidsound], 128*velspeed/10);
6562                                                         OPENAL_SetPaused(channels[skidsound], false);
6563                                                 }
6564                                                 else {
6565                                                         PlaySoundEx( snowskidsound, samp[snowskidsound], NULL, true);
6566                                                         OPENAL_3D_SetAttributes(channels[snowskidsound], gLoc, vel);
6567                                                         OPENAL_SetVolume(channels[snowskidsound], 128*velspeed/10);
6568                                                         OPENAL_SetPaused(channels[snowskidsound], false);
6569                                                 }
6570                                         }
6571
6572                                         if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
6573                                                 terrainnormal=victim->coords-coords;
6574                                                 Normalise(&terrainnormal);
6575                                                 targetrotation=-asin(0-terrainnormal.x);
6576                                                 targetrotation*=360/6.28;
6577                                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
6578                                                 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
6579                                         }
6580
6581                                         if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
6582                                                 targetrotation=victim->targetrotation;
6583                                         }
6584                                         if(targetanimation==rabbittacklinganim){
6585                                                 coords=victim->coords;
6586                                         }
6587                         }
6588                         skeleton.oldfree=skeleton.free;
6589
6590                         XYZ midterrain;
6591                         midterrain=0;
6592                         midterrain.x=terrain.size*terrain.scale/2;
6593                         midterrain.z=terrain.size*terrain.scale/2;
6594                         if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
6595                                 XYZ tempposit;
6596                                 tempposit=coords-midterrain;
6597                                 tempposit.y=0;
6598                                 Normalise(&tempposit);
6599                                 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
6600                                 coords.x=tempposit.x+midterrain.x;
6601                                 coords.z=tempposit.z+midterrain.z;
6602                         }
6603 }
6604
6605 int Person::DrawSkeleton(){
6606         int oldplayerdetail;
6607         if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
6608                 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
6609                         calcrot=1;
6610                 }
6611
6612                 if(headless){
6613                         headmorphness=0;
6614                         headmorphstart=6;
6615                         headmorphend=6;
6616                 }
6617
6618                 glAlphaFunc(GL_GREATER, 0.0001);
6619                 XYZ terrainlight;
6620                 float terrainheight;
6621                 float distance;
6622                 if(!isnormal(rotation))rotation=0;
6623                 if(!isnormal(tilt))tilt=0;
6624                 if(!isnormal(tilt2))tilt2=0;
6625                 oldplayerdetail=playerdetail;
6626                 playerdetail=0;
6627                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
6628                         playerdetail=1;
6629                 }
6630                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
6631                         playerdetail=1;
6632                 }
6633                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
6634                         playerdetail=1;
6635                 }
6636                 if(id==0)
6637                         playerdetail=1;
6638                 if(playerdetail!=oldplayerdetail) {
6639                         updatedelay=0;
6640                         normalsupdatedelay=0;
6641                 }
6642                 static float updatedelaychange;
6643                 static float morphness;
6644                 static float framemult;
6645                 if(calcrot){
6646                         skeleton.FindForwards();
6647                         if(howactive==typesittingwall){
6648                                 skeleton.specialforward[1]=0;
6649                                 skeleton.specialforward[1].z=1;
6650                         }
6651                 }
6652                 static XYZ mid;
6653                 static float M[16];
6654                 static int i,j,k;
6655                 static int weaponattachmuscle;
6656                 static int weaponrotatemuscle,weaponrotatemuscle2;
6657                 static XYZ weaponpoint;
6658                 static int start,endthing;
6659                 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
6660                         if(!isSleeping()&&!isSitting()){
6661                                 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6662                                         XYZ point,newpoint,change,change2;
6663                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6664                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6665                                         point.y=heightleft;
6666                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6667                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6668                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6669                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6670                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6671
6672                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6673                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6674                                         point.y=heightright;
6675                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6676                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6677                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6678                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6679                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6680                                         skeleton.DoConstraints(&coords,&scale);
6681
6682                                         if(creature==wolftype){
6683                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6684                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6685                                                 point.y=heightleft;
6686                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6687                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6688                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6689                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6690                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6691
6692                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6693                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6694                                                 point.y=heightright;
6695                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6696                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6697                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6698                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6699                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6700                                                 skeleton.DoConstraints(&coords,&scale);
6701                                         }
6702                                 }
6703                                 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6704                                         XYZ point,newpoint,change,change2;
6705                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6706                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6707                                         point.y=heightleft;
6708                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6709                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6710                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
6711                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6712                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6713
6714                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6715                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6716                                         point.y=heightright;
6717                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6718                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6719                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
6720                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6721                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6722                                         skeleton.DoConstraints(&coords,&scale);
6723
6724                                         if(creature==wolftype){
6725                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6726                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6727                                                 point.y=heightleft;
6728                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6729                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6730                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
6731                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6732                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6733
6734                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6735                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6736                                                 point.y=heightright;
6737                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6738                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6739                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
6740                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6741                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6742                                                 skeleton.DoConstraints(&coords,&scale);
6743                                         }
6744                                 }
6745
6746                                 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6747                                         XYZ point,newpoint,change,change2;
6748                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6749                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6750                                         point.y=heightleft;
6751                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6752                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6753                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
6754                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6755                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6756
6757                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6758                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6759                                         point.y=heightright;
6760                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6761                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6762                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
6763                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6764                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6765                                         skeleton.DoConstraints(&coords,&scale);
6766
6767                                         if(creature==wolftype){
6768                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6769                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6770                                                 point.y=heightleft;
6771                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6772                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6773                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
6774                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6775                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6776
6777                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6778                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6779                                                 point.y=heightright;
6780                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6781                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6782                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
6783                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6784                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6785                                                 skeleton.DoConstraints(&coords,&scale);
6786                                         }
6787                                 }
6788                         }
6789                         if(!skeleton.free&&(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&((targetanimation!=rollanim&&!isFlip())||animation[targetanimation].label[targetframe]==6)&&targetanimation!=getupfromfrontanim&&targetanimation!=wolfrunninganim&&targetanimation!=rabbitrunninganim&&targetanimation!=backhandspringanim&&targetanimation!=walljumpfrontanim&&targetanimation!=hurtidleanim&&!isLandhard()&&!isSleeping()))
6790                                 DoHead();
6791                         else {
6792                                 targetheadrotation=-targetrotation;
6793                                 targetheadrotation2=0;
6794                                 if(animation[targetanimation].attack==3)targetheadrotation+=180;
6795                         }
6796                         for(i=0;i<skeleton.drawmodel.vertexNum;i++){
6797                                 skeleton.drawmodel.vertex[i]=0;
6798                                 skeleton.drawmodel.vertex[i].y=999;
6799                         }
6800                         for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
6801                                 skeleton.drawmodellow.vertex[i]=0;
6802                                 skeleton.drawmodellow.vertex[i].y=999;
6803                         }
6804                         for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
6805                                 skeleton.drawmodelclothes.vertex[i]=0;
6806                                 skeleton.drawmodelclothes.vertex[i].y=999;
6807                         }
6808                         for(i=0;i<skeleton.num_muscles;i++){
6809                                 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
6810                                         morphness=0;
6811                                         start=0;
6812                                         endthing=0;
6813                                         if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
6814                                                 morphness=righthandmorphness;
6815                                                 start=righthandmorphstart;
6816                                                 endthing=righthandmorphend;
6817                                         }
6818                                         if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
6819                                                 morphness=lefthandmorphness;
6820                                                 start=lefthandmorphstart;
6821                                                 endthing=lefthandmorphend;
6822                                         }
6823                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
6824                                                 morphness=headmorphness;
6825                                                 start=headmorphstart;
6826                                                 endthing=headmorphend;
6827                                         }
6828                                         if((skeleton.muscles[i].parent1->label==neck&&skeleton.muscles[i].parent2->label==abdomen)||(skeleton.muscles[i].parent2->label==neck&&skeleton.muscles[i].parent1->label==abdomen)){
6829                                                 morphness=chestmorphness;
6830                                                 start=chestmorphstart;
6831                                                 endthing=chestmorphend;
6832                                         }
6833                                         if((skeleton.muscles[i].parent1->label==groin&&skeleton.muscles[i].parent2->label==abdomen)||(skeleton.muscles[i].parent2->label==groin&&skeleton.muscles[i].parent1->label==abdomen)){
6834                                                 morphness=tailmorphness;
6835                                                 start=tailmorphstart;
6836                                                 endthing=tailmorphend;
6837                                         }
6838                                         if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
6839                                         mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
6840                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6841                                         glPushMatrix();
6842                                                 glLoadIdentity();
6843                                                 if(!skeleton.free)glRotatef(tilt2,1,0,0);
6844                                                 if(!skeleton.free)glRotatef(tilt,0,0,1);
6845
6846
6847                                                 glTranslatef(mid.x,mid.y,mid.z);
6848
6849                                                 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
6850                                                 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
6851
6852                                                 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
6853                                                 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
6854
6855                                                 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
6856                                                 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
6857                                                 /*
6858                                                 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
6859                                                 proportionbody=1;
6860                                                 proportionweird=1;
6861                                                 }
6862                                                 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
6863                                                 proportionarms=1;
6864                                                 proportionweird=1;
6865                                                 }
6866                                                 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
6867                                                 proportionhead=1;
6868                                                 proportionweird=1;
6869                                                 }
6870                                                 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
6871                                                 proportionlegs=1;
6872                                                 proportionweird=1;
6873                                                 }*/
6874
6875                                                 if(playerdetail||skeleton.free==3)
6876                                                 {
6877                                                         for(j=0;j<skeleton.muscles[i].numvertices;j++)
6878                                                         {
6879                                                                 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
6880                                                                 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
6881                                                                 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
6882                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
6883                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
6884                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
6885                                                                 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
6886                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6887                                                                 glPushMatrix();
6888                                                                         if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6889                                                                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x*morphness)*proportionbody.x,
6890                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y*morphness)*proportionbody.y,
6891                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z*morphness)*proportionbody.z);
6892                                                                         if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent1->label==leftwrist||skeleton.muscles[i].parent1->label==rightwrist||skeleton.muscles[i].parent1->label==leftelbow||skeleton.muscles[i].parent1->label==rightelbow||skeleton.muscles[i].parent2->label==leftelbow||skeleton.muscles[i].parent2->label==rightelbow)
6893                                                                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x*morphness)*proportionarms.x,
6894                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y*morphness)*proportionarms.y,
6895                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z*morphness)*proportionarms.z);
6896                                                                         if(skeleton.muscles[i].parent1->label==leftfoot||skeleton.muscles[i].parent1->label==rightfoot||skeleton.muscles[i].parent1->label==leftankle||skeleton.muscles[i].parent1->label==rightankle||skeleton.muscles[i].parent1->label==leftknee||skeleton.muscles[i].parent1->label==rightknee||skeleton.muscles[i].parent2->label==leftknee||skeleton.muscles[i].parent2->label==rightknee)
6897                                                                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x*morphness)*proportionlegs.x,
6898                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y*morphness)*proportionlegs.y,
6899                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z*morphness)*proportionlegs.z);
6900                                                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6901                                                                                 glTranslatef((skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x*morphness)*proportionhead.x,
6902                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y*morphness)*proportionhead.y,
6903                                                                                 (skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z*(1-morphness)+skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z*morphness)*proportionhead.z);
6904                                                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
6905                                                                         //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6906                                                                         //if(isnormal(M[12])&&isnormal(M[13])&&isnormal(M[14])){
6907                                                                         //if(!isnormal(scale))test=1;
6908                                                                         //if(isnormal(scale)){
6909                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
6910                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
6911                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
6912                                                                         //test=2;
6913                                                                         //}
6914                                                                         //}
6915                                                                 glPopMatrix();
6916                                                                 //}
6917                                                         }
6918                                                 }
6919                                                 if(!playerdetail||skeleton.free==3)
6920                                                 {
6921                                                         for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
6922                                                         {
6923                                                                 //if(skeleton.muscles[i].verticeslow[j]<skeleton.modellow.vertexNum&&skeleton.muscles[i].verticeslow[j]>=0){
6924                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6925                                                                 glPushMatrix();
6926                                                                         if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6927                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
6928                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
6929                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
6930                                                                         if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent1->label==leftwrist||skeleton.muscles[i].parent1->label==rightwrist||skeleton.muscles[i].parent1->label==leftelbow||skeleton.muscles[i].parent1->label==rightelbow||skeleton.muscles[i].parent2->label==leftelbow||skeleton.muscles[i].parent2->label==rightelbow)
6931                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
6932                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
6933                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
6934                                                                         if(skeleton.muscles[i].parent1->label==leftfoot||skeleton.muscles[i].parent1->label==rightfoot||skeleton.muscles[i].parent1->label==leftankle||skeleton.muscles[i].parent1->label==rightankle||skeleton.muscles[i].parent1->label==leftknee||skeleton.muscles[i].parent1->label==rightknee||skeleton.muscles[i].parent2->label==leftknee||skeleton.muscles[i].parent2->label==rightknee)
6935                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
6936                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
6937                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
6938                                                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6939                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
6940                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
6941                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
6942
6943                                                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
6944                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
6945                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
6946                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
6947                                                                 glPopMatrix();
6948                                                                 //}
6949                                                         }
6950                                                 }
6951                                         glPopMatrix();
6952                                 }
6953                                 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
6954                                         mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
6955
6956                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6957                                         glPushMatrix();
6958                                                 glLoadIdentity();
6959                                                 if(!skeleton.free)glRotatef(tilt2,1,0,0);
6960                                                 if(!skeleton.free)glRotatef(tilt,0,0,1);
6961                                                 glTranslatef(mid.x,mid.y,mid.z);
6962                                                 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
6963                                                 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
6964
6965                                                 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
6966                                                 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
6967
6968                                                 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
6969                                                 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
6970
6971                                                 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
6972                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6973                                                         glPushMatrix();
6974                                                                 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6975                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
6976                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
6977                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
6978                                                                 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent1->label==leftwrist||skeleton.muscles[i].parent1->label==rightwrist||skeleton.muscles[i].parent1->label==leftelbow||skeleton.muscles[i].parent1->label==rightelbow||skeleton.muscles[i].parent2->label==leftelbow||skeleton.muscles[i].parent2->label==rightelbow)
6979                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
6980                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
6981                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
6982                                                                 if(skeleton.muscles[i].parent1->label==leftfoot||skeleton.muscles[i].parent1->label==rightfoot||skeleton.muscles[i].parent1->label==leftankle||skeleton.muscles[i].parent1->label==rightankle||skeleton.muscles[i].parent1->label==leftknee||skeleton.muscles[i].parent1->label==rightknee||skeleton.muscles[i].parent2->label==leftknee||skeleton.muscles[i].parent2->label==rightknee)
6983                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
6984                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
6985                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
6986                                                                 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6987                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
6988                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
6989                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
6990                                                                 glGetFloatv(GL_MODELVIEW_MATRIX,M);
6991                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
6992                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
6993                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
6994                                                         glPopMatrix();
6995                                                 }
6996                                         glPopMatrix();
6997                                 }
6998                                 updatedelay=1+(float)(Random()%100)/1000;
6999                         }
7000                         if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
7001                                 normalsupdatedelay=1;
7002                                 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
7003                                 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
7004                                 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
7005                         }
7006                         else
7007                         {
7008                                 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
7009                                 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
7010                                 if(skeleton.clothes){
7011                                         skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
7012                                 }
7013                         }
7014                 }
7015                 framemult=.01;
7016                 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
7017                 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
7018                 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
7019                 if(skeleton.free==1)updatedelaychange*=6;
7020                 if(id==0)updatedelaychange*=8;
7021                 updatedelay+=updatedelaychange;
7022
7023                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
7024                 glPushMatrix();
7025                 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
7026                 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
7027                 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
7028                 if(!skeleton.free)glRotatef(rotation,0,1,0);
7029                 if(showpoints){
7030                         glPointSize(5);
7031                         glColor4f(.4,1,.4,1);
7032                         glDisable(GL_LIGHTING);
7033                         glDisable(GL_TEXTURE_2D);
7034                         glBegin(GL_POINTS);
7035                         if(playerdetail)
7036                                 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
7037                                         glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
7038                                 }
7039                                 glEnd();
7040                                 glBegin(GL_LINES);
7041
7042                                 if(playerdetail)
7043                                         for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
7044                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
7045                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
7046                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[1]].z);
7047                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
7048                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[2]].z);
7049                                                 glVertex3f(skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].x,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].y,skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[i].vertex[0]].z);
7050                                         }
7051
7052                                 glEnd();
7053                 }
7054
7055                 terrainlight=terrain.getLighting(coords.x,coords.z);
7056                 distance=findDistancefast(&viewer,&coords);
7057                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
7058                 if(distance>1)distance=1;
7059                 if(distance>0){
7060                         terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
7061                         if(terrainheight<1)terrainheight=1;
7062                         if(terrainheight>1.7)terrainheight=1.7;
7063
7064                         //burnt=0;
7065                         glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
7066                         glDisable(GL_BLEND);
7067                         glAlphaFunc(GL_GREATER, 0.0001);
7068                         glEnable(GL_TEXTURE_2D);
7069                         if(cellophane){
7070                                 glDisable(GL_TEXTURE_2D);
7071                                 glColor4f(.7,.35,0,.5);
7072                                 glDepthMask(0);
7073                                 glEnable(GL_LIGHTING);
7074                                 glEnable(GL_BLEND);
7075                         }
7076                         if(tutoriallevel&&id!=0){
7077                                 //glDisable(GL_TEXTURE_2D);
7078                                 glColor4f(.7,.7,.7,0.6);
7079                                 glDepthMask(0);
7080                                 glEnable(GL_LIGHTING);
7081                                 glEnable(GL_BLEND);
7082                                 if(canattack&&cananger)
7083                                         if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
7084                                                 glDisable(GL_TEXTURE_2D);
7085                                                 glColor4f(1,0,0,0.8);
7086                                         }
7087                                         glMatrixMode(GL_TEXTURE);
7088                                         glPushMatrix();
7089                                         glTranslatef(0,-smoketex,0);
7090                                         glTranslatef(-smoketex,0,0);
7091                         }
7092                         if(playerdetail){
7093                                 if(!showpoints){
7094                                         if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
7095                                         else skeleton.drawmodel.draw();
7096                                 }
7097                         }
7098                         if(!playerdetail){
7099                                 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
7100                                 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
7101                         }
7102
7103                         if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
7104                                 if(tutoriallevel&&id!=0){
7105                                         glPopMatrix();
7106                                         glMatrixMode(GL_MODELVIEW);
7107                                         glEnable(GL_TEXTURE_2D);
7108                                         glColor4f(.7,.7,.7,0.6);
7109                                         glDepthMask(0);
7110                                         glEnable(GL_LIGHTING);
7111                                         glEnable(GL_BLEND);
7112                                         if(canattack&&cananger)
7113                                                 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
7114                                                         glDisable(GL_TEXTURE_2D);
7115                                                         glColor4f(1,0,0,0.8);
7116                                                 }
7117                                                 glMatrixMode(GL_TEXTURE);
7118                                                 glPushMatrix();
7119                                                 glTranslatef(0,-smoketex*.6,0);
7120                                                 glTranslatef(smoketex*.6,0,0);
7121                                                 if(playerdetail){
7122                                                         if(!showpoints){
7123                                                                 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
7124                                                                 else skeleton.drawmodel.draw();
7125                                                         }
7126                                                 }
7127                                                 if(!playerdetail){
7128                                                         if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
7129                                                         else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
7130                                                 }
7131                                 }
7132
7133
7134                                 if(tutoriallevel&&id!=0){
7135                                         glPopMatrix();
7136                                         glMatrixMode(GL_MODELVIEW);
7137                                         glEnable(GL_TEXTURE_2D);
7138                                 }
7139                                 if(skeleton.clothes){
7140                                         glDepthMask(0);
7141                                         glEnable(GL_BLEND);
7142                                         if(!immediate)skeleton.drawmodelclothes.draw();
7143                                         if(immediate)skeleton.drawmodelclothes.drawimmediate();
7144                                         glDepthMask(1);
7145                                 }
7146                 }
7147                 glPopMatrix();
7148
7149                 if(num_weapons>0){
7150                         for(k=0;k<num_weapons;k++){
7151                                 i=weaponids[k];
7152                                 if(weaponactive==k){
7153                                         if(weapons.type[i]!=staff){
7154                                                 for(j=0;j<skeleton.num_muscles;j++){
7155                                                         if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
7156                                                                 weaponattachmuscle=j;
7157                                                         }
7158                                                 }
7159                                                 for(j=0;j<skeleton.num_muscles;j++){
7160                                                         if((skeleton.muscles[j].parent1->label==rightwrist||skeleton.muscles[j].parent2->label==rightwrist)&&(skeleton.muscles[j].parent1->label!=righthand&&skeleton.muscles[j].parent2->label!=righthand)&&skeleton.muscles[j].numvertices>0){
7161                                                                 weaponrotatemuscle=j;
7162                                                         }
7163                                                 }
7164                                                 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
7165                                                 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
7166                                         }
7167                                         if(weapons.type[i]==staff){
7168                                                 for(j=0;j<skeleton.num_muscles;j++){
7169                                                         if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
7170                                                                 weaponattachmuscle=j;
7171                                                         }
7172                                                 }
7173                                                 for(j=0;j<skeleton.num_muscles;j++){
7174                                                         if((skeleton.muscles[j].parent1->label==rightelbow||skeleton.muscles[j].parent2->label==rightelbow)&&(skeleton.muscles[j].parent1->label!=rightshoulder&&skeleton.muscles[j].parent2->label!=rightshoulder)&&skeleton.muscles[j].numvertices>0){
7175                                                                 weaponrotatemuscle=j;
7176                                                         }
7177                                                 }
7178                                                 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
7179                                                 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
7180                                                 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
7181                                                 XYZ tempnormthing,vec1,vec2;
7182                                                 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
7183                                                 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
7184                                                 CrossProduct(&vec1,&vec2,&tempnormthing);
7185                                                 Normalise(&tempnormthing);
7186                                                 if(targetanimation!=staffhitanim&&currentanimation!=staffhitanim&&targetanimation!=staffgroundsmashanim&&currentanimation!=staffgroundsmashanim&&targetanimation!=staffspinhitanim&&currentanimation!=staffspinhitanim)weaponpoint+=tempnormthing*.1-skeleton.specialforward[1]*.3+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
7187                                                 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
7188                                                 XYZ weaptargnorm;
7189                                                 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
7190                                                 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7191                                                 Normalise(&weaptargnorm);
7192                                                 weaponpoint-=weaptargnorm*2;
7193                                                 }*/
7194                                         }
7195                                 }
7196                                 if(weaponactive!=k&&weaponstuck!=k){
7197                                         if(weapons.type[i]==knife)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[righthip]].position-skeleton.joints[skeleton.jointlabels[lefthip]].position)*.1+(skeleton.joints[skeleton.jointlabels[rightshoulder]].position-skeleton.joints[skeleton.jointlabels[leftshoulder]].position)*.35;
7198                                         if(weapons.type[i]==sword)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[lefthip]].position-skeleton.joints[skeleton.jointlabels[righthip]].position)*.09+(skeleton.joints[skeleton.jointlabels[leftshoulder]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position)*.33;
7199                                         if(weapons.type[i]==staff)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[lefthip]].position-skeleton.joints[skeleton.jointlabels[righthip]].position)*.09+(skeleton.joints[skeleton.jointlabels[leftshoulder]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position)*.33;
7200                                         for(j=0;j<skeleton.num_muscles;j++){
7201                                                 if((skeleton.muscles[j].parent1->label==abdomen||skeleton.muscles[j].parent2->label==abdomen)&&(skeleton.muscles[j].parent1->label==neck||skeleton.muscles[j].parent2->label==neck)&&skeleton.muscles[j].numvertices>0){
7202                                                         weaponrotatemuscle=j;
7203                                                 }
7204                                         }
7205                                 }
7206                                 if(weaponstuck==k){
7207                                         if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
7208                                         else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
7209                                         for(j=0;j<skeleton.num_muscles;j++){
7210                                                 if((skeleton.muscles[j].parent1->label==abdomen||skeleton.muscles[j].parent2->label==abdomen)&&(skeleton.muscles[j].parent1->label==neck||skeleton.muscles[j].parent2->label==neck)&&skeleton.muscles[j].numvertices>0){
7211                                                         weaponrotatemuscle=j;
7212                                                 }
7213                                         }
7214                                 }
7215                                 if(!skeleton.free){
7216                                         weapons.position[i]=DoRotation(DoRotation(DoRotation(weaponpoint,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords+currentoffset*(1-target)*scale+targetoffset*target*scale;
7217                                         weapons.bigrotation[i]=rotation;
7218                                         weapons.bigtilt[i]=tilt;
7219                                         weapons.bigtilt2[i]=tilt2;
7220                                 }
7221                                 if(skeleton.free){
7222                                         weapons.position[i]=weaponpoint*scale+coords;
7223                                         weapons.bigrotation[i]=0;
7224                                         weapons.bigtilt[i]=0;
7225                                         weapons.bigtilt2[i]=0;
7226                                 }
7227                                 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
7228                                 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
7229                                 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
7230                                 if(weaponactive==k){
7231                                         if(weapons.type[i]==knife){
7232                                                 weapons.smallrotation[i]=180;
7233                                                 weapons.smallrotation2[i]=0;
7234                                                 if(isCrouch()||wasCrouch()){
7235                                                         weapons.smallrotation2[i]=20;
7236                                                 }
7237                                                 if(targetanimation==hurtidleanim){
7238                                                         weapons.smallrotation2[i]=50;
7239                                                 }
7240                                                 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
7241                                                         XYZ temppoint1,temppoint2,tempforward;
7242                                                         float distance;
7243
7244                                                         temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
7245                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7246                                                         distance=findDistance(&temppoint1,&temppoint2);
7247                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7248                                                         weapons.rotation2[i]*=360/6.28;
7249                                                         temppoint1.y=0;
7250                                                         temppoint2.y=0;
7251                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7252                                                         weapons.rotation1[i]*=360/6.28;
7253                                                         weapons.rotation3[i]=0;
7254                                                         weapons.smallrotation[i]=-90;
7255                                                         weapons.smallrotation2[i]=0;
7256                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7257                                                 }
7258                                                 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
7259                                                         XYZ temppoint1,temppoint2,tempforward;
7260                                                         float distance;
7261
7262                                                         temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
7263                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7264                                                         distance=findDistance(&temppoint1,&temppoint2);
7265                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7266                                                         weapons.rotation2[i]*=360/6.28;
7267                                                         temppoint1.y=0;
7268                                                         temppoint2.y=0;
7269                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7270                                                         weapons.rotation1[i]*=360/6.28;
7271                                                         weapons.rotation3[i]=0;
7272                                                         weapons.smallrotation[i]=90;
7273                                                         weapons.smallrotation2[i]=0;
7274                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7275                                                 }
7276                                                 if(targetanimation==knifethrowanim){
7277                                                         weapons.smallrotation[i]=90;
7278                                                         //weapons.smallrotation2[i]=-90;
7279                                                         weapons.smallrotation2[i]=0;
7280                                                         weapons.rotation1[i]=0;
7281                                                         weapons.rotation2[i]=0;
7282                                                         weapons.rotation3[i]=0;
7283                                                 }
7284                                                 if(targetanimation==knifesneakattackanim&&targetframe<5){
7285                                                         weapons.smallrotation[i]=-90;
7286                                                         weapons.rotation1[i]=0;
7287                                                         weapons.rotation2[i]=0;
7288                                                         weapons.rotation3[i]=0;
7289                                                 }
7290                                         }
7291                                         if(weapons.type[i]==sword){
7292                                                 weapons.smallrotation[i]=0;
7293                                                 weapons.smallrotation2[i]=0;
7294                                                 if(targetanimation==knifethrowanim){
7295                                                         weapons.smallrotation[i]=-90;
7296                                                         weapons.smallrotation2[i]=0;
7297                                                         weapons.rotation1[i]=0;
7298                                                         weapons.rotation2[i]=0;
7299                                                         weapons.rotation3[i]=0;
7300                                                 }
7301                                                 if((targetanimation==swordgroundstabanim&&currentanimation==swordgroundstabanim)||(targetanimation==swordsneakattackanim&&currentanimation==swordsneakattackanim)||(targetanimation==swordslashparryanim&&currentanimation==swordslashparryanim)||(targetanimation==swordslashparriedanim&&currentanimation==swordslashparriedanim)||(targetanimation==swordslashreversalanim&&currentanimation==swordslashreversalanim)||(targetanimation==swordslashreversedanim&&currentanimation==swordslashreversedanim)||(targetanimation==knifeslashreversalanim&&currentanimation==knifeslashreversalanim)||(targetanimation==knifeslashreversedanim&&currentanimation==knifeslashreversedanim)||(targetanimation==swordslashanim&&currentanimation==swordslashanim)||(targetanimation==drawleftanim&&currentanimation==drawleftanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
7302                                                         XYZ temppoint1,temppoint2,tempforward;
7303                                                         float distance;
7304
7305                                                         temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
7306                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7307                                                         distance=findDistance(&temppoint1,&temppoint2);
7308                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7309                                                         weapons.rotation2[i]*=360/6.28;
7310                                                         temppoint1.y=0;
7311                                                         temppoint2.y=0;
7312                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7313                                                         weapons.rotation1[i]*=360/6.28;
7314                                                         weapons.rotation3[i]=0;
7315                                                         weapons.smallrotation[i]=90;
7316                                                         weapons.smallrotation2[i]=0;
7317                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7318                                                 }
7319                                         }
7320                                         if(weapons.type[i]==staff){
7321                                                 weapons.smallrotation[i]=100;
7322                                                 weapons.smallrotation2[i]=0;
7323                                                 if((targetanimation==staffhitanim&&currentanimation==staffhitanim)||(targetanimation==staffhitreversedanim&&currentanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&&currentanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&&currentanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&&currentanimation==staffspinhitanim)){
7324                                                         XYZ temppoint1,temppoint2,tempforward;
7325                                                         float distance;
7326
7327                                                         temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
7328                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7329                                                         distance=findDistance(&temppoint1,&temppoint2);
7330                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7331                                                         weapons.rotation2[i]*=360/6.28;
7332                                                         temppoint1.y=0;
7333                                                         temppoint2.y=0;
7334                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7335                                                         weapons.rotation1[i]*=360/6.28;
7336                                                         weapons.rotation3[i]=0;
7337                                                         weapons.smallrotation[i]=90;
7338                                                         weapons.smallrotation2[i]=0;
7339                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7340                                                 }
7341                                         }
7342                                 }
7343                                 if(weaponactive!=k&&weaponstuck!=k){
7344                                         if(weapons.type[i]==knife){
7345                                                 weapons.smallrotation[i]=-70;
7346                                                 weapons.smallrotation2[i]=10;
7347                                         }
7348                                         if(weapons.type[i]==sword){
7349                                                 weapons.smallrotation[i]=-100;
7350                                                 weapons.smallrotation2[i]=-8;
7351                                         }
7352                                         if(weapons.type[i]==staff){
7353                                                 weapons.smallrotation[i]=-100;
7354                                                 weapons.smallrotation2[i]=-8;
7355                                         }
7356                                 }
7357                                 if(weaponstuck==k){
7358                                         if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
7359                                         else weapons.smallrotation[i]=0;
7360                                         weapons.smallrotation2[i]=10;
7361                                         //if(animation[targetanimation].height==lowheight&&animation[targetanimation].attack==neutral){
7362                                         //}
7363                                 }
7364                         }
7365                 }
7366         }
7367
7368         calcrot=0;
7369         if(skeleton.free)calcrot=1;
7370         if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
7371         if(currentanimation!=targetanimation)calcrot=1;
7372         //if(id==0)calcrot=1;
7373         if(skeleton.free==2)calcrot=0;
7374
7375         return 0;
7376 }
7377
7378
7379 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
7380 {
7381         static int i,j;
7382         static float distance;
7383         static float olddistance;
7384         static int intersecting;
7385         static int firstintersecting;
7386         static XYZ point;
7387         static XYZ oldp1;
7388         static XYZ start,end;
7389         static float slopethreshold=-.4;
7390
7391         firstintersecting=-1;
7392
7393         oldp1=*p1;
7394         *p1=*p1-*move;
7395         if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
7396         if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
7397         for(i=0;i<4;i++){
7398                 for (j=0;j<model->TriangleNum;j++){
7399                         if(model->facenormals[j].y<=slopethreshold){
7400                                 intersecting=0;
7401                                 distance=abs((model->facenormals[j].x*p1->x)+(model->facenormals[j].y*p1->y)+(model->facenormals[j].z*p1->z)-((model->facenormals[j].x*model->vertex[model->Triangles[j].vertex[0]].x)+(model->facenormals[j].y*model->vertex[model->Triangles[j].vertex[0]].y)+(model->facenormals[j].z*model->vertex[model->Triangles[j].vertex[0]].z)));
7402                                 if(distance<radius){
7403                                         point=*p1-model->facenormals[j]*distance;
7404                                         if(PointInTriangle( &point, model->facenormals[j], &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))intersecting=1;
7405                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7406                                                 &model->vertex[model->Triangles[j].vertex[1]],
7407                                                 p1, &radius);
7408                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
7409                                                 &model->vertex[model->Triangles[j].vertex[2]],
7410                                                 p1, &radius);
7411                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7412                                                 &model->vertex[model->Triangles[j].vertex[2]],
7413                                                 p1, &radius);
7414                                         end=*p1-point;
7415                                         if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
7416                                                 start=*p1;
7417                                                 end=*p1;
7418                                                 end.y-=radius;
7419                                                 if(LineFacetd(&start,&end,&model->vertex[model->Triangles[j].vertex[0]],&model->vertex[model->Triangles[j].vertex[1]],&model->vertex[model->Triangles[j].vertex[2]],&model->facenormals[j],&point)){
7420                                                         p1->y=point.y+radius;
7421                                                         if((targetanimation==jumpdownanim||isFlip())){
7422                                                                 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
7423
7424                                                                 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
7425                                                                 target=0;
7426                                                                 targetframe=0;
7427                                                                 onterrain=1;
7428
7429                                                                 if(id==0){
7430                                                                         OPENAL_SetPaused(channels[whooshsound], true);
7431                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
7432                                                                 }
7433
7434                                                                 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
7435                                                                         if(isFlip())jumppower=-4;
7436                                                                         targetanimation=getLanding();
7437                                                                         float gLoc[3];
7438                                                                         float vel[3];
7439                                                                         gLoc[0]=coords.x;
7440                                                                         gLoc[1]=coords.y;
7441                                                                         gLoc[2]=coords.z;
7442                                                                         vel[0]=velocity.x;
7443                                                                         vel[1]=velocity.y;
7444                                                                         vel[2]=velocity.z;
7445                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
7446                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
7447                                                                         OPENAL_SetVolume(channels[landsound], 128);
7448                                                                         OPENAL_SetPaused(channels[landsound], false);
7449
7450                                                                         if(id==0){
7451                                                                                 envsound[numenvsounds]=coords;
7452                                                                                 envsoundvol[numenvsounds]=16;
7453                                                                                 envsoundlife[numenvsounds]=.4;
7454                                                                                 numenvsounds++;
7455                                                                         }
7456                                                                 }
7457                                                         }
7458                                                 }
7459                                         }
7460                                 }
7461                                 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
7462                         }
7463                 }
7464                 for (j=0;j<model->TriangleNum;j++){
7465                         if(model->facenormals[j].y>slopethreshold){
7466                                 intersecting=0;
7467                                 start=*p1;
7468                                 start.y-=radius/4;
7469                                 distance=abs((model->facenormals[j].x*start.x)+(model->facenormals[j].y*start.y)+(model->facenormals[j].z*start.z)-((model->facenormals[j].x*model->vertex[model->Triangles[j].vertex[0]].x)+(model->facenormals[j].y*model->vertex[model->Triangles[j].vertex[0]].y)+(model->facenormals[j].z*model->vertex[model->Triangles[j].vertex[0]].z)));
7470                                 if(distance<radius*.5){
7471                                         point=start-model->facenormals[j]*distance;
7472                                         if(PointInTriangle( &point, model->facenormals[j], &model->vertex[model->Triangles[j].vertex[0]], &model->vertex[model->Triangles[j].vertex[1]], &model->vertex[model->Triangles[j].vertex[2]]))intersecting=1;
7473                                         if(!intersecting)intersecting=sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x,model->vertex[model->Triangles[j].vertex[0]].y,model->vertex[model->Triangles[j].vertex[0]].z,
7474                                                 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
7475                                                 p1->x, p1->y, p1->z, radius/2);
7476                                         if(!intersecting)intersecting=sphere_line_intersection(model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
7477                                                 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
7478                                                 p1->x, p1->y, p1->z, radius/2);
7479                                         if(!intersecting)intersecting=sphere_line_intersection(model->vertex[model->Triangles[j].vertex[0]].x,model->vertex[model->Triangles[j].vertex[0]].y,model->vertex[model->Triangles[j].vertex[0]].z,
7480                                                 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
7481                                                 p1->x, p1->y, p1->z, radius/2);
7482                                         end=*p1-point;
7483                                         if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
7484                                                 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
7485                                                         start=velocity;
7486                                                         velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
7487                                                         if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
7488                                                 }
7489                                                 *p1+=model->facenormals[j]*(distance-radius*.5);
7490                                         }
7491                                 }
7492                                 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
7493                         }
7494                 }
7495         }
7496         if(*rotate)*p=DoRotation(*p,0,*rotate,0);
7497         *p=*p+*move;
7498         if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
7499         *p1+=*move;
7500         return firstintersecting;
7501 }
7502
7503 Person::Person()
7504 {
7505         whichpatchx = 0;
7506         whichpatchz = 0;
7507
7508         currentframe = 0;
7509         targetframe = 0;
7510         currentanimation = 0;
7511         targetanimation = 0;
7512         oldcurrentframe = 0;
7513         oldtargetframe = 0;
7514         oldcurrentanimation = 0;
7515         oldtargetanimation = 0;
7516
7517         howactive = 0;
7518
7519         parriedrecently = 0;
7520
7521         superruntoggle = 0;
7522
7523         lastattack = 0,lastattack2 = 0,lastattack3 = 0;
7524
7525         currentoffset = 0,targetoffset = 0,offset = 0;
7526         target = 0;
7527         transspeed = 0;
7528
7529         realoldcoords = 0;
7530         oldcoords = 0;
7531         coords = 0;
7532         originalcoords = 0;
7533         velocity = 0;
7534
7535         proportionhead = 0;
7536         proportionlegs = 0;
7537         proportionarms = 0;
7538         proportionbody = 0;
7539
7540         heightleft = 0;
7541         heightright = 0;
7542
7543         unconscioustime = 0;
7544
7545         immobile = 0;
7546
7547         velspeed = 0;
7548         targetrotation = 0;
7549         targetrot = 0;
7550         rot = 0;
7551         oldrot = 0;
7552         lookrotation = 0;
7553         lookrotation2 = 0;
7554         rotation = 0;
7555         rotation2 = 0;
7556         lowrotation = 0;
7557         tilt = 0;
7558         targettilt = 0;
7559         tilt2 = 0;
7560         targettilt2 = 0;
7561         rabbitkickenabled = 0;
7562
7563         bloodloss = 0;
7564         bleeddelay = 0;
7565         skiddelay = 0;
7566         skiddingdelay = 0;
7567         deathbleeding = 0;
7568         tempdeltav = 0;
7569
7570         damagetolerance = 0;
7571         damage = 0;
7572         permanentdamage = 0;
7573         superpermanentdamage = 0;       lastcollide = 0;
7574         dead = 0;
7575
7576         jumppower = 0;
7577         onground = 0;
7578         madskills = 0;
7579
7580         wentforweapon = 0;
7581
7582         calcrot = 0;
7583
7584         backwardsanim = 0;
7585
7586         facing = 0;
7587
7588         bleeding = 0;
7589         bleedx = 0,bleedy;
7590         direction = 0;
7591         texupdatedelay = 0;
7592
7593         headrotation = 0,headrotation2 = 0;
7594         targetheadrotation = 0,targetheadrotation2 = 0;
7595
7596         onterrain = 0;
7597         pause = 0;
7598
7599         grabdelay = 0;
7600
7601         victim = 0;
7602         hasvictim = 0;
7603
7604         updatedelay = 0;
7605         normalsupdatedelay = 0;
7606
7607         jumpstart = 0;
7608
7609         forwardkeydown = 0;
7610         forwardstogglekeydown = 0;
7611         rightkeydown = 0;
7612         leftkeydown = 0;
7613         backkeydown = 0;
7614         jumpkeydown = 0;
7615         jumptogglekeydown = 0;
7616         crouchkeydown = 0;
7617         crouchtogglekeydown = 0;
7618         drawkeydown = 0;
7619         drawtogglekeydown = 0;
7620         throwkeydown = 0;
7621         throwtogglekeydown = 0;
7622         attackkeydown = 0;
7623         feint = 0;
7624         lastfeint = 0;
7625         headless = 0;
7626
7627         crouchkeydowntime = 0;
7628         jumpkeydowntime = 0;
7629         freefall = 0;
7630
7631
7632         turnspeed = 0;
7633
7634         aitype = 0;
7635         aitarget = 0;
7636         aiupdatedelay = 0;
7637         losupdatedelay = 0;
7638         ally = 0;
7639         movetarget = 0;
7640         collide = 0;
7641         collided = 0;
7642         avoidcollided = 0;
7643         loaded = 0;
7644         whichdirection = 0;
7645         whichdirectiondelay = 0;
7646         avoidsomething = 0;     avoidwhere = 0;
7647         blooddimamount = 0;
7648
7649         staggerdelay = 0;
7650         blinkdelay = 0;
7651         twitchdelay = 0;
7652         twitchdelay2 = 0;
7653         twitchdelay3 = 0;
7654         lefthandmorphness = 0;
7655         righthandmorphness = 0;
7656         headmorphness = 0;
7657         chestmorphness = 0;
7658         tailmorphness = 0;
7659         targetlefthandmorphness = 0;
7660         targetrighthandmorphness = 0;
7661         targetheadmorphness = 0;
7662         targetchestmorphness = 0;
7663         targettailmorphness = 0;
7664         lefthandmorphstart = 0,lefthandmorphend = 0;
7665         righthandmorphstart = 0,righthandmorphend = 0;
7666         headmorphstart = 0,headmorphend = 0;
7667         chestmorphstart = 0,chestmorphend = 0;
7668         tailmorphstart = 0,tailmorphend = 0;
7669
7670         weaponmissdelay = 0;
7671         highreversaldelay = 0;
7672         lowreversaldelay = 0;
7673         nocollidedelay = 0;
7674
7675         creature = 0;
7676
7677         id = 0;
7678
7679         //Skeleton skeleton;
7680
7681         speed = 0;
7682         scale = 0;
7683         power = 0;
7684         speedmult = 0;
7685
7686         protectionhead = 0;
7687         protectionhigh = 0;
7688         protectionlow = 0;
7689         armorhead = 0;
7690         armorhigh = 0;
7691         armorlow = 0;
7692         metalhead = 0;
7693         metalhigh = 0;
7694         metallow = 0;
7695
7696         numclothes = 0;
7697
7698         memset(clothes, 0, sizeof(clothes));
7699         memset(clothestintr, 0, sizeof(clothestintr));
7700         memset(clothestintg, 0, sizeof(clothestintg));
7701         memset(clothestintb, 0, sizeof(clothestintb));
7702
7703         landhard = 0;
7704         bled = 0;
7705         spurt = 0;
7706         onfire = 0;
7707         onfiredelay = 0;        burnt = 0;
7708         fireduration = 0;
7709
7710         flamedelay = 0;
7711         updatestuffdelay = 0;
7712
7713         playerdetail = 0;
7714
7715         num_weapons = 0;
7716
7717         memset(weaponids, 0, sizeof(weaponids));
7718
7719         weaponactive = 0;
7720         weaponstuck = 0;
7721         weaponstuckwhere = 0;
7722         weaponwhere = 0;
7723
7724         numwaypoints = 0;
7725
7726         memset(waypoints, 0, sizeof(waypoints));
7727         memset(waypointtype, 0, sizeof(waypointtype));
7728
7729         pausetime = 0;
7730         hastempwaypoint = 0;
7731         tempwaypoint = 0;
7732
7733         headtarget = 0;
7734         interestdelay = 0;
7735
7736         finalfinaltarget = 0;
7737         finaltarget = 0;
7738         finalpathfindpoint = 0;
7739         targetpathfindpoint = 0;
7740         lastpathfindpoint = 0;
7741         lastpathfindpoint2 = 0;
7742         lastpathfindpoint3 = 0;
7743         lastpathfindpoint4 = 0;
7744         onpath = 0;
7745
7746         waypoint = 0;
7747         jumppath = 0;
7748
7749         lastseen = 0;
7750         lastseentime = 0;
7751         lastchecktime = 0;
7752         stunned = 0;
7753         surprised = 0;
7754         runninghowlong = 0;     lastoccluded = 0;
7755         laststanding = 0;
7756         escapednum = 0;
7757
7758         speechdelay = 0;
7759         neckspurtdelay = 0;
7760         neckspurtparticledelay = 0;
7761         neckspurtamount = 0;
7762
7763         whichskin = 0;
7764         rabbitkickragdoll = 0;
7765
7766         averageloc = 0;
7767         oldaverageloc = 0;
7768
7769         //Animation tempanimation;
7770
7771         occluded = 0;
7772
7773         jumpclimb = 0;
7774 }
7775
7776 Person::~Person()
7777 {
7778 }
7779