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