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