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