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