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