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