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