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