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