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