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