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