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