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