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