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