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