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