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