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