2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
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.
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.
15 See the GNU General Public License for more details.
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.
22 /**> HEADER FILES <**/
24 #include "openal_wrapper.h"
25 #include "Animation.h"
30 extern float multiplier;
31 extern int channels[100];
32 extern Terrain terrain;
34 extern int environment;
36 extern FRUSTUM frustum;
38 extern float realmultiplier;
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;
49 extern bool autoslomo;
50 extern float camerashake;
52 extern float terraindetail;
53 extern float viewdistance;
54 extern float blackout;
55 extern int difficulty;
57 extern float fadestart;
59 extern bool winfreeze;
60 extern float flashamount,flashr,flashg,flashb;
61 extern int flashdelay;
62 extern bool showpoints;
63 extern bool immediate;
65 extern bool tilt2weird;
66 extern bool tiltweird;
68 extern bool proportionweird;
69 extern bool vertexweird[6];
70 extern XYZ envsound[30];
71 extern float envsoundvol[30];
72 extern float envsoundlife[30];
73 extern int numenvsounds;
74 extern int tutoriallevel;
75 extern float smoketex;
76 extern int tutorialstage;
77 extern bool reversaltrain;
78 extern bool canattack;
80 extern float damagedealt;
82 extern float hostiletime;
84 extern int indialogue;
86 extern bool gamestarted;
88 void Person::CheckKick()
91 && (targetanimation == rabbitkickanim
95 && currentanimation == rabbitkickanim)
96 && (findDistancefast(&coords,&victim->coords) < 1.2)
97 && (!victim->skeleton.free)))
100 if (animation[victim->targetanimation].height!=lowheight)
102 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
103 XYZ relative = velocity;
105 Normalise(&relative);
110 emit_sound_at(heavyimpactsound, victim->coords);
112 for(int i=0;i<victim->skeleton.num_joints;i++){
113 victim->skeleton.joints[i].velocity+=relative*120*damagemult;
116 victim->DoDamage(100*damagemult/victim->protectionhigh);
117 if(id==0)camerashake+=.4;
121 targetanimation=backflipanim;
126 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
128 award_bonus(id, cannon);
130 else if (victim->isCrouch())
132 targetanimation=rabbitkickreversedanim;
133 currentanimation=rabbitkickreversedanim;
134 victim->currentanimation=rabbitkickreversalanim;
135 victim->targetanimation=rabbitkickreversalanim;
141 victim->oldcoords=victim->coords;
142 coords=victim->coords;
143 victim->targetrotation=targetrotation;
148 void Person::CatchFire(){
149 XYZ flatfacing,flatvelocity;
151 for(int i=0;i<10;i++){
152 howmany=abs(Random()%(skeleton.num_joints));
153 if(!skeleton.free)flatvelocity=velocity;
154 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity;
155 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
156 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
157 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, 2, 1);
162 emit_sound_at(firestartsound, coords);
164 emit_stream_at(stream_firesound, coords);
171 int Person::getIdle(){
172 if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
173 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)){
174 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
175 if(creature==rabbittype)return fightidleanim;
176 if(creature==wolftype)return wolfidle;
178 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
179 if(weapons.type[weaponids[weaponactive]]==knife)return knifefightidleanim;
180 if(weapons.type[weaponids[weaponactive]]==sword&&victim->weaponactive!=-1)return swordfightidlebothanim;
181 if(weapons.type[weaponids[weaponactive]]==sword)return swordfightidleanim;
182 if(weapons.type[weaponids[weaponactive]]==staff)return swordfightidleanim;
184 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
186 if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
187 if(howactive==typesitting)return sitanim;
188 if(howactive==typesittingwall)return sitwallanim;
189 if(howactive==typesleeping)return sleepanim;
190 if(howactive==typedead1)return dead1anim;
191 if(howactive==typedead2)return dead2anim;
192 if(howactive==typedead3)return dead3anim;
193 if(howactive==typedead4)return dead4anim;
194 if(creature==rabbittype)return bounceidleanim;
195 if(creature==wolftype)return wolfidle;
199 int Person::getCrouch(){
200 if(creature==rabbittype)return crouchanim;
201 if(creature==wolftype)return wolfcrouchanim;
205 int Person::getRun(){
206 if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
207 if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
209 if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
210 if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
214 int Person::getStop(){
215 if(creature==rabbittype)return stopanim;
216 if(creature==wolftype)return wolfstopanim;
220 int Person::getLanding(){
221 if(creature==rabbittype)return landanim;
222 if(creature==wolftype)return wolflandanim;
226 int Person::getLandhard(){
227 if(creature==rabbittype)return landhardanim;
228 if(creature==wolftype)return wolflandhardanim;
233 SolidHitBonus(int playerid)
235 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
236 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
238 award_bonus(playerid, solidhit);
241 void Person::DoBlood(float howmuch,int which){
242 static int bleedxint,bleedyint;
244 //if(howmuch&&id==0)blooddimamount=1;
245 if(bloodtoggle&&tutoriallevel!=1){
246 if(bleeding<=0&&spurt){
248 for(int i=0;i<3;i++){
252 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
255 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
257 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
258 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
260 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
261 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
264 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);
265 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);
269 for(int i=0;i<3;i++){
273 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
274 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
277 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
278 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
282 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
284 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);
286 Sprite::setLastSpriteSpecial(3);
291 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
294 int texdetailint=realtexdetail;
295 if(creature==rabbittype)
296 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){
297 bleedxint=abs(Random()%512);
298 bleedyint=abs(Random()%512);
300 if(creature==wolftype)
301 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){
302 bleedxint=abs(Random()%512);
303 bleedyint=abs(Random()%512);
307 bleedy/=realtexdetail;
308 bleedx/=realtexdetail;
309 direction=abs(Random()%2)*2-1;
313 if(bleeding>2)bleeding=2;
316 void Person::DoBloodBig(float howmuch,int which){
317 static int bleedxint,bleedyint,i,j;
319 if(howmuch&&id==0)blooddimamount=1;
321 if(tutoriallevel!=1||id==0)
322 if(aitype!=playercontrolled&&howmuch>0){
325 if(creature==wolftype){
326 int i=abs(Random()%2);
327 if(i==0)whichsound=snarlsound;
328 if(i==1)whichsound=snarl2sound;
329 envsound[numenvsounds]=coords;
330 envsoundvol[numenvsounds]=16;
331 envsoundlife[numenvsounds]=.4;
334 if(creature==rabbittype){
335 int i=abs(Random()%2);
336 if(i==0)whichsound=rabbitpainsound;
337 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
338 envsound[numenvsounds]=coords;
339 envsoundvol[numenvsounds]=16;
340 envsoundlife[numenvsounds]=.4;
342 //if(i==2)whichsound=rabbitpain2sound;
346 emit_sound_at(whichsound, coords);
349 if(id==0&&howmuch>0){
357 if(bloodtoggle&&decals&&tutoriallevel!=1){
358 if(bleeding<=0&&spurt){
360 for(int i=0;i<3;i++){
364 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
367 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
369 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
370 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
372 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
373 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
376 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);
377 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);
381 int offsetx=0,offsety=0;
384 offsetx=abs(Random()%60);
386 if(which==190||which==185){
388 offsetx=abs(Random()%100)-20;
398 if(which==220||which==215){
399 //offsety=Random()%20;
401 //offsetx=abs(Random()%80);
410 if(creature==rabbittype)
413 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
414 if(i<startx)startx=i;
415 if(j<starty)starty=j;
421 if(creature==wolftype)
424 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
425 if(i<startx)startx=i;
426 if(j<starty)starty=j;
438 if(startx<0)startx=0;
439 if(starty<0)starty=0;
440 if(endx>512-1)endx=512-1;
441 if(endy>512-1)endy=512-1;
442 if(endx<startx)endx=startx;
443 if(endy<starty)endy=starty;
445 startx/=realtexdetail;
446 starty/=realtexdetail;
450 int texdetailint=realtexdetail;
452 if(creature==rabbittype)
453 for(i=startx;i<endx;i++){
454 for(j=starty;j<endy;j++){
455 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){
456 color=Random()%85+170;
457 where=i*skeleton.skinsize*3+j*3;
458 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
459 skeleton.skinText[where+1]=0;
460 skeleton.skinText[where+2]=0;
464 if(creature==wolftype)
465 for(i=startx;i<endx;i++){
466 for(j=starty;j<endy;j++){
467 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){
468 color=Random()%85+170;
469 where=i*skeleton.skinsize*3+j*3;
470 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
471 skeleton.skinText[where+1]=0;
472 skeleton.skinText[where+2]=0;
476 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
481 if(creature==rabbittype)
482 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){
483 bleedxint=abs(Random()%512);
484 bleedyint=abs(Random()%512);
486 if(creature==wolftype)
487 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){
488 bleedxint=abs(Random()%512);
489 bleedyint=abs(Random()%512);
491 bleedy=bleedxint+offsetx;
492 bleedx=bleedyint+offsety;
493 bleedy/=realtexdetail;
494 bleedx/=realtexdetail;
495 if(bleedx<0)bleedx=0;
496 if(bleedy<0)bleedy=0;
497 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
498 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
499 direction=abs(Random()%2)*2-1;
502 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
503 deathbleeding+=bleeding;
504 bloodloss+=bleeding*3;
506 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
507 if(abs(Random()%2)==0){aitype=gethelptype;
510 else aitype=attacktypecutoff;
513 if(bleeding>2)bleeding=2;
516 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
517 static int bleedxint,bleedyint,i,j;
519 static XYZ startpoint,endpoint,colpoint,movepoint;
520 static float rotationpoint;
522 static XYZ p1,p2,p3,p0;
526 float coordsx,coordsy;
529 if(bloodtoggle&&decals&&tutoriallevel!=1){
531 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
539 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
542 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
543 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
544 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
546 CrossProduct(p2-p1,p3-p1,&N);
547 CrossProduct(p0-p1,p3-p1,&temp);
548 s = dotproduct(&temp,&N)/findLength(&N);
549 CrossProduct(p2-p1,p1-p0,&temp);
550 t = dotproduct(&temp,&N)/findLength(&N);
553 bary.x=findDistancefast(&p0,&p1);
554 bary.y=findDistancefast(&p0,&p2);
555 bary.z=findDistancefast(&p0,&p3);
557 total=bary.x+bary.y+bary.z;
566 total=bary.x+bary.y+bary.z;
572 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
573 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
574 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
575 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
576 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
577 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
578 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;
579 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;
581 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
582 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
584 if(bleeding<=0&&spurt){
586 for(int i=0;i<3;i++){
590 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
593 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
595 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
596 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
598 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
599 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
602 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);
603 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);
607 int offsetx=0,offsety=0;
610 offsetx=abs(Random()%120);
612 if(which==220||which==215){
614 offsetx=abs(Random()%80);
617 offsetx=(1+coordsy)*512-291;
618 offsety=coordsx*512-437;
625 if(creature==rabbittype)
628 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
629 if(i<startx)startx=i;
630 if(j<starty)starty=j;
636 if(creature==wolftype)
639 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
640 if(i<startx)startx=i;
641 if(j<starty)starty=j;
652 if(startx<0)startx=0;
653 if(starty<0)starty=0;
654 if(endx>512-1)endx=512-1;
655 if(endy>512-1)endy=512-1;
656 if(endx<startx)endx=startx;
657 if(endy<starty)endy=starty;
659 startx/=realtexdetail;
660 starty/=realtexdetail;
664 int texdetailint=realtexdetail;
666 if(creature==rabbittype)
667 for(i=startx;i<endx;i++){
668 for(j=starty;j<endy;j++){
669 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){
670 color=Random()%85+170;
671 where=i*skeleton.skinsize*3+j*3;
672 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
673 skeleton.skinText[where+1]=0;
674 skeleton.skinText[where+2]=0;
676 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){
677 color=Random()%85+170;
678 where=i*skeleton.skinsize*3+j*3;
679 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
680 skeleton.skinText[where+1]=0;
681 skeleton.skinText[where+2]=0;
685 if(creature==wolftype)
686 for(i=startx;i<endx;i++){
687 for(j=starty;j<endy;j++){
688 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){
689 color=Random()%85+170;
690 where=i*skeleton.skinsize*3+j*3;
691 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
692 skeleton.skinText[where+1]=0;
693 skeleton.skinText[where+2]=0;
695 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){
696 color=Random()%85+170;
697 where=i*skeleton.skinsize*3+j*3;
698 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
699 skeleton.skinText[where+1]=0;
700 skeleton.skinText[where+2]=0;
704 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
707 bleedy=(1+coordsy)*512;
709 bleedy/=realtexdetail;
710 bleedx/=realtexdetail;
711 if(bleedx<0)bleedx=0;
712 if(bleedy<0)bleedy=0;
713 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
714 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
715 direction=abs(Random()%2)*2-1;
717 if(whichtri==-1)return 0;
719 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
720 deathbleeding+=bleeding;
721 bloodloss+=bleeding*3;
723 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
724 if(abs(Random()%2)==0){aitype=gethelptype;
727 else aitype=attacktypecutoff;
730 if(bleeding>2)bleeding=2;
736 void Person::Reverse()
738 if (!((victim->aitype == playercontrolled
740 || staggerdelay <= 0)
741 && victim->targetanimation != jumpupanim
742 && victim->targetanimation != jumpdownanim
743 && (tutoriallevel != 1 || cananger)
747 if (normaldotproduct (victim->facing, victim->coords-coords) > 0
748 && (victim->id != 0 || difficulty >= 2)
749 && (creature != wolftype || victim->creature == wolftype))
752 if(targetanimation==sweepanim){
753 targetanimation=sweepreversedanim;
754 currentanimation=sweepreversedanim;
755 victim->currentanimation=sweepreversalanim;
756 victim->targetanimation=sweepreversalanim;
758 if(targetanimation==spinkickanim){
759 targetanimation=spinkickreversedanim;
760 currentanimation=spinkickreversedanim;
761 victim->currentanimation=spinkickreversalanim;
762 victim->targetanimation=spinkickreversalanim;
764 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
765 if(targetanimation==rabbittacklinganim){
768 victim->currentframe=6;
769 victim->targetframe=7;
771 targetanimation=upunchreversedanim;
772 currentanimation=upunchreversedanim;
773 victim->currentanimation=upunchreversalanim;
774 victim->targetanimation=upunchreversalanim;
776 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
777 if(victim->weaponactive!=-1){
778 victim->throwtogglekeydown=1;
779 weapons.owner[victim->weaponids[0]]=-1;
780 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
781 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
782 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
783 weapons.missed[victim->weaponids[0]]=1;
784 weapons.freetime[victim->weaponids[0]]=0;
785 weapons.firstfree[victim->weaponids[0]]=1;
786 weapons.physics[victim->weaponids[0]]=1;
787 victim->num_weapons--;
788 if(victim->num_weapons){
789 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
790 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
793 victim->weaponactive=-1;
794 for(int j=0;j<numplayers;j++){
795 player[j].wentforweapon=0;
799 targetanimation=staffhitreversedanim;
800 currentanimation=staffhitreversedanim;
801 victim->currentanimation=staffhitreversalanim;
802 victim->targetanimation=staffhitreversalanim;
804 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
805 if(victim->weaponactive!=-1){
806 victim->throwtogglekeydown=1;
807 weapons.owner[victim->weaponids[0]]=-1;
808 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
809 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
810 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
811 weapons.missed[victim->weaponids[0]]=1;
812 weapons.freetime[victim->weaponids[0]]=0;
813 weapons.firstfree[victim->weaponids[0]]=1;
814 weapons.physics[victim->weaponids[0]]=1;
815 victim->num_weapons--;
816 if(victim->num_weapons){
817 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
818 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
821 victim->weaponactive=-1;
822 for(int j=0;j<numplayers;j++){
823 player[j].wentforweapon=0;
826 targetanimation=staffspinhitreversedanim;
827 currentanimation=staffspinhitreversedanim;
828 victim->currentanimation=staffspinhitreversalanim;
829 victim->targetanimation=staffspinhitreversalanim;
831 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
832 if(victim->weaponactive!=-1){
833 victim->throwtogglekeydown=1;
834 weapons.owner[victim->weaponids[0]]=-1;
835 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
836 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
837 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
838 weapons.missed[victim->weaponids[0]]=1;
839 weapons.freetime[victim->weaponids[0]]=0;
840 weapons.firstfree[victim->weaponids[0]]=1;
841 weapons.physics[victim->weaponids[0]]=1;
842 victim->num_weapons--;
843 if(victim->num_weapons){
844 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
845 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
848 victim->weaponactive=-1;
849 for(int j=0;j<numplayers;j++){
850 player[j].wentforweapon=0;
853 targetanimation=swordslashreversedanim;
854 currentanimation=swordslashreversedanim;
855 victim->currentanimation=swordslashreversalanim;
856 victim->targetanimation=swordslashreversalanim;
858 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
859 if(victim->weaponactive!=-1){
860 victim->throwtogglekeydown=1;
861 weapons.owner[victim->weaponids[0]]=-1;
862 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
863 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
864 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
865 weapons.missed[victim->weaponids[0]]=1;
866 weapons.freetime[victim->weaponids[0]]=0;
867 weapons.firstfree[victim->weaponids[0]]=1;
868 weapons.physics[victim->weaponids[0]]=1;
869 victim->num_weapons--;
870 if(victim->num_weapons){
871 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
872 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
875 victim->weaponactive=-1;
876 for(int j=0;j<numplayers;j++){
877 player[j].wentforweapon=0;
880 targetanimation=knifeslashreversedanim;
881 currentanimation=knifeslashreversedanim;
882 victim->currentanimation=knifeslashreversalanim;
883 victim->targetanimation=knifeslashreversalanim;
885 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
886 victim->targettilt2=targettilt2;
887 victim->currentframe=currentframe;
888 victim->targetframe=targetframe;
889 victim->target=target;
891 victim->oldcoords=victim->coords;
892 victim->coords=coords;
893 victim->targetrotation=targetrotation;
894 victim->rotation=targetrotation;
897 if(targetanimation==winduppunchanim){
898 targetanimation=winduppunchblockedanim;
899 victim->targetanimation=blockhighleftanim;
900 victim->targetframe=1;
903 victim->targetrotation=targetrotation+180;
905 if(targetanimation==wolfslapanim){
906 targetanimation=winduppunchblockedanim;
907 victim->targetanimation=blockhighleftanim;
908 victim->targetframe=1;
911 victim->targetrotation=targetrotation+180;
913 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
914 targetanimation=swordslashparriedanim;
916 victim->parriedrecently=0;
917 victim->targetanimation=swordslashparryanim;
918 victim->targetframe=1;
921 victim->targetrotation=targetrotation+180;
923 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
924 if(victim->weaponactive!=-1){
925 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
926 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
927 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
928 emit_sound_at(swordstaffsound, victim->coords);
931 emit_sound_at(metalhitsound, victim->coords);
935 victim->Puff(righthand);
937 victim->targetframe=0;
938 victim->targetanimation=staggerbackhighanim;
939 victim->targetrotation=targetrotation+180;
941 weapons.owner[victim->weaponids[0]]=-1;
942 aim=DoRotation(facing,0,90,0)*21;
944 weapons.velocity[victim->weaponids[0]]=aim*-.2;
945 weapons.tipvelocity[victim->weaponids[0]]=aim;
946 weapons.missed[victim->weaponids[0]]=1;
947 weapons.hitsomething[victim->weaponids[0]]=0;
948 weapons.freetime[victim->weaponids[0]]=0;
949 weapons.firstfree[victim->weaponids[0]]=1;
950 weapons.physics[victim->weaponids[0]]=1;
951 victim->num_weapons--;
952 if(victim->num_weapons){
953 victim->weaponids[0]=victim->weaponids[num_weapons];
954 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
956 victim->weaponactive=-1;
957 for(int i=0;i<numplayers;i++){
958 player[i].wentforweapon=0;
962 if(abs(Random()%20)==0){
963 if(weaponactive!=-1){
964 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
965 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
966 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
968 emit_sound_at(swordstaffsound, coords);
971 emit_sound_at(metalhitsound, coords);
979 targetanimation=staggerbackhighanim;
980 targetrotation=targetrotation+180;
982 weapons.owner[weaponids[0]]=-1;
983 aim=DoRotation(facing,0,90,0)*21;
985 weapons.velocity[weaponids[0]]=aim*-.2;
986 weapons.tipvelocity[weaponids[0]]=aim;
987 weapons.hitsomething[weaponids[0]]=0;
988 weapons.missed[weaponids[0]]=1;
989 weapons.freetime[weaponids[0]]=0;
990 weapons.firstfree[weaponids[0]]=1;
991 weapons.physics[weaponids[0]]=1;
994 weaponids[0]=weaponids[num_weapons];
995 if(weaponstuck==num_weapons)weaponstuck=0;
998 for(int i=0;i<numplayers;i++){
999 player[i].wentforweapon=0;
1006 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1007 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1008 victim->targetanimation=dodgebackanim;
1009 victim->targetframe=0;
1013 rotatetarget=coords-victim->coords;
1014 Normalise(&rotatetarget);
1015 victim->targetrotation=-asin(0-rotatetarget.x);
1016 victim->targetrotation*=360/6.28;
1017 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1019 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1021 victim->lastattack3=victim->lastattack2;
1022 victim->lastattack2=victim->lastattack;
1023 victim->lastattack=victim->targetanimation;
1027 victim->targetanimation=sweepanim;
1028 victim->targetframe=0;
1032 rotatetarget=coords-victim->coords;
1033 Normalise(&rotatetarget);
1034 victim->targetrotation=-asin(0-rotatetarget.x);
1035 victim->targetrotation*=360/6.28;
1036 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1038 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1040 victim->lastattack3=victim->lastattack2;
1041 victim->lastattack2=victim->lastattack;
1042 victim->lastattack=victim->targetanimation;
1049 if(aitype!=playercontrolled)feint=0;
1050 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1051 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1052 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1054 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1057 void Person::DoDamage(float howmuch){
1058 if(tutoriallevel!=1)damage+=howmuch/power;
1059 if(id!=0)damagedealt+=howmuch/power;
1060 if(id==0)damagetaken+=howmuch/power;
1062 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1063 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1064 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1065 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1066 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1068 if(id==0)camerashake+=howmuch/100;
1069 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1070 if(blackout>1)blackout=1;
1072 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1073 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1074 if(abs(Random()%2)==0){aitype=gethelptype;
1077 else aitype=attacktypecutoff;
1081 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1084 for(int i=0;i<skeleton.num_joints; i++){
1085 if(!skeleton.free)flatvelocity2=velocity;
1086 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1087 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1088 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1089 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1090 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1091 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1092 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1093 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1094 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1097 emit_sound_at(splattersound, coords);
1106 if(!dead&&creature==wolftype){
1107 award_bonus(0, Wolfbonus);
1113 if(tutoriallevel!=1||id==0)
1114 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1117 if(creature==wolftype){
1118 int i=abs(Random()%2);
1119 if(i==0)whichsound=snarlsound;
1120 if(i==1)whichsound=snarl2sound;
1121 envsound[numenvsounds]=coords;
1122 envsoundvol[numenvsounds]=16;
1123 envsoundlife[numenvsounds]=.4;
1126 if(creature==rabbittype){
1127 int i=abs(Random()%2);
1128 if(i==0)whichsound=rabbitpainsound;
1129 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1130 envsound[numenvsounds]=coords;
1131 envsoundvol[numenvsounds]=16;
1132 envsoundlife[numenvsounds]=.4;
1134 //if(i==2)whichsound=rabbitpain2sound;
1138 emit_sound_at(whichsound, coords);
1143 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1144 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1147 void Person::DoHead(){
1148 static XYZ rotatearound;
1150 static float lookspeed=500;
1152 if(!freeze&&!winfreeze){
1155 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1156 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1158 while(targetheadrotation>180)targetheadrotation-=360;
1159 while(targetheadrotation<-180)targetheadrotation+=360;
1161 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1162 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1163 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1164 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1166 if(targetheadrotation2>120)targetheadrotation2=120;
1167 if(targetheadrotation2<-120)targetheadrotation2=-120;
1168 if(targetheadrotation>120)targetheadrotation=120;
1169 if(targetheadrotation<-120)targetheadrotation=-120;
1171 if(!isIdle())targetheadrotation2=0;
1173 if(targetheadrotation>80)targetheadrotation=80;
1174 if(targetheadrotation<-80)targetheadrotation=-80;
1175 if(targetheadrotation2>50)targetheadrotation2=50;
1176 if(targetheadrotation2<-50)targetheadrotation2=-50;
1179 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1180 else if(headrotation>targetheadrotation){
1181 headrotation-=multiplier*lookspeed;
1183 else if(headrotation<targetheadrotation){
1184 headrotation+=multiplier*lookspeed;
1187 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1188 else if(headrotation2>targetheadrotation2){
1189 headrotation2-=multiplier*lookspeed/2;
1191 else if(headrotation2<targetheadrotation2){
1192 headrotation2+=multiplier*lookspeed/2;
1195 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1196 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1200 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1201 facing=DoRotation(facing,headrotation2*.4,0,0);
1202 facing=DoRotation(facing,0,headrotation*.4,0);
1205 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1206 facing=DoRotation(facing,headrotation2*.8,0,0);
1207 facing=DoRotation(facing,0,headrotation*.8,0);
1210 if(targetanimation==walkanim){
1211 facing=DoRotation(facing,headrotation2*.6,0,0);
1212 facing=DoRotation(facing,0,headrotation*.6,0);
1215 skeleton.specialforward[0]=facing;
1216 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1218 for(i=0;i<skeleton.num_muscles;i++){
1219 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1221 skeleton.FindRotationMuscle(i,targetanimation);
1227 void Person::RagDoll(bool checkcollision){
1232 if(id==0)numfalls++;
1233 if(id==0&&isFlip())numflipfail++;
1239 facing=DoRotation(facing,0,rotation,0);
1241 skeleton.freetime=0;
1243 skeleton.longdead=0;
1249 skeleton.freefall=1;
1251 if(!isnormal(velocity.x))velocity.x=0;
1252 if(!isnormal(velocity.y))velocity.y=0;
1253 if(!isnormal(velocity.z))velocity.z=0;
1254 if(!isnormal(rotation))rotation=0;
1255 if(!isnormal(coords.x))coords=0;
1256 if(!isnormal(tilt))tilt=0;
1257 if(!isnormal(tilt2))tilt2=0;
1259 for(i=0;i<skeleton.num_joints;i++){
1260 skeleton.joints[i].delay=0;
1261 skeleton.joints[i].locked=0;
1262 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1263 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1264 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1265 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1266 skeleton.joints[i].position.y+=.1;
1267 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1268 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1271 for(i=0;i<skeleton.num_joints;i++){
1272 skeleton.joints[i].velocity=0;
1273 skeleton.joints[i].velchange=0;
1275 skeleton.DoConstraints(&coords,&scale);
1276 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1278 skeleton.DoConstraints(&coords,&scale);
1279 skeleton.DoConstraints(&coords,&scale);
1280 skeleton.DoConstraints(&coords,&scale);
1281 skeleton.DoConstraints(&coords,&scale);
1284 speed=animation[targetanimation].speed[targetframe]*2;
1285 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1286 speed=animation[currentanimation].speed[currentframe]*2;
1288 if(transspeed)speed=transspeed*2;
1292 for(i=0;i<skeleton.num_joints;i++){
1293 if((animation[currentanimation].attack!=reversed||currentanimation==swordslashreversedanim)&¤tanimation!=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);
1294 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1295 change.x=(float)(Random()%100)/100;
1296 change.y=(float)(Random()%100)/100;
1297 change.z=(float)(Random()%100)/100;
1298 skeleton.joints[i].velocity+=change;
1299 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1301 change.x=(float)(Random()%100)/100;
1302 change.y=(float)(Random()%100)/100;
1303 change.z=(float)(Random()%100)/100;
1304 skeleton.joints[i].velchange+=change;
1305 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1315 for(j=0;j<skeleton.num_joints;j++){
1316 average+=skeleton.joints[j].position;
1320 coords+=average*scale;
1321 for(j=0;j<skeleton.num_joints;j++){
1322 skeleton.joints[j].position-=average;
1325 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1326 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1327 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1328 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1329 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1332 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1333 coords.x=lowpoint.x;
1334 coords.z=lowpoint.z;
1343 for(i=0;i<skeleton.num_joints;i++){
1344 velocity+=skeleton.joints[i].velocity*scale;
1346 velocity/=skeleton.num_joints;
1349 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1350 weapons.owner[weaponids[0]]=-1;
1351 weapons.hitsomething[weaponids[0]]=0;
1352 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1353 weapons.velocity[weaponids[0]].x+=.01;
1354 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1355 weapons.missed[weaponids[0]]=1;
1356 weapons.freetime[weaponids[0]]=0;
1357 weapons.firstfree[weaponids[0]]=1;
1358 weapons.physics[weaponids[0]]=1;
1361 weaponids[0]=weaponids[num_weapons];
1362 if(weaponstuck==num_weapons)weaponstuck=0;
1365 for(i=0;i<numplayers;i++){
1366 player[i].wentforweapon=0;
1371 targetanimation=bounceidleanim;
1372 currentanimation=bounceidleanim;
1380 void Person::FootLand(int which, float opacity){
1381 static XYZ terrainlight;
1382 static XYZ footvel,footpoint;
1383 if(opacity>=1||skiddelay<=0)
1387 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1388 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1389 //footpoint.y=coords.y;
1390 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1392 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1394 if(footvel.y<.8)footvel.y=.8;
1395 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1396 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1397 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1398 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1399 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1400 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1402 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1404 if(footvel.y<.8)footvel.y=.8;
1405 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1406 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1407 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1408 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1409 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);
1411 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1413 if(footvel.y<.8)footvel.y=.8;
1414 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1415 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1416 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1417 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1418 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);
1419 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1421 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1424 if(footvel.y<.8)footvel.y=.8;
1425 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1426 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1427 //footpoint.y=coords.y;
1428 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1432 void Person::Puff(int whichlabel){
1433 static XYZ footvel,footpoint;
1436 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1437 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1441 void Person::DoAnimations(){
1444 static float oldtarget;
1446 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1448 if(targetanimation==tempanim||currentanimation==tempanim){
1449 animation[tempanim]=tempanimation;
1451 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1462 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1463 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1465 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1466 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1468 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1473 targfacing=DoRotation(targfacing,0,targetrotation,0);
1475 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1476 else targetanimation=backflipanim;
1477 crouchtogglekeydown=1;
1481 if(id==0)numflipped++;
1484 if(animation[targetanimation].attack!=reversed)feint=0;
1485 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1486 crouchtogglekeydown=0;
1487 if(aitype==playercontrolled)feint=0;
1491 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1492 if(!isFlip())crouchtogglekeydown=1;
1496 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1497 if(detail)normalsupdatedelay=0;
1501 if(targetanimation==rollanim&&targetframe==3&&onfire){
1503 emit_sound_at(fireendsound, coords);
1504 OPENAL_SetPaused(channels[stream_firesound], true);
1508 if(targetanimation==rabbittacklinganim&&targetframe==1){
1509 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1510 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1511 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1512 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1513 else victim->targetanimation=rabbittackledfrontanim;
1514 victim->targetframe=2;
1516 victim->rotation=rotation;
1517 victim->targetrotation=rotation;
1518 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1519 //victim->DoDamage(30);
1520 if(creature==wolftype){
1522 emit_sound_at(clawslicesound, victim->coords);
1524 victim->DoBloodBig(1/victim->armorhead,210);
1526 award_bonus(id, TackleBonus,
1527 victim->aitype == gethelptype ? 50 : 0);
1531 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1532 if(weapons.type[weaponids[0]]==knife){
1533 if(weaponactive==-1)weaponactive=0;
1534 else if(weaponactive==0)weaponactive=-1;
1536 if(weaponactive==-1){
1537 emit_sound_at(knifesheathesound, coords);
1539 if(weaponactive!=-1){
1540 emit_sound_at(knifedrawsound, coords, 128);
1543 drawtogglekeydown=1;
1546 if(tutoriallevel!=1||id==0)
1547 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1550 if(terrain.getOpacity(coords.x,coords.z)<.2){
1551 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1552 else whichsound=footstepsound2;
1553 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1554 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1555 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1561 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1562 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1563 else whichsound=footstepsound4;
1567 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1568 else whichsound=footstepsound4;
1570 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1571 if(animation[targetanimation].attack!=neutral){
1573 if(i==0)whichsound=lowwhooshsound;
1574 if(i==1)whichsound=midwhooshsound;
1575 if(i==2)whichsound=highwhooshsound;
1577 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1579 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1580 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1582 emit_sound_at(whichsound, coords, 256.);
1585 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1586 envsound[numenvsounds]=coords;
1587 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1588 else envsoundvol[numenvsounds]=6;
1589 envsoundlife[numenvsounds]=.4;
1593 if(animation[targetanimation].label[targetframe]==3){
1595 emit_sound_at(whichsound, coords, 128.);
1600 if(tutoriallevel!=1||id==0)
1602 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1603 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1605 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1606 if(animation[targetanimation].attack!=neutral){
1608 if(creature==rabbittype){
1609 if(i==0)whichsound=rabbitattacksound;
1610 if(i==1)whichsound=rabbitattack2sound;
1611 if(i==2)whichsound=rabbitattack3sound;
1612 if(i==3)whichsound=rabbitattack4sound;
1614 if(creature==wolftype){
1615 if(i==0)whichsound=barksound;
1616 if(i==1)whichsound=bark2sound;
1617 if(i==2)whichsound=bark3sound;
1618 if(i==3)whichsound=barkgrowlsound;
1622 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1624 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1625 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1628 emit_sound_at(whichsound, coords);
1634 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1640 currentoffset=targetoffset;
1641 targetframe=currentframe;
1642 currentanimation=targetanimation;
1645 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1646 for(i=0;i<weapons.numweapons;i++){
1647 if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1648 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1649 if(findDistancefast(&coords,&weapons.position[i])>=1){
1650 if(weapons.type[i]!=staff){
1651 emit_sound_at(knifedrawsound, coords, 128.);
1655 weapons.owner[i]=id;
1657 weaponids[num_weapons]=weaponids[0];
1666 static bool willwork;
1667 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1668 for(i=0;i<weapons.numweapons;i++){
1670 if(weapons.owner[i]!=-1)
1671 if(player[weapons.owner[i]].weaponstuck!=-1)
1672 if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
1673 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
1674 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))
1675 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
1676 if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
1678 if(weapons.owner[i]!=-1)
1679 if(victim->weaponstuck!=-1){
1680 if(victim->weaponids[victim->weaponstuck]==i){
1685 if(weapons.type[i]!=staff){
1686 emit_sound_at(knifedrawsound, coords, 128.);
1690 emit_sound_at(fleshstabremovesound, coords, 128.);
1693 if(weapons.owner[i]!=-1){
1695 victim=&player[weapons.owner[i]];
1696 if(victim->num_weapons==1)victim->num_weapons=0;
1697 else victim->num_weapons=1;
1699 //victim->weaponactive=-1;
1700 victim->skeleton.longdead=0;
1701 victim->skeleton.free=1;
1702 victim->skeleton.broken=0;
1704 for(int j=0;j<victim->skeleton.num_joints;j++){
1705 victim->skeleton.joints[j].velchange=0;
1706 victim->skeleton.joints[j].locked=0;
1712 Normalise(&relative);
1713 XYZ footvel,footpoint;
1715 footpoint=weapons.position[i];
1716 if(victim->weaponstuck!=-1){
1717 if(victim->weaponids[victim->weaponstuck]==i){
1718 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1719 weapons.bloody[i]=2;
1720 weapons.blooddrip[i]=5;
1721 victim->weaponstuck=-1;
1724 if(victim->num_weapons>0){
1725 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1726 if(victim->weaponids[0]==i)
1727 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1730 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1731 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1732 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1733 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1735 weapons.owner[i]=id;
1737 weaponids[num_weapons]=weaponids[0];
1746 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1747 if(weaponactive==-1)weaponactive=0;
1748 else if(weaponactive==0){
1752 buffer=weaponids[0];
1753 weaponids[0]=weaponids[1];
1754 weaponids[1]=buffer;
1757 if(weaponactive==-1){
1758 emit_sound_at(knifesheathesound, coords, 128.);
1760 if(weaponactive!=-1){
1761 emit_sound_at(knifedrawsound, coords, 128.);
1766 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1767 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1768 Normalise(&rotatetarget);
1769 targetrotation=-asin(0-rotatetarget.x);
1770 targetrotation*=360/6.28;
1771 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1773 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1774 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1779 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1781 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;
1783 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1784 targetanimation=rabbittackleanim;
1786 emit_sound_at(jumpsound, coords);
1795 Normalise(&targetloc);
1797 for(i=0;i<numplayers;i++){
1799 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1800 closestdist=findDistancefast(&targetloc,&player[i].coords);
1805 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1807 victim=&player[closestid];
1808 coords=victim->coords;
1809 currentanimation=rabbittacklinganim;
1810 targetanimation=rabbittacklinganim;
1814 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1815 rotatetarget=coords-victim->coords;
1816 Normalise(&rotatetarget);
1817 targetrotation=-asin(0-rotatetarget.x);
1818 targetrotation*=360/6.28;
1819 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1821 if(targetanimation!=rabbitrunninganim){
1822 emit_sound_at(jumpsound, coords, 128.);
1828 float damagemult=1*power;
1829 if(creature==wolftype)damagemult=2.5*power;
1830 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1831 //if(onfire)damagemult=3;
1832 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1833 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1834 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1836 if(id==0)camerashake+=.4;
1837 if(Random()%2||creature==wolftype){
1840 if(creature==wolftype)DoBloodBig(0,250);
1842 if(tutoriallevel!=1){
1843 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1845 if(creature==wolftype){
1846 emit_sound_at(clawslicesound, victim->coords, 128.);
1848 victim->DoBloodBig(2/victim->armorhead,175);
1852 relative=victim->coords-coords;
1854 Normalise(&relative);
1855 relative=DoRotation(relative,0,-90,0);
1856 for(i=0;i<victim->skeleton.num_joints;i++){
1857 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1859 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1862 victim->DoDamage(damagemult*100/victim->protectionhead);
1868 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1869 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1871 if(id==0)camerashake+=.4;
1872 if(Random()%2||creature==wolftype){
1874 if(creature==wolftype)DoBloodBig(0,235);
1876 emit_sound_at(whooshhitsound, victim->coords);
1877 if(creature==wolftype){
1878 emit_sound_at(clawslicesound, victim->coords, 128.);
1880 victim->DoBloodBig(2,175);
1884 relative=victim->coords-coords;
1886 Normalise(&relative);
1888 Normalise(&relative);
1889 relative=DoRotation(relative,0,90,0);
1890 for(i=0;i<victim->skeleton.num_joints;i++){
1891 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
1893 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1896 victim->DoDamage(damagemult*50/victim->protectionhead);
1900 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
1901 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1903 if(id==0)camerashake+=.4;
1906 if(tutoriallevel!=1){
1907 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1909 if(creature==wolftype){
1910 emit_sound_at(clawslicesound, victim->coords, 128.);
1912 victim->DoBloodBig(2/victim->armorhead,175);
1918 Normalise(&relative);
1919 relative=DoRotation(relative,0,-90,0);
1920 for(i=0;i<victim->skeleton.num_joints;i++){
1921 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1923 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1926 victim->DoDamage(damagemult*150/victim->protectionhead);
1928 if(victim->damage>victim->damagetolerance)
1929 award_bonus(id, style);
1935 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
1936 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1938 if(id==0)camerashake+=.4;
1941 if(tutoriallevel!=1){
1942 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1944 if(creature==wolftype){
1945 emit_sound_at(clawslicesound, victim->coords, 128.);
1947 victim->DoBloodBig(2/victim->armorhead,175);
1953 Normalise(&relative);
1954 relative=DoRotation(relative,0,90,0);
1955 for(i=0;i<victim->skeleton.num_joints;i++){
1956 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1958 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1961 victim->DoDamage(damagemult*150/victim->protectionhead);
1963 if(victim->damage>victim->damagetolerance)
1964 award_bonus(id, style);
1970 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
1971 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1973 if(id==0)camerashake+=.4;
1978 emit_sound_at(whooshhitsound, victim->coords);
1981 relative=victim->coords-coords;
1983 Normalise(&relative);
1984 for(i=0;i<victim->skeleton.num_joints;i++){
1985 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
1987 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1990 victim->DoDamage(damagemult*50/victim->protectionhead);
1994 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
1995 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
1997 if(id==0)camerashake+=.2;
1998 emit_sound_at(whooshhitsound, victim->coords, 128.);
2000 victim->skeleton.longdead=0;
2001 victim->skeleton.free=1;
2002 victim->skeleton.broken=0;
2003 victim->skeleton.spinny=1;
2005 for(i=0;i<victim->skeleton.num_joints;i++){
2006 victim->skeleton.joints[i].velchange=0;
2007 victim->skeleton.joints[i].delay=0;
2008 victim->skeleton.joints[i].locked=0;
2009 //victim->skeleton.joints[i].velocity=0;
2015 Normalise(&relative);
2016 for(i=0;i<victim->skeleton.num_joints;i++){
2017 victim->skeleton.joints[i].velocity.y=relative.y*10;
2018 victim->skeleton.joints[i].position.y+=relative.y*.3;
2019 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2020 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2022 victim->Puff(abdomen);
2023 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2027 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2028 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2030 if(id==0)camerashake+=.4;
2031 if(tutoriallevel!=1){
2032 emit_sound_at(heavyimpactsound, coords, 128.);
2035 relative=victim->coords-coords;
2037 Normalise(&relative);
2038 for(i=0;i<victim->skeleton.num_joints;i++){
2039 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2041 victim->Puff(abdomen);
2042 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2046 victim->DoDamage(damagemult*500/victim->protectionhigh);
2047 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2051 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2052 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2054 if(id==0)camerashake+=.4;
2055 if(tutoriallevel!=1){
2056 emit_sound_at(thudsound, coords);
2059 victim->skeleton.longdead=0;
2060 victim->skeleton.free=1;
2061 victim->skeleton.broken=0;
2062 victim->skeleton.spinny=1;
2064 for(i=0;i<victim->skeleton.num_joints;i++){
2065 victim->skeleton.joints[i].velchange=0;
2066 //victim->skeleton.joints[i].delay=0;
2067 victim->skeleton.joints[i].locked=0;
2070 relative=victim->coords-coords;
2071 Normalise(&relative);
2073 Normalise(&relative);
2074 for(i=0;i<victim->skeleton.num_joints;i++){
2075 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2080 victim->Puff(abdomen);
2081 victim->DoDamage(damagemult*20/victim->protectionhigh);
2082 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2084 if(!victim->dead)staggerdelay=1.2;
2090 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2091 //if(id==0)camerashake+=.4;
2094 if(!victim->skeleton.free)hasvictim=0;
2097 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2098 emit_sound_at(knifesheathesound, coords, 128.);
2101 if(victim&&hasvictim){
2102 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2104 XYZ where,startpoint,endpoint,movepoint,colpoint;
2105 float rotationpoint;
2107 if(weapons.type[weaponids[weaponactive]]==knife){
2108 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2109 where-=victim->coords;
2110 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2117 if(weapons.type[weaponids[weaponactive]]==sword){
2118 where=weapons.position[weaponids[weaponactive]];
2119 where-=victim->coords;
2120 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2122 where=weapons.tippoint[weaponids[weaponactive]];
2123 where-=victim->coords;
2124 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2127 if(weapons.type[weaponids[weaponactive]]==staff){
2128 where=weapons.position[weaponids[weaponactive]];
2129 where-=victim->coords;
2130 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2132 where=weapons.tippoint[weaponids[weaponactive]];
2133 where-=victim->coords;
2134 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2139 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2142 if(victim->dead!=2){
2143 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2145 award_bonus(id, FinishedBonus);
2147 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2149 victim->skeleton.longdead=0;
2150 victim->skeleton.free=1;
2151 victim->skeleton.broken=0;
2153 for(i=0;i<victim->skeleton.num_joints;i++){
2154 victim->skeleton.joints[i].velchange=0;
2155 victim->skeleton.joints[i].locked=0;
2156 //victim->skeleton.joints[i].velocity=0;
2158 emit_sound_at(fleshstabsound, coords, 128);
2161 if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2162 weapons.blooddrip[weaponids[weaponactive]]+=5;
2163 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2167 emit_sound_at(knifesheathesound, coords, 128.);
2173 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2175 emit_sound_at(knifedrawsound, coords, 128);
2178 if(victim&&hasvictim){
2179 XYZ footvel,footpoint;
2181 emit_sound_at(fleshstabremovesound, coords, 128.);
2184 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2186 if(weapons.type[weaponids[weaponactive]]==sword){
2187 XYZ where,startpoint,endpoint,movepoint;
2188 float rotationpoint;
2191 where=weapons.position[weaponids[weaponactive]];
2192 where-=victim->coords;
2193 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2195 where=weapons.tippoint[weaponids[weaponactive]];
2196 where-=victim->coords;
2197 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2202 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2203 footpoint+=victim->coords;
2206 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2209 if(weapons.type[weaponids[weaponactive]]==staff){
2210 XYZ where,startpoint,endpoint,movepoint;
2211 float rotationpoint;
2214 where=weapons.position[weaponids[weaponactive]];
2215 where-=victim->coords;
2216 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2218 where=weapons.tippoint[weaponids[weaponactive]];
2219 where-=victim->coords;
2220 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2225 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2226 footpoint+=victim->coords;
2229 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2232 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2234 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2235 victim->skeleton.longdead=0;
2236 victim->skeleton.free=1;
2237 victim->skeleton.broken=0;
2239 for(i=0;i<victim->skeleton.num_joints;i++){
2240 victim->skeleton.joints[i].velchange=0;
2241 victim->skeleton.joints[i].locked=0;
2242 //victim->skeleton.joints[i].velocity=0;
2248 Normalise(&relative);
2249 //victim->Puff(abdomen);
2250 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2252 if(victim->bloodloss<victim->damagetolerance){
2253 victim->bloodloss+=1000;
2257 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2261 if(!hasvictim&&onterrain){
2262 weapons.bloody[weaponids[weaponactive]]=0;
2263 weapons.blooddrip[weaponids[weaponactive]]=0;
2267 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2268 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2270 if(id==0)camerashake+=.4;
2275 if(tutoriallevel!=1){
2276 emit_sound_at(heavyimpactsound, victim->coords, 128);
2281 relative=victim->coords-coords;
2283 Normalise(&relative);
2284 for(i=0;i<victim->skeleton.num_joints;i++){
2285 victim->skeleton.joints[i].velocity=relative*30;
2287 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2289 victim->targetframe=0;
2290 victim->targetanimation=staggerbackhardanim;
2291 victim->targetrotation=targetrotation+180;
2296 victim->Puff(abdomen);
2297 victim->DoDamage(damagemult*60/victim->protectionhigh);
2304 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2305 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2307 if(id==0)camerashake+=.4;
2308 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2309 if(tutoriallevel!=1){
2310 emit_sound_at(thudsound, victim->coords);
2313 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2314 if(tutoriallevel!=1){
2315 emit_sound_at(whooshhitsound, victim->coords);
2319 if(tutoriallevel!=1){
2320 emit_sound_at(heavyimpactsound, victim->coords);
2324 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2327 relative=victim->coords-coords;
2329 Normalise(&relative);
2331 Normalise(&relative);
2332 for(i=0;i<victim->skeleton.num_joints;i++){
2333 victim->skeleton.joints[i].velocity=relative*5;
2335 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2337 victim->targetframe=0;
2338 victim->targetanimation=staggerbackhardanim;
2339 victim->targetrotation=targetrotation+180;
2343 victim->Puff(abdomen);
2344 victim->DoDamage(damagemult*60/victim->protectionhigh);
2350 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2351 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2352 if(victim->id==0)camerashake+=.4;
2353 emit_sound_at(landsound2, victim->coords);
2359 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2360 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2361 if(victim->id==0)camerashake+=.4;
2363 if(weaponactive!=-1){
2364 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2365 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2366 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2368 emit_sound_at(swordstaffsound, victim->coords);
2371 emit_sound_at(metalhitsound, victim->coords);
2379 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2380 if(weaponactive!=-1){
2383 weapons.owner[weaponids[0]]=-1;
2384 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);
2386 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2387 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2389 weapons.velocity[weaponids[0]]=aim*50;
2390 weapons.tipvelocity[weaponids[0]]=aim*50;
2391 weapons.missed[weaponids[0]]=0;
2392 weapons.hitsomething[weaponids[0]]=0;
2393 weapons.freetime[weaponids[0]]=0;
2394 weapons.firstfree[weaponids[0]]=1;
2395 weapons.physics[weaponids[0]]=0;
2398 weaponids[0]=weaponids[num_weapons];
2404 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2406 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2408 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2410 award_bonus(id, Slicebonus);
2411 if(tutoriallevel!=1){
2412 emit_sound_at(knifeslicesound, victim->coords);
2414 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2415 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2416 if(victim->id != 0 || difficulty==2){
2417 victim->targetframe=0;
2418 victim->targetanimation=staggerbackhardanim;
2419 victim->targetrotation=targetrotation+180;
2423 victim->lowreversaldelay=0;
2424 victim->highreversaldelay=0;
2425 if(aitype!=playercontrolled)weaponmissdelay=.6;
2427 if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2428 if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
2430 XYZ footvel,footpoint;
2433 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2436 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;
2438 if(tutoriallevel!=1){
2439 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2440 footvel=DoRotation(facing,0,90,0)*.8;
2442 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2443 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2444 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2445 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2447 if(tutoriallevel==1){
2448 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2450 victim->DoDamage(damagemult*0);
2453 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2454 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2455 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2456 award_bonus(id, Slashbonus);
2458 if(tutoriallevel!=1){
2459 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2460 else victim->DoBloodBig(2/victim->armorhigh,185);
2461 victim->deathbleeding=1;
2462 emit_sound_at(swordslicesound, victim->coords);
2464 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2465 if(tutoriallevel!=1){
2466 victim->targetframe=0;
2467 victim->targetanimation=staggerbackhardanim;
2468 victim->targetrotation=targetrotation+180;
2472 if(tutoriallevel!=1){
2473 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2474 weapons.blooddrip[weaponids[weaponactive]]+=3;
2476 float bloodlossamount;
2477 bloodlossamount=200+abs((float)(Random()%40))-20;
2478 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2479 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2480 victim->DoDamage(damagemult*0);
2482 XYZ footvel,footpoint;
2485 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2488 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;
2490 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2491 footvel=DoRotation(facing,0,90,0)*.8;
2493 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2494 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2495 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2496 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2500 if(victim->weaponactive!=-1){
2501 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2502 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2503 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2505 emit_sound_at(swordstaffsound, victim->coords);
2508 emit_sound_at(metalhitsound, victim->coords);
2514 victim->Puff(righthand);
2516 victim->targetframe=0;
2517 victim->targetanimation=staggerbackhighanim;
2518 victim->targetrotation=targetrotation+180;
2520 weapons.owner[victim->weaponids[0]]=-1;
2521 aim=DoRotation(facing,0,90,0)*21;
2523 weapons.velocity[victim->weaponids[0]]=aim*-.2;
2524 weapons.tipvelocity[victim->weaponids[0]]=aim;
2525 weapons.missed[victim->weaponids[0]]=1;
2526 weapons.hitsomething[weaponids[0]]=0;
2527 weapons.freetime[victim->weaponids[0]]=0;
2528 weapons.firstfree[victim->weaponids[0]]=1;
2529 weapons.physics[victim->weaponids[0]]=1;
2530 victim->num_weapons--;
2531 if(victim->num_weapons){
2532 victim->weaponids[0]=victim->weaponids[num_weapons];
2533 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2535 victim->weaponactive=-1;
2536 for(i=0;i<numplayers;i++){
2537 player[i].wentforweapon=0;
2544 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2545 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2546 if(tutoriallevel!=1){
2547 weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
2549 if(id==0)camerashake+=.4;
2550 if(Random()%2||creature==wolftype){
2553 emit_sound_at(staffheadsound, victim->coords);
2557 relative=victim->coords-coords;
2559 Normalise(&relative);
2560 relative=DoRotation(relative,0,90,0);
2562 Normalise(&relative);
2563 for(i=0;i<victim->skeleton.num_joints;i++){
2564 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2566 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2567 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2570 if(tutoriallevel!=1){
2571 victim->DoDamage(damagemult*120/victim->protectionhigh);
2573 award_bonus(id, solidhit, 30);
2578 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2579 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2580 if(tutoriallevel!=1){
2581 weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
2583 if(id==0)camerashake+=.4;
2584 if(Random()%2||creature==wolftype){
2587 emit_sound_at(staffheadsound, victim->coords);
2591 relative=victim->coords-coords;
2593 Normalise(&relative);
2594 relative=DoRotation(relative,0,-90,0);
2595 for(i=0;i<victim->skeleton.num_joints;i++){
2596 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2598 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2599 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2602 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2604 award_bonus(id, solidhit, 60);
2609 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2610 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2612 if(tutoriallevel!=1){
2613 if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
2614 if(id==0)camerashake+=.4;
2615 if(Random()%2||creature==wolftype){
2618 emit_sound_at(staffbodysound, victim->coords);
2620 victim->skeleton.longdead=0;
2621 victim->skeleton.free=1;
2622 victim->skeleton.broken=0;
2624 for(i=0;i<victim->skeleton.num_joints;i++){
2625 victim->skeleton.joints[i].velchange=0;
2626 victim->skeleton.joints[i].locked=0;
2627 //victim->skeleton.joints[i].velocity=0;
2633 /*relative=victim->coords-coords;
2635 Normalise(&relative);
2636 relative=DoRotation(relative,0,90,0);*/
2638 Normalise(&relative);
2640 for(i=0;i<victim->skeleton.num_joints;i++){
2641 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2644 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2647 for(i=0;i<victim->skeleton.num_joints;i++){
2648 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2651 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2653 victim->Puff(abdomen);
2654 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2657 award_bonus(id, solidhit, 40);
2663 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2664 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2666 if(id==0)camerashake+=.4;
2668 relative=victim->coords-coords;
2670 Normalise(&relative);
2674 if(animation[victim->targetanimation].height==lowheight){
2680 for(i=0;i<victim->skeleton.num_joints;i++){
2681 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2683 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2684 if(tutoriallevel!=1){
2685 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2688 victim->DoDamage(damagemult*100/victim->protectionhead);
2689 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2690 if(creature==wolftype){
2691 emit_sound_at(clawslicesound, victim->coords, 128.);
2693 victim->DoBloodBig(2/victim->armorhead,175);
2697 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2698 for(i=0;i<victim->skeleton.num_joints;i++){
2699 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2701 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2702 victim->targetframe=0;
2703 victim->targetanimation=staggerbackhighanim;
2704 victim->targetrotation=targetrotation+180;
2706 if(tutoriallevel!=1){
2707 emit_sound_at(landsound2, victim->coords, 128.);
2709 victim->Puff(abdomen);
2710 victim->DoDamage(damagemult*30/victim->protectionhigh);
2711 if(creature==wolftype){
2712 emit_sound_at(clawslicesound, victim->coords, 128.);
2714 victim->DoBloodBig(2/victim->armorhigh,170);
2721 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2722 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2724 if(id==0)camerashake+=.2;
2725 if(tutoriallevel!=1){
2726 emit_sound_at(landsound2, victim->coords, 128.);
2729 relative=victim->coords-coords;
2731 Normalise(&relative);
2733 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2736 for(i=0;i<victim->skeleton.num_joints;i++){
2737 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2739 relative=DoRotation(relative,0,-90,0);
2741 for(i=0;i<victim->skeleton.num_joints;i++){
2742 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)
2743 victim->skeleton.joints[i].velocity=relative*80;
2745 victim->Puff(rightankle);
2746 victim->Puff(leftankle);
2747 victim->DoDamage(damagemult*40/victim->protectionlow);
2750 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2751 for(i=0;i<victim->skeleton.num_joints;i++){
2752 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2754 relative=DoRotation(relative,0,-90,0);
2755 for(i=0;i<victim->skeleton.num_joints;i++){
2756 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)
2757 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2759 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2760 victim->targetframe=0;
2761 victim->targetanimation=staggerbackhighanim;
2762 victim->targetrotation=targetrotation+180;
2764 if(tutoriallevel!=1){
2765 emit_sound_at(landsound2, victim->coords, 128.);
2767 victim->Puff(abdomen);
2768 victim->DoDamage(damagemult*30/victim->protectionlow);
2776 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2777 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2779 if(id==0)camerashake+=.4;
2784 if(tutoriallevel!=1){
2785 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2787 if(creature==wolftype){
2788 emit_sound_at(clawslicesound, victim->coords, 128);
2790 victim->DoBloodBig(2/victim->armorhigh,170);
2794 relative=victim->coords-oldcoords;
2796 Normalise(&relative);
2797 //relative=DoRotation(relative,0,-90,0);
2798 for(i=0;i<victim->skeleton.num_joints;i++){
2799 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2801 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2803 victim->Puff(abdomen);
2804 victim->DoDamage(damagemult*150/victim->protectionhigh);
2806 award_bonus(id, Reversal);
2809 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2810 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2811 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
2812 weapons.owner[victim->weaponids[victim->weaponactive]]=id;
2815 weaponids[num_weapons]=weaponids[victim->weaponactive];
2818 weaponids[0]=victim->weaponids[victim->weaponactive];
2819 victim->num_weapons--;
2820 if(victim->num_weapons>0){
2821 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2822 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2824 victim->weaponactive=-1;
2829 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2831 if(id==0)camerashake+=.4;
2836 emit_sound_at(whooshhitsound, victim->coords, 128.);
2839 relative=victim->coords-oldcoords;
2841 Normalise(&relative);
2842 //relative=DoRotation(relative,0,-90,0);
2843 for(i=0;i<victim->skeleton.num_joints;i++){
2844 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2846 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2849 victim->DoDamage(damagemult*70/victim->protectionhigh);
2852 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2854 if(id==0)camerashake+=.4;
2860 award_bonus(id, staffreversebonus);
2862 if(tutoriallevel!=1){
2863 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2866 award_bonus(id, staffreversebonus); // Huh, again?
2869 relative=victim->coords-oldcoords;
2871 Normalise(&relative);
2872 //relative=DoRotation(relative,0,-90,0);
2873 for(i=0;i<victim->skeleton.num_joints;i++){
2874 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2876 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2879 victim->DoDamage(damagemult*70/victim->protectionhigh);
2882 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
2888 Normalise(&relative);
2891 for(i=0;i<victim->skeleton.num_joints;i++){
2892 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2894 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
2895 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
2896 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
2897 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
2898 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
2899 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
2900 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
2901 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
2903 victim->Puff(abdomen);
2904 victim->DoDamage(damagemult*90/victim->protectionhigh);
2906 award_bonus(id, Reversal);
2910 if(weaponactive!=-1||creature==wolftype)doslice=1;
2911 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
2913 if(weaponactive!=-1){
2914 victim->DoBloodBig(2/victim->armorhigh,225);
2915 emit_sound_at(knifeslicesound, victim->coords);
2916 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2917 weapons.blooddrip[weaponids[weaponactive]]+=3;
2919 if(weaponactive==-1&&creature==wolftype){;
2920 emit_sound_at(clawslicesound, victim->coords, 128.);
2922 victim->DoBloodBig(2/victim->armorhigh,175);
2929 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2935 Normalise(&relative);
2938 for(i=0;i<victim->skeleton.num_joints;i++){
2939 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2941 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
2942 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
2943 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
2944 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
2945 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
2946 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
2947 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
2948 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
2950 award_bonus(id, swordreversebonus);
2953 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2955 if(id==0)camerashake+=.4;
2960 if(tutoriallevel!=1){
2961 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2965 relative=victim->coords-oldcoords;
2967 Normalise(&relative);
2968 relative=DoRotation(relative,0,-90,0);
2969 for(i=0;i<victim->skeleton.num_joints;i++){
2970 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2972 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2974 victim->Puff(abdomen);
2975 victim->DoDamage(damagemult*30/victim->protectionhigh);
2977 award_bonus(id, Reversal);
2980 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
2983 victim->skeleton.spinny=0;
2987 Normalise(&relative);
2988 if(victim->id==0)relative/=30;
2989 for(i=0;i<victim->skeleton.num_joints;i++){
2990 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2992 //victim->DoDamage(1000);
2993 victim->damage=victim->damagetolerance;
2994 victim->permanentdamage=victim->damagetolerance-1;
2997 if(weaponactive!=-1||creature==wolftype)doslice=1;
2998 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3000 if(weaponactive!=-1){
3001 victim->DoBloodBig(200,225);
3002 emit_sound_at(knifeslicesound, victim->coords);
3003 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3004 weapons.blooddrip[weaponids[weaponactive]]+=5;
3007 if(creature==wolftype&&weaponactive==-1){
3008 emit_sound_at(clawslicesound, victim->coords, 128.);
3010 victim->DoBloodBig(2,175);
3013 award_bonus(id, spinecrusher);
3016 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3017 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3019 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3020 if(targetanimation==knifesneakattackanim){
3021 /*victim->DoBloodBig(200,195);
3026 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3027 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3029 XYZ footvel,footpoint;
3031 footpoint=weapons.tippoint[weaponids[0]];
3032 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3033 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3034 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3035 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3036 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3037 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3038 victim->DoBloodBig(200,195);
3039 award_bonus(id, tracheotomy);
3041 if(targetanimation==knifefollowanim){
3042 award_bonus(id, Stabbonus);
3043 XYZ footvel,footpoint;
3045 footpoint=weapons.tippoint[weaponids[0]];
3046 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3047 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3048 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3049 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3050 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3051 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3054 victim->bloodloss+=10000;
3056 emit_sound_at(fleshstabsound, victim->coords);
3057 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3058 weapons.blooddrip[weaponids[weaponactive]]+=5;
3062 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3065 for(i=0;i<victim->skeleton.num_joints;i++){
3066 victim->skeleton.joints[i].velocity=0;
3068 if(targetanimation==knifefollowanim){
3070 for(i=0;i<victim->skeleton.num_joints;i++){
3071 victim->skeleton.joints[i].velocity=0;
3074 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3075 emit_sound_at(fleshstabremovesound, victim->coords);
3076 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3077 weapons.blooddrip[weaponids[weaponactive]]+=5;
3079 XYZ footvel,footpoint;
3081 footpoint=weapons.tippoint[weaponids[0]];
3082 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3083 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3084 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3085 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3086 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3087 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3091 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3092 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3093 award_bonus(id, backstab);
3097 XYZ footvel,footpoint;
3099 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3100 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3101 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3102 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3103 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3104 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3105 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3106 victim->DoBloodBig(200,180);
3107 victim->DoBloodBig(200,215);
3108 victim->bloodloss+=10000;
3110 emit_sound_at(fleshstabsound, victim->coords);
3111 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3112 weapons.blooddrip[weaponids[weaponactive]]+=5;
3116 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3119 for(i=0;i<victim->skeleton.num_joints;i++){
3120 victim->skeleton.joints[i].velocity=0;
3122 if(weaponactive!=-1){
3123 emit_sound_at(fleshstabremovesound, victim->coords);
3124 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3125 weapons.blooddrip[weaponids[weaponactive]]+=5;
3127 XYZ footvel,footpoint;
3129 footpoint=weapons.tippoint[weaponids[0]];
3130 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3131 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3132 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3133 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3134 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3135 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3139 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3141 if(id==0)camerashake+=.4;
3146 if(weaponactive==-1){
3147 if(tutoriallevel!=1){
3148 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3153 if(weaponactive!=-1||creature==wolftype)doslice=1;
3154 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3156 if(weaponactive!=-1){
3157 victim->DoBloodBig(2/victim->armorhead,225);
3158 emit_sound_at(knifeslicesound, victim->coords);
3159 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3160 weapons.blooddrip[weaponids[weaponactive]]+=3;
3162 if(weaponactive==-1&&creature==wolftype){
3163 emit_sound_at(clawslicesound, victim->coords, 128.);
3165 victim->DoBloodBig(2/victim->armorhead,175);
3169 award_bonus(id, Reversal);
3174 //relative=victim->coords-oldcoords;
3177 Normalise(&relative);
3178 relative=DoRotation(relative,0,90,0);
3180 Normalise(&relative);
3181 for(i=0;i<victim->skeleton.num_joints;i++){
3182 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3184 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3185 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3186 victim->DoDamage(damagemult*100/victim->protectionhead);
3190 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3194 //relative=victim->coords-oldcoords;
3197 Normalise(&relative);
3198 relative=DoRotation(relative,0,90,0);
3200 Normalise(&relative);
3201 for(i=0;i<victim->skeleton.num_joints;i++){
3202 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3204 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3207 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3208 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3209 award_bonus(id, reverseko);
3215 if(targetframe>animation[currentanimation].numframes-1){
3218 targetanimation=getIdle();
3222 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3223 targetanimation=rollanim;
3225 emit_sound_at(movewhooshsound, coords, 128.);
3227 if(currentanimation==staggerbackhighanim){
3228 targetanimation=getIdle();
3230 if(currentanimation==staggerbackhardanim){
3231 targetanimation=getIdle();
3233 if(currentanimation==removeknifeanim){
3234 targetanimation=getIdle();
3236 if(currentanimation==crouchremoveknifeanim){
3237 targetanimation=getCrouch();
3239 if(currentanimation==backhandspringanim){
3240 targetanimation=getIdle();
3242 if(currentanimation==dodgebackanim){
3243 targetanimation=getIdle();
3245 if(currentanimation==drawleftanim){
3246 targetanimation=getIdle();
3248 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3249 targetanimation=getIdle();
3250 if(currentanimation==crouchdrawrightanim){
3251 targetanimation=getCrouch();
3253 if(weaponactive==-1)weaponactive=0;
3254 else if(weaponactive==0){
3258 buffer=weaponids[0];
3259 weaponids[0]=weaponids[1];
3260 weaponids[1]=buffer;
3264 if(weaponactive==-1){
3265 emit_sound_at(knifesheathesound, coords, 128.);
3267 if(weaponactive!=-1){
3268 emit_sound_at(knifedrawsound, coords, 128.);
3271 if(currentanimation==rollanim){
3272 targetanimation=getCrouch();
3277 if(targetanimation==walljumprightkickanim){
3280 if(targetanimation==walljumpleftkickanim){
3283 targetanimation=jumpdownanim;
3285 if(currentanimation==climbanim){
3286 targetanimation=getCrouch();
3289 if(!isnormal(coords.x))
3300 if(targetanimation==rabbitkickreversalanim){
3301 targetanimation=getCrouch();
3304 if(targetanimation==jumpreversalanim){
3305 targetanimation=getCrouch();
3308 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3309 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3311 float closestdist=-1;
3314 for(i=0;i<numplayers;i++){
3315 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3316 distance=findDistancefast(&player[i].coords,&coords);
3317 if(closestdist==-1||distance<closestdist){
3318 closestdist=distance;
3323 if(closestdist>0&&closest>=0&&closestdist<16){
3324 victim=&player[closest];
3325 targetanimation=walljumprightkickanim;
3327 XYZ rotatetarget=victim->coords-coords;
3328 Normalise(&rotatetarget);
3329 rotation=-asin(0-rotatetarget.x);
3331 if(rotatetarget.z<0)rotation=180-rotation;
3332 targettilt2=-asin(rotatetarget.y)*360/6.28;
3333 velocity=(victim->coords-coords)*4;
3338 if(targetanimation==walljumpbackanim){
3339 targetanimation=backflipanim;
3343 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3345 if(targetanimation==walljumprightanim){
3346 targetanimation=rightflipanim;
3350 velocity=DoRotation(facing,0,30,0)*-8;
3353 if(targetanimation==walljumpfrontanim){
3354 targetanimation=frontflipanim;
3356 //targetrotation-=180;
3361 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3363 if(targetanimation==walljumpleftanim){
3366 float closestdist=-1;
3369 for(i=0;i<numplayers;i++){
3370 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3371 distance=findDistancefast(&player[i].coords,&coords);
3372 if(closestdist==-1||distance<closestdist){
3373 closestdist=distance;
3378 if(closestdist>0&&closest>=0&&closestdist<16){
3379 victim=&player[closest];
3380 targetanimation=walljumpleftkickanim;
3382 XYZ rotatetarget=victim->coords-coords;
3383 Normalise(&rotatetarget);
3384 rotation=-asin(0-rotatetarget.x);
3386 if(rotatetarget.z<0)rotation=180-rotation;
3387 targettilt2=-asin(rotatetarget.y)*360/6.28;
3388 velocity=(victim->coords-coords)*4;
3393 if(targetanimation!=walljumpleftkickanim){
3394 targetanimation=leftflipanim;
3398 velocity=DoRotation(facing,0,-30,0)*-8;
3401 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3403 if(targetanimation==sneakattackanim){
3404 float ycoords=oldcoords.y;
3405 currentanimation=getCrouch();
3406 targetanimation=getCrouch();
3409 targetrotation+=180;
3414 targetheadrotation+=180;
3416 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3420 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3421 float ycoords=oldcoords.y;
3422 targetanimation=getIdle();
3424 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3428 if(currentanimation==knifefollowanim){
3429 targetanimation=getIdle();
3432 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3433 float ycoords=oldcoords.y;
3434 targetanimation=getStop();
3435 targetrotation+=180;
3440 targetheadrotation+=180;
3441 if(!isnormal(coords.x))
3443 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3444 oldcoords=coords+facing*.5;
3445 else if(currentanimation==sweepreversalanim)
3446 oldcoords=coords+facing*1.1;
3447 else if(currentanimation==upunchreversalanim){
3448 oldcoords=coords+facing*1.5;
3449 targetrotation+=180;
3451 targetheadrotation+=180;
3455 else if(currentanimation==knifeslashreversalanim){
3456 oldcoords=coords+facing*.5;
3459 targetheadrotation+=90;
3463 else if(currentanimation==staffspinhitreversalanim){
3464 targetrotation+=180;
3466 targetheadrotation+=180;
3470 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3471 else oldcoords.y=ycoords;
3472 currentoffset=coords-oldcoords;
3478 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3483 if(animation[targetanimation].attack==reversed){
3485 if(targetanimation==sweepreversedanim)targetrotation+=90;
3486 targetanimation=backhandspringanim;
3488 emit_sound_at(landsound, coords, 128);
3490 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3491 targetanimation=rollanim;
3494 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3495 coords.y=oldcoords.y;
3497 if(currentanimation==knifeslashreversedanim){
3498 targetanimation=rollanim;
3503 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3504 coords.y=oldcoords.y;
3508 targetanimation=jumpdownanim;
3510 if(wasLanding())targetanimation=getIdle();
3511 if(wasLandhard())targetanimation=getIdle();
3512 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3513 targetanimation=getIdle();
3515 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3516 coords.y=oldcoords.y;
3517 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3518 targetoffset.y=coords.y;
3519 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3520 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3521 currentoffset.y-=(coords.y-targetoffset.y);
3522 coords.y=targetoffset.y;
3524 normalsupdatedelay=0;
3526 if(currentanimation==upunchanim){
3527 targetanimation=getStop();
3528 normalsupdatedelay=0;
3531 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3532 targetrotation=rotation;
3535 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
3536 if(!hasstaff)DoDamage(35);
3539 rabbitkickragdoll=1;
3541 if(currentanimation==rabbitkickreversedanim){
3548 SolidHitBonus(!id); // FIXME: tricky id
3552 targetanimation=rollanim;
3554 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3558 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3564 if(currentanimation==jumpreversedanim){
3571 SolidHitBonus(!id); // FIXME: tricky id
3575 targetanimation=rollanim;
3577 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3582 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){
3583 targetanimation=getupfromfrontanim;
3586 else if(animation[currentanimation].attack==normalattack){
3587 targetanimation=getIdle();
3590 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3591 targetanimation=blockhighleftstrikeanim;
3593 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3594 targetanimation=getIdle();
3597 if(currentanimation==spinkickanim&&victim->skeleton.free){
3598 if(creature==rabbittype)targetanimation=fightidleanim;
3603 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3605 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3606 targetanimation=jumpdownanim;
3611 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3612 if(!isRun()||!wasRun()){
3613 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3614 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3615 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3616 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3618 if(isRun()&&wasRun()){
3621 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3622 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3625 else if(transspeed)target+=multiplier*transspeed*speed*2;
3627 if(!isRun()||!wasRun()){
3628 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3629 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3630 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3631 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3635 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3637 if(target>1){currentframe=targetframe; target=1;}
3639 rot=targetrot*target;
3640 rotation+=rot-oldrot;
3646 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3648 for(i=0;i<skeleton.num_joints;i++){
3649 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3652 skeleton.FindForwards();
3654 for(i=0;i<skeleton.num_muscles;i++){
3655 if(skeleton.muscles[i].visible)
3657 skeleton.FindRotationMuscle(i,targetanimation);
3660 for(i=0;i<skeleton.num_muscles;i++){
3661 if(skeleton.muscles[i].visible)
3663 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3664 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3665 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3670 for(i=0;i<skeleton.num_joints;i++){
3671 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3674 skeleton.FindForwards();
3676 for(i=0;i<skeleton.num_muscles;i++){
3677 if(skeleton.muscles[i].visible)
3679 skeleton.FindRotationMuscle(i,targetanimation);
3682 for(i=0;i<skeleton.num_muscles;i++){
3683 if(skeleton.muscles[i].visible)
3685 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3686 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3687 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3688 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3689 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3690 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3691 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3692 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3693 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3697 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3699 oldcurrentanimation=currentanimation;
3700 oldtargetanimation=targetanimation;
3701 oldtargetframe=targetframe;
3702 oldcurrentframe=currentframe;
3704 for(i=0;i<skeleton.num_joints;i++){
3705 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3706 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3708 offset=currentoffset*(1-target)+targetoffset*target;
3709 for(i=0;i<skeleton.num_muscles;i++){
3710 if(skeleton.muscles[i].visible)
3712 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3713 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3714 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3719 if(isLanding()&&landhard){
3720 if(id==0)camerashake+=.4;
3721 targetanimation=getLandhard();
3728 //skeleton.DoConstraints();
3731 void Person::DoStuff(){
3732 static XYZ terrainnormal;
3733 static XYZ flatfacing;
3734 static XYZ flatvelocity;
3735 static float flatvelspeed;
3739 static int bloodsize;
3740 static int startx,starty,endx,endy;
3741 static int texdetailint;
3742 static GLubyte color;
3743 static XYZ bloodvel;
3745 onfiredelay-=multiplier;
3746 if(onfiredelay<0&&onfire)
3754 crouchkeydowntime+=multiplier;
3755 if(!crouchkeydown)crouchkeydowntime=0;
3756 jumpkeydowntime+=multiplier;
3757 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3759 if(hostile||damage>0||bloodloss>0)immobile=0;
3761 if(isIdle()||isRun())targetoffset=0;
3763 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3765 if(id==0)blooddimamount-=multiplier*.3;
3766 speechdelay-=multiplier;
3767 texupdatedelay-=multiplier;
3768 interestdelay-=multiplier;
3769 flamedelay-=multiplier;
3770 parriedrecently-=multiplier;
3776 if(id==0)speed=1.1*speedmult;
3777 else speed=1.0*speedmult;
3778 if(!skeleton.free)rabbitkickragdoll=0;
3782 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3783 if(id!=0&&creature==wolftype&&difficulty==2){
3785 if(aitype!=passivetype){
3787 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){
3791 if(scale<0.2)superruntoggle=0;
3792 if(targetanimation==wolfrunninganim&&!superruntoggle){
3793 targetanimation=getRun();
3797 if(weaponactive==-1&&num_weapons>0){
3798 if(weapons.type[weaponids[0]]==staff){
3805 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3806 /*if(aitype!=playercontrolled)*/
3808 if(burnt>.6)burnt=.6;
3809 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3811 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3822 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3823 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3827 while(flamedelay<0&&onfire){
3829 howmany=abs(Random()%(skeleton.num_joints));
3830 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3831 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3832 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3833 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3834 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3837 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3839 howmany=abs(Random()%(skeleton.num_joints));
3840 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3841 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3842 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3843 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3844 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3848 bleeding-=multiplier*.3;
3850 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3851 if(bleeding<=0&&(detail!=2||osx))DoMipmaps();
3855 if(neckspurtamount>0){
3856 neckspurtamount-=multiplier;
3857 neckspurtdelay-=multiplier*3;
3858 neckspurtparticledelay-=multiplier*3;
3859 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3863 bloodvel.z=5*neckspurtamount;
3864 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3867 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3869 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3870 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3871 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);
3872 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);
3873 neckspurtparticledelay=.05;
3875 if(neckspurtdelay<0){
3880 if(deathbleeding>0&&dead!=2){
3881 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
3882 else bleeddelay-=5*multiplier/4;
3883 if(bleeddelay<0&&bloodtoggle){
3888 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3889 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
3890 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
3891 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);
3894 bloodloss+=deathbleeding*multiplier*80;
3895 deathbleeding-=multiplier*1.6;
3896 //if(id==0)deathbleeding-=multiplier*.2;
3897 if(deathbleeding<0)deathbleeding=0;
3898 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
3899 if(weaponactive!=-1){
3900 weapons.owner[weaponids[0]]=-1;
3901 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
3902 weapons.velocity[weaponids[0]].x+=.01;
3903 weapons.tipvelocity[weaponids[0]]=velocity*scale;
3904 weapons.missed[weaponids[0]]=1;
3905 weapons.hitsomething[weaponids[0]]=0;
3906 weapons.freetime[weaponids[0]]=0;
3907 weapons.firstfree[weaponids[0]]=1;
3908 weapons.physics[weaponids[0]]=1;
3911 weaponids[0]=weaponids[num_weapons];
3912 if(weaponstuck==num_weapons)weaponstuck=0;
3915 for(i=0;i<numplayers;i++){
3916 player[i].wentforweapon=0;
3928 if(!dead&&creature==wolftype){
3929 award_bonus(0, Wolfbonus);
3932 if(targetanimation==knifefollowedanim&&!skeleton.free){
3933 for(i=0;i<skeleton.num_joints;i++){
3934 skeleton.joints[i].velocity=0;
3935 skeleton.joints[i].velocity.y=-2;
3938 if(id!=0&&unconscioustime>.1){
3946 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
3949 bloodsize=5-realtexdetail;
3953 texdetailint=realtexdetail;
3954 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3955 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3956 endx=startx+bloodsize;
3957 endy=starty+bloodsize;
3959 if(startx<0){startx=0;bleeding=0;}
3960 if(starty<0){starty=0;bleeding=0;}
3961 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
3962 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
3963 if(endx<startx)endx=startx;
3964 if(endy<starty)endy=starty;
3966 for(i=startx;i<endx;i++){
3967 for(j=starty;j<endy;j++){
3969 color=Random()%85+170;
3970 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
3971 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
3972 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
3977 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3982 bleedy-=4/realtexdetail;
3983 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
3984 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
3987 bleedx+=4*direction/realtexdetail;
3988 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
3989 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
3993 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
3994 righthandmorphness=targetrighthandmorphness;
3995 righthandmorphstart=righthandmorphend;
3997 else if(righthandmorphness>targetrighthandmorphness){
3998 righthandmorphness-=multiplier*4;
4000 else if(righthandmorphness<targetrighthandmorphness){
4001 righthandmorphness+=multiplier*4;
4004 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4005 lefthandmorphness=targetlefthandmorphness;
4006 lefthandmorphstart=lefthandmorphend;
4008 else if(lefthandmorphness>targetlefthandmorphness){
4009 lefthandmorphness-=multiplier*4;
4011 else if(lefthandmorphness<targetlefthandmorphness){
4012 lefthandmorphness+=multiplier*4;
4015 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4016 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4017 tailmorphness=targettailmorphness;
4018 tailmorphstart=tailmorphend;
4020 else if(tailmorphness>targettailmorphness){
4021 tailmorphness-=multiplier*10;
4023 else if(tailmorphness<targettailmorphness){
4024 tailmorphness+=multiplier*10;
4028 if(creature==wolftype){
4029 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4030 tailmorphness=targettailmorphness;
4031 tailmorphstart=tailmorphend;
4033 else if(tailmorphness>targettailmorphness){
4034 tailmorphness-=multiplier*2;
4036 else if(tailmorphness<targettailmorphness){
4037 tailmorphness+=multiplier*2;
4041 if(headmorphend==3||headmorphstart==3){
4042 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4043 headmorphness=targetheadmorphness;
4044 headmorphstart=headmorphend;
4046 else if(headmorphness>targetheadmorphness){
4047 headmorphness-=multiplier*7;
4049 else if(headmorphness<targetheadmorphness){
4050 headmorphness+=multiplier*7;
4053 else if(headmorphend==5||headmorphstart==5){
4054 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4055 headmorphness=targetheadmorphness;
4056 headmorphstart=headmorphend;
4058 else if(headmorphness>targetheadmorphness){
4059 headmorphness-=multiplier*10;
4061 else if(headmorphness<targetheadmorphness){
4062 headmorphness+=multiplier*10;
4066 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4067 headmorphness=targetheadmorphness;
4068 headmorphstart=headmorphend;
4070 else if(headmorphness>targetheadmorphness){
4071 headmorphness-=multiplier*4;
4073 else if(headmorphness<targetheadmorphness){
4074 headmorphness+=multiplier*4;
4078 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4079 chestmorphness=targetchestmorphness;
4080 chestmorphstart=chestmorphend;
4082 else if(chestmorphness>targetchestmorphness){
4083 chestmorphness-=multiplier;
4085 else if(chestmorphness<targetchestmorphness){
4086 chestmorphness+=multiplier;
4089 if(dead!=2&&howactive<=typesleeping){
4090 if(chestmorphstart==0&&chestmorphend==0){
4092 targetchestmorphness=1;
4095 if(chestmorphstart!=0&&chestmorphend!=0){
4097 targetchestmorphness=1;
4099 if(environment==snowyenvironment){
4102 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4103 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4104 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4105 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4106 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4107 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4111 if(!dead&&howactive<typesleeping){
4112 blinkdelay-=multiplier*2;
4113 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4115 targetheadmorphness=1;
4117 blinkdelay=(float)(abs(Random()%40))/5;
4119 if(headmorphstart==3&&headmorphend==3){
4121 targetheadmorphness=1;
4126 twitchdelay-=multiplier*1.5;
4127 if(targetanimation!=hurtidleanim){
4128 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4130 targetheadmorphness=1;
4132 twitchdelay=(float)(abs(Random()%40))/5;
4134 if(headmorphstart==5&&headmorphend==5){
4136 targetheadmorphness=1;
4140 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4141 twitchdelay3-=multiplier*1;
4143 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4144 righthandmorphness=0;
4145 targetrighthandmorphness=1;
4146 righthandmorphend=1;
4147 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4149 if(righthandmorphstart==1&&righthandmorphend==1){
4150 righthandmorphness=0;
4151 targetrighthandmorphness=1;
4152 righthandmorphend=0;
4156 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4157 lefthandmorphness=0;
4158 targetlefthandmorphness=1;
4160 twitchdelay3=(float)(abs(Random()%40))/5;
4162 if(lefthandmorphstart==1&&lefthandmorphend==1){
4163 lefthandmorphness=0;
4164 targetlefthandmorphness=1;
4171 if(creature==rabbittype){
4172 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4173 else twitchdelay2-=multiplier*0.5;
4174 if(howactive<=typesleeping){
4175 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4177 targettailmorphness=1;
4179 twitchdelay2=(float)(abs(Random()%40))/5;
4181 if(tailmorphstart==1&&tailmorphend==1){
4183 targettailmorphness=1;
4186 if(tailmorphstart==2&&tailmorphend==2){
4188 targettailmorphness=1;
4195 if(creature==wolftype){
4196 twitchdelay2-=multiplier*1.5;
4198 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4200 targettailmorphness=1;
4205 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4207 targettailmorphness=1;
4211 if(twitchdelay2<=0){
4212 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4214 targettailmorphness=1;
4217 if(tailmorphstart==1&&tailmorphend==1){
4219 targettailmorphness=1;
4222 if(tailmorphstart==2&&tailmorphend==2){
4224 targettailmorphness=1;
4227 if(tailmorphstart==3&&tailmorphend==3){
4229 targettailmorphness=1;
4232 if(tailmorphstart==4&&tailmorphend==4){
4234 targettailmorphness=1;
4240 if(dead!=1)unconscioustime=0;
4242 if(dead==1||howactive==typesleeping){
4243 unconscioustime+=multiplier;
4244 //If unconscious, close eyes and mouth
4245 if(righthandmorphend!=0)righthandmorphness=0;
4246 righthandmorphend=0;
4247 targetrighthandmorphness=1;
4249 if(lefthandmorphend!=0)lefthandmorphness=0;
4251 targetlefthandmorphness=1;
4253 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4255 targetheadmorphness=1;
4259 if(howactive>typesleeping){
4262 if(bloodtoggle&&!bled){
4263 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4265 if(bloodtoggle&&!bled)
4266 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4267 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4268 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4272 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4277 if(dead==2||howactive>typesleeping){
4278 //If dead, open mouth and hands
4279 if(righthandmorphend!=0)righthandmorphness=0;
4280 righthandmorphend=0;
4281 targetrighthandmorphness=1;
4283 if(lefthandmorphend!=0)lefthandmorphness=0;
4285 targetlefthandmorphness=1;
4287 if(headmorphend!=2)headmorphness=0;
4289 targetheadmorphness=1;
4292 if(stunned>0&&!dead&&headmorphend!=2){
4293 if(headmorphend!=4)headmorphness=0;
4295 targetheadmorphness=1;
4298 if(damage>damagetolerance&&!dead){
4303 if(creature==wolftype){
4304 award_bonus(0, Wolfbonus);
4309 if(weaponactive!=-1){
4310 weapons.owner[weaponids[0]]=-1;
4311 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4312 weapons.velocity[weaponids[0]].x+=.01;
4313 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4314 weapons.missed[weaponids[0]]=1;
4315 weapons.hitsomething[weaponids[0]]=0;
4316 weapons.freetime[weaponids[0]]=0;
4317 weapons.firstfree[weaponids[0]]=1;
4318 weapons.physics[weaponids[0]]=1;
4321 weaponids[0]=weaponids[num_weapons];
4322 if(weaponstuck==num_weapons)weaponstuck=0;
4325 for(i=0;i<numplayers;i++){
4326 player[i].wentforweapon=0;
4332 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4340 //if(dead)damage-=multiplier/4;
4341 if(!dead)damage-=multiplier*13;
4342 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4343 if(!dead)permanentdamage-=multiplier*4;
4344 if(isIdle()||isCrouch()){
4345 if(!dead)permanentdamage-=multiplier*4;
4346 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4348 if(damage<0)damage=0;
4349 if(permanentdamage<0)permanentdamage=0;
4350 if(superpermanentdamage<0)superpermanentdamage=0;
4351 if(permanentdamage<superpermanentdamage){
4352 permanentdamage=superpermanentdamage;
4354 if(damage<permanentdamage){
4355 damage=permanentdamage;
4357 if(dead==1&&damage<damagetolerance){
4361 for(i=0;i<skeleton.num_joints;i++){
4362 skeleton.joints[i].velocity=0;
4365 if(permanentdamage>damagetolerance&&dead!=2){
4368 if(weaponactive!=-1){
4369 weapons.owner[weaponids[0]]=-1;
4370 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4371 weapons.velocity[weaponids[0]].x+=.01;
4372 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4373 weapons.missed[weaponids[0]]=1;
4374 weapons.hitsomething[weaponids[0]]=0;
4375 weapons.freetime[weaponids[0]]=0;
4376 weapons.firstfree[weaponids[0]]=1;
4377 weapons.physics[weaponids[0]]=1;
4380 weaponids[0]=weaponids[num_weapons];
4381 if(weaponstuck==num_weapons)weaponstuck=0;
4384 for(i=0;i<numplayers;i++){
4385 player[i].wentforweapon=0;
4391 if(!dead&&creature==wolftype){
4392 award_bonus(0, Wolfbonus);
4395 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4396 award_bonus(id, touchofdeath);
4397 if(id!=0&&unconscioustime>.1){
4405 emit_sound_at(breaksound, coords);
4408 if(skeleton.free==1){
4409 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4412 //If knocked over, open hands and close mouth
4413 if(righthandmorphend!=0)righthandmorphness=0;
4414 righthandmorphend=0;
4415 targetrighthandmorphness=1;
4417 if(lefthandmorphend!=0)lefthandmorphness=0;
4419 targetlefthandmorphness=1;
4421 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4422 if(headmorphend!=0)headmorphness=0;
4424 targetheadmorphness=1;
4428 skeleton.DoGravity(&scale);
4430 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4431 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4432 award_bonus(id, deepimpact);
4433 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4437 for(j=0;j<skeleton.num_joints;j++){
4438 average+=skeleton.joints[j].position;
4442 coords+=average*scale;
4443 for(j=0;j<skeleton.num_joints;j++){
4444 skeleton.joints[j].position-=average;
4446 average/=multiplier;
4448 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4450 for(i=0;i<skeleton.num_joints;i++){
4451 velocity+=skeleton.joints[i].velocity*scale;
4453 velocity/=skeleton.num_joints;
4455 if(!isnormal(velocity.x)&&velocity.x){
4468 if(findLength(&average)<10&&dead&&skeleton.free){
4469 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4470 if(skeleton.longdead>2000){
4471 if(skeleton.longdead>6000){
4472 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4477 if(dead==2&&bloodloss<damagetolerance){
4479 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4481 if(bloodtoggle&&!bled){
4482 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4484 if(bloodtoggle&&!bled)
4485 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4486 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4487 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4491 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4495 if(dead==2&&bloodloss>=damagetolerance){
4497 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4498 if(bleeding<=0)DoBlood(1,255);
4499 if(bloodtoggle&&!bled){
4500 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4502 if(bloodtoggle&&!bled)
4503 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4504 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4505 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4509 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4516 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4518 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4522 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4523 if(velocity.y<-30)canrecover=0;
4524 for(i=0;i<objects.numobjects;i++){
4525 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4526 colviewer=startpoint;
4528 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4536 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4537 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4538 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4539 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4541 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4542 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4543 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4545 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4546 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4547 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4549 Normalise(&terrainnormal);
4551 targetrotation=-asin(0-terrainnormal.x);
4552 targetrotation*=360/6.28;
4553 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4554 rotation=targetrotation;
4558 targetanimation=flipanim;
4559 crouchtogglekeydown=1;
4564 currentanimation=tempanim;
4567 //tilt2=targettilt2;
4569 //if(middle.y>0)targetoffset.y=middle.y+1;
4571 for(i=0;i<skeleton.num_joints;i++){
4572 tempanimation.position[i][0]=skeleton.joints[i].position;
4573 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4578 if(findLength(&average)<10&&!dead&&skeleton.free){
4579 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4580 if(skeleton.longdead>(damage+500)*1.5){
4581 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4587 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4588 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4589 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4590 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4592 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4593 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4594 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4596 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4597 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4598 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4600 Normalise(&terrainnormal);
4602 targetrotation=-asin(0-terrainnormal.x);
4603 targetrotation*=360/6.28;
4604 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4605 rotation=targetrotation;
4608 terrainnormal=terrain.getNormal(coords.x,coords.z);
4609 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4613 /*XYZ otherterrainnormal;
4614 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
4615 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4616 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4617 targettilt2=asin(otherterrainnormal.y)*180/3.14;
4620 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4624 if(skeleton.forward.y<0){
4625 targetanimation=getupfrombackanim;
4629 if(skeleton.forward.y>-.3){
4630 targetanimation=getupfromfrontanim;
4632 targetrotation+=180;
4638 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4639 targetanimation=rollanim;
4640 targetrotation=lookrotation;
4644 if(forwardkeydown)targetrotation+=45;
4645 if(backkeydown)targetrotation-=45;
4649 if(forwardkeydown)targetrotation-=45;
4650 if(backkeydown)targetrotation+=45;
4653 if ( !leftkeydown&&!rightkeydown)
4654 targetrotation+=180;
4656 targetrotation+=180;
4660 if(abs(targettilt2)>50)targettilt2=0;
4661 currentanimation=tempanim;
4666 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4668 for(i=0;i<skeleton.num_joints;i++){
4669 tempanimation.position[i][0]=skeleton.joints[i].position;
4670 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4677 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4678 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4681 tempvelocity=velocity;
4682 Normalise(&tempvelocity);
4683 targetrotation=-asin(0-tempvelocity.x);
4684 targetrotation*=360/6.28;
4685 if(velocity.z<0)targetrotation=180-targetrotation;
4686 //targetrotation+=180;
4689 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4690 targetanimation=rollanim;
4694 targetanimation=backhandspringanim;
4695 targetrotation+=180;
4700 emit_sound_at(movewhooshsound, coords, 128.);
4702 currentanimation=targetanimation;
4703 currentframe=targetframe-1;
4708 rotation=targetrotation;
4715 if(skeleton.freefall==0)freefall=0;
4717 if(!isnormal(velocity.x)&&velocity.x){
4722 if(aitype!=passivetype||skeleton.free==1)
4723 if(findLengthfast(&velocity)>.1)
4724 for(i=0;i<objects.numobjects;i++){
4725 if(objects.type[i]==firetype)
4726 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){
4728 if(!objects.onfire[i]){
4729 emit_sound_at(firestartsound, objects.position[i]);
4731 objects.onfire[i]=1;
4734 if(objects.onfire[i]){
4739 if(objects.type[i]==bushtype)
4740 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){
4742 if(!objects.onfire[i]){
4743 emit_sound_at(firestartsound, objects.position[i]);
4745 objects.onfire[i]=1;
4749 if(objects.onfire[i]){
4753 if(objects.messedwith[i]<=0){
4757 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4760 envsound[numenvsounds]=coords;
4761 envsoundvol[numenvsounds]=4*findLength(&velocity);
4762 envsoundlife[numenvsounds]=.4;
4767 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4768 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4770 if(environment!=desertenvironment)
4771 for(j=0;j<howmany;j++){
4772 tempvel.x=float(abs(Random()%100)-50)/20;
4773 tempvel.y=float(abs(Random()%100)-50)/20;
4774 tempvel.z=float(abs(Random()%100)-50)/20;
4777 pos.x+=float(abs(Random()%100)-50)/200;
4778 pos.y+=float(abs(Random()%100)-50)/200;
4779 pos.z+=float(abs(Random()%100)-50)/200;
4780 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);
4781 Sprite::setLastSpriteSpecial(1);
4783 howmany=findLength(&velocity)*4;
4785 if(environment==snowyenvironment)
4786 for(j=0;j<howmany;j++){
4787 tempvel.x=float(abs(Random()%100)-50)/20;
4788 tempvel.y=float(abs(Random()%100)-50)/20;
4789 tempvel.z=float(abs(Random()%100)-50)/20;
4792 pos.x+=float(abs(Random()%100)-50)/200;
4793 pos.y+=float(abs(Random()%100)-50)/200;
4794 pos.z+=float(abs(Random()%100)-50)/200;
4795 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4796 Sprite::setLastSpriteSpecial(2);
4799 objects.rotx[i]+=velocity.x*multiplier*6;
4800 objects.roty[i]+=velocity.z*multiplier*6;
4801 objects.messedwith[i]=.5;
4804 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4805 if(objects.rotation2[i]==0)tempcoord=coords;
4807 tempcoord=coords-objects.position[i];
4808 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4809 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4810 tempcoord+=objects.position[i];
4812 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]){
4813 if(objects.messedwith[i]<=0){
4817 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4820 envsound[numenvsounds]=coords;
4821 envsoundvol[numenvsounds]=4*findLength(&velocity);
4822 envsoundlife[numenvsounds]=.4;
4827 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4828 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4830 if(environment!=desertenvironment)
4831 for(j=0;j<howmany;j++){
4832 tempvel.x=float(abs(Random()%100)-50)/20;
4833 tempvel.y=float(abs(Random()%100)-50)/20;
4834 tempvel.z=float(abs(Random()%100)-50)/20;
4838 pos.x+=float(abs(Random()%100)-50)/150;
4839 pos.y+=float(abs(Random()%100)-50)/150;
4840 pos.z+=float(abs(Random()%100)-50)/150;
4841 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);
4842 Sprite::setLastSpriteSpecial(1);
4844 howmany=findLength(&velocity)*4;
4846 if(environment==snowyenvironment)
4847 for(j=0;j<howmany;j++){
4848 tempvel.x=float(abs(Random()%100)-50)/20;
4849 tempvel.y=float(abs(Random()%100)-50)/20;
4850 tempvel.z=float(abs(Random()%100)-50)/20;
4854 pos.x+=float(abs(Random()%100)-50)/150;
4855 pos.y+=float(abs(Random()%100)-50)/150;
4856 pos.z+=float(abs(Random()%100)-50)/150;
4857 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4858 Sprite::setLastSpriteSpecial(2);
4861 objects.messedwith[i]=.5;
4869 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
4871 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
4872 if(tutoriallevel==1&&id!=0)play=0;
4873 if(play&&aitype!=playercontrolled){
4877 if(creature==rabbittype){
4878 if(i==0)whichsound=rabbitchitter;
4879 if(i==1)whichsound=rabbitchitter2;
4881 if(creature==wolftype){
4882 if(i==0)whichsound=growlsound;
4883 if(i==1)whichsound=growl2sound;
4889 emit_sound_at(whichsound, coords);
4893 if(targetanimation==staggerbackhighanim)staggerdelay=1;
4894 if(targetanimation==staggerbackhardanim)staggerdelay=1;
4895 staggerdelay-=multiplier;
4896 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
4897 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
4898 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
4899 targetanimation=getIdle();
4903 weaponmissdelay-=multiplier;
4904 highreversaldelay-=multiplier;
4905 lowreversaldelay-=multiplier;
4906 lastcollide-=multiplier;
4907 skiddelay-=multiplier;
4908 if(!isnormal(velocity.x)&&velocity.x){
4911 if(!isnormal(targettilt)&&targettilt){
4914 if(!isnormal(targettilt2)&&targettilt2){
4917 if(!isnormal(targetrotation)&&targetrotation){
4921 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
4922 //open hands and close mouth
4923 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4924 righthandmorphness=0;
4925 righthandmorphend=0;
4926 targetrighthandmorphness=1;
4929 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4930 lefthandmorphness=0;
4932 targetlefthandmorphness=1;
4935 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
4938 targetheadmorphness=1;
4942 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){
4943 //open hands and mouth
4944 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4945 righthandmorphness=0;
4946 righthandmorphend=0;
4947 targetrighthandmorphness=1;
4950 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4951 lefthandmorphness=0;
4953 targetlefthandmorphness=1;
4956 if(headmorphend!=1&&headmorphness==targetheadmorphness){
4959 targetheadmorphness=1;
4963 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
4964 //close hands and mouth
4965 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4966 righthandmorphness=0;
4967 righthandmorphend=1;
4968 targetrighthandmorphness=1;
4971 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4972 lefthandmorphness=0;
4974 targetlefthandmorphness=1;
4977 if(headmorphend!=0&&headmorphness==targetheadmorphness){
4980 targetheadmorphness=1;
4984 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){
4985 //close hands and yell
4986 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4987 righthandmorphness=0;
4988 righthandmorphend=1;
4989 targetrighthandmorphness=1;
4992 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4993 lefthandmorphness=0;
4995 targetlefthandmorphness=1;
4998 if(headmorphend!=2&&headmorphness==targetheadmorphness){
5001 targetheadmorphness=1;
5005 if(speechdelay>.25){
5006 if(headmorphend!=2)headmorphness=0;
5008 targetheadmorphness=1;
5014 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
5015 behind=(normaldotproduct(facing,coords-victim->coords)>0);
5019 if(!dead&&targetanimation!=hurtidleanim)
5020 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
5021 if(headmorphend!=4||headmorphness==targetheadmorphness){
5024 targetheadmorphness=1;
5028 if(weaponactive!=-1){
5029 if(weapons.type[weaponids[weaponactive]]!=staff){
5030 righthandmorphstart=1;
5031 righthandmorphend=1;
5033 if(weapons.type[weaponids[weaponactive]]==staff){
5034 righthandmorphstart=2;
5035 righthandmorphend=2;
5037 targetrighthandmorphness=1;
5040 terrainnormal=terrain.getNormal(coords.x,coords.z);
5042 if(animation[targetanimation].attack!=reversal){
5043 if(!isnormal(coords.x))
5051 flatfacing=DoRotation(flatfacing,0,rotation,0);
5053 ReflectVector(&facing,terrainnormal);
5056 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5057 if(onterrain)targettilt2=-facing.y*20;
5061 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5062 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5063 flatvelocity=velocity;
5065 flatvelspeed=findLength(&flatvelocity);
5066 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5067 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5068 if(velocity.y<0)targettilt2*=-1;
5069 if(velocity.y<0)targettilt*=-1;
5070 if(targettilt>25)targettilt=25;
5071 if(targettilt<-25)targettilt=-25;
5074 if(targettilt2>45)targettilt2=45;
5075 if(targettilt2<-45)targettilt2=-45;
5076 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5077 else if(tilt2>targettilt2){
5078 tilt2-=multiplier*400;
5080 else if(tilt2<targettilt2){
5081 tilt2+=multiplier*400;
5083 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5084 if(tilt2>25)tilt2=25;
5085 if(tilt2<-25)tilt2=-25;
5088 if(!isnormal(targettilt)&&targettilt){
5091 if(!isnormal(targettilt2)&&targettilt2){
5096 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5097 if(targetanimation==rabbittackleanim){
5098 velocity+=facing*multiplier*speed*700*scale;
5099 velspeed=findLength(&velocity);
5100 if(velspeed>speed*65*scale){
5102 velspeed=speed*65*scale;
5105 velocity.y+=gravity*multiplier*20;
5106 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5107 velspeed=findLength(&velocity);
5108 velocity=flatfacing*velspeed;
5110 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5111 if(isRun()||targetanimation==rabbitkickanim){
5112 velocity+=facing*multiplier*speed*700*scale;
5113 velspeed=findLength(&velocity);
5114 if(velspeed>speed*45*scale){
5116 velspeed=speed*45*scale;
5119 velocity.y+=gravity*multiplier*20;
5120 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5121 velspeed=findLength(&velocity);
5122 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5123 velocity=flatfacing*velspeed;
5127 velocity+=facing*multiplier*speed*700*scale;
5128 velspeed=findLength(&velocity);
5129 if(creature==rabbittype){
5130 if(velspeed>speed*55*scale){
5132 velspeed=speed*55*scale;
5136 if(creature==wolftype){
5137 if(velspeed>speed*75*scale){
5139 velspeed=speed*75*scale;
5143 velocity.y+=gravity*multiplier*20;
5144 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5145 velspeed=findLength(&velocity);
5146 velocity=flatfacing*velspeed;
5149 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5150 velocity+=facing*multiplier*speed*700*scale;
5151 velspeed=findLength(&velocity);
5152 if(velspeed>speed*45*scale){
5154 velspeed=speed*45*scale;
5157 velocity.y+=gravity*multiplier*20;
5158 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5159 velspeed=findLength(&velocity);
5160 velocity=flatfacing*velspeed;
5164 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5165 velocity+=facing*multiplier*speed*700*scale;
5166 velspeed=findLength(&velocity);
5167 if(velspeed>speed*25*scale){
5169 velspeed=speed*25*scale;
5172 velocity.y+=gravity*multiplier*20;
5173 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5174 velspeed=findLength(&velocity);
5175 velocity=flatfacing*velspeed;
5178 if(targetanimation==sneakanim||targetanimation==walkanim){
5179 velocity+=facing*multiplier*speed*700*scale;
5180 velspeed=findLength(&velocity);
5181 if(velspeed>speed*12*scale){
5183 velspeed=speed*12*scale;
5186 velocity.y+=gravity*multiplier*20;
5187 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5188 velspeed=findLength(&velocity);
5189 velocity=flatfacing*velspeed;
5192 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5193 velocity+=facing*multiplier*speed*700*scale;
5194 velspeed=findLength(&velocity);
5195 if(velspeed>speed*2*scale){
5197 velspeed=speed*2*scale;
5200 velocity.y+=gravity*multiplier*20;
5201 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5202 velspeed=findLength(&velocity);
5203 velocity=flatfacing*velspeed;
5207 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5208 velocity-=facing*multiplier*speed*700*scale;
5209 velspeed=findLength(&velocity);
5210 if(velspeed>speed*2*scale){
5212 velspeed=speed*2*scale;
5215 velocity.y+=gravity*multiplier*20;
5216 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5217 velspeed=findLength(&velocity);
5218 velocity=flatfacing*velspeed*-1;
5221 if(targetanimation==fightsidestep){
5222 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5223 velspeed=findLength(&velocity);
5224 if(velspeed>speed*12*scale){
5226 velspeed=speed*12*scale;
5229 velocity.y+=gravity*multiplier*20;
5230 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5231 velspeed=findLength(&velocity);
5232 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5235 if(targetanimation==staggerbackhighanim){
5236 coords-=facing*multiplier*speed*16*scale;
5239 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5240 coords-=facing*multiplier*speed*20*scale;
5244 if(targetanimation==backhandspringanim){
5245 //coords-=facing*multiplier*50*scale;
5246 velocity+=facing*multiplier*speed*700*scale*-1;
5247 velspeed=findLength(&velocity);
5248 if(velspeed>speed*50*scale){
5250 velspeed=speed*50*scale;
5253 velocity.y+=gravity*multiplier*20;
5254 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5255 velspeed=findLength(&velocity);
5256 velocity=flatfacing*velspeed*-1;
5258 if(targetanimation==dodgebackanim){
5259 //coords-=facing*multiplier*50*scale;
5260 velocity+=facing*multiplier*speed*700*scale*-1;
5261 velspeed=findLength(&velocity);
5262 if(velspeed>speed*60*scale){
5264 velspeed=speed*60*scale;
5267 velocity.y+=gravity*multiplier*20;
5268 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5269 velspeed=findLength(&velocity);
5270 velocity=flatfacing*velspeed*-1;
5273 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5274 velspeed=findLength(&velocity);
5278 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5279 velocity.y+=gravity*multiplier;
5282 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5284 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5285 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5287 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5293 OPENAL_SetPaused(channels[whooshsound], true);
5294 OPENAL_SetVolume(channels[whooshsound], 0);
5297 if(targetanimation==jumpdownanim||isFlip()){
5298 if(isFlip())jumppower=-4;
5299 targetanimation=getLanding();
5300 emit_sound_at(landsound, coords, 128.);
5303 envsound[numenvsounds]=coords;
5304 envsoundvol[numenvsounds]=16;
5305 envsoundlife[numenvsounds]=.4;
5311 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5312 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5313 coords.y=terrain.getHeight(coords.x,coords.z);
5318 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)){
5319 velspeed=findLength(&velocity);
5321 if(velspeed<multiplier*300*scale){
5323 } else velocity-=velocity/velspeed*multiplier*300*scale;
5324 if(velspeed>5&&(isLanding()||isLandhard())){
5325 skiddingdelay+=multiplier;
5332 else skiddingdelay=0;
5336 velspeed=findLength(&velocity);
5338 if(velspeed<multiplier*600*scale){
5340 } else velocity-=velocity/velspeed*multiplier*600*scale;
5342 if(velspeed>5&&(isLanding()||isLandhard())){
5343 skiddingdelay+=multiplier;
5350 else skiddingdelay=0;
5353 if(skiddingdelay<0)skiddingdelay+=multiplier;
5354 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5356 if(!onterrain||environment==grassyenvironment){
5357 emit_sound_at(skidsound, coords, 128*velspeed/10);
5360 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5364 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5365 terrainnormal=victim->coords-coords;
5366 Normalise(&terrainnormal);
5367 targetrotation=-asin(0-terrainnormal.x);
5368 targetrotation*=360/6.28;
5369 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5370 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5373 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5374 targetrotation=victim->targetrotation;
5376 if(targetanimation==rabbittacklinganim){
5377 coords=victim->coords;
5380 skeleton.oldfree=skeleton.free;
5384 midterrain.x=terrain.size*terrain.scale/2;
5385 midterrain.z=terrain.size*terrain.scale/2;
5386 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5388 tempposit=coords-midterrain;
5390 Normalise(&tempposit);
5391 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5392 coords.x=tempposit.x+midterrain.x;
5393 coords.z=tempposit.z+midterrain.z;
5397 int Person::DrawSkeleton(){
5398 int oldplayerdetail;
5399 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5400 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5410 glAlphaFunc(GL_GREATER, 0.0001);
5412 float terrainheight;
5414 if(!isnormal(rotation))rotation=0;
5415 if(!isnormal(tilt))tilt=0;
5416 if(!isnormal(tilt2))tilt2=0;
5417 oldplayerdetail=playerdetail;
5419 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5422 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5425 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5430 if(playerdetail!=oldplayerdetail) {
5432 normalsupdatedelay=0;
5434 static float updatedelaychange;
5435 static float morphness;
5436 static float framemult;
5438 skeleton.FindForwards();
5439 if(howactive==typesittingwall){
5440 skeleton.specialforward[1]=0;
5441 skeleton.specialforward[1].z=1;
5447 static int weaponattachmuscle;
5448 static int weaponrotatemuscle,weaponrotatemuscle2;
5449 static XYZ weaponpoint;
5450 static int start,endthing;
5451 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5452 if(!isSleeping()&&!isSitting()){
5453 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5454 XYZ point,newpoint,change,change2;
5455 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5456 heightleft=terrain.getHeight(point.x,point.z)+.04;
5458 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5459 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5460 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5461 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5462 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5464 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5465 heightright=terrain.getHeight(point.x,point.z)+.04;
5466 point.y=heightright;
5467 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5468 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5469 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5470 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5471 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5472 skeleton.DoConstraints(&coords,&scale);
5474 if(creature==wolftype){
5475 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5476 heightleft=terrain.getHeight(point.x,point.z)+.04;
5478 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5479 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5480 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5481 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5482 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5484 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5485 heightright=terrain.getHeight(point.x,point.z)+.04;
5486 point.y=heightright;
5487 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5488 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5489 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5490 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5491 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5492 skeleton.DoConstraints(&coords,&scale);
5495 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5496 XYZ point,newpoint,change,change2;
5497 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5498 heightleft=terrain.getHeight(point.x,point.z)+.04;
5500 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5501 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5502 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5503 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5504 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5506 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5507 heightright=terrain.getHeight(point.x,point.z)+.04;
5508 point.y=heightright;
5509 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5510 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5511 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5512 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5513 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5514 skeleton.DoConstraints(&coords,&scale);
5516 if(creature==wolftype){
5517 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5518 heightleft=terrain.getHeight(point.x,point.z)+.04;
5520 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5521 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5522 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5523 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5524 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5526 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5527 heightright=terrain.getHeight(point.x,point.z)+.04;
5528 point.y=heightright;
5529 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5530 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5531 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5532 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5533 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5534 skeleton.DoConstraints(&coords,&scale);
5538 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5539 XYZ point,newpoint,change,change2;
5540 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5541 heightleft=terrain.getHeight(point.x,point.z)+.04;
5543 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5544 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5545 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5546 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5547 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5549 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5550 heightright=terrain.getHeight(point.x,point.z)+.04;
5551 point.y=heightright;
5552 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5553 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5554 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5555 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5556 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5557 skeleton.DoConstraints(&coords,&scale);
5559 if(creature==wolftype){
5560 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5561 heightleft=terrain.getHeight(point.x,point.z)+.04;
5563 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5564 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5565 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5566 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5567 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5569 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5570 heightright=terrain.getHeight(point.x,point.z)+.04;
5571 point.y=heightright;
5572 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5573 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5574 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5575 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5576 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5577 skeleton.DoConstraints(&coords,&scale);
5581 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()))
5584 targetheadrotation=-targetrotation;
5585 targetheadrotation2=0;
5586 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5588 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5589 skeleton.drawmodel.vertex[i]=0;
5590 skeleton.drawmodel.vertex[i].y=999;
5592 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5593 skeleton.drawmodellow.vertex[i]=0;
5594 skeleton.drawmodellow.vertex[i].y=999;
5596 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5597 skeleton.drawmodelclothes.vertex[i]=0;
5598 skeleton.drawmodelclothes.vertex[i].y=999;
5600 for(i=0;i<skeleton.num_muscles;i++){
5601 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5605 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5606 morphness=righthandmorphness;
5607 start=righthandmorphstart;
5608 endthing=righthandmorphend;
5610 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5611 morphness=lefthandmorphness;
5612 start=lefthandmorphstart;
5613 endthing=lefthandmorphend;
5615 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5616 morphness=headmorphness;
5617 start=headmorphstart;
5618 endthing=headmorphend;
5620 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)){
5621 morphness=chestmorphness;
5622 start=chestmorphstart;
5623 endthing=chestmorphend;
5625 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)){
5626 morphness=tailmorphness;
5627 start=tailmorphstart;
5628 endthing=tailmorphend;
5630 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5631 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5632 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5635 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5636 if(!skeleton.free)glRotatef(tilt,0,0,1);
5639 glTranslatef(mid.x,mid.y,mid.z);
5641 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5642 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5644 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5645 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5647 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5648 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5650 if(playerdetail||skeleton.free==3)
5652 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5654 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5656 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5657 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,
5658 (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,
5659 (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);
5660 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)
5661 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,
5662 (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,
5663 (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);
5664 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)
5665 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,
5666 (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,
5667 (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);
5668 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5669 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,
5670 (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,
5671 (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);
5672 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5673 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5674 //if(!isnormal(scale))test=1;
5675 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5676 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5677 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5682 if(!playerdetail||skeleton.free==3)
5684 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5686 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5688 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5689 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5690 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5691 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5692 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)
5693 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5694 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5695 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5696 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)
5697 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5698 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5699 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5700 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5701 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5702 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5703 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5705 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5706 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5707 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5708 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5714 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5715 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5717 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5720 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5721 if(!skeleton.free)glRotatef(tilt,0,0,1);
5722 glTranslatef(mid.x,mid.y,mid.z);
5723 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5724 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5726 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5727 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5729 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5730 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5732 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5733 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5735 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5736 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5737 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5738 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5739 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)
5740 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5741 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5742 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5743 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)
5744 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5745 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5746 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5747 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5748 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5749 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5750 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5751 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5752 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5753 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5754 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5759 updatedelay=1+(float)(Random()%100)/1000;
5761 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5762 normalsupdatedelay=1;
5763 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5764 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5765 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5769 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5770 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5771 if(skeleton.clothes){
5772 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5777 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5778 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5779 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5780 if(skeleton.free==1)updatedelaychange*=6;
5781 if(id==0)updatedelaychange*=8;
5782 updatedelay+=updatedelaychange;
5784 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5786 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5787 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5788 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5789 if(!skeleton.free)glRotatef(rotation,0,1,0);
5792 glColor4f(.4,1,.4,1);
5793 glDisable(GL_LIGHTING);
5794 glDisable(GL_TEXTURE_2D);
5797 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5798 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5804 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5805 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);
5806 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);
5807 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);
5808 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);
5809 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);
5810 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);
5816 terrainlight=terrain.getLighting(coords.x,coords.z);
5817 distance=findDistancefast(&viewer,&coords);
5818 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5819 if(distance>1)distance=1;
5821 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5822 if(terrainheight<1)terrainheight=1;
5823 if(terrainheight>1.7)terrainheight=1.7;
5826 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5827 glDisable(GL_BLEND);
5828 glAlphaFunc(GL_GREATER, 0.0001);
5829 glEnable(GL_TEXTURE_2D);
5831 glDisable(GL_TEXTURE_2D);
5832 glColor4f(.7,.35,0,.5);
5834 glEnable(GL_LIGHTING);
5837 if(tutoriallevel&&id!=0){
5838 //glDisable(GL_TEXTURE_2D);
5839 glColor4f(.7,.7,.7,0.6);
5841 glEnable(GL_LIGHTING);
5843 if(canattack&&cananger)
5844 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5845 glDisable(GL_TEXTURE_2D);
5846 glColor4f(1,0,0,0.8);
5848 glMatrixMode(GL_TEXTURE);
5850 glTranslatef(0,-smoketex,0);
5851 glTranslatef(-smoketex,0,0);
5855 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5856 else skeleton.drawmodel.draw();
5860 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5861 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5864 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
5865 if(tutoriallevel&&id!=0){
5867 glMatrixMode(GL_MODELVIEW);
5868 glEnable(GL_TEXTURE_2D);
5869 glColor4f(.7,.7,.7,0.6);
5871 glEnable(GL_LIGHTING);
5873 if(canattack&&cananger)
5874 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5875 glDisable(GL_TEXTURE_2D);
5876 glColor4f(1,0,0,0.8);
5878 glMatrixMode(GL_TEXTURE);
5880 glTranslatef(0,-smoketex*.6,0);
5881 glTranslatef(smoketex*.6,0,0);
5884 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5885 else skeleton.drawmodel.draw();
5889 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5890 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5895 if(tutoriallevel&&id!=0){
5897 glMatrixMode(GL_MODELVIEW);
5898 glEnable(GL_TEXTURE_2D);
5900 if(skeleton.clothes){
5903 if(!immediate)skeleton.drawmodelclothes.draw();
5904 if(immediate)skeleton.drawmodelclothes.drawimmediate();
5911 for(k=0;k<num_weapons;k++){
5913 if(weaponactive==k){
5914 if(weapons.type[i]!=staff){
5915 for(j=0;j<skeleton.num_muscles;j++){
5916 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5917 weaponattachmuscle=j;
5920 for(j=0;j<skeleton.num_muscles;j++){
5921 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){
5922 weaponrotatemuscle=j;
5925 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5926 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
5928 if(weapons.type[i]==staff){
5929 for(j=0;j<skeleton.num_muscles;j++){
5930 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5931 weaponattachmuscle=j;
5934 for(j=0;j<skeleton.num_muscles;j++){
5935 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){
5936 weaponrotatemuscle=j;
5939 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
5940 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5941 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5942 XYZ tempnormthing,vec1,vec2;
5943 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5944 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
5945 CrossProduct(&vec1,&vec2,&tempnormthing);
5946 Normalise(&tempnormthing);
5947 if(targetanimation!=staffhitanim&¤tanimation!=staffhitanim&&targetanimation!=staffgroundsmashanim&¤tanimation!=staffgroundsmashanim&&targetanimation!=staffspinhitanim&¤tanimation!=staffspinhitanim)weaponpoint+=tempnormthing*.1-skeleton.specialforward[1]*.3+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5950 if(weaponactive!=k&&weaponstuck!=k){
5951 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;
5952 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;
5953 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;
5954 for(j=0;j<skeleton.num_muscles;j++){
5955 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){
5956 weaponrotatemuscle=j;
5961 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
5962 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
5963 for(j=0;j<skeleton.num_muscles;j++){
5964 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){
5965 weaponrotatemuscle=j;
5970 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;
5971 weapons.bigrotation[i]=rotation;
5972 weapons.bigtilt[i]=tilt;
5973 weapons.bigtilt2[i]=tilt2;
5976 weapons.position[i]=weaponpoint*scale+coords;
5977 weapons.bigrotation[i]=0;
5978 weapons.bigtilt[i]=0;
5979 weapons.bigtilt2[i]=0;
5981 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
5982 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
5983 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
5984 if(weaponactive==k){
5985 if(weapons.type[i]==knife){
5986 weapons.smallrotation[i]=180;
5987 weapons.smallrotation2[i]=0;
5988 if(isCrouch()||wasCrouch()){
5989 weapons.smallrotation2[i]=20;
5991 if(targetanimation==hurtidleanim){
5992 weapons.smallrotation2[i]=50;
5994 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
5995 XYZ temppoint1,temppoint2,tempforward;
5998 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5999 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6000 distance=findDistance(&temppoint1,&temppoint2);
6001 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6002 weapons.rotation2[i]*=360/6.28;
6005 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6006 weapons.rotation1[i]*=360/6.28;
6007 weapons.rotation3[i]=0;
6008 weapons.smallrotation[i]=-90;
6009 weapons.smallrotation2[i]=0;
6010 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6012 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
6013 XYZ temppoint1,temppoint2,tempforward;
6016 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6017 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6018 distance=findDistance(&temppoint1,&temppoint2);
6019 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6020 weapons.rotation2[i]*=360/6.28;
6023 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6024 weapons.rotation1[i]*=360/6.28;
6025 weapons.rotation3[i]=0;
6026 weapons.smallrotation[i]=90;
6027 weapons.smallrotation2[i]=0;
6028 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6030 if(targetanimation==knifethrowanim){
6031 weapons.smallrotation[i]=90;
6032 //weapons.smallrotation2[i]=-90;
6033 weapons.smallrotation2[i]=0;
6034 weapons.rotation1[i]=0;
6035 weapons.rotation2[i]=0;
6036 weapons.rotation3[i]=0;
6038 if(targetanimation==knifesneakattackanim&&targetframe<5){
6039 weapons.smallrotation[i]=-90;
6040 weapons.rotation1[i]=0;
6041 weapons.rotation2[i]=0;
6042 weapons.rotation3[i]=0;
6045 if(weapons.type[i]==sword){
6046 weapons.smallrotation[i]=0;
6047 weapons.smallrotation2[i]=0;
6048 if(targetanimation==knifethrowanim){
6049 weapons.smallrotation[i]=-90;
6050 weapons.smallrotation2[i]=0;
6051 weapons.rotation1[i]=0;
6052 weapons.rotation2[i]=0;
6053 weapons.rotation3[i]=0;
6055 if((targetanimation==swordgroundstabanim&¤tanimation==swordgroundstabanim)||(targetanimation==swordsneakattackanim&¤tanimation==swordsneakattackanim)||(targetanimation==swordslashparryanim&¤tanimation==swordslashparryanim)||(targetanimation==swordslashparriedanim&¤tanimation==swordslashparriedanim)||(targetanimation==swordslashreversalanim&¤tanimation==swordslashreversalanim)||(targetanimation==swordslashreversedanim&¤tanimation==swordslashreversedanim)||(targetanimation==knifeslashreversalanim&¤tanimation==knifeslashreversalanim)||(targetanimation==knifeslashreversedanim&¤tanimation==knifeslashreversedanim)||(targetanimation==swordslashanim&¤tanimation==swordslashanim)||(targetanimation==drawleftanim&¤tanimation==drawleftanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
6056 XYZ temppoint1,temppoint2,tempforward;
6059 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6060 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6061 distance=findDistance(&temppoint1,&temppoint2);
6062 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6063 weapons.rotation2[i]*=360/6.28;
6066 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6067 weapons.rotation1[i]*=360/6.28;
6068 weapons.rotation3[i]=0;
6069 weapons.smallrotation[i]=90;
6070 weapons.smallrotation2[i]=0;
6071 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6074 if(weapons.type[i]==staff){
6075 weapons.smallrotation[i]=100;
6076 weapons.smallrotation2[i]=0;
6077 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6078 XYZ temppoint1,temppoint2,tempforward;
6081 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6082 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6083 distance=findDistance(&temppoint1,&temppoint2);
6084 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6085 weapons.rotation2[i]*=360/6.28;
6088 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6089 weapons.rotation1[i]*=360/6.28;
6090 weapons.rotation3[i]=0;
6091 weapons.smallrotation[i]=90;
6092 weapons.smallrotation2[i]=0;
6093 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6097 if(weaponactive!=k&&weaponstuck!=k){
6098 if(weapons.type[i]==knife){
6099 weapons.smallrotation[i]=-70;
6100 weapons.smallrotation2[i]=10;
6102 if(weapons.type[i]==sword){
6103 weapons.smallrotation[i]=-100;
6104 weapons.smallrotation2[i]=-8;
6106 if(weapons.type[i]==staff){
6107 weapons.smallrotation[i]=-100;
6108 weapons.smallrotation2[i]=-8;
6112 if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
6113 else weapons.smallrotation[i]=0;
6114 weapons.smallrotation2[i]=10;
6121 if(skeleton.free)calcrot=1;
6122 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6123 if(currentanimation!=targetanimation)calcrot=1;
6124 //if(id==0)calcrot=1;
6125 if(skeleton.free==2)calcrot=0;
6131 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6134 static float distance;
6135 static float olddistance;
6136 static int intersecting;
6137 static int firstintersecting;
6140 static XYZ start,end;
6141 static float slopethreshold=-.4;
6143 firstintersecting=-1;
6147 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6148 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6150 for (j=0;j<model->TriangleNum;j++){
6151 if(model->facenormals[j].y<=slopethreshold){
6153 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)));
6154 if(distance<radius){
6155 point=*p1-model->facenormals[j]*distance;
6156 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;
6157 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6158 &model->vertex[model->Triangles[j].vertex[1]],
6160 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6161 &model->vertex[model->Triangles[j].vertex[2]],
6163 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6164 &model->vertex[model->Triangles[j].vertex[2]],
6167 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6171 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)){
6172 p1->y=point.y+radius;
6173 if((targetanimation==jumpdownanim||isFlip())){
6174 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6176 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6182 OPENAL_SetPaused(channels[whooshsound], true);
6183 OPENAL_SetVolume(channels[whooshsound], 0);
6186 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6187 if(isFlip())jumppower=-4;
6188 targetanimation=getLanding();
6189 emit_sound_at(landsound, coords, 128.);
6192 envsound[numenvsounds]=coords;
6193 envsoundvol[numenvsounds]=16;
6194 envsoundlife[numenvsounds]=.4;
6202 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6205 for (j=0;j<model->TriangleNum;j++){
6206 if(model->facenormals[j].y>slopethreshold){
6210 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)));
6211 if(distance<radius*.5){
6212 point=start-model->facenormals[j]*distance;
6213 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;
6214 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,
6215 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6216 p1->x, p1->y, p1->z, radius/2);
6217 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,
6218 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6219 p1->x, p1->y, p1->z, radius/2);
6220 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,
6221 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6222 p1->x, p1->y, p1->z, radius/2);
6224 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6225 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6227 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6228 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6230 *p1+=model->facenormals[j]*(distance-radius*.5);
6233 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6237 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6239 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6241 return firstintersecting;