]> git.jsancho.org Git - lugaru.git/blob - Source/Person.cpp
A tiny cleanup
[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                                                     victim->aitype == gethelptype ? 50 : 0);
1824                                 }
1825                         }
1826
1827                         if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&&currentanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1828                                 if(weapons.type[weaponids[0]]==knife){
1829                                         if(weaponactive==-1)weaponactive=0;
1830                                         else if(weaponactive==0)weaponactive=-1;
1831
1832                                         if(weaponactive==-1){
1833                                                 float gLoc[3];
1834                                                 float vel[3];
1835                                                 gLoc[0]=coords.x;
1836                                                 gLoc[1]=coords.y;
1837                                                 gLoc[2]=coords.z;
1838                                                 vel[0]=velocity.x;
1839                                                 vel[1]=velocity.y;
1840                                                 vel[2]=velocity.z;
1841
1842                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
1843                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
1844                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
1845                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
1846                                         }
1847                                         if(weaponactive!=-1){
1848                                                 float gLoc[3];
1849                                                 float vel[3];
1850                                                 gLoc[0]=coords.x;
1851                                                 gLoc[1]=coords.y;
1852                                                 gLoc[2]=coords.z;
1853                                                 vel[0]=velocity.x;
1854                                                 vel[1]=velocity.y;
1855                                                 vel[2]=velocity.z;
1856
1857                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
1858                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
1859                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
1860                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
1861                                         }
1862                                 }
1863                                 drawtogglekeydown=1;
1864                         }
1865                         //Footstep sounds
1866                         if(tutoriallevel!=1||id==0)
1867                                 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1868                                         int whichsound;
1869                                         float gLoc[3];
1870                                         float vel[3];
1871                                         gLoc[0]=coords.x;
1872                                         gLoc[1]=coords.y;
1873                                         gLoc[2]=coords.z;
1874                                         vel[0]=velocity.x;
1875                                         vel[1]=velocity.y;
1876                                         vel[2]=velocity.z;
1877                                         if(onterrain){
1878                                                 if(terrain.getOpacity(coords.x,coords.z)<.2){
1879                                                         if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1880                                                         else whichsound=footstepsound2;
1881                                                         if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1882                                                         if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1883                                                         if(animation[targetanimation].label[targetframe]==3&&isRun()){
1884                                                                 FootLand(1,1);
1885                                                                 FootLand(0,1);
1886                                                         }
1887
1888                                                 }
1889                                                 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1890                                                         if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1891                                                         else whichsound=footstepsound4;
1892                                                 }
1893                                         }
1894                                         if(!onterrain){
1895                                                 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1896                                                 else whichsound=footstepsound4;
1897                                         }
1898                                         if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1899                                                 if(animation[targetanimation].attack!=neutral){
1900                                                         i=abs(Random()%3);
1901                                                         if(i==0)whichsound=lowwhooshsound;
1902                                                         if(i==1)whichsound=midwhooshsound;
1903                                                         if(i==2)whichsound=highwhooshsound;
1904                                                 }
1905                                                 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1906                                         }
1907                                         else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1908                                         if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1909
1910                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1911                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1912                                         if(whichsound!=knifeswishsound)OPENAL_SetVolume(channels[whichsound], 128);
1913                                         if(whichsound!=knifeswishsound&&(targetanimation==staffhitanim||targetanimation==staffgroundsmashanim||targetanimation==staffspinhitanim))OPENAL_SetVolume(channels[whichsound], 256);
1914                                         if(whichsound==knifeswishsound)OPENAL_SetVolume(channels[whichsound], 512);
1915                                         OPENAL_SetPaused(channels[whichsound], false);
1916
1917                                         if(id==0)
1918                                                 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1919                                                         envsound[numenvsounds]=coords;
1920                                                         if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1921                                                         else envsoundvol[numenvsounds]=6;
1922                                                         envsoundlife[numenvsounds]=.4;
1923                                                         numenvsounds++;
1924                                                 }
1925
1926                                                 if(animation[targetanimation].label[targetframe]==3){
1927                                                         whichsound--;
1928                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1929                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1930                                                         OPENAL_SetVolume(channels[whichsound], 128);
1931                                                         OPENAL_SetPaused(channels[whichsound], false);
1932                                                 }
1933                                 }
1934
1935                                 //Combat sounds
1936                                 if(tutoriallevel!=1||id==0)
1937                                         if(speechdelay<=0)
1938                                                 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1939                                                         if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1940                                                                 int whichsound=-1;
1941                                                                 float gLoc[3];
1942                                                                 float vel[3];
1943                                                                 gLoc[0]=coords.x;
1944                                                                 gLoc[1]=coords.y;
1945                                                                 gLoc[2]=coords.z;
1946                                                                 vel[0]=velocity.x;
1947                                                                 vel[1]=velocity.y;
1948                                                                 vel[2]=velocity.z;
1949                                                                 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1950                                                                         if(animation[targetanimation].attack!=neutral){
1951                                                                                 i=abs(Random()%4);
1952                                                                                 if(creature==rabbittype){
1953                                                                                         if(i==0)whichsound=rabbitattacksound;
1954                                                                                         if(i==1)whichsound=rabbitattack2sound;
1955                                                                                         if(i==2)whichsound=rabbitattack3sound;
1956                                                                                         if(i==3)whichsound=rabbitattack4sound;
1957                                                                                 }
1958                                                                                 if(creature==wolftype){
1959                                                                                         if(i==0)whichsound=barksound;
1960                                                                                         if(i==1)whichsound=bark2sound;
1961                                                                                         if(i==2)whichsound=bark3sound;
1962                                                                                         if(i==3)whichsound=barkgrowlsound;
1963                                                                                 }
1964                                                                                 speechdelay=.3;
1965                                                                         }
1966                                                                         //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1967                                                                 }
1968                                                                 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1969                                                                 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1970
1971                                                                 if(whichsound!=-1){
1972                                                                         PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1973                                                                         OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1974                                                                         OPENAL_SetVolume(channels[whichsound], 512);
1975                                                                         OPENAL_SetPaused(channels[whichsound], false);
1976                                                                 }
1977                                                         }
1978
1979
1980
1981                                                         if((!wasLanding()&&!wasLandhard())&&currentanimation!=getIdle()&&(isLanding()||isLandhard())){
1982                                                                 FootLand(0,1);
1983                                                                 FootLand(1,1);
1984                                                         }
1985
1986                                                         transspeed=0;
1987                                                         currentoffset=targetoffset;
1988                                                         targetframe=currentframe;
1989                                                         currentanimation=targetanimation;
1990                                                         targetframe++;
1991
1992                                                         if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1993                                                                 for(i=0;i<weapons.numweapons;i++){
1994                                                                         if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1995                                                                                 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1996                                                                                         if(findDistancefast(&coords,&weapons.position[i])>=1){
1997                                                                                                 if(weapons.type[i]!=staff){
1998                                                                                                         float gLoc[3];
1999                                                                                                         float vel[3];
2000                                                                                                         gLoc[0]=coords.x;
2001                                                                                                         gLoc[1]=coords.y;
2002                                                                                                         gLoc[2]=coords.z;
2003                                                                                                         vel[0]=velocity.x;
2004                                                                                                         vel[1]=velocity.y;
2005                                                                                                         vel[2]=velocity.z;
2006                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2007                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2008                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2009                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2010                                                                                                 }
2011
2012                                                                                                 weaponactive=0;
2013                                                                                                 weapons.owner[i]=id;
2014                                                                                                 if(num_weapons>0){
2015                                                                                                         weaponids[num_weapons]=weaponids[0];
2016                                                                                                 }
2017                                                                                                 num_weapons++;
2018                                                                                                 weaponids[0]=i;
2019                                                                                         }
2020                                                                                 }
2021                                                                 }
2022                                                         }
2023
2024                                                         static bool willwork;
2025                                                         if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
2026                                                                 for(i=0;i<weapons.numweapons;i++){
2027                                                                         bool willwork=1;
2028                                                                         if(weapons.owner[i]!=-1)
2029                                                                                 if(player[weapons.owner[i]].weaponstuck!=-1)
2030                                                                                         if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
2031                                                                                                 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
2032                                                                         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))
2033                                                                                 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
2034                                                                                         if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
2035                                                                                                 float gLoc[3];
2036                                                                                                 float vel[3];
2037                                                                                                 gLoc[0]=coords.x;
2038                                                                                                 gLoc[1]=coords.y;
2039                                                                                                 gLoc[2]=coords.z;
2040                                                                                                 vel[0]=velocity.x;
2041                                                                                                 vel[1]=velocity.y;
2042                                                                                                 vel[2]=velocity.z;
2043                                                                                                 bool fleshstuck=0;
2044                                                                                                 if(weapons.owner[i]!=-1)
2045                                                                                                         if(victim->weaponstuck!=-1){
2046                                                                                                                 if(victim->weaponids[victim->weaponstuck]==i){
2047                                                                                                                         fleshstuck=1;
2048                                                                                                                 }
2049                                                                                                         }
2050                                                                                                         if(!fleshstuck){
2051                                                                                                                 if(weapons.type[i]!=staff){
2052                                                                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2053                                                                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2054                                                                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2055                                                                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2056                                                                                                                 }
2057                                                                                                         }
2058                                                                                                         if(fleshstuck){
2059                                                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
2060                                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
2061                                                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
2062                                                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
2063                                                                                                         }
2064                                                                                                         weaponactive=0;
2065                                                                                                         if(weapons.owner[i]!=-1){
2066
2067                                                                                                                 victim=&player[weapons.owner[i]];
2068                                                                                                                 if(victim->num_weapons==1)victim->num_weapons=0;
2069                                                                                                                 else victim->num_weapons=1;
2070
2071                                                                                                                 //victim->weaponactive=-1;
2072                                                                                                                 victim->skeleton.longdead=0;
2073                                                                                                                 victim->skeleton.free=1;
2074                                                                                                                 victim->skeleton.broken=0;
2075
2076                                                                                                                 for(int j=0;j<victim->skeleton.num_joints;j++){
2077                                                                                                                         victim->skeleton.joints[j].velchange=0;
2078                                                                                                                         victim->skeleton.joints[j].locked=0;
2079                                                                                                                 }
2080
2081                                                                                                                 XYZ relative;
2082                                                                                                                 relative=0;
2083                                                                                                                 relative.y=10;
2084                                                                                                                 Normalise(&relative);
2085                                                                                                                 XYZ footvel,footpoint;
2086                                                                                                                 footvel=0;
2087                                                                                                                 footpoint=weapons.position[i];
2088                                                                                                                 if(victim->weaponstuck!=-1){
2089                                                                                                                         if(victim->weaponids[victim->weaponstuck]==i){
2090                                                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2091                                                                                                                                 weapons.bloody[i]=2;
2092                                                                                                                                 weapons.blooddrip[i]=5;
2093                                                                                                                                 victim->weaponstuck=-1;
2094                                                                                                                         }
2095                                                                                                                 }
2096                                                                                                                 if(victim->num_weapons>0){
2097                                                                                                                         if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
2098                                                                                                                         if(victim->weaponids[0]==i)
2099                                                                                                                                 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
2100                                                                                                                 }
2101
2102                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
2103                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
2104                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
2105                                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
2106                                                                                                         }
2107                                                                                                         weapons.owner[i]=id;
2108                                                                                                         if(num_weapons>0){
2109                                                                                                                 weaponids[num_weapons]=weaponids[0];
2110                                                                                                         }
2111                                                                                                         num_weapons++;
2112                                                                                                         weaponids[0]=i;
2113                                                                                         }
2114                                                                                 }
2115                                                                 }
2116                                                         }
2117
2118                                                         if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
2119                                                                 if(weaponactive==-1)weaponactive=0;
2120                                                                 else if(weaponactive==0){
2121                                                                         weaponactive=-1;
2122                                                                         if(num_weapons==2){
2123                                                                                 int buffer;
2124                                                                                 buffer=weaponids[0];
2125                                                                                 weaponids[0]=weaponids[1];
2126                                                                                 weaponids[1]=buffer;
2127                                                                         }
2128                                                                 }
2129                                                                 if(weaponactive==-1){
2130                                                                         float gLoc[3];
2131                                                                         float vel[3];
2132                                                                         gLoc[0]=coords.x;
2133                                                                         gLoc[1]=coords.y;
2134                                                                         gLoc[2]=coords.z;
2135                                                                         vel[0]=velocity.x;
2136                                                                         vel[1]=velocity.y;
2137                                                                         vel[2]=velocity.z;
2138
2139                                                                         PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2140                                                                         OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2141                                                                         OPENAL_SetVolume(channels[knifesheathesound], 128);
2142                                                                         OPENAL_SetPaused(channels[knifesheathesound], false);
2143                                                                 }
2144                                                                 if(weaponactive!=-1){
2145                                                                         float gLoc[3];
2146                                                                         float vel[3];
2147                                                                         gLoc[0]=coords.x;
2148                                                                         gLoc[1]=coords.y;
2149                                                                         gLoc[2]=coords.z;
2150                                                                         vel[0]=velocity.x;
2151                                                                         vel[1]=velocity.y;
2152                                                                         vel[2]=velocity.z;
2153
2154                                                                         PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2155                                                                         OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2156                                                                         OPENAL_SetVolume(channels[knifedrawsound], 128);
2157                                                                         OPENAL_SetPaused(channels[knifedrawsound], false);
2158                                                                 }
2159                                                         }
2160
2161
2162                                                         if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
2163                                                                 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
2164                                                                 Normalise(&rotatetarget);
2165                                                                 targetrotation=-asin(0-rotatetarget.x);
2166                                                                 targetrotation*=360/6.28;
2167                                                                 if(rotatetarget.z<0)targetrotation=180-targetrotation;
2168
2169                                                                 if(targetanimation==walljumprightkickanim)targetrotation+=40;
2170                                                                 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
2171                                                         }
2172
2173                                                         bool dojumpattack;
2174                                                         dojumpattack=0;
2175                                                         if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
2176                                                         if(hasvictim)
2177                         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;
2178                                                         if(dojumpattack){
2179                                                                 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
2180                                                                         targetanimation=rabbittackleanim;
2181                                                                         targetframe=0;
2182                                                                         float gLoc[3];
2183                                                                         float vel[3];
2184                                                                         gLoc[0]=coords.x;
2185                                                                         gLoc[1]=coords.y;
2186                                                                         gLoc[2]=coords.z;
2187                                                                         vel[0]=velocity.x;
2188                                                                         vel[1]=velocity.y;
2189                                                                         vel[2]=velocity.z;
2190
2191                                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
2192                                                                         OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
2193                                                                         OPENAL_SetVolume(channels[jumpsound], 128);
2194                                                                         OPENAL_SetPaused(channels[jumpsound], false);
2195                                                                 }
2196
2197                                                                 float closestdist;
2198                                                                 closestdist=0;
2199                                                                 int closestid;
2200                                                                 closestid=-1;
2201                                                                 XYZ targetloc;
2202                                                                 targetloc=velocity;
2203                                                                 Normalise(&targetloc);
2204                                                                 targetloc+=coords;
2205                                                                 for(i=0;i<numplayers;i++){
2206                                                                         if(i!=id)
2207                                                                                 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
2208                                                                                         closestdist=findDistancefast(&targetloc,&player[i].coords);
2209                                                                                         closestid=i;
2210                                                                                 }
2211                                                                 }
2212                                                                 if(closestid!=-1)
2213                                                                         if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
2214                                                                                 hasvictim=1;
2215                                                                                 victim=&player[closestid];
2216                                                                                 coords=victim->coords;
2217                                                                                 currentanimation=rabbittacklinganim;
2218                                                                                 targetanimation=rabbittacklinganim;
2219                                                                                 currentframe=0;
2220                                                                                 targetframe=1;
2221                                                                                 XYZ rotatetarget;
2222                                                                                 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
2223                                                                                         rotatetarget=coords-victim->coords;
2224                                                                                         Normalise(&rotatetarget);
2225                                                                                         targetrotation=-asin(0-rotatetarget.x);
2226                                                                                         targetrotation*=360/6.28;
2227                                                                                         if(rotatetarget.z<0)targetrotation=180-targetrotation;
2228                                                                                 }
2229                                                                                 if(targetanimation!=rabbitrunninganim){
2230                                                                                         float gLoc[3];
2231                                                                                         float vel[3];
2232                                                                                         gLoc[0]=coords.x;
2233                                                                                         gLoc[1]=coords.y;
2234                                                                                         gLoc[2]=coords.z;
2235                                                                                         vel[0]=velocity.x;
2236                                                                                         vel[1]=velocity.y;
2237                                                                                         vel[2]=velocity.z;
2238
2239                                                                                         PlaySoundEx( jumpsound, samp[jumpsound], NULL, true);
2240                                                                                         OPENAL_3D_SetAttributes(channels[jumpsound], gLoc, vel);
2241                                                                                         OPENAL_SetVolume(channels[jumpsound], 128);
2242                                                                                         OPENAL_SetPaused(channels[jumpsound], false);
2243                                                                                 }
2244                                                                         }
2245                                                         }
2246
2247                                                         //Move impacts
2248                                                         float damagemult=1*power;
2249                                                         if(creature==wolftype)damagemult=2.5*power;
2250                                                         if(hasvictim){damagemult/=victim->damagetolerance/200;}
2251                                                         //if(onfire)damagemult=3;
2252                                                         if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
2253                                                                 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
2254                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2255                                                                                 escapednum=0;
2256                                                                                 if(id==0)camerashake+=.4;
2257                                                                                 if(Random()%2||creature==wolftype){
2258                                                                                         victim->spurt=1;
2259                                                                                         DoBlood(.2,250);
2260                                                                                         if(creature==wolftype)DoBloodBig(0,250);
2261                                                                                 }
2262                                                                                 float gLoc[3];
2263                                                                                 float vel[3];
2264                                                                                 gLoc[0]=victim->coords.x;
2265                                                                                 gLoc[1]=victim->coords.y;
2266                                                                                 gLoc[2]=victim->coords.z;
2267                                                                                 vel[0]=velocity.x;
2268                                                                                 vel[1]=velocity.y;
2269                                                                                 vel[2]=velocity.z;
2270                                                                                 if(tutoriallevel!=1){
2271                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2272                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2273                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
2274                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2275                                                                                 }
2276                                                                                 if(creature==wolftype){
2277                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2278                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2279                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2280                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2281                                                                                         victim->spurt=1;
2282                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2283                                                                                 }
2284                                                                                 victim->RagDoll(0);
2285                                                                                 XYZ relative;
2286                                                                                 relative=victim->coords-coords;
2287                                                                                 relative.y=0;
2288                                                                                 Normalise(&relative);
2289                                                                                 relative=DoRotation(relative,0,-90,0);
2290                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2291                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2292                                                                                 }
2293                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2294                                                                                 //FootLand(1,2);
2295                                                                                 victim->Puff(head);
2296                                                                                 victim->DoDamage(damagemult*100/victim->protectionhead);
2297
2298                                                                                 if(id==0){
2299                                                                                         SolidHitBonus();
2300                                                                                 }
2301                                                                         }
2302                                                                 }
2303
2304                                                                 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
2305                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2306                                                                                 escapednum=0;
2307                                                                                 if(id==0)camerashake+=.4;
2308                                                                                 if(Random()%2||creature==wolftype){
2309                                                                                         victim->spurt=1;
2310                                                                                         if(creature==wolftype)DoBloodBig(0,235);
2311                                                                                 }
2312                                                                                 float gLoc[3];
2313                                                                                 float vel[3];
2314                                                                                 gLoc[0]=victim->coords.x;
2315                                                                                 gLoc[1]=victim->coords.y;
2316                                                                                 gLoc[2]=victim->coords.z;
2317                                                                                 vel[0]=velocity.x;
2318                                                                                 vel[1]=velocity.y;
2319                                                                                 vel[2]=velocity.z;
2320                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2321                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2322                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2323                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2324                                                                                 if(creature==wolftype){
2325                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2326                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2327                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2328                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2329                                                                                         victim->spurt=1;
2330                                                                                         victim->DoBloodBig(2,175);
2331                                                                                 }
2332                                                                                 victim->RagDoll(0);
2333                                                                                 XYZ relative;
2334                                                                                 relative=victim->coords-coords;
2335                                                                                 relative.y=0;
2336                                                                                 Normalise(&relative);
2337                                                                                 relative.y-=1;
2338                                                                                 Normalise(&relative);
2339                                                                                 relative=DoRotation(relative,0,90,0);
2340                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2341                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2342                                                                                 }
2343                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2344                                                                                 //FootLand(1,2);
2345                                                                                 victim->Puff(head);
2346                                                                                 victim->DoDamage(damagemult*50/victim->protectionhead);
2347                                                                         }
2348                                                                 }
2349
2350                                                                 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
2351                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2352                                                                                 escapednum=0;
2353                                                                                 if(id==0)camerashake+=.4;
2354                                                                                 victim->spurt=1;
2355                                                                                 DoBlood(.2,250);
2356                                                                                 float gLoc[3];
2357                                                                                 float vel[3];
2358                                                                                 gLoc[0]=victim->coords.x;
2359                                                                                 gLoc[1]=victim->coords.y;
2360                                                                                 gLoc[2]=victim->coords.z;
2361                                                                                 vel[0]=velocity.x;
2362                                                                                 vel[1]=velocity.y;
2363                                                                                 vel[2]=velocity.z;
2364                                                                                 if(tutoriallevel!=1){
2365                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2366                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2367                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 160);
2368                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2369                                                                                 }
2370                                                                                 if(creature==wolftype){
2371                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2372                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2373                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2374                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2375                                                                                         victim->spurt=1;
2376                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2377                                                                                 }
2378                                                                                 victim->RagDoll(0);
2379                                                                                 XYZ relative;
2380                                                                                 relative=facing;
2381                                                                                 relative.y=0;
2382                                                                                 Normalise(&relative);
2383                                                                                 relative=DoRotation(relative,0,-90,0);
2384                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2385                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2386                                                                                 }
2387                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2388                                                                                 //FootLand(1,2);
2389                                                                                 victim->Puff(head);
2390                                                                                 victim->DoDamage(damagemult*150/victim->protectionhead);
2391
2392                                                                                 if(victim->damage>victim->damagetolerance){
2393                                                                                   award_bonus(id, style);
2394                                                                                 }
2395                                                                                 else if(id==0){
2396                                                                                         SolidHitBonus();
2397                                                                                 }
2398                                                                         }
2399                                                                 }
2400
2401                                                                 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2402                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2403                                                                                 escapednum=0;
2404                                                                                 if(id==0)camerashake+=.4;
2405                                                                                 victim->spurt=1;
2406                                                                                 DoBlood(.2,250);
2407                                                                                 float gLoc[3];
2408                                                                                 float vel[3];
2409                                                                                 gLoc[0]=victim->coords.x;
2410                                                                                 gLoc[1]=victim->coords.y;
2411                                                                                 gLoc[2]=victim->coords.z;
2412                                                                                 vel[0]=velocity.x;
2413                                                                                 vel[1]=velocity.y;
2414                                                                                 vel[2]=velocity.z;
2415                                                                                 if(tutoriallevel!=1){
2416                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2417                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2418                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 160);
2419                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2420                                                                                 }
2421                                                                                 if(creature==wolftype){
2422                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
2423                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
2424                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
2425                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
2426                                                                                         victim->spurt=1;
2427                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
2428                                                                                 }
2429                                                                                 victim->RagDoll(0);
2430                                                                                 XYZ relative;
2431                                                                                 relative=facing;
2432                                                                                 relative.y=0;
2433                                                                                 Normalise(&relative);
2434                                                                                 relative=DoRotation(relative,0,90,0);
2435                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2436                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2437                                                                                 }
2438                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2439                                                                                 //FootLand(1,2);
2440                                                                                 victim->Puff(head);
2441                                                                                 victim->DoDamage(damagemult*150/victim->protectionhead);
2442
2443                                                                                 if(victim->damage>victim->damagetolerance){
2444                                                                                   award_bonus(id, style);
2445                                                                                 }
2446                                                                                 else if(id==0){
2447                                                                                         SolidHitBonus();
2448                                                                                 }
2449                                                                         }
2450                                                                 }
2451
2452                                                                 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2453                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2454                                                                                 escapednum=0;
2455                                                                                 if(id==0)camerashake+=.4;
2456                                                                                 if(Random()%2){
2457                                                                                         victim->spurt=1;
2458                                                                                         DoBlood(.2,235);
2459                                                                                 }
2460                                                                                 float gLoc[3];
2461                                                                                 float vel[3];
2462                                                                                 gLoc[0]=victim->coords.x;
2463                                                                                 gLoc[1]=victim->coords.y;
2464                                                                                 gLoc[2]=victim->coords.z;
2465                                                                                 vel[0]=velocity.x;
2466                                                                                 vel[1]=velocity.y;
2467                                                                                 vel[2]=velocity.z;
2468                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2469                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2470                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2471                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2472                                                                                 victim->RagDoll(0);
2473                                                                                 XYZ relative;
2474                                                                                 relative=victim->coords-coords;
2475                                                                                 relative.y=0;
2476                                                                                 Normalise(&relative);
2477                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2478                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2479                                                                                 }
2480                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2481                                                                                 //FootLand(1,2);
2482                                                                                 victim->Puff(head);
2483                                                                                 victim->DoDamage(damagemult*50/victim->protectionhead);
2484                                                                         }
2485                                                                 }
2486
2487                                                                 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2488                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2489                                                                                 escapednum=0;
2490                                                                                 if(id==0)camerashake+=.2;
2491                                                                                 float gLoc[3];
2492                                                                                 float vel[3];
2493                                                                                 gLoc[0]=victim->coords.x;
2494                                                                                 gLoc[1]=victim->coords.y;
2495                                                                                 gLoc[2]=victim->coords.z;
2496                                                                                 vel[0]=velocity.x;
2497                                                                                 vel[1]=velocity.y;
2498                                                                                 vel[2]=velocity.z;
2499                                                                                 /*PlaySoundEx( landsound2, samp[landsound2], NULL, true);
2500                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
2501                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
2502                                                                                 OPENAL_SetPaused(channels[landsound2], false);
2503                                                                                 */
2504                                                                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
2505                                                                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
2506                                                                                 OPENAL_SetVolume(channels[movewhooshsound], 128);
2507                                                                                 OPENAL_SetPaused(channels[movewhooshsound], false);
2508
2509                                                                                 victim->skeleton.longdead=0;
2510                                                                                 victim->skeleton.free=1;
2511                                                                                 victim->skeleton.broken=0;
2512                                                                                 victim->skeleton.spinny=1;
2513
2514                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2515                                                                                         victim->skeleton.joints[i].velchange=0;
2516                                                                                         victim->skeleton.joints[i].delay=0;
2517                                                                                         victim->skeleton.joints[i].locked=0;
2518                                                                                         //victim->skeleton.joints[i].velocity=0;
2519                                                                                 }
2520
2521                                                                                 XYZ relative;
2522                                                                                 relative=0;
2523                                                                                 relative.y=1;
2524                                                                                 Normalise(&relative);
2525                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2526                                                                                         victim->skeleton.joints[i].velocity.y=relative.y*10;
2527                                                                                         victim->skeleton.joints[i].position.y+=relative.y*.3;
2528                                                                                         victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2529                                                                                         victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2530                                                                                 }
2531                                                                                 victim->Puff(abdomen);
2532                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2533                                                                         }
2534                                                                 }
2535
2536                                                                 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2537                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2538                                                                                 escapednum=0;
2539                                                                                 if(id==0)camerashake+=.4;
2540                                                                                 float gLoc[3];
2541                                                                                 float vel[3];
2542                                                                                 gLoc[0]=coords.x;
2543                                                                                 gLoc[1]=coords.y;
2544                                                                                 gLoc[2]=coords.z;
2545                                                                                 vel[0]=velocity.x;
2546                                                                                 vel[1]=velocity.y;
2547                                                                                 vel[2]=velocity.z;
2548                                                                                 if(tutoriallevel!=1){
2549                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2550                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2551                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
2552                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
2553                                                                                 }
2554                                                                                 XYZ relative;
2555                                                                                 relative=victim->coords-coords;
2556                                                                                 relative.y=0;
2557                                                                                 Normalise(&relative);
2558                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2559                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2560                                                                                 }
2561                                                                                 victim->Puff(abdomen);
2562                                                                                 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2563                                                                                         slomo=1;
2564                                                                                         slomodelay=.2;
2565                                                                                 }
2566                                                                                 victim->DoDamage(damagemult*500/victim->protectionhigh);
2567                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2568                                                                         }
2569                                                                 }
2570
2571                                                                 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2572                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2573                                                                                 escapednum=0;
2574                                                                                 if(id==0)camerashake+=.4;
2575                                                                                 float gLoc[3];
2576                                                                                 float vel[3];
2577                                                                                 gLoc[0]=coords.x;
2578                                                                                 gLoc[1]=coords.y;
2579                                                                                 gLoc[2]=coords.z;
2580                                                                                 vel[0]=velocity.x;
2581                                                                                 vel[1]=velocity.y;
2582                                                                                 vel[2]=velocity.z;
2583                                                                                 if(tutoriallevel!=1){
2584                                                                                         PlaySoundEx( thudsound, samp[thudsound], NULL, true);
2585                                                                                         OPENAL_3D_SetAttributes(channels[thudsound], gLoc, vel);
2586                                                                                         OPENAL_SetVolume(channels[thudsound], 400);
2587                                                                                         OPENAL_SetPaused(channels[thudsound], false);
2588                                                                                 }
2589
2590                                                                                 victim->skeleton.longdead=0;
2591                                                                                 victim->skeleton.free=1;
2592                                                                                 victim->skeleton.broken=0;
2593                                                                                 victim->skeleton.spinny=1;
2594
2595                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2596                                                                                         victim->skeleton.joints[i].velchange=0;
2597                                                                                         //victim->skeleton.joints[i].delay=0;
2598                                                                                         victim->skeleton.joints[i].locked=0;
2599                                                                                 }
2600                                                                                 XYZ relative;
2601                                                                                 relative=victim->coords-coords;
2602                                                                                 Normalise(&relative);
2603                                                                                 relative.y+=.3;
2604                                                                                 Normalise(&relative);
2605                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2606                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2607                                                                                 }
2608                                                                                 if(id==0&&!victim->dead){
2609                                                                                         SolidHitBonus();
2610                                                                                 }
2611
2612                                                                                 victim->Puff(abdomen);
2613                                                                                 victim->DoDamage(damagemult*20/victim->protectionhigh);
2614                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2615                                                                                 staggerdelay=.5;
2616                                                                                 if(!victim->dead)staggerdelay=1.2;
2617
2618
2619                                                                         }
2620                                                                 }
2621
2622                                                                 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2623                                                                         // if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9){
2624                                                                         //if(id==0)camerashake+=.4;
2625                                                                         float gLoc[3];
2626                                                                         float vel[3];
2627                                                                         gLoc[0]=coords.x;
2628                                                                         gLoc[1]=coords.y;
2629                                                                         gLoc[2]=coords.z;
2630                                                                         vel[0]=velocity.x;
2631                                                                         vel[1]=velocity.y;
2632                                                                         vel[2]=velocity.z;
2633
2634                                                                         if(hasvictim)
2635                                                                                 if(!victim->skeleton.free)hasvictim=0;
2636
2637                                                                         if(!hasvictim){
2638                                                                                 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2639                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2640                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2641                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
2642                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
2643                                                                         }
2644
2645                                                                         if(victim&&hasvictim){
2646                                                                                 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2647
2648                                                                                         XYZ where,startpoint,endpoint,movepoint,colpoint;
2649                                                                                         float rotationpoint;
2650                                                                                         int whichtri;
2651                                                                                         if(weapons.type[weaponids[weaponactive]]==knife){
2652                                                                                                 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2653                                                                                                 where-=victim->coords;
2654                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2655                                                                                                 //where=scale;
2656                                                                                                 startpoint=where;
2657                                                                                                 startpoint.y+=100;
2658                                                                                                 endpoint=where;
2659                                                                                                 endpoint.y-=100;
2660                                                                                         }
2661                                                                                         if(weapons.type[weaponids[weaponactive]]==sword){
2662                                                                                                 where=weapons.position[weaponids[weaponactive]];
2663                                                                                                 where-=victim->coords;
2664                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2665                                                                                                 startpoint=where;
2666                                                                                                 where=weapons.tippoint[weaponids[weaponactive]];
2667                                                                                                 where-=victim->coords;
2668                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2669                                                                                                 endpoint=where;
2670                                                                                         }
2671                                                                                         if(weapons.type[weaponids[weaponactive]]==staff){
2672                                                                                                 where=weapons.position[weaponids[weaponactive]];
2673                                                                                                 where-=victim->coords;
2674                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2675                                                                                                 startpoint=where;
2676                                                                                                 where=weapons.tippoint[weaponids[weaponactive]];
2677                                                                                                 where-=victim->coords;
2678                                                                                                 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2679                                                                                                 endpoint=where;
2680                                                                                         }
2681                                                                                         movepoint=0;
2682                                                                                         rotationpoint=0;
2683                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2684
2685                                                                                         if(whichtri!=-1){
2686                                                                                                 if(victim->dead!=2){
2687                                                                                                         victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2688                                                                                                         if (!victim->dead)
2689                                                                                                           award_bonus(id, FinishedBonus);
2690                                                                                                 }
2691                                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2692
2693                                                                                                 victim->skeleton.longdead=0;
2694                                                                                                 victim->skeleton.free=1;
2695                                                                                                 victim->skeleton.broken=0;
2696
2697                                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2698                                                                                                         victim->skeleton.joints[i].velchange=0;
2699                                                                                                         victim->skeleton.joints[i].locked=0;
2700                                                                                                         //victim->skeleton.joints[i].velocity=0;
2701                                                                                                 }
2702                                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
2703                                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
2704                                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 128);
2705                                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
2706
2707                                                                                         }
2708                                                                                         if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2709                                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
2710                                                                                                 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2711                                                                                         }
2712                                                                                         if(whichtri==-1){
2713                                                                                                 hasvictim=0;
2714                                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
2715                                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
2716                                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
2717                                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
2718                                                                                         }
2719                                                                                 }
2720                                                                         }
2721                                                                 }
2722
2723                                                                 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2724                                                                         // if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9){
2725                                                                         //if(id==0)camerashake+=.4;
2726                                                                         float gLoc[3];
2727                                                                         float vel[3];
2728                                                                         gLoc[0]=coords.x;
2729                                                                         gLoc[1]=coords.y;
2730                                                                         gLoc[2]=coords.z;
2731                                                                         vel[0]=velocity.x;
2732                                                                         vel[1]=velocity.y;
2733                                                                         vel[2]=velocity.z;
2734                                                                         if(!hasvictim){
2735                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
2736                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
2737                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
2738                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
2739                                                                         }
2740
2741                                                                         if(victim&&hasvictim){
2742                                                                                 XYZ footvel,footpoint;
2743
2744                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
2745                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
2746                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 128);
2747                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
2748
2749                                                                                 footvel=0;
2750                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2751
2752                                                                                 if(weapons.type[weaponids[weaponactive]]==sword){
2753                                                                                         XYZ where,startpoint,endpoint,movepoint;
2754                                                                                         float rotationpoint;
2755                                                                                         int whichtri;
2756
2757                                                                                         where=weapons.position[weaponids[weaponactive]];
2758                                                                                         where-=victim->coords;
2759                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2760                                                                                         startpoint=where;
2761                                                                                         where=weapons.tippoint[weaponids[weaponactive]];
2762                                                                                         where-=victim->coords;
2763                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2764                                                                                         endpoint=where;
2765
2766                                                                                         movepoint=0;
2767                                                                                         rotationpoint=0;
2768                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2769                                                                                         footpoint+=victim->coords;
2770
2771                                                                                         if(whichtri==-1){
2772                                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2773                                                                                         }
2774                                                                                 }
2775                                                                                 if(weapons.type[weaponids[weaponactive]]==staff){
2776                                                                                         XYZ where,startpoint,endpoint,movepoint;
2777                                                                                         float rotationpoint;
2778                                                                                         int whichtri;
2779
2780                                                                                         where=weapons.position[weaponids[weaponactive]];
2781                                                                                         where-=victim->coords;
2782                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2783                                                                                         startpoint=where;
2784                                                                                         where=weapons.tippoint[weaponids[weaponactive]];
2785                                                                                         where-=victim->coords;
2786                                                                                         if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2787                                                                                         endpoint=where;
2788
2789                                                                                         movepoint=0;
2790                                                                                         rotationpoint=0;
2791                                                                                         whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2792                                                                                         footpoint+=victim->coords;
2793
2794                                                                                         if(whichtri==-1){
2795                                                                                                 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2796                                                                                         }
2797                                                                                 }
2798                                                                                 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2799                                                                                 if(hasvictim){
2800                                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2801                                                                                                 victim->skeleton.longdead=0;
2802                                                                                                 victim->skeleton.free=1;
2803                                                                                                 victim->skeleton.broken=0;
2804
2805                                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2806                                                                                                         victim->skeleton.joints[i].velchange=0;
2807                                                                                                         victim->skeleton.joints[i].locked=0;
2808                                                                                                         //victim->skeleton.joints[i].velocity=0;
2809                                                                                                 }
2810
2811                                                                                                 XYZ relative;
2812                                                                                                 relative=0;
2813                                                                                                 relative.y=10;
2814                                                                                                 Normalise(&relative);
2815                                                                                                 //victim->Puff(abdomen);
2816                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2817
2818                                                                                                 if(victim->bloodloss<victim->damagetolerance){
2819                                                                                                         victim->bloodloss+=1000;
2820                                                                                                         victim->bled=0;
2821                                                                                                 }
2822
2823                                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2824                                                                                         }
2825                                                                                 }
2826                                                                         }
2827                                                                         if(!hasvictim&&onterrain){
2828                                                                                 weapons.bloody[weaponids[weaponactive]]=0;
2829                                                                                 weapons.blooddrip[weaponids[weaponactive]]=0;
2830                                                                         }
2831                                                                 }
2832
2833                                                                 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2834                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2835                                                                                 escapednum=0;
2836                                                                                 if(id==0)camerashake+=.4;
2837                                                                                 if(Random()%2){
2838                                                                                         victim->spurt=1;
2839                                                                                         DoBlood(.2,235);
2840                                                                                 }
2841                                                                                 float gLoc[3];
2842                                                                                 float vel[3];
2843                                                                                 gLoc[0]=victim->coords.x;
2844                                                                                 gLoc[1]=victim->coords.y;
2845                                                                                 gLoc[2]=victim->coords.z;
2846                                                                                 vel[0]=velocity.x;
2847                                                                                 vel[1]=velocity.y;
2848                                                                                 vel[2]=velocity.z;
2849                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60){
2850                                                                                 if(1==1){
2851                                                                                         if(tutoriallevel!=1){
2852                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2853                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2854                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
2855                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
2856                                                                                         }
2857                                                                                 }
2858                                                                                 else {
2859                                                                                         if(tutoriallevel!=1){
2860                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
2861                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
2862                                                                                                 OPENAL_SetVolume(channels[landsound2], 256);
2863                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
2864                                                                                         }
2865                                                                                 }
2866
2867                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60)
2868                                                                                 victim->RagDoll(0);
2869                                                                                 XYZ relative;
2870                                                                                 relative=victim->coords-coords;
2871                                                                                 relative.y=0;
2872                                                                                 Normalise(&relative);
2873                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2874                                                                                         victim->skeleton.joints[i].velocity=relative*30;
2875                                                                                 }
2876                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2877
2878                                                                                 victim->targetframe=0;
2879                                                                                 victim->targetanimation=staggerbackhardanim;
2880                                                                                 victim->targetrotation=targetrotation+180;
2881                                                                                 victim->target=0;
2882                                                                                 victim->stunned=1;
2883
2884                                                                                 victim->Puff(head);
2885                                                                                 victim->Puff(abdomen);
2886                                                                                 victim->DoDamage(damagemult*60/victim->protectionhigh);
2887
2888                                                                                 if(id==0){
2889                                                                                         SolidHitBonus();
2890                                                                                 }
2891                                                                         }
2892                                                                 }
2893
2894
2895                                                                 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2896                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2897                                                                                 escapednum=0;
2898                                                                                 if(id==0)camerashake+=.4;
2899                                                                                 float gLoc[3];
2900                                                                                 float vel[3];
2901                                                                                 gLoc[0]=victim->coords.x;
2902                                                                                 gLoc[1]=victim->coords.y;
2903                                                                                 gLoc[2]=victim->coords.z;
2904                                                                                 vel[0]=velocity.x;
2905                                                                                 vel[1]=velocity.y;
2906                                                                                 vel[2]=velocity.z;
2907                                                                                 //if(!victim->isIdle()||victim->damage>victim->damagetolerance-60){
2908                                                                                 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2909                                                                                         if(tutoriallevel!=1){
2910                                                                                                 PlaySoundEx( thudsound, samp[thudsound], NULL, true);
2911                                                                                                 OPENAL_3D_SetAttributes(channels[thudsound], gLoc, vel);
2912                                                                                                 OPENAL_SetVolume(channels[thudsound], 512);
2913                                                                                                 OPENAL_SetPaused(channels[thudsound], false);
2914                                                                                         }
2915                                                                                 }
2916                                                                                 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2917                                                                                         if(tutoriallevel!=1){
2918                                                                                                 PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
2919                                                                                                 OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
2920                                                                                                 OPENAL_SetVolume(channels[whooshhitsound], 512);
2921                                                                                                 OPENAL_SetPaused(channels[whooshhitsound], false);
2922                                                                                         }
2923                                                                                 }
2924                                                                                 else {
2925                                                                                         if(tutoriallevel!=1){
2926                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
2927                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
2928                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 256);
2929                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
2930                                                                                         }
2931                                                                                 }
2932
2933                                                                                 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2934                                                                                         victim->RagDoll(0);
2935                                                                                 XYZ relative;
2936                                                                                 relative=victim->coords-coords;
2937                                                                                 relative.y=0;
2938                                                                                 Normalise(&relative);
2939                                                                                 relative.y=.3;
2940                                                                                 Normalise(&relative);
2941                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
2942                                                                                         victim->skeleton.joints[i].velocity=relative*5;
2943                                                                                 }
2944                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2945
2946                                                                                 victim->targetframe=0;
2947                                                                                 victim->targetanimation=staggerbackhardanim;
2948                                                                                 victim->targetrotation=targetrotation+180;
2949                                                                                 victim->target=0;
2950                                                                                 victim->stunned=1;
2951
2952                                                                                 victim->Puff(abdomen);
2953                                                                                 victim->DoDamage(damagemult*60/victim->protectionhigh);
2954
2955                                                                                 if(id==0){
2956                                                                                         SolidHitBonus();
2957                                                                                 }
2958                                                                         }
2959                                                                 }
2960
2961                                                                 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2962                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2963                                                                                 if(victim->id==0)camerashake+=.4;
2964                                                                                 float gLoc[3];
2965                                                                                 float vel[3];
2966                                                                                 gLoc[0]=victim->coords.x;
2967                                                                                 gLoc[1]=victim->coords.y;
2968                                                                                 gLoc[2]=victim->coords.z;
2969                                                                                 vel[0]=velocity.x;
2970                                                                                 vel[1]=velocity.y;
2971                                                                                 vel[2]=velocity.z;
2972
2973                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
2974                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
2975                                                                                 OPENAL_SetVolume(channels[landsound2], 256);
2976                                                                                 OPENAL_SetPaused(channels[landsound2], false);
2977
2978                                                                                 Puff(righthand);
2979                                                                         }
2980                                                                 }
2981
2982                                                                 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2983                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2984                                                                                 if(victim->id==0)camerashake+=.4;
2985                                                                                 float gLoc[3];
2986                                                                                 float vel[3];
2987                                                                                 gLoc[0]=victim->coords.x;
2988                                                                                 gLoc[1]=victim->coords.y;
2989                                                                                 gLoc[2]=victim->coords.z;
2990                                                                                 vel[0]=velocity.x;
2991                                                                                 vel[1]=velocity.y;
2992                                                                                 vel[2]=velocity.z;
2993
2994                                                                                 if(weaponactive!=-1){
2995                                                                                         if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2996                                                                                                 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2997                                                                                                 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2998
2999                                                                                                 PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
3000                                                                                                 OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
3001                                                                                                 OPENAL_SetVolume(channels[swordstaffsound], 512);
3002                                                                                                 OPENAL_SetPaused(channels[swordstaffsound], false);
3003                                                                                         }
3004                                                                                         else{
3005                                                                                                 PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3006                                                                                                 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3007                                                                                                 OPENAL_SetVolume(channels[metalhitsound], 512);
3008                                                                                                 OPENAL_SetPaused(channels[metalhitsound], false);
3009                                                                                         }
3010                                                                                 }
3011
3012                                                                                 //Puff(righthand);
3013                                                                         }
3014                                                                 }
3015
3016                                                                 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
3017                                                                         if(weaponactive!=-1){
3018                                                                                 escapednum=0;
3019                                                                                 XYZ aim;
3020                                                                                 weapons.owner[weaponids[0]]=-1;
3021                                                                                 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);
3022                                                                                 Normalise(&aim);
3023                                                                                 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
3024                                                                                 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
3025                                                                                 }*/
3026                                                                                 weapons.velocity[weaponids[0]]=aim*50;
3027                                                                                 weapons.tipvelocity[weaponids[0]]=aim*50;
3028                                                                                 weapons.missed[weaponids[0]]=0;
3029                                                                                 weapons.hitsomething[weaponids[0]]=0;
3030                                                                                 weapons.freetime[weaponids[0]]=0;
3031                                                                                 weapons.firstfree[weaponids[0]]=1;
3032                                                                                 weapons.physics[weaponids[0]]=0;
3033                                                                                 num_weapons--;
3034                                                                                 if(num_weapons){
3035                                                                                         weaponids[0]=weaponids[num_weapons];
3036                                                                                 }
3037                                                                                 weaponactive=-1;
3038                                                                         }
3039                                                                 }
3040
3041                                                                 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
3042                                                                         if(hasvictim)
3043                                                                                 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
3044                                                                                         escapednum=0;
3045                                                                                         //if(Random()%2){
3046                                                                                         if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
3047                                                                                         //}
3048
3049                                                                                         award_bonus(id, Slicebonus);
3050                                                                                         if(tutoriallevel!=1){
3051                                                                                                 float gLoc[3];
3052                                                                                                 float vel[3];
3053                                                                                                 gLoc[0]=victim->coords.x;
3054                                                                                                 gLoc[1]=victim->coords.y;
3055                                                                                                 gLoc[2]=victim->coords.z;
3056                                                                                                 vel[0]=velocity.x;
3057                                                                                                 vel[1]=velocity.y;
3058                                                                                                 vel[2]=velocity.z;
3059                                                                                                 PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3060                                                                                                 OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3061                                                                                                 OPENAL_SetVolume(channels[knifeslicesound], 512);
3062                                                                                                 OPENAL_SetPaused(channels[knifeslicesound], false);
3063                                                                                         }
3064                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3065                                                                                         if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
3066                                                                                                 if(victim->id != 0 || difficulty==2){
3067                                                                                                         victim->targetframe=0;
3068                                                                                                         victim->targetanimation=staggerbackhardanim;
3069                                                                                                         victim->targetrotation=targetrotation+180;
3070                                                                                                         victim->target=0;
3071                                                                                                 }
3072                                                                                         }
3073                                                                                         victim->lowreversaldelay=0;
3074                                                                                         victim->highreversaldelay=0;
3075                                                                                         if(aitype!=playercontrolled)weaponmissdelay=.6;
3076
3077                                                                                         if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3078                                                                                         if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
3079
3080                                                                                         XYZ footvel,footpoint;
3081                                                                                         footvel=0;
3082                                                                                         if(skeleton.free){
3083                                                                                                 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
3084                                                                                         }
3085                                                                                         if(!skeleton.free){
3086                                                                                                 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;
3087                                                                                         }
3088                                                                                         if(tutoriallevel!=1){
3089                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
3090                                                                                                 footvel=DoRotation(facing,0,90,0)*.8;
3091                                                                                                 //footvel.y-=.3;
3092                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3093                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3094                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3095                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3096                                                                                         }
3097                                                                                         if(tutoriallevel==1){
3098                                                                                                 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
3099                                                                                         }
3100                                                                                         victim->DoDamage(damagemult*0);
3101                                                                                 }
3102                                                                 }
3103                                                                 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3104                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
3105                                                                                 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
3106                                                                                         award_bonus(id, Slashbonus);
3107                                                                                         escapednum=0;
3108                                                                                         if(tutoriallevel!=1){
3109                                                                                                 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
3110                                                                                                 else victim->DoBloodBig(2/victim->armorhigh,185);
3111                                                                                                 victim->deathbleeding=1;
3112                                                                                                 float gLoc[3];
3113                                                                                                 float vel[3];
3114                                                                                                 gLoc[0]=victim->coords.x;
3115                                                                                                 gLoc[1]=victim->coords.y;
3116                                                                                                 gLoc[2]=victim->coords.z;
3117                                                                                                 vel[0]=velocity.x;
3118                                                                                                 vel[1]=velocity.y;
3119                                                                                                 vel[2]=velocity.z;
3120                                                                                                 PlaySoundEx( swordslicesound, samp[swordslicesound], NULL, true);
3121                                                                                                 OPENAL_3D_SetAttributes(channels[swordslicesound], gLoc, vel);
3122                                                                                                 OPENAL_SetVolume(channels[swordslicesound], 512);
3123                                                                                                 OPENAL_SetPaused(channels[swordslicesound], false);
3124                                                                                         }
3125                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3126                                                                                         //if(animation[victim->targetanimation].attack){
3127                                                                                         //if(victim->creature==rabbittype){
3128                                                                                         if(tutoriallevel!=1){
3129                                                                                                 victim->targetframe=0;
3130                                                                                                 victim->targetanimation=staggerbackhardanim;
3131                                                                                                 victim->targetrotation=targetrotation+180;
3132                                                                                                 victim->target=0;
3133                                                                                         }
3134                                                                                         //}
3135                                                                                         //}
3136
3137                                                                                         if(tutoriallevel!=1){
3138                                                                                                 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3139                                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=3;
3140
3141                                                                                                 float bloodlossamount;
3142                                                                                                 bloodlossamount=200+abs((float)(Random()%40))-20;
3143                                                                                                 victim->bloodloss+=bloodlossamount/victim->armorhigh;
3144                                                                                                 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
3145                                                                                                 victim->DoDamage(damagemult*0);
3146
3147                                                                                                 XYZ footvel,footpoint;
3148                                                                                                 footvel=0;
3149                                                                                                 if(skeleton.free){
3150                                                                                                         footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
3151                                                                                                 }
3152                                                                                                 if(!skeleton.free){
3153                                                                                                         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;
3154                                                                                                 }
3155                                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3156                                                                                                 footvel=DoRotation(facing,0,90,0)*.8;
3157                                                                                                 footvel.y-=.3;
3158                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3159                                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3160                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3161                                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3162                                                                                         }
3163                                                                                 }
3164                                                                                 else {
3165
3166
3167                                                                                         float gLoc[3];
3168                                                                                         float vel[3];
3169                                                                                         gLoc[0]=victim->coords.x;
3170                                                                                         gLoc[1]=victim->coords.y;
3171                                                                                         gLoc[2]=victim->coords.z;
3172                                                                                         vel[0]=velocity.x;
3173                                                                                         vel[1]=velocity.y;
3174                                                                                         vel[2]=velocity.z;
3175                                                                                         if(victim->weaponactive!=-1){
3176                                                                                                 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
3177                                                                                                         if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3178                                                                                                         if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
3179
3180                                                                                                         PlaySoundEx( swordstaffsound, samp[swordstaffsound], NULL, true);
3181                                                                                                         OPENAL_3D_SetAttributes(channels[swordstaffsound], gLoc, vel);
3182                                                                                                         OPENAL_SetVolume(channels[swordstaffsound], 512);
3183                                                                                                         OPENAL_SetPaused(channels[swordstaffsound], false);
3184                                                                                                 }
3185                                                                                                 else{
3186                                                                                                         PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3187                                                                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3188                                                                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
3189                                                                                                         OPENAL_SetPaused(channels[metalhitsound], false);
3190                                                                                                 }
3191                                                                                         }
3192
3193
3194                                                                                         XYZ aim;
3195                                                                                         victim->Puff(righthand);
3196                                                                                         victim->target=0;
3197                                                                                         victim->targetframe=0;
3198                                                                                         victim->targetanimation=staggerbackhighanim;
3199                                                                                         victim->targetrotation=targetrotation+180;
3200                                                                                         victim->target=0;
3201                                                                                         weapons.owner[victim->weaponids[0]]=-1;
3202                                                                                         aim=DoRotation(facing,0,90,0)*21;
3203                                                                                         aim.y+=7;
3204                                                                                         weapons.velocity[victim->weaponids[0]]=aim*-.2;
3205                                                                                         weapons.tipvelocity[victim->weaponids[0]]=aim;
3206                                                                                         weapons.missed[victim->weaponids[0]]=1;
3207                                                                                         weapons.hitsomething[weaponids[0]]=0;
3208                                                                                         weapons.freetime[victim->weaponids[0]]=0;
3209                                                                                         weapons.firstfree[victim->weaponids[0]]=1;
3210                                                                                         weapons.physics[victim->weaponids[0]]=1;
3211                                                                                         victim->num_weapons--;
3212                                                                                         if(victim->num_weapons){
3213                                                                                                 victim->weaponids[0]=victim->weaponids[num_weapons];
3214                                                                                                 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3215                                                                                         }
3216                                                                                         victim->weaponactive=-1;
3217                                                                                         for(i=0;i<numplayers;i++){
3218                                                                                                 player[i].wentforweapon=0;
3219                                                                                         }
3220
3221                                                                                         /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
3222                                                                                         OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
3223                                                                                         OPENAL_SetVolume(channels[metalhitsound], 512);
3224                                                                                         OPENAL_SetPaused(channels[metalhitsound], false);*/
3225
3226                                                                                 }
3227                                                                         }
3228                                                                 }
3229
3230                                                                 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3231                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
3232                                                                                 if(tutoriallevel!=1){
3233                                                                                         weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
3234                                                                                         escapednum=0;
3235                                                                                         if(id==0)camerashake+=.4;
3236                                                                                         if(Random()%2||creature==wolftype){
3237                                                                                                 victim->spurt=1;
3238                                                                                         }
3239                                                                                         float gLoc[3];
3240                                                                                         float vel[3];
3241                                                                                         gLoc[0]=victim->coords.x;
3242                                                                                         gLoc[1]=victim->coords.y;
3243                                                                                         gLoc[2]=victim->coords.z;
3244                                                                                         vel[0]=velocity.x;
3245                                                                                         vel[1]=velocity.y;
3246                                                                                         vel[2]=velocity.z;
3247                                                                                         PlaySoundEx( staffheadsound, samp[staffheadsound], NULL, true);
3248                                                                                         OPENAL_3D_SetAttributes(channels[staffheadsound], gLoc, vel);
3249                                                                                         OPENAL_SetVolume(channels[staffheadsound], 256);
3250                                                                                         OPENAL_SetPaused(channels[staffheadsound], false);
3251                                                                                 }
3252                                                                                 victim->RagDoll(0);
3253                                                                                 XYZ relative;
3254                                                                                 relative=victim->coords-coords;
3255                                                                                 relative.y=0;
3256                                                                                 Normalise(&relative);
3257                                                                                 relative=DoRotation(relative,0,90,0);
3258                                                                                 relative.y-=1;
3259                                                                                 Normalise(&relative);
3260                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3261                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*60;
3262                                                                                 }
3263                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
3264                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
3265                                                                                 //FootLand(1,2);
3266                                                                                 victim->Puff(head);
3267                                                                                 if(tutoriallevel!=1){
3268                                                                                         victim->DoDamage(damagemult*120/victim->protectionhigh);
3269
3270                                                                                         award_bonus(id, solidhit, 30);
3271                                                                                 }
3272                                                                         }
3273                                                                 }
3274
3275                                                                 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
3276                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
3277                                                                                 if(tutoriallevel!=1){
3278                                                                                         weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
3279                                                                                         escapednum=0;
3280                                                                                         if(id==0)camerashake+=.4;
3281                                                                                         if(Random()%2||creature==wolftype){
3282                                                                                                 victim->spurt=1;
3283                                                                                         }
3284                                                                                         float gLoc[3];
3285                                                                                         float vel[3];
3286                                                                                         gLoc[0]=victim->coords.x;
3287                                                                                         gLoc[1]=victim->coords.y;
3288                                                                                         gLoc[2]=victim->coords.z;
3289                                                                                         vel[0]=velocity.x;
3290                                                                                         vel[1]=velocity.y;
3291                                                                                         vel[2]=velocity.z;
3292                                                                                         PlaySoundEx( staffheadsound, samp[staffheadsound], NULL, true);
3293                                                                                         OPENAL_3D_SetAttributes(channels[staffheadsound], gLoc, vel);
3294                                                                                         OPENAL_SetVolume(channels[staffheadsound], 256);
3295                                                                                         OPENAL_SetPaused(channels[staffheadsound], false);
3296                                                                                 }
3297                                                                                 victim->RagDoll(0);
3298                                                                                 XYZ relative;
3299                                                                                 relative=victim->coords-coords;
3300                                                                                 relative.y=0;
3301                                                                                 Normalise(&relative);
3302                                                                                 relative=DoRotation(relative,0,-90,0);
3303                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3304                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3305                                                                                 }
3306                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
3307                                                                                 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
3308                                                                                 //FootLand(1,2);
3309                                                                                 victim->Puff(head);
3310                                                                                 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
3311
3312                                                                                 award_bonus(id, solidhit, 60);
3313                                                                                 }
3314                                                                         }
3315                                                                 }
3316
3317                                                                 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
3318                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
3319                                                                                 escapednum=0;
3320                                                                                 if(tutoriallevel!=1){
3321                                                                                         if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
3322                                                                                         if(id==0)camerashake+=.4;
3323                                                                                         if(Random()%2||creature==wolftype){
3324                                                                                                 victim->spurt=1;
3325                                                                                         }
3326                                                                                         float gLoc[3];
3327                                                                                         float vel[3];
3328                                                                                         gLoc[0]=victim->coords.x;
3329                                                                                         gLoc[1]=victim->coords.y;
3330                                                                                         gLoc[2]=victim->coords.z;
3331                                                                                         vel[0]=velocity.x;
3332                                                                                         vel[1]=velocity.y;
3333                                                                                         vel[2]=velocity.z;
3334                                                                                         PlaySoundEx( staffbodysound, samp[staffbodysound], NULL, true);
3335                                                                                         OPENAL_3D_SetAttributes(channels[staffbodysound], gLoc, vel);
3336                                                                                         OPENAL_SetVolume(channels[staffbodysound], 256);
3337                                                                                         OPENAL_SetPaused(channels[staffbodysound], false);
3338                                                                                 }
3339                                                                                 victim->skeleton.longdead=0;
3340                                                                                 victim->skeleton.free=1;
3341                                                                                 victim->skeleton.broken=0;
3342
3343                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3344                                                                                         victim->skeleton.joints[i].velchange=0;
3345                                                                                         victim->skeleton.joints[i].locked=0;
3346                                                                                         //victim->skeleton.joints[i].velocity=0;
3347                                                                                 }
3348
3349                                                                                 victim->RagDoll(0);
3350                                                                                 XYZ relative;
3351                                                                                 relative=0;
3352                                                                                 /*relative=victim->coords-coords;
3353                                                                                 relative.y=0;
3354                                                                                 Normalise(&relative);
3355                                                                                 relative=DoRotation(relative,0,90,0);*/
3356                                                                                 relative.y=-1;
3357                                                                                 Normalise(&relative);
3358                                                                                 if(!victim->dead){
3359                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3360                                                                                                 victim->skeleton.joints[i].velocity=relative*damagemult*40;
3361                                                                                         }
3362                                                                                         //FootLand(1,2);
3363                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
3364                                                                                 }
3365                                                                                 if(victim->dead){
3366                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3367                                                                                                 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
3368                                                                                         }
3369                                                                                         //FootLand(1,2);
3370                                                                                         //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
3371                                                                                 }
3372                                                                                 victim->Puff(abdomen);
3373                                                                                 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
3374
3375                                                                                 if(!victim->dead){
3376                                                                                   award_bonus(id, solidhit, 40);
3377                                                                                 }
3378                                                                                 }
3379                                                                         }
3380                                                                 }
3381
3382                                                                 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
3383                                                                         if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
3384                                                                                 escapednum=0;
3385                                                                                 if(id==0)camerashake+=.4;
3386                                                                                 float gLoc[3];
3387                                                                                 float vel[3];
3388                                                                                 gLoc[0]=victim->coords.x;
3389                                                                                 gLoc[1]=victim->coords.y;
3390                                                                                 gLoc[2]=victim->coords.z;
3391                                                                                 vel[0]=velocity.x;
3392                                                                                 vel[1]=velocity.y;
3393                                                                                 vel[2]=velocity.z;
3394                                                                                 XYZ relative;
3395                                                                                 relative=victim->coords-coords;
3396                                                                                 relative.y=0;
3397                                                                                 Normalise(&relative);
3398
3399                                                                                 if(id==0){
3400                                                                                         SolidHitBonus();
3401                                                                                 }
3402
3403                                                                                 if(animation[victim->targetanimation].height==lowheight){
3404                                                                                         if(Random()%2){
3405                                                                                                 victim->spurt=1;
3406                                                                                                 DoBlood(.2,250);
3407                                                                                         }
3408                                                                                         victim->RagDoll(0);
3409                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3410                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3411                                                                                         }
3412                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3413                                                                                         if(tutoriallevel!=1){
3414                                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3415                                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3416                                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3417                                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3418                                                                                         }
3419                                                                                         victim->Puff(head);
3420                                                                                         victim->DoDamage(damagemult*100/victim->protectionhead);
3421                                                                                         if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
3422                                                                                         if(creature==wolftype){
3423                                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3424                                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3425                                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3426                                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3427                                                                                                 victim->spurt=1;
3428                                                                                                 victim->DoBloodBig(2/victim->armorhead,175);
3429                                                                                         }
3430                                                                                 }
3431                                                                                 else{
3432                                                                                         if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
3433                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3434                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
3435                                                                                         }
3436                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3437                                                                                         victim->targetframe=0;
3438                                                                                         victim->targetanimation=staggerbackhighanim;
3439                                                                                         victim->targetrotation=targetrotation+180;
3440                                                                                         victim->target=0;
3441                                                                                         if(tutoriallevel!=1){
3442                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3443                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3444                                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
3445                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
3446                                                                                         }
3447                                                                                         victim->Puff(abdomen);
3448                                                                                         victim->DoDamage(damagemult*30/victim->protectionhigh);
3449                                                                                         if(creature==wolftype){
3450                                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3451                                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3452                                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3453                                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3454                                                                                                 victim->spurt=1;
3455                                                                                                 victim->DoBloodBig(2/victim->armorhigh,170);
3456                                                                                         }
3457                                                                                 }
3458
3459                                                                         }
3460                                                                 }
3461
3462                                                                 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
3463                                                                         if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
3464                                                                                 escapednum=0;
3465                                                                                 if(id==0)camerashake+=.2;
3466                                                                                 float gLoc[3];
3467                                                                                 float vel[3];
3468                                                                                 gLoc[0]=victim->coords.x;
3469                                                                                 gLoc[1]=victim->coords.y;
3470                                                                                 gLoc[2]=victim->coords.z;
3471                                                                                 vel[0]=velocity.x;
3472                                                                                 vel[1]=velocity.y;
3473                                                                                 vel[2]=velocity.z;
3474                                                                                 if(tutoriallevel!=1){
3475                                                                                         PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3476                                                                                         OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3477                                                                                         OPENAL_SetVolume(channels[landsound2], 128);
3478                                                                                         OPENAL_SetPaused(channels[landsound2], false);
3479                                                                                 }
3480                                                                                 XYZ relative;
3481                                                                                 relative=victim->coords-coords;
3482                                                                                 relative.y=0;
3483                                                                                 Normalise(&relative);
3484
3485                                                                                 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
3486                                                                                         victim->RagDoll(0);
3487
3488                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3489                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
3490                                                                                         }
3491                                                                                         relative=DoRotation(relative,0,-90,0);
3492                                                                                         relative.y+=.1;
3493                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3494                                                                                                 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)
3495                                                                                                         victim->skeleton.joints[i].velocity=relative*80;
3496                                                                                         }
3497                                                                                         victim->Puff(rightankle);
3498                                                                                         victim->Puff(leftankle);
3499                                                                                         victim->DoDamage(damagemult*40/victim->protectionlow);
3500                                                                                 }
3501                                                                                 else{
3502                                                                                         if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
3503                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3504                                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
3505                                                                                         }
3506                                                                                         relative=DoRotation(relative,0,-90,0);
3507                                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3508                                                                                                 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)
3509                                                                                                         victim->skeleton.joints[i].velocity+=relative*damagemult*80;
3510                                                                                         }
3511                                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3512                                                                                         victim->targetframe=0;
3513                                                                                         victim->targetanimation=staggerbackhighanim;
3514                                                                                         victim->targetrotation=targetrotation+180;
3515                                                                                         victim->target=0;
3516                                                                                         if(tutoriallevel!=1){
3517                                                                                                 PlaySoundEx( landsound2, samp[landsound2], NULL, true);
3518                                                                                                 OPENAL_3D_SetAttributes(channels[landsound2], gLoc, vel);
3519                                                                                                 OPENAL_SetVolume(channels[landsound2], 128);
3520                                                                                                 OPENAL_SetPaused(channels[landsound2], false);
3521                                                                                         }
3522                                                                                         victim->Puff(abdomen);
3523                                                                                         victim->DoDamage(damagemult*30/victim->protectionlow);
3524                                                                                 }
3525
3526                                                                                 if(id==0){
3527                                                                                         SolidHitBonus();
3528                                                                                 }
3529
3530                                                                         }
3531                                                                 }
3532                                                         }
3533                                                         if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
3534                                                                 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
3535                                                                         escapednum=0;
3536                                                                         if(id==0)camerashake+=.4;
3537                                                                         if(Random()%2){
3538                                                                                 victim->spurt=1;
3539                                                                                 DoBlood(.2,230);
3540                                                                         }
3541                                                                         float gLoc[3];
3542                                                                         float vel[3];
3543                                                                         gLoc[0]=victim->coords.x;
3544                                                                         gLoc[1]=victim->coords.y;
3545                                                                         gLoc[2]=victim->coords.z;
3546                                                                         vel[0]=velocity.x;
3547                                                                         vel[1]=velocity.y;
3548                                                                         vel[2]=velocity.z;
3549                                                                         if(tutoriallevel!=1){
3550                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3551                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3552                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3553                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3554                                                                         }
3555                                                                         if(creature==wolftype){
3556                                                                                 PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3557                                                                                 OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3558                                                                                 OPENAL_SetVolume(channels[clawslicesound], 128);
3559                                                                                 OPENAL_SetPaused(channels[clawslicesound], false);
3560                                                                                 victim->spurt=1;
3561                                                                                 victim->DoBloodBig(2/victim->armorhigh,170);
3562                                                                         }
3563                                                                         victim->RagDoll(0);
3564                                                                         XYZ relative;
3565                                                                         relative=victim->coords-oldcoords;
3566                                                                         relative.y=0;
3567                                                                         Normalise(&relative);
3568                                                                         //relative=DoRotation(relative,0,-90,0);
3569                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3570                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3571                                                                         }
3572                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3573                                                                         //FootLand(1,2);
3574                                                                         victim->Puff(abdomen);
3575                                                                         victim->DoDamage(damagemult*150/victim->protectionhigh);
3576
3577                                                                         award_bonus(id, Reversal);
3578                                                                 }
3579
3580                                                                 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
3581                                                                         if(victim->weaponactive!=-1&&victim->num_weapons>0){
3582                                                                                 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
3583                                                                                         weapons.owner[victim->weaponids[victim->weaponactive]]=id;
3584                                                                                         weaponactive=0;
3585                                                                                         if(num_weapons>0){
3586                                                                                                 weaponids[num_weapons]=weaponids[victim->weaponactive];
3587                                                                                         }
3588                                                                                         num_weapons++;
3589                                                                                         weaponids[0]=victim->weaponids[victim->weaponactive];
3590                                                                                         victim->num_weapons--;
3591                                                                                         if(victim->num_weapons>0){
3592                                                                                                 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
3593                                                                                                 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3594                                                                                         }
3595                                                                                         victim->weaponactive=-1;
3596                                                                                 }
3597                                                                         }
3598                                                                 }
3599
3600                                                                 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
3601                                                                         escapednum=0;
3602                                                                         if(id==0)camerashake+=.4;
3603                                                                         if(Random()%2){
3604                                                                                 victim->spurt=1;
3605                                                                                 DoBlood(.2,230);
3606                                                                         }
3607                                                                         float gLoc[3];
3608                                                                         float vel[3];
3609                                                                         gLoc[0]=victim->coords.x;
3610                                                                         gLoc[1]=victim->coords.y;
3611                                                                         gLoc[2]=victim->coords.z;
3612                                                                         vel[0]=velocity.x;
3613                                                                         vel[1]=velocity.y;
3614                                                                         vel[2]=velocity.z;
3615                                                                         PlaySoundEx( whooshhitsound, samp[whooshhitsound], NULL, true);
3616                                                                         OPENAL_3D_SetAttributes(channels[whooshhitsound], gLoc, vel);
3617                                                                         OPENAL_SetVolume(channels[whooshhitsound], 128);
3618                                                                         OPENAL_SetPaused(channels[whooshhitsound], false);
3619                                                                         victim->RagDoll(0);
3620                                                                         XYZ relative;
3621                                                                         relative=victim->coords-oldcoords;
3622                                                                         relative.y=0;
3623                                                                         Normalise(&relative);
3624                                                                         //relative=DoRotation(relative,0,-90,0);
3625                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3626                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3627                                                                         }
3628                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3629                                                                         //FootLand(1,2);
3630                                                                         victim->Puff(head);
3631                                                                         victim->DoDamage(damagemult*70/victim->protectionhigh);
3632                                                                 }
3633
3634                                                                 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
3635                                                                         escapednum=0;
3636                                                                         if(id==0)camerashake+=.4;
3637                                                                         if(Random()%2){
3638                                                                                 victim->spurt=1;
3639                                                                                 DoBlood(.2,230);
3640                                                                         }
3641                                                                         float gLoc[3];
3642                                                                         float vel[3];
3643                                                                         gLoc[0]=victim->coords.x;
3644                                                                         gLoc[1]=victim->coords.y;
3645                                                                         gLoc[2]=victim->coords.z;
3646                                                                         vel[0]=velocity.x;
3647                                                                         vel[1]=velocity.y;
3648                                                                         vel[2]=velocity.z;
3649
3650                                                                         award_bonus(id, staffreversebonus);
3651
3652                                                                         if(tutoriallevel!=1){
3653                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3654                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3655                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3656                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3657                                                                         }
3658                                                                         victim->RagDoll(0);
3659                                                                         award_bonus(id, staffreversebonus); // Huh, again?
3660
3661                                                                         XYZ relative;
3662                                                                         relative=victim->coords-oldcoords;
3663                                                                         relative.y=0;
3664                                                                         Normalise(&relative);
3665                                                                         //relative=DoRotation(relative,0,-90,0);
3666                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3667                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3668                                                                         }
3669                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3670                                                                         //FootLand(1,2);
3671                                                                         victim->Puff(head);
3672                                                                         victim->DoDamage(damagemult*70/victim->protectionhigh);
3673                                                                 }
3674
3675                                                                 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
3676                                                                         escapednum=0;
3677                                                                         victim->RagDoll(1);
3678                                                                         XYZ relative;
3679                                                                         relative=facing;
3680                                                                         relative.y=0;
3681                                                                         Normalise(&relative);
3682                                                                         //relative*=-1;
3683                                                                         relative.y-=.1;
3684                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3685                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3686                                                                         }
3687                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
3688                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
3689                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
3690                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
3691                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
3692                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
3693                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
3694                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
3695
3696                                                                         victim->Puff(abdomen);
3697                                                                         victim->DoDamage(damagemult*90/victim->protectionhigh);
3698
3699                                                                         award_bonus(id, Reversal);
3700
3701                                                                         bool doslice;
3702                                                                         doslice=0;
3703                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
3704                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3705                                                                         if(doslice){
3706                                                                                 float gLoc[3];
3707                                                                                 float vel[3];
3708                                                                                 gLoc[0]=victim->coords.x;
3709                                                                                 gLoc[1]=victim->coords.y;
3710                                                                                 gLoc[2]=victim->coords.z;
3711                                                                                 vel[0]=velocity.x;
3712                                                                                 vel[1]=velocity.y;
3713                                                                                 vel[2]=velocity.z;
3714                                                                                 if(weaponactive!=-1){
3715                                                                                         victim->DoBloodBig(2/victim->armorhigh,225);
3716                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3717                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3718                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
3719                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
3720                                                                                         if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3721                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=3;
3722                                                                                 }
3723                                                                                 if(weaponactive==-1&&creature==wolftype){
3724                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3725                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3726                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
3727                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
3728                                                                                         victim->spurt=1;
3729                                                                                         victim->DoBloodBig(2/victim->armorhigh,175);
3730                                                                                 }
3731                                                                         }
3732                                                                 }
3733
3734
3735
3736                                                                 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3737                                                                         escapednum=0;
3738                                                                         victim->RagDoll(1);
3739                                                                         XYZ relative;
3740                                                                         relative=facing;
3741                                                                         relative.y=0;
3742                                                                         Normalise(&relative);
3743                                                                         //relative*=-1;
3744                                                                         relative.y-=.1;
3745                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3746                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3747                                                                         }
3748                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3749                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3750                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3751                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3752                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3753                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3754                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3755                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3756
3757                                                                         award_bonus(id, swordreversebonus);
3758                                                                 }
3759
3760                                                                 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3761                                                                         escapednum=0;
3762                                                                         if(id==0)camerashake+=.4;
3763                                                                         if(Random()%2){
3764                                                                                 victim->spurt=1;
3765                                                                                 DoBlood(.2,230);
3766                                                                         }
3767                                                                         float gLoc[3];
3768                                                                         float vel[3];
3769                                                                         gLoc[0]=victim->coords.x;
3770                                                                         gLoc[1]=victim->coords.y;
3771                                                                         gLoc[2]=victim->coords.z;
3772                                                                         vel[0]=velocity.x;
3773                                                                         vel[1]=velocity.y;
3774                                                                         vel[2]=velocity.z;
3775                                                                         if(tutoriallevel!=1){
3776                                                                                 PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
3777                                                                                 OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
3778                                                                                 OPENAL_SetVolume(channels[heavyimpactsound], 128);
3779                                                                                 OPENAL_SetPaused(channels[heavyimpactsound], false);
3780                                                                         }
3781                                                                         victim->RagDoll(0);
3782                                                                         XYZ relative;
3783                                                                         relative=victim->coords-oldcoords;
3784                                                                         relative.y=0;
3785                                                                         Normalise(&relative);
3786                                                                         relative=DoRotation(relative,0,-90,0);
3787                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3788                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3789                                                                         }
3790                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3791                                                                         //FootLand(1,2);
3792                                                                         victim->Puff(abdomen);
3793                                                                         victim->DoDamage(damagemult*30/victim->protectionhigh);
3794
3795                                                                         award_bonus(id, Reversal);
3796                                                                 }
3797
3798                                                                 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3799                                                                         escapednum=0;
3800                                                                         victim->RagDoll(0);
3801                                                                         victim->skeleton.spinny=0;
3802                                                                         XYZ relative;
3803                                                                         relative=facing*-1;
3804                                                                         relative.y=-3;
3805                                                                         Normalise(&relative);
3806                                                                         if(victim->id==0)relative/=30;
3807                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3808                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3809                                                                         }
3810                                                                         //victim->DoDamage(1000);
3811                                                                         victim->damage=victim->damagetolerance;
3812                                                                         victim->permanentdamage=victim->damagetolerance-1;
3813                                                                         bool doslice;
3814                                                                         doslice=0;
3815                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
3816                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3817                                                                         if(doslice){
3818                                                                                 float gLoc[3];
3819                                                                                 float vel[3];
3820                                                                                 gLoc[0]=victim->coords.x;
3821                                                                                 gLoc[1]=victim->coords.y;
3822                                                                                 gLoc[2]=victim->coords.z;
3823                                                                                 vel[0]=velocity.x;
3824                                                                                 vel[1]=velocity.y;
3825                                                                                 vel[2]=velocity.z;
3826                                                                                 if(weaponactive!=-1){
3827                                                                                         victim->DoBloodBig(200,225);
3828                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
3829                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
3830                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
3831                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
3832                                                                                         if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3833                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=5;
3834                                                                                 }
3835
3836                                                                                 if(creature==wolftype&&weaponactive==-1){
3837                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
3838                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
3839                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
3840                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
3841                                                                                         victim->spurt=1;
3842                                                                                         victim->DoBloodBig(2,175);
3843                                                                                 }
3844                                                                         }
3845                                                                         award_bonus(id, spinecrusher);
3846                                                                 }
3847
3848                                                                 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3849                                                                         if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3850                                                                                 escapednum=0;
3851                                                                                 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3852                                                                                 if(targetanimation==knifesneakattackanim){
3853                                                                                         /*victim->DoBloodBig(200,195);
3854                                                                                         XYZ bloodvel;
3855                                                                                         bloodvel=0;
3856                                                                                         bloodvel.z=20;
3857                                                                                         bloodvel.y=5;
3858                                                                                         bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3859                                                                                         Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3860                                                                                         */
3861                                                                                         XYZ footvel,footpoint;
3862                                                                                         footvel=0;
3863                                                                                         footpoint=weapons.tippoint[weaponids[0]];
3864                                                                                         if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3865                                                                                         footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3866                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3867                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3868                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3869                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3870                                                                                         victim->DoBloodBig(200,195);
3871                                                                                         award_bonus(id, tracheotomy);
3872                                                                                 }
3873                                                                                 if(targetanimation==knifefollowanim){
3874                                                                                         award_bonus(id, Stabbonus);
3875                                                                                         XYZ footvel,footpoint;
3876                                                                                         footvel=0;
3877                                                                                         footpoint=weapons.tippoint[weaponids[0]];
3878                                                                                         if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3879                                                                                         footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3880                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3881                                                                                         Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3882                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3883                                                                                         Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3884
3885                                                                                 }
3886                                                                                 victim->bloodloss+=10000;
3887                                                                                 victim->velocity=0;
3888                                                                                 float gLoc[3];
3889                                                                                 float vel[3];
3890                                                                                 gLoc[0]=victim->coords.x;
3891                                                                                 gLoc[1]=victim->coords.y;
3892                                                                                 gLoc[2]=victim->coords.z;
3893                                                                                 vel[0]=velocity.x;
3894                                                                                 vel[1]=velocity.y;
3895                                                                                 vel[2]=velocity.z;
3896                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
3897                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
3898                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 512);
3899                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
3900                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3901                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
3902                                                                         }
3903                                                                 }
3904
3905                                                                 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3906                                                                         escapednum=0;
3907                                                                         victim->velocity=0;
3908                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3909                                                                                 victim->skeleton.joints[i].velocity=0;
3910                                                                         }
3911                                                                         if(targetanimation==knifefollowanim){
3912                                                                                 victim->RagDoll(0);
3913                                                                                 for(i=0;i<victim->skeleton.num_joints;i++){
3914                                                                                         victim->skeleton.joints[i].velocity=0;
3915                                                                                 }
3916                                                                         }
3917                                                                         if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3918                                                                                 float gLoc[3];
3919                                                                                 float vel[3];
3920                                                                                 gLoc[0]=victim->coords.x;
3921                                                                                 gLoc[1]=victim->coords.y;
3922                                                                                 gLoc[2]=victim->coords.z;
3923                                                                                 vel[0]=velocity.x;
3924                                                                                 vel[1]=velocity.y;
3925                                                                                 vel[2]=velocity.z;
3926                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
3927                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
3928                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 512);
3929                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
3930                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3931                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
3932
3933                                                                                 XYZ footvel,footpoint;
3934                                                                                 footvel=0;
3935                                                                                 footpoint=weapons.tippoint[weaponids[0]];
3936                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3937                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3938                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3939                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3940                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3941                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3942                                                                         }
3943                                                                 }
3944
3945                                                                 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3946                                                                         if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3947                                                                                 award_bonus(id, backstab);
3948
3949                                                                                 escapednum=0;
3950
3951                                                                                 XYZ footvel,footpoint;
3952                                                                                 footvel=0;
3953                                                                                 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3954                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3955                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3956                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3957                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3958                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3959                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3960                                                                                 victim->DoBloodBig(200,180);
3961                                                                                 victim->DoBloodBig(200,215);
3962                                                                                 victim->bloodloss+=10000;
3963                                                                                 victim->velocity=0;
3964                                                                                 float gLoc[3];
3965                                                                                 float vel[3];
3966                                                                                 gLoc[0]=victim->coords.x;
3967                                                                                 gLoc[1]=victim->coords.y;
3968                                                                                 gLoc[2]=victim->coords.z;
3969                                                                                 vel[0]=velocity.x;
3970                                                                                 vel[1]=velocity.y;
3971                                                                                 vel[2]=velocity.z;
3972                                                                                 PlaySoundEx( fleshstabsound, samp[fleshstabsound], NULL, true);
3973                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabsound], gLoc, vel);
3974                                                                                 OPENAL_SetVolume(channels[fleshstabsound], 512);
3975                                                                                 OPENAL_SetPaused(channels[fleshstabsound], false);
3976                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3977                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
3978                                                                         }
3979                                                                 }
3980
3981                                                                 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3982                                                                         escapednum=0;
3983                                                                         victim->velocity=0;
3984                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
3985                                                                                 victim->skeleton.joints[i].velocity=0;
3986                                                                         }
3987                                                                         if(weaponactive!=-1){
3988                                                                                 float gLoc[3];
3989                                                                                 float vel[3];
3990                                                                                 gLoc[0]=victim->coords.x;
3991                                                                                 gLoc[1]=victim->coords.y;
3992                                                                                 gLoc[2]=victim->coords.z;
3993                                                                                 vel[0]=velocity.x;
3994                                                                                 vel[1]=velocity.y;
3995                                                                                 vel[2]=velocity.z;
3996                                                                                 PlaySoundEx( fleshstabremovesound, samp[fleshstabremovesound], NULL, true);
3997                                                                                 OPENAL_3D_SetAttributes(channels[fleshstabremovesound], gLoc, vel);
3998                                                                                 OPENAL_SetVolume(channels[fleshstabremovesound], 512);
3999                                                                                 OPENAL_SetPaused(channels[fleshstabremovesound], false);
4000                                                                                 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
4001                                                                                 weapons.blooddrip[weaponids[weaponactive]]+=5;
4002
4003                                                                                 XYZ footvel,footpoint;
4004                                                                                 footvel=0;
4005                                                                                 footpoint=weapons.tippoint[weaponids[0]];
4006                                                                                 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
4007                                                                                 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
4008                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4009                                                                                 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
4010                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
4011                                                                                 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
4012                                                                         }
4013                                                                 }
4014
4015                                                                 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
4016                                                                         escapednum=0;
4017                                                                         if(id==0)camerashake+=.4;
4018                                                                         if(Random()%2){
4019                                                                                 victim->spurt=1;
4020                                                                                 DoBlood(.2,240);
4021                                                                         }
4022                                                                         float gLoc[3];
4023                                                                         float vel[3];
4024                                                                         gLoc[0]=victim->coords.x;
4025                                                                         gLoc[1]=victim->coords.y;
4026                                                                         gLoc[2]=victim->coords.z;
4027                                                                         vel[0]=velocity.x;
4028                                                                         vel[1]=velocity.y;
4029                                                                         vel[2]=velocity.z;
4030                                                                         if(weaponactive==-1){
4031                                                                                 if(tutoriallevel!=1){
4032                                                                                         PlaySoundEx( heavyimpactsound, samp[heavyimpactsound], NULL, true);
4033                                                                                         OPENAL_3D_SetAttributes(channels[heavyimpactsound], gLoc, vel);
4034                                                                                         OPENAL_SetVolume(channels[heavyimpactsound], 128);
4035                                                                                         OPENAL_SetPaused(channels[heavyimpactsound], false);
4036                                                                                 }
4037                                                                         }
4038                                                                         bool doslice;
4039                                                                         doslice=0;
4040                                                                         if(weaponactive!=-1||creature==wolftype)doslice=1;
4041                                                                         if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
4042                                                                         if(doslice){
4043                                                                                 if(weaponactive!=-1){
4044                                                                                         victim->DoBloodBig(2/victim->armorhead,225);
4045                                                                                         PlaySoundEx( knifeslicesound, samp[knifeslicesound], NULL, true);
4046                                                                                         OPENAL_3D_SetAttributes(channels[knifeslicesound], gLoc, vel);
4047                                                                                         OPENAL_SetVolume(channels[knifeslicesound], 512);
4048                                                                                         OPENAL_SetPaused(channels[knifeslicesound], false);
4049                                                                                         if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
4050                                                                                         weapons.blooddrip[weaponids[weaponactive]]+=3;
4051                                                                                 }
4052                                                                                 if(weaponactive==-1&&creature==wolftype){
4053                                                                                         PlaySoundEx( clawslicesound, samp[clawslicesound], NULL, true);
4054                                                                                         OPENAL_3D_SetAttributes(channels[clawslicesound], gLoc, vel);
4055                                                                                         OPENAL_SetVolume(channels[clawslicesound], 128);
4056                                                                                         OPENAL_SetPaused(channels[clawslicesound], false);
4057                                                                                         victim->spurt=1;
4058                                                                                         victim->DoBloodBig(2/victim->armorhead,175);
4059                                                                                 }
4060                                                                         }
4061
4062                                                                         award_bonus(id, Reversal);
4063
4064                                                                         victim->Puff(neck);
4065
4066                                                                         XYZ relative;
4067                                                                         //relative=victim->coords-oldcoords;
4068                                                                         relative=facing*-1;
4069                                                                         relative.y=0;
4070                                                                         Normalise(&relative);
4071                                                                         relative=DoRotation(relative,0,90,0);
4072                                                                         relative.y=.5;
4073                                                                         Normalise(&relative);
4074                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4075                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
4076                                                                         }
4077                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
4078                                                                         if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
4079                                                                         victim->DoDamage(damagemult*100/victim->protectionhead);
4080                                                                         victim->velocity=0;
4081                                                                 }
4082
4083                                                                 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
4084                                                                         escapednum=0;
4085                                                                         victim->RagDoll(0);
4086                                                                         XYZ relative;
4087                                                                         //relative=victim->coords-oldcoords;
4088                                                                         relative=facing*-1;
4089                                                                         relative.y=0;
4090                                                                         Normalise(&relative);
4091                                                                         relative=DoRotation(relative,0,90,0);
4092                                                                         relative.y=.5;
4093                                                                         Normalise(&relative);
4094                                                                         for(i=0;i<victim->skeleton.num_joints;i++){
4095                                                                                 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
4096                                                                         }
4097                                                                         victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
4098                                                                 }
4099
4100                                                                 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
4101                                                                         if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
4102                                                                           award_bonus(id, reverseko);
4103                                                                         }
4104                                                         }
4105
4106
4107                                                         //Animation end
4108                                                         if(targetframe>animation[currentanimation].numframes-1){
4109                                                                 targetframe=0;
4110                                                                 if(wasStop()){
4111                                                                         targetanimation=getIdle();
4112                                                                         FootLand(0,1);
4113                                                                         FootLand(1,1);
4114                                                                 }
4115                                                                 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
4116                                                                         targetanimation=rollanim;
4117                                                                         targetframe=3;
4118                                                                         float gLoc[3];
4119                                                                         float vel[3];
4120                                                                         gLoc[0]=coords.x;
4121                                                                         gLoc[1]=coords.y;
4122                                                                         gLoc[2]=coords.z;
4123                                                                         vel[0]=velocity.x;
4124                                                                         vel[1]=velocity.y;
4125                                                                         vel[2]=velocity.z;
4126
4127                                                                         PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
4128                                                                         OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
4129                                                                         OPENAL_SetVolume(channels[movewhooshsound], 128);
4130                                                                         OPENAL_SetPaused(channels[movewhooshsound], false);
4131                                                                 }
4132                                                                 if(currentanimation==staggerbackhighanim){
4133                                                                         targetanimation=getIdle();
4134                                                                 }
4135                                                                 if(currentanimation==staggerbackhardanim){
4136                                                                         targetanimation=getIdle();
4137                                                                 }
4138                                                                 if(currentanimation==removeknifeanim){
4139                                                                         targetanimation=getIdle();
4140                                                                 }
4141                                                                 if(currentanimation==crouchremoveknifeanim){
4142                                                                         targetanimation=getCrouch();
4143                                                                 }
4144                                                                 if(currentanimation==backhandspringanim){
4145                                                                         targetanimation=getIdle();
4146                                                                 }
4147                                                                 if(currentanimation==dodgebackanim){
4148                                                                         targetanimation=getIdle();
4149                                                                 }
4150                                                                 if(currentanimation==drawleftanim){
4151                                                                         targetanimation=getIdle();
4152                                                                 }
4153                                                                 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
4154                                                                         targetanimation=getIdle();
4155                                                                         if(currentanimation==crouchdrawrightanim){
4156                                                                                 targetanimation=getCrouch();
4157                                                                         }
4158                                                                         if(weaponactive==-1)weaponactive=0;
4159                                                                         else if(weaponactive==0){
4160                                                                                 weaponactive=-1;
4161                                                                                 if(num_weapons==2){
4162                                                                                         int buffer;
4163                                                                                         buffer=weaponids[0];
4164                                                                                         weaponids[0]=weaponids[1];
4165                                                                                         weaponids[1]=buffer;
4166                                                                                 }
4167                                                                         }
4168
4169                                                                         if(weaponactive==-1){
4170                                                                                 float gLoc[3];
4171                                                                                 float vel[3];
4172                                                                                 gLoc[0]=coords.x;
4173                                                                                 gLoc[1]=coords.y;
4174                                                                                 gLoc[2]=coords.z;
4175                                                                                 vel[0]=velocity.x;
4176                                                                                 vel[1]=velocity.y;
4177                                                                                 vel[2]=velocity.z;
4178
4179                                                                                 PlaySoundEx( knifesheathesound, samp[knifesheathesound], NULL, true);
4180                                                                                 OPENAL_3D_SetAttributes(channels[knifesheathesound], gLoc, vel);
4181                                                                                 OPENAL_SetVolume(channels[knifesheathesound], 128);
4182                                                                                 OPENAL_SetPaused(channels[knifesheathesound], false);
4183                                                                         }
4184                                                                         if(weaponactive!=-1){
4185                                                                                 float gLoc[3];
4186                                                                                 float vel[3];
4187                                                                                 gLoc[0]=coords.x;
4188                                                                                 gLoc[1]=coords.y;
4189                                                                                 gLoc[2]=coords.z;
4190                                                                                 vel[0]=velocity.x;
4191                                                                                 vel[1]=velocity.y;
4192                                                                                 vel[2]=velocity.z;
4193
4194                                                                                 PlaySoundEx( knifedrawsound, samp[knifedrawsound], NULL, true);
4195                                                                                 OPENAL_3D_SetAttributes(channels[knifedrawsound], gLoc, vel);
4196                                                                                 OPENAL_SetVolume(channels[knifedrawsound], 128);
4197                                                                                 OPENAL_SetPaused(channels[knifedrawsound], false);
4198                                                                         }
4199                                                                 }
4200                                                                 if(currentanimation==rollanim){
4201                                                                         targetanimation=getCrouch();
4202                                                                         FootLand(0,1);
4203                                                                         FootLand(1,1);
4204                                                                 }
4205                                                                 if(isFlip()){
4206                                                                         if(targetanimation==walljumprightkickanim){
4207                                                                                 targetrot=-190;
4208                                                                         }
4209                                                                         if(targetanimation==walljumpleftkickanim){
4210                                                                                 targetrot=190;
4211                                                                         }
4212                                                                         targetanimation=jumpdownanim;
4213                                                                 }
4214                                                                 if(currentanimation==climbanim){
4215                                                                         targetanimation=getCrouch();
4216                                                                         targetframe=1;
4217                                                                         coords+=facing*.1;
4218                                                                         if(!isnormal(coords.x))
4219                                                                                 coords=oldcoords;
4220                                                                         oldcoords=coords;
4221                                                                         collided=0;
4222                                                                         targetoffset=0;
4223                                                                         currentoffset=0;
4224                                                                         grabdelay=1;
4225                                                                         velocity=0;
4226                                                                         collided=0;
4227                                                                         avoidcollided=0;
4228                                                                 }
4229                                                                 if(targetanimation==rabbitkickreversalanim){
4230                                                                         targetanimation=getCrouch();
4231                                                                         lastfeint=0;
4232                                                                 }
4233                                                                 if(targetanimation==jumpreversalanim){
4234                                                                         targetanimation=getCrouch();
4235                                                                         lastfeint=0;
4236                                                                 }
4237                                                                 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
4238                                                                         if(attackkeydown&&targetanimation!=walljumpfrontanim){
4239                                                                                 int closest=-1;
4240                                                                                 float closestdist=-1;
4241                                                                                 float distance;
4242                                                                                 if(numplayers>1)
4243                                                                                         for(i=0;i<numplayers;i++){
4244                                                                                                 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
4245                                                                                                         distance=findDistancefast(&player[i].coords,&coords);
4246                                                                                                         if(closestdist==-1||distance<closestdist){
4247                                                                                                                 closestdist=distance;
4248                                                                                                                 closest=i;
4249                                                                                                         }
4250                                                                                                 }
4251                                                                                         }
4252                                                                                         if(closestdist>0&&closest>=0&&closestdist<16){
4253                                                                                                 victim=&player[closest];
4254                                                                                                 targetanimation=walljumprightkickanim;
4255                                                                                                 targetframe=0;
4256                                                                                                 XYZ rotatetarget=victim->coords-coords;
4257                                                                                                 Normalise(&rotatetarget);
4258                                                                                                 rotation=-asin(0-rotatetarget.x);
4259                                                                                                 rotation*=360/6.28;
4260                                                                                                 if(rotatetarget.z<0)rotation=180-rotation;
4261                                                                                                 targettilt2=-asin(rotatetarget.y)*360/6.28;
4262                                                                                                 velocity=(victim->coords-coords)*4;
4263                                                                                                 velocity.y+=2;
4264                                                                                                 transspeed=40;
4265                                                                                         }
4266                                                                         }
4267                                                                         if(targetanimation==walljumpbackanim){
4268                                                                                 targetanimation=backflipanim;
4269                                                                                 targetframe=3;
4270                                                                                 velocity=facing*-8;
4271                                                                                 velocity.y=4;
4272                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4273                                                                         }
4274                                                                         if(targetanimation==walljumprightanim){
4275                                                                                 targetanimation=rightflipanim;
4276                                                                                 targetframe=4;
4277                                                                                 targetrotation-=90;
4278                                                                                 rotation-=90;
4279                                                                                 velocity=DoRotation(facing,0,30,0)*-8;
4280                                                                                 velocity.y=4;
4281                                                                         }
4282                                                                         if(targetanimation==walljumpfrontanim){
4283                                                                                 targetanimation=frontflipanim;
4284                                                                                 targetframe=2;
4285                                                                                 //targetrotation-=180;
4286                                                                                 ////rotation-=180;
4287                                                                                 velocity=facing*8;
4288                                                                                 velocity.y=4;
4289                                                                         }
4290                                                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4291                                                                 }
4292                                                                 if(targetanimation==walljumpleftanim){
4293                                                                         if(attackkeydown){
4294                                                                                 int closest=-1;
4295                                                                                 float closestdist=-1;
4296                                                                                 float distance;
4297                                                                                 if(numplayers>1)
4298                                                                                         for(i=0;i<numplayers;i++){
4299                                                                                                 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
4300                                                                                                         distance=findDistancefast(&player[i].coords,&coords);
4301                                                                                                         if(closestdist==-1||distance<closestdist){
4302                                                                                                                 closestdist=distance;
4303                                                                                                                 closest=i;
4304                                                                                                         }
4305                                                                                                 }
4306                                                                                         }
4307                                                                                         if(closestdist>0&&closest>=0&&closestdist<16){
4308                                                                                                 victim=&player[closest];
4309                                                                                                 targetanimation=walljumpleftkickanim;
4310                                                                                                 targetframe=0;
4311                                                                                                 XYZ rotatetarget=victim->coords-coords;
4312                                                                                                 Normalise(&rotatetarget);
4313                                                                                                 rotation=-asin(0-rotatetarget.x);
4314                                                                                                 rotation*=360/6.28;
4315                                                                                                 if(rotatetarget.z<0)rotation=180-rotation;
4316                                                                                                 targettilt2=-asin(rotatetarget.y)*360/6.28;
4317                                                                                                 velocity=(victim->coords-coords)*4;
4318                                                                                                 velocity.y+=2;
4319                                                                                                 transspeed=40;
4320                                                                                         }
4321                                                                         }
4322                                                                         if(targetanimation!=walljumpleftkickanim){
4323                                                                                 targetanimation=leftflipanim;
4324                                                                                 targetframe=4;
4325                                                                                 targetrotation+=90;
4326                                                                                 rotation+=90;
4327                                                                                 velocity=DoRotation(facing,0,-30,0)*-8;
4328                                                                                 velocity.y=4;
4329                                                                         }
4330                                                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
4331                                                                 }
4332                                                                 if(targetanimation==sneakattackanim){
4333                                                                         float ycoords=oldcoords.y;
4334                                                                         currentanimation=getCrouch();
4335                                                                         targetanimation=getCrouch();
4336                                                                         targetframe=1;
4337                                                                         currentframe=0;
4338                                                                         targetrotation+=180;
4339                                                                         rotation+=180;
4340                                                                         targettilt2*=-1;
4341                                                                         tilt2*=-1;
4342                                                                         transspeed=1000000;
4343                                                                         targetheadrotation+=180;
4344                                                                         coords-=facing*.7;
4345                                                                         if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
4346
4347                                                                         lastfeint=0;
4348                                                                 }
4349                                                                 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
4350                                                                         float ycoords=oldcoords.y;
4351                                                                         targetanimation=getIdle();
4352                                                                         targetframe=0;
4353                                                                         if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
4354
4355                                                                         lastfeint=0;
4356                                                                 }
4357                                                                 if(currentanimation==knifefollowanim){
4358                                                                         targetanimation=getIdle();
4359                                                                         lastfeint=0;
4360                                                                 }
4361                                                                 if(animation[targetanimation].attack==reversal&&currentanimation!=sneakattackanim&&currentanimation!=knifesneakattackanim&&currentanimation!=swordsneakattackanim&&currentanimation!=knifefollowanim){
4362                                                                         float ycoords=oldcoords.y;
4363                                                                         targetanimation=getStop();
4364                                                                         targetrotation+=180;
4365                                                                         rotation+=180;
4366                                                                         targettilt2*=-1;
4367                                                                         tilt2*=-1;
4368                                                                         transspeed=1000000;
4369                                                                         targetheadrotation+=180;
4370                                                                         if(!isnormal(coords.x))
4371                                                                                 coords=oldcoords;
4372                                                                         if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
4373                                                                                 oldcoords=coords+facing*.5;
4374                                                                         else if(currentanimation==sweepreversalanim)
4375                                                                                 oldcoords=coords+facing*1.1;
4376                                                                         else if(currentanimation==upunchreversalanim){
4377                                                                                 oldcoords=coords+facing*1.5;
4378                                                                                 targetrotation+=180;
4379                                                                                 rotation+=180;
4380                                                                                 targetheadrotation+=180;
4381                                                                                 targettilt2*=-1;
4382                                                                                 tilt2*=-1;
4383                                                                         }
4384                                                                         else if(currentanimation==knifeslashreversalanim){
4385                                                                                 oldcoords=coords+facing*.5;
4386                                                                                 targetrotation+=90;
4387                                                                                 rotation+=90;
4388                                                                                 targetheadrotation+=90;
4389                                                                                 targettilt2=0;
4390                                                                                 tilt2=0;
4391                                                                         }
4392                                                                         else if(currentanimation==staffspinhitreversalanim){
4393                                                                                 targetrotation+=180;
4394                                                                                 rotation+=180;
4395                                                                                 targetheadrotation+=180;
4396                                                                                 targettilt2=0;
4397                                                                                 tilt2=0;
4398                                                                         }
4399                                                                         if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
4400                                                                         else oldcoords.y=ycoords;
4401                                                                         currentoffset=coords-oldcoords;
4402                                                                         targetoffset=0;
4403                                                                         coords=oldcoords;
4404
4405                                                                         lastfeint=0;
4406                                                                 }
4407                                                                 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
4408                                                                         velocity=0;
4409                                                                         velocity.y=-5;
4410                                                                         RagDoll(0);
4411                                                                 }
4412                                                                 if(animation[targetanimation].attack==reversed){
4413                                                                         escapednum++;
4414                                                                         if(targetanimation==sweepreversedanim)targetrotation+=90;
4415                                                                         targetanimation=backhandspringanim;
4416                                                                         targetframe=2;
4417                                                                         float gLoc[3];
4418                                                                         float vel[3];
4419                                                                         gLoc[0]=coords.x;
4420                                                                         gLoc[1]=coords.y;
4421                                                                         gLoc[2]=coords.z;
4422                                                                         vel[0]=velocity.x;
4423                                                                         vel[1]=velocity.y;
4424                                                                         vel[2]=velocity.z;
4425                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
4426                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
4427                                                                         OPENAL_SetVolume(channels[landsound], 128);
4428                                                                         OPENAL_SetPaused(channels[landsound], false);
4429
4430                                                                         if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
4431                                                                                 targetanimation=rollanim;
4432                                                                                 targetframe=5;
4433                                                                                 oldcoords=coords;
4434                                                                                 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4435                                                                                 coords.y=oldcoords.y;
4436                                                                         }
4437                                                                         if(currentanimation==knifeslashreversedanim){
4438                                                                                 targetanimation=rollanim;
4439                                                                                 targetframe=0;
4440                                                                                 targetrotation+=90;
4441                                                                                 rotation+=90;
4442                                                                                 oldcoords=coords;
4443                                                                                 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4444                                                                                 coords.y=oldcoords.y;
4445                                                                         }
4446                                                                 }
4447                                                                 if(wasFlip()){
4448                                                                         targetanimation=jumpdownanim;
4449                                                                 }
4450                                                                 if(wasLanding())targetanimation=getIdle();
4451                                                                 if(wasLandhard())targetanimation=getIdle();
4452                                                                 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
4453                                                                         targetanimation=getIdle();
4454                                                                         oldcoords=coords;
4455                                                                         coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
4456                                                                         coords.y=oldcoords.y;
4457                                                                         //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
4458                                                                         targetoffset.y=coords.y;
4459                                                                         if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
4460                                                                         currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
4461                                                                         currentoffset.y-=(coords.y-targetoffset.y);
4462                                                                         coords.y=targetoffset.y;
4463                                                                         targetoffset=0;
4464                                                                         normalsupdatedelay=0;
4465                                                                 }
4466                                                                 if(currentanimation==upunchanim){
4467                                                                         targetanimation=getStop();
4468                                                                         normalsupdatedelay=0;
4469                                                                         lastfeint=0;
4470                                                                 }
4471                                                                 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
4472                                                                         targetrotation=rotation;
4473                                                                         bool hasstaff;
4474                                                                         hasstaff=0;
4475                                                                         if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4476                                                                         if(!hasstaff)DoDamage(35);
4477                                                                         RagDoll(0);
4478                                                                         lastfeint=0;
4479                                                                         rabbitkickragdoll=1;
4480                                                                 }
4481                                                                 if(currentanimation==rabbitkickreversedanim){
4482                                                                         if(!feint){
4483                                                                                 velocity=0;
4484                                                                                 velocity.y=-10;
4485                                                                                 //DoDamage(100);
4486                                                                                 RagDoll(0);
4487                                                                                 skeleton.spinny=0;
4488                                                                                 if(id!=0)SolidHitBonus();
4489                                                                         }
4490                                                                         if(feint){
4491                                                                                 escapednum++;
4492                                                                                 targetanimation=rollanim;
4493                                                                                 coords+=facing;
4494                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4495                                                                         }
4496                                                                         lastfeint=0;
4497                                                                 }
4498                                                                 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
4499                                                                         velocity=0;
4500                                                                         velocity.y=-10;
4501                                                                         RagDoll(0);
4502                                                                         skeleton.spinny=0;
4503                                                                 }
4504                                                                 if(currentanimation==jumpreversedanim){
4505                                                                         if(!feint){
4506                                                                                 velocity=0;
4507                                                                                 velocity.y=-10;
4508                                                                                 //DoDamage(100);
4509                                                                                 RagDoll(0);
4510                                                                                 skeleton.spinny=0;
4511                                                                                 if(id!=0)SolidHitBonus();
4512                                                                         }
4513                                                                         if(feint){
4514                                                                                 escapednum++;
4515                                                                                 targetanimation=rollanim;
4516                                                                                 coords+=facing*2;
4517                                                                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4518                                                                         }
4519                                                                         lastfeint=0;
4520                                                                 }
4521
4522                                                                 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){
4523                                                                         targetanimation=getupfromfrontanim;
4524                                                                         lastfeint=0;
4525                                                                 }
4526                                                                 else if(animation[currentanimation].attack==normalattack){
4527                                                                         targetanimation=getIdle();
4528                                                                         lastfeint=0;
4529                                                                 }
4530                                                                 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
4531                                                                         targetanimation=blockhighleftstrikeanim;
4532                                                                 }
4533                                                                 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
4534                                                                         targetanimation=getIdle();
4535                                                                         lastfeint=0;
4536                                                                 }
4537                                                                 if(currentanimation==spinkickanim&&victim->skeleton.free){
4538                                                                         if(creature==rabbittype)targetanimation=fightidleanim;
4539                                                                 }
4540                                                         }
4541                                                         target=0;
4542
4543                                                         if(isIdle()&&!wasIdle())normalsupdatedelay=0;
4544
4545                                                         if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
4546                                                                 targetanimation=jumpdownanim;
4547                                                         }
4548                 }
4549                 if(!skeleton.free){
4550                         oldtarget=target;
4551                         if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
4552                                 if(!isRun()||!wasRun()){
4553                                         if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
4554                                                 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
4555                                         if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
4556                                                 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
4557                                 }
4558                                 if(isRun()&&wasRun()){
4559                                         float tempspeed;
4560                                         tempspeed=velspeed;
4561                                         if(tempspeed<10*speedmult)tempspeed=10*speedmult;
4562                                         target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
4563                                 }
4564                         }
4565                         else if(transspeed)target+=multiplier*transspeed*speed*2;
4566                         else{
4567                                 if(!isRun()||!wasRun()){
4568                                         if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
4569                                                 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
4570                                         if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
4571                                                 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
4572                                 }
4573                         }
4574
4575                         if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
4576
4577                         if(target>1){currentframe=targetframe; target=1;}
4578                         oldrot=rot;
4579                         rot=targetrot*target;
4580                         rotation+=rot-oldrot;
4581                         if(target==1){
4582                                 rot=0;
4583                                 oldrot=0;
4584                                 targetrot=0;
4585                         }
4586                         if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
4587                                 //Old rotates
4588                                 for(i=0;i<skeleton.num_joints;i++){
4589                                         skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
4590                                 }
4591
4592                                 skeleton.FindForwards();
4593
4594                                 for(i=0;i<skeleton.num_muscles;i++){
4595                                         if(skeleton.muscles[i].visible)
4596                                         {
4597                                                 skeleton.FindRotationMuscle(i,targetanimation);
4598                                         }
4599                                 }
4600                                 for(i=0;i<skeleton.num_muscles;i++){
4601                                         if(skeleton.muscles[i].visible)
4602                                         {
4603                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
4604                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
4605                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
4606                                         }
4607                                 }
4608
4609                                 //New rotates
4610                                 for(i=0;i<skeleton.num_joints;i++){
4611                                         skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
4612                                 }
4613
4614                                 skeleton.FindForwards();
4615
4616                                 for(i=0;i<skeleton.num_muscles;i++){
4617                                         if(skeleton.muscles[i].visible)
4618                                         {
4619                                                 skeleton.FindRotationMuscle(i,targetanimation);
4620                                         }
4621                                 }
4622                                 for(i=0;i<skeleton.num_muscles;i++){
4623                                         if(skeleton.muscles[i].visible)
4624                                         {
4625                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
4626                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
4627                                                 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
4628                                                 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
4629                                                 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
4630                                                 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
4631                                                 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
4632                                                 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
4633                                                 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
4634                                         }
4635                                 }
4636                         }
4637                         if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
4638
4639                         oldcurrentanimation=currentanimation;
4640                         oldtargetanimation=targetanimation;
4641                         oldtargetframe=targetframe;
4642                         oldcurrentframe=currentframe;
4643
4644                         for(i=0;i<skeleton.num_joints;i++){
4645                                 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
4646                                 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
4647                         }
4648                         offset=currentoffset*(1-target)+targetoffset*target;
4649                         for(i=0;i<skeleton.num_muscles;i++){
4650                                 if(skeleton.muscles[i].visible)
4651                                 {
4652                                         skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
4653                                         skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
4654                                         skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
4655                                 }
4656                         }
4657                 }
4658
4659                 if(isLanding()&&landhard){
4660                         //if(abs(velocity.y)>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z)){
4661                         if(id==0)camerashake+=.4;
4662                         targetanimation=getLandhard();
4663                         targetframe=0;
4664                         target=0;
4665                         landhard=0;
4666                         transspeed=15;
4667                         //}
4668                 }
4669         }
4670         //skeleton.DoConstraints();
4671 }
4672
4673 void    Person::DoStuff(){
4674         static XYZ terrainnormal;
4675         static XYZ flatfacing;
4676         static XYZ flatvelocity;
4677         static float flatvelspeed;
4678         static int i,j,l;
4679         static XYZ average;
4680         static int howmany;
4681         static int bloodsize;
4682         static int startx,starty,endx,endy;
4683         static int texdetailint;
4684         static GLubyte color;
4685         static XYZ bloodvel;
4686
4687         onfiredelay-=multiplier;
4688         if(onfiredelay<0&&onfire)
4689         {
4690                 if(Random()%2==0){
4691                         crouchkeydown=1;
4692                 }
4693                 onfiredelay=0.3;
4694         }
4695
4696         crouchkeydowntime+=multiplier;
4697         if(!crouchkeydown)crouchkeydowntime=0;
4698         jumpkeydowntime+=multiplier;
4699         if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
4700
4701         if(hostile||damage>0||bloodloss>0)immobile=0;
4702
4703         if(isIdle()||isRun())targetoffset=0;
4704
4705         if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
4706
4707         if(id==0)blooddimamount-=multiplier*.3;
4708         speechdelay-=multiplier;
4709         texupdatedelay-=multiplier;
4710         interestdelay-=multiplier;
4711         flamedelay-=multiplier;
4712         parriedrecently-=multiplier;
4713         if(!victim){
4714                 victim=this;
4715                 hasvictim=0;
4716         }
4717
4718         if(id==0)speed=1.1*speedmult;
4719         else speed=1.0*speedmult;
4720         if(!skeleton.free)rabbitkickragdoll=0;
4721
4722         speed*=speedmult;
4723
4724         if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
4725         if(id!=0&&creature==wolftype&&difficulty==2){
4726                 superruntoggle=0;
4727                 if(aitype!=passivetype){
4728                         superruntoggle=1;
4729                         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){
4730                                 superruntoggle=0;
4731                         }
4732                 }
4733                 if(scale<0.2)superruntoggle=0;
4734                 if(targetanimation==wolfrunninganim&&!superruntoggle){
4735                         targetanimation=getRun();
4736                         targetframe=0;
4737                 }
4738         }
4739         if(weaponactive==-1&&num_weapons>0){
4740                 if(weapons.type[weaponids[0]]==staff){
4741                         weaponactive=0;
4742                 }
4743         }
4744
4745         if(onfire){
4746                 burnt+=multiplier;
4747                 /*if(aitype!=playercontrolled)*///deathbleeding=5;
4748                 /*if(aitype!=playercontrolled)*/
4749                 deathbleeding=1;
4750                 if(burnt>.6)burnt=.6;
4751                 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
4752
4753                 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
4754                         float gLoc[3];
4755                         float vel[3];
4756                         gLoc[0]=coords.x;
4757                         gLoc[1]=coords.y;
4758                         gLoc[2]=coords.z;
4759                         vel[0]=velocity.x;
4760                         vel[1]=velocity.y;
4761                         vel[2]=velocity.z;
4762
4763                         if(id==0){
4764                                 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4765                                 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
4766                         }
4767                 }
4768         }
4769         while(flamedelay<0&&onfire){
4770                 flamedelay+=.006;
4771                 howmany=abs(Random()%(skeleton.num_joints));
4772                 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4773                 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4774                 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4775                 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4776                 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
4777         }
4778
4779         while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
4780                 flamedelay+=.05;
4781                 howmany=abs(Random()%(skeleton.num_joints));
4782                 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4783                 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4784                 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4785                 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4786                 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
4787         }
4788
4789         if(bleeding>0){
4790                 bleeding-=multiplier*.3;
4791                 if(bloodtoggle==2){
4792                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4793                         if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
4794                 }
4795         }
4796
4797         if(neckspurtamount>0){
4798                 neckspurtamount-=multiplier;
4799                 neckspurtdelay-=multiplier*3;
4800                 neckspurtparticledelay-=multiplier*3;
4801                 if(neckspurtparticledelay<0&&neckspurtdelay>2){
4802                         spurt=0;
4803                         bloodvel=0;
4804                         if(!skeleton.free){
4805                                 bloodvel.z=5*neckspurtamount;
4806                                 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4807                         }
4808                         if(skeleton.free){
4809                                 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
4810                         }
4811                         if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4812                         if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
4813                         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);
4814                         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);
4815                         neckspurtparticledelay=.05;
4816                 }
4817                 if(neckspurtdelay<0){
4818                         neckspurtdelay=3;
4819                 }
4820         }
4821
4822         if(deathbleeding>0&&dead!=2){
4823                 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
4824                 else bleeddelay-=5*multiplier/4;
4825                 if(bleeddelay<0&&bloodtoggle){
4826                         bleeddelay=1;
4827                         XYZ bloodvel;
4828                         if(bloodtoggle){
4829                                 bloodvel=0;
4830                                 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
4831                                 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
4832                                 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
4833                                 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);
4834                         }
4835                 }
4836                 bloodloss+=deathbleeding*multiplier*80;
4837                 deathbleeding-=multiplier*1.6;
4838                 //if(id==0)deathbleeding-=multiplier*.2;
4839                 if(deathbleeding<0)deathbleeding=0;
4840                 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
4841                         if(weaponactive!=-1){
4842                                 weapons.owner[weaponids[0]]=-1;
4843                                 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4844                                 weapons.velocity[weaponids[0]].x+=.01;
4845                                 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4846                                 weapons.missed[weaponids[0]]=1;
4847                                 weapons.hitsomething[weaponids[0]]=0;
4848                                 weapons.freetime[weaponids[0]]=0;
4849                                 weapons.firstfree[weaponids[0]]=1;
4850                                 weapons.physics[weaponids[0]]=1;
4851                                 num_weapons--;
4852                                 if(num_weapons){
4853                                         weaponids[0]=weaponids[num_weapons];
4854                                         if(weaponstuck==num_weapons)weaponstuck=0;
4855                                 }
4856                                 weaponactive=-1;
4857                                 for(i=0;i<numplayers;i++){
4858                                         player[i].wentforweapon=0;
4859                                 }
4860
4861                                 if(id==0){
4862                                         flashamount=.5;
4863                                         flashr=1;
4864                                         flashg=0;
4865                                         flashb=0;
4866                                         flashdelay=0;
4867                                 }
4868                         }
4869
4870                         if(!dead&&creature==wolftype){
4871                           award_bonus(0, Wolfbonus);
4872                         }
4873                         dead=2;
4874                         if(targetanimation==knifefollowedanim&&!skeleton.free){
4875                                 for(i=0;i<skeleton.num_joints;i++){
4876                                         skeleton.joints[i].velocity=0;
4877                                         skeleton.joints[i].velocity.y=-2;
4878                                 }
4879                         }
4880                         if(id!=0&&unconscioustime>.1){
4881                                 numafterkill++;
4882                         }
4883
4884                         RagDoll(0);
4885                 }
4886         }
4887
4888         if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
4889                 texupdatedelay=.12;
4890
4891                 bloodsize=5-realtexdetail;
4892
4893                 startx=0;
4894                 starty=0;
4895                 texdetailint=realtexdetail;
4896                 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4897                 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4898                 endx=startx+bloodsize;
4899                 endy=starty+bloodsize;
4900
4901                 if(startx<0){startx=0;bleeding=0;}
4902                 if(starty<0){starty=0;bleeding=0;}
4903                 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
4904                 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
4905                 if(endx<startx)endx=startx;
4906                 if(endy<starty)endy=starty;
4907
4908                 for(i=startx;i<endx;i++){
4909                         for(j=starty;j<endy;j++){
4910                                 if(Random()%2==0){
4911                                         color=Random()%85+170;
4912                                         if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
4913                                         skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
4914                                         skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
4915                                 }
4916                         }
4917                 }
4918                 if(!osx&&detail>1){
4919                         glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4920                         DoMipmaps(0,startx,endx,starty,endy);
4921                 }
4922
4923                 if(!skeleton.free){
4924                         bleedy-=4/realtexdetail;
4925                         if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
4926                         else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
4927                 }
4928                 if(skeleton.free){
4929                         bleedx+=4*direction/realtexdetail;
4930                         if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
4931                         else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4932                 }
4933         }
4934
4935         if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4936                 righthandmorphness=targetrighthandmorphness;
4937                 righthandmorphstart=righthandmorphend;
4938         }
4939         else if(righthandmorphness>targetrighthandmorphness){
4940                 righthandmorphness-=multiplier*4;
4941         }
4942         else if(righthandmorphness<targetrighthandmorphness){
4943                 righthandmorphness+=multiplier*4;
4944         }
4945
4946         if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4947                 lefthandmorphness=targetlefthandmorphness;
4948                 lefthandmorphstart=lefthandmorphend;
4949         }
4950         else if(lefthandmorphness>targetlefthandmorphness){
4951                 lefthandmorphness-=multiplier*4;
4952         }
4953         else if(lefthandmorphness<targetlefthandmorphness){
4954                 lefthandmorphness+=multiplier*4;
4955         }
4956
4957         if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4958                 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4959                         tailmorphness=targettailmorphness;
4960                         tailmorphstart=tailmorphend;
4961                 }
4962                 else if(tailmorphness>targettailmorphness){
4963                         tailmorphness-=multiplier*10;
4964                 }
4965                 else if(tailmorphness<targettailmorphness){
4966                         tailmorphness+=multiplier*10;
4967                 }
4968         }
4969
4970         if(creature==wolftype){
4971                 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4972                         tailmorphness=targettailmorphness;
4973                         tailmorphstart=tailmorphend;
4974                 }
4975                 else if(tailmorphness>targettailmorphness){
4976                         tailmorphness-=multiplier*2;
4977                 }
4978                 else if(tailmorphness<targettailmorphness){
4979                         tailmorphness+=multiplier*2;
4980                 }
4981         }
4982
4983         if(headmorphend==3||headmorphstart==3){
4984                 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4985                         headmorphness=targetheadmorphness;
4986                         headmorphstart=headmorphend;
4987                 }
4988                 else if(headmorphness>targetheadmorphness){
4989                         headmorphness-=multiplier*7;
4990                 }
4991                 else if(headmorphness<targetheadmorphness){
4992                         headmorphness+=multiplier*7;
4993                 }
4994         }
4995         else if(headmorphend==5||headmorphstart==5){
4996                 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4997                         headmorphness=targetheadmorphness;
4998                         headmorphstart=headmorphend;
4999                 }
5000                 else if(headmorphness>targetheadmorphness){
5001                         headmorphness-=multiplier*10;
5002                 }
5003                 else if(headmorphness<targetheadmorphness){
5004                         headmorphness+=multiplier*10;
5005                 }
5006         }
5007         else{
5008                 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
5009                         headmorphness=targetheadmorphness;
5010                         headmorphstart=headmorphend;
5011                 }
5012                 else if(headmorphness>targetheadmorphness){
5013                         headmorphness-=multiplier*4;
5014                 }
5015                 else if(headmorphness<targetheadmorphness){
5016                         headmorphness+=multiplier*4;
5017                 }
5018         }
5019
5020         if(abs(chestmorphness-targetchestmorphness)<multiplier){
5021                 chestmorphness=targetchestmorphness;
5022                 chestmorphstart=chestmorphend;
5023         }
5024         else if(chestmorphness>targetchestmorphness){
5025                 chestmorphness-=multiplier;
5026         }
5027         else if(chestmorphness<targetchestmorphness){
5028                 chestmorphness+=multiplier;
5029         }
5030
5031         if(dead!=2&&howactive<=typesleeping){
5032                 if(chestmorphstart==0&&chestmorphend==0){
5033                         chestmorphness=0;
5034                         targetchestmorphness=1;
5035                         chestmorphend=3;
5036                 }
5037                 if(chestmorphstart!=0&&chestmorphend!=0){
5038                         chestmorphness=0;
5039                         targetchestmorphness=1;
5040                         chestmorphend=0;
5041                         if(environment==snowyenvironment){
5042                                 XYZ footpoint;
5043                                 XYZ footvel;
5044                                 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
5045                                 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
5046                                 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
5047                                 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
5048                                 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
5049                                 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
5050                         }
5051                 }
5052
5053                 if(!dead&&howactive<typesleeping){
5054                         blinkdelay-=multiplier*2;
5055                         if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
5056                                 headmorphness=0;
5057                                 targetheadmorphness=1;
5058                                 headmorphend=3;
5059                                 blinkdelay=(float)(abs(Random()%40))/5;
5060                         }
5061                         if(headmorphstart==3&&headmorphend==3){
5062                                 headmorphness=0;
5063                                 targetheadmorphness=1;
5064                                 headmorphend=0;
5065                         }
5066                 }
5067                 if(!dead){
5068                         twitchdelay-=multiplier*1.5;
5069                         if(targetanimation!=hurtidleanim){
5070                                 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
5071                                         headmorphness=0;
5072                                         targetheadmorphness=1;
5073                                         headmorphend=5;
5074                                         twitchdelay=(float)(abs(Random()%40))/5;
5075                                 }
5076                                 if(headmorphstart==5&&headmorphend==5){
5077                                         headmorphness=0;
5078                                         targetheadmorphness=1;
5079                                         headmorphend=0;
5080                                 }
5081                         }
5082                         if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
5083                                 twitchdelay3-=multiplier*1;
5084                                 if(Random()%2==0){
5085                                         if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
5086                                                 righthandmorphness=0;
5087                                                 targetrighthandmorphness=1;
5088                                                 righthandmorphend=1;
5089                                                 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
5090                                         }
5091                                         if(righthandmorphstart==1&&righthandmorphend==1){
5092                                                 righthandmorphness=0;
5093                                                 targetrighthandmorphness=1;
5094                                                 righthandmorphend=0;
5095                                         }
5096                                 }
5097                                 if(Random()%2==0){
5098                                         if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
5099                                                 lefthandmorphness=0;
5100                                                 targetlefthandmorphness=1;
5101                                                 lefthandmorphend=1;
5102                                                 twitchdelay3=(float)(abs(Random()%40))/5;
5103                                         }
5104                                         if(lefthandmorphstart==1&&lefthandmorphend==1){
5105                                                 lefthandmorphness=0;
5106                                                 targetlefthandmorphness=1;
5107                                                 lefthandmorphend=0;
5108                                         }
5109                                 }
5110                         }
5111                 }
5112                 if(!dead){
5113                         if(creature==rabbittype){
5114                                 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
5115                                 else twitchdelay2-=multiplier*0.5;
5116                                 if(howactive<=typesleeping){
5117                                         if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
5118                                                 tailmorphness=0;
5119                                                 targettailmorphness=1;
5120                                                 tailmorphend=1;
5121                                                 twitchdelay2=(float)(abs(Random()%40))/5;
5122                                         }
5123                                         if(tailmorphstart==1&&tailmorphend==1){
5124                                                 tailmorphness=0;
5125                                                 targettailmorphness=1;
5126                                                 tailmorphend=2;
5127                                         }
5128                                         if(tailmorphstart==2&&tailmorphend==2){
5129                                                 tailmorphness=0;
5130                                                 targettailmorphness=1;
5131                                                 tailmorphend=0;
5132                                         }
5133                                 }
5134                         }
5135                 }
5136         }
5137         if(creature==wolftype){
5138                 twitchdelay2-=multiplier*1.5;
5139                 if(tailmorphend!=0)
5140                         if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
5141                                 tailmorphness=0;
5142                                 targettailmorphness=1;
5143                                 tailmorphend=0;
5144                                 twitchdelay2=.1;
5145                         }
5146                         if(tailmorphend!=5)
5147                                 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
5148                                         tailmorphness=0;
5149                                         targettailmorphness=1;
5150                                         tailmorphend=5;
5151                                         twitchdelay2=.1;
5152                                 }
5153                                 if(twitchdelay2<=0){
5154                                         if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
5155                                                 tailmorphness=0;
5156                                                 targettailmorphness=1;
5157                                                 tailmorphend=1;
5158                                         }
5159                                         if(tailmorphstart==1&&tailmorphend==1){
5160                                                 tailmorphness=0;
5161                                                 targettailmorphness=1;
5162                                                 tailmorphend=2;
5163                                         }
5164                                         if(tailmorphstart==2&&tailmorphend==2){
5165                                                 tailmorphness=0;
5166                                                 targettailmorphness=1;
5167                                                 tailmorphend=3;
5168                                         }
5169                                         if(tailmorphstart==3&&tailmorphend==3){
5170                                                 tailmorphness=0;
5171                                                 targettailmorphness=1;
5172                                                 tailmorphend=4;
5173                                         }
5174                                         if(tailmorphstart==4&&tailmorphend==4){
5175                                                 tailmorphness=0;
5176                                                 targettailmorphness=1;
5177                                                 tailmorphend=1;
5178                                         }
5179                                 }
5180         }
5181
5182         if(dead!=1)unconscioustime=0;
5183
5184         if(dead==1||howactive==typesleeping){
5185                 unconscioustime+=multiplier;
5186                 //If unconscious, close eyes and mouth
5187                 if(righthandmorphend!=0)righthandmorphness=0;
5188                 righthandmorphend=0;
5189                 targetrighthandmorphness=1;
5190
5191                 if(lefthandmorphend!=0)lefthandmorphness=0;
5192                 lefthandmorphend=0;
5193                 targetlefthandmorphness=1;
5194
5195                 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
5196                 headmorphend=3;
5197                 targetheadmorphness=1;
5198         }
5199
5200
5201         if(howactive>typesleeping){
5202                 XYZ headpoint;
5203                 headpoint=coords;
5204                 if(bloodtoggle&&!bled){
5205                         terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
5206                 }
5207                 if(bloodtoggle&&!bled)
5208                         for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5209                                 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5210                                 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5211                                 float size=.8;
5212                                 float opacity=.6;
5213                                 float rotation=0;
5214                                 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
5215                         }
5216                         bled=1;
5217         }
5218
5219         if(dead==2||howactive>typesleeping){
5220                 //If dead, open mouth and hands
5221                 if(righthandmorphend!=0)righthandmorphness=0;
5222                 righthandmorphend=0;
5223                 targetrighthandmorphness=1;
5224
5225                 if(lefthandmorphend!=0)lefthandmorphness=0;
5226                 lefthandmorphend=0;
5227                 targetlefthandmorphness=1;
5228
5229                 if(headmorphend!=2)headmorphness=0;
5230                 headmorphend=2;
5231                 targetheadmorphness=1;
5232         }
5233
5234         if(stunned>0&&!dead&&headmorphend!=2){
5235                 if(headmorphend!=4)headmorphness=0;
5236                 headmorphend=4;
5237                 targetheadmorphness=1;
5238         }
5239
5240         if(damage>damagetolerance&&!dead){
5241
5242                 dead=1;
5243                 unconscioustime=0;
5244
5245                 if(creature==wolftype){
5246                   award_bonus(0, Wolfbonus);
5247                 }
5248
5249                 RagDoll(0);
5250
5251                 if(weaponactive!=-1){
5252                         weapons.owner[weaponids[0]]=-1;
5253                         weapons.velocity[weaponids[0]]=velocity*scale*-.3;
5254                         weapons.velocity[weaponids[0]].x+=.01;
5255                         weapons.tipvelocity[weaponids[0]]=velocity*scale;
5256                         weapons.missed[weaponids[0]]=1;
5257                         weapons.hitsomething[weaponids[0]]=0;
5258                         weapons.freetime[weaponids[0]]=0;
5259                         weapons.firstfree[weaponids[0]]=1;
5260                         weapons.physics[weaponids[0]]=1;
5261                         num_weapons--;
5262                         if(num_weapons){
5263                                 weaponids[0]=weaponids[num_weapons];
5264                                 if(weaponstuck==num_weapons)weaponstuck=0;
5265                         }
5266                         weaponactive=-1;
5267                         for(i=0;i<numplayers;i++){
5268                                 player[i].wentforweapon=0;
5269                         }
5270                 }
5271
5272
5273
5274                 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
5275                         slomo=1;
5276                         slomodelay=.2;
5277                 }
5278
5279                 damage+=20;
5280         }
5281
5282         //if(dead)damage-=multiplier/4;
5283         if(!dead)damage-=multiplier*13;
5284         //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
5285         if(!dead)permanentdamage-=multiplier*4;
5286         if(isIdle()||isCrouch()){
5287                 if(!dead)permanentdamage-=multiplier*4;
5288                 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
5289         }
5290         if(damage<0)damage=0;
5291         if(permanentdamage<0)permanentdamage=0;
5292         if(superpermanentdamage<0)superpermanentdamage=0;
5293         if(permanentdamage<superpermanentdamage){
5294                 permanentdamage=superpermanentdamage;
5295         }
5296         if(damage<permanentdamage){
5297                 damage=permanentdamage;
5298         }
5299         if(dead==1&&damage<damagetolerance){
5300                 dead=0;
5301                 skeleton.free=1;
5302                 damage-=20;
5303                 for(i=0;i<skeleton.num_joints;i++){
5304                         skeleton.joints[i].velocity=0;
5305                 }
5306         }
5307         if(permanentdamage>damagetolerance&&dead!=2){
5308                 DoBlood(1,255);
5309
5310                 if(weaponactive!=-1){
5311                         weapons.owner[weaponids[0]]=-1;
5312                         weapons.velocity[weaponids[0]]=velocity*scale*-.3;
5313                         weapons.velocity[weaponids[0]].x+=.01;
5314                         weapons.tipvelocity[weaponids[0]]=velocity*scale;
5315                         weapons.missed[weaponids[0]]=1;
5316                         weapons.hitsomething[weaponids[0]]=0;
5317                         weapons.freetime[weaponids[0]]=0;
5318                         weapons.firstfree[weaponids[0]]=1;
5319                         weapons.physics[weaponids[0]]=1;
5320                         num_weapons--;
5321                         if(num_weapons){
5322                                 weaponids[0]=weaponids[num_weapons];
5323                                 if(weaponstuck==num_weapons)weaponstuck=0;
5324                         }
5325                         weaponactive=-1;
5326                         for(i=0;i<numplayers;i++){
5327                                 player[i].wentforweapon=0;
5328                         }
5329                 }
5330
5331                 bled=0;
5332
5333                 if(!dead&&creature==wolftype){
5334                   award_bonus(0, Wolfbonus);
5335                 }
5336
5337                 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
5338                   award_bonus(id, touchofdeath);
5339                 if(id!=0&&unconscioustime>.1){
5340                         numafterkill++;
5341                 }
5342
5343                 dead=2;
5344
5345                 skeleton.free=1;
5346
5347                 float gLoc[3];
5348                 float vel[3];
5349                 gLoc[0]=coords.x;
5350                 gLoc[1]=coords.y;
5351                 gLoc[2]=coords.z;
5352                 vel[0]=velocity.x;
5353                 vel[1]=velocity.y;
5354                 vel[2]=velocity.z;
5355                 PlaySoundEx( breaksound, samp[breaksound], NULL, true);
5356                 OPENAL_3D_SetAttributes(channels[breaksound], gLoc, vel);
5357                 OPENAL_SetVolume(channels[breaksound], 512);
5358                 OPENAL_SetPaused(channels[breaksound], false);
5359                 /*if(id==0||findDistancefast(&coords,&viewer)<50){
5360                 slomo=1;
5361                 slomodelay=.2;
5362                 }*/
5363         }
5364
5365         if(skeleton.free==1){
5366                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5367
5368                 if(!dead){
5369                         //If knocked over, open hands and close mouth
5370                         if(righthandmorphend!=0)righthandmorphness=0;
5371                         righthandmorphend=0;
5372                         targetrighthandmorphness=1;
5373
5374                         if(lefthandmorphend!=0)lefthandmorphness=0;
5375                         lefthandmorphend=0;
5376                         targetlefthandmorphness=1;
5377
5378                         if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
5379                                 if(headmorphend!=0)headmorphness=0;
5380                                 headmorphend=0;
5381                                 targetheadmorphness=1;
5382                         }
5383                 }
5384
5385                 skeleton.DoGravity(&scale);
5386                 float damageamount;
5387                 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
5388                 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
5389                   award_bonus(id, deepimpact);
5390                 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
5391
5392                 average=0;
5393                 howmany=0;
5394                 for(j=0;j<skeleton.num_joints;j++){
5395                         average+=skeleton.joints[j].position;
5396                         howmany++;
5397                 }
5398                 average/=howmany;
5399                 coords+=average*scale;
5400                 for(j=0;j<skeleton.num_joints;j++){
5401                         skeleton.joints[j].position-=average;
5402                 }
5403                 average/=multiplier;
5404
5405                 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
5406                 velocity=0;
5407                 for(i=0;i<skeleton.num_joints;i++){
5408                         velocity+=skeleton.joints[i].velocity*scale;
5409                 }
5410                 velocity/=skeleton.num_joints;
5411
5412                 if(!isnormal(velocity.x)&&velocity.x){
5413                         velocity=0;
5414                 }
5415
5416                 float gLoc[3];
5417                 float vel[3];
5418                 gLoc[0]=coords.x;
5419                 gLoc[1]=coords.y;
5420                 gLoc[2]=coords.z;
5421                 vel[0]=velocity.x;
5422                 vel[1]=velocity.y;
5423                 vel[2]=velocity.z;
5424
5425                 if(findLength(&average)<10&&dead&&skeleton.free){
5426                         skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
5427                         if(skeleton.longdead>2000){
5428                                 if(skeleton.longdead>6000){
5429                                         if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5430                                         skeleton.free=3;
5431                                         DrawSkeleton();
5432                                         skeleton.free=2;
5433                                 }
5434                                 if(dead==2&&bloodloss<damagetolerance){
5435                                         XYZ headpoint;
5436                                         headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
5437                                         DoBlood(1,255);
5438                                         if(bloodtoggle&&!bled){
5439                                                 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
5440                                         }
5441                                         if(bloodtoggle&&!bled)
5442                                                 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5443                                                         j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5444                                                         XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5445                                                         float size=.2*1.2;
5446                                                         float opacity=.6;
5447                                                         float rotation=0;
5448                                                         objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
5449                                                 }
5450                                                 bled=1;
5451                                 }
5452                                 if(dead==2&&bloodloss>=damagetolerance){
5453                                         XYZ headpoint;
5454                                         headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
5455                                         if(bleeding<=0)DoBlood(1,255);
5456                                         if(bloodtoggle&&!bled){
5457                                                 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
5458                                         }
5459                                         if(bloodtoggle&&!bled)
5460                                                 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
5461                                                         j=terrain.patchobjects[whichpatchx][whichpatchz][l];
5462                                                         XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
5463                                                         float size=.8;
5464                                                         float opacity=.6;
5465                                                         float rotation=0;
5466                                                         objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
5467                                                 }
5468                                                 bled=1;
5469                                 }
5470                         }
5471                 }
5472
5473                 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
5474                         bool canrecover=1;
5475                         XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
5476                         startpoint=coords;
5477                         endpoint=coords;
5478                         endpoint.y-=.7;
5479                         if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
5480                         if(velocity.y<-30)canrecover=0;
5481                         for(i=0;i<objects.numobjects;i++){
5482                                 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
5483                                         colviewer=startpoint;
5484                                         coltarget=endpoint;
5485                                         if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
5486                                 }
5487                         }
5488                         if(canrecover){
5489                                 skeleton.free=0;
5490                                 XYZ middle;
5491                                 middle=0;
5492
5493                                 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5494                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
5495                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5496                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5497                                 }
5498                                 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5499                                         terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5500                                         middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5501                                 }
5502                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5503                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5504                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
5505                                 }
5506                                 Normalise(&terrainnormal);
5507
5508                                 targetrotation=-asin(0-terrainnormal.x);
5509                                 targetrotation*=360/6.28;
5510                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5511                                 rotation=targetrotation;
5512
5513                                 //if(skeleton.forward.y<0){
5514                                 targetframe=0;
5515                                 //}
5516                                 //if(skeleton.forward.y>-.3){
5517                                 //      targetframe=2;
5518                                 //}
5519                                 targetanimation=flipanim;
5520                                 crouchtogglekeydown=1;
5521                                 target=0;
5522                                 tilt2=0;
5523                                 targettilt2=0;
5524
5525                                 currentanimation=tempanim;
5526                                 currentframe=0;
5527                                 target=0;
5528                                 //tilt2=targettilt2;
5529
5530                                 //if(middle.y>0)targetoffset.y=middle.y+1;
5531
5532                                 for(i=0;i<skeleton.num_joints;i++){
5533                                         tempanimation.position[i][0]=skeleton.joints[i].position;
5534                                         tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
5535                                 }
5536                         }
5537                 }
5538
5539                 if(findLength(&average)<10&&!dead&&skeleton.free){
5540                         skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
5541                         if(skeleton.longdead>(damage+500)*1.5){
5542                                 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
5543                                 skeleton.free=0;
5544                                 velocity=0;
5545                                 XYZ middle;
5546                                 middle=0;
5547
5548                                 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5549                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
5550                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
5551                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5552                                 }
5553                                 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5554                                         terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5555                                         middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
5556                                 }
5557                                 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
5558                                         terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
5559                                         middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
5560                                 }
5561                                 Normalise(&terrainnormal);
5562
5563                                 targetrotation=-asin(0-terrainnormal.x);
5564                                 targetrotation*=360/6.28;
5565                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5566                                 rotation=targetrotation;
5567
5568                                 /*if(onterrain){
5569                                 terrainnormal=terrain.getNormal(coords.x,coords.z);
5570                                 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
5571                                 }
5572                                 else*/
5573
5574                                 /*XYZ otherterrainnormal;
5575                                 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
5576                                 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
5577                                 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
5578                                 targettilt2=asin(otherterrainnormal.y)*180/3.14;
5579                                 */
5580
5581                                 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
5582
5583
5584
5585                                 if(skeleton.forward.y<0){
5586                                         targetanimation=getupfrombackanim;
5587                                         targetframe=0;
5588                                         targettilt2=0;
5589                                 }
5590                                 if(skeleton.forward.y>-.3){
5591                                         targetanimation=getupfromfrontanim;
5592                                         rotation+=180;
5593                                         targetrotation+=180;
5594                                         targettilt2*=-1;
5595                                         targetframe=0;
5596                                         targettilt2=0;
5597                                 }
5598
5599                                 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
5600                                         targetanimation=rollanim;
5601                                         targetrotation=lookrotation;
5602                                         if(id==0){
5603                                                 if(rightkeydown){
5604                                                         targetrotation-=90;
5605                                                         if(forwardkeydown)targetrotation+=45;
5606                                                         if(backkeydown)targetrotation-=45;
5607                                                 }
5608                                                 if(leftkeydown){
5609                                                         targetrotation+=90;
5610                                                         if(forwardkeydown)targetrotation-=45;
5611                                                         if(backkeydown)targetrotation+=45;
5612                                                 }
5613                                                 if(backkeydown){
5614                                                         if ( !leftkeydown&&!rightkeydown)
5615                                                                 targetrotation+=180;
5616                                                 }
5617                                                 targetrotation+=180;
5618                                         }
5619                                 }
5620
5621                                 if(abs(targettilt2)>50)targettilt2=0;
5622                                 currentanimation=tempanim;
5623                                 currentframe=0;
5624                                 target=0;
5625                                 tilt2=targettilt2;
5626
5627                                 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
5628
5629                                 for(i=0;i<skeleton.num_joints;i++){
5630                                         tempanimation.position[i][0]=skeleton.joints[i].position;
5631                                         tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
5632                                 }
5633                         }
5634                 }
5635
5636                 bool hasstaff;
5637                 hasstaff=0;
5638                 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
5639                 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
5640                         if(velocity.y>-30){
5641                                 XYZ tempvelocity;
5642                                 tempvelocity=velocity;
5643                                 Normalise(&tempvelocity);
5644                                 targetrotation=-asin(0-tempvelocity.x);
5645                                 targetrotation*=360/6.28;
5646                                 if(velocity.z<0)targetrotation=180-targetrotation;
5647                                 //targetrotation+=180;
5648
5649                                 skeleton.free=0;
5650                                 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
5651                                         targetanimation=rollanim;
5652                                         targetframe=2;
5653                                 }
5654                                 else{
5655                                         targetanimation=backhandspringanim;
5656                                         targetrotation+=180;
5657                                         targetframe=6;
5658                                 }
5659                                 target=0;
5660
5661                                 float gLoc[3];
5662                                 float vel[3];
5663                                 gLoc[0]=coords.x;
5664                                 gLoc[1]=coords.y;
5665                                 gLoc[2]=coords.z;
5666                                 vel[0]=velocity.x;
5667                                 vel[1]=velocity.y;
5668                                 vel[2]=velocity.z;
5669                                 PlaySoundEx( movewhooshsound, samp[movewhooshsound], NULL, true);
5670                                 OPENAL_3D_SetAttributes(channels[movewhooshsound], gLoc, vel);
5671                                 OPENAL_SetVolume(channels[movewhooshsound], 128);
5672                                 OPENAL_SetPaused(channels[movewhooshsound], false);
5673
5674                                 currentanimation=targetanimation;
5675                                 currentframe=targetframe-1;
5676                                 target=0;
5677
5678                                 velocity=0;
5679
5680                                 rotation=targetrotation;
5681                                 tilt=0;
5682                                 targettilt=0;
5683                                 tilt2=0;
5684                                 targettilt2=0;
5685                         }
5686                 }
5687                 if(skeleton.freefall==0)freefall=0;
5688
5689                 if(!isnormal(velocity.x)&&velocity.x){
5690                         int xy=1;
5691                 }
5692         }
5693
5694         if(aitype!=passivetype||skeleton.free==1)
5695                 if(findLengthfast(&velocity)>.1)
5696                         for(i=0;i<objects.numobjects;i++){
5697                                 if(objects.type[i]==firetype)
5698                                         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){
5699                                                 if(onfire){
5700                                                         if(!objects.onfire[i]){
5701                                                                 float gLoc[3];
5702                                                                 float vel[3];
5703                                                                 gLoc[0]=objects.position[i].x;
5704                                                                 gLoc[1]=objects.position[i].y;
5705                                                                 gLoc[2]=objects.position[i].z;
5706                                                                 vel[0]=0;
5707                                                                 vel[1]=0;
5708                                                                 vel[2]=0;
5709                                                                 PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
5710                                                                 OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
5711                                                                 OPENAL_SetVolume(channels[firestartsound], 256);
5712                                                                 OPENAL_SetPaused(channels[firestartsound], false);
5713                                                         }
5714                                                         objects.onfire[i]=1;
5715                                                 }
5716                                                 if(!onfire){
5717                                                         if(objects.onfire[i]){
5718                                                                 CatchFire();
5719                                                         }
5720                                                 }
5721                                         }
5722                                         if(objects.type[i]==bushtype)
5723                                                 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){
5724                                                         if(onfire){
5725                                                                 if(!objects.onfire[i]){
5726                                                                         float gLoc[3];
5727                                                                         float vel[3];
5728                                                                         gLoc[0]=objects.position[i].x;
5729                                                                         gLoc[1]=objects.position[i].y;
5730                                                                         gLoc[2]=objects.position[i].z;
5731                                                                         vel[0]=0;
5732                                                                         vel[1]=0;
5733                                                                         vel[2]=0;
5734                                                                         PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
5735                                                                         OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
5736                                                                         OPENAL_SetVolume(channels[firestartsound], 256);
5737                                                                         OPENAL_SetPaused(channels[firestartsound], false);
5738                                                                 }
5739                                                                 objects.onfire[i]=1;
5740                                                         }
5741
5742                                                         if(!onfire){
5743                                                                 if(objects.onfire[i]){
5744                                                                         CatchFire();
5745                                                                 }
5746                                                         }
5747                                                         if(objects.messedwith[i]<=0){
5748                                                                 XYZ tempvel;
5749                                                                 XYZ pos;
5750
5751                                                                 float gLoc[3];
5752                                                                 float vel[3];
5753                                                                 gLoc[0]=coords.x;
5754                                                                 gLoc[1]=coords.y;
5755                                                                 gLoc[2]=coords.z;
5756                                                                 vel[0]=velocity.x;
5757                                                                 vel[1]=velocity.y;
5758                                                                 vel[2]=velocity.z;
5759                                                                 PlaySoundEx( bushrustle, samp[bushrustle], NULL, true);
5760                                                                 OPENAL_3D_SetAttributes(channels[bushrustle], gLoc, vel);
5761                                                                 OPENAL_SetVolume(channels[bushrustle], 40*findLength(&velocity));
5762                                                                 OPENAL_SetPaused(channels[bushrustle], false);
5763
5764                                                                 if(id==0){
5765                                                                         envsound[numenvsounds]=coords;
5766                                                                         envsoundvol[numenvsounds]=4*findLength(&velocity);
5767                                                                         envsoundlife[numenvsounds]=.4;
5768                                                                         numenvsounds++;
5769                                                                 }
5770
5771                                                                 int howmany;
5772                                                                 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
5773                                                                 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
5774                                                                 if(detail==2)
5775                                                                         if(environment!=desertenvironment)
5776                                                                                 for(j=0;j<howmany;j++){
5777                                                                                         tempvel.x=float(abs(Random()%100)-50)/20;
5778                                                                                         tempvel.y=float(abs(Random()%100)-50)/20;
5779                                                                                         tempvel.z=float(abs(Random()%100)-50)/20;
5780                                                                                         pos=coords;
5781                                                                                         pos.y+=1;
5782                                                                                         pos.x+=float(abs(Random()%100)-50)/200;
5783                                                                                         pos.y+=float(abs(Random()%100)-50)/200;
5784                                                                                         pos.z+=float(abs(Random()%100)-50)/200;
5785                                                                                         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);
5786                                                                                         Sprite::setLastSpriteSpecial(1);
5787                                                                                 }
5788                                                                                 howmany=findLength(&velocity)*4;
5789                                                                                 if(detail==2)
5790                                                                                         if(environment==snowyenvironment)
5791                                                                                                 for(j=0;j<howmany;j++){
5792                                                                                                         tempvel.x=float(abs(Random()%100)-50)/20;
5793                                                                                                         tempvel.y=float(abs(Random()%100)-50)/20;
5794                                                                                                         tempvel.z=float(abs(Random()%100)-50)/20;
5795                                                                                                         pos=coords;
5796                                                                                                         pos.y+=1;
5797                                                                                                         pos.x+=float(abs(Random()%100)-50)/200;
5798                                                                                                         pos.y+=float(abs(Random()%100)-50)/200;
5799                                                                                                         pos.z+=float(abs(Random()%100)-50)/200;
5800                                                                                                         Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
5801                                                                                                         Sprite::setLastSpriteSpecial(2);
5802                                                                                                 }
5803                                                         }
5804                                                         objects.rotx[i]+=velocity.x*multiplier*6;
5805                                                         objects.roty[i]+=velocity.z*multiplier*6;
5806                                                         objects.messedwith[i]=.5;
5807                                                 }
5808                                                 XYZ tempcoord;
5809                                                 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
5810                                                         if(objects.rotation2[i]==0)tempcoord=coords;
5811                                                         else{
5812                                                                 tempcoord=coords-objects.position[i];
5813                                                                 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
5814                                                                 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
5815                                                                 tempcoord+=objects.position[i];
5816                                                         }
5817                                                         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]){
5818                                                                 if(objects.messedwith[i]<=0){
5819                                                                         XYZ tempvel;
5820                                                                         XYZ pos;
5821
5822                                                                         float gLoc[3];
5823                                                                         float vel[3];
5824                                                                         gLoc[0]=coords.x;
5825                                                                         gLoc[1]=coords.y;
5826                                                                         gLoc[2]=coords.z;
5827                                                                         vel[0]=velocity.x;
5828                                                                         vel[1]=velocity.y;
5829                                                                         vel[2]=velocity.z;
5830                                                                         PlaySoundEx( bushrustle, samp[bushrustle], NULL, true);
5831                                                                         OPENAL_3D_SetAttributes(channels[bushrustle], gLoc, vel);
5832                                                                         OPENAL_SetVolume(channels[bushrustle], 40*findLength(&velocity));
5833                                                                         OPENAL_SetPaused(channels[bushrustle], false);
5834
5835                                                                         if(id==0){
5836                                                                                 envsound[numenvsounds]=coords;
5837                                                                                 envsoundvol[numenvsounds]=4*findLength(&velocity);
5838                                                                                 envsoundlife[numenvsounds]=.4;
5839                                                                                 numenvsounds++;
5840                                                                         }
5841
5842                                                                         int howmany;
5843                                                                         if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
5844                                                                         if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
5845                                                                         if(detail==2)
5846                                                                                 if(environment!=desertenvironment)
5847                                                                                         for(j=0;j<howmany;j++){
5848                                                                                                 tempvel.x=float(abs(Random()%100)-50)/20;
5849                                                                                                 tempvel.y=float(abs(Random()%100)-50)/20;
5850                                                                                                 tempvel.z=float(abs(Random()%100)-50)/20;
5851                                                                                                 pos=coords;
5852                                                                                                 pos+=velocity*.1;
5853                                                                                                 pos.y+=1;
5854                                                                                                 pos.x+=float(abs(Random()%100)-50)/150;
5855                                                                                                 pos.y+=float(abs(Random()%100)-50)/150;
5856                                                                                                 pos.z+=float(abs(Random()%100)-50)/150;
5857                                                                                                 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);
5858                                                                                                 Sprite::setLastSpriteSpecial(1);
5859                                                                                         }
5860                                                                                         howmany=findLength(&velocity)*4;
5861                                                                                         if(detail==2)
5862                                                                                                 if(environment==snowyenvironment)
5863                                                                                                         for(j=0;j<howmany;j++){
5864                                                                                                                 tempvel.x=float(abs(Random()%100)-50)/20;
5865                                                                                                                 tempvel.y=float(abs(Random()%100)-50)/20;
5866                                                                                                                 tempvel.z=float(abs(Random()%100)-50)/20;
5867                                                                                                                 pos=coords;
5868                                                                                                                 pos+=velocity*.1;
5869                                                                                                                 pos.y+=1;
5870                                                                                                                 pos.x+=float(abs(Random()%100)-50)/150;
5871                                                                                                                 pos.y+=float(abs(Random()%100)-50)/150;
5872                                                                                                                 pos.z+=float(abs(Random()%100)-50)/150;
5873                                                                                                                 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
5874                                                                                                                 Sprite::setLastSpriteSpecial(2);
5875                                                                                                         }
5876                                                                 }
5877                                                                 objects.messedwith[i]=.5;
5878                                                         }
5879                                                 }
5880                         }
5881
5882                         if(!skeleton.free){
5883                                 bool play;
5884                                 play=0;
5885                                 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
5886                                 if(hasvictim)
5887                                         if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
5888                                 if(tutoriallevel==1&&id!=0)play=0;
5889                                 if(play&&aitype!=playercontrolled){
5890                                         int whichsound=-1;
5891                                         float gLoc[3];
5892                                         float vel[3];
5893                                         gLoc[0]=coords.x;
5894                                         gLoc[1]=coords.y;
5895                                         gLoc[2]=coords.z;
5896                                         vel[0]=velocity.x;
5897                                         vel[1]=velocity.y;
5898                                         vel[2]=velocity.z;
5899                                         i=abs(Random()%4);
5900                                         if(speechdelay<=0){
5901                                                 if(creature==rabbittype){
5902                                                         if(i==0)whichsound=rabbitchitter;
5903                                                         if(i==1)whichsound=rabbitchitter2;
5904                                                 }
5905                                                 if(creature==wolftype){
5906                                                         if(i==0)whichsound=growlsound;
5907                                                         if(i==1)whichsound=growl2sound;
5908                                                 }
5909                                         }
5910                                         speechdelay=.3;
5911
5912                                         if(whichsound!=-1){
5913                                                 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
5914                                                 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
5915                                                 OPENAL_SetVolume(channels[whichsound], 512);
5916                                                 OPENAL_SetPaused(channels[whichsound], false);
5917                                         }
5918                                 }
5919
5920                                 if(targetanimation==staggerbackhighanim)staggerdelay=1;
5921                                 if(targetanimation==staggerbackhardanim)staggerdelay=1;
5922                                 staggerdelay-=multiplier;
5923                                 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
5924                                 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
5925                                 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
5926                                         targetanimation=getIdle();
5927                                         targetframe=0;
5928                                         target=0;
5929                                 }
5930                                 weaponmissdelay-=multiplier;
5931                                 highreversaldelay-=multiplier;
5932                                 lowreversaldelay-=multiplier;
5933                                 lastcollide-=multiplier;
5934                                 skiddelay-=multiplier;
5935                                 if(!isnormal(velocity.x)&&velocity.x){
5936                                         velocity=0;
5937                                 }
5938                                 if(!isnormal(targettilt)&&targettilt){
5939                                         targettilt=0;
5940                                 }
5941                                 if(!isnormal(targettilt2)&&targettilt2){
5942                                         targettilt2=0;
5943                                 }
5944                                 if(!isnormal(targetrotation)&&targetrotation){
5945                                         targetrotation=0;
5946                                 }
5947
5948                                 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
5949                                         //open hands and close mouth
5950                                         //if(targetanimation!=wolfidle){
5951                                         if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5952                                                 righthandmorphness=0;
5953                                                 righthandmorphend=0;
5954                                                 targetrighthandmorphness=1;
5955                                         }
5956
5957                                         if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5958                                                 lefthandmorphness=0;
5959                                                 lefthandmorphend=0;
5960                                                 targetlefthandmorphness=1;
5961                                         }
5962                                         //s}
5963
5964                                         if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
5965                                                 headmorphness=0;
5966                                                 headmorphend=0;
5967                                                 targetheadmorphness=1;
5968                                         }
5969                                 }
5970
5971                                 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){
5972                                         //open hands and mouth
5973                                         if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5974                                                 righthandmorphness=0;
5975                                                 righthandmorphend=0;
5976                                                 targetrighthandmorphness=1;
5977                                         }
5978
5979                                         if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5980                                                 lefthandmorphness=0;
5981                                                 lefthandmorphend=0;
5982                                                 targetlefthandmorphness=1;
5983                                         }
5984
5985                                         if(headmorphend!=1&&headmorphness==targetheadmorphness){
5986                                                 headmorphness=0;
5987                                                 headmorphend=1;
5988                                                 targetheadmorphness=1;
5989                                         }
5990                                 }
5991
5992                                 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
5993                                         //close hands and mouth
5994                                         if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5995                                                 righthandmorphness=0;
5996                                                 righthandmorphend=1;
5997                                                 targetrighthandmorphness=1;
5998                                         }
5999
6000                                         if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
6001                                                 lefthandmorphness=0;
6002                                                 lefthandmorphend=1;
6003                                                 targetlefthandmorphness=1;
6004                                         }
6005
6006                                         if(headmorphend!=0&&headmorphness==targetheadmorphness){
6007                                                 headmorphness=0;
6008                                                 headmorphend=0;
6009                                                 targetheadmorphness=1;
6010                                         }
6011                                 }
6012
6013                                 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){
6014                                         //close hands and yell
6015                                         if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
6016                                                 righthandmorphness=0;
6017                                                 righthandmorphend=1;
6018                                                 targetrighthandmorphness=1;
6019                                         }
6020
6021                                         if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
6022                                                 lefthandmorphness=0;
6023                                                 lefthandmorphend=1;
6024                                                 targetlefthandmorphness=1;
6025                                         }
6026
6027                                         if(headmorphend!=2&&headmorphness==targetheadmorphness){
6028                                                 headmorphness=1;
6029                                                 headmorphend=2;
6030                                                 targetheadmorphness=1;
6031                                         }
6032                                 }
6033                                 /*
6034                                 if(speechdelay>.25){
6035                                 if(headmorphend!=2)headmorphness=0;
6036                                 headmorphend=2;
6037                                 targetheadmorphness=1;
6038                                 }
6039                                 */
6040                                 bool behind;
6041                                 behind=0;
6042                                 if(hasvictim){
6043                                         if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
6044                                                 behind=(normaldotproduct(facing,coords-victim->coords)>0);
6045                                         }
6046                                 }
6047
6048                                 if(!dead&&targetanimation!=hurtidleanim)
6049                                         if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
6050                                                 if(headmorphend!=4||headmorphness==targetheadmorphness){
6051                                                         headmorphend=4;
6052                                                         //headmorphness=1;
6053                                                         targetheadmorphness=1;
6054                                                 }
6055                                         }
6056
6057                                         if(weaponactive!=-1){
6058                                                 if(weapons.type[weaponids[weaponactive]]!=staff){
6059                                                         righthandmorphstart=1;
6060                                                         righthandmorphend=1;
6061                                                 }
6062                                                 if(weapons.type[weaponids[weaponactive]]==staff){
6063                                                         righthandmorphstart=2;
6064                                                         righthandmorphend=2;
6065                                                 }
6066                                                 targetrighthandmorphness=1;
6067                                         }
6068
6069                                         terrainnormal=terrain.getNormal(coords.x,coords.z);
6070
6071                                         if(animation[targetanimation].attack!=reversal){
6072                                                 if(!isnormal(coords.x))
6073                                                         coords=oldcoords;
6074                                                 oldcoords=coords;
6075                                         }
6076
6077                                         flatfacing=0;
6078                                         flatfacing.z=1;
6079
6080                                         flatfacing=DoRotation(flatfacing,0,rotation,0);
6081                                         facing=flatfacing;
6082                                         ReflectVector(&facing,terrainnormal);
6083                                         Normalise(&facing);
6084
6085                                         if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
6086                                                 if(onterrain)targettilt2=-facing.y*20;
6087                                                 else targettilt2=0;
6088                                         }
6089                                         onterrain=0;
6090                                         if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
6091                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6092                                                 flatvelocity=velocity;
6093                                                 flatvelocity.y=0;
6094                                                 flatvelspeed=findLength(&flatvelocity);
6095                                                 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
6096                                                 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
6097                                                 if(velocity.y<0)targettilt2*=-1;
6098                                                 if(velocity.y<0)targettilt*=-1;
6099                                                 if(targettilt>25)targettilt=25;
6100                                                 if(targettilt<-25)targettilt=-25;
6101                                         }
6102
6103                                         if(targettilt2>45)targettilt2=45;
6104                                         if(targettilt2<-45)targettilt2=-45;
6105                                         if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
6106                                         else if(tilt2>targettilt2){
6107                                                 tilt2-=multiplier*400;
6108                                         }
6109                                         else if(tilt2<targettilt2){
6110                                                 tilt2+=multiplier*400;
6111                                         }
6112                                         if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
6113                                                 if(tilt2>25)tilt2=25;
6114                                                 if(tilt2<-25)tilt2=-25;
6115                                         }
6116
6117                                         if(!isnormal(targettilt)&&targettilt){
6118                                                 targettilt=0;
6119                                         }
6120                                         if(!isnormal(targettilt2)&&targettilt2){
6121                                                 targettilt2=0;
6122                                         }
6123
6124                                         //Running velocity
6125                                         //if(!creature==wolftype||targetanimation==rabbitkickanim)
6126                                         if(targetanimation==rabbittackleanim){
6127                                                 velocity+=facing*multiplier*speed*700*scale;
6128                                                 velspeed=findLength(&velocity);
6129                                                 if(velspeed>speed*65*scale){
6130                                                         velocity/=velspeed;
6131                                                         velspeed=speed*65*scale;
6132                                                         velocity*=velspeed;
6133                                                 }
6134                                                 velocity.y+=gravity*multiplier*20;
6135                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6136                                                 velspeed=findLength(&velocity);
6137                                                 velocity=flatfacing*velspeed;
6138                                         }
6139                                         if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
6140                                                 if(isRun()||targetanimation==rabbitkickanim){
6141                                                         velocity+=facing*multiplier*speed*700*scale;
6142                                                         velspeed=findLength(&velocity);
6143                                                         if(velspeed>speed*45*scale){
6144                                                                 velocity/=velspeed;
6145                                                                 velspeed=speed*45*scale;
6146                                                                 velocity*=velspeed;
6147                                                         }
6148                                                         velocity.y+=gravity*multiplier*20;
6149                                                         ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6150                                                         velspeed=findLength(&velocity);
6151                                                         if(velspeed<speed*30*scale)velspeed=speed*30*scale;
6152                                                         velocity=flatfacing*velspeed;
6153                                                 }
6154                                         }
6155                                         else if(isRun()){
6156                                                 velocity+=facing*multiplier*speed*700*scale;
6157                                                 velspeed=findLength(&velocity);
6158                                                 if(creature==rabbittype){
6159                                                         if(velspeed>speed*55*scale){
6160                                                                 velocity/=velspeed;
6161                                                                 velspeed=speed*55*scale;
6162                                                                 velocity*=velspeed;
6163                                                         }
6164                                                 }
6165                                                 if(creature==wolftype){
6166                                                         if(velspeed>speed*75*scale){
6167                                                                 velocity/=velspeed;
6168                                                                 velspeed=speed*75*scale;
6169                                                                 velocity*=velspeed;
6170                                                         }
6171                                                 }
6172                                                 velocity.y+=gravity*multiplier*20;
6173                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6174                                                 velspeed=findLength(&velocity);
6175                                                 velocity=flatfacing*velspeed;
6176                                         }
6177
6178                                         if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
6179                                                 velocity+=facing*multiplier*speed*700*scale;
6180                                                 velspeed=findLength(&velocity);
6181                                                 if(velspeed>speed*45*scale){
6182                                                         velocity/=velspeed;
6183                                                         velspeed=speed*45*scale;
6184                                                         velocity*=velspeed;
6185                                                 }
6186                                                 velocity.y+=gravity*multiplier*20;
6187                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6188                                                 velspeed=findLength(&velocity);
6189                                                 velocity=flatfacing*velspeed;
6190                                         }
6191
6192
6193                                         /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
6194                                         velocity+=facing*multiplier*speed*700*scale;
6195                                         velspeed=findLength(&velocity);
6196                                         if(velspeed>speed*25*scale){
6197                                         velocity/=velspeed;
6198                                         velspeed=speed*25*scale;
6199                                         velocity*=velspeed;
6200                                         }
6201                                         velocity.y+=gravity*multiplier*20;
6202                                         ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6203                                         velspeed=findLength(&velocity);
6204                                         velocity=flatfacing*velspeed;
6205                                         }*/
6206
6207                                         if(targetanimation==sneakanim||targetanimation==walkanim){
6208                                                 velocity+=facing*multiplier*speed*700*scale;
6209                                                 velspeed=findLength(&velocity);
6210                                                 if(velspeed>speed*12*scale){
6211                                                         velocity/=velspeed;
6212                                                         velspeed=speed*12*scale;
6213                                                         velocity*=velspeed;
6214                                                 }
6215                                                 velocity.y+=gravity*multiplier*20;
6216                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6217                                                 velspeed=findLength(&velocity);
6218                                                 velocity=flatfacing*velspeed;
6219                                         }
6220
6221                                         if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
6222                                                 velocity+=facing*multiplier*speed*700*scale;
6223                                                 velspeed=findLength(&velocity);
6224                                                 if(velspeed>speed*2*scale){
6225                                                         velocity/=velspeed;
6226                                                         velspeed=speed*2*scale;
6227                                                         velocity*=velspeed;
6228                                                 }
6229                                                 velocity.y+=gravity*multiplier*20;
6230                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6231                                                 velspeed=findLength(&velocity);
6232                                                 velocity=flatfacing*velspeed;
6233                                         }
6234
6235
6236                                         if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
6237                                                 velocity-=facing*multiplier*speed*700*scale;
6238                                                 velspeed=findLength(&velocity);
6239                                                 if(velspeed>speed*2*scale){
6240                                                         velocity/=velspeed;
6241                                                         velspeed=speed*2*scale;
6242                                                         velocity*=velspeed;
6243                                                 }
6244                                                 velocity.y+=gravity*multiplier*20;
6245                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6246                                                 velspeed=findLength(&velocity);
6247                                                 velocity=flatfacing*velspeed*-1;
6248                                         }
6249
6250                                         if(targetanimation==fightsidestep){
6251                                                 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
6252                                                 velspeed=findLength(&velocity);
6253                                                 if(velspeed>speed*12*scale){
6254                                                         velocity/=velspeed;
6255                                                         velspeed=speed*12*scale;
6256                                                         velocity*=velspeed;
6257                                                 }
6258                                                 velocity.y+=gravity*multiplier*20;
6259                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6260                                                 velspeed=findLength(&velocity);
6261                                                 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
6262                                         }
6263
6264                                         if(targetanimation==staggerbackhighanim){
6265                                                 coords-=facing*multiplier*speed*16*scale;
6266                                                 velocity=0;
6267                                         }
6268                                         if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
6269                                                 coords-=facing*multiplier*speed*20*scale;
6270                                                 velocity=0;
6271                                         }
6272
6273                                         if(targetanimation==backhandspringanim){
6274                                                 //coords-=facing*multiplier*50*scale;
6275                                                 velocity+=facing*multiplier*speed*700*scale*-1;
6276                                                 velspeed=findLength(&velocity);
6277                                                 if(velspeed>speed*50*scale){
6278                                                         velocity/=velspeed;
6279                                                         velspeed=speed*50*scale;
6280                                                         velocity*=velspeed;
6281                                                 }
6282                                                 velocity.y+=gravity*multiplier*20;
6283                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6284                                                 velspeed=findLength(&velocity);
6285                                                 velocity=flatfacing*velspeed*-1;
6286                                         }
6287                                         if(targetanimation==dodgebackanim){
6288                                                 //coords-=facing*multiplier*50*scale;
6289                                                 velocity+=facing*multiplier*speed*700*scale*-1;
6290                                                 velspeed=findLength(&velocity);
6291                                                 if(velspeed>speed*60*scale){
6292                                                         velocity/=velspeed;
6293                                                         velspeed=speed*60*scale;
6294                                                         velocity*=velspeed;
6295                                                 }
6296                                                 velocity.y+=gravity*multiplier*20;
6297                                                 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
6298                                                 velspeed=findLength(&velocity);
6299                                                 velocity=flatfacing*velspeed*-1;
6300                                         }
6301
6302                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6303                                                 velspeed=findLength(&velocity);
6304                                         }
6305
6306
6307                                         if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
6308                                                 velocity.y+=gravity*multiplier;
6309                                         }
6310
6311                                         if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
6312
6313                                         if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6314                                                 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
6315
6316                                                 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6317                                                 target=0;
6318                                                 targetframe=0;
6319                                                 onterrain=1;
6320
6321                                                 if(id==0){
6322                                                         OPENAL_SetPaused(channels[whooshsound], true);
6323                                                         OPENAL_SetVolume(channels[whooshsound], 0);
6324                                                 }
6325
6326                                                 if(targetanimation==jumpdownanim||isFlip()){
6327                                                         if(isFlip())jumppower=-4;
6328                                                         targetanimation=getLanding();
6329                                                         float gLoc[3];
6330                                                         float vel[3];
6331                                                         gLoc[0]=coords.x;
6332                                                         gLoc[1]=coords.y;
6333                                                         gLoc[2]=coords.z;
6334                                                         vel[0]=velocity.x;
6335                                                         vel[1]=velocity.y;
6336                                                         vel[2]=velocity.z;
6337                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
6338                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
6339                                                         OPENAL_SetVolume(channels[landsound], 128);
6340                                                         OPENAL_SetPaused(channels[landsound], false);
6341
6342                                                         if(id==0){
6343                                                                 envsound[numenvsounds]=coords;
6344                                                                 envsoundvol[numenvsounds]=16;
6345                                                                 envsoundlife[numenvsounds]=.4;
6346                                                                 numenvsounds++;
6347                                                         }
6348                                                 }
6349                                         }
6350
6351                                         if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
6352                                         if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
6353                                                 coords.y=terrain.getHeight(coords.x,coords.z);
6354                                                 onterrain=1;
6355                                         }
6356
6357
6358                                         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)){
6359                                                 velspeed=findLength(&velocity);
6360                                                 velocity.y=0;
6361                                                 if(velspeed<multiplier*300*scale){
6362                                                         velocity=0;
6363                                                 } else velocity-=velocity/velspeed*multiplier*300*scale;
6364                                                 if(velspeed>5&&(isLanding()||isLandhard())){
6365                                                         skiddingdelay+=multiplier;
6366                                                         if(skiddelay<=0){
6367                                                                 FootLand(0,.5);
6368                                                                 FootLand(1,.5);
6369                                                                 skiddelay=.02;
6370                                                         }
6371                                                 }
6372                                                 else skiddingdelay=0;
6373                                         }
6374
6375                                         if(isLandhard()){
6376                                                 velspeed=findLength(&velocity);
6377                                                 velocity.y=0;
6378                                                 if(velspeed<multiplier*600*scale){
6379                                                         velocity=0;
6380                                                 } else velocity-=velocity/velspeed*multiplier*600*scale;
6381                                                 velocity=0;
6382                                                 if(velspeed>5&&(isLanding()||isLandhard())){
6383                                                         skiddingdelay+=multiplier;
6384                                                         if(skiddelay<=0){
6385                                                                 FootLand(0,.5);
6386                                                                 FootLand(1,.5);
6387                                                                 skiddelay=.02;
6388                                                         }
6389                                                 }
6390                                                 else skiddingdelay=0;
6391                                         }
6392
6393                                         if(skiddingdelay<0)skiddingdelay+=multiplier;
6394                                         if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
6395                                                 skiddingdelay=-1;
6396                                                 float gLoc[3];
6397                                                 float vel[3];
6398                                                 gLoc[0]=coords.x;
6399                                                 gLoc[1]=coords.y;
6400                                                 gLoc[2]=coords.z;
6401                                                 vel[0]=velocity.x;
6402                                                 vel[1]=velocity.y;
6403                                                 vel[2]=velocity.z;
6404                                                 if(!onterrain||environment==grassyenvironment){
6405                                                         PlaySoundEx( skidsound, samp[skidsound], NULL, true);
6406                                                         OPENAL_3D_SetAttributes(channels[skidsound], gLoc, vel);
6407                                                         OPENAL_SetVolume(channels[skidsound], 128*velspeed/10);
6408                                                         OPENAL_SetPaused(channels[skidsound], false);
6409                                                 }
6410                                                 else {
6411                                                         PlaySoundEx( snowskidsound, samp[snowskidsound], NULL, true);
6412                                                         OPENAL_3D_SetAttributes(channels[snowskidsound], gLoc, vel);
6413                                                         OPENAL_SetVolume(channels[snowskidsound], 128*velspeed/10);
6414                                                         OPENAL_SetPaused(channels[snowskidsound], false);
6415                                                 }
6416                                         }
6417
6418                                         if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
6419                                                 terrainnormal=victim->coords-coords;
6420                                                 Normalise(&terrainnormal);
6421                                                 targetrotation=-asin(0-terrainnormal.x);
6422                                                 targetrotation*=360/6.28;
6423                                                 if(terrainnormal.z<0)targetrotation=180-targetrotation;
6424                                                 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
6425                                         }
6426
6427                                         if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
6428                                                 targetrotation=victim->targetrotation;
6429                                         }
6430                                         if(targetanimation==rabbittacklinganim){
6431                                                 coords=victim->coords;
6432                                         }
6433                         }
6434                         skeleton.oldfree=skeleton.free;
6435
6436                         XYZ midterrain;
6437                         midterrain=0;
6438                         midterrain.x=terrain.size*terrain.scale/2;
6439                         midterrain.z=terrain.size*terrain.scale/2;
6440                         if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
6441                                 XYZ tempposit;
6442                                 tempposit=coords-midterrain;
6443                                 tempposit.y=0;
6444                                 Normalise(&tempposit);
6445                                 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
6446                                 coords.x=tempposit.x+midterrain.x;
6447                                 coords.z=tempposit.z+midterrain.z;
6448                         }
6449 }
6450
6451 int Person::DrawSkeleton(){
6452         int oldplayerdetail;
6453         if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
6454                 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
6455                         calcrot=1;
6456                 }
6457
6458                 if(headless){
6459                         headmorphness=0;
6460                         headmorphstart=6;
6461                         headmorphend=6;
6462                 }
6463
6464                 glAlphaFunc(GL_GREATER, 0.0001);
6465                 XYZ terrainlight;
6466                 float terrainheight;
6467                 float distance;
6468                 if(!isnormal(rotation))rotation=0;
6469                 if(!isnormal(tilt))tilt=0;
6470                 if(!isnormal(tilt2))tilt2=0;
6471                 oldplayerdetail=playerdetail;
6472                 playerdetail=0;
6473                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
6474                         playerdetail=1;
6475                 }
6476                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
6477                         playerdetail=1;
6478                 }
6479                 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
6480                         playerdetail=1;
6481                 }
6482                 if(id==0)
6483                         playerdetail=1;
6484                 if(playerdetail!=oldplayerdetail) {
6485                         updatedelay=0;
6486                         normalsupdatedelay=0;
6487                 }
6488                 static float updatedelaychange;
6489                 static float morphness;
6490                 static float framemult;
6491                 if(calcrot){
6492                         skeleton.FindForwards();
6493                         if(howactive==typesittingwall){
6494                                 skeleton.specialforward[1]=0;
6495                                 skeleton.specialforward[1].z=1;
6496                         }
6497                 }
6498                 static XYZ mid;
6499                 static float M[16];
6500                 static int i,j,k;
6501                 static int weaponattachmuscle;
6502                 static int weaponrotatemuscle,weaponrotatemuscle2;
6503                 static XYZ weaponpoint;
6504                 static int start,endthing;
6505                 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
6506                         if(!isSleeping()&&!isSitting()){
6507                                 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6508                                         XYZ point,newpoint,change,change2;
6509                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6510                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6511                                         point.y=heightleft;
6512                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6513                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6514                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6515                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6516                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6517
6518                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6519                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6520                                         point.y=heightright;
6521                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6522                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6523                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6524                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6525                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6526                                         skeleton.DoConstraints(&coords,&scale);
6527
6528                                         if(creature==wolftype){
6529                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6530                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6531                                                 point.y=heightleft;
6532                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6533                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6534                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6535                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6536                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6537
6538                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6539                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6540                                                 point.y=heightright;
6541                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6542                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6543                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
6544                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6545                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6546                                                 skeleton.DoConstraints(&coords,&scale);
6547                                         }
6548                                 }
6549                                 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6550                                         XYZ point,newpoint,change,change2;
6551                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6552                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6553                                         point.y=heightleft;
6554                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6555                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6556                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
6557                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6558                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6559
6560                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6561                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6562                                         point.y=heightright;
6563                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6564                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6565                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
6566                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6567                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6568                                         skeleton.DoConstraints(&coords,&scale);
6569
6570                                         if(creature==wolftype){
6571                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6572                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6573                                                 point.y=heightleft;
6574                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6575                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6576                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
6577                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6578                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6579
6580                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6581                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6582                                                 point.y=heightright;
6583                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6584                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6585                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
6586                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6587                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6588                                                 skeleton.DoConstraints(&coords,&scale);
6589                                         }
6590                                 }
6591
6592                                 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
6593                                         XYZ point,newpoint,change,change2;
6594                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6595                                         heightleft=terrain.getHeight(point.x,point.z)+.04;
6596                                         point.y=heightleft;
6597                                         change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6598                                         change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6599                                         skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
6600                                         skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6601                                         skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6602
6603                                         point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6604                                         heightright=terrain.getHeight(point.x,point.z)+.04;
6605                                         point.y=heightright;
6606                                         change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6607                                         change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6608                                         skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
6609                                         skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6610                                         skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6611                                         skeleton.DoConstraints(&coords,&scale);
6612
6613                                         if(creature==wolftype){
6614                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
6615                                                 heightleft=terrain.getHeight(point.x,point.z)+.04;
6616                                                 point.y=heightleft;
6617                                                 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6618                                                 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
6619                                                 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
6620                                                 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
6621                                                 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
6622
6623                                                 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
6624                                                 heightright=terrain.getHeight(point.x,point.z)+.04;
6625                                                 point.y=heightright;
6626                                                 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6627                                                 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
6628                                                 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
6629                                                 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
6630                                                 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
6631                                                 skeleton.DoConstraints(&coords,&scale);
6632                                         }
6633                                 }
6634                         }
6635                         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()))
6636                                 DoHead();
6637                         else {
6638                                 targetheadrotation=-targetrotation;
6639                                 targetheadrotation2=0;
6640                                 if(animation[targetanimation].attack==3)targetheadrotation+=180;
6641                         }
6642                         for(i=0;i<skeleton.drawmodel.vertexNum;i++){
6643                                 skeleton.drawmodel.vertex[i]=0;
6644                                 skeleton.drawmodel.vertex[i].y=999;
6645                         }
6646                         for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
6647                                 skeleton.drawmodellow.vertex[i]=0;
6648                                 skeleton.drawmodellow.vertex[i].y=999;
6649                         }
6650                         for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
6651                                 skeleton.drawmodelclothes.vertex[i]=0;
6652                                 skeleton.drawmodelclothes.vertex[i].y=999;
6653                         }
6654                         for(i=0;i<skeleton.num_muscles;i++){
6655                                 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
6656                                         morphness=0;
6657                                         start=0;
6658                                         endthing=0;
6659                                         if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
6660                                                 morphness=righthandmorphness;
6661                                                 start=righthandmorphstart;
6662                                                 endthing=righthandmorphend;
6663                                         }
6664                                         if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
6665                                                 morphness=lefthandmorphness;
6666                                                 start=lefthandmorphstart;
6667                                                 endthing=lefthandmorphend;
6668                                         }
6669                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
6670                                                 morphness=headmorphness;
6671                                                 start=headmorphstart;
6672                                                 endthing=headmorphend;
6673                                         }
6674                                         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)){
6675                                                 morphness=chestmorphness;
6676                                                 start=chestmorphstart;
6677                                                 endthing=chestmorphend;
6678                                         }
6679                                         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)){
6680                                                 morphness=tailmorphness;
6681                                                 start=tailmorphstart;
6682                                                 endthing=tailmorphend;
6683                                         }
6684                                         if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
6685                                         mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
6686                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6687                                         glPushMatrix();
6688                                                 glLoadIdentity();
6689                                                 if(!skeleton.free)glRotatef(tilt2,1,0,0);
6690                                                 if(!skeleton.free)glRotatef(tilt,0,0,1);
6691
6692
6693                                                 glTranslatef(mid.x,mid.y,mid.z);
6694
6695                                                 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
6696                                                 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
6697
6698                                                 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
6699                                                 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
6700
6701                                                 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
6702                                                 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
6703                                                 /*
6704                                                 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
6705                                                 proportionbody=1;
6706                                                 proportionweird=1;
6707                                                 }
6708                                                 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
6709                                                 proportionarms=1;
6710                                                 proportionweird=1;
6711                                                 }
6712                                                 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
6713                                                 proportionhead=1;
6714                                                 proportionweird=1;
6715                                                 }
6716                                                 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
6717                                                 proportionlegs=1;
6718                                                 proportionweird=1;
6719                                                 }*/
6720
6721                                                 if(playerdetail||skeleton.free==3)
6722                                                 {
6723                                                         for(j=0;j<skeleton.muscles[i].numvertices;j++)
6724                                                         {
6725                                                                 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
6726                                                                 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
6727                                                                 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
6728                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
6729                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
6730                                                                 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
6731                                                                 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
6732                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6733                                                                 glPushMatrix();
6734                                                                         if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6735                                                                                 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,
6736                                                                                 (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,
6737                                                                                 (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);
6738                                                                         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)
6739                                                                                 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,
6740                                                                                 (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,
6741                                                                                 (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);
6742                                                                         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)
6743                                                                                 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,
6744                                                                                 (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,
6745                                                                                 (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);
6746                                                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6747                                                                                 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,
6748                                                                                 (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,
6749                                                                                 (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);
6750                                                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
6751                                                                         //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
6752                                                                         //if(isnormal(M[12])&&isnormal(M[13])&&isnormal(M[14])){
6753                                                                         //if(!isnormal(scale))test=1;
6754                                                                         //if(isnormal(scale)){
6755                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
6756                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
6757                                                                         skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
6758                                                                         //test=2;
6759                                                                         //}
6760                                                                         //}
6761                                                                 glPopMatrix();
6762                                                                 //}
6763                                                         }
6764                                                 }
6765                                                 if(!playerdetail||skeleton.free==3)
6766                                                 {
6767                                                         for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
6768                                                         {
6769                                                                 //if(skeleton.muscles[i].verticeslow[j]<skeleton.modellow.vertexNum&&skeleton.muscles[i].verticeslow[j]>=0){
6770                                                                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6771                                                                 glPushMatrix();
6772                                                                         if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6773                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
6774                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
6775                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
6776                                                                         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)
6777                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
6778                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
6779                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
6780                                                                         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)
6781                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
6782                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
6783                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
6784                                                                         if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6785                                                                                 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
6786                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
6787                                                                                 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
6788
6789                                                                         glGetFloatv(GL_MODELVIEW_MATRIX,M);
6790                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
6791                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
6792                                                                         skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
6793                                                                 glPopMatrix();
6794                                                                 //}
6795                                                         }
6796                                                 }
6797                                         glPopMatrix();
6798                                 }
6799                                 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
6800                                         mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
6801
6802                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6803                                         glPushMatrix();
6804                                                 glLoadIdentity();
6805                                                 if(!skeleton.free)glRotatef(tilt2,1,0,0);
6806                                                 if(!skeleton.free)glRotatef(tilt,0,0,1);
6807                                                 glTranslatef(mid.x,mid.y,mid.z);
6808                                                 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
6809                                                 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
6810
6811                                                 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
6812                                                 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
6813
6814                                                 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
6815                                                 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
6816
6817                                                 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
6818                                                         glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6819                                                         glPushMatrix();
6820                                                                 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
6821                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
6822                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
6823                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
6824                                                                 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)
6825                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
6826                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
6827                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
6828                                                                 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)
6829                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
6830                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
6831                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
6832                                                                 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
6833                                                                         glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
6834                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
6835                                                                         (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
6836                                                                 glGetFloatv(GL_MODELVIEW_MATRIX,M);
6837                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
6838                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
6839                                                                 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
6840                                                         glPopMatrix();
6841                                                 }
6842                                         glPopMatrix();
6843                                 }
6844                                 updatedelay=1+(float)(Random()%100)/1000;
6845                         }
6846                         if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
6847                                 normalsupdatedelay=1;
6848                                 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
6849                                 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
6850                                 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
6851                         }
6852                         else
6853                         {
6854                                 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
6855                                 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
6856                                 if(skeleton.clothes){
6857                                         skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
6858                                 }
6859                         }
6860                 }
6861                 framemult=.01;
6862                 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
6863                 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
6864                 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
6865                 if(skeleton.free==1)updatedelaychange*=6;
6866                 if(id==0)updatedelaychange*=8;
6867                 updatedelay+=updatedelaychange;
6868
6869                 glMatrixMode(GL_MODELVIEW);                                                     // Select The Modelview Matrix
6870                 glPushMatrix();
6871                 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
6872                 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
6873                 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
6874                 if(!skeleton.free)glRotatef(rotation,0,1,0);
6875                 if(showpoints){
6876                         glPointSize(5);
6877                         glColor4f(.4,1,.4,1);
6878                         glDisable(GL_LIGHTING);
6879                         glDisable(GL_TEXTURE_2D);
6880                         glBegin(GL_POINTS);
6881                         if(playerdetail)
6882                                 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
6883                                         glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
6884                                 }
6885                                 glEnd();
6886                                 glBegin(GL_LINES);
6887
6888                                 if(playerdetail)
6889                                         for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
6890                                                 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);
6891                                                 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);
6892                                                 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);
6893                                                 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);
6894                                                 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);
6895                                                 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);
6896                                         }
6897
6898                                 glEnd();
6899                 }
6900
6901                 terrainlight=terrain.getLighting(coords.x,coords.z);
6902                 distance=findDistancefast(&viewer,&coords);
6903                 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
6904                 if(distance>1)distance=1;
6905                 if(distance>0){
6906                         terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
6907                         if(terrainheight<1)terrainheight=1;
6908                         if(terrainheight>1.7)terrainheight=1.7;
6909
6910                         //burnt=0;
6911                         glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
6912                         glDisable(GL_BLEND);
6913                         glAlphaFunc(GL_GREATER, 0.0001);
6914                         glEnable(GL_TEXTURE_2D);
6915                         if(cellophane){
6916                                 glDisable(GL_TEXTURE_2D);
6917                                 glColor4f(.7,.35,0,.5);
6918                                 glDepthMask(0);
6919                                 glEnable(GL_LIGHTING);
6920                                 glEnable(GL_BLEND);
6921                         }
6922                         if(tutoriallevel&&id!=0){
6923                                 //glDisable(GL_TEXTURE_2D);
6924                                 glColor4f(.7,.7,.7,0.6);
6925                                 glDepthMask(0);
6926                                 glEnable(GL_LIGHTING);
6927                                 glEnable(GL_BLEND);
6928                                 if(canattack&&cananger)
6929                                         if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6930                                                 glDisable(GL_TEXTURE_2D);
6931                                                 glColor4f(1,0,0,0.8);
6932                                         }
6933                                         glMatrixMode(GL_TEXTURE);
6934                                         glPushMatrix();
6935                                         glTranslatef(0,-smoketex,0);
6936                                         glTranslatef(-smoketex,0,0);
6937                         }
6938                         if(playerdetail){
6939                                 if(!showpoints){
6940                                         if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6941                                         else skeleton.drawmodel.draw();
6942                                 }
6943                         }
6944                         if(!playerdetail){
6945                                 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6946                                 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6947                         }
6948
6949                         if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
6950                                 if(tutoriallevel&&id!=0){
6951                                         glPopMatrix();
6952                                         glMatrixMode(GL_MODELVIEW);
6953                                         glEnable(GL_TEXTURE_2D);
6954                                         glColor4f(.7,.7,.7,0.6);
6955                                         glDepthMask(0);
6956                                         glEnable(GL_LIGHTING);
6957                                         glEnable(GL_BLEND);
6958                                         if(canattack&&cananger)
6959                                                 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6960                                                         glDisable(GL_TEXTURE_2D);
6961                                                         glColor4f(1,0,0,0.8);
6962                                                 }
6963                                                 glMatrixMode(GL_TEXTURE);
6964                                                 glPushMatrix();
6965                                                 glTranslatef(0,-smoketex*.6,0);
6966                                                 glTranslatef(smoketex*.6,0,0);
6967                                                 if(playerdetail){
6968                                                         if(!showpoints){
6969                                                                 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6970                                                                 else skeleton.drawmodel.draw();
6971                                                         }
6972                                                 }
6973                                                 if(!playerdetail){
6974                                                         if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6975                                                         else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6976                                                 }
6977                                 }
6978
6979
6980                                 if(tutoriallevel&&id!=0){
6981                                         glPopMatrix();
6982                                         glMatrixMode(GL_MODELVIEW);
6983                                         glEnable(GL_TEXTURE_2D);
6984                                 }
6985                                 if(skeleton.clothes){
6986                                         glDepthMask(0);
6987                                         glEnable(GL_BLEND);
6988                                         if(!immediate)skeleton.drawmodelclothes.draw();
6989                                         if(immediate)skeleton.drawmodelclothes.drawimmediate();
6990                                         glDepthMask(1);
6991                                 }
6992                 }
6993                 glPopMatrix();
6994
6995                 if(num_weapons>0){
6996                         for(k=0;k<num_weapons;k++){
6997                                 i=weaponids[k];
6998                                 if(weaponactive==k){
6999                                         if(weapons.type[i]!=staff){
7000                                                 for(j=0;j<skeleton.num_muscles;j++){
7001                                                         if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
7002                                                                 weaponattachmuscle=j;
7003                                                         }
7004                                                 }
7005                                                 for(j=0;j<skeleton.num_muscles;j++){
7006                                                         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){
7007                                                                 weaponrotatemuscle=j;
7008                                                         }
7009                                                 }
7010                                                 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
7011                                                 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
7012                                         }
7013                                         if(weapons.type[i]==staff){
7014                                                 for(j=0;j<skeleton.num_muscles;j++){
7015                                                         if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
7016                                                                 weaponattachmuscle=j;
7017                                                         }
7018                                                 }
7019                                                 for(j=0;j<skeleton.num_muscles;j++){
7020                                                         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){
7021                                                                 weaponrotatemuscle=j;
7022                                                         }
7023                                                 }
7024                                                 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
7025                                                 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
7026                                                 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
7027                                                 XYZ tempnormthing,vec1,vec2;
7028                                                 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
7029                                                 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
7030                                                 CrossProduct(&vec1,&vec2,&tempnormthing);
7031                                                 Normalise(&tempnormthing);
7032                                                 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);
7033                                                 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
7034                                                 XYZ weaptargnorm;
7035                                                 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
7036                                                 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7037                                                 Normalise(&weaptargnorm);
7038                                                 weaponpoint-=weaptargnorm*2;
7039                                                 }*/
7040                                         }
7041                                 }
7042                                 if(weaponactive!=k&&weaponstuck!=k){
7043                                         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;
7044                                         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;
7045                                         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;
7046                                         for(j=0;j<skeleton.num_muscles;j++){
7047                                                 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){
7048                                                         weaponrotatemuscle=j;
7049                                                 }
7050                                         }
7051                                 }
7052                                 if(weaponstuck==k){
7053                                         if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
7054                                         else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
7055                                         for(j=0;j<skeleton.num_muscles;j++){
7056                                                 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){
7057                                                         weaponrotatemuscle=j;
7058                                                 }
7059                                         }
7060                                 }
7061                                 if(!skeleton.free){
7062                                         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;
7063                                         weapons.bigrotation[i]=rotation;
7064                                         weapons.bigtilt[i]=tilt;
7065                                         weapons.bigtilt2[i]=tilt2;
7066                                 }
7067                                 if(skeleton.free){
7068                                         weapons.position[i]=weaponpoint*scale+coords;
7069                                         weapons.bigrotation[i]=0;
7070                                         weapons.bigtilt[i]=0;
7071                                         weapons.bigtilt2[i]=0;
7072                                 }
7073                                 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
7074                                 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
7075                                 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
7076                                 if(weaponactive==k){
7077                                         if(weapons.type[i]==knife){
7078                                                 weapons.smallrotation[i]=180;
7079                                                 weapons.smallrotation2[i]=0;
7080                                                 if(isCrouch()||wasCrouch()){
7081                                                         weapons.smallrotation2[i]=20;
7082                                                 }
7083                                                 if(targetanimation==hurtidleanim){
7084                                                         weapons.smallrotation2[i]=50;
7085                                                 }
7086                                                 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
7087                                                         XYZ temppoint1,temppoint2,tempforward;
7088                                                         float distance;
7089
7090                                                         temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
7091                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7092                                                         distance=findDistance(&temppoint1,&temppoint2);
7093                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7094                                                         weapons.rotation2[i]*=360/6.28;
7095                                                         temppoint1.y=0;
7096                                                         temppoint2.y=0;
7097                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7098                                                         weapons.rotation1[i]*=360/6.28;
7099                                                         weapons.rotation3[i]=0;
7100                                                         weapons.smallrotation[i]=-90;
7101                                                         weapons.smallrotation2[i]=0;
7102                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7103                                                 }
7104                                                 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
7105                                                         XYZ temppoint1,temppoint2,tempforward;
7106                                                         float distance;
7107
7108                                                         temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
7109                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7110                                                         distance=findDistance(&temppoint1,&temppoint2);
7111                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7112                                                         weapons.rotation2[i]*=360/6.28;
7113                                                         temppoint1.y=0;
7114                                                         temppoint2.y=0;
7115                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7116                                                         weapons.rotation1[i]*=360/6.28;
7117                                                         weapons.rotation3[i]=0;
7118                                                         weapons.smallrotation[i]=90;
7119                                                         weapons.smallrotation2[i]=0;
7120                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7121                                                 }
7122                                                 if(targetanimation==knifethrowanim){
7123                                                         weapons.smallrotation[i]=90;
7124                                                         //weapons.smallrotation2[i]=-90;
7125                                                         weapons.smallrotation2[i]=0;
7126                                                         weapons.rotation1[i]=0;
7127                                                         weapons.rotation2[i]=0;
7128                                                         weapons.rotation3[i]=0;
7129                                                 }
7130                                                 if(targetanimation==knifesneakattackanim&&targetframe<5){
7131                                                         weapons.smallrotation[i]=-90;
7132                                                         weapons.rotation1[i]=0;
7133                                                         weapons.rotation2[i]=0;
7134                                                         weapons.rotation3[i]=0;
7135                                                 }
7136                                         }
7137                                         if(weapons.type[i]==sword){
7138                                                 weapons.smallrotation[i]=0;
7139                                                 weapons.smallrotation2[i]=0;
7140                                                 if(targetanimation==knifethrowanim){
7141                                                         weapons.smallrotation[i]=-90;
7142                                                         weapons.smallrotation2[i]=0;
7143                                                         weapons.rotation1[i]=0;
7144                                                         weapons.rotation2[i]=0;
7145                                                         weapons.rotation3[i]=0;
7146                                                 }
7147                                                 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)){
7148                                                         XYZ temppoint1,temppoint2,tempforward;
7149                                                         float distance;
7150
7151                                                         temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
7152                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7153                                                         distance=findDistance(&temppoint1,&temppoint2);
7154                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7155                                                         weapons.rotation2[i]*=360/6.28;
7156                                                         temppoint1.y=0;
7157                                                         temppoint2.y=0;
7158                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7159                                                         weapons.rotation1[i]*=360/6.28;
7160                                                         weapons.rotation3[i]=0;
7161                                                         weapons.smallrotation[i]=90;
7162                                                         weapons.smallrotation2[i]=0;
7163                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7164                                                 }
7165                                         }
7166                                         if(weapons.type[i]==staff){
7167                                                 weapons.smallrotation[i]=100;
7168                                                 weapons.smallrotation2[i]=0;
7169                                                 if((targetanimation==staffhitanim&&currentanimation==staffhitanim)||(targetanimation==staffhitreversedanim&&currentanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&&currentanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&&currentanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&&currentanimation==staffspinhitanim)){
7170                                                         XYZ temppoint1,temppoint2,tempforward;
7171                                                         float distance;
7172
7173                                                         temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
7174                                                         temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
7175                                                         distance=findDistance(&temppoint1,&temppoint2);
7176                                                         weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
7177                                                         weapons.rotation2[i]*=360/6.28;
7178                                                         temppoint1.y=0;
7179                                                         temppoint2.y=0;
7180                                                         weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
7181                                                         weapons.rotation1[i]*=360/6.28;
7182                                                         weapons.rotation3[i]=0;
7183                                                         weapons.smallrotation[i]=90;
7184                                                         weapons.smallrotation2[i]=0;
7185                                                         if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
7186                                                 }
7187                                         }
7188                                 }
7189                                 if(weaponactive!=k&&weaponstuck!=k){
7190                                         if(weapons.type[i]==knife){
7191                                                 weapons.smallrotation[i]=-70;
7192                                                 weapons.smallrotation2[i]=10;
7193                                         }
7194                                         if(weapons.type[i]==sword){
7195                                                 weapons.smallrotation[i]=-100;
7196                                                 weapons.smallrotation2[i]=-8;
7197                                         }
7198                                         if(weapons.type[i]==staff){
7199                                                 weapons.smallrotation[i]=-100;
7200                                                 weapons.smallrotation2[i]=-8;
7201                                         }
7202                                 }
7203                                 if(weaponstuck==k){
7204                                         if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
7205                                         else weapons.smallrotation[i]=0;
7206                                         weapons.smallrotation2[i]=10;
7207                                         //if(animation[targetanimation].height==lowheight&&animation[targetanimation].attack==neutral){
7208                                         //}
7209                                 }
7210                         }
7211                 }
7212         }
7213
7214         calcrot=0;
7215         if(skeleton.free)calcrot=1;
7216         if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
7217         if(currentanimation!=targetanimation)calcrot=1;
7218         //if(id==0)calcrot=1;
7219         if(skeleton.free==2)calcrot=0;
7220
7221         return 0;
7222 }
7223
7224
7225 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
7226 {
7227         static int i,j;
7228         static float distance;
7229         static float olddistance;
7230         static int intersecting;
7231         static int firstintersecting;
7232         static XYZ point;
7233         static XYZ oldp1;
7234         static XYZ start,end;
7235         static float slopethreshold=-.4;
7236
7237         firstintersecting=-1;
7238
7239         oldp1=*p1;
7240         *p1=*p1-*move;
7241         if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
7242         if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
7243         for(i=0;i<4;i++){
7244                 for (j=0;j<model->TriangleNum;j++){
7245                         if(model->facenormals[j].y<=slopethreshold){
7246                                 intersecting=0;
7247                                 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)));
7248                                 if(distance<radius){
7249                                         point=*p1-model->facenormals[j]*distance;
7250                                         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;
7251                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7252                                                 &model->vertex[model->Triangles[j].vertex[1]],
7253                                                 p1, &radius);
7254                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
7255                                                 &model->vertex[model->Triangles[j].vertex[2]],
7256                                                 p1, &radius);
7257                                         if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
7258                                                 &model->vertex[model->Triangles[j].vertex[2]],
7259                                                 p1, &radius);
7260                                         end=*p1-point;
7261                                         if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
7262                                                 start=*p1;
7263                                                 end=*p1;
7264                                                 end.y-=radius;
7265                                                 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)){
7266                                                         p1->y=point.y+radius;
7267                                                         if((targetanimation==jumpdownanim||isFlip())){
7268                                                                 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
7269
7270                                                                 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
7271                                                                 target=0;
7272                                                                 targetframe=0;
7273                                                                 onterrain=1;
7274
7275                                                                 if(id==0){
7276                                                                         OPENAL_SetPaused(channels[whooshsound], true);
7277                                                                         OPENAL_SetVolume(channels[whooshsound], 0);
7278                                                                 }
7279
7280                                                                 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
7281                                                                         if(isFlip())jumppower=-4;
7282                                                                         targetanimation=getLanding();
7283                                                                         float gLoc[3];
7284                                                                         float vel[3];
7285                                                                         gLoc[0]=coords.x;
7286                                                                         gLoc[1]=coords.y;
7287                                                                         gLoc[2]=coords.z;
7288                                                                         vel[0]=velocity.x;
7289                                                                         vel[1]=velocity.y;
7290                                                                         vel[2]=velocity.z;
7291                                                                         PlaySoundEx( landsound, samp[landsound], NULL, true);
7292                                                                         OPENAL_3D_SetAttributes(channels[landsound], gLoc, vel);
7293                                                                         OPENAL_SetVolume(channels[landsound], 128);
7294                                                                         OPENAL_SetPaused(channels[landsound], false);
7295
7296                                                                         if(id==0){
7297                                                                                 envsound[numenvsounds]=coords;
7298                                                                                 envsoundvol[numenvsounds]=16;
7299                                                                                 envsoundlife[numenvsounds]=.4;
7300                                                                                 numenvsounds++;
7301                                                                         }
7302                                                                 }
7303                                                         }
7304                                                 }
7305                                         }
7306                                 }
7307                                 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
7308                         }
7309                 }
7310                 for (j=0;j<model->TriangleNum;j++){
7311                         if(model->facenormals[j].y>slopethreshold){
7312                                 intersecting=0;
7313                                 start=*p1;
7314                                 start.y-=radius/4;
7315                                 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)));
7316                                 if(distance<radius*.5){
7317                                         point=start-model->facenormals[j]*distance;
7318                                         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;
7319                                         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,
7320                                                 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
7321                                                 p1->x, p1->y, p1->z, radius/2);
7322                                         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,
7323                                                 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
7324                                                 p1->x, p1->y, p1->z, radius/2);
7325                                         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,
7326                                                 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
7327                                                 p1->x, p1->y, p1->z, radius/2);
7328                                         end=*p1-point;
7329                                         if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
7330                                                 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
7331                                                         start=velocity;
7332                                                         velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
7333                                                         if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
7334                                                 }
7335                                                 *p1+=model->facenormals[j]*(distance-radius*.5);
7336                                         }
7337                                 }
7338                                 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
7339                         }
7340                 }
7341         }
7342         if(*rotate)*p=DoRotation(*p,0,*rotate,0);
7343         *p=*p+*move;
7344         if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
7345         *p1+=*move;
7346         return firstintersecting;
7347 }
7348
7349 Person::Person()
7350 {
7351         whichpatchx = 0;
7352         whichpatchz = 0;
7353
7354         currentframe = 0;
7355         targetframe = 0;
7356         currentanimation = 0;
7357         targetanimation = 0;
7358         oldcurrentframe = 0;
7359         oldtargetframe = 0;
7360         oldcurrentanimation = 0;
7361         oldtargetanimation = 0;
7362
7363         howactive = 0;
7364
7365         parriedrecently = 0;
7366
7367         superruntoggle = 0;
7368
7369         lastattack = 0,lastattack2 = 0,lastattack3 = 0;
7370
7371         currentoffset = 0,targetoffset = 0,offset = 0;
7372         target = 0;
7373         transspeed = 0;
7374
7375         realoldcoords = 0;
7376         oldcoords = 0;
7377         coords = 0;
7378         originalcoords = 0;
7379         velocity = 0;
7380
7381         proportionhead = 0;
7382         proportionlegs = 0;
7383         proportionarms = 0;
7384         proportionbody = 0;
7385
7386         heightleft = 0;
7387         heightright = 0;
7388
7389         unconscioustime = 0;
7390
7391         immobile = 0;
7392
7393         velspeed = 0;
7394         targetrotation = 0;
7395         targetrot = 0;
7396         rot = 0;
7397         oldrot = 0;
7398         lookrotation = 0;
7399         lookrotation2 = 0;
7400         rotation = 0;
7401         rotation2 = 0;
7402         lowrotation = 0;
7403         tilt = 0;
7404         targettilt = 0;
7405         tilt2 = 0;
7406         targettilt2 = 0;
7407         rabbitkickenabled = 0;
7408
7409         bloodloss = 0;
7410         bleeddelay = 0;
7411         skiddelay = 0;
7412         skiddingdelay = 0;
7413         deathbleeding = 0;
7414         tempdeltav = 0;
7415
7416         damagetolerance = 0;
7417         damage = 0;
7418         permanentdamage = 0;
7419         superpermanentdamage = 0;       lastcollide = 0;
7420         dead = 0;
7421
7422         jumppower = 0;
7423         onground = 0;
7424         madskills = 0;
7425
7426         wentforweapon = 0;
7427
7428         calcrot = 0;
7429
7430         backwardsanim = 0;
7431
7432         facing = 0;
7433
7434         bleeding = 0;
7435         bleedx = 0,bleedy;
7436         direction = 0;
7437         texupdatedelay = 0;
7438
7439         headrotation = 0,headrotation2 = 0;
7440         targetheadrotation = 0,targetheadrotation2 = 0;
7441
7442         onterrain = 0;
7443         pause = 0;
7444
7445         grabdelay = 0;
7446
7447         victim = 0;
7448         hasvictim = 0;
7449
7450         updatedelay = 0;
7451         normalsupdatedelay = 0;
7452
7453         jumpstart = 0;
7454
7455         forwardkeydown = 0;
7456         forwardstogglekeydown = 0;
7457         rightkeydown = 0;
7458         leftkeydown = 0;
7459         backkeydown = 0;
7460         jumpkeydown = 0;
7461         jumptogglekeydown = 0;
7462         crouchkeydown = 0;
7463         crouchtogglekeydown = 0;
7464         drawkeydown = 0;
7465         drawtogglekeydown = 0;
7466         throwkeydown = 0;
7467         throwtogglekeydown = 0;
7468         attackkeydown = 0;
7469         feint = 0;
7470         lastfeint = 0;
7471         headless = 0;
7472
7473         crouchkeydowntime = 0;
7474         jumpkeydowntime = 0;
7475         freefall = 0;
7476
7477
7478         turnspeed = 0;
7479
7480         aitype = 0;
7481         aitarget = 0;
7482         aiupdatedelay = 0;
7483         losupdatedelay = 0;
7484         ally = 0;
7485         movetarget = 0;
7486         collide = 0;
7487         collided = 0;
7488         avoidcollided = 0;
7489         loaded = 0;
7490         whichdirection = 0;
7491         whichdirectiondelay = 0;
7492         avoidsomething = 0;     avoidwhere = 0;
7493         blooddimamount = 0;
7494
7495         staggerdelay = 0;
7496         blinkdelay = 0;
7497         twitchdelay = 0;
7498         twitchdelay2 = 0;
7499         twitchdelay3 = 0;
7500         lefthandmorphness = 0;
7501         righthandmorphness = 0;
7502         headmorphness = 0;
7503         chestmorphness = 0;
7504         tailmorphness = 0;
7505         targetlefthandmorphness = 0;
7506         targetrighthandmorphness = 0;
7507         targetheadmorphness = 0;
7508         targetchestmorphness = 0;
7509         targettailmorphness = 0;
7510         lefthandmorphstart = 0,lefthandmorphend = 0;
7511         righthandmorphstart = 0,righthandmorphend = 0;
7512         headmorphstart = 0,headmorphend = 0;
7513         chestmorphstart = 0,chestmorphend = 0;
7514         tailmorphstart = 0,tailmorphend = 0;
7515
7516         weaponmissdelay = 0;
7517         highreversaldelay = 0;
7518         lowreversaldelay = 0;
7519         nocollidedelay = 0;
7520
7521         creature = 0;
7522
7523         id = 0;
7524
7525         //Skeleton skeleton;
7526
7527         speed = 0;
7528         scale = 0;
7529         power = 0;
7530         speedmult = 0;
7531
7532         protectionhead = 0;
7533         protectionhigh = 0;
7534         protectionlow = 0;
7535         armorhead = 0;
7536         armorhigh = 0;
7537         armorlow = 0;
7538         metalhead = 0;
7539         metalhigh = 0;
7540         metallow = 0;
7541
7542         numclothes = 0;
7543
7544         memset(clothes, 0, sizeof(clothes));
7545         memset(clothestintr, 0, sizeof(clothestintr));
7546         memset(clothestintg, 0, sizeof(clothestintg));
7547         memset(clothestintb, 0, sizeof(clothestintb));
7548
7549         landhard = 0;
7550         bled = 0;
7551         spurt = 0;
7552         onfire = 0;
7553         onfiredelay = 0;        burnt = 0;
7554         fireduration = 0;
7555
7556         flamedelay = 0;
7557         updatestuffdelay = 0;
7558
7559         playerdetail = 0;
7560
7561         num_weapons = 0;
7562
7563         memset(weaponids, 0, sizeof(weaponids));
7564
7565         weaponactive = 0;
7566         weaponstuck = 0;
7567         weaponstuckwhere = 0;
7568         weaponwhere = 0;
7569
7570         numwaypoints = 0;
7571
7572         memset(waypoints, 0, sizeof(waypoints));
7573         memset(waypointtype, 0, sizeof(waypointtype));
7574
7575         pausetime = 0;
7576         hastempwaypoint = 0;
7577         tempwaypoint = 0;
7578
7579         headtarget = 0;
7580         interestdelay = 0;
7581
7582         finalfinaltarget = 0;
7583         finaltarget = 0;
7584         finalpathfindpoint = 0;
7585         targetpathfindpoint = 0;
7586         lastpathfindpoint = 0;
7587         lastpathfindpoint2 = 0;
7588         lastpathfindpoint3 = 0;
7589         lastpathfindpoint4 = 0;
7590         onpath = 0;
7591
7592         waypoint = 0;
7593         jumppath = 0;
7594
7595         lastseen = 0;
7596         lastseentime = 0;
7597         lastchecktime = 0;
7598         stunned = 0;
7599         surprised = 0;
7600         runninghowlong = 0;     lastoccluded = 0;
7601         laststanding = 0;
7602         escapednum = 0;
7603
7604         speechdelay = 0;
7605         neckspurtdelay = 0;
7606         neckspurtparticledelay = 0;
7607         neckspurtamount = 0;
7608
7609         whichskin = 0;
7610         rabbitkickragdoll = 0;
7611
7612         averageloc = 0;
7613         oldaverageloc = 0;
7614
7615         //Animation tempanimation;
7616
7617         occluded = 0;
7618
7619         jumpclimb = 0;
7620 }
7621
7622 Person::~Person()
7623 {
7624 }
7625