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