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