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