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