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