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