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