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 GLubyte texturearray[512*512*3];
71 extern XYZ envsound[30];
72 extern float envsoundvol[30];
73 extern float envsoundlife[30];
74 extern int numenvsounds;
75 extern int tutoriallevel;
76 extern float smoketex;
77 extern int tutorialstage;
78 extern bool reversaltrain;
79 extern bool canattack;
81 extern float damagedealt;
83 extern float hostiletime;
85 extern int indialogue;
87 extern bool gamestarted;
89 void Person::CheckKick(){
93 float damagemult=1*power;
94 if(creature==wolftype)damagemult=2.5*power;
98 if(targetanimation==rabbitkickanim&&victim&&victim!=this&¤tframe>=2&¤tanimation==rabbitkickanim){
99 if(findDistancefast(&coords,&victim->coords)<1.2){
100 if(!victim->skeleton.free){
102 Normalise(&relative);
103 relative=coords+relative*1;
104 if(animation[victim->targetanimation].height!=lowheight){
108 emit_sound_at(heavyimpactsound, victim->coords);
112 Normalise(&relative);
113 for(i=0;i<victim->skeleton.num_joints;i++){
114 victim->skeleton.joints[i].velocity+=relative*120*damagemult;
117 victim->DoDamage(100*damagemult/victim->protectionhigh);
118 if(id==0)camerashake+=.4;
122 targetanimation=backflipanim;
127 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
129 award_bonus(id, cannon);
131 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;
151 void Person::CatchFire(){
152 XYZ flatfacing,flatvelocity;
154 for(int i=0;i<10;i++){
155 howmany=abs(Random()%(skeleton.num_joints));
156 if(!skeleton.free)flatvelocity=velocity;
157 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity;
158 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
159 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
160 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, 2, 1);
165 emit_sound_at(firestartsound, coords);
167 emit_stream_at(stream_firesound, coords);
174 int Person::getIdle(){
175 if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
176 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)){
177 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
178 if(creature==rabbittype)return fightidleanim;
179 if(creature==wolftype)return wolfidle;
181 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
182 if(weapons.type[weaponids[weaponactive]]==knife)return knifefightidleanim;
183 if(weapons.type[weaponids[weaponactive]]==sword&&victim->weaponactive!=-1)return swordfightidlebothanim;
184 if(weapons.type[weaponids[weaponactive]]==sword)return swordfightidleanim;
185 if(weapons.type[weaponids[weaponactive]]==staff)return swordfightidleanim;
187 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
189 if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
190 if(howactive==typesitting)return sitanim;
191 if(howactive==typesittingwall)return sitwallanim;
192 if(howactive==typesleeping)return sleepanim;
193 if(howactive==typedead1)return dead1anim;
194 if(howactive==typedead2)return dead2anim;
195 if(howactive==typedead3)return dead3anim;
196 if(howactive==typedead4)return dead4anim;
197 if(creature==rabbittype)return bounceidleanim;
198 if(creature==wolftype)return wolfidle;
202 int Person::getCrouch(){
203 if(creature==rabbittype)return crouchanim;
204 if(creature==wolftype)return wolfcrouchanim;
208 int Person::getRun(){
209 if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
210 if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
212 if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
213 if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
217 int Person::getStop(){
218 if(creature==rabbittype)return stopanim;
219 if(creature==wolftype)return wolfstopanim;
223 int Person::getLanding(){
224 if(creature==rabbittype)return landanim;
225 if(creature==wolftype)return wolflandanim;
229 int Person::getLandhard(){
230 if(creature==rabbittype)return landhardanim;
231 if(creature==wolftype)return wolflandhardanim;
236 SolidHitBonus(int playerid)
238 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
239 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
241 award_bonus(playerid, solidhit);
244 void Person::DoBlood(float howmuch,int which){
245 static int bleedxint,bleedyint;
247 //if(howmuch&&id==0)blooddimamount=1;
248 if(bloodtoggle&&tutoriallevel!=1){
249 if(bleeding<=0&&spurt){
251 for(int i=0;i<3;i++){
255 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
258 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
260 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
261 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
263 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
264 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
267 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);
268 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);
272 for(int i=0;i<3;i++){
276 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
277 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
280 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
281 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
285 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
287 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);
289 Sprite::setLastSpriteSpecial(3);
294 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
297 int texdetailint=realtexdetail;
298 if(creature==rabbittype)
299 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){
300 bleedxint=abs(Random()%512);
301 bleedyint=abs(Random()%512);
303 if(creature==wolftype)
304 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){
305 bleedxint=abs(Random()%512);
306 bleedyint=abs(Random()%512);
310 bleedy/=realtexdetail;
311 bleedx/=realtexdetail;
312 direction=abs(Random()%2)*2-1;
316 if(bleeding>2)bleeding=2;
319 void Person::DoBloodBig(float howmuch,int which){
320 static int bleedxint,bleedyint,i,j;
322 if(howmuch&&id==0)blooddimamount=1;
324 if(tutoriallevel!=1||id==0)
325 if(aitype!=playercontrolled&&howmuch>0){
328 if(creature==wolftype){
329 int i=abs(Random()%2);
330 if(i==0)whichsound=snarlsound;
331 if(i==1)whichsound=snarl2sound;
332 envsound[numenvsounds]=coords;
333 envsoundvol[numenvsounds]=16;
334 envsoundlife[numenvsounds]=.4;
337 if(creature==rabbittype){
338 int i=abs(Random()%2);
339 if(i==0)whichsound=rabbitpainsound;
340 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
341 envsound[numenvsounds]=coords;
342 envsoundvol[numenvsounds]=16;
343 envsoundlife[numenvsounds]=.4;
345 //if(i==2)whichsound=rabbitpain2sound;
349 emit_sound_at(whichsound, coords);
352 if(id==0&&howmuch>0){
360 if(bloodtoggle&&decals&&tutoriallevel!=1){
361 if(bleeding<=0&&spurt){
363 for(int i=0;i<3;i++){
367 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
370 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
372 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
373 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
375 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
376 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
379 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);
380 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);
384 int offsetx=0,offsety=0;
387 offsetx=abs(Random()%60);
389 if(which==190||which==185){
391 offsetx=abs(Random()%100)-20;
401 if(which==220||which==215){
402 //offsety=Random()%20;
404 //offsetx=abs(Random()%80);
413 if(creature==rabbittype)
416 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
417 if(i<startx)startx=i;
418 if(j<starty)starty=j;
424 if(creature==wolftype)
427 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
428 if(i<startx)startx=i;
429 if(j<starty)starty=j;
441 if(startx<0)startx=0;
442 if(starty<0)starty=0;
443 if(endx>512-1)endx=512-1;
444 if(endy>512-1)endy=512-1;
445 if(endx<startx)endx=startx;
446 if(endy<starty)endy=starty;
448 startx/=realtexdetail;
449 starty/=realtexdetail;
453 int texdetailint=realtexdetail;
455 if(creature==rabbittype)
456 for(i=startx;i<endx;i++){
457 for(j=starty;j<endy;j++){
458 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){
459 color=Random()%85+170;
460 where=i*skeleton.skinsize*3+j*3;
461 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
462 skeleton.skinText[where+1]=0;
463 skeleton.skinText[where+2]=0;
467 if(creature==wolftype)
468 for(i=startx;i<endx;i++){
469 for(j=starty;j<endy;j++){
470 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){
471 color=Random()%85+170;
472 where=i*skeleton.skinsize*3+j*3;
473 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
474 skeleton.skinText[where+1]=0;
475 skeleton.skinText[where+2]=0;
479 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
480 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
481 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
485 if(creature==rabbittype)
486 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){
487 bleedxint=abs(Random()%512);
488 bleedyint=abs(Random()%512);
490 if(creature==wolftype)
491 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){
492 bleedxint=abs(Random()%512);
493 bleedyint=abs(Random()%512);
495 bleedy=bleedxint+offsetx;
496 bleedx=bleedyint+offsety;
497 bleedy/=realtexdetail;
498 bleedx/=realtexdetail;
499 if(bleedx<0)bleedx=0;
500 if(bleedy<0)bleedy=0;
501 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
502 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
503 direction=abs(Random()%2)*2-1;
506 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
507 deathbleeding+=bleeding;
508 bloodloss+=bleeding*3;
510 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
511 if(abs(Random()%2)==0){aitype=gethelptype;
514 else aitype=attacktypecutoff;
517 if(bleeding>2)bleeding=2;
520 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
521 static int bleedxint,bleedyint,i,j;
523 static XYZ startpoint,endpoint,colpoint,movepoint;
524 static float rotationpoint;
526 static XYZ p1,p2,p3,p0;
530 float coordsx,coordsy;
533 if(bloodtoggle&&decals&&tutoriallevel!=1){
535 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
543 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
546 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
547 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
548 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
550 CrossProduct(p2-p1,p3-p1,&N);
551 CrossProduct(p0-p1,p3-p1,&temp);
552 s = dotproduct(&temp,&N)/findLength(&N);
553 CrossProduct(p2-p1,p1-p0,&temp);
554 t = dotproduct(&temp,&N)/findLength(&N);
557 bary.x=findDistancefast(&p0,&p1);
558 bary.y=findDistancefast(&p0,&p2);
559 bary.z=findDistancefast(&p0,&p3);
561 total=bary.x+bary.y+bary.z;
570 total=bary.x+bary.y+bary.z;
576 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
577 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
578 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
579 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
580 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
581 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
582 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;
583 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;
585 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
586 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
588 if(bleeding<=0&&spurt){
590 for(int i=0;i<3;i++){
594 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
597 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
599 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
600 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
602 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
603 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
606 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);
607 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);
611 int offsetx=0,offsety=0;
614 offsetx=abs(Random()%120);
616 if(which==220||which==215){
618 offsetx=abs(Random()%80);
621 offsetx=(1+coordsy)*512-291;
622 offsety=coordsx*512-437;
629 if(creature==rabbittype)
632 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
633 if(i<startx)startx=i;
634 if(j<starty)starty=j;
640 if(creature==wolftype)
643 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
644 if(i<startx)startx=i;
645 if(j<starty)starty=j;
656 if(startx<0)startx=0;
657 if(starty<0)starty=0;
658 if(endx>512-1)endx=512-1;
659 if(endy>512-1)endy=512-1;
660 if(endx<startx)endx=startx;
661 if(endy<starty)endy=starty;
663 startx/=realtexdetail;
664 starty/=realtexdetail;
668 int texdetailint=realtexdetail;
670 if(creature==rabbittype)
671 for(i=startx;i<endx;i++){
672 for(j=starty;j<endy;j++){
673 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){
674 color=Random()%85+170;
675 where=i*skeleton.skinsize*3+j*3;
676 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
677 skeleton.skinText[where+1]=0;
678 skeleton.skinText[where+2]=0;
680 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){
681 color=Random()%85+170;
682 where=i*skeleton.skinsize*3+j*3;
683 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
684 skeleton.skinText[where+1]=0;
685 skeleton.skinText[where+2]=0;
689 if(creature==wolftype)
690 for(i=startx;i<endx;i++){
691 for(j=starty;j<endy;j++){
692 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){
693 color=Random()%85+170;
694 where=i*skeleton.skinsize*3+j*3;
695 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
696 skeleton.skinText[where+1]=0;
697 skeleton.skinText[where+2]=0;
699 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){
700 color=Random()%85+170;
701 where=i*skeleton.skinsize*3+j*3;
702 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
703 skeleton.skinText[where+1]=0;
704 skeleton.skinText[where+2]=0;
708 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
709 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
710 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
712 bleedy=(1+coordsy)*512;
714 bleedy/=realtexdetail;
715 bleedx/=realtexdetail;
716 if(bleedx<0)bleedx=0;
717 if(bleedy<0)bleedy=0;
718 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
719 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
720 direction=abs(Random()%2)*2-1;
722 if(whichtri==-1)return 0;
724 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
725 deathbleeding+=bleeding;
726 bloodloss+=bleeding*3;
728 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
729 if(abs(Random()%2)==0){aitype=gethelptype;
732 else aitype=attacktypecutoff;
735 if(bleeding>2)bleeding=2;
740 void Person::DoMipmaps(int howmanylevels,float startx, float endx, float starty, float endy){
743 static int bytesPerPixel=3;
744 static int newsize,totalsize,rowsize,bigstep,smallstep,sum;
745 static int newstartx,newstarty,newendx,newendy;
746 static int newnewstartx,newnewstarty,newnewendx,newnewendy;
748 static float sizemult;
750 for(i=0;i<skeleton.skinsize*skeleton.skinsize*bytesPerPixel;i++){
751 texture[i]=skeleton.skinText[i];
754 if((!osx||howmanylevels)){
756 if(startx<0)startx=0;
757 if(starty<0)starty=0;
758 if(endx>skeleton.skinsize-1)endx=skeleton.skinsize-1;
759 if(endy>skeleton.skinsize-1)endy=skeleton.skinsize-1;
760 if((endx>startx&&endy>starty)||howmanylevels){
767 for(i=startx;i<endx;i++){
768 for(j=starty;j<endy;j++){
769 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+0]=skeleton.skinText[i*skeleton.skinsize*3+j*3+0];
770 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+1]=skeleton.skinText[i*skeleton.skinsize*3+j*3+1];
771 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+2]=skeleton.skinText[i*skeleton.skinsize*3+j*3+2];
775 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
778 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
779 glTexSubImage2D(GL_TEXTURE_2D,0,starty,startx,endy-starty,endx-startx,GL_RGB,GL_UNSIGNED_BYTE,texturearray);
780 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
783 newsize=skeleton.skinsize;
786 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, skeleton.skinsize, skeleton.skinsize, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0] );
788 /*for(j=1;j<=howmanylevels;j++){
789 if(j==1)texpointer=&skeleton.skinText[0];
790 else texpointer=&texture[0];
792 totalsize=int( newsize*newsize*bytesPerPixel);
793 rowsize=int( newsize*bytesPerPixel );
794 bigstep=bytesPerPixel*newsize*2;
795 smallstep=bytesPerPixel*2;
801 glTexSubImage2D(GL_TEXTURE_2D,j,0,0,newsize/2,newsize/2,GL_RGB,GL_UNSIGNED_BYTE,texture);
808 void Person::Reverse(){
809 if(victim->aitype==playercontrolled||hostiletime>1)
810 if(victim->targetanimation!=jumpupanim&&victim->targetanimation!=jumpdownanim&&((tutoriallevel!=1||cananger)&&hostile)){
811 if(normaldotproduct(victim->facing,victim->coords-coords)>0&&!(victim->id==0&&difficulty<2)&&(creature!=wolftype||victim->creature==wolftype))return;
812 if(victim->aitype!=playercontrolled&&staggerdelay>0)return;
813 if(targetanimation==sweepanim){
814 targetanimation=sweepreversedanim;
815 currentanimation=sweepreversedanim;
816 victim->currentanimation=sweepreversalanim;
817 victim->targetanimation=sweepreversalanim;
819 if(targetanimation==spinkickanim){
820 targetanimation=spinkickreversedanim;
821 currentanimation=spinkickreversedanim;
822 victim->currentanimation=spinkickreversalanim;
823 victim->targetanimation=spinkickreversalanim;
825 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
826 if(targetanimation==rabbittacklinganim){
829 victim->currentframe=6;
830 victim->targetframe=7;
832 targetanimation=upunchreversedanim;
833 currentanimation=upunchreversedanim;
834 victim->currentanimation=upunchreversalanim;
835 victim->targetanimation=upunchreversalanim;
837 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
838 if(victim->weaponactive!=-1){
839 victim->throwtogglekeydown=1;
840 weapons.owner[victim->weaponids[0]]=-1;
841 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
842 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
843 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
844 weapons.missed[victim->weaponids[0]]=1;
845 weapons.freetime[victim->weaponids[0]]=0;
846 weapons.firstfree[victim->weaponids[0]]=1;
847 weapons.physics[victim->weaponids[0]]=1;
848 victim->num_weapons--;
849 if(victim->num_weapons){
850 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
851 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
854 victim->weaponactive=-1;
855 for(int j=0;j<numplayers;j++){
856 player[j].wentforweapon=0;
860 targetanimation=staffhitreversedanim;
861 currentanimation=staffhitreversedanim;
862 victim->currentanimation=staffhitreversalanim;
863 victim->targetanimation=staffhitreversalanim;
865 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
866 if(victim->weaponactive!=-1){
867 victim->throwtogglekeydown=1;
868 weapons.owner[victim->weaponids[0]]=-1;
869 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
870 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
871 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
872 weapons.missed[victim->weaponids[0]]=1;
873 weapons.freetime[victim->weaponids[0]]=0;
874 weapons.firstfree[victim->weaponids[0]]=1;
875 weapons.physics[victim->weaponids[0]]=1;
876 victim->num_weapons--;
877 if(victim->num_weapons){
878 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
879 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
882 victim->weaponactive=-1;
883 for(int j=0;j<numplayers;j++){
884 player[j].wentforweapon=0;
887 targetanimation=staffspinhitreversedanim;
888 currentanimation=staffspinhitreversedanim;
889 victim->currentanimation=staffspinhitreversalanim;
890 victim->targetanimation=staffspinhitreversalanim;
892 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
893 if(victim->weaponactive!=-1){
894 victim->throwtogglekeydown=1;
895 weapons.owner[victim->weaponids[0]]=-1;
896 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
897 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
898 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
899 weapons.missed[victim->weaponids[0]]=1;
900 weapons.freetime[victim->weaponids[0]]=0;
901 weapons.firstfree[victim->weaponids[0]]=1;
902 weapons.physics[victim->weaponids[0]]=1;
903 victim->num_weapons--;
904 if(victim->num_weapons){
905 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
906 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
909 victim->weaponactive=-1;
910 for(int j=0;j<numplayers;j++){
911 player[j].wentforweapon=0;
914 targetanimation=swordslashreversedanim;
915 currentanimation=swordslashreversedanim;
916 victim->currentanimation=swordslashreversalanim;
917 victim->targetanimation=swordslashreversalanim;
919 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
920 if(victim->weaponactive!=-1){
921 victim->throwtogglekeydown=1;
922 weapons.owner[victim->weaponids[0]]=-1;
923 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
924 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
925 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
926 weapons.missed[victim->weaponids[0]]=1;
927 weapons.freetime[victim->weaponids[0]]=0;
928 weapons.firstfree[victim->weaponids[0]]=1;
929 weapons.physics[victim->weaponids[0]]=1;
930 victim->num_weapons--;
931 if(victim->num_weapons){
932 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
933 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
936 victim->weaponactive=-1;
937 for(int j=0;j<numplayers;j++){
938 player[j].wentforweapon=0;
941 targetanimation=knifeslashreversedanim;
942 currentanimation=knifeslashreversedanim;
943 victim->currentanimation=knifeslashreversalanim;
944 victim->targetanimation=knifeslashreversalanim;
946 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
947 victim->targettilt2=targettilt2;
948 victim->currentframe=currentframe;
949 victim->targetframe=targetframe;
950 victim->target=target;
952 victim->oldcoords=victim->coords;
953 victim->coords=coords;
954 victim->targetrotation=targetrotation;
955 victim->rotation=targetrotation;
958 if(targetanimation==winduppunchanim){
959 targetanimation=winduppunchblockedanim;
960 victim->targetanimation=blockhighleftanim;
961 victim->targetframe=1;
964 victim->targetrotation=targetrotation+180;
966 if(targetanimation==wolfslapanim){
967 targetanimation=winduppunchblockedanim;
968 victim->targetanimation=blockhighleftanim;
969 victim->targetframe=1;
972 victim->targetrotation=targetrotation+180;
974 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
975 targetanimation=swordslashparriedanim;
977 victim->parriedrecently=0;
978 victim->targetanimation=swordslashparryanim;
979 victim->targetframe=1;
982 victim->targetrotation=targetrotation+180;
984 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
985 if(victim->weaponactive!=-1){
986 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
987 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
988 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
989 emit_sound_at(swordstaffsound, victim->coords);
992 emit_sound_at(metalhitsound, victim->coords);
996 victim->Puff(righthand);
998 victim->targetframe=0;
999 victim->targetanimation=staggerbackhighanim;
1000 victim->targetrotation=targetrotation+180;
1002 weapons.owner[victim->weaponids[0]]=-1;
1003 aim=DoRotation(facing,0,90,0)*21;
1005 weapons.velocity[victim->weaponids[0]]=aim*-.2;
1006 weapons.tipvelocity[victim->weaponids[0]]=aim;
1007 weapons.missed[victim->weaponids[0]]=1;
1008 weapons.hitsomething[victim->weaponids[0]]=0;
1009 weapons.freetime[victim->weaponids[0]]=0;
1010 weapons.firstfree[victim->weaponids[0]]=1;
1011 weapons.physics[victim->weaponids[0]]=1;
1012 victim->num_weapons--;
1013 if(victim->num_weapons){
1014 victim->weaponids[0]=victim->weaponids[num_weapons];
1015 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1017 victim->weaponactive=-1;
1018 for(int i=0;i<numplayers;i++){
1019 player[i].wentforweapon=0;
1028 if(abs(Random()%20)==0){
1029 if(weaponactive!=-1){
1030 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1031 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1032 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1034 emit_sound_at(swordstaffsound, coords);
1037 emit_sound_at(metalhitsound, coords);
1045 targetanimation=staggerbackhighanim;
1046 targetrotation=targetrotation+180;
1048 weapons.owner[weaponids[0]]=-1;
1049 aim=DoRotation(facing,0,90,0)*21;
1051 weapons.velocity[weaponids[0]]=aim*-.2;
1052 weapons.tipvelocity[weaponids[0]]=aim;
1053 weapons.hitsomething[weaponids[0]]=0;
1054 weapons.missed[weaponids[0]]=1;
1055 weapons.freetime[weaponids[0]]=0;
1056 weapons.firstfree[weaponids[0]]=1;
1057 weapons.physics[weaponids[0]]=1;
1060 weaponids[0]=weaponids[num_weapons];
1061 if(weaponstuck==num_weapons)weaponstuck=0;
1064 for(int i=0;i<numplayers;i++){
1065 player[i].wentforweapon=0;
1072 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1073 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1074 //victim->targetanimation=sweepanim;
1075 victim->targetanimation=dodgebackanim;
1076 victim->targetframe=0;
1078 //victim->velocity=0;
1081 rotatetarget=coords-victim->coords;
1082 Normalise(&rotatetarget);
1083 victim->targetrotation=-asin(0-rotatetarget.x);
1084 victim->targetrotation*=360/6.28;
1085 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1087 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1089 victim->lastattack3=victim->lastattack2;
1090 victim->lastattack2=victim->lastattack;
1091 victim->lastattack=victim->targetanimation;
1095 victim->targetanimation=sweepanim;
1096 victim->targetframe=0;
1100 rotatetarget=coords-victim->coords;
1101 Normalise(&rotatetarget);
1102 victim->targetrotation=-asin(0-rotatetarget.x);
1103 victim->targetrotation*=360/6.28;
1104 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1106 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1108 victim->lastattack3=victim->lastattack2;
1109 victim->lastattack2=victim->lastattack;
1110 victim->lastattack=victim->targetanimation;
1117 if(aitype!=playercontrolled)feint=0;
1118 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1119 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1120 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1122 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1126 void Person::DoDamage(float howmuch){
1127 if(tutoriallevel!=1)damage+=howmuch/power;
1128 if(id!=0)damagedealt+=howmuch/power;
1129 if(id==0)damagetaken+=howmuch/power;
1131 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1132 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1133 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1134 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1135 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1137 if(id==0)camerashake+=howmuch/100;
1138 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1139 if(blackout>1)blackout=1;
1141 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1142 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1143 if(abs(Random()%2)==0){aitype=gethelptype;
1146 else aitype=attacktypecutoff;
1150 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1153 for(int i=0;i<skeleton.num_joints; i++){
1154 if(!skeleton.free)flatvelocity2=velocity;
1155 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1156 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1157 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1158 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1159 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1160 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1161 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1162 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1163 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1166 emit_sound_at(splattersound, coords);
1175 if(!dead&&creature==wolftype){
1176 award_bonus(0, Wolfbonus);
1182 if(tutoriallevel!=1||id==0)
1183 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1186 if(creature==wolftype){
1187 int i=abs(Random()%2);
1188 if(i==0)whichsound=snarlsound;
1189 if(i==1)whichsound=snarl2sound;
1190 envsound[numenvsounds]=coords;
1191 envsoundvol[numenvsounds]=16;
1192 envsoundlife[numenvsounds]=.4;
1195 if(creature==rabbittype){
1196 int i=abs(Random()%2);
1197 if(i==0)whichsound=rabbitpainsound;
1198 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1199 envsound[numenvsounds]=coords;
1200 envsoundvol[numenvsounds]=16;
1201 envsoundlife[numenvsounds]=.4;
1203 //if(i==2)whichsound=rabbitpain2sound;
1207 emit_sound_at(whichsound, coords);
1212 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1213 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1216 void Person::DoHead(){
1217 static XYZ rotatearound;
1219 static float lookspeed=500;
1221 if(!freeze&&!winfreeze){
1224 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1225 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1227 while(targetheadrotation>180)targetheadrotation-=360;
1228 while(targetheadrotation<-180)targetheadrotation+=360;
1230 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1231 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1232 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1233 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1235 if(targetheadrotation2>120)targetheadrotation2=120;
1236 if(targetheadrotation2<-120)targetheadrotation2=-120;
1237 if(targetheadrotation>120)targetheadrotation=120;
1238 if(targetheadrotation<-120)targetheadrotation=-120;
1240 if(!isIdle())targetheadrotation2=0;
1242 if(targetheadrotation>80)targetheadrotation=80;
1243 if(targetheadrotation<-80)targetheadrotation=-80;
1244 if(targetheadrotation2>50)targetheadrotation2=50;
1245 if(targetheadrotation2<-50)targetheadrotation2=-50;
1248 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1249 else if(headrotation>targetheadrotation){
1250 headrotation-=multiplier*lookspeed;
1252 else if(headrotation<targetheadrotation){
1253 headrotation+=multiplier*lookspeed;
1256 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1257 else if(headrotation2>targetheadrotation2){
1258 headrotation2-=multiplier*lookspeed/2;
1260 else if(headrotation2<targetheadrotation2){
1261 headrotation2+=multiplier*lookspeed/2;
1264 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1265 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1269 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1270 facing=DoRotation(facing,headrotation2*.4,0,0);
1271 facing=DoRotation(facing,0,headrotation*.4,0);
1274 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1275 facing=DoRotation(facing,headrotation2*.8,0,0);
1276 facing=DoRotation(facing,0,headrotation*.8,0);
1279 if(targetanimation==walkanim){
1280 facing=DoRotation(facing,headrotation2*.6,0,0);
1281 facing=DoRotation(facing,0,headrotation*.6,0);
1284 skeleton.specialforward[0]=facing;
1285 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1287 for(i=0;i<skeleton.num_muscles;i++){
1288 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1290 skeleton.FindRotationMuscle(i,targetanimation);
1296 void Person::RagDoll(bool checkcollision){
1301 if(id==0)numfalls++;
1302 if(id==0&&isFlip())numflipfail++;
1308 facing=DoRotation(facing,0,rotation,0);
1310 skeleton.freetime=0;
1312 skeleton.longdead=0;
1318 skeleton.freefall=1;
1320 if(!isnormal(velocity.x))velocity.x=0;
1321 if(!isnormal(velocity.y))velocity.y=0;
1322 if(!isnormal(velocity.z))velocity.z=0;
1323 if(!isnormal(rotation))rotation=0;
1324 if(!isnormal(coords.x))coords=0;
1325 if(!isnormal(tilt))tilt=0;
1326 if(!isnormal(tilt2))tilt2=0;
1328 for(i=0;i<skeleton.num_joints;i++){
1329 skeleton.joints[i].delay=0;
1330 skeleton.joints[i].locked=0;
1331 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1332 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1333 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1334 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1335 skeleton.joints[i].position.y+=.1;
1336 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1337 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1340 for(i=0;i<skeleton.num_joints;i++){
1341 skeleton.joints[i].velocity=0;
1342 skeleton.joints[i].velchange=0;
1344 skeleton.DoConstraints(&coords,&scale);
1345 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1347 skeleton.DoConstraints(&coords,&scale);
1348 skeleton.DoConstraints(&coords,&scale);
1349 skeleton.DoConstraints(&coords,&scale);
1350 skeleton.DoConstraints(&coords,&scale);
1353 speed=animation[targetanimation].speed[targetframe]*2;
1354 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1355 speed=animation[currentanimation].speed[currentframe]*2;
1357 if(transspeed)speed=transspeed*2;
1361 for(i=0;i<skeleton.num_joints;i++){
1362 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);
1363 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1364 change.x=(float)(Random()%100)/100;
1365 change.y=(float)(Random()%100)/100;
1366 change.z=(float)(Random()%100)/100;
1367 skeleton.joints[i].velocity+=change;
1368 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1370 change.x=(float)(Random()%100)/100;
1371 change.y=(float)(Random()%100)/100;
1372 change.z=(float)(Random()%100)/100;
1373 skeleton.joints[i].velchange+=change;
1374 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1384 for(j=0;j<skeleton.num_joints;j++){
1385 average+=skeleton.joints[j].position;
1389 coords+=average*scale;
1390 for(j=0;j<skeleton.num_joints;j++){
1391 skeleton.joints[j].position-=average;
1394 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1395 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1396 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1397 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1398 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1401 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1402 coords.x=lowpoint.x;
1403 coords.z=lowpoint.z;
1412 for(i=0;i<skeleton.num_joints;i++){
1413 velocity+=skeleton.joints[i].velocity*scale;
1415 velocity/=skeleton.num_joints;
1418 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1419 weapons.owner[weaponids[0]]=-1;
1420 weapons.hitsomething[weaponids[0]]=0;
1421 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1422 weapons.velocity[weaponids[0]].x+=.01;
1423 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1424 weapons.missed[weaponids[0]]=1;
1425 weapons.freetime[weaponids[0]]=0;
1426 weapons.firstfree[weaponids[0]]=1;
1427 weapons.physics[weaponids[0]]=1;
1430 weaponids[0]=weaponids[num_weapons];
1431 if(weaponstuck==num_weapons)weaponstuck=0;
1434 for(i=0;i<numplayers;i++){
1435 player[i].wentforweapon=0;
1440 targetanimation=bounceidleanim;
1441 currentanimation=bounceidleanim;
1449 void Person::FootLand(int which, float opacity){
1450 static XYZ terrainlight;
1451 static XYZ footvel,footpoint;
1452 if(opacity>=1||skiddelay<=0)
1456 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1457 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1458 //footpoint.y=coords.y;
1459 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1461 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1463 if(footvel.y<.8)footvel.y=.8;
1464 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1465 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1466 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1467 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1468 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1469 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1471 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1473 if(footvel.y<.8)footvel.y=.8;
1474 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1475 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1476 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1477 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1478 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);
1480 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1482 if(footvel.y<.8)footvel.y=.8;
1483 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1484 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1485 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1486 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1487 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);
1488 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1490 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1493 if(footvel.y<.8)footvel.y=.8;
1494 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1495 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1496 //footpoint.y=coords.y;
1497 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1501 void Person::Puff(int whichlabel){
1502 static XYZ footvel,footpoint;
1505 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1506 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1510 void Person::DoAnimations(){
1513 static float oldtarget;
1515 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1517 if(targetanimation==tempanim||currentanimation==tempanim){
1518 animation[tempanim]=tempanimation;
1520 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1531 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1532 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1534 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1535 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1537 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1542 targfacing=DoRotation(targfacing,0,targetrotation,0);
1544 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1545 else targetanimation=backflipanim;
1546 crouchtogglekeydown=1;
1550 if(id==0)numflipped++;
1553 if(animation[targetanimation].attack!=reversed)feint=0;
1554 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1555 crouchtogglekeydown=0;
1556 if(aitype==playercontrolled)feint=0;
1560 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1561 if(!isFlip())crouchtogglekeydown=1;
1565 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1566 if(detail)normalsupdatedelay=0;
1570 if(targetanimation==rollanim&&targetframe==3&&onfire){
1572 emit_sound_at(fireendsound, coords);
1573 OPENAL_SetPaused(channels[stream_firesound], true);
1577 if(targetanimation==rabbittacklinganim&&targetframe==1){
1578 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1579 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1580 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1581 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1582 else victim->targetanimation=rabbittackledfrontanim;
1583 victim->targetframe=2;
1585 victim->rotation=rotation;
1586 victim->targetrotation=rotation;
1587 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1588 //victim->DoDamage(30);
1589 if(creature==wolftype){
1591 emit_sound_at(clawslicesound, victim->coords);
1593 victim->DoBloodBig(1/victim->armorhead,210);
1595 award_bonus(id, TackleBonus,
1596 victim->aitype == gethelptype ? 50 : 0);
1600 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1601 if(weapons.type[weaponids[0]]==knife){
1602 if(weaponactive==-1)weaponactive=0;
1603 else if(weaponactive==0)weaponactive=-1;
1605 if(weaponactive==-1){
1606 emit_sound_at(knifesheathesound, coords);
1608 if(weaponactive!=-1){
1609 emit_sound_at(knifedrawsound, coords, 128);
1612 drawtogglekeydown=1;
1615 if(tutoriallevel!=1||id==0)
1616 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1619 if(terrain.getOpacity(coords.x,coords.z)<.2){
1620 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1621 else whichsound=footstepsound2;
1622 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1623 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1624 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1630 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1631 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1632 else whichsound=footstepsound4;
1636 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1637 else whichsound=footstepsound4;
1639 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1640 if(animation[targetanimation].attack!=neutral){
1642 if(i==0)whichsound=lowwhooshsound;
1643 if(i==1)whichsound=midwhooshsound;
1644 if(i==2)whichsound=highwhooshsound;
1646 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1648 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1649 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1651 emit_sound_at(whichsound, coords, 256.);
1654 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1655 envsound[numenvsounds]=coords;
1656 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1657 else envsoundvol[numenvsounds]=6;
1658 envsoundlife[numenvsounds]=.4;
1662 if(animation[targetanimation].label[targetframe]==3){
1664 emit_sound_at(whichsound, coords, 128.);
1669 if(tutoriallevel!=1||id==0)
1671 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1672 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1674 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1675 if(animation[targetanimation].attack!=neutral){
1677 if(creature==rabbittype){
1678 if(i==0)whichsound=rabbitattacksound;
1679 if(i==1)whichsound=rabbitattack2sound;
1680 if(i==2)whichsound=rabbitattack3sound;
1681 if(i==3)whichsound=rabbitattack4sound;
1683 if(creature==wolftype){
1684 if(i==0)whichsound=barksound;
1685 if(i==1)whichsound=bark2sound;
1686 if(i==2)whichsound=bark3sound;
1687 if(i==3)whichsound=barkgrowlsound;
1691 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1693 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1694 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1697 emit_sound_at(whichsound, coords);
1703 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1709 currentoffset=targetoffset;
1710 targetframe=currentframe;
1711 currentanimation=targetanimation;
1714 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1715 for(i=0;i<weapons.numweapons;i++){
1716 if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1717 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1718 if(findDistancefast(&coords,&weapons.position[i])>=1){
1719 if(weapons.type[i]!=staff){
1720 emit_sound_at(knifedrawsound, coords, 128.);
1724 weapons.owner[i]=id;
1726 weaponids[num_weapons]=weaponids[0];
1735 static bool willwork;
1736 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1737 for(i=0;i<weapons.numweapons;i++){
1739 if(weapons.owner[i]!=-1)
1740 if(player[weapons.owner[i]].weaponstuck!=-1)
1741 if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
1742 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
1743 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))
1744 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
1745 if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
1747 if(weapons.owner[i]!=-1)
1748 if(victim->weaponstuck!=-1){
1749 if(victim->weaponids[victim->weaponstuck]==i){
1754 if(weapons.type[i]!=staff){
1755 emit_sound_at(knifedrawsound, coords, 128.);
1759 emit_sound_at(fleshstabremovesound, coords, 128.);
1762 if(weapons.owner[i]!=-1){
1764 victim=&player[weapons.owner[i]];
1765 if(victim->num_weapons==1)victim->num_weapons=0;
1766 else victim->num_weapons=1;
1768 //victim->weaponactive=-1;
1769 victim->skeleton.longdead=0;
1770 victim->skeleton.free=1;
1771 victim->skeleton.broken=0;
1773 for(int j=0;j<victim->skeleton.num_joints;j++){
1774 victim->skeleton.joints[j].velchange=0;
1775 victim->skeleton.joints[j].locked=0;
1781 Normalise(&relative);
1782 XYZ footvel,footpoint;
1784 footpoint=weapons.position[i];
1785 if(victim->weaponstuck!=-1){
1786 if(victim->weaponids[victim->weaponstuck]==i){
1787 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1788 weapons.bloody[i]=2;
1789 weapons.blooddrip[i]=5;
1790 victim->weaponstuck=-1;
1793 if(victim->num_weapons>0){
1794 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1795 if(victim->weaponids[0]==i)
1796 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1799 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1800 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1801 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1802 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1804 weapons.owner[i]=id;
1806 weaponids[num_weapons]=weaponids[0];
1815 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1816 if(weaponactive==-1)weaponactive=0;
1817 else if(weaponactive==0){
1821 buffer=weaponids[0];
1822 weaponids[0]=weaponids[1];
1823 weaponids[1]=buffer;
1826 if(weaponactive==-1){
1827 emit_sound_at(knifesheathesound, coords, 128.);
1829 if(weaponactive!=-1){
1830 emit_sound_at(knifedrawsound, coords, 128.);
1835 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1836 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1837 Normalise(&rotatetarget);
1838 targetrotation=-asin(0-rotatetarget.x);
1839 targetrotation*=360/6.28;
1840 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1842 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1843 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1848 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1850 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;
1852 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1853 targetanimation=rabbittackleanim;
1855 emit_sound_at(jumpsound, coords);
1864 Normalise(&targetloc);
1866 for(i=0;i<numplayers;i++){
1868 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1869 closestdist=findDistancefast(&targetloc,&player[i].coords);
1874 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1876 victim=&player[closestid];
1877 coords=victim->coords;
1878 currentanimation=rabbittacklinganim;
1879 targetanimation=rabbittacklinganim;
1883 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1884 rotatetarget=coords-victim->coords;
1885 Normalise(&rotatetarget);
1886 targetrotation=-asin(0-rotatetarget.x);
1887 targetrotation*=360/6.28;
1888 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1890 if(targetanimation!=rabbitrunninganim){
1891 emit_sound_at(jumpsound, coords, 128.);
1897 float damagemult=1*power;
1898 if(creature==wolftype)damagemult=2.5*power;
1899 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1900 //if(onfire)damagemult=3;
1901 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1902 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1903 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1905 if(id==0)camerashake+=.4;
1906 if(Random()%2||creature==wolftype){
1909 if(creature==wolftype)DoBloodBig(0,250);
1911 if(tutoriallevel!=1){
1912 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1914 if(creature==wolftype){
1915 emit_sound_at(clawslicesound, victim->coords, 128.);
1917 victim->DoBloodBig(2/victim->armorhead,175);
1921 relative=victim->coords-coords;
1923 Normalise(&relative);
1924 relative=DoRotation(relative,0,-90,0);
1925 for(i=0;i<victim->skeleton.num_joints;i++){
1926 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1928 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1931 victim->DoDamage(damagemult*100/victim->protectionhead);
1937 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1938 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1940 if(id==0)camerashake+=.4;
1941 if(Random()%2||creature==wolftype){
1943 if(creature==wolftype)DoBloodBig(0,235);
1945 emit_sound_at(whooshhitsound, victim->coords);
1946 if(creature==wolftype){
1947 emit_sound_at(clawslicesound, victim->coords, 128.);
1949 victim->DoBloodBig(2,175);
1953 relative=victim->coords-coords;
1955 Normalise(&relative);
1957 Normalise(&relative);
1958 relative=DoRotation(relative,0,90,0);
1959 for(i=0;i<victim->skeleton.num_joints;i++){
1960 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
1962 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1965 victim->DoDamage(damagemult*50/victim->protectionhead);
1969 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
1970 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1972 if(id==0)camerashake+=.4;
1975 if(tutoriallevel!=1){
1976 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1978 if(creature==wolftype){
1979 emit_sound_at(clawslicesound, victim->coords, 128.);
1981 victim->DoBloodBig(2/victim->armorhead,175);
1987 Normalise(&relative);
1988 relative=DoRotation(relative,0,-90,0);
1989 for(i=0;i<victim->skeleton.num_joints;i++){
1990 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1992 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1995 victim->DoDamage(damagemult*150/victim->protectionhead);
1997 if(victim->damage>victim->damagetolerance)
1998 award_bonus(id, style);
2004 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2005 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2007 if(id==0)camerashake+=.4;
2010 if(tutoriallevel!=1){
2011 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2013 if(creature==wolftype){
2014 emit_sound_at(clawslicesound, victim->coords, 128.);
2016 victim->DoBloodBig(2/victim->armorhead,175);
2022 Normalise(&relative);
2023 relative=DoRotation(relative,0,90,0);
2024 for(i=0;i<victim->skeleton.num_joints;i++){
2025 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2027 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2030 victim->DoDamage(damagemult*150/victim->protectionhead);
2032 if(victim->damage>victim->damagetolerance)
2033 award_bonus(id, style);
2039 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2040 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2042 if(id==0)camerashake+=.4;
2047 emit_sound_at(whooshhitsound, victim->coords);
2050 relative=victim->coords-coords;
2052 Normalise(&relative);
2053 for(i=0;i<victim->skeleton.num_joints;i++){
2054 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2056 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2059 victim->DoDamage(damagemult*50/victim->protectionhead);
2063 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2064 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2066 if(id==0)camerashake+=.2;
2067 emit_sound_at(whooshhitsound, victim->coords, 128.);
2069 victim->skeleton.longdead=0;
2070 victim->skeleton.free=1;
2071 victim->skeleton.broken=0;
2072 victim->skeleton.spinny=1;
2074 for(i=0;i<victim->skeleton.num_joints;i++){
2075 victim->skeleton.joints[i].velchange=0;
2076 victim->skeleton.joints[i].delay=0;
2077 victim->skeleton.joints[i].locked=0;
2078 //victim->skeleton.joints[i].velocity=0;
2084 Normalise(&relative);
2085 for(i=0;i<victim->skeleton.num_joints;i++){
2086 victim->skeleton.joints[i].velocity.y=relative.y*10;
2087 victim->skeleton.joints[i].position.y+=relative.y*.3;
2088 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2089 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2091 victim->Puff(abdomen);
2092 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2096 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2097 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2099 if(id==0)camerashake+=.4;
2100 if(tutoriallevel!=1){
2101 emit_sound_at(heavyimpactsound, coords, 128.);
2104 relative=victim->coords-coords;
2106 Normalise(&relative);
2107 for(i=0;i<victim->skeleton.num_joints;i++){
2108 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2110 victim->Puff(abdomen);
2111 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2115 victim->DoDamage(damagemult*500/victim->protectionhigh);
2116 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2120 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2121 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2123 if(id==0)camerashake+=.4;
2124 if(tutoriallevel!=1){
2125 emit_sound_at(thudsound, coords);
2128 victim->skeleton.longdead=0;
2129 victim->skeleton.free=1;
2130 victim->skeleton.broken=0;
2131 victim->skeleton.spinny=1;
2133 for(i=0;i<victim->skeleton.num_joints;i++){
2134 victim->skeleton.joints[i].velchange=0;
2135 //victim->skeleton.joints[i].delay=0;
2136 victim->skeleton.joints[i].locked=0;
2139 relative=victim->coords-coords;
2140 Normalise(&relative);
2142 Normalise(&relative);
2143 for(i=0;i<victim->skeleton.num_joints;i++){
2144 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2149 victim->Puff(abdomen);
2150 victim->DoDamage(damagemult*20/victim->protectionhigh);
2151 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2153 if(!victim->dead)staggerdelay=1.2;
2159 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2160 //if(id==0)camerashake+=.4;
2163 if(!victim->skeleton.free)hasvictim=0;
2166 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2167 emit_sound_at(knifesheathesound, coords, 128.);
2170 if(victim&&hasvictim){
2171 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2173 XYZ where,startpoint,endpoint,movepoint,colpoint;
2174 float rotationpoint;
2176 if(weapons.type[weaponids[weaponactive]]==knife){
2177 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2178 where-=victim->coords;
2179 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2186 if(weapons.type[weaponids[weaponactive]]==sword){
2187 where=weapons.position[weaponids[weaponactive]];
2188 where-=victim->coords;
2189 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2191 where=weapons.tippoint[weaponids[weaponactive]];
2192 where-=victim->coords;
2193 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2196 if(weapons.type[weaponids[weaponactive]]==staff){
2197 where=weapons.position[weaponids[weaponactive]];
2198 where-=victim->coords;
2199 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2201 where=weapons.tippoint[weaponids[weaponactive]];
2202 where-=victim->coords;
2203 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2208 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2211 if(victim->dead!=2){
2212 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2214 award_bonus(id, FinishedBonus);
2216 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2218 victim->skeleton.longdead=0;
2219 victim->skeleton.free=1;
2220 victim->skeleton.broken=0;
2222 for(i=0;i<victim->skeleton.num_joints;i++){
2223 victim->skeleton.joints[i].velchange=0;
2224 victim->skeleton.joints[i].locked=0;
2225 //victim->skeleton.joints[i].velocity=0;
2227 emit_sound_at(fleshstabsound, coords, 128);
2230 if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2231 weapons.blooddrip[weaponids[weaponactive]]+=5;
2232 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2236 emit_sound_at(knifesheathesound, coords, 128.);
2242 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2244 emit_sound_at(knifedrawsound, coords, 128);
2247 if(victim&&hasvictim){
2248 XYZ footvel,footpoint;
2250 emit_sound_at(fleshstabremovesound, coords, 128.);
2253 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2255 if(weapons.type[weaponids[weaponactive]]==sword){
2256 XYZ where,startpoint,endpoint,movepoint;
2257 float rotationpoint;
2260 where=weapons.position[weaponids[weaponactive]];
2261 where-=victim->coords;
2262 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2264 where=weapons.tippoint[weaponids[weaponactive]];
2265 where-=victim->coords;
2266 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2271 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2272 footpoint+=victim->coords;
2275 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2278 if(weapons.type[weaponids[weaponactive]]==staff){
2279 XYZ where,startpoint,endpoint,movepoint;
2280 float rotationpoint;
2283 where=weapons.position[weaponids[weaponactive]];
2284 where-=victim->coords;
2285 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2287 where=weapons.tippoint[weaponids[weaponactive]];
2288 where-=victim->coords;
2289 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2294 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2295 footpoint+=victim->coords;
2298 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2301 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2303 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2304 victim->skeleton.longdead=0;
2305 victim->skeleton.free=1;
2306 victim->skeleton.broken=0;
2308 for(i=0;i<victim->skeleton.num_joints;i++){
2309 victim->skeleton.joints[i].velchange=0;
2310 victim->skeleton.joints[i].locked=0;
2311 //victim->skeleton.joints[i].velocity=0;
2317 Normalise(&relative);
2318 //victim->Puff(abdomen);
2319 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2321 if(victim->bloodloss<victim->damagetolerance){
2322 victim->bloodloss+=1000;
2326 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2330 if(!hasvictim&&onterrain){
2331 weapons.bloody[weaponids[weaponactive]]=0;
2332 weapons.blooddrip[weaponids[weaponactive]]=0;
2336 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2337 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2339 if(id==0)camerashake+=.4;
2344 if(tutoriallevel!=1){
2345 emit_sound_at(heavyimpactsound, victim->coords, 128);
2350 relative=victim->coords-coords;
2352 Normalise(&relative);
2353 for(i=0;i<victim->skeleton.num_joints;i++){
2354 victim->skeleton.joints[i].velocity=relative*30;
2356 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2358 victim->targetframe=0;
2359 victim->targetanimation=staggerbackhardanim;
2360 victim->targetrotation=targetrotation+180;
2365 victim->Puff(abdomen);
2366 victim->DoDamage(damagemult*60/victim->protectionhigh);
2373 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2374 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2376 if(id==0)camerashake+=.4;
2377 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2378 if(tutoriallevel!=1){
2379 emit_sound_at(thudsound, victim->coords);
2382 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2383 if(tutoriallevel!=1){
2384 emit_sound_at(whooshhitsound, victim->coords);
2388 if(tutoriallevel!=1){
2389 emit_sound_at(heavyimpactsound, victim->coords);
2393 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2396 relative=victim->coords-coords;
2398 Normalise(&relative);
2400 Normalise(&relative);
2401 for(i=0;i<victim->skeleton.num_joints;i++){
2402 victim->skeleton.joints[i].velocity=relative*5;
2404 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2406 victim->targetframe=0;
2407 victim->targetanimation=staggerbackhardanim;
2408 victim->targetrotation=targetrotation+180;
2412 victim->Puff(abdomen);
2413 victim->DoDamage(damagemult*60/victim->protectionhigh);
2419 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2420 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2421 if(victim->id==0)camerashake+=.4;
2422 emit_sound_at(landsound2, victim->coords);
2428 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2429 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2430 if(victim->id==0)camerashake+=.4;
2432 if(weaponactive!=-1){
2433 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2434 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2435 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2437 emit_sound_at(swordstaffsound, victim->coords);
2440 emit_sound_at(metalhitsound, victim->coords);
2448 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2449 if(weaponactive!=-1){
2452 weapons.owner[weaponids[0]]=-1;
2453 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);
2455 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2456 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2458 weapons.velocity[weaponids[0]]=aim*50;
2459 weapons.tipvelocity[weaponids[0]]=aim*50;
2460 weapons.missed[weaponids[0]]=0;
2461 weapons.hitsomething[weaponids[0]]=0;
2462 weapons.freetime[weaponids[0]]=0;
2463 weapons.firstfree[weaponids[0]]=1;
2464 weapons.physics[weaponids[0]]=0;
2467 weaponids[0]=weaponids[num_weapons];
2473 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2475 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2477 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2479 award_bonus(id, Slicebonus);
2480 if(tutoriallevel!=1){
2481 emit_sound_at(knifeslicesound, victim->coords);
2483 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2484 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2485 if(victim->id != 0 || difficulty==2){
2486 victim->targetframe=0;
2487 victim->targetanimation=staggerbackhardanim;
2488 victim->targetrotation=targetrotation+180;
2492 victim->lowreversaldelay=0;
2493 victim->highreversaldelay=0;
2494 if(aitype!=playercontrolled)weaponmissdelay=.6;
2496 if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2497 if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
2499 XYZ footvel,footpoint;
2502 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2505 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;
2507 if(tutoriallevel!=1){
2508 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2509 footvel=DoRotation(facing,0,90,0)*.8;
2511 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2512 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2513 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2514 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2516 if(tutoriallevel==1){
2517 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2519 victim->DoDamage(damagemult*0);
2522 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2523 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2524 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2525 award_bonus(id, Slashbonus);
2527 if(tutoriallevel!=1){
2528 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2529 else victim->DoBloodBig(2/victim->armorhigh,185);
2530 victim->deathbleeding=1;
2531 emit_sound_at(swordslicesound, victim->coords);
2533 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2534 if(tutoriallevel!=1){
2535 victim->targetframe=0;
2536 victim->targetanimation=staggerbackhardanim;
2537 victim->targetrotation=targetrotation+180;
2541 if(tutoriallevel!=1){
2542 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2543 weapons.blooddrip[weaponids[weaponactive]]+=3;
2545 float bloodlossamount;
2546 bloodlossamount=200+abs((float)(Random()%40))-20;
2547 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2548 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2549 victim->DoDamage(damagemult*0);
2551 XYZ footvel,footpoint;
2554 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2557 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;
2559 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2560 footvel=DoRotation(facing,0,90,0)*.8;
2562 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2563 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2564 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2565 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2569 if(victim->weaponactive!=-1){
2570 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2571 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2572 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2574 emit_sound_at(swordstaffsound, victim->coords);
2577 emit_sound_at(metalhitsound, victim->coords);
2583 victim->Puff(righthand);
2585 victim->targetframe=0;
2586 victim->targetanimation=staggerbackhighanim;
2587 victim->targetrotation=targetrotation+180;
2589 weapons.owner[victim->weaponids[0]]=-1;
2590 aim=DoRotation(facing,0,90,0)*21;
2592 weapons.velocity[victim->weaponids[0]]=aim*-.2;
2593 weapons.tipvelocity[victim->weaponids[0]]=aim;
2594 weapons.missed[victim->weaponids[0]]=1;
2595 weapons.hitsomething[weaponids[0]]=0;
2596 weapons.freetime[victim->weaponids[0]]=0;
2597 weapons.firstfree[victim->weaponids[0]]=1;
2598 weapons.physics[victim->weaponids[0]]=1;
2599 victim->num_weapons--;
2600 if(victim->num_weapons){
2601 victim->weaponids[0]=victim->weaponids[num_weapons];
2602 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2604 victim->weaponactive=-1;
2605 for(i=0;i<numplayers;i++){
2606 player[i].wentforweapon=0;
2613 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2614 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2615 if(tutoriallevel!=1){
2616 weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
2618 if(id==0)camerashake+=.4;
2619 if(Random()%2||creature==wolftype){
2622 emit_sound_at(staffheadsound, victim->coords);
2626 relative=victim->coords-coords;
2628 Normalise(&relative);
2629 relative=DoRotation(relative,0,90,0);
2631 Normalise(&relative);
2632 for(i=0;i<victim->skeleton.num_joints;i++){
2633 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2635 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2636 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2639 if(tutoriallevel!=1){
2640 victim->DoDamage(damagemult*120/victim->protectionhigh);
2642 award_bonus(id, solidhit, 30);
2647 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2648 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2649 if(tutoriallevel!=1){
2650 weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
2652 if(id==0)camerashake+=.4;
2653 if(Random()%2||creature==wolftype){
2656 emit_sound_at(staffheadsound, victim->coords);
2660 relative=victim->coords-coords;
2662 Normalise(&relative);
2663 relative=DoRotation(relative,0,-90,0);
2664 for(i=0;i<victim->skeleton.num_joints;i++){
2665 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2667 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2668 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2671 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2673 award_bonus(id, solidhit, 60);
2678 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2679 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2681 if(tutoriallevel!=1){
2682 if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
2683 if(id==0)camerashake+=.4;
2684 if(Random()%2||creature==wolftype){
2687 emit_sound_at(staffbodysound, victim->coords);
2689 victim->skeleton.longdead=0;
2690 victim->skeleton.free=1;
2691 victim->skeleton.broken=0;
2693 for(i=0;i<victim->skeleton.num_joints;i++){
2694 victim->skeleton.joints[i].velchange=0;
2695 victim->skeleton.joints[i].locked=0;
2696 //victim->skeleton.joints[i].velocity=0;
2702 /*relative=victim->coords-coords;
2704 Normalise(&relative);
2705 relative=DoRotation(relative,0,90,0);*/
2707 Normalise(&relative);
2709 for(i=0;i<victim->skeleton.num_joints;i++){
2710 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2713 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2716 for(i=0;i<victim->skeleton.num_joints;i++){
2717 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2720 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2722 victim->Puff(abdomen);
2723 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2726 award_bonus(id, solidhit, 40);
2732 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2733 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2735 if(id==0)camerashake+=.4;
2737 relative=victim->coords-coords;
2739 Normalise(&relative);
2743 if(animation[victim->targetanimation].height==lowheight){
2749 for(i=0;i<victim->skeleton.num_joints;i++){
2750 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2752 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2753 if(tutoriallevel!=1){
2754 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2757 victim->DoDamage(damagemult*100/victim->protectionhead);
2758 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2759 if(creature==wolftype){
2760 emit_sound_at(clawslicesound, victim->coords, 128.);
2762 victim->DoBloodBig(2/victim->armorhead,175);
2766 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2767 for(i=0;i<victim->skeleton.num_joints;i++){
2768 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2770 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2771 victim->targetframe=0;
2772 victim->targetanimation=staggerbackhighanim;
2773 victim->targetrotation=targetrotation+180;
2775 if(tutoriallevel!=1){
2776 emit_sound_at(landsound2, victim->coords, 128.);
2778 victim->Puff(abdomen);
2779 victim->DoDamage(damagemult*30/victim->protectionhigh);
2780 if(creature==wolftype){
2781 emit_sound_at(clawslicesound, victim->coords, 128.);
2783 victim->DoBloodBig(2/victim->armorhigh,170);
2790 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2791 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2793 if(id==0)camerashake+=.2;
2794 if(tutoriallevel!=1){
2795 emit_sound_at(landsound2, victim->coords, 128.);
2798 relative=victim->coords-coords;
2800 Normalise(&relative);
2802 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2805 for(i=0;i<victim->skeleton.num_joints;i++){
2806 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2808 relative=DoRotation(relative,0,-90,0);
2810 for(i=0;i<victim->skeleton.num_joints;i++){
2811 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)
2812 victim->skeleton.joints[i].velocity=relative*80;
2814 victim->Puff(rightankle);
2815 victim->Puff(leftankle);
2816 victim->DoDamage(damagemult*40/victim->protectionlow);
2819 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2820 for(i=0;i<victim->skeleton.num_joints;i++){
2821 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2823 relative=DoRotation(relative,0,-90,0);
2824 for(i=0;i<victim->skeleton.num_joints;i++){
2825 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)
2826 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2828 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2829 victim->targetframe=0;
2830 victim->targetanimation=staggerbackhighanim;
2831 victim->targetrotation=targetrotation+180;
2833 if(tutoriallevel!=1){
2834 emit_sound_at(landsound2, victim->coords, 128.);
2836 victim->Puff(abdomen);
2837 victim->DoDamage(damagemult*30/victim->protectionlow);
2845 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2846 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2848 if(id==0)camerashake+=.4;
2853 if(tutoriallevel!=1){
2854 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2856 if(creature==wolftype){
2857 emit_sound_at(clawslicesound, victim->coords, 128);
2859 victim->DoBloodBig(2/victim->armorhigh,170);
2863 relative=victim->coords-oldcoords;
2865 Normalise(&relative);
2866 //relative=DoRotation(relative,0,-90,0);
2867 for(i=0;i<victim->skeleton.num_joints;i++){
2868 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2870 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2872 victim->Puff(abdomen);
2873 victim->DoDamage(damagemult*150/victim->protectionhigh);
2875 award_bonus(id, Reversal);
2878 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2879 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2880 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
2881 weapons.owner[victim->weaponids[victim->weaponactive]]=id;
2884 weaponids[num_weapons]=weaponids[victim->weaponactive];
2887 weaponids[0]=victim->weaponids[victim->weaponactive];
2888 victim->num_weapons--;
2889 if(victim->num_weapons>0){
2890 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2891 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2893 victim->weaponactive=-1;
2898 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2900 if(id==0)camerashake+=.4;
2905 emit_sound_at(whooshhitsound, victim->coords, 128.);
2908 relative=victim->coords-oldcoords;
2910 Normalise(&relative);
2911 //relative=DoRotation(relative,0,-90,0);
2912 for(i=0;i<victim->skeleton.num_joints;i++){
2913 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2915 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2918 victim->DoDamage(damagemult*70/victim->protectionhigh);
2921 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2923 if(id==0)camerashake+=.4;
2929 award_bonus(id, staffreversebonus);
2931 if(tutoriallevel!=1){
2932 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2935 award_bonus(id, staffreversebonus); // Huh, again?
2938 relative=victim->coords-oldcoords;
2940 Normalise(&relative);
2941 //relative=DoRotation(relative,0,-90,0);
2942 for(i=0;i<victim->skeleton.num_joints;i++){
2943 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2945 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2948 victim->DoDamage(damagemult*70/victim->protectionhigh);
2951 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
2957 Normalise(&relative);
2960 for(i=0;i<victim->skeleton.num_joints;i++){
2961 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2963 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
2964 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
2965 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
2966 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
2967 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
2968 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
2969 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
2970 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
2972 victim->Puff(abdomen);
2973 victim->DoDamage(damagemult*90/victim->protectionhigh);
2975 award_bonus(id, Reversal);
2979 if(weaponactive!=-1||creature==wolftype)doslice=1;
2980 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
2982 if(weaponactive!=-1){
2983 victim->DoBloodBig(2/victim->armorhigh,225);
2984 emit_sound_at(knifeslicesound, victim->coords);
2985 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2986 weapons.blooddrip[weaponids[weaponactive]]+=3;
2988 if(weaponactive==-1&&creature==wolftype){;
2989 emit_sound_at(clawslicesound, victim->coords, 128.);
2991 victim->DoBloodBig(2/victim->armorhigh,175);
2998 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3004 Normalise(&relative);
3007 for(i=0;i<victim->skeleton.num_joints;i++){
3008 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3010 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3011 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3012 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3013 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3014 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3015 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3016 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3017 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3019 award_bonus(id, swordreversebonus);
3022 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3024 if(id==0)camerashake+=.4;
3029 if(tutoriallevel!=1){
3030 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3034 relative=victim->coords-oldcoords;
3036 Normalise(&relative);
3037 relative=DoRotation(relative,0,-90,0);
3038 for(i=0;i<victim->skeleton.num_joints;i++){
3039 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3041 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3043 victim->Puff(abdomen);
3044 victim->DoDamage(damagemult*30/victim->protectionhigh);
3046 award_bonus(id, Reversal);
3049 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3052 victim->skeleton.spinny=0;
3056 Normalise(&relative);
3057 if(victim->id==0)relative/=30;
3058 for(i=0;i<victim->skeleton.num_joints;i++){
3059 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3061 //victim->DoDamage(1000);
3062 victim->damage=victim->damagetolerance;
3063 victim->permanentdamage=victim->damagetolerance-1;
3066 if(weaponactive!=-1||creature==wolftype)doslice=1;
3067 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3069 if(weaponactive!=-1){
3070 victim->DoBloodBig(200,225);
3071 emit_sound_at(knifeslicesound, victim->coords);
3072 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3073 weapons.blooddrip[weaponids[weaponactive]]+=5;
3076 if(creature==wolftype&&weaponactive==-1){
3077 emit_sound_at(clawslicesound, victim->coords, 128.);
3079 victim->DoBloodBig(2,175);
3082 award_bonus(id, spinecrusher);
3085 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3086 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3088 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3089 if(targetanimation==knifesneakattackanim){
3090 /*victim->DoBloodBig(200,195);
3095 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3096 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3098 XYZ footvel,footpoint;
3100 footpoint=weapons.tippoint[weaponids[0]];
3101 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3102 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3103 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3104 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3105 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3106 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3107 victim->DoBloodBig(200,195);
3108 award_bonus(id, tracheotomy);
3110 if(targetanimation==knifefollowanim){
3111 award_bonus(id, Stabbonus);
3112 XYZ footvel,footpoint;
3114 footpoint=weapons.tippoint[weaponids[0]];
3115 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3116 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3117 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3118 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3119 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3120 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3123 victim->bloodloss+=10000;
3125 emit_sound_at(fleshstabsound, victim->coords);
3126 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3127 weapons.blooddrip[weaponids[weaponactive]]+=5;
3131 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3134 for(i=0;i<victim->skeleton.num_joints;i++){
3135 victim->skeleton.joints[i].velocity=0;
3137 if(targetanimation==knifefollowanim){
3139 for(i=0;i<victim->skeleton.num_joints;i++){
3140 victim->skeleton.joints[i].velocity=0;
3143 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3144 emit_sound_at(fleshstabremovesound, victim->coords);
3145 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3146 weapons.blooddrip[weaponids[weaponactive]]+=5;
3148 XYZ footvel,footpoint;
3150 footpoint=weapons.tippoint[weaponids[0]];
3151 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3152 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3153 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3154 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3155 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3156 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3160 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3161 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3162 award_bonus(id, backstab);
3166 XYZ footvel,footpoint;
3168 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3169 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3170 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3171 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3172 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3173 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3174 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3175 victim->DoBloodBig(200,180);
3176 victim->DoBloodBig(200,215);
3177 victim->bloodloss+=10000;
3179 emit_sound_at(fleshstabsound, victim->coords);
3180 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3181 weapons.blooddrip[weaponids[weaponactive]]+=5;
3185 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3188 for(i=0;i<victim->skeleton.num_joints;i++){
3189 victim->skeleton.joints[i].velocity=0;
3191 if(weaponactive!=-1){
3192 emit_sound_at(fleshstabremovesound, victim->coords);
3193 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3194 weapons.blooddrip[weaponids[weaponactive]]+=5;
3196 XYZ footvel,footpoint;
3198 footpoint=weapons.tippoint[weaponids[0]];
3199 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3200 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3201 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3202 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3203 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3204 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3208 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3210 if(id==0)camerashake+=.4;
3215 if(weaponactive==-1){
3216 if(tutoriallevel!=1){
3217 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3222 if(weaponactive!=-1||creature==wolftype)doslice=1;
3223 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3225 if(weaponactive!=-1){
3226 victim->DoBloodBig(2/victim->armorhead,225);
3227 emit_sound_at(knifeslicesound, victim->coords);
3228 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3229 weapons.blooddrip[weaponids[weaponactive]]+=3;
3231 if(weaponactive==-1&&creature==wolftype){
3232 emit_sound_at(clawslicesound, victim->coords, 128.);
3234 victim->DoBloodBig(2/victim->armorhead,175);
3238 award_bonus(id, Reversal);
3243 //relative=victim->coords-oldcoords;
3246 Normalise(&relative);
3247 relative=DoRotation(relative,0,90,0);
3249 Normalise(&relative);
3250 for(i=0;i<victim->skeleton.num_joints;i++){
3251 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3253 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3254 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3255 victim->DoDamage(damagemult*100/victim->protectionhead);
3259 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3263 //relative=victim->coords-oldcoords;
3266 Normalise(&relative);
3267 relative=DoRotation(relative,0,90,0);
3269 Normalise(&relative);
3270 for(i=0;i<victim->skeleton.num_joints;i++){
3271 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3273 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3276 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3277 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3278 award_bonus(id, reverseko);
3284 if(targetframe>animation[currentanimation].numframes-1){
3287 targetanimation=getIdle();
3291 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3292 targetanimation=rollanim;
3294 emit_sound_at(movewhooshsound, coords, 128.);
3296 if(currentanimation==staggerbackhighanim){
3297 targetanimation=getIdle();
3299 if(currentanimation==staggerbackhardanim){
3300 targetanimation=getIdle();
3302 if(currentanimation==removeknifeanim){
3303 targetanimation=getIdle();
3305 if(currentanimation==crouchremoveknifeanim){
3306 targetanimation=getCrouch();
3308 if(currentanimation==backhandspringanim){
3309 targetanimation=getIdle();
3311 if(currentanimation==dodgebackanim){
3312 targetanimation=getIdle();
3314 if(currentanimation==drawleftanim){
3315 targetanimation=getIdle();
3317 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3318 targetanimation=getIdle();
3319 if(currentanimation==crouchdrawrightanim){
3320 targetanimation=getCrouch();
3322 if(weaponactive==-1)weaponactive=0;
3323 else if(weaponactive==0){
3327 buffer=weaponids[0];
3328 weaponids[0]=weaponids[1];
3329 weaponids[1]=buffer;
3333 if(weaponactive==-1){
3334 emit_sound_at(knifesheathesound, coords, 128.);
3336 if(weaponactive!=-1){
3337 emit_sound_at(knifedrawsound, coords, 128.);
3340 if(currentanimation==rollanim){
3341 targetanimation=getCrouch();
3346 if(targetanimation==walljumprightkickanim){
3349 if(targetanimation==walljumpleftkickanim){
3352 targetanimation=jumpdownanim;
3354 if(currentanimation==climbanim){
3355 targetanimation=getCrouch();
3358 if(!isnormal(coords.x))
3369 if(targetanimation==rabbitkickreversalanim){
3370 targetanimation=getCrouch();
3373 if(targetanimation==jumpreversalanim){
3374 targetanimation=getCrouch();
3377 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3378 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3380 float closestdist=-1;
3383 for(i=0;i<numplayers;i++){
3384 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3385 distance=findDistancefast(&player[i].coords,&coords);
3386 if(closestdist==-1||distance<closestdist){
3387 closestdist=distance;
3392 if(closestdist>0&&closest>=0&&closestdist<16){
3393 victim=&player[closest];
3394 targetanimation=walljumprightkickanim;
3396 XYZ rotatetarget=victim->coords-coords;
3397 Normalise(&rotatetarget);
3398 rotation=-asin(0-rotatetarget.x);
3400 if(rotatetarget.z<0)rotation=180-rotation;
3401 targettilt2=-asin(rotatetarget.y)*360/6.28;
3402 velocity=(victim->coords-coords)*4;
3407 if(targetanimation==walljumpbackanim){
3408 targetanimation=backflipanim;
3412 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3414 if(targetanimation==walljumprightanim){
3415 targetanimation=rightflipanim;
3419 velocity=DoRotation(facing,0,30,0)*-8;
3422 if(targetanimation==walljumpfrontanim){
3423 targetanimation=frontflipanim;
3425 //targetrotation-=180;
3430 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3432 if(targetanimation==walljumpleftanim){
3435 float closestdist=-1;
3438 for(i=0;i<numplayers;i++){
3439 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3440 distance=findDistancefast(&player[i].coords,&coords);
3441 if(closestdist==-1||distance<closestdist){
3442 closestdist=distance;
3447 if(closestdist>0&&closest>=0&&closestdist<16){
3448 victim=&player[closest];
3449 targetanimation=walljumpleftkickanim;
3451 XYZ rotatetarget=victim->coords-coords;
3452 Normalise(&rotatetarget);
3453 rotation=-asin(0-rotatetarget.x);
3455 if(rotatetarget.z<0)rotation=180-rotation;
3456 targettilt2=-asin(rotatetarget.y)*360/6.28;
3457 velocity=(victim->coords-coords)*4;
3462 if(targetanimation!=walljumpleftkickanim){
3463 targetanimation=leftflipanim;
3467 velocity=DoRotation(facing,0,-30,0)*-8;
3470 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3472 if(targetanimation==sneakattackanim){
3473 float ycoords=oldcoords.y;
3474 currentanimation=getCrouch();
3475 targetanimation=getCrouch();
3478 targetrotation+=180;
3483 targetheadrotation+=180;
3485 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3489 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3490 float ycoords=oldcoords.y;
3491 targetanimation=getIdle();
3493 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3497 if(currentanimation==knifefollowanim){
3498 targetanimation=getIdle();
3501 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3502 float ycoords=oldcoords.y;
3503 targetanimation=getStop();
3504 targetrotation+=180;
3509 targetheadrotation+=180;
3510 if(!isnormal(coords.x))
3512 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3513 oldcoords=coords+facing*.5;
3514 else if(currentanimation==sweepreversalanim)
3515 oldcoords=coords+facing*1.1;
3516 else if(currentanimation==upunchreversalanim){
3517 oldcoords=coords+facing*1.5;
3518 targetrotation+=180;
3520 targetheadrotation+=180;
3524 else if(currentanimation==knifeslashreversalanim){
3525 oldcoords=coords+facing*.5;
3528 targetheadrotation+=90;
3532 else if(currentanimation==staffspinhitreversalanim){
3533 targetrotation+=180;
3535 targetheadrotation+=180;
3539 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3540 else oldcoords.y=ycoords;
3541 currentoffset=coords-oldcoords;
3547 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3552 if(animation[targetanimation].attack==reversed){
3554 if(targetanimation==sweepreversedanim)targetrotation+=90;
3555 targetanimation=backhandspringanim;
3557 emit_sound_at(landsound, coords, 128);
3559 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3560 targetanimation=rollanim;
3563 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3564 coords.y=oldcoords.y;
3566 if(currentanimation==knifeslashreversedanim){
3567 targetanimation=rollanim;
3572 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3573 coords.y=oldcoords.y;
3577 targetanimation=jumpdownanim;
3579 if(wasLanding())targetanimation=getIdle();
3580 if(wasLandhard())targetanimation=getIdle();
3581 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3582 targetanimation=getIdle();
3584 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3585 coords.y=oldcoords.y;
3586 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3587 targetoffset.y=coords.y;
3588 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3589 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3590 currentoffset.y-=(coords.y-targetoffset.y);
3591 coords.y=targetoffset.y;
3593 normalsupdatedelay=0;
3595 if(currentanimation==upunchanim){
3596 targetanimation=getStop();
3597 normalsupdatedelay=0;
3600 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3601 targetrotation=rotation;
3604 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
3605 if(!hasstaff)DoDamage(35);
3608 rabbitkickragdoll=1;
3610 if(currentanimation==rabbitkickreversedanim){
3617 SolidHitBonus(!id); // FIXME: tricky id
3621 targetanimation=rollanim;
3623 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3627 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3633 if(currentanimation==jumpreversedanim){
3640 SolidHitBonus(!id); // FIXME: tricky id
3644 targetanimation=rollanim;
3646 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3651 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){
3652 targetanimation=getupfromfrontanim;
3655 else if(animation[currentanimation].attack==normalattack){
3656 targetanimation=getIdle();
3659 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3660 targetanimation=blockhighleftstrikeanim;
3662 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3663 targetanimation=getIdle();
3666 if(currentanimation==spinkickanim&&victim->skeleton.free){
3667 if(creature==rabbittype)targetanimation=fightidleanim;
3672 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3674 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3675 targetanimation=jumpdownanim;
3680 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3681 if(!isRun()||!wasRun()){
3682 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3683 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3684 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3685 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3687 if(isRun()&&wasRun()){
3690 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3691 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3694 else if(transspeed)target+=multiplier*transspeed*speed*2;
3696 if(!isRun()||!wasRun()){
3697 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3698 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3699 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3700 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3704 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3706 if(target>1){currentframe=targetframe; target=1;}
3708 rot=targetrot*target;
3709 rotation+=rot-oldrot;
3715 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3717 for(i=0;i<skeleton.num_joints;i++){
3718 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3721 skeleton.FindForwards();
3723 for(i=0;i<skeleton.num_muscles;i++){
3724 if(skeleton.muscles[i].visible)
3726 skeleton.FindRotationMuscle(i,targetanimation);
3729 for(i=0;i<skeleton.num_muscles;i++){
3730 if(skeleton.muscles[i].visible)
3732 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3733 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3734 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3739 for(i=0;i<skeleton.num_joints;i++){
3740 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3743 skeleton.FindForwards();
3745 for(i=0;i<skeleton.num_muscles;i++){
3746 if(skeleton.muscles[i].visible)
3748 skeleton.FindRotationMuscle(i,targetanimation);
3751 for(i=0;i<skeleton.num_muscles;i++){
3752 if(skeleton.muscles[i].visible)
3754 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3755 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3756 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3757 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3758 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3759 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3760 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3761 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3762 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3766 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3768 oldcurrentanimation=currentanimation;
3769 oldtargetanimation=targetanimation;
3770 oldtargetframe=targetframe;
3771 oldcurrentframe=currentframe;
3773 for(i=0;i<skeleton.num_joints;i++){
3774 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3775 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3777 offset=currentoffset*(1-target)+targetoffset*target;
3778 for(i=0;i<skeleton.num_muscles;i++){
3779 if(skeleton.muscles[i].visible)
3781 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3782 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3783 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3788 if(isLanding()&&landhard){
3789 if(id==0)camerashake+=.4;
3790 targetanimation=getLandhard();
3797 //skeleton.DoConstraints();
3800 void Person::DoStuff(){
3801 static XYZ terrainnormal;
3802 static XYZ flatfacing;
3803 static XYZ flatvelocity;
3804 static float flatvelspeed;
3808 static int bloodsize;
3809 static int startx,starty,endx,endy;
3810 static int texdetailint;
3811 static GLubyte color;
3812 static XYZ bloodvel;
3814 onfiredelay-=multiplier;
3815 if(onfiredelay<0&&onfire)
3823 crouchkeydowntime+=multiplier;
3824 if(!crouchkeydown)crouchkeydowntime=0;
3825 jumpkeydowntime+=multiplier;
3826 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3828 if(hostile||damage>0||bloodloss>0)immobile=0;
3830 if(isIdle()||isRun())targetoffset=0;
3832 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3834 if(id==0)blooddimamount-=multiplier*.3;
3835 speechdelay-=multiplier;
3836 texupdatedelay-=multiplier;
3837 interestdelay-=multiplier;
3838 flamedelay-=multiplier;
3839 parriedrecently-=multiplier;
3845 if(id==0)speed=1.1*speedmult;
3846 else speed=1.0*speedmult;
3847 if(!skeleton.free)rabbitkickragdoll=0;
3851 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3852 if(id!=0&&creature==wolftype&&difficulty==2){
3854 if(aitype!=passivetype){
3856 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){
3860 if(scale<0.2)superruntoggle=0;
3861 if(targetanimation==wolfrunninganim&&!superruntoggle){
3862 targetanimation=getRun();
3866 if(weaponactive==-1&&num_weapons>0){
3867 if(weapons.type[weaponids[0]]==staff){
3874 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3875 /*if(aitype!=playercontrolled)*/
3877 if(burnt>.6)burnt=.6;
3878 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3880 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3891 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3892 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3896 while(flamedelay<0&&onfire){
3898 howmany=abs(Random()%(skeleton.num_joints));
3899 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3900 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3901 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3902 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3903 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3906 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3908 howmany=abs(Random()%(skeleton.num_joints));
3909 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3910 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3911 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3912 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3913 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3917 bleeding-=multiplier*.3;
3919 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3920 if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
3924 if(neckspurtamount>0){
3925 neckspurtamount-=multiplier;
3926 neckspurtdelay-=multiplier*3;
3927 neckspurtparticledelay-=multiplier*3;
3928 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3932 bloodvel.z=5*neckspurtamount;
3933 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3936 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3938 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3939 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3940 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);
3941 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);
3942 neckspurtparticledelay=.05;
3944 if(neckspurtdelay<0){
3949 if(deathbleeding>0&&dead!=2){
3950 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
3951 else bleeddelay-=5*multiplier/4;
3952 if(bleeddelay<0&&bloodtoggle){
3957 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3958 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
3959 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
3960 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);
3963 bloodloss+=deathbleeding*multiplier*80;
3964 deathbleeding-=multiplier*1.6;
3965 //if(id==0)deathbleeding-=multiplier*.2;
3966 if(deathbleeding<0)deathbleeding=0;
3967 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
3968 if(weaponactive!=-1){
3969 weapons.owner[weaponids[0]]=-1;
3970 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
3971 weapons.velocity[weaponids[0]].x+=.01;
3972 weapons.tipvelocity[weaponids[0]]=velocity*scale;
3973 weapons.missed[weaponids[0]]=1;
3974 weapons.hitsomething[weaponids[0]]=0;
3975 weapons.freetime[weaponids[0]]=0;
3976 weapons.firstfree[weaponids[0]]=1;
3977 weapons.physics[weaponids[0]]=1;
3980 weaponids[0]=weaponids[num_weapons];
3981 if(weaponstuck==num_weapons)weaponstuck=0;
3984 for(i=0;i<numplayers;i++){
3985 player[i].wentforweapon=0;
3997 if(!dead&&creature==wolftype){
3998 award_bonus(0, Wolfbonus);
4001 if(targetanimation==knifefollowedanim&&!skeleton.free){
4002 for(i=0;i<skeleton.num_joints;i++){
4003 skeleton.joints[i].velocity=0;
4004 skeleton.joints[i].velocity.y=-2;
4007 if(id!=0&&unconscioustime>.1){
4015 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
4018 bloodsize=5-realtexdetail;
4022 texdetailint=realtexdetail;
4023 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4024 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4025 endx=startx+bloodsize;
4026 endy=starty+bloodsize;
4028 if(startx<0){startx=0;bleeding=0;}
4029 if(starty<0){starty=0;bleeding=0;}
4030 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
4031 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
4032 if(endx<startx)endx=startx;
4033 if(endy<starty)endy=starty;
4035 for(i=startx;i<endx;i++){
4036 for(j=starty;j<endy;j++){
4038 color=Random()%85+170;
4039 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
4040 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
4041 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
4046 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4047 DoMipmaps(0,startx,endx,starty,endy);
4051 bleedy-=4/realtexdetail;
4052 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
4053 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
4056 bleedx+=4*direction/realtexdetail;
4057 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
4058 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4062 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4063 righthandmorphness=targetrighthandmorphness;
4064 righthandmorphstart=righthandmorphend;
4066 else if(righthandmorphness>targetrighthandmorphness){
4067 righthandmorphness-=multiplier*4;
4069 else if(righthandmorphness<targetrighthandmorphness){
4070 righthandmorphness+=multiplier*4;
4073 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4074 lefthandmorphness=targetlefthandmorphness;
4075 lefthandmorphstart=lefthandmorphend;
4077 else if(lefthandmorphness>targetlefthandmorphness){
4078 lefthandmorphness-=multiplier*4;
4080 else if(lefthandmorphness<targetlefthandmorphness){
4081 lefthandmorphness+=multiplier*4;
4084 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4085 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4086 tailmorphness=targettailmorphness;
4087 tailmorphstart=tailmorphend;
4089 else if(tailmorphness>targettailmorphness){
4090 tailmorphness-=multiplier*10;
4092 else if(tailmorphness<targettailmorphness){
4093 tailmorphness+=multiplier*10;
4097 if(creature==wolftype){
4098 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4099 tailmorphness=targettailmorphness;
4100 tailmorphstart=tailmorphend;
4102 else if(tailmorphness>targettailmorphness){
4103 tailmorphness-=multiplier*2;
4105 else if(tailmorphness<targettailmorphness){
4106 tailmorphness+=multiplier*2;
4110 if(headmorphend==3||headmorphstart==3){
4111 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4112 headmorphness=targetheadmorphness;
4113 headmorphstart=headmorphend;
4115 else if(headmorphness>targetheadmorphness){
4116 headmorphness-=multiplier*7;
4118 else if(headmorphness<targetheadmorphness){
4119 headmorphness+=multiplier*7;
4122 else if(headmorphend==5||headmorphstart==5){
4123 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4124 headmorphness=targetheadmorphness;
4125 headmorphstart=headmorphend;
4127 else if(headmorphness>targetheadmorphness){
4128 headmorphness-=multiplier*10;
4130 else if(headmorphness<targetheadmorphness){
4131 headmorphness+=multiplier*10;
4135 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4136 headmorphness=targetheadmorphness;
4137 headmorphstart=headmorphend;
4139 else if(headmorphness>targetheadmorphness){
4140 headmorphness-=multiplier*4;
4142 else if(headmorphness<targetheadmorphness){
4143 headmorphness+=multiplier*4;
4147 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4148 chestmorphness=targetchestmorphness;
4149 chestmorphstart=chestmorphend;
4151 else if(chestmorphness>targetchestmorphness){
4152 chestmorphness-=multiplier;
4154 else if(chestmorphness<targetchestmorphness){
4155 chestmorphness+=multiplier;
4158 if(dead!=2&&howactive<=typesleeping){
4159 if(chestmorphstart==0&&chestmorphend==0){
4161 targetchestmorphness=1;
4164 if(chestmorphstart!=0&&chestmorphend!=0){
4166 targetchestmorphness=1;
4168 if(environment==snowyenvironment){
4171 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4172 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4173 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4174 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4175 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4176 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4180 if(!dead&&howactive<typesleeping){
4181 blinkdelay-=multiplier*2;
4182 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4184 targetheadmorphness=1;
4186 blinkdelay=(float)(abs(Random()%40))/5;
4188 if(headmorphstart==3&&headmorphend==3){
4190 targetheadmorphness=1;
4195 twitchdelay-=multiplier*1.5;
4196 if(targetanimation!=hurtidleanim){
4197 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4199 targetheadmorphness=1;
4201 twitchdelay=(float)(abs(Random()%40))/5;
4203 if(headmorphstart==5&&headmorphend==5){
4205 targetheadmorphness=1;
4209 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4210 twitchdelay3-=multiplier*1;
4212 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4213 righthandmorphness=0;
4214 targetrighthandmorphness=1;
4215 righthandmorphend=1;
4216 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4218 if(righthandmorphstart==1&&righthandmorphend==1){
4219 righthandmorphness=0;
4220 targetrighthandmorphness=1;
4221 righthandmorphend=0;
4225 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4226 lefthandmorphness=0;
4227 targetlefthandmorphness=1;
4229 twitchdelay3=(float)(abs(Random()%40))/5;
4231 if(lefthandmorphstart==1&&lefthandmorphend==1){
4232 lefthandmorphness=0;
4233 targetlefthandmorphness=1;
4240 if(creature==rabbittype){
4241 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4242 else twitchdelay2-=multiplier*0.5;
4243 if(howactive<=typesleeping){
4244 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4246 targettailmorphness=1;
4248 twitchdelay2=(float)(abs(Random()%40))/5;
4250 if(tailmorphstart==1&&tailmorphend==1){
4252 targettailmorphness=1;
4255 if(tailmorphstart==2&&tailmorphend==2){
4257 targettailmorphness=1;
4264 if(creature==wolftype){
4265 twitchdelay2-=multiplier*1.5;
4267 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4269 targettailmorphness=1;
4274 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4276 targettailmorphness=1;
4280 if(twitchdelay2<=0){
4281 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4283 targettailmorphness=1;
4286 if(tailmorphstart==1&&tailmorphend==1){
4288 targettailmorphness=1;
4291 if(tailmorphstart==2&&tailmorphend==2){
4293 targettailmorphness=1;
4296 if(tailmorphstart==3&&tailmorphend==3){
4298 targettailmorphness=1;
4301 if(tailmorphstart==4&&tailmorphend==4){
4303 targettailmorphness=1;
4309 if(dead!=1)unconscioustime=0;
4311 if(dead==1||howactive==typesleeping){
4312 unconscioustime+=multiplier;
4313 //If unconscious, close eyes and mouth
4314 if(righthandmorphend!=0)righthandmorphness=0;
4315 righthandmorphend=0;
4316 targetrighthandmorphness=1;
4318 if(lefthandmorphend!=0)lefthandmorphness=0;
4320 targetlefthandmorphness=1;
4322 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4324 targetheadmorphness=1;
4328 if(howactive>typesleeping){
4331 if(bloodtoggle&&!bled){
4332 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4334 if(bloodtoggle&&!bled)
4335 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4336 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4337 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4341 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4346 if(dead==2||howactive>typesleeping){
4347 //If dead, open mouth and hands
4348 if(righthandmorphend!=0)righthandmorphness=0;
4349 righthandmorphend=0;
4350 targetrighthandmorphness=1;
4352 if(lefthandmorphend!=0)lefthandmorphness=0;
4354 targetlefthandmorphness=1;
4356 if(headmorphend!=2)headmorphness=0;
4358 targetheadmorphness=1;
4361 if(stunned>0&&!dead&&headmorphend!=2){
4362 if(headmorphend!=4)headmorphness=0;
4364 targetheadmorphness=1;
4367 if(damage>damagetolerance&&!dead){
4372 if(creature==wolftype){
4373 award_bonus(0, Wolfbonus);
4378 if(weaponactive!=-1){
4379 weapons.owner[weaponids[0]]=-1;
4380 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4381 weapons.velocity[weaponids[0]].x+=.01;
4382 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4383 weapons.missed[weaponids[0]]=1;
4384 weapons.hitsomething[weaponids[0]]=0;
4385 weapons.freetime[weaponids[0]]=0;
4386 weapons.firstfree[weaponids[0]]=1;
4387 weapons.physics[weaponids[0]]=1;
4390 weaponids[0]=weaponids[num_weapons];
4391 if(weaponstuck==num_weapons)weaponstuck=0;
4394 for(i=0;i<numplayers;i++){
4395 player[i].wentforweapon=0;
4401 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4409 //if(dead)damage-=multiplier/4;
4410 if(!dead)damage-=multiplier*13;
4411 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4412 if(!dead)permanentdamage-=multiplier*4;
4413 if(isIdle()||isCrouch()){
4414 if(!dead)permanentdamage-=multiplier*4;
4415 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4417 if(damage<0)damage=0;
4418 if(permanentdamage<0)permanentdamage=0;
4419 if(superpermanentdamage<0)superpermanentdamage=0;
4420 if(permanentdamage<superpermanentdamage){
4421 permanentdamage=superpermanentdamage;
4423 if(damage<permanentdamage){
4424 damage=permanentdamage;
4426 if(dead==1&&damage<damagetolerance){
4430 for(i=0;i<skeleton.num_joints;i++){
4431 skeleton.joints[i].velocity=0;
4434 if(permanentdamage>damagetolerance&&dead!=2){
4437 if(weaponactive!=-1){
4438 weapons.owner[weaponids[0]]=-1;
4439 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4440 weapons.velocity[weaponids[0]].x+=.01;
4441 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4442 weapons.missed[weaponids[0]]=1;
4443 weapons.hitsomething[weaponids[0]]=0;
4444 weapons.freetime[weaponids[0]]=0;
4445 weapons.firstfree[weaponids[0]]=1;
4446 weapons.physics[weaponids[0]]=1;
4449 weaponids[0]=weaponids[num_weapons];
4450 if(weaponstuck==num_weapons)weaponstuck=0;
4453 for(i=0;i<numplayers;i++){
4454 player[i].wentforweapon=0;
4460 if(!dead&&creature==wolftype){
4461 award_bonus(0, Wolfbonus);
4464 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4465 award_bonus(id, touchofdeath);
4466 if(id!=0&&unconscioustime>.1){
4474 emit_sound_at(breaksound, coords);
4475 /*if(id==0||findDistancefast(&coords,&viewer)<50){
4481 if(skeleton.free==1){
4482 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4485 //If knocked over, open hands and close mouth
4486 if(righthandmorphend!=0)righthandmorphness=0;
4487 righthandmorphend=0;
4488 targetrighthandmorphness=1;
4490 if(lefthandmorphend!=0)lefthandmorphness=0;
4492 targetlefthandmorphness=1;
4494 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4495 if(headmorphend!=0)headmorphness=0;
4497 targetheadmorphness=1;
4501 skeleton.DoGravity(&scale);
4503 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4504 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4505 award_bonus(id, deepimpact);
4506 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4510 for(j=0;j<skeleton.num_joints;j++){
4511 average+=skeleton.joints[j].position;
4515 coords+=average*scale;
4516 for(j=0;j<skeleton.num_joints;j++){
4517 skeleton.joints[j].position-=average;
4519 average/=multiplier;
4521 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4523 for(i=0;i<skeleton.num_joints;i++){
4524 velocity+=skeleton.joints[i].velocity*scale;
4526 velocity/=skeleton.num_joints;
4528 if(!isnormal(velocity.x)&&velocity.x){
4541 if(findLength(&average)<10&&dead&&skeleton.free){
4542 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4543 if(skeleton.longdead>2000){
4544 if(skeleton.longdead>6000){
4545 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4550 if(dead==2&&bloodloss<damagetolerance){
4552 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4554 if(bloodtoggle&&!bled){
4555 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4557 if(bloodtoggle&&!bled)
4558 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4559 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4560 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4564 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4568 if(dead==2&&bloodloss>=damagetolerance){
4570 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4571 if(bleeding<=0)DoBlood(1,255);
4572 if(bloodtoggle&&!bled){
4573 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4575 if(bloodtoggle&&!bled)
4576 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4577 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4578 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4582 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4589 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4591 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4595 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4596 if(velocity.y<-30)canrecover=0;
4597 for(i=0;i<objects.numobjects;i++){
4598 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4599 colviewer=startpoint;
4601 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4609 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4610 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4611 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4612 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4614 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4615 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4616 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4618 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4619 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4620 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4622 Normalise(&terrainnormal);
4624 targetrotation=-asin(0-terrainnormal.x);
4625 targetrotation*=360/6.28;
4626 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4627 rotation=targetrotation;
4631 targetanimation=flipanim;
4632 crouchtogglekeydown=1;
4637 currentanimation=tempanim;
4640 //tilt2=targettilt2;
4642 //if(middle.y>0)targetoffset.y=middle.y+1;
4644 for(i=0;i<skeleton.num_joints;i++){
4645 tempanimation.position[i][0]=skeleton.joints[i].position;
4646 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4651 if(findLength(&average)<10&&!dead&&skeleton.free){
4652 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4653 if(skeleton.longdead>(damage+500)*1.5){
4654 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4660 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4661 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4662 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4663 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4665 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4666 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4667 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4669 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4670 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4671 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4673 Normalise(&terrainnormal);
4675 targetrotation=-asin(0-terrainnormal.x);
4676 targetrotation*=360/6.28;
4677 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4678 rotation=targetrotation;
4681 terrainnormal=terrain.getNormal(coords.x,coords.z);
4682 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4686 /*XYZ otherterrainnormal;
4687 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
4688 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4689 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4690 targettilt2=asin(otherterrainnormal.y)*180/3.14;
4693 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4697 if(skeleton.forward.y<0){
4698 targetanimation=getupfrombackanim;
4702 if(skeleton.forward.y>-.3){
4703 targetanimation=getupfromfrontanim;
4705 targetrotation+=180;
4711 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4712 targetanimation=rollanim;
4713 targetrotation=lookrotation;
4717 if(forwardkeydown)targetrotation+=45;
4718 if(backkeydown)targetrotation-=45;
4722 if(forwardkeydown)targetrotation-=45;
4723 if(backkeydown)targetrotation+=45;
4726 if ( !leftkeydown&&!rightkeydown)
4727 targetrotation+=180;
4729 targetrotation+=180;
4733 if(abs(targettilt2)>50)targettilt2=0;
4734 currentanimation=tempanim;
4739 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4741 for(i=0;i<skeleton.num_joints;i++){
4742 tempanimation.position[i][0]=skeleton.joints[i].position;
4743 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4750 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4751 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4754 tempvelocity=velocity;
4755 Normalise(&tempvelocity);
4756 targetrotation=-asin(0-tempvelocity.x);
4757 targetrotation*=360/6.28;
4758 if(velocity.z<0)targetrotation=180-targetrotation;
4759 //targetrotation+=180;
4762 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4763 targetanimation=rollanim;
4767 targetanimation=backhandspringanim;
4768 targetrotation+=180;
4773 emit_sound_at(movewhooshsound, coords, 128.);
4775 currentanimation=targetanimation;
4776 currentframe=targetframe-1;
4781 rotation=targetrotation;
4788 if(skeleton.freefall==0)freefall=0;
4790 if(!isnormal(velocity.x)&&velocity.x){
4795 if(aitype!=passivetype||skeleton.free==1)
4796 if(findLengthfast(&velocity)>.1)
4797 for(i=0;i<objects.numobjects;i++){
4798 if(objects.type[i]==firetype)
4799 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){
4801 if(!objects.onfire[i]){
4802 emit_sound_at(firestartsound, objects.position[i]);
4804 objects.onfire[i]=1;
4807 if(objects.onfire[i]){
4812 if(objects.type[i]==bushtype)
4813 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){
4815 if(!objects.onfire[i]){
4816 emit_sound_at(firestartsound, objects.position[i]);
4818 objects.onfire[i]=1;
4822 if(objects.onfire[i]){
4826 if(objects.messedwith[i]<=0){
4830 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4833 envsound[numenvsounds]=coords;
4834 envsoundvol[numenvsounds]=4*findLength(&velocity);
4835 envsoundlife[numenvsounds]=.4;
4840 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4841 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4843 if(environment!=desertenvironment)
4844 for(j=0;j<howmany;j++){
4845 tempvel.x=float(abs(Random()%100)-50)/20;
4846 tempvel.y=float(abs(Random()%100)-50)/20;
4847 tempvel.z=float(abs(Random()%100)-50)/20;
4850 pos.x+=float(abs(Random()%100)-50)/200;
4851 pos.y+=float(abs(Random()%100)-50)/200;
4852 pos.z+=float(abs(Random()%100)-50)/200;
4853 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);
4854 Sprite::setLastSpriteSpecial(1);
4856 howmany=findLength(&velocity)*4;
4858 if(environment==snowyenvironment)
4859 for(j=0;j<howmany;j++){
4860 tempvel.x=float(abs(Random()%100)-50)/20;
4861 tempvel.y=float(abs(Random()%100)-50)/20;
4862 tempvel.z=float(abs(Random()%100)-50)/20;
4865 pos.x+=float(abs(Random()%100)-50)/200;
4866 pos.y+=float(abs(Random()%100)-50)/200;
4867 pos.z+=float(abs(Random()%100)-50)/200;
4868 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4869 Sprite::setLastSpriteSpecial(2);
4872 objects.rotx[i]+=velocity.x*multiplier*6;
4873 objects.roty[i]+=velocity.z*multiplier*6;
4874 objects.messedwith[i]=.5;
4877 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4878 if(objects.rotation2[i]==0)tempcoord=coords;
4880 tempcoord=coords-objects.position[i];
4881 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4882 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4883 tempcoord+=objects.position[i];
4885 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]){
4886 if(objects.messedwith[i]<=0){
4890 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4893 envsound[numenvsounds]=coords;
4894 envsoundvol[numenvsounds]=4*findLength(&velocity);
4895 envsoundlife[numenvsounds]=.4;
4900 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4901 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4903 if(environment!=desertenvironment)
4904 for(j=0;j<howmany;j++){
4905 tempvel.x=float(abs(Random()%100)-50)/20;
4906 tempvel.y=float(abs(Random()%100)-50)/20;
4907 tempvel.z=float(abs(Random()%100)-50)/20;
4911 pos.x+=float(abs(Random()%100)-50)/150;
4912 pos.y+=float(abs(Random()%100)-50)/150;
4913 pos.z+=float(abs(Random()%100)-50)/150;
4914 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);
4915 Sprite::setLastSpriteSpecial(1);
4917 howmany=findLength(&velocity)*4;
4919 if(environment==snowyenvironment)
4920 for(j=0;j<howmany;j++){
4921 tempvel.x=float(abs(Random()%100)-50)/20;
4922 tempvel.y=float(abs(Random()%100)-50)/20;
4923 tempvel.z=float(abs(Random()%100)-50)/20;
4927 pos.x+=float(abs(Random()%100)-50)/150;
4928 pos.y+=float(abs(Random()%100)-50)/150;
4929 pos.z+=float(abs(Random()%100)-50)/150;
4930 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4931 Sprite::setLastSpriteSpecial(2);
4934 objects.messedwith[i]=.5;
4942 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
4944 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
4945 if(tutoriallevel==1&&id!=0)play=0;
4946 if(play&&aitype!=playercontrolled){
4950 if(creature==rabbittype){
4951 if(i==0)whichsound=rabbitchitter;
4952 if(i==1)whichsound=rabbitchitter2;
4954 if(creature==wolftype){
4955 if(i==0)whichsound=growlsound;
4956 if(i==1)whichsound=growl2sound;
4962 emit_sound_at(whichsound, coords);
4966 if(targetanimation==staggerbackhighanim)staggerdelay=1;
4967 if(targetanimation==staggerbackhardanim)staggerdelay=1;
4968 staggerdelay-=multiplier;
4969 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
4970 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
4971 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
4972 targetanimation=getIdle();
4976 weaponmissdelay-=multiplier;
4977 highreversaldelay-=multiplier;
4978 lowreversaldelay-=multiplier;
4979 lastcollide-=multiplier;
4980 skiddelay-=multiplier;
4981 if(!isnormal(velocity.x)&&velocity.x){
4984 if(!isnormal(targettilt)&&targettilt){
4987 if(!isnormal(targettilt2)&&targettilt2){
4990 if(!isnormal(targetrotation)&&targetrotation){
4994 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
4995 //open hands and close mouth
4996 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4997 righthandmorphness=0;
4998 righthandmorphend=0;
4999 targetrighthandmorphness=1;
5002 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5003 lefthandmorphness=0;
5005 targetlefthandmorphness=1;
5008 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
5011 targetheadmorphness=1;
5015 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){
5016 //open hands and mouth
5017 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5018 righthandmorphness=0;
5019 righthandmorphend=0;
5020 targetrighthandmorphness=1;
5023 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5024 lefthandmorphness=0;
5026 targetlefthandmorphness=1;
5029 if(headmorphend!=1&&headmorphness==targetheadmorphness){
5032 targetheadmorphness=1;
5036 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
5037 //close hands and mouth
5038 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5039 righthandmorphness=0;
5040 righthandmorphend=1;
5041 targetrighthandmorphness=1;
5044 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5045 lefthandmorphness=0;
5047 targetlefthandmorphness=1;
5050 if(headmorphend!=0&&headmorphness==targetheadmorphness){
5053 targetheadmorphness=1;
5057 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){
5058 //close hands and yell
5059 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5060 righthandmorphness=0;
5061 righthandmorphend=1;
5062 targetrighthandmorphness=1;
5065 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5066 lefthandmorphness=0;
5068 targetlefthandmorphness=1;
5071 if(headmorphend!=2&&headmorphness==targetheadmorphness){
5074 targetheadmorphness=1;
5078 if(speechdelay>.25){
5079 if(headmorphend!=2)headmorphness=0;
5081 targetheadmorphness=1;
5087 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
5088 behind=(normaldotproduct(facing,coords-victim->coords)>0);
5092 if(!dead&&targetanimation!=hurtidleanim)
5093 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
5094 if(headmorphend!=4||headmorphness==targetheadmorphness){
5097 targetheadmorphness=1;
5101 if(weaponactive!=-1){
5102 if(weapons.type[weaponids[weaponactive]]!=staff){
5103 righthandmorphstart=1;
5104 righthandmorphend=1;
5106 if(weapons.type[weaponids[weaponactive]]==staff){
5107 righthandmorphstart=2;
5108 righthandmorphend=2;
5110 targetrighthandmorphness=1;
5113 terrainnormal=terrain.getNormal(coords.x,coords.z);
5115 if(animation[targetanimation].attack!=reversal){
5116 if(!isnormal(coords.x))
5124 flatfacing=DoRotation(flatfacing,0,rotation,0);
5126 ReflectVector(&facing,terrainnormal);
5129 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5130 if(onterrain)targettilt2=-facing.y*20;
5134 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5135 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5136 flatvelocity=velocity;
5138 flatvelspeed=findLength(&flatvelocity);
5139 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5140 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5141 if(velocity.y<0)targettilt2*=-1;
5142 if(velocity.y<0)targettilt*=-1;
5143 if(targettilt>25)targettilt=25;
5144 if(targettilt<-25)targettilt=-25;
5147 if(targettilt2>45)targettilt2=45;
5148 if(targettilt2<-45)targettilt2=-45;
5149 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5150 else if(tilt2>targettilt2){
5151 tilt2-=multiplier*400;
5153 else if(tilt2<targettilt2){
5154 tilt2+=multiplier*400;
5156 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5157 if(tilt2>25)tilt2=25;
5158 if(tilt2<-25)tilt2=-25;
5161 if(!isnormal(targettilt)&&targettilt){
5164 if(!isnormal(targettilt2)&&targettilt2){
5169 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5170 if(targetanimation==rabbittackleanim){
5171 velocity+=facing*multiplier*speed*700*scale;
5172 velspeed=findLength(&velocity);
5173 if(velspeed>speed*65*scale){
5175 velspeed=speed*65*scale;
5178 velocity.y+=gravity*multiplier*20;
5179 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5180 velspeed=findLength(&velocity);
5181 velocity=flatfacing*velspeed;
5183 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5184 if(isRun()||targetanimation==rabbitkickanim){
5185 velocity+=facing*multiplier*speed*700*scale;
5186 velspeed=findLength(&velocity);
5187 if(velspeed>speed*45*scale){
5189 velspeed=speed*45*scale;
5192 velocity.y+=gravity*multiplier*20;
5193 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5194 velspeed=findLength(&velocity);
5195 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5196 velocity=flatfacing*velspeed;
5200 velocity+=facing*multiplier*speed*700*scale;
5201 velspeed=findLength(&velocity);
5202 if(creature==rabbittype){
5203 if(velspeed>speed*55*scale){
5205 velspeed=speed*55*scale;
5209 if(creature==wolftype){
5210 if(velspeed>speed*75*scale){
5212 velspeed=speed*75*scale;
5216 velocity.y+=gravity*multiplier*20;
5217 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5218 velspeed=findLength(&velocity);
5219 velocity=flatfacing*velspeed;
5222 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5223 velocity+=facing*multiplier*speed*700*scale;
5224 velspeed=findLength(&velocity);
5225 if(velspeed>speed*45*scale){
5227 velspeed=speed*45*scale;
5230 velocity.y+=gravity*multiplier*20;
5231 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5232 velspeed=findLength(&velocity);
5233 velocity=flatfacing*velspeed;
5237 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5238 velocity+=facing*multiplier*speed*700*scale;
5239 velspeed=findLength(&velocity);
5240 if(velspeed>speed*25*scale){
5242 velspeed=speed*25*scale;
5245 velocity.y+=gravity*multiplier*20;
5246 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5247 velspeed=findLength(&velocity);
5248 velocity=flatfacing*velspeed;
5251 if(targetanimation==sneakanim||targetanimation==walkanim){
5252 velocity+=facing*multiplier*speed*700*scale;
5253 velspeed=findLength(&velocity);
5254 if(velspeed>speed*12*scale){
5256 velspeed=speed*12*scale;
5259 velocity.y+=gravity*multiplier*20;
5260 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5261 velspeed=findLength(&velocity);
5262 velocity=flatfacing*velspeed;
5265 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5266 velocity+=facing*multiplier*speed*700*scale;
5267 velspeed=findLength(&velocity);
5268 if(velspeed>speed*2*scale){
5270 velspeed=speed*2*scale;
5273 velocity.y+=gravity*multiplier*20;
5274 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5275 velspeed=findLength(&velocity);
5276 velocity=flatfacing*velspeed;
5280 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5281 velocity-=facing*multiplier*speed*700*scale;
5282 velspeed=findLength(&velocity);
5283 if(velspeed>speed*2*scale){
5285 velspeed=speed*2*scale;
5288 velocity.y+=gravity*multiplier*20;
5289 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5290 velspeed=findLength(&velocity);
5291 velocity=flatfacing*velspeed*-1;
5294 if(targetanimation==fightsidestep){
5295 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5296 velspeed=findLength(&velocity);
5297 if(velspeed>speed*12*scale){
5299 velspeed=speed*12*scale;
5302 velocity.y+=gravity*multiplier*20;
5303 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5304 velspeed=findLength(&velocity);
5305 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5308 if(targetanimation==staggerbackhighanim){
5309 coords-=facing*multiplier*speed*16*scale;
5312 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5313 coords-=facing*multiplier*speed*20*scale;
5317 if(targetanimation==backhandspringanim){
5318 //coords-=facing*multiplier*50*scale;
5319 velocity+=facing*multiplier*speed*700*scale*-1;
5320 velspeed=findLength(&velocity);
5321 if(velspeed>speed*50*scale){
5323 velspeed=speed*50*scale;
5326 velocity.y+=gravity*multiplier*20;
5327 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5328 velspeed=findLength(&velocity);
5329 velocity=flatfacing*velspeed*-1;
5331 if(targetanimation==dodgebackanim){
5332 //coords-=facing*multiplier*50*scale;
5333 velocity+=facing*multiplier*speed*700*scale*-1;
5334 velspeed=findLength(&velocity);
5335 if(velspeed>speed*60*scale){
5337 velspeed=speed*60*scale;
5340 velocity.y+=gravity*multiplier*20;
5341 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5342 velspeed=findLength(&velocity);
5343 velocity=flatfacing*velspeed*-1;
5346 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5347 velspeed=findLength(&velocity);
5351 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5352 velocity.y+=gravity*multiplier;
5355 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5357 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5358 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5360 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5366 OPENAL_SetPaused(channels[whooshsound], true);
5367 OPENAL_SetVolume(channels[whooshsound], 0);
5370 if(targetanimation==jumpdownanim||isFlip()){
5371 if(isFlip())jumppower=-4;
5372 targetanimation=getLanding();
5373 emit_sound_at(landsound, coords, 128.);
5376 envsound[numenvsounds]=coords;
5377 envsoundvol[numenvsounds]=16;
5378 envsoundlife[numenvsounds]=.4;
5384 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5385 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5386 coords.y=terrain.getHeight(coords.x,coords.z);
5391 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)){
5392 velspeed=findLength(&velocity);
5394 if(velspeed<multiplier*300*scale){
5396 } else velocity-=velocity/velspeed*multiplier*300*scale;
5397 if(velspeed>5&&(isLanding()||isLandhard())){
5398 skiddingdelay+=multiplier;
5405 else skiddingdelay=0;
5409 velspeed=findLength(&velocity);
5411 if(velspeed<multiplier*600*scale){
5413 } else velocity-=velocity/velspeed*multiplier*600*scale;
5415 if(velspeed>5&&(isLanding()||isLandhard())){
5416 skiddingdelay+=multiplier;
5423 else skiddingdelay=0;
5426 if(skiddingdelay<0)skiddingdelay+=multiplier;
5427 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5429 if(!onterrain||environment==grassyenvironment){
5430 emit_sound_at(skidsound, coords, 128*velspeed/10);
5433 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5437 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5438 terrainnormal=victim->coords-coords;
5439 Normalise(&terrainnormal);
5440 targetrotation=-asin(0-terrainnormal.x);
5441 targetrotation*=360/6.28;
5442 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5443 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5446 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5447 targetrotation=victim->targetrotation;
5449 if(targetanimation==rabbittacklinganim){
5450 coords=victim->coords;
5453 skeleton.oldfree=skeleton.free;
5457 midterrain.x=terrain.size*terrain.scale/2;
5458 midterrain.z=terrain.size*terrain.scale/2;
5459 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5461 tempposit=coords-midterrain;
5463 Normalise(&tempposit);
5464 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5465 coords.x=tempposit.x+midterrain.x;
5466 coords.z=tempposit.z+midterrain.z;
5470 int Person::DrawSkeleton(){
5471 int oldplayerdetail;
5472 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5473 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5483 glAlphaFunc(GL_GREATER, 0.0001);
5485 float terrainheight;
5487 if(!isnormal(rotation))rotation=0;
5488 if(!isnormal(tilt))tilt=0;
5489 if(!isnormal(tilt2))tilt2=0;
5490 oldplayerdetail=playerdetail;
5492 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5495 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5498 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5503 if(playerdetail!=oldplayerdetail) {
5505 normalsupdatedelay=0;
5507 static float updatedelaychange;
5508 static float morphness;
5509 static float framemult;
5511 skeleton.FindForwards();
5512 if(howactive==typesittingwall){
5513 skeleton.specialforward[1]=0;
5514 skeleton.specialforward[1].z=1;
5520 static int weaponattachmuscle;
5521 static int weaponrotatemuscle,weaponrotatemuscle2;
5522 static XYZ weaponpoint;
5523 static int start,endthing;
5524 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5525 if(!isSleeping()&&!isSitting()){
5526 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5527 XYZ point,newpoint,change,change2;
5528 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5529 heightleft=terrain.getHeight(point.x,point.z)+.04;
5531 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5532 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5533 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5534 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5535 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5537 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5538 heightright=terrain.getHeight(point.x,point.z)+.04;
5539 point.y=heightright;
5540 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5541 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5542 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5543 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5544 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5545 skeleton.DoConstraints(&coords,&scale);
5547 if(creature==wolftype){
5548 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5549 heightleft=terrain.getHeight(point.x,point.z)+.04;
5551 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5552 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5553 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5554 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5555 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5557 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5558 heightright=terrain.getHeight(point.x,point.z)+.04;
5559 point.y=heightright;
5560 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5561 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5562 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5563 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5564 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5565 skeleton.DoConstraints(&coords,&scale);
5568 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5569 XYZ point,newpoint,change,change2;
5570 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5571 heightleft=terrain.getHeight(point.x,point.z)+.04;
5573 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5574 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5575 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5576 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5577 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5579 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5580 heightright=terrain.getHeight(point.x,point.z)+.04;
5581 point.y=heightright;
5582 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5583 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5584 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5585 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5586 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5587 skeleton.DoConstraints(&coords,&scale);
5589 if(creature==wolftype){
5590 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5591 heightleft=terrain.getHeight(point.x,point.z)+.04;
5593 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5594 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5595 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5596 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5597 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5599 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5600 heightright=terrain.getHeight(point.x,point.z)+.04;
5601 point.y=heightright;
5602 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5603 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5604 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5605 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5606 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5607 skeleton.DoConstraints(&coords,&scale);
5611 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5612 XYZ point,newpoint,change,change2;
5613 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5614 heightleft=terrain.getHeight(point.x,point.z)+.04;
5616 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5617 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5618 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5619 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5620 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5622 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5623 heightright=terrain.getHeight(point.x,point.z)+.04;
5624 point.y=heightright;
5625 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5626 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5627 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5628 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5629 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5630 skeleton.DoConstraints(&coords,&scale);
5632 if(creature==wolftype){
5633 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5634 heightleft=terrain.getHeight(point.x,point.z)+.04;
5636 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5637 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5638 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5639 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5640 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5642 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5643 heightright=terrain.getHeight(point.x,point.z)+.04;
5644 point.y=heightright;
5645 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5646 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5647 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5648 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5649 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5650 skeleton.DoConstraints(&coords,&scale);
5654 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()))
5657 targetheadrotation=-targetrotation;
5658 targetheadrotation2=0;
5659 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5661 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5662 skeleton.drawmodel.vertex[i]=0;
5663 skeleton.drawmodel.vertex[i].y=999;
5665 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5666 skeleton.drawmodellow.vertex[i]=0;
5667 skeleton.drawmodellow.vertex[i].y=999;
5669 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5670 skeleton.drawmodelclothes.vertex[i]=0;
5671 skeleton.drawmodelclothes.vertex[i].y=999;
5673 for(i=0;i<skeleton.num_muscles;i++){
5674 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5678 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5679 morphness=righthandmorphness;
5680 start=righthandmorphstart;
5681 endthing=righthandmorphend;
5683 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5684 morphness=lefthandmorphness;
5685 start=lefthandmorphstart;
5686 endthing=lefthandmorphend;
5688 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5689 morphness=headmorphness;
5690 start=headmorphstart;
5691 endthing=headmorphend;
5693 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)){
5694 morphness=chestmorphness;
5695 start=chestmorphstart;
5696 endthing=chestmorphend;
5698 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)){
5699 morphness=tailmorphness;
5700 start=tailmorphstart;
5701 endthing=tailmorphend;
5703 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5704 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5705 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5708 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5709 if(!skeleton.free)glRotatef(tilt,0,0,1);
5712 glTranslatef(mid.x,mid.y,mid.z);
5714 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5715 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5717 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5718 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5720 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5721 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5723 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
5727 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
5731 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
5735 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
5740 if(playerdetail||skeleton.free==3)
5742 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5744 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
5745 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
5746 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
5747 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
5748 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
5749 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
5750 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
5751 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5753 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5754 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,
5755 (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,
5756 (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);
5757 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)
5758 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,
5759 (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,
5760 (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);
5761 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)
5762 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,
5763 (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,
5764 (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);
5765 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5766 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,
5767 (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,
5768 (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);
5769 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5770 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5771 //if(!isnormal(scale))test=1;
5772 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5773 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5774 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5779 if(!playerdetail||skeleton.free==3)
5781 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5783 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5785 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5786 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5787 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5788 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5789 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)
5790 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5791 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5792 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5793 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)
5794 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5795 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5796 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5797 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5798 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5799 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5800 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5802 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5803 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5804 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5805 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5811 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5812 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5814 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5817 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5818 if(!skeleton.free)glRotatef(tilt,0,0,1);
5819 glTranslatef(mid.x,mid.y,mid.z);
5820 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5821 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5823 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5824 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5826 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5827 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5829 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5830 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5832 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5833 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5834 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5835 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5836 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)
5837 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5838 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5839 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5840 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)
5841 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5842 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5843 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5844 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5845 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5846 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5847 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5848 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5849 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5850 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5851 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5856 updatedelay=1+(float)(Random()%100)/1000;
5858 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5859 normalsupdatedelay=1;
5860 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5861 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5862 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5866 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5867 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5868 if(skeleton.clothes){
5869 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5874 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5875 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5876 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5877 if(skeleton.free==1)updatedelaychange*=6;
5878 if(id==0)updatedelaychange*=8;
5879 updatedelay+=updatedelaychange;
5881 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5883 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5884 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5885 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5886 if(!skeleton.free)glRotatef(rotation,0,1,0);
5889 glColor4f(.4,1,.4,1);
5890 glDisable(GL_LIGHTING);
5891 glDisable(GL_TEXTURE_2D);
5894 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5895 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5901 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5902 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);
5903 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);
5904 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);
5905 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);
5906 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);
5907 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);
5913 terrainlight=terrain.getLighting(coords.x,coords.z);
5914 distance=findDistancefast(&viewer,&coords);
5915 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5916 if(distance>1)distance=1;
5918 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5919 if(terrainheight<1)terrainheight=1;
5920 if(terrainheight>1.7)terrainheight=1.7;
5923 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5924 glDisable(GL_BLEND);
5925 glAlphaFunc(GL_GREATER, 0.0001);
5926 glEnable(GL_TEXTURE_2D);
5928 glDisable(GL_TEXTURE_2D);
5929 glColor4f(.7,.35,0,.5);
5931 glEnable(GL_LIGHTING);
5934 if(tutoriallevel&&id!=0){
5935 //glDisable(GL_TEXTURE_2D);
5936 glColor4f(.7,.7,.7,0.6);
5938 glEnable(GL_LIGHTING);
5940 if(canattack&&cananger)
5941 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5942 glDisable(GL_TEXTURE_2D);
5943 glColor4f(1,0,0,0.8);
5945 glMatrixMode(GL_TEXTURE);
5947 glTranslatef(0,-smoketex,0);
5948 glTranslatef(-smoketex,0,0);
5952 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5953 else skeleton.drawmodel.draw();
5957 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5958 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5961 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
5962 if(tutoriallevel&&id!=0){
5964 glMatrixMode(GL_MODELVIEW);
5965 glEnable(GL_TEXTURE_2D);
5966 glColor4f(.7,.7,.7,0.6);
5968 glEnable(GL_LIGHTING);
5970 if(canattack&&cananger)
5971 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5972 glDisable(GL_TEXTURE_2D);
5973 glColor4f(1,0,0,0.8);
5975 glMatrixMode(GL_TEXTURE);
5977 glTranslatef(0,-smoketex*.6,0);
5978 glTranslatef(smoketex*.6,0,0);
5981 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5982 else skeleton.drawmodel.draw();
5986 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5987 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5992 if(tutoriallevel&&id!=0){
5994 glMatrixMode(GL_MODELVIEW);
5995 glEnable(GL_TEXTURE_2D);
5997 if(skeleton.clothes){
6000 if(!immediate)skeleton.drawmodelclothes.draw();
6001 if(immediate)skeleton.drawmodelclothes.drawimmediate();
6008 for(k=0;k<num_weapons;k++){
6010 if(weaponactive==k){
6011 if(weapons.type[i]!=staff){
6012 for(j=0;j<skeleton.num_muscles;j++){
6013 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6014 weaponattachmuscle=j;
6017 for(j=0;j<skeleton.num_muscles;j++){
6018 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){
6019 weaponrotatemuscle=j;
6022 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6023 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
6025 if(weapons.type[i]==staff){
6026 for(j=0;j<skeleton.num_muscles;j++){
6027 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6028 weaponattachmuscle=j;
6031 for(j=0;j<skeleton.num_muscles;j++){
6032 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){
6033 weaponrotatemuscle=j;
6036 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
6037 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6038 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6039 XYZ tempnormthing,vec1,vec2;
6040 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6041 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
6042 CrossProduct(&vec1,&vec2,&tempnormthing);
6043 Normalise(&tempnormthing);
6044 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);
6045 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
6047 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
6048 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6049 Normalise(&weaptargnorm);
6050 weaponpoint-=weaptargnorm*2;
6054 if(weaponactive!=k&&weaponstuck!=k){
6055 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;
6056 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;
6057 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;
6058 for(j=0;j<skeleton.num_muscles;j++){
6059 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){
6060 weaponrotatemuscle=j;
6065 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
6066 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
6067 for(j=0;j<skeleton.num_muscles;j++){
6068 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){
6069 weaponrotatemuscle=j;
6074 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;
6075 weapons.bigrotation[i]=rotation;
6076 weapons.bigtilt[i]=tilt;
6077 weapons.bigtilt2[i]=tilt2;
6080 weapons.position[i]=weaponpoint*scale+coords;
6081 weapons.bigrotation[i]=0;
6082 weapons.bigtilt[i]=0;
6083 weapons.bigtilt2[i]=0;
6085 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
6086 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
6087 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
6088 if(weaponactive==k){
6089 if(weapons.type[i]==knife){
6090 weapons.smallrotation[i]=180;
6091 weapons.smallrotation2[i]=0;
6092 if(isCrouch()||wasCrouch()){
6093 weapons.smallrotation2[i]=20;
6095 if(targetanimation==hurtidleanim){
6096 weapons.smallrotation2[i]=50;
6098 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
6099 XYZ temppoint1,temppoint2,tempforward;
6102 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6103 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6104 distance=findDistance(&temppoint1,&temppoint2);
6105 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6106 weapons.rotation2[i]*=360/6.28;
6109 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6110 weapons.rotation1[i]*=360/6.28;
6111 weapons.rotation3[i]=0;
6112 weapons.smallrotation[i]=-90;
6113 weapons.smallrotation2[i]=0;
6114 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6116 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
6117 XYZ temppoint1,temppoint2,tempforward;
6120 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6121 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6122 distance=findDistance(&temppoint1,&temppoint2);
6123 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6124 weapons.rotation2[i]*=360/6.28;
6127 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6128 weapons.rotation1[i]*=360/6.28;
6129 weapons.rotation3[i]=0;
6130 weapons.smallrotation[i]=90;
6131 weapons.smallrotation2[i]=0;
6132 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6134 if(targetanimation==knifethrowanim){
6135 weapons.smallrotation[i]=90;
6136 //weapons.smallrotation2[i]=-90;
6137 weapons.smallrotation2[i]=0;
6138 weapons.rotation1[i]=0;
6139 weapons.rotation2[i]=0;
6140 weapons.rotation3[i]=0;
6142 if(targetanimation==knifesneakattackanim&&targetframe<5){
6143 weapons.smallrotation[i]=-90;
6144 weapons.rotation1[i]=0;
6145 weapons.rotation2[i]=0;
6146 weapons.rotation3[i]=0;
6149 if(weapons.type[i]==sword){
6150 weapons.smallrotation[i]=0;
6151 weapons.smallrotation2[i]=0;
6152 if(targetanimation==knifethrowanim){
6153 weapons.smallrotation[i]=-90;
6154 weapons.smallrotation2[i]=0;
6155 weapons.rotation1[i]=0;
6156 weapons.rotation2[i]=0;
6157 weapons.rotation3[i]=0;
6159 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)){
6160 XYZ temppoint1,temppoint2,tempforward;
6163 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6164 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6165 distance=findDistance(&temppoint1,&temppoint2);
6166 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6167 weapons.rotation2[i]*=360/6.28;
6170 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6171 weapons.rotation1[i]*=360/6.28;
6172 weapons.rotation3[i]=0;
6173 weapons.smallrotation[i]=90;
6174 weapons.smallrotation2[i]=0;
6175 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6178 if(weapons.type[i]==staff){
6179 weapons.smallrotation[i]=100;
6180 weapons.smallrotation2[i]=0;
6181 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6182 XYZ temppoint1,temppoint2,tempforward;
6185 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6186 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6187 distance=findDistance(&temppoint1,&temppoint2);
6188 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6189 weapons.rotation2[i]*=360/6.28;
6192 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6193 weapons.rotation1[i]*=360/6.28;
6194 weapons.rotation3[i]=0;
6195 weapons.smallrotation[i]=90;
6196 weapons.smallrotation2[i]=0;
6197 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6201 if(weaponactive!=k&&weaponstuck!=k){
6202 if(weapons.type[i]==knife){
6203 weapons.smallrotation[i]=-70;
6204 weapons.smallrotation2[i]=10;
6206 if(weapons.type[i]==sword){
6207 weapons.smallrotation[i]=-100;
6208 weapons.smallrotation2[i]=-8;
6210 if(weapons.type[i]==staff){
6211 weapons.smallrotation[i]=-100;
6212 weapons.smallrotation2[i]=-8;
6216 if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
6217 else weapons.smallrotation[i]=0;
6218 weapons.smallrotation2[i]=10;
6225 if(skeleton.free)calcrot=1;
6226 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6227 if(currentanimation!=targetanimation)calcrot=1;
6228 //if(id==0)calcrot=1;
6229 if(skeleton.free==2)calcrot=0;
6235 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6238 static float distance;
6239 static float olddistance;
6240 static int intersecting;
6241 static int firstintersecting;
6244 static XYZ start,end;
6245 static float slopethreshold=-.4;
6247 firstintersecting=-1;
6251 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6252 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6254 for (j=0;j<model->TriangleNum;j++){
6255 if(model->facenormals[j].y<=slopethreshold){
6257 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)));
6258 if(distance<radius){
6259 point=*p1-model->facenormals[j]*distance;
6260 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;
6261 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6262 &model->vertex[model->Triangles[j].vertex[1]],
6264 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6265 &model->vertex[model->Triangles[j].vertex[2]],
6267 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6268 &model->vertex[model->Triangles[j].vertex[2]],
6271 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6275 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)){
6276 p1->y=point.y+radius;
6277 if((targetanimation==jumpdownanim||isFlip())){
6278 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6280 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6286 OPENAL_SetPaused(channels[whooshsound], true);
6287 OPENAL_SetVolume(channels[whooshsound], 0);
6290 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6291 if(isFlip())jumppower=-4;
6292 targetanimation=getLanding();
6293 emit_sound_at(landsound, coords, 128.);
6296 envsound[numenvsounds]=coords;
6297 envsoundvol[numenvsounds]=16;
6298 envsoundlife[numenvsounds]=.4;
6306 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6309 for (j=0;j<model->TriangleNum;j++){
6310 if(model->facenormals[j].y>slopethreshold){
6314 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)));
6315 if(distance<radius*.5){
6316 point=start-model->facenormals[j]*distance;
6317 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;
6318 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,
6319 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6320 p1->x, p1->y, p1->z, radius/2);
6321 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,
6322 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6323 p1->x, p1->y, p1->z, radius/2);
6324 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,
6325 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6326 p1->x, p1->y, p1->z, radius/2);
6328 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6329 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6331 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6332 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6334 *p1+=model->facenormals[j]*(distance-radius*.5);
6337 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6341 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6343 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6345 return firstintersecting;