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