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