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 Terrain terrain;
33 extern int environment;
35 extern FRUSTUM frustum;
37 extern float realmultiplier;
39 extern float slomodelay;
40 extern bool cellophane;
41 extern float texdetail;
42 extern float realtexdetail;
43 extern GLubyte bloodText[512*512*3];
44 extern GLubyte wolfbloodText[512*512*3];
45 extern int bloodtoggle;
46 extern Objects objects;
48 extern bool autoslomo;
49 extern float camerashake;
51 extern float viewdistance;
52 extern float blackout;
53 extern int difficulty;
55 extern float fadestart;
57 extern bool winfreeze;
58 extern float flashamount,flashr,flashg,flashb;
59 extern int flashdelay;
60 extern bool showpoints;
61 extern bool immediate;
63 extern bool tilt2weird;
64 extern bool tiltweird;
66 extern bool proportionweird;
67 extern bool vertexweird[6];
68 extern XYZ envsound[30];
69 extern float envsoundvol[30];
70 extern float envsoundlife[30];
71 extern int numenvsounds;
72 extern int tutoriallevel;
73 extern float smoketex;
74 extern int tutorialstage;
75 extern bool reversaltrain;
76 extern bool canattack;
78 extern float damagedealt;
80 extern float hostiletime;
82 extern int indialogue;
84 extern bool gamestarted;
86 Person player[maxplayers];
88 void Person::CheckKick()
91 && (targetanimation == rabbitkickanim
95 && currentanimation == rabbitkickanim)
96 && (findDistancefast(&coords,&victim->coords) < 1.2)
97 && (!victim->skeleton.free)))
100 if (animation[victim->targetanimation].height!=lowheight)
102 float damagemult = (creature == wolftype ? 2.5 : 1.) * power * power;
103 XYZ relative = velocity;
105 Normalise(&relative);
110 emit_sound_at(heavyimpactsound, victim->coords);
112 for(int i=0;i<victim->skeleton.num_joints;i++){
113 victim->skeleton.joints[i].velocity+=relative*120*damagemult;
116 victim->DoDamage(100*damagemult/victim->protectionhigh);
117 if(id==0)camerashake+=.4;
121 targetanimation=backflipanim;
127 resume_stream(whooshsound);
129 award_bonus(id, cannon);
131 else if (victim->isCrouch())
133 targetanimation=rabbitkickreversedanim;
134 currentanimation=rabbitkickreversedanim;
135 victim->currentanimation=rabbitkickreversalanim;
136 victim->targetanimation=rabbitkickreversalanim;
142 victim->oldcoords=victim->coords;
143 coords=victim->coords;
144 victim->targetyaw=targetyaw;
149 void Person::CatchFire(){
150 XYZ flatfacing,flatvelocity;
152 for(int i=0;i<10;i++){
153 howmany=abs(Random()%(skeleton.num_joints));
154 if(!skeleton.free)flatvelocity=velocity;
155 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity;
156 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,yaw,0)*scale+coords;
157 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
158 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, 2, 1);
163 emit_sound_at(firestartsound, coords);
165 emit_stream_at(stream_firesound, coords);
172 int Person::getIdle(){
173 if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
174 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)){
175 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
176 if(creature==rabbittype)return fightidleanim;
177 if(creature==wolftype)return wolfidle;
179 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
180 if(weapons[weaponids[weaponactive]].getType()==knife)
181 return knifefightidleanim;
182 if(weapons[weaponids[weaponactive]].getType()==sword&&victim->weaponactive!=-1)
183 return swordfightidlebothanim;
184 if(weapons[weaponids[weaponactive]].getType()==sword)
185 return swordfightidleanim;
186 if(weapons[weaponids[weaponactive]].getType()==staff)
187 return swordfightidleanim;
189 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
191 if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
192 if(howactive==typesitting)return sitanim;
193 if(howactive==typesittingwall)return sitwallanim;
194 if(howactive==typesleeping)return sleepanim;
195 if(howactive==typedead1)return dead1anim;
196 if(howactive==typedead2)return dead2anim;
197 if(howactive==typedead3)return dead3anim;
198 if(howactive==typedead4)return dead4anim;
199 if(creature==rabbittype)return bounceidleanim;
200 if(creature==wolftype)return wolfidle;
204 int Person::getCrouch(){
205 if(creature==rabbittype)return crouchanim;
206 if(creature==wolftype)return wolfcrouchanim;
210 int Person::getRun(){
211 if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
212 if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
214 if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
215 if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
219 int Person::getStop(){
220 if(creature==rabbittype)return stopanim;
221 if(creature==wolftype)return wolfstopanim;
225 int Person::getLanding(){
226 if(creature==rabbittype)return landanim;
227 if(creature==wolftype)return wolflandanim;
231 int Person::getLandhard(){
232 if(creature==rabbittype)return landhardanim;
233 if(creature==wolftype)return wolflandhardanim;
238 SolidHitBonus(int playerid)
240 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
241 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
243 award_bonus(playerid, solidhit);
246 void Person::DoBlood(float howmuch,int which){
247 static int bleedxint,bleedyint;
249 //if(howmuch&&id==0)blooddimamount=1;
250 if(bloodtoggle&&tutoriallevel!=1){
251 if(bleeding<=0&&spurt){
253 for(int i=0;i<3;i++){
257 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
260 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
262 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
263 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
265 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
266 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
269 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
270 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
274 for(int i=0;i<3;i++){
278 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
279 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
282 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
283 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
287 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
289 Sprite::MakeSprite(splintersprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
291 Sprite::setLastSpriteSpecial(3);
296 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
299 if(creature==rabbittype)
300 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){
301 bleedxint=abs(Random()%512);
302 bleedyint=abs(Random()%512);
304 if(creature==wolftype)
305 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){
306 bleedxint=abs(Random()%512);
307 bleedyint=abs(Random()%512);
311 bleedy/=realtexdetail;
312 bleedx/=realtexdetail;
313 direction=abs(Random()%2)*2-1;
317 if(bleeding>2)bleeding=2;
320 void Person::DoBloodBig(float howmuch,int which){
321 static int bleedxint,bleedyint,i,j;
323 if(howmuch&&id==0)blooddimamount=1;
325 if(tutoriallevel!=1||id==0)
326 if(aitype!=playercontrolled&&howmuch>0){
329 if(creature==wolftype){
330 int i=abs(Random()%2);
331 if(i==0)whichsound=snarlsound;
332 if(i==1)whichsound=snarl2sound;
333 envsound[numenvsounds]=coords;
334 envsoundvol[numenvsounds]=16;
335 envsoundlife[numenvsounds]=.4;
338 if(creature==rabbittype){
339 int i=abs(Random()%2);
340 if(i==0)whichsound=rabbitpainsound;
341 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
342 envsound[numenvsounds]=coords;
343 envsoundvol[numenvsounds]=16;
344 envsoundlife[numenvsounds]=.4;
346 //if(i==2)whichsound=rabbitpain2sound;
350 emit_sound_at(whichsound, coords);
353 if(id==0&&howmuch>0){
361 if(bloodtoggle&&decals&&tutoriallevel!=1){
362 if(bleeding<=0&&spurt){
364 for(int i=0;i<3;i++){
368 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
371 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
373 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
374 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
376 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
377 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
380 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
381 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
385 int offsetx=0,offsety=0;
388 offsetx=abs(Random()%60);
390 if(which==190||which==185){
392 offsetx=abs(Random()%100)-20;
402 if(which==220||which==215){
412 if(creature==rabbittype)
415 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
416 if(i<startx)startx=i;
417 if(j<starty)starty=j;
423 if(creature==wolftype)
426 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
427 if(i<startx)startx=i;
428 if(j<starty)starty=j;
440 if(startx<0)startx=0;
441 if(starty<0)starty=0;
442 if(endx>512-1)endx=512-1;
443 if(endy>512-1)endy=512-1;
444 if(endx<startx)endx=startx;
445 if(endy<starty)endy=starty;
447 startx/=realtexdetail;
448 starty/=realtexdetail;
452 int texdetailint=realtexdetail;
454 if(creature==rabbittype)
455 for(i=startx;i<endx;i++){
456 for(j=starty;j<endy;j++){
457 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){
458 color=Random()%85+170;
459 where=i*skeleton.skinsize*3+j*3;
460 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
461 skeleton.skinText[where+1]=0;
462 skeleton.skinText[where+2]=0;
466 if(creature==wolftype)
467 for(i=startx;i<endx;i++){
468 for(j=starty;j<endy;j++){
469 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){
470 color=Random()%85+170;
471 where=i*skeleton.skinsize*3+j*3;
472 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
473 skeleton.skinText[where+1]=0;
474 skeleton.skinText[where+2]=0;
478 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
483 if(creature==rabbittype)
484 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){
485 bleedxint=abs(Random()%512);
486 bleedyint=abs(Random()%512);
488 if(creature==wolftype)
489 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){
490 bleedxint=abs(Random()%512);
491 bleedyint=abs(Random()%512);
493 bleedy=bleedxint+offsetx;
494 bleedx=bleedyint+offsety;
495 bleedy/=realtexdetail;
496 bleedx/=realtexdetail;
497 if(bleedx<0)bleedx=0;
498 if(bleedy<0)bleedy=0;
499 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
500 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
501 direction=abs(Random()%2)*2-1;
504 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
505 deathbleeding+=bleeding;
506 bloodloss+=bleeding*3;
508 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
509 if(abs(Random()%2)==0){aitype=gethelptype;
512 else aitype=attacktypecutoff;
515 if(bleeding>2)bleeding=2;
518 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
521 static XYZ startpoint,endpoint,colpoint,movepoint;
522 static float rotationpoint;
524 static XYZ p1,p2,p3,p0;
528 float coordsx,coordsy;
531 if(bloodtoggle&&decals&&tutoriallevel!=1){
533 if(!skeleton.free)where=DoRotation(where,0,-yaw,0);
541 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
544 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
545 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
546 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
548 CrossProduct(p2-p1,p3-p1,&N);
549 CrossProduct(p0-p1,p3-p1,&temp);
550 s = dotproduct(&temp,&N)/findLength(&N);
551 CrossProduct(p2-p1,p1-p0,&temp);
552 t = dotproduct(&temp,&N)/findLength(&N);
555 bary.x=findDistancefast(&p0,&p1);
556 bary.y=findDistancefast(&p0,&p2);
557 bary.z=findDistancefast(&p0,&p3);
559 total=bary.x+bary.y+bary.z;
568 total=bary.x+bary.y+bary.z;
574 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
575 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
576 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
577 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
578 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
579 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
580 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;
581 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;
583 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
584 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
586 if(bleeding<=0&&spurt){
588 for(int i=0;i<3;i++){
592 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
595 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
597 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
598 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
600 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
601 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
604 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
605 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
609 int offsetx=0,offsety=0;
612 offsetx=abs(Random()%120);
614 if(which==220||which==215){
616 offsetx=abs(Random()%80);
619 offsetx=(1+coordsy)*512-291;
620 offsety=coordsx*512-437;
627 if(creature==rabbittype)
630 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
631 if(i<startx)startx=i;
632 if(j<starty)starty=j;
638 if(creature==wolftype)
641 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
642 if(i<startx)startx=i;
643 if(j<starty)starty=j;
654 if(startx<0)startx=0;
655 if(starty<0)starty=0;
656 if(endx>512-1)endx=512-1;
657 if(endy>512-1)endy=512-1;
658 if(endx<startx)endx=startx;
659 if(endy<starty)endy=starty;
661 startx/=realtexdetail;
662 starty/=realtexdetail;
666 int texdetailint=realtexdetail;
668 if(creature==rabbittype)
669 for(i=startx;i<endx;i++){
670 for(j=starty;j<endy;j++){
671 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){
672 color=Random()%85+170;
673 where=i*skeleton.skinsize*3+j*3;
674 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
675 skeleton.skinText[where+1]=0;
676 skeleton.skinText[where+2]=0;
678 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){
679 color=Random()%85+170;
680 where=i*skeleton.skinsize*3+j*3;
681 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
682 skeleton.skinText[where+1]=0;
683 skeleton.skinText[where+2]=0;
687 if(creature==wolftype)
688 for(i=startx;i<endx;i++){
689 for(j=starty;j<endy;j++){
690 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){
691 color=Random()%85+170;
692 where=i*skeleton.skinsize*3+j*3;
693 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
694 skeleton.skinText[where+1]=0;
695 skeleton.skinText[where+2]=0;
697 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){
698 color=Random()%85+170;
699 where=i*skeleton.skinsize*3+j*3;
700 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
701 skeleton.skinText[where+1]=0;
702 skeleton.skinText[where+2]=0;
706 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
709 bleedy=(1+coordsy)*512;
711 bleedy/=realtexdetail;
712 bleedx/=realtexdetail;
713 if(bleedx<0)bleedx=0;
714 if(bleedy<0)bleedy=0;
715 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
716 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
717 direction=abs(Random()%2)*2-1;
719 if(whichtri==-1)return 0;
721 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
722 deathbleeding+=bleeding;
723 bloodloss+=bleeding*3;
725 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
726 if(abs(Random()%2)==0){aitype=gethelptype;
729 else aitype=attacktypecutoff;
732 if(bleeding>2)bleeding=2;
738 void Person::Reverse()
740 if (!((victim->aitype == playercontrolled
742 || staggerdelay <= 0)
743 && victim->targetanimation != jumpupanim
744 && victim->targetanimation != jumpdownanim
745 && (tutoriallevel != 1 || cananger)
749 if (normaldotproduct (victim->facing, victim->coords-coords) > 0
750 && (victim->id != 0 || difficulty >= 2)
751 && (creature != wolftype || victim->creature == wolftype))
754 if(targetanimation==sweepanim){
755 targetanimation=sweepreversedanim;
756 currentanimation=sweepreversedanim;
757 victim->currentanimation=sweepreversalanim;
758 victim->targetanimation=sweepreversalanim;
760 if(targetanimation==spinkickanim){
761 targetanimation=spinkickreversedanim;
762 currentanimation=spinkickreversedanim;
763 victim->currentanimation=spinkickreversalanim;
764 victim->targetanimation=spinkickreversalanim;
766 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
767 if(targetanimation==rabbittacklinganim){
770 victim->currentframe=6;
771 victim->targetframe=7;
773 targetanimation=upunchreversedanim;
774 currentanimation=upunchreversedanim;
775 victim->currentanimation=upunchreversalanim;
776 victim->targetanimation=upunchreversalanim;
778 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
779 if(victim->weaponactive!=-1){
780 victim->throwtogglekeydown=1;
781 weapons[victim->weaponids[0]].owner=-1;
782 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
783 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
784 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
785 weapons[victim->weaponids[0]].missed=1;
786 weapons[victim->weaponids[0]].freetime=0;
787 weapons[victim->weaponids[0]].firstfree=1;
788 weapons[victim->weaponids[0]].physics=1;
789 victim->num_weapons--;
790 if(victim->num_weapons){
791 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
792 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
795 victim->weaponactive=-1;
796 for(int j=0;j<numplayers;j++){
797 player[j].wentforweapon=0;
801 targetanimation=staffhitreversedanim;
802 currentanimation=staffhitreversedanim;
803 victim->currentanimation=staffhitreversalanim;
804 victim->targetanimation=staffhitreversalanim;
806 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
807 if(victim->weaponactive!=-1){
808 victim->throwtogglekeydown=1;
809 weapons[victim->weaponids[0]].owner=-1;
810 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
811 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
812 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
813 weapons[victim->weaponids[0]].missed=1;
814 weapons[victim->weaponids[0]].freetime=0;
815 weapons[victim->weaponids[0]].firstfree=1;
816 weapons[victim->weaponids[0]].physics=1;
817 victim->num_weapons--;
818 if(victim->num_weapons){
819 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
820 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
823 victim->weaponactive=-1;
824 for(int j=0;j<numplayers;j++){
825 player[j].wentforweapon=0;
828 targetanimation=staffspinhitreversedanim;
829 currentanimation=staffspinhitreversedanim;
830 victim->currentanimation=staffspinhitreversalanim;
831 victim->targetanimation=staffspinhitreversalanim;
833 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
834 if(victim->weaponactive!=-1){
835 victim->throwtogglekeydown=1;
836 weapons[victim->weaponids[0]].owner=-1;
837 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
838 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
839 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
840 weapons[victim->weaponids[0]].missed=1;
841 weapons[victim->weaponids[0]].freetime=0;
842 weapons[victim->weaponids[0]].firstfree=1;
843 weapons[victim->weaponids[0]].physics=1;
844 victim->num_weapons--;
845 if(victim->num_weapons){
846 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
847 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
850 victim->weaponactive=-1;
851 for(int j=0;j<numplayers;j++){
852 player[j].wentforweapon=0;
855 targetanimation=swordslashreversedanim;
856 currentanimation=swordslashreversedanim;
857 victim->currentanimation=swordslashreversalanim;
858 victim->targetanimation=swordslashreversalanim;
860 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
861 if(victim->weaponactive!=-1){
862 victim->throwtogglekeydown=1;
863 weapons[victim->weaponids[0]].owner=-1;
864 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
865 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
866 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
867 weapons[victim->weaponids[0]].missed=1;
868 weapons[victim->weaponids[0]].freetime=0;
869 weapons[victim->weaponids[0]].firstfree=1;
870 weapons[victim->weaponids[0]].physics=1;
871 victim->num_weapons--;
872 if(victim->num_weapons){
873 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
874 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
877 victim->weaponactive=-1;
878 for(int j=0;j<numplayers;j++){
879 player[j].wentforweapon=0;
882 targetanimation=knifeslashreversedanim;
883 currentanimation=knifeslashreversedanim;
884 victim->currentanimation=knifeslashreversalanim;
885 victim->targetanimation=knifeslashreversalanim;
887 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
888 victim->targettilt2=targettilt2;
889 victim->currentframe=currentframe;
890 victim->targetframe=targetframe;
891 victim->target=target;
893 victim->oldcoords=victim->coords;
894 victim->coords=coords;
895 victim->targetyaw=targetyaw;
896 victim->yaw=targetyaw;
899 if(targetanimation==winduppunchanim){
900 targetanimation=winduppunchblockedanim;
901 victim->targetanimation=blockhighleftanim;
902 victim->targetframe=1;
905 victim->targetyaw=targetyaw+180;
907 if(targetanimation==wolfslapanim){
908 targetanimation=winduppunchblockedanim;
909 victim->targetanimation=blockhighleftanim;
910 victim->targetframe=1;
913 victim->targetyaw=targetyaw+180;
915 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
916 targetanimation=swordslashparriedanim;
918 victim->parriedrecently=0;
919 victim->targetanimation=swordslashparryanim;
920 victim->targetframe=1;
923 victim->targetyaw=targetyaw+180;
925 if(abs(Random()%20)==0||weapons[victim->weaponids[victim->weaponactive]].getType()==knife){
926 if(victim->weaponactive!=-1){
927 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff) {
928 if(weapons[victim->weaponids[0]].getType()==staff)
929 weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
930 if(weapons[weaponids[0]].getType()==staff)
931 weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
932 emit_sound_at(swordstaffsound, victim->coords);
935 emit_sound_at(metalhitsound, victim->coords);
939 victim->Puff(righthand);
941 victim->targetframe=0;
942 victim->targetanimation=staggerbackhighanim;
943 victim->targetyaw=targetyaw+180;
945 weapons[victim->weaponids[0]].owner=-1;
946 aim=DoRotation(facing,0,90,0)*21;
948 weapons[victim->weaponids[0]].velocity=aim*-.2;
949 weapons[victim->weaponids[0]].tipvelocity=aim;
950 weapons[victim->weaponids[0]].missed=1;
951 weapons[victim->weaponids[0]].hitsomething=0;
952 weapons[victim->weaponids[0]].freetime=0;
953 weapons[victim->weaponids[0]].firstfree=1;
954 weapons[victim->weaponids[0]].physics=1;
955 victim->num_weapons--;
956 if(victim->num_weapons){
957 victim->weaponids[0]=victim->weaponids[num_weapons];
958 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
960 victim->weaponactive=-1;
961 for(int i=0;i<numplayers;i++){
962 player[i].wentforweapon=0;
966 if(abs(Random()%20)==0){
967 if(weaponactive!=-1){
968 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
969 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
970 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
972 emit_sound_at(swordstaffsound, coords);
975 emit_sound_at(metalhitsound, coords);
983 targetanimation=staggerbackhighanim;
984 targetyaw=targetyaw+180;
986 weapons[weaponids[0]].owner=-1;
987 aim=DoRotation(facing,0,90,0)*21;
989 weapons[weaponids[0]].velocity=aim*-.2;
990 weapons[weaponids[0]].tipvelocity=aim;
991 weapons[weaponids[0]].hitsomething=0;
992 weapons[weaponids[0]].missed=1;
993 weapons[weaponids[0]].freetime=0;
994 weapons[weaponids[0]].firstfree=1;
995 weapons[weaponids[0]].physics=1;
998 weaponids[0]=weaponids[num_weapons];
999 if(weaponstuck==num_weapons)weaponstuck=0;
1002 for(int i=0;i<numplayers;i++){
1003 player[i].wentforweapon=0;
1010 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1011 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1012 victim->targetanimation=dodgebackanim;
1013 victim->targetframe=0;
1017 rotatetarget=coords-victim->coords;
1018 Normalise(&rotatetarget);
1019 victim->targetyaw=-asin(0-rotatetarget.x);
1020 victim->targetyaw*=360/6.28;
1021 if(rotatetarget.z<0)victim->targetyaw=180-victim->targetyaw;
1023 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1025 victim->lastattack3=victim->lastattack2;
1026 victim->lastattack2=victim->lastattack;
1027 victim->lastattack=victim->targetanimation;
1031 victim->targetanimation=sweepanim;
1032 victim->targetframe=0;
1036 rotatetarget=coords-victim->coords;
1037 Normalise(&rotatetarget);
1038 victim->targetyaw=-asin(0-rotatetarget.x);
1039 victim->targetyaw*=360/6.28;
1040 if(rotatetarget.z<0)victim->targetyaw=180-victim->targetyaw;
1042 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1044 victim->lastattack3=victim->lastattack2;
1045 victim->lastattack2=victim->lastattack;
1046 victim->lastattack=victim->targetanimation;
1053 if(aitype!=playercontrolled)feint=0;
1054 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1055 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1056 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1058 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1061 void Person::DoDamage(float howmuch){
1062 if(tutoriallevel!=1)damage+=howmuch/power;
1063 if(id!=0)damagedealt+=howmuch/power;
1064 if(id==0)damagetaken+=howmuch/power;
1066 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1067 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1068 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1069 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1070 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1072 if(id==0)camerashake+=howmuch/100;
1073 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1074 if(blackout>1)blackout=1;
1076 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1077 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1078 if(abs(Random()%2)==0){aitype=gethelptype;
1081 else aitype=attacktypecutoff;
1085 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1088 for(int i=0;i<skeleton.num_joints; i++){
1089 if(!skeleton.free)flatvelocity2=velocity;
1090 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1091 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,yaw,0)*scale+coords;
1092 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1093 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1094 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1095 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1096 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1097 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1098 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1101 emit_sound_at(splattersound, coords);
1110 if(!dead&&creature==wolftype){
1111 award_bonus(0, Wolfbonus);
1117 if(tutoriallevel!=1||id==0)
1118 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1121 if(creature==wolftype){
1122 int i=abs(Random()%2);
1123 if(i==0)whichsound=snarlsound;
1124 if(i==1)whichsound=snarl2sound;
1125 envsound[numenvsounds]=coords;
1126 envsoundvol[numenvsounds]=16;
1127 envsoundlife[numenvsounds]=.4;
1130 if(creature==rabbittype){
1131 int i=abs(Random()%2);
1132 if(i==0)whichsound=rabbitpainsound;
1133 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1134 envsound[numenvsounds]=coords;
1135 envsoundvol[numenvsounds]=16;
1136 envsoundlife[numenvsounds]=.4;
1138 //if(i==2)whichsound=rabbitpain2sound;
1142 emit_sound_at(whichsound, coords);
1147 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1148 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1151 void Person::DoHead(){
1152 static XYZ rotatearound;
1154 static float lookspeed=500;
1156 if(!freeze&&!winfreeze){
1159 targetheadyaw=(float)((int)((0-yaw-targetheadyaw+180)*100)%36000)/100;
1160 targetheadpitch=(float)((int)(targetheadpitch*100)%36000)/100;
1162 while(targetheadyaw>180)targetheadyaw-=360;
1163 while(targetheadyaw<-180)targetheadyaw+=360;
1165 if(targetheadyaw>160)targetheadpitch=targetheadpitch*-1;
1166 if(targetheadyaw<-160)targetheadpitch=targetheadpitch*-1;
1167 if(targetheadyaw>160)targetheadyaw=targetheadyaw-180;
1168 if(targetheadyaw<-160)targetheadyaw=targetheadyaw+180;
1170 if(targetheadpitch>120)targetheadpitch=120;
1171 if(targetheadpitch<-120)targetheadpitch=-120;
1172 if(targetheadyaw>120)targetheadyaw=120;
1173 if(targetheadyaw<-120)targetheadyaw=-120;
1175 if(!isIdle())targetheadpitch=0;
1177 if(targetheadyaw>80)targetheadyaw=80;
1178 if(targetheadyaw<-80)targetheadyaw=-80;
1179 if(targetheadpitch>50)targetheadpitch=50;
1180 if(targetheadpitch<-50)targetheadpitch=-50;
1183 if(abs(headyaw-targetheadyaw)<multiplier*lookspeed)headyaw=targetheadyaw;
1184 else if(headyaw>targetheadyaw){
1185 headyaw-=multiplier*lookspeed;
1187 else if(headyaw<targetheadyaw){
1188 headyaw+=multiplier*lookspeed;
1191 if(abs(headpitch-targetheadpitch)<multiplier*lookspeed/2)headpitch=targetheadpitch;
1192 else if(headpitch>targetheadpitch){
1193 headpitch-=multiplier*lookspeed/2;
1195 else if(headpitch<targetheadpitch){
1196 headpitch+=multiplier*lookspeed/2;
1199 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1200 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headpitch,0,0);
1204 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1205 facing=DoRotation(facing,headpitch*.4,0,0);
1206 facing=DoRotation(facing,0,headyaw*.4,0);
1209 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1210 facing=DoRotation(facing,headpitch*.8,0,0);
1211 facing=DoRotation(facing,0,headyaw*.8,0);
1214 if(targetanimation==walkanim){
1215 facing=DoRotation(facing,headpitch*.6,0,0);
1216 facing=DoRotation(facing,0,headyaw*.6,0);
1219 skeleton.specialforward[0]=facing;
1220 //skeleton.specialforward[0]=DoRotation(facing,0,yaw,0);
1222 for(i=0;i<skeleton.num_muscles;i++){
1223 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1225 skeleton.FindRotationMuscle(i,targetanimation);
1231 void Person::RagDoll(bool checkcollision){
1236 if(id==0)numfalls++;
1237 if(id==0&&isFlip())numflipfail++;
1243 facing=DoRotation(facing,0,yaw,0);
1245 skeleton.freetime=0;
1247 skeleton.longdead=0;
1253 skeleton.freefall=1;
1255 if(!isnormal(velocity.x))velocity.x=0;
1256 if(!isnormal(velocity.y))velocity.y=0;
1257 if(!isnormal(velocity.z))velocity.z=0;
1258 if(!isnormal(yaw))yaw=0;
1259 if(!isnormal(coords.x))coords=0;
1260 if(!isnormal(tilt))tilt=0;
1261 if(!isnormal(tilt2))tilt2=0;
1263 for(i=0;i<skeleton.num_joints;i++){
1264 skeleton.joints[i].delay=0;
1265 skeleton.joints[i].locked=0;
1266 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,yaw,0);
1267 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,yaw,0);
1268 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1269 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1270 skeleton.joints[i].position.y+=.1;
1271 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1272 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1275 for(i=0;i<skeleton.num_joints;i++){
1276 skeleton.joints[i].velocity=0;
1277 skeleton.joints[i].velchange=0;
1279 skeleton.DoConstraints(&coords,&scale);
1280 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1282 skeleton.DoConstraints(&coords,&scale);
1283 skeleton.DoConstraints(&coords,&scale);
1284 skeleton.DoConstraints(&coords,&scale);
1285 skeleton.DoConstraints(&coords,&scale);
1288 speed=animation[targetanimation].speed[targetframe]*2;
1289 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1290 speed=animation[currentanimation].speed[currentframe]*2;
1292 if(transspeed)speed=transspeed*2;
1296 for(i=0;i<skeleton.num_joints;i++){
1297 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,yaw,0);
1298 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1299 change.x=(float)(Random()%100)/100;
1300 change.y=(float)(Random()%100)/100;
1301 change.z=(float)(Random()%100)/100;
1302 skeleton.joints[i].velocity+=change;
1303 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1305 change.x=(float)(Random()%100)/100;
1306 change.y=(float)(Random()%100)/100;
1307 change.z=(float)(Random()%100)/100;
1308 skeleton.joints[i].velchange+=change;
1309 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1319 for(j=0;j<skeleton.num_joints;j++){
1320 average+=skeleton.joints[j].position;
1324 coords+=average*scale;
1325 for(j=0;j<skeleton.num_joints;j++){
1326 skeleton.joints[j].position-=average;
1329 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale);
1330 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale);
1331 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1332 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1333 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1336 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.yaw[i], &objects.model[i])!=-1){
1337 coords.x=lowpoint.x;
1338 coords.z=lowpoint.z;
1347 for(i=0;i<skeleton.num_joints;i++){
1348 velocity+=skeleton.joints[i].velocity*scale;
1350 velocity/=skeleton.num_joints;
1353 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1354 weapons[weaponids[0]].owner=-1;
1355 weapons[weaponids[0]].hitsomething=0;
1356 weapons[weaponids[0]].velocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1357 weapons[weaponids[0]].velocity.x+=.01;
1358 weapons[weaponids[0]].tipvelocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1359 weapons[weaponids[0]].missed=1;
1360 weapons[weaponids[0]].freetime=0;
1361 weapons[weaponids[0]].firstfree=1;
1362 weapons[weaponids[0]].physics=1;
1365 weaponids[0]=weaponids[num_weapons];
1366 if(weaponstuck==num_weapons)weaponstuck=0;
1369 for(i=0;i<numplayers;i++){
1370 player[i].wentforweapon=0;
1375 targetanimation=bounceidleanim;
1376 currentanimation=bounceidleanim;
1384 void Person::FootLand(int which, float opacity){
1385 static XYZ terrainlight;
1386 static XYZ footvel,footpoint;
1387 if(opacity>=1||skiddelay<=0)
1391 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
1392 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
1393 //footpoint.y=coords.y;
1394 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1396 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1398 if(footvel.y<.8)footvel.y=.8;
1399 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
1400 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
1401 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1402 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1403 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1404 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,yaw);
1406 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1408 if(footvel.y<.8)footvel.y=.8;
1409 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
1410 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
1411 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1412 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1413 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);
1415 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1417 if(footvel.y<.8)footvel.y=.8;
1418 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
1419 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
1420 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1421 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1422 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);
1423 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,yaw);
1425 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1428 if(footvel.y<.8)footvel.y=.8;
1429 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
1430 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
1431 //footpoint.y=coords.y;
1432 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1436 void Person::Puff(int whichlabel){
1437 static XYZ footvel,footpoint;
1440 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,yaw,0)*scale+coords;
1441 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1444 Joint& Person::getJointFor(int bodypart) {
1445 return skeleton.joints[skeleton.jointlabels[bodypart]];
1448 void Person::setAnimation(int animation) {
1449 targetanimation=animation;
1454 void Person::DoAnimations(){
1457 static float oldtarget;
1459 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1461 if(targetanimation==tempanim||currentanimation==tempanim){
1462 animation[tempanim]=tempanimation;
1464 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1475 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1476 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1478 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1479 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1481 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1486 targfacing=DoRotation(targfacing,0,targetyaw,0);
1488 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1489 else targetanimation=backflipanim;
1490 crouchtogglekeydown=1;
1494 if(id==0)numflipped++;
1497 if(animation[targetanimation].attack!=reversed)feint=0;
1498 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1499 crouchtogglekeydown=0;
1500 if(aitype==playercontrolled)feint=0;
1504 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1505 if(!isFlip())crouchtogglekeydown=1;
1509 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1510 if(detail)normalsupdatedelay=0;
1514 if(targetanimation==rollanim&&targetframe==3&&onfire){
1516 emit_sound_at(fireendsound, coords);
1517 pause_sound(stream_firesound);
1521 if(targetanimation==rabbittacklinganim&&targetframe==1){
1522 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1523 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1524 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1525 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1526 else victim->targetanimation=rabbittackledfrontanim;
1527 victim->targetframe=2;
1530 victim->targetyaw=yaw;
1531 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1532 //victim->DoDamage(30);
1533 if(creature==wolftype){
1535 emit_sound_at(clawslicesound, victim->coords);
1537 victim->DoBloodBig(1/victim->armorhead,210);
1539 award_bonus(id, TackleBonus,
1540 victim->aitype == gethelptype ? 50 : 0);
1544 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1545 if(weapons[weaponids[0]].getType()==knife){
1546 if(weaponactive==-1)weaponactive=0;
1547 else if(weaponactive==0)weaponactive=-1;
1549 if(weaponactive==-1){
1550 emit_sound_at(knifesheathesound, coords);
1552 if(weaponactive!=-1){
1553 emit_sound_at(knifedrawsound, coords, 128);
1556 drawtogglekeydown=1;
1559 if(tutoriallevel!=1||id==0)
1560 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1563 if(terrain.getOpacity(coords.x,coords.z)<.2){
1564 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1565 else whichsound=footstepsound2;
1566 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1567 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1568 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1574 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1575 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1576 else whichsound=footstepsound4;
1580 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1581 else whichsound=footstepsound4;
1583 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1584 if(animation[targetanimation].attack!=neutral){
1586 if(i==0)whichsound=lowwhooshsound;
1587 if(i==1)whichsound=midwhooshsound;
1588 if(i==2)whichsound=highwhooshsound;
1590 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1592 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1593 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1595 emit_sound_at(whichsound, coords, 256.);
1598 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1599 envsound[numenvsounds]=coords;
1600 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1601 else envsoundvol[numenvsounds]=6;
1602 envsoundlife[numenvsounds]=.4;
1606 if(animation[targetanimation].label[targetframe]==3){
1608 emit_sound_at(whichsound, coords, 128.);
1613 if(tutoriallevel!=1||id==0)
1615 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1616 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1618 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1619 if(animation[targetanimation].attack!=neutral){
1621 if(creature==rabbittype){
1622 if(i==0)whichsound=rabbitattacksound;
1623 if(i==1)whichsound=rabbitattack2sound;
1624 if(i==2)whichsound=rabbitattack3sound;
1625 if(i==3)whichsound=rabbitattack4sound;
1627 if(creature==wolftype){
1628 if(i==0)whichsound=barksound;
1629 if(i==1)whichsound=bark2sound;
1630 if(i==2)whichsound=bark3sound;
1631 if(i==3)whichsound=barkgrowlsound;
1635 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1637 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1638 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1641 emit_sound_at(whichsound, coords);
1647 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1653 currentoffset=targetoffset;
1654 targetframe=currentframe;
1655 currentanimation=targetanimation;
1658 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1659 for(i=0;i<weapons.size();i++){
1660 if(weapons[i].owner==-1)
1661 if(findDistancefastflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
1662 if(findDistancefast(&coords,&weapons[i].position)>=1){
1663 if(weapons[i].getType()!=staff){
1664 emit_sound_at(knifedrawsound, coords, 128.);
1668 weapons[i].owner=id;
1670 weaponids[num_weapons]=weaponids[0];
1679 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1680 for(i=0;i<weapons.size();i++){
1682 if(weapons[i].owner!=-1)
1683 if(player[weapons[i].owner].weaponstuck!=-1)
1684 if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i)
1685 if(player[weapons[i].owner].num_weapons>1)willwork=0;
1686 if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free))
1687 if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
1688 if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){
1689 bool fleshstuck=false;
1690 if(weapons[i].owner!=-1)
1691 if(victim->weaponstuck!=-1){
1692 if(victim->weaponids[victim->weaponstuck]==i){
1697 emit_sound_at(fleshstabremovesound, coords, 128.);
1699 if(weapons[i].getType()!=staff){
1700 emit_sound_at(knifedrawsound, coords, 128.);
1704 if(weapons[i].owner!=-1){
1706 victim=&player[weapons[i].owner];
1707 if(victim->num_weapons==1)victim->num_weapons=0;
1708 else victim->num_weapons=1;
1710 //victim->weaponactive=-1;
1711 victim->skeleton.longdead=0;
1712 victim->skeleton.free=1;
1713 victim->skeleton.broken=0;
1715 for(int j=0;j<victim->skeleton.num_joints;j++){
1716 victim->skeleton.joints[j].velchange=0;
1717 victim->skeleton.joints[j].locked=0;
1723 Normalise(&relative);
1724 XYZ footvel,footpoint;
1726 footpoint=weapons[i].position;
1727 if(victim->weaponstuck!=-1){
1728 if(victim->weaponids[victim->weaponstuck]==i){
1729 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1730 weapons[i].bloody=2;
1731 weapons[i].blooddrip=5;
1732 victim->weaponstuck=-1;
1735 if(victim->num_weapons>0){
1736 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1737 if(victim->weaponids[0]==i)
1738 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1741 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1742 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1743 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1744 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1746 weapons[i].owner=id;
1748 weaponids[num_weapons]=weaponids[0];
1757 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1758 if(weaponactive==-1)weaponactive=0;
1759 else if(weaponactive==0){
1763 buffer=weaponids[0];
1764 weaponids[0]=weaponids[1];
1765 weaponids[1]=buffer;
1768 if(weaponactive==-1){
1769 emit_sound_at(knifesheathesound, coords, 128.);
1771 if(weaponactive!=-1){
1772 emit_sound_at(knifedrawsound, coords, 128.);
1777 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1778 XYZ rotatetarget=DoRotation(skeleton.forward,0,yaw,0);
1779 Normalise(&rotatetarget);
1780 targetyaw=-asin(0-rotatetarget.x);
1781 targetyaw*=360/6.28;
1782 if(rotatetarget.z<0)targetyaw=180-targetyaw;
1784 if(targetanimation==walljumprightkickanim)targetyaw+=40;
1785 if(targetanimation==walljumpleftkickanim)targetyaw-=40;
1790 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1792 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;
1794 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1795 targetanimation=rabbittackleanim;
1797 emit_sound_at(jumpsound, coords);
1806 Normalise(&targetloc);
1808 for(i=0;i<numplayers;i++){
1810 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1811 closestdist=findDistancefast(&targetloc,&player[i].coords);
1816 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1818 victim=&player[closestid];
1819 coords=victim->coords;
1820 currentanimation=rabbittacklinganim;
1821 targetanimation=rabbittacklinganim;
1825 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1826 rotatetarget=coords-victim->coords;
1827 Normalise(&rotatetarget);
1828 targetyaw=-asin(0-rotatetarget.x);
1829 targetyaw*=360/6.28;
1830 if(rotatetarget.z<0)targetyaw=180-targetyaw;
1832 if(targetanimation!=rabbitrunninganim){
1833 emit_sound_at(jumpsound, coords, 128.);
1839 float damagemult=1*power;
1840 if(creature==wolftype)damagemult=2.5*power;
1841 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1842 //if(onfire)damagemult=3;
1843 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1844 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1845 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1847 if(id==0)camerashake+=.4;
1848 if(Random()%2||creature==wolftype){
1851 if(creature==wolftype)DoBloodBig(0,250);
1853 if(tutoriallevel!=1){
1854 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1856 if(creature==wolftype){
1857 emit_sound_at(clawslicesound, victim->coords, 128.);
1859 victim->DoBloodBig(2/victim->armorhead,175);
1863 relative=victim->coords-coords;
1865 Normalise(&relative);
1866 relative=DoRotation(relative,0,-90,0);
1867 for(i=0;i<victim->skeleton.num_joints;i++){
1868 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1870 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1873 victim->DoDamage(damagemult*100/victim->protectionhead);
1879 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1880 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1882 if(id==0)camerashake+=.4;
1883 if(Random()%2||creature==wolftype){
1885 if(creature==wolftype)DoBloodBig(0,235);
1887 emit_sound_at(whooshhitsound, victim->coords);
1888 if(creature==wolftype){
1889 emit_sound_at(clawslicesound, victim->coords, 128.);
1891 victim->DoBloodBig(2,175);
1895 relative=victim->coords-coords;
1897 Normalise(&relative);
1899 Normalise(&relative);
1900 relative=DoRotation(relative,0,90,0);
1901 for(i=0;i<victim->skeleton.num_joints;i++){
1902 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
1904 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1907 victim->DoDamage(damagemult*50/victim->protectionhead);
1911 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
1912 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1914 if(id==0)camerashake+=.4;
1917 if(tutoriallevel!=1){
1918 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1920 if(creature==wolftype){
1921 emit_sound_at(clawslicesound, victim->coords, 128.);
1923 victim->DoBloodBig(2/victim->armorhead,175);
1929 Normalise(&relative);
1930 relative=DoRotation(relative,0,-90,0);
1931 for(i=0;i<victim->skeleton.num_joints;i++){
1932 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1934 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1937 victim->DoDamage(damagemult*150/victim->protectionhead);
1939 if(victim->damage>victim->damagetolerance)
1940 award_bonus(id, style);
1946 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
1947 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1949 if(id==0)camerashake+=.4;
1952 if(tutoriallevel!=1){
1953 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1955 if(creature==wolftype){
1956 emit_sound_at(clawslicesound, victim->coords, 128.);
1958 victim->DoBloodBig(2/victim->armorhead,175);
1964 Normalise(&relative);
1965 relative=DoRotation(relative,0,90,0);
1966 for(i=0;i<victim->skeleton.num_joints;i++){
1967 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1969 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1972 victim->DoDamage(damagemult*150/victim->protectionhead);
1974 if(victim->damage>victim->damagetolerance)
1975 award_bonus(id, style);
1981 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
1982 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1984 if(id==0)camerashake+=.4;
1989 emit_sound_at(whooshhitsound, victim->coords);
1992 relative=victim->coords-coords;
1994 Normalise(&relative);
1995 for(i=0;i<victim->skeleton.num_joints;i++){
1996 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
1998 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2001 victim->DoDamage(damagemult*50/victim->protectionhead);
2005 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2006 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2008 if(id==0)camerashake+=.2;
2009 emit_sound_at(whooshhitsound, victim->coords, 128.);
2011 victim->skeleton.longdead=0;
2012 victim->skeleton.free=1;
2013 victim->skeleton.broken=0;
2014 victim->skeleton.spinny=1;
2016 for(i=0;i<victim->skeleton.num_joints;i++){
2017 victim->skeleton.joints[i].velchange=0;
2018 victim->skeleton.joints[i].delay=0;
2019 victim->skeleton.joints[i].locked=0;
2020 //victim->skeleton.joints[i].velocity=0;
2026 Normalise(&relative);
2027 for(i=0;i<victim->skeleton.num_joints;i++){
2028 victim->skeleton.joints[i].velocity.y=relative.y*10;
2029 victim->skeleton.joints[i].position.y+=relative.y*.3;
2030 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2031 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2033 victim->Puff(abdomen);
2034 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2038 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2039 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2041 if(id==0)camerashake+=.4;
2042 if(tutoriallevel!=1){
2043 emit_sound_at(heavyimpactsound, coords, 128.);
2046 relative=victim->coords-coords;
2048 Normalise(&relative);
2049 for(i=0;i<victim->skeleton.num_joints;i++){
2050 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2052 victim->Puff(abdomen);
2053 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2057 victim->DoDamage(damagemult*500/victim->protectionhigh);
2058 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2062 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2063 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2065 if(id==0)camerashake+=.4;
2066 if(tutoriallevel!=1){
2067 emit_sound_at(thudsound, coords);
2070 victim->skeleton.longdead=0;
2071 victim->skeleton.free=1;
2072 victim->skeleton.broken=0;
2073 victim->skeleton.spinny=1;
2075 for(i=0;i<victim->skeleton.num_joints;i++){
2076 victim->skeleton.joints[i].velchange=0;
2077 //victim->skeleton.joints[i].delay=0;
2078 victim->skeleton.joints[i].locked=0;
2081 relative=victim->coords-coords;
2082 Normalise(&relative);
2084 Normalise(&relative);
2085 for(i=0;i<victim->skeleton.num_joints;i++){
2086 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2091 victim->Puff(abdomen);
2092 victim->DoDamage(damagemult*20/victim->protectionhigh);
2093 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2095 if(!victim->dead)staggerdelay=1.2;
2101 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2102 //if(id==0)camerashake+=.4;
2105 if(!victim->skeleton.free)hasvictim=0;
2108 terrain.MakeDecal(blooddecalfast,(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2),.08,.6,Random()%360);
2109 emit_sound_at(knifesheathesound, coords, 128.);
2112 if(victim&&hasvictim){
2113 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2115 XYZ where,startpoint,endpoint,movepoint,colpoint;
2116 float rotationpoint;
2118 if(weapons[weaponids[weaponactive]].getType()==knife){
2119 where=(weapons[weaponids[weaponactive]].tippoint*.6+weapons[weaponids[weaponactive]].position*.4);
2120 where-=victim->coords;
2121 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2128 if(weapons[weaponids[weaponactive]].getType()==sword){
2129 where=weapons[weaponids[weaponactive]].position;
2130 where-=victim->coords;
2131 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2133 where=weapons[weaponids[weaponactive]].tippoint;
2134 where-=victim->coords;
2135 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2138 if(weapons[weaponids[weaponactive]].getType()==staff){
2139 where=weapons[weaponids[weaponactive]].position;
2140 where-=victim->coords;
2141 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2143 where=weapons[weaponids[weaponactive]].tippoint;
2144 where-=victim->coords;
2145 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2150 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2153 if(victim->dead!=2){
2154 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2156 award_bonus(id, FinishedBonus);
2158 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
2160 victim->skeleton.longdead=0;
2161 victim->skeleton.free=1;
2162 victim->skeleton.broken=0;
2164 for(i=0;i<victim->skeleton.num_joints;i++){
2165 victim->skeleton.joints[i].velchange=0;
2166 victim->skeleton.joints[i].locked=0;
2167 //victim->skeleton.joints[i].velocity=0;
2169 emit_sound_at(fleshstabsound, coords, 128);
2172 if(whichtri!=-1||weapons[weaponids[weaponactive]].bloody){
2173 weapons[weaponids[weaponactive]].blooddrip+=5;
2174 weapons[weaponids[weaponactive]].blooddripdelay=0;
2178 emit_sound_at(knifesheathesound, coords, 128.);
2184 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2186 emit_sound_at(knifedrawsound, coords, 128);
2189 if(victim&&hasvictim){
2190 XYZ footvel,footpoint;
2192 emit_sound_at(fleshstabremovesound, coords, 128.);
2195 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2197 if(weapons[weaponids[weaponactive]].getType()==sword){
2198 XYZ where,startpoint,endpoint,movepoint;
2199 float rotationpoint;
2202 where=weapons[weaponids[weaponactive]].position;
2203 where-=victim->coords;
2204 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2206 where=weapons[weaponids[weaponactive]].tippoint;
2207 where-=victim->coords;
2208 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2213 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2214 footpoint+=victim->coords;
2217 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2220 if(weapons[weaponids[weaponactive]].getType()==staff){
2221 XYZ where,startpoint,endpoint,movepoint;
2222 float rotationpoint;
2225 where=weapons[weaponids[weaponactive]].position;
2226 where-=victim->coords;
2227 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2229 where=weapons[weaponids[weaponactive]].tippoint;
2230 where-=victim->coords;
2231 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->yaw,0);
2236 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2237 footpoint+=victim->coords;
2240 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2243 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2245 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2246 victim->skeleton.longdead=0;
2247 victim->skeleton.free=1;
2248 victim->skeleton.broken=0;
2250 for(i=0;i<victim->skeleton.num_joints;i++){
2251 victim->skeleton.joints[i].velchange=0;
2252 victim->skeleton.joints[i].locked=0;
2253 //victim->skeleton.joints[i].velocity=0;
2259 Normalise(&relative);
2260 //victim->Puff(abdomen);
2261 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2263 if(victim->bloodloss<victim->damagetolerance){
2264 victim->bloodloss+=1000;
2268 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2272 if(!hasvictim&&onterrain){
2273 weapons[weaponids[weaponactive]].bloody=0;
2274 weapons[weaponids[weaponactive]].blooddrip=0;
2278 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2279 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2281 if(id==0)camerashake+=.4;
2286 if(tutoriallevel!=1){
2287 emit_sound_at(heavyimpactsound, victim->coords, 128);
2292 relative=victim->coords-coords;
2294 Normalise(&relative);
2295 for(i=0;i<victim->skeleton.num_joints;i++){
2296 victim->skeleton.joints[i].velocity=relative*30;
2298 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2300 victim->targetframe=0;
2301 victim->targetanimation=staggerbackhardanim;
2302 victim->targetyaw=targetyaw+180;
2307 victim->Puff(abdomen);
2308 victim->DoDamage(damagemult*60/victim->protectionhigh);
2315 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2316 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2318 if(id==0)camerashake+=.4;
2319 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2320 if(tutoriallevel!=1){
2321 emit_sound_at(thudsound, victim->coords);
2324 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2325 if(tutoriallevel!=1){
2326 emit_sound_at(whooshhitsound, victim->coords);
2330 if(tutoriallevel!=1){
2331 emit_sound_at(heavyimpactsound, victim->coords);
2335 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2338 relative=victim->coords-coords;
2340 Normalise(&relative);
2342 Normalise(&relative);
2343 for(i=0;i<victim->skeleton.num_joints;i++){
2344 victim->skeleton.joints[i].velocity=relative*5;
2346 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2348 victim->targetframe=0;
2349 victim->targetanimation=staggerbackhardanim;
2350 victim->targetyaw=targetyaw+180;
2354 victim->Puff(abdomen);
2355 victim->DoDamage(damagemult*60/victim->protectionhigh);
2361 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2362 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2363 if(victim->id==0)camerashake+=.4;
2364 emit_sound_at(landsound2, victim->coords);
2370 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2371 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2372 if(victim->id==0)camerashake+=.4;
2374 if(weaponactive!=-1){
2375 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2376 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2377 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2379 emit_sound_at(swordstaffsound, victim->coords);
2382 emit_sound_at(metalhitsound, victim->coords);
2390 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2391 if(weaponactive!=-1){
2394 weapons[weaponids[0]].owner=-1;
2395 aim=victim->coords+DoRotation(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position,0,victim->yaw,0)*victim->scale+victim->velocity*findDistance(&victim->coords,&coords)/50-(coords+DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,yaw,0)*scale);
2397 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2398 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2400 weapons[weaponids[0]].velocity=aim*50;
2401 weapons[weaponids[0]].tipvelocity=aim*50;
2402 weapons[weaponids[0]].missed=0;
2403 weapons[weaponids[0]].hitsomething=0;
2404 weapons[weaponids[0]].freetime=0;
2405 weapons[weaponids[0]].firstfree=1;
2406 weapons[weaponids[0]].physics=0;
2409 weaponids[0]=weaponids[num_weapons];
2415 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2417 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2419 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2421 award_bonus(id, Slicebonus);
2422 if(tutoriallevel!=1){
2423 emit_sound_at(knifeslicesound, victim->coords);
2425 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2426 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2427 if(victim->id != 0 || difficulty==2){
2428 victim->targetframe=0;
2429 victim->targetanimation=staggerbackhardanim;
2430 victim->targetyaw=targetyaw+180;
2434 victim->lowreversaldelay=0;
2435 victim->highreversaldelay=0;
2436 if(aitype!=playercontrolled)weaponmissdelay=.6;
2438 if(tutoriallevel!=1)if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2439 if(tutoriallevel!=1)weapons[weaponids[weaponactive]].blooddrip+=3;
2441 XYZ footvel,footpoint;
2444 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2447 footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->yaw,0)*victim->scale+victim->coords;
2449 if(tutoriallevel!=1){
2450 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2451 footvel=DoRotation(facing,0,90,0)*.8;
2453 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2454 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2455 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2456 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2458 if(tutoriallevel==1){
2459 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2461 victim->DoDamage(damagemult*0);
2464 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2465 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2466 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2467 award_bonus(id, Slashbonus);
2469 if(tutoriallevel!=1){
2470 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2471 else victim->DoBloodBig(2/victim->armorhigh,185);
2472 victim->deathbleeding=1;
2473 emit_sound_at(swordslicesound, victim->coords);
2475 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2476 if(tutoriallevel!=1){
2477 victim->targetframe=0;
2478 victim->targetanimation=staggerbackhardanim;
2479 victim->targetyaw=targetyaw+180;
2483 if(tutoriallevel!=1){
2484 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2485 weapons[weaponids[weaponactive]].blooddrip+=3;
2487 float bloodlossamount;
2488 bloodlossamount=200+abs((float)(Random()%40))-20;
2489 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2490 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2491 victim->DoDamage(damagemult*0);
2493 XYZ footvel,footpoint;
2496 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2499 footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->yaw,0)*victim->scale+victim->coords;
2501 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2502 footvel=DoRotation(facing,0,90,0)*.8;
2504 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2505 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2506 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2507 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2511 if(victim->weaponactive!=-1){
2512 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2513 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2514 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2516 emit_sound_at(swordstaffsound, victim->coords);
2519 emit_sound_at(metalhitsound, victim->coords);
2525 victim->Puff(righthand);
2527 victim->targetframe=0;
2528 victim->targetanimation=staggerbackhighanim;
2529 victim->targetyaw=targetyaw+180;
2531 weapons[victim->weaponids[0]].owner=-1;
2532 aim=DoRotation(facing,0,90,0)*21;
2534 weapons[victim->weaponids[0]].velocity=aim*-.2;
2535 weapons[victim->weaponids[0]].tipvelocity=aim;
2536 weapons[victim->weaponids[0]].missed=1;
2537 weapons[weaponids[0]].hitsomething=0;
2538 weapons[victim->weaponids[0]].freetime=0;
2539 weapons[victim->weaponids[0]].firstfree=1;
2540 weapons[victim->weaponids[0]].physics=1;
2541 victim->num_weapons--;
2542 if(victim->num_weapons){
2543 victim->weaponids[0]=victim->weaponids[num_weapons];
2544 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2546 victim->weaponactive=-1;
2547 for(i=0;i<numplayers;i++){
2548 player[i].wentforweapon=0;
2555 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2556 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2557 if(tutoriallevel!=1){
2558 weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250;
2560 if(id==0)camerashake+=.4;
2561 if(Random()%2||creature==wolftype){
2564 emit_sound_at(staffheadsound, victim->coords);
2568 relative=victim->coords-coords;
2570 Normalise(&relative);
2571 relative=DoRotation(relative,0,90,0);
2573 Normalise(&relative);
2574 for(i=0;i<victim->skeleton.num_joints;i++){
2575 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2577 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2578 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2581 if(tutoriallevel!=1){
2582 victim->DoDamage(damagemult*120/victim->protectionhigh);
2584 award_bonus(id, solidhit, 30);
2589 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2590 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2591 if(tutoriallevel!=1){
2592 weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250;
2594 if(id==0)camerashake+=.4;
2595 if(Random()%2||creature==wolftype){
2598 emit_sound_at(staffheadsound, victim->coords);
2602 relative=victim->coords-coords;
2604 Normalise(&relative);
2605 relative=DoRotation(relative,0,-90,0);
2606 for(i=0;i<victim->skeleton.num_joints;i++){
2607 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2609 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2610 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2613 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2615 award_bonus(id, solidhit, 60);
2620 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2621 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2623 if(tutoriallevel!=1){
2624 if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500;
2625 if(id==0)camerashake+=.4;
2626 if(Random()%2||creature==wolftype){
2629 emit_sound_at(staffbodysound, victim->coords);
2631 victim->skeleton.longdead=0;
2632 victim->skeleton.free=1;
2633 victim->skeleton.broken=0;
2635 for(i=0;i<victim->skeleton.num_joints;i++){
2636 victim->skeleton.joints[i].velchange=0;
2637 victim->skeleton.joints[i].locked=0;
2638 //victim->skeleton.joints[i].velocity=0;
2644 /*relative=victim->coords-coords;
2646 Normalise(&relative);
2647 relative=DoRotation(relative,0,90,0);*/
2649 Normalise(&relative);
2651 for(i=0;i<victim->skeleton.num_joints;i++){
2652 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2655 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2658 for(i=0;i<victim->skeleton.num_joints;i++){
2659 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2662 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2664 victim->Puff(abdomen);
2665 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2668 award_bonus(id, solidhit, 40);
2674 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2675 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2677 if(id==0)camerashake+=.4;
2679 relative=victim->coords-coords;
2681 Normalise(&relative);
2685 if(animation[victim->targetanimation].height==lowheight){
2691 for(i=0;i<victim->skeleton.num_joints;i++){
2692 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2694 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2695 if(tutoriallevel!=1){
2696 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2699 victim->DoDamage(damagemult*100/victim->protectionhead);
2700 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2701 if(creature==wolftype){
2702 emit_sound_at(clawslicesound, victim->coords, 128.);
2704 victim->DoBloodBig(2/victim->armorhead,175);
2708 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2709 for(i=0;i<victim->skeleton.num_joints;i++){
2710 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2712 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2713 victim->targetframe=0;
2714 victim->targetanimation=staggerbackhighanim;
2715 victim->targetyaw=targetyaw+180;
2717 if(tutoriallevel!=1){
2718 emit_sound_at(landsound2, victim->coords, 128.);
2720 victim->Puff(abdomen);
2721 victim->DoDamage(damagemult*30/victim->protectionhigh);
2722 if(creature==wolftype){
2723 emit_sound_at(clawslicesound, victim->coords, 128.);
2725 victim->DoBloodBig(2/victim->armorhigh,170);
2732 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2733 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2735 if(id==0)camerashake+=.2;
2736 if(tutoriallevel!=1){
2737 emit_sound_at(landsound2, victim->coords, 128.);
2740 relative=victim->coords-coords;
2742 Normalise(&relative);
2744 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2747 for(i=0;i<victim->skeleton.num_joints;i++){
2748 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2750 relative=DoRotation(relative,0,-90,0);
2752 for(i=0;i<victim->skeleton.num_joints;i++){
2753 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)
2754 victim->skeleton.joints[i].velocity=relative*80;
2756 victim->Puff(rightankle);
2757 victim->Puff(leftankle);
2758 victim->DoDamage(damagemult*40/victim->protectionlow);
2761 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2762 for(i=0;i<victim->skeleton.num_joints;i++){
2763 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2765 relative=DoRotation(relative,0,-90,0);
2766 for(i=0;i<victim->skeleton.num_joints;i++){
2767 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)
2768 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2770 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2771 victim->targetframe=0;
2772 victim->targetanimation=staggerbackhighanim;
2773 victim->targetyaw=targetyaw+180;
2775 if(tutoriallevel!=1){
2776 emit_sound_at(landsound2, victim->coords, 128.);
2778 victim->Puff(abdomen);
2779 victim->DoDamage(damagemult*30/victim->protectionlow);
2787 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2788 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2790 if(id==0)camerashake+=.4;
2795 if(tutoriallevel!=1){
2796 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2798 if(creature==wolftype){
2799 emit_sound_at(clawslicesound, victim->coords, 128);
2801 victim->DoBloodBig(2/victim->armorhigh,170);
2805 relative=victim->coords-oldcoords;
2807 Normalise(&relative);
2808 //relative=DoRotation(relative,0,-90,0);
2809 for(i=0;i<victim->skeleton.num_joints;i++){
2810 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2812 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2814 victim->Puff(abdomen);
2815 victim->DoDamage(damagemult*150/victim->protectionhigh);
2817 award_bonus(id, Reversal);
2820 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2821 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2822 if(weapons[victim->weaponids[victim->weaponactive]].owner==victim->id){
2823 weapons[victim->weaponids[victim->weaponactive]].owner=id;
2826 weaponids[num_weapons]=weaponids[victim->weaponactive];
2829 weaponids[0]=victim->weaponids[victim->weaponactive];
2830 victim->num_weapons--;
2831 if(victim->num_weapons>0){
2832 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2833 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2835 victim->weaponactive=-1;
2840 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2842 if(id==0)camerashake+=.4;
2847 emit_sound_at(whooshhitsound, victim->coords, 128.);
2850 relative=victim->coords-oldcoords;
2852 Normalise(&relative);
2853 //relative=DoRotation(relative,0,-90,0);
2854 for(i=0;i<victim->skeleton.num_joints;i++){
2855 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2857 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2860 victim->DoDamage(damagemult*70/victim->protectionhigh);
2863 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2865 if(id==0)camerashake+=.4;
2871 award_bonus(id, staffreversebonus);
2873 if(tutoriallevel!=1){
2874 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2877 award_bonus(id, staffreversebonus); // Huh, again?
2880 relative=victim->coords-oldcoords;
2882 Normalise(&relative);
2883 //relative=DoRotation(relative,0,-90,0);
2884 for(i=0;i<victim->skeleton.num_joints;i++){
2885 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2887 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2890 victim->DoDamage(damagemult*70/victim->protectionhigh);
2893 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
2899 Normalise(&relative);
2902 for(i=0;i<victim->skeleton.num_joints;i++){
2903 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2905 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
2906 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
2907 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
2908 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
2909 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
2910 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
2911 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
2912 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
2914 victim->Puff(abdomen);
2915 victim->DoDamage(damagemult*90/victim->protectionhigh);
2917 award_bonus(id, Reversal);
2921 if(weaponactive!=-1||creature==wolftype)doslice=1;
2922 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
2924 if(weaponactive!=-1){
2925 victim->DoBloodBig(2/victim->armorhigh,225);
2926 emit_sound_at(knifeslicesound, victim->coords);
2927 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2928 weapons[weaponids[weaponactive]].blooddrip+=3;
2930 if(weaponactive==-1&&creature==wolftype){;
2931 emit_sound_at(clawslicesound, victim->coords, 128.);
2933 victim->DoBloodBig(2/victim->armorhigh,175);
2940 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2946 Normalise(&relative);
2949 for(i=0;i<victim->skeleton.num_joints;i++){
2950 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2952 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
2953 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
2954 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
2955 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
2956 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
2957 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
2958 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
2959 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
2961 award_bonus(id, swordreversebonus);
2964 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2966 if(id==0)camerashake+=.4;
2971 if(tutoriallevel!=1){
2972 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2976 relative=victim->coords-oldcoords;
2978 Normalise(&relative);
2979 relative=DoRotation(relative,0,-90,0);
2980 for(i=0;i<victim->skeleton.num_joints;i++){
2981 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2983 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2985 victim->Puff(abdomen);
2986 victim->DoDamage(damagemult*30/victim->protectionhigh);
2988 award_bonus(id, Reversal);
2991 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
2994 victim->skeleton.spinny=0;
2998 Normalise(&relative);
2999 if(victim->id==0)relative/=30;
3000 for(i=0;i<victim->skeleton.num_joints;i++){
3001 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3003 //victim->DoDamage(1000);
3004 victim->damage=victim->damagetolerance;
3005 victim->permanentdamage=victim->damagetolerance-1;
3008 if(weaponactive!=-1||creature==wolftype)doslice=1;
3009 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3011 if(weaponactive!=-1){
3012 victim->DoBloodBig(200,225);
3013 emit_sound_at(knifeslicesound, victim->coords);
3014 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3015 weapons[weaponids[weaponactive]].blooddrip+=5;
3018 if(creature==wolftype&&weaponactive==-1){
3019 emit_sound_at(clawslicesound, victim->coords, 128.);
3021 victim->DoBloodBig(2,175);
3024 award_bonus(id, spinecrusher);
3027 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3028 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3030 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3031 if(targetanimation==knifesneakattackanim){
3032 /*victim->DoBloodBig(200,195);
3037 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3038 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3040 XYZ footvel,footpoint;
3042 footpoint=weapons[weaponids[0]].tippoint;
3043 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3044 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3045 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3046 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3047 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3048 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3049 victim->DoBloodBig(200,195);
3050 award_bonus(id, tracheotomy);
3052 if(targetanimation==knifefollowanim){
3053 award_bonus(id, Stabbonus);
3054 XYZ footvel,footpoint;
3056 footpoint=weapons[weaponids[0]].tippoint;
3057 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3058 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3059 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3060 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3061 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3062 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3065 victim->bloodloss+=10000;
3067 emit_sound_at(fleshstabsound, victim->coords);
3068 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3069 weapons[weaponids[weaponactive]].blooddrip+=5;
3073 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3076 for(i=0;i<victim->skeleton.num_joints;i++){
3077 victim->skeleton.joints[i].velocity=0;
3079 if(targetanimation==knifefollowanim){
3081 for(i=0;i<victim->skeleton.num_joints;i++){
3082 victim->skeleton.joints[i].velocity=0;
3085 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3086 emit_sound_at(fleshstabremovesound, victim->coords);
3087 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3088 weapons[weaponids[weaponactive]].blooddrip+=5;
3090 XYZ footvel,footpoint;
3092 footpoint=weapons[weaponids[0]].tippoint;
3093 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3094 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3095 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3096 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3097 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3098 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3102 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3103 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3104 award_bonus(id, backstab);
3108 XYZ footvel,footpoint;
3110 footpoint=(weapons[weaponids[0]].tippoint+weapons[weaponids[0]].position)/2;
3111 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3112 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3113 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3114 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3115 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3116 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3117 victim->DoBloodBig(200,180);
3118 victim->DoBloodBig(200,215);
3119 victim->bloodloss+=10000;
3121 emit_sound_at(fleshstabsound, victim->coords);
3122 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3123 weapons[weaponids[weaponactive]].blooddrip+=5;
3127 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3130 for(i=0;i<victim->skeleton.num_joints;i++){
3131 victim->skeleton.joints[i].velocity=0;
3133 if(weaponactive!=-1){
3134 emit_sound_at(fleshstabremovesound, victim->coords);
3135 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3136 weapons[weaponids[weaponactive]].blooddrip+=5;
3138 XYZ footvel,footpoint;
3140 footpoint=weapons[weaponids[0]].tippoint;
3141 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3142 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3143 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3144 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3145 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3146 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3150 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3152 if(id==0)camerashake+=.4;
3157 if(weaponactive==-1){
3158 if(tutoriallevel!=1){
3159 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3164 if(weaponactive!=-1||creature==wolftype)doslice=1;
3165 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3167 if(weaponactive!=-1){
3168 victim->DoBloodBig(2/victim->armorhead,225);
3169 emit_sound_at(knifeslicesound, victim->coords);
3170 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
3171 weapons[weaponids[weaponactive]].blooddrip+=3;
3173 if(weaponactive==-1&&creature==wolftype){
3174 emit_sound_at(clawslicesound, victim->coords, 128.);
3176 victim->DoBloodBig(2/victim->armorhead,175);
3180 award_bonus(id, Reversal);
3185 //relative=victim->coords-oldcoords;
3188 Normalise(&relative);
3189 relative=DoRotation(relative,0,90,0);
3191 Normalise(&relative);
3192 for(i=0;i<victim->skeleton.num_joints;i++){
3193 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3195 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3196 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3197 victim->DoDamage(damagemult*100/victim->protectionhead);
3201 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3205 //relative=victim->coords-oldcoords;
3208 Normalise(&relative);
3209 relative=DoRotation(relative,0,90,0);
3211 Normalise(&relative);
3212 for(i=0;i<victim->skeleton.num_joints;i++){
3213 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3215 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3218 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3219 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3220 award_bonus(id, reverseko);
3226 if(targetframe>animation[currentanimation].numframes-1){
3229 targetanimation=getIdle();
3233 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3234 targetanimation=rollanim;
3236 emit_sound_at(movewhooshsound, coords, 128.);
3238 if(currentanimation==staggerbackhighanim){
3239 targetanimation=getIdle();
3241 if(currentanimation==staggerbackhardanim){
3242 targetanimation=getIdle();
3244 if(currentanimation==removeknifeanim){
3245 targetanimation=getIdle();
3247 if(currentanimation==crouchremoveknifeanim){
3248 targetanimation=getCrouch();
3250 if(currentanimation==backhandspringanim){
3251 targetanimation=getIdle();
3253 if(currentanimation==dodgebackanim){
3254 targetanimation=getIdle();
3256 if(currentanimation==drawleftanim){
3257 targetanimation=getIdle();
3259 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3260 targetanimation=getIdle();
3261 if(currentanimation==crouchdrawrightanim){
3262 targetanimation=getCrouch();
3264 if(weaponactive==-1)weaponactive=0;
3265 else if(weaponactive==0){
3269 buffer=weaponids[0];
3270 weaponids[0]=weaponids[1];
3271 weaponids[1]=buffer;
3275 if(weaponactive==-1){
3276 emit_sound_at(knifesheathesound, coords, 128.);
3278 if(weaponactive!=-1){
3279 emit_sound_at(knifedrawsound, coords, 128.);
3282 if(currentanimation==rollanim){
3283 targetanimation=getCrouch();
3288 if(targetanimation==walljumprightkickanim){
3291 if(targetanimation==walljumpleftkickanim){
3294 targetanimation=jumpdownanim;
3296 if(currentanimation==climbanim){
3297 targetanimation=getCrouch();
3300 if(!isnormal(coords.x))
3311 if(targetanimation==rabbitkickreversalanim){
3312 targetanimation=getCrouch();
3315 if(targetanimation==jumpreversalanim){
3316 targetanimation=getCrouch();
3319 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3320 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3322 float closestdist=-1;
3325 for(i=0;i<numplayers;i++){
3326 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3327 distance=findDistancefast(&player[i].coords,&coords);
3328 if(closestdist==-1||distance<closestdist){
3329 closestdist=distance;
3334 if(closestdist>0&&closest>=0&&closestdist<16){
3335 victim=&player[closest];
3336 targetanimation=walljumprightkickanim;
3338 XYZ rotatetarget=victim->coords-coords;
3339 Normalise(&rotatetarget);
3340 yaw=-asin(0-rotatetarget.x);
3342 if(rotatetarget.z<0)yaw=180-yaw;
3343 targettilt2=-asin(rotatetarget.y)*360/6.28;
3344 velocity=(victim->coords-coords)*4;
3349 if(targetanimation==walljumpbackanim){
3350 targetanimation=backflipanim;
3355 resume_stream(whooshsound);
3357 if(targetanimation==walljumprightanim){
3358 targetanimation=rightflipanim;
3362 velocity=DoRotation(facing,0,30,0)*-8;
3365 if(targetanimation==walljumpfrontanim){
3366 targetanimation=frontflipanim;
3374 resume_stream(whooshsound);
3376 if(targetanimation==walljumpleftanim){
3379 float closestdist=-1;
3382 for(i=0;i<numplayers;i++){
3383 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3384 distance=findDistancefast(&player[i].coords,&coords);
3385 if(closestdist==-1||distance<closestdist){
3386 closestdist=distance;
3391 if(closestdist>0&&closest>=0&&closestdist<16){
3392 victim=&player[closest];
3393 targetanimation=walljumpleftkickanim;
3395 XYZ rotatetarget=victim->coords-coords;
3396 Normalise(&rotatetarget);
3397 yaw=-asin(0-rotatetarget.x);
3399 if(rotatetarget.z<0)yaw=180-yaw;
3400 targettilt2=-asin(rotatetarget.y)*360/6.28;
3401 velocity=(victim->coords-coords)*4;
3406 if(targetanimation!=walljumpleftkickanim){
3407 targetanimation=leftflipanim;
3411 velocity=DoRotation(facing,0,-30,0)*-8;
3415 resume_stream(whooshsound);
3417 if(targetanimation==sneakattackanim){
3418 currentanimation=getCrouch();
3419 targetanimation=getCrouch();
3429 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3433 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3434 targetanimation=getIdle();
3436 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3440 if(currentanimation==knifefollowanim){
3441 targetanimation=getIdle();
3444 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3445 float ycoords=oldcoords.y;
3446 targetanimation=getStop();
3453 if(!isnormal(coords.x))
3455 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3456 oldcoords=coords+facing*.5;
3457 else if(currentanimation==sweepreversalanim)
3458 oldcoords=coords+facing*1.1;
3459 else if(currentanimation==upunchreversalanim){
3460 oldcoords=coords+facing*1.5;
3467 else if(currentanimation==knifeslashreversalanim){
3468 oldcoords=coords+facing*.5;
3475 else if(currentanimation==staffspinhitreversalanim){
3482 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3483 else oldcoords.y=ycoords;
3484 currentoffset=coords-oldcoords;
3490 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3495 if(animation[targetanimation].attack==reversed){
3497 if(targetanimation==sweepreversedanim)targetyaw+=90;
3498 targetanimation=backhandspringanim;
3500 emit_sound_at(landsound, coords, 128);
3502 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3503 targetanimation=rollanim;
3506 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0))/2*scale;
3507 coords.y=oldcoords.y;
3509 if(currentanimation==knifeslashreversedanim){
3510 targetanimation=rollanim;
3515 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0))/2*scale;
3516 coords.y=oldcoords.y;
3520 targetanimation=jumpdownanim;
3522 if(wasLanding())targetanimation=getIdle();
3523 if(wasLandhard())targetanimation=getIdle();
3524 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3525 targetanimation=getIdle();
3527 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0))/2*scale;
3528 coords.y=oldcoords.y;
3529 //coords+=DoRotation(animation[currentanimation].offset,0,yaw,0)*scale;
3530 targetoffset.y=coords.y;
3531 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3532 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,yaw,0)*scale;
3533 currentoffset.y-=(coords.y-targetoffset.y);
3534 coords.y=targetoffset.y;
3536 normalsupdatedelay=0;
3538 if(currentanimation==upunchanim){
3539 targetanimation=getStop();
3540 normalsupdatedelay=0;
3543 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3547 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
3548 if(!hasstaff)DoDamage(35);
3551 rabbitkickragdoll=1;
3553 if(currentanimation==rabbitkickreversedanim){
3560 SolidHitBonus(!id); // FIXME: tricky id
3564 targetanimation=rollanim;
3566 if(id==0)pause_sound(whooshsound);
3570 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3576 if(currentanimation==jumpreversedanim){
3583 SolidHitBonus(!id); // FIXME: tricky id
3587 targetanimation=rollanim;
3589 if(id==0)pause_sound(whooshsound);
3594 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){
3595 targetanimation=getupfromfrontanim;
3598 else if(animation[currentanimation].attack==normalattack){
3599 targetanimation=getIdle();
3602 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3603 targetanimation=blockhighleftstrikeanim;
3605 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3606 targetanimation=getIdle();
3609 if(currentanimation==spinkickanim&&victim->skeleton.free){
3610 if(creature==rabbittype)targetanimation=fightidleanim;
3615 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3617 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3618 targetanimation=jumpdownanim;
3623 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3624 if(!isRun()||!wasRun()){
3625 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3626 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3627 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3628 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3630 if(isRun()&&wasRun()){
3633 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3634 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3637 else if(transspeed)target+=multiplier*transspeed*speed*2;
3639 if(!isRun()||!wasRun()){
3640 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3641 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3642 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3643 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3647 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3649 if(target>1){currentframe=targetframe; target=1;}
3651 rot=targetrot*target;
3658 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3660 for(i=0;i<skeleton.num_joints;i++){
3661 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3664 skeleton.FindForwards();
3666 for(i=0;i<skeleton.num_muscles;i++){
3667 if(skeleton.muscles[i].visible)
3669 skeleton.FindRotationMuscle(i,targetanimation);
3672 for(i=0;i<skeleton.num_muscles;i++){
3673 if(skeleton.muscles[i].visible)
3675 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3676 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3677 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3682 for(i=0;i<skeleton.num_joints;i++){
3683 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3686 skeleton.FindForwards();
3688 for(i=0;i<skeleton.num_muscles;i++){
3689 if(skeleton.muscles[i].visible)
3691 skeleton.FindRotationMuscle(i,targetanimation);
3694 for(i=0;i<skeleton.num_muscles;i++){
3695 if(skeleton.muscles[i].visible)
3697 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3698 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3699 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3700 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3701 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3702 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3703 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3704 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3705 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3709 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3711 oldcurrentanimation=currentanimation;
3712 oldtargetanimation=targetanimation;
3713 oldtargetframe=targetframe;
3714 oldcurrentframe=currentframe;
3716 for(i=0;i<skeleton.num_joints;i++){
3717 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3718 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3720 offset=currentoffset*(1-target)+targetoffset*target;
3721 for(i=0;i<skeleton.num_muscles;i++){
3722 if(skeleton.muscles[i].visible)
3724 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3725 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3726 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3731 if(isLanding()&&landhard){
3732 if(id==0)camerashake+=.4;
3733 targetanimation=getLandhard();
3740 //skeleton.DoConstraints();
3743 void Person::DoStuff(){
3744 static XYZ terrainnormal;
3745 static XYZ flatfacing;
3746 static XYZ flatvelocity;
3747 static float flatvelspeed;
3751 static int bloodsize;
3752 static int startx,starty,endx,endy;
3753 static GLubyte color;
3754 static XYZ bloodvel;
3756 onfiredelay-=multiplier;
3757 if(onfiredelay<0&&onfire)
3765 crouchkeydowntime+=multiplier;
3766 if(!crouchkeydown)crouchkeydowntime=0;
3767 jumpkeydowntime+=multiplier;
3768 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3770 if(hostile||damage>0||bloodloss>0)immobile=0;
3772 if(isIdle()||isRun())targetoffset=0;
3774 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3776 if(id==0)blooddimamount-=multiplier*.3;
3777 speechdelay-=multiplier;
3778 texupdatedelay-=multiplier;
3779 interestdelay-=multiplier;
3780 flamedelay-=multiplier;
3781 parriedrecently-=multiplier;
3787 if(id==0)speed=1.1*speedmult;
3788 else speed=1.0*speedmult;
3789 if(!skeleton.free)rabbitkickragdoll=0;
3793 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3794 if(id!=0&&creature==wolftype&&difficulty==2){
3796 if(aitype!=passivetype){
3798 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){
3802 if(scale<0.2)superruntoggle=0;
3803 if(targetanimation==wolfrunninganim&&!superruntoggle){
3804 targetanimation=getRun();
3808 if(weaponactive==-1&&num_weapons>0){
3809 if(weapons[weaponids[0]].getType()==staff){
3816 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3817 /*if(aitype!=playercontrolled)*/
3819 if(burnt>.6)burnt=.6;
3820 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3822 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3833 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3834 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3838 while(flamedelay<0&&onfire){
3840 howmany=abs(Random()%(skeleton.num_joints));
3841 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3842 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3843 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,yaw,0)*scale+coords;
3844 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3845 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3848 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3850 howmany=abs(Random()%(skeleton.num_joints));
3851 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3852 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3853 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,yaw,0)*scale+coords;
3854 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3855 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3859 bleeding-=multiplier*.3;
3861 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3862 if(bleeding<=0&&(detail!=2||osx))DoMipmaps();
3866 if(neckspurtamount>0){
3867 neckspurtamount-=multiplier;
3868 neckspurtdelay-=multiplier*3;
3869 neckspurtparticledelay-=multiplier*3;
3870 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3874 bloodvel.z=5*neckspurtamount;
3875 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,yaw+((float)(Random()%100))/40,0)*scale;
3878 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3880 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,yaw+((float)(Random()%100))/40,0)*scale;
3881 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3882 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);
3883 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,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, .9);
3884 neckspurtparticledelay=.05;
3886 if(neckspurtdelay<0){
3891 if(deathbleeding>0&&dead!=2){
3892 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
3893 else bleeddelay-=5*multiplier/4;
3894 if(bleeddelay<0&&bloodtoggle){
3899 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,yaw+((float)(Random()%100))/4,0)*scale;
3900 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
3901 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
3902 if(!skeleton.free)Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2,0,yaw,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3905 bloodloss+=deathbleeding*multiplier*80;
3906 deathbleeding-=multiplier*1.6;
3907 //if(id==0)deathbleeding-=multiplier*.2;
3908 if(deathbleeding<0)deathbleeding=0;
3909 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
3910 if(weaponactive!=-1){
3911 weapons[weaponids[0]].owner=-1;
3912 weapons[weaponids[0]].velocity=velocity*scale*-.3;
3913 weapons[weaponids[0]].velocity.x+=.01;
3914 weapons[weaponids[0]].tipvelocity=velocity*scale;
3915 weapons[weaponids[0]].missed=1;
3916 weapons[weaponids[0]].hitsomething=0;
3917 weapons[weaponids[0]].freetime=0;
3918 weapons[weaponids[0]].firstfree=1;
3919 weapons[weaponids[0]].physics=1;
3922 weaponids[0]=weaponids[num_weapons];
3923 if(weaponstuck==num_weapons)weaponstuck=0;
3926 for(i=0;i<numplayers;i++){
3927 player[i].wentforweapon=0;
3939 if(!dead&&creature==wolftype){
3940 award_bonus(0, Wolfbonus);
3943 if(targetanimation==knifefollowedanim&&!skeleton.free){
3944 for(i=0;i<skeleton.num_joints;i++){
3945 skeleton.joints[i].velocity=0;
3946 skeleton.joints[i].velocity.y=-2;
3949 if(id!=0&&unconscioustime>.1){
3957 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
3960 bloodsize=5-realtexdetail;
3964 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3965 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3966 endx=startx+bloodsize;
3967 endy=starty+bloodsize;
3969 if(startx<0){startx=0;bleeding=0;}
3970 if(starty<0){starty=0;bleeding=0;}
3971 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
3972 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
3973 if(endx<startx)endx=startx;
3974 if(endy<starty)endy=starty;
3976 for(i=startx;i<endx;i++){
3977 for(j=starty;j<endy;j++){
3979 color=Random()%85+170;
3980 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
3981 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
3982 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
3987 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3992 bleedy-=4/realtexdetail;
3993 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
3994 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
3997 bleedx+=4*direction/realtexdetail;
3998 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
3999 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4003 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4004 righthandmorphness=targetrighthandmorphness;
4005 righthandmorphstart=righthandmorphend;
4007 else if(righthandmorphness>targetrighthandmorphness){
4008 righthandmorphness-=multiplier*4;
4010 else if(righthandmorphness<targetrighthandmorphness){
4011 righthandmorphness+=multiplier*4;
4014 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4015 lefthandmorphness=targetlefthandmorphness;
4016 lefthandmorphstart=lefthandmorphend;
4018 else if(lefthandmorphness>targetlefthandmorphness){
4019 lefthandmorphness-=multiplier*4;
4021 else if(lefthandmorphness<targetlefthandmorphness){
4022 lefthandmorphness+=multiplier*4;
4025 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4026 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4027 tailmorphness=targettailmorphness;
4028 tailmorphstart=tailmorphend;
4030 else if(tailmorphness>targettailmorphness){
4031 tailmorphness-=multiplier*10;
4033 else if(tailmorphness<targettailmorphness){
4034 tailmorphness+=multiplier*10;
4038 if(creature==wolftype){
4039 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4040 tailmorphness=targettailmorphness;
4041 tailmorphstart=tailmorphend;
4043 else if(tailmorphness>targettailmorphness){
4044 tailmorphness-=multiplier*2;
4046 else if(tailmorphness<targettailmorphness){
4047 tailmorphness+=multiplier*2;
4051 if(headmorphend==3||headmorphstart==3){
4052 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4053 headmorphness=targetheadmorphness;
4054 headmorphstart=headmorphend;
4056 else if(headmorphness>targetheadmorphness){
4057 headmorphness-=multiplier*7;
4059 else if(headmorphness<targetheadmorphness){
4060 headmorphness+=multiplier*7;
4063 else if(headmorphend==5||headmorphstart==5){
4064 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4065 headmorphness=targetheadmorphness;
4066 headmorphstart=headmorphend;
4068 else if(headmorphness>targetheadmorphness){
4069 headmorphness-=multiplier*10;
4071 else if(headmorphness<targetheadmorphness){
4072 headmorphness+=multiplier*10;
4076 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4077 headmorphness=targetheadmorphness;
4078 headmorphstart=headmorphend;
4080 else if(headmorphness>targetheadmorphness){
4081 headmorphness-=multiplier*4;
4083 else if(headmorphness<targetheadmorphness){
4084 headmorphness+=multiplier*4;
4088 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4089 chestmorphness=targetchestmorphness;
4090 chestmorphstart=chestmorphend;
4092 else if(chestmorphness>targetchestmorphness){
4093 chestmorphness-=multiplier;
4095 else if(chestmorphness<targetchestmorphness){
4096 chestmorphness+=multiplier;
4099 if(dead!=2&&howactive<=typesleeping){
4100 if(chestmorphstart==0&&chestmorphend==0){
4102 targetchestmorphness=1;
4105 if(chestmorphstart!=0&&chestmorphend!=0){
4107 targetchestmorphness=1;
4109 if(environment==snowyenvironment){
4112 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,yaw,0)*-1;
4113 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4114 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,yaw,0)*scale+coords;
4115 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4116 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4117 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4121 if(!dead&&howactive<typesleeping){
4122 blinkdelay-=multiplier*2;
4123 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4125 targetheadmorphness=1;
4127 blinkdelay=(float)(abs(Random()%40))/5;
4129 if(headmorphstart==3&&headmorphend==3){
4131 targetheadmorphness=1;
4136 twitchdelay-=multiplier*1.5;
4137 if(targetanimation!=hurtidleanim){
4138 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4140 targetheadmorphness=1;
4142 twitchdelay=(float)(abs(Random()%40))/5;
4144 if(headmorphstart==5&&headmorphend==5){
4146 targetheadmorphness=1;
4150 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4151 twitchdelay3-=multiplier*1;
4153 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4154 righthandmorphness=0;
4155 targetrighthandmorphness=1;
4156 righthandmorphend=1;
4157 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4159 if(righthandmorphstart==1&&righthandmorphend==1){
4160 righthandmorphness=0;
4161 targetrighthandmorphness=1;
4162 righthandmorphend=0;
4166 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4167 lefthandmorphness=0;
4168 targetlefthandmorphness=1;
4170 twitchdelay3=(float)(abs(Random()%40))/5;
4172 if(lefthandmorphstart==1&&lefthandmorphend==1){
4173 lefthandmorphness=0;
4174 targetlefthandmorphness=1;
4181 if(creature==rabbittype){
4182 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4183 else twitchdelay2-=multiplier*0.5;
4184 if(howactive<=typesleeping){
4185 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4187 targettailmorphness=1;
4189 twitchdelay2=(float)(abs(Random()%40))/5;
4191 if(tailmorphstart==1&&tailmorphend==1){
4193 targettailmorphness=1;
4196 if(tailmorphstart==2&&tailmorphend==2){
4198 targettailmorphness=1;
4205 if(creature==wolftype){
4206 twitchdelay2-=multiplier*1.5;
4208 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4210 targettailmorphness=1;
4215 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4217 targettailmorphness=1;
4221 if(twitchdelay2<=0){
4222 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4224 targettailmorphness=1;
4227 if(tailmorphstart==1&&tailmorphend==1){
4229 targettailmorphness=1;
4232 if(tailmorphstart==2&&tailmorphend==2){
4234 targettailmorphness=1;
4237 if(tailmorphstart==3&&tailmorphend==3){
4239 targettailmorphness=1;
4242 if(tailmorphstart==4&&tailmorphend==4){
4244 targettailmorphness=1;
4250 if(dead!=1)unconscioustime=0;
4252 if(dead==1||howactive==typesleeping){
4253 unconscioustime+=multiplier;
4254 //If unconscious, close eyes and mouth
4255 if(righthandmorphend!=0)righthandmorphness=0;
4256 righthandmorphend=0;
4257 targetrighthandmorphness=1;
4259 if(lefthandmorphend!=0)lefthandmorphness=0;
4261 targetlefthandmorphness=1;
4263 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4265 targetheadmorphness=1;
4269 if(howactive>typesleeping){
4272 if(bloodtoggle&&!bled){
4273 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4275 if(bloodtoggle&&!bled)
4276 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4277 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4278 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.yaw[j],0);
4282 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&yaw);
4287 if(dead==2||howactive>typesleeping){
4288 //If dead, open mouth and hands
4289 if(righthandmorphend!=0)righthandmorphness=0;
4290 righthandmorphend=0;
4291 targetrighthandmorphness=1;
4293 if(lefthandmorphend!=0)lefthandmorphness=0;
4295 targetlefthandmorphness=1;
4297 if(headmorphend!=2)headmorphness=0;
4299 targetheadmorphness=1;
4302 if(stunned>0&&!dead&&headmorphend!=2){
4303 if(headmorphend!=4)headmorphness=0;
4305 targetheadmorphness=1;
4308 if(damage>damagetolerance&&!dead){
4313 if(creature==wolftype){
4314 award_bonus(0, Wolfbonus);
4319 if(weaponactive!=-1){
4320 weapons[weaponids[0]].owner=-1;
4321 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4322 weapons[weaponids[0]].velocity.x+=.01;
4323 weapons[weaponids[0]].tipvelocity=velocity*scale;
4324 weapons[weaponids[0]].missed=1;
4325 weapons[weaponids[0]].hitsomething=0;
4326 weapons[weaponids[0]].freetime=0;
4327 weapons[weaponids[0]].firstfree=1;
4328 weapons[weaponids[0]].physics=1;
4331 weaponids[0]=weaponids[num_weapons];
4332 if(weaponstuck==num_weapons)weaponstuck=0;
4335 for(i=0;i<numplayers;i++){
4336 player[i].wentforweapon=0;
4342 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4350 //if(dead)damage-=multiplier/4;
4351 if(!dead)damage-=multiplier*13;
4352 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4353 if(!dead)permanentdamage-=multiplier*4;
4354 if(isIdle()||isCrouch()){
4355 if(!dead)permanentdamage-=multiplier*4;
4356 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4358 if(damage<0)damage=0;
4359 if(permanentdamage<0)permanentdamage=0;
4360 if(superpermanentdamage<0)superpermanentdamage=0;
4361 if(permanentdamage<superpermanentdamage){
4362 permanentdamage=superpermanentdamage;
4364 if(damage<permanentdamage){
4365 damage=permanentdamage;
4367 if(dead==1&&damage<damagetolerance){
4371 for(i=0;i<skeleton.num_joints;i++){
4372 skeleton.joints[i].velocity=0;
4375 if(permanentdamage>damagetolerance&&dead!=2){
4378 if(weaponactive!=-1){
4379 weapons[weaponids[0]].owner=-1;
4380 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4381 weapons[weaponids[0]].velocity.x+=.01;
4382 weapons[weaponids[0]].tipvelocity=velocity*scale;
4383 weapons[weaponids[0]].missed=1;
4384 weapons[weaponids[0]].hitsomething=0;
4385 weapons[weaponids[0]].freetime=0;
4386 weapons[weaponids[0]].firstfree=1;
4387 weapons[weaponids[0]].physics=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(!dead&&creature==wolftype){
4402 award_bonus(0, Wolfbonus);
4405 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4406 award_bonus(id, touchofdeath);
4407 if(id!=0&&unconscioustime>.1){
4415 emit_sound_at(breaksound, coords);
4418 if(skeleton.free==1){
4419 if(id==0)pause_sound(whooshsound);
4422 //If knocked over, open hands and close mouth
4423 if(righthandmorphend!=0)righthandmorphness=0;
4424 righthandmorphend=0;
4425 targetrighthandmorphness=1;
4427 if(lefthandmorphend!=0)lefthandmorphness=0;
4429 targetlefthandmorphness=1;
4431 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4432 if(headmorphend!=0)headmorphness=0;
4434 targetheadmorphness=1;
4438 skeleton.DoGravity(&scale);
4440 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4441 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4442 award_bonus(id, deepimpact);
4443 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4447 for(j=0;j<skeleton.num_joints;j++){
4448 average+=skeleton.joints[j].position;
4452 coords+=average*scale;
4453 for(j=0;j<skeleton.num_joints;j++){
4454 skeleton.joints[j].position-=average;
4456 average/=multiplier;
4458 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4460 for(i=0;i<skeleton.num_joints;i++){
4461 velocity+=skeleton.joints[i].velocity*scale;
4463 velocity/=skeleton.num_joints;
4465 if(!isnormal(velocity.x)&&velocity.x){
4469 if(findLength(&average)<10&&dead&&skeleton.free){
4470 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4471 if(skeleton.longdead>2000){
4472 if(skeleton.longdead>6000){
4473 if(id==0)pause_sound(whooshsound);
4478 if(dead==2&&bloodloss<damagetolerance){
4480 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4482 if(bloodtoggle&&!bled){
4483 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4485 if(bloodtoggle&&!bled)
4486 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4487 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4488 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.yaw[j],0);
4492 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&yaw);
4496 if(dead==2&&bloodloss>=damagetolerance){
4498 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4499 if(bleeding<=0)DoBlood(1,255);
4500 if(bloodtoggle&&!bled){
4501 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4503 if(bloodtoggle&&!bled)
4504 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4505 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4506 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.yaw[j],0);
4510 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&yaw);
4517 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4519 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4523 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4524 if(velocity.y<-30)canrecover=0;
4525 for(i=0;i<objects.numobjects;i++){
4526 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4527 colviewer=startpoint;
4529 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.yaw[i])!=-1)canrecover=0;
4537 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4538 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4539 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4540 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4542 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4543 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4544 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4546 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4547 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4548 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4550 Normalise(&terrainnormal);
4552 targetyaw=-asin(0-terrainnormal.x);
4553 targetyaw*=360/6.28;
4554 if(terrainnormal.z<0)targetyaw=180-targetyaw;
4559 targetanimation=flipanim;
4560 crouchtogglekeydown=1;
4565 currentanimation=tempanim;
4568 //tilt2=targettilt2;
4570 //if(middle.y>0)targetoffset.y=middle.y+1;
4572 for(i=0;i<skeleton.num_joints;i++){
4573 tempanimation.position[i][0]=skeleton.joints[i].position;
4574 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-yaw,0);
4579 if(findLength(&average)<10&&!dead&&skeleton.free){
4580 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4581 if(skeleton.longdead>(damage+500)*1.5){
4582 if(id==0)pause_sound(whooshsound);
4588 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4589 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4590 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4591 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4593 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4594 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4595 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4597 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4598 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4599 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4601 Normalise(&terrainnormal);
4603 targetyaw=-asin(0-terrainnormal.x);
4604 targetyaw*=360/6.28;
4605 if(terrainnormal.z<0)targetyaw=180-targetyaw;
4608 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4611 if(skeleton.forward.y<0){
4612 targetanimation=getupfrombackanim;
4616 if(skeleton.forward.y>-.3){
4617 targetanimation=getupfromfrontanim;
4625 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4626 targetanimation=rollanim;
4631 if(forwardkeydown)targetyaw+=45;
4632 if(backkeydown)targetyaw-=45;
4636 if(forwardkeydown)targetyaw-=45;
4637 if(backkeydown)targetyaw+=45;
4640 if ( !leftkeydown&&!rightkeydown)
4647 if(abs(targettilt2)>50)targettilt2=0;
4648 currentanimation=tempanim;
4653 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4655 for(i=0;i<skeleton.num_joints;i++){
4656 tempanimation.position[i][0]=skeleton.joints[i].position;
4657 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-yaw,0);
4664 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
4665 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4668 tempvelocity=velocity;
4669 Normalise(&tempvelocity);
4670 targetyaw=-asin(0-tempvelocity.x);
4671 targetyaw*=360/6.28;
4672 if(velocity.z<0)targetyaw=180-targetyaw;
4676 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4677 targetanimation=rollanim;
4681 targetanimation=backhandspringanim;
4687 emit_sound_at(movewhooshsound, coords, 128.);
4689 currentanimation=targetanimation;
4690 currentframe=targetframe-1;
4702 if(skeleton.freefall==0)freefall=0;
4706 if(aitype!=passivetype||skeleton.free==1)
4707 if(findLengthfast(&velocity)>.1)
4708 for(i=0;i<objects.numobjects;i++){
4709 if(objects.type[i]==firetype)
4710 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){
4712 if(!objects.onfire[i]){
4713 emit_sound_at(firestartsound, objects.position[i]);
4715 objects.onfire[i]=1;
4718 if(objects.onfire[i]){
4723 if(objects.type[i]==bushtype)
4724 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){
4726 if(!objects.onfire[i]){
4727 emit_sound_at(firestartsound, objects.position[i]);
4729 objects.onfire[i]=1;
4733 if(objects.onfire[i]){
4737 if(objects.messedwith[i]<=0){
4741 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4744 envsound[numenvsounds]=coords;
4745 envsoundvol[numenvsounds]=4*findLength(&velocity);
4746 envsoundlife[numenvsounds]=.4;
4751 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4752 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4754 if(environment!=desertenvironment)
4755 for(j=0;j<howmany;j++){
4756 tempvel.x=float(abs(Random()%100)-50)/20;
4757 tempvel.y=float(abs(Random()%100)-50)/20;
4758 tempvel.z=float(abs(Random()%100)-50)/20;
4761 pos.x+=float(abs(Random()%100)-50)/200;
4762 pos.y+=float(abs(Random()%100)-50)/200;
4763 pos.z+=float(abs(Random()%100)-50)/200;
4764 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);
4765 Sprite::setLastSpriteSpecial(1);
4767 howmany=findLength(&velocity)*4;
4769 if(environment==snowyenvironment)
4770 for(j=0;j<howmany;j++){
4771 tempvel.x=float(abs(Random()%100)-50)/20;
4772 tempvel.y=float(abs(Random()%100)-50)/20;
4773 tempvel.z=float(abs(Random()%100)-50)/20;
4776 pos.x+=float(abs(Random()%100)-50)/200;
4777 pos.y+=float(abs(Random()%100)-50)/200;
4778 pos.z+=float(abs(Random()%100)-50)/200;
4779 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4780 Sprite::setLastSpriteSpecial(2);
4783 objects.rotx[i]+=velocity.x*multiplier*6;
4784 objects.roty[i]+=velocity.z*multiplier*6;
4785 objects.messedwith[i]=.5;
4788 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4789 if(objects.pitch[i]==0)tempcoord=coords;
4791 tempcoord=coords-objects.position[i];
4792 tempcoord=DoRotation(tempcoord,0,-objects.yaw[i],0);
4793 tempcoord=DoRotation(tempcoord,-objects.pitch[i],0,0);
4794 tempcoord+=objects.position[i];
4796 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]){
4797 if(objects.messedwith[i]<=0){
4801 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4804 envsound[numenvsounds]=coords;
4805 envsoundvol[numenvsounds]=4*findLength(&velocity);
4806 envsoundlife[numenvsounds]=.4;
4811 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4812 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4814 if(environment!=desertenvironment)
4815 for(j=0;j<howmany;j++){
4816 tempvel.x=float(abs(Random()%100)-50)/20;
4817 tempvel.y=float(abs(Random()%100)-50)/20;
4818 tempvel.z=float(abs(Random()%100)-50)/20;
4822 pos.x+=float(abs(Random()%100)-50)/150;
4823 pos.y+=float(abs(Random()%100)-50)/150;
4824 pos.z+=float(abs(Random()%100)-50)/150;
4825 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);
4826 Sprite::setLastSpriteSpecial(1);
4828 howmany=findLength(&velocity)*4;
4830 if(environment==snowyenvironment)
4831 for(j=0;j<howmany;j++){
4832 tempvel.x=float(abs(Random()%100)-50)/20;
4833 tempvel.y=float(abs(Random()%100)-50)/20;
4834 tempvel.z=float(abs(Random()%100)-50)/20;
4838 pos.x+=float(abs(Random()%100)-50)/150;
4839 pos.y+=float(abs(Random()%100)-50)/150;
4840 pos.z+=float(abs(Random()%100)-50)/150;
4841 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4842 Sprite::setLastSpriteSpecial(2);
4845 objects.messedwith[i]=.5;
4853 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
4855 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
4856 if(tutoriallevel==1&&id!=0)play=0;
4857 if(play&&aitype!=playercontrolled){
4861 if(creature==rabbittype){
4862 if(i==0)whichsound=rabbitchitter;
4863 if(i==1)whichsound=rabbitchitter2;
4865 if(creature==wolftype){
4866 if(i==0)whichsound=growlsound;
4867 if(i==1)whichsound=growl2sound;
4873 emit_sound_at(whichsound, coords);
4877 if(targetanimation==staggerbackhighanim)staggerdelay=1;
4878 if(targetanimation==staggerbackhardanim)staggerdelay=1;
4879 staggerdelay-=multiplier;
4880 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
4881 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
4882 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
4883 targetanimation=getIdle();
4887 weaponmissdelay-=multiplier;
4888 highreversaldelay-=multiplier;
4889 lowreversaldelay-=multiplier;
4890 lastcollide-=multiplier;
4891 skiddelay-=multiplier;
4892 if(!isnormal(velocity.x)&&velocity.x){
4895 if(!isnormal(targettilt)&&targettilt){
4898 if(!isnormal(targettilt2)&&targettilt2){
4901 if(!isnormal(targetyaw)&&targetyaw){
4905 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
4906 //open hands and close mouth
4907 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4908 righthandmorphness=0;
4909 righthandmorphend=0;
4910 targetrighthandmorphness=1;
4913 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4914 lefthandmorphness=0;
4916 targetlefthandmorphness=1;
4919 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
4922 targetheadmorphness=1;
4926 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){
4927 //open hands and mouth
4928 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4929 righthandmorphness=0;
4930 righthandmorphend=0;
4931 targetrighthandmorphness=1;
4934 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4935 lefthandmorphness=0;
4937 targetlefthandmorphness=1;
4940 if(headmorphend!=1&&headmorphness==targetheadmorphness){
4943 targetheadmorphness=1;
4947 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
4948 //close hands and mouth
4949 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4950 righthandmorphness=0;
4951 righthandmorphend=1;
4952 targetrighthandmorphness=1;
4955 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4956 lefthandmorphness=0;
4958 targetlefthandmorphness=1;
4961 if(headmorphend!=0&&headmorphness==targetheadmorphness){
4964 targetheadmorphness=1;
4968 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){
4969 //close hands and yell
4970 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4971 righthandmorphness=0;
4972 righthandmorphend=1;
4973 targetrighthandmorphness=1;
4976 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4977 lefthandmorphness=0;
4979 targetlefthandmorphness=1;
4982 if(headmorphend!=2&&headmorphness==targetheadmorphness){
4985 targetheadmorphness=1;
4992 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
4993 behind=(normaldotproduct(facing,coords-victim->coords)>0);
4997 if(!dead&&targetanimation!=hurtidleanim)
4998 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
4999 if(headmorphend!=4||headmorphness==targetheadmorphness){
5002 targetheadmorphness=1;
5006 if(weaponactive!=-1){
5007 if(weapons[weaponids[weaponactive]].getType()!=staff){
5008 righthandmorphstart=1;
5009 righthandmorphend=1;
5011 if(weapons[weaponids[weaponactive]].getType()==staff){
5012 righthandmorphstart=2;
5013 righthandmorphend=2;
5015 targetrighthandmorphness=1;
5018 terrainnormal=terrain.getNormal(coords.x,coords.z);
5020 if(animation[targetanimation].attack!=reversal){
5021 if(!isnormal(coords.x))
5029 flatfacing=DoRotation(flatfacing,0,yaw,0);
5031 ReflectVector(&facing,terrainnormal);
5034 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5035 if(onterrain)targettilt2=-facing.y*20;
5039 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5040 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5041 flatvelocity=velocity;
5043 flatvelspeed=findLength(&flatvelocity);
5044 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5045 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5046 if(velocity.y<0)targettilt2*=-1;
5047 if(velocity.y<0)targettilt*=-1;
5048 if(targettilt>25)targettilt=25;
5049 if(targettilt<-25)targettilt=-25;
5052 if(targettilt2>45)targettilt2=45;
5053 if(targettilt2<-45)targettilt2=-45;
5054 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5055 else if(tilt2>targettilt2){
5056 tilt2-=multiplier*400;
5058 else if(tilt2<targettilt2){
5059 tilt2+=multiplier*400;
5061 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5062 if(tilt2>25)tilt2=25;
5063 if(tilt2<-25)tilt2=-25;
5066 if(!isnormal(targettilt)&&targettilt){
5069 if(!isnormal(targettilt2)&&targettilt2){
5074 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5075 if(targetanimation==rabbittackleanim){
5076 velocity+=facing*multiplier*speed*700*scale;
5077 velspeed=findLength(&velocity);
5078 if(velspeed>speed*65*scale){
5080 velspeed=speed*65*scale;
5083 velocity.y+=gravity*multiplier*20;
5084 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5085 velspeed=findLength(&velocity);
5086 velocity=flatfacing*velspeed;
5088 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5089 if(isRun()||targetanimation==rabbitkickanim){
5090 velocity+=facing*multiplier*speed*700*scale;
5091 velspeed=findLength(&velocity);
5092 if(velspeed>speed*45*scale){
5094 velspeed=speed*45*scale;
5097 velocity.y+=gravity*multiplier*20;
5098 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5099 velspeed=findLength(&velocity);
5100 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5101 velocity=flatfacing*velspeed;
5105 velocity+=facing*multiplier*speed*700*scale;
5106 velspeed=findLength(&velocity);
5107 if(creature==rabbittype){
5108 if(velspeed>speed*55*scale){
5110 velspeed=speed*55*scale;
5114 if(creature==wolftype){
5115 if(velspeed>speed*75*scale){
5117 velspeed=speed*75*scale;
5121 velocity.y+=gravity*multiplier*20;
5122 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5123 velspeed=findLength(&velocity);
5124 velocity=flatfacing*velspeed;
5127 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5128 velocity+=facing*multiplier*speed*700*scale;
5129 velspeed=findLength(&velocity);
5130 if(velspeed>speed*45*scale){
5132 velspeed=speed*45*scale;
5135 velocity.y+=gravity*multiplier*20;
5136 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5137 velspeed=findLength(&velocity);
5138 velocity=flatfacing*velspeed;
5142 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5143 velocity+=facing*multiplier*speed*700*scale;
5144 velspeed=findLength(&velocity);
5145 if(velspeed>speed*25*scale){
5147 velspeed=speed*25*scale;
5150 velocity.y+=gravity*multiplier*20;
5151 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5152 velspeed=findLength(&velocity);
5153 velocity=flatfacing*velspeed;
5156 if(targetanimation==sneakanim||targetanimation==walkanim){
5157 velocity+=facing*multiplier*speed*700*scale;
5158 velspeed=findLength(&velocity);
5159 if(velspeed>speed*12*scale){
5161 velspeed=speed*12*scale;
5164 velocity.y+=gravity*multiplier*20;
5165 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5166 velspeed=findLength(&velocity);
5167 velocity=flatfacing*velspeed;
5170 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5171 velocity+=facing*multiplier*speed*700*scale;
5172 velspeed=findLength(&velocity);
5173 if(velspeed>speed*2*scale){
5175 velspeed=speed*2*scale;
5178 velocity.y+=gravity*multiplier*20;
5179 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5180 velspeed=findLength(&velocity);
5181 velocity=flatfacing*velspeed;
5185 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5186 velocity-=facing*multiplier*speed*700*scale;
5187 velspeed=findLength(&velocity);
5188 if(velspeed>speed*2*scale){
5190 velspeed=speed*2*scale;
5193 velocity.y+=gravity*multiplier*20;
5194 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5195 velspeed=findLength(&velocity);
5196 velocity=flatfacing*velspeed*-1;
5199 if(targetanimation==fightsidestep){
5200 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5201 velspeed=findLength(&velocity);
5202 if(velspeed>speed*12*scale){
5204 velspeed=speed*12*scale;
5207 velocity.y+=gravity*multiplier*20;
5208 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5209 velspeed=findLength(&velocity);
5210 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5213 if(targetanimation==staggerbackhighanim){
5214 coords-=facing*multiplier*speed*16*scale;
5217 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5218 coords-=facing*multiplier*speed*20*scale;
5222 if(targetanimation==backhandspringanim){
5223 //coords-=facing*multiplier*50*scale;
5224 velocity+=facing*multiplier*speed*700*scale*-1;
5225 velspeed=findLength(&velocity);
5226 if(velspeed>speed*50*scale){
5228 velspeed=speed*50*scale;
5231 velocity.y+=gravity*multiplier*20;
5232 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5233 velspeed=findLength(&velocity);
5234 velocity=flatfacing*velspeed*-1;
5236 if(targetanimation==dodgebackanim){
5237 //coords-=facing*multiplier*50*scale;
5238 velocity+=facing*multiplier*speed*700*scale*-1;
5239 velspeed=findLength(&velocity);
5240 if(velspeed>speed*60*scale){
5242 velspeed=speed*60*scale;
5245 velocity.y+=gravity*multiplier*20;
5246 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5247 velspeed=findLength(&velocity);
5248 velocity=flatfacing*velspeed*-1;
5251 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5252 velspeed=findLength(&velocity);
5256 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5257 velocity.y+=gravity*multiplier;
5260 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5262 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5263 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5265 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5271 pause_sound(whooshsound);
5272 OPENAL_SetVolume(channels[whooshsound], 0);
5275 if(targetanimation==jumpdownanim||isFlip()){
5276 if(isFlip())jumppower=-4;
5277 targetanimation=getLanding();
5278 emit_sound_at(landsound, coords, 128.);
5281 envsound[numenvsounds]=coords;
5282 envsoundvol[numenvsounds]=16;
5283 envsoundlife[numenvsounds]=.4;
5289 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5290 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5291 coords.y=terrain.getHeight(coords.x,coords.z);
5296 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)){
5297 velspeed=findLength(&velocity);
5299 if(velspeed<multiplier*300*scale){
5301 } else velocity-=velocity/velspeed*multiplier*300*scale;
5302 if(velspeed>5&&(isLanding()||isLandhard())){
5303 skiddingdelay+=multiplier;
5310 else skiddingdelay=0;
5314 velspeed=findLength(&velocity);
5316 if(velspeed<multiplier*600*scale){
5318 } else velocity-=velocity/velspeed*multiplier*600*scale;
5320 if(velspeed>5&&(isLanding()||isLandhard())){
5321 skiddingdelay+=multiplier;
5328 else skiddingdelay=0;
5331 if(skiddingdelay<0)skiddingdelay+=multiplier;
5332 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5334 if(!onterrain||environment==grassyenvironment){
5335 emit_sound_at(skidsound, coords, 128*velspeed/10);
5338 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5342 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5343 terrainnormal=victim->coords-coords;
5344 Normalise(&terrainnormal);
5345 targetyaw=-asin(0-terrainnormal.x);
5346 targetyaw*=360/6.28;
5347 if(terrainnormal.z<0)targetyaw=180-targetyaw;
5348 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5351 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5352 targetyaw=victim->targetyaw;
5354 if(targetanimation==rabbittacklinganim){
5355 coords=victim->coords;
5358 skeleton.oldfree=skeleton.free;
5362 midterrain.x=terrain.size*terrain.scale/2;
5363 midterrain.z=terrain.size*terrain.scale/2;
5364 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5366 tempposit=coords-midterrain;
5368 Normalise(&tempposit);
5369 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5370 coords.x=tempposit.x+midterrain.x;
5371 coords.z=tempposit.z+midterrain.z;
5375 int Person::DrawSkeleton(){
5376 int oldplayerdetail;
5377 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5378 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5388 glAlphaFunc(GL_GREATER, 0.0001);
5390 float terrainheight;
5392 if(!isnormal(yaw))yaw=0;
5393 if(!isnormal(tilt))tilt=0;
5394 if(!isnormal(tilt2))tilt2=0;
5395 oldplayerdetail=playerdetail;
5397 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5400 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5403 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5408 if(playerdetail!=oldplayerdetail) {
5410 normalsupdatedelay=0;
5412 static float updatedelaychange;
5413 static float morphness;
5414 static float framemult;
5416 skeleton.FindForwards();
5417 if(howactive==typesittingwall){
5418 skeleton.specialforward[1]=0;
5419 skeleton.specialforward[1].z=1;
5425 static int weaponattachmuscle;
5426 static int weaponrotatemuscle;
5427 static XYZ weaponpoint;
5428 static int start,endthing;
5429 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5430 if(!isSleeping()&&!isSitting()){
5431 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5432 XYZ point,newpoint,change,change2;
5433 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5434 heightleft=terrain.getHeight(point.x,point.z)+.04;
5436 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5437 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5438 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0);
5439 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5440 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5442 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5443 heightright=terrain.getHeight(point.x,point.z)+.04;
5444 point.y=heightright;
5445 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5446 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5447 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0);
5448 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5449 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5450 skeleton.DoConstraints(&coords,&scale);
5452 if(creature==wolftype){
5453 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5454 heightleft=terrain.getHeight(point.x,point.z)+.04;
5456 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5457 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5458 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0);
5459 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5460 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5462 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5463 heightright=terrain.getHeight(point.x,point.z)+.04;
5464 point.y=heightright;
5465 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5466 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5467 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0);
5468 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5469 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5470 skeleton.DoConstraints(&coords,&scale);
5473 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5474 XYZ point,newpoint,change,change2;
5475 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5476 heightleft=terrain.getHeight(point.x,point.z)+.04;
5478 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5479 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5480 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5481 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5482 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5484 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5485 heightright=terrain.getHeight(point.x,point.z)+.04;
5486 point.y=heightright;
5487 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5488 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5489 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5490 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5491 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5492 skeleton.DoConstraints(&coords,&scale);
5494 if(creature==wolftype){
5495 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5496 heightleft=terrain.getHeight(point.x,point.z)+.04;
5498 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5499 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5500 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5501 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5502 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5504 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5505 heightright=terrain.getHeight(point.x,point.z)+.04;
5506 point.y=heightright;
5507 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5508 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5509 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5510 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5511 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5512 skeleton.DoConstraints(&coords,&scale);
5516 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5517 XYZ point,newpoint,change,change2;
5518 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5519 heightleft=terrain.getHeight(point.x,point.z)+.04;
5521 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5522 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5523 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5524 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5525 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5527 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5528 heightright=terrain.getHeight(point.x,point.z)+.04;
5529 point.y=heightright;
5530 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5531 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5532 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5533 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5534 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5535 skeleton.DoConstraints(&coords,&scale);
5537 if(creature==wolftype){
5538 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,yaw,0)*scale+coords;
5539 heightleft=terrain.getHeight(point.x,point.z)+.04;
5541 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5542 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5543 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5544 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5545 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5547 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,yaw,0)*scale+coords;
5548 heightright=terrain.getHeight(point.x,point.z)+.04;
5549 point.y=heightright;
5550 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5551 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5552 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-yaw,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5553 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5554 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5555 skeleton.DoConstraints(&coords,&scale);
5559 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()))
5562 targetheadyaw=-targetyaw;
5564 if(animation[targetanimation].attack==3)targetheadyaw+=180;
5566 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5567 skeleton.drawmodel.vertex[i]=0;
5568 skeleton.drawmodel.vertex[i].y=999;
5570 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5571 skeleton.drawmodellow.vertex[i]=0;
5572 skeleton.drawmodellow.vertex[i].y=999;
5574 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5575 skeleton.drawmodelclothes.vertex[i]=0;
5576 skeleton.drawmodelclothes.vertex[i].y=999;
5578 for(i=0;i<skeleton.num_muscles;i++){
5579 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5583 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5584 morphness=righthandmorphness;
5585 start=righthandmorphstart;
5586 endthing=righthandmorphend;
5588 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5589 morphness=lefthandmorphness;
5590 start=lefthandmorphstart;
5591 endthing=lefthandmorphend;
5593 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5594 morphness=headmorphness;
5595 start=headmorphstart;
5596 endthing=headmorphend;
5598 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)){
5599 morphness=chestmorphness;
5600 start=chestmorphstart;
5601 endthing=chestmorphend;
5603 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)){
5604 morphness=tailmorphness;
5605 start=tailmorphstart;
5606 endthing=tailmorphend;
5608 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5609 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5610 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5613 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5614 if(!skeleton.free)glRotatef(tilt,0,0,1);
5617 glTranslatef(mid.x,mid.y,mid.z);
5619 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5620 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5622 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5623 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5625 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5626 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5628 if(playerdetail||skeleton.free==3)
5630 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5632 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5634 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5635 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,
5636 (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,
5637 (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);
5638 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)
5639 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,
5640 (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,
5641 (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);
5642 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)
5643 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,
5644 (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,
5645 (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);
5646 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5647 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,
5648 (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,
5649 (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);
5650 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5651 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5652 //if(!isnormal(scale))test=1;
5653 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5654 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5655 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5660 if(!playerdetail||skeleton.free==3)
5662 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5664 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5666 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5667 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5668 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5669 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5670 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)
5671 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5672 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5673 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5674 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)
5675 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5676 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5677 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5678 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5679 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5680 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5681 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5683 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5684 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5685 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5686 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5692 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5693 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5695 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5698 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5699 if(!skeleton.free)glRotatef(tilt,0,0,1);
5700 glTranslatef(mid.x,mid.y,mid.z);
5701 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5702 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5704 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5705 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5707 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5708 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5710 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5711 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5713 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5714 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5715 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5716 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5717 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)
5718 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5719 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5720 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5721 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)
5722 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5723 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5724 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5725 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5726 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5727 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5728 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5729 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5730 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5731 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5732 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5737 updatedelay=1+(float)(Random()%100)/1000;
5739 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5740 normalsupdatedelay=1;
5741 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5742 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5743 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5747 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5748 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5749 if(skeleton.clothes){
5750 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5755 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5756 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5757 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5758 if(skeleton.free==1)updatedelaychange*=6;
5759 if(id==0)updatedelaychange*=8;
5760 updatedelay+=updatedelaychange;
5762 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5764 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5765 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5766 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5767 if(!skeleton.free)glRotatef(yaw,0,1,0);
5770 glColor4f(.4,1,.4,1);
5771 glDisable(GL_LIGHTING);
5772 glDisable(GL_TEXTURE_2D);
5775 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5776 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5782 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5783 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);
5784 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);
5785 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);
5786 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);
5787 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);
5788 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);
5794 terrainlight=terrain.getLighting(coords.x,coords.z);
5795 distance=findDistancefast(&viewer,&coords);
5796 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5797 if(distance>1)distance=1;
5799 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5800 if(terrainheight<1)terrainheight=1;
5801 if(terrainheight>1.7)terrainheight=1.7;
5804 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5805 glDisable(GL_BLEND);
5806 glAlphaFunc(GL_GREATER, 0.0001);
5807 glEnable(GL_TEXTURE_2D);
5809 glDisable(GL_TEXTURE_2D);
5810 glColor4f(.7,.35,0,.5);
5812 glEnable(GL_LIGHTING);
5815 if(tutoriallevel&&id!=0){
5816 //glDisable(GL_TEXTURE_2D);
5817 glColor4f(.7,.7,.7,0.6);
5819 glEnable(GL_LIGHTING);
5821 if(canattack&&cananger)
5822 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5823 glDisable(GL_TEXTURE_2D);
5824 glColor4f(1,0,0,0.8);
5826 glMatrixMode(GL_TEXTURE);
5828 glTranslatef(0,-smoketex,0);
5829 glTranslatef(-smoketex,0,0);
5833 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5834 else skeleton.drawmodel.draw();
5838 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5839 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5842 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
5843 if(tutoriallevel&&id!=0){
5845 glMatrixMode(GL_MODELVIEW);
5846 glEnable(GL_TEXTURE_2D);
5847 glColor4f(.7,.7,.7,0.6);
5849 glEnable(GL_LIGHTING);
5851 if(canattack&&cananger)
5852 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5853 glDisable(GL_TEXTURE_2D);
5854 glColor4f(1,0,0,0.8);
5856 glMatrixMode(GL_TEXTURE);
5858 glTranslatef(0,-smoketex*.6,0);
5859 glTranslatef(smoketex*.6,0,0);
5862 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5863 else skeleton.drawmodel.draw();
5867 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5868 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5873 if(tutoriallevel&&id!=0){
5875 glMatrixMode(GL_MODELVIEW);
5876 glEnable(GL_TEXTURE_2D);
5878 if(skeleton.clothes){
5881 if(!immediate)skeleton.drawmodelclothes.draw();
5882 if(immediate)skeleton.drawmodelclothes.drawimmediate();
5889 for(k=0;k<num_weapons;k++){
5891 if(weaponactive==k){
5892 if(weapons[i].getType()!=staff){
5893 for(j=0;j<skeleton.num_muscles;j++){
5894 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5895 weaponattachmuscle=j;
5898 for(j=0;j<skeleton.num_muscles;j++){
5899 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){
5900 weaponrotatemuscle=j;
5903 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5904 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
5906 if(weapons[i].getType()==staff){
5907 for(j=0;j<skeleton.num_muscles;j++){
5908 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5909 weaponattachmuscle=j;
5912 for(j=0;j<skeleton.num_muscles;j++){
5913 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){
5914 weaponrotatemuscle=j;
5917 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
5918 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5919 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5920 XYZ tempnormthing,vec1,vec2;
5921 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5922 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
5923 CrossProduct(&vec1,&vec2,&tempnormthing);
5924 Normalise(&tempnormthing);
5925 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);
5928 if(weaponactive!=k&&weaponstuck!=k){
5929 if(weapons[i].getType()==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;
5930 if(weapons[i].getType()==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;
5931 if(weapons[i].getType()==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;
5932 for(j=0;j<skeleton.num_muscles;j++){
5933 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){
5934 weaponrotatemuscle=j;
5939 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
5940 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
5941 for(j=0;j<skeleton.num_muscles;j++){
5942 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){
5943 weaponrotatemuscle=j;
5948 weapons[i].position=weaponpoint*scale+coords;
5949 weapons[i].bigrotation=0;
5950 weapons[i].bigtilt=0;
5951 weapons[i].bigtilt2=0;
5953 weapons[i].position=DoRotation(DoRotation(DoRotation(weaponpoint,0,0,tilt),tilt2,0,0),0,yaw,0)*scale+coords+currentoffset*(1-target)*scale+targetoffset*target*scale;
5954 weapons[i].bigrotation=yaw;
5955 weapons[i].bigtilt=tilt;
5956 weapons[i].bigtilt2=tilt2;
5958 weapons[i].rotation1=skeleton.muscles[weaponrotatemuscle].lastrotate1;
5959 weapons[i].rotation2=skeleton.muscles[weaponrotatemuscle].lastrotate2;
5960 weapons[i].rotation3=skeleton.muscles[weaponrotatemuscle].lastrotate3;
5961 if(weaponactive==k){
5962 if(weapons[i].getType()==knife){
5963 weapons[i].smallrotation=180;
5964 weapons[i].smallrotation2=0;
5965 if(isCrouch()||wasCrouch()){
5966 weapons[i].smallrotation2=20;
5968 if(targetanimation==hurtidleanim){
5969 weapons[i].smallrotation2=50;
5971 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
5972 XYZ temppoint1,temppoint2,tempforward;
5975 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5976 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5977 distance=findDistance(&temppoint1,&temppoint2);
5978 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5979 weapons[i].rotation2*=360/6.28;
5982 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
5983 weapons[i].rotation1*=360/6.28;
5984 weapons[i].rotation3=0;
5985 weapons[i].smallrotation=-90;
5986 weapons[i].smallrotation2=0;
5987 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
5989 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
5990 XYZ temppoint1,temppoint2,tempforward;
5993 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5994 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5995 distance=findDistance(&temppoint1,&temppoint2);
5996 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5997 weapons[i].rotation2*=360/6.28;
6000 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6001 weapons[i].rotation1*=360/6.28;
6002 weapons[i].rotation3=0;
6003 weapons[i].smallrotation=90;
6004 weapons[i].smallrotation2=0;
6005 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6007 if(targetanimation==knifethrowanim){
6008 weapons[i].smallrotation=90;
6009 //weapons[i].smallrotation2=-90;
6010 weapons[i].smallrotation2=0;
6011 weapons[i].rotation1=0;
6012 weapons[i].rotation2=0;
6013 weapons[i].rotation3=0;
6015 if(targetanimation==knifesneakattackanim&&targetframe<5){
6016 weapons[i].smallrotation=-90;
6017 weapons[i].rotation1=0;
6018 weapons[i].rotation2=0;
6019 weapons[i].rotation3=0;
6022 if(weapons[i].getType()==sword){
6023 weapons[i].smallrotation=0;
6024 weapons[i].smallrotation2=0;
6025 if(targetanimation==knifethrowanim){
6026 weapons[i].smallrotation=-90;
6027 weapons[i].smallrotation2=0;
6028 weapons[i].rotation1=0;
6029 weapons[i].rotation2=0;
6030 weapons[i].rotation3=0;
6032 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)){
6033 XYZ temppoint1,temppoint2,tempforward;
6036 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6037 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6038 distance=findDistance(&temppoint1,&temppoint2);
6039 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6040 weapons[i].rotation2*=360/6.28;
6043 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6044 weapons[i].rotation1*=360/6.28;
6045 weapons[i].rotation3=0;
6046 weapons[i].smallrotation=90;
6047 weapons[i].smallrotation2=0;
6048 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6051 if(weapons[i].getType()==staff){
6052 weapons[i].smallrotation=100;
6053 weapons[i].smallrotation2=0;
6054 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6055 XYZ temppoint1,temppoint2,tempforward;
6058 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6059 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6060 distance=findDistance(&temppoint1,&temppoint2);
6061 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6062 weapons[i].rotation2*=360/6.28;
6065 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6066 weapons[i].rotation1*=360/6.28;
6067 weapons[i].rotation3=0;
6068 weapons[i].smallrotation=90;
6069 weapons[i].smallrotation2=0;
6070 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6074 if(weaponactive!=k&&weaponstuck!=k){
6075 if(weapons[i].getType()==knife){
6076 weapons[i].smallrotation=-70;
6077 weapons[i].smallrotation2=10;
6079 if(weapons[i].getType()==sword){
6080 weapons[i].smallrotation=-100;
6081 weapons[i].smallrotation2=-8;
6083 if(weapons[i].getType()==staff){
6084 weapons[i].smallrotation=-100;
6085 weapons[i].smallrotation2=-8;
6089 if(weaponstuckwhere==0)
6090 weapons[i].smallrotation=180;
6092 weapons[i].smallrotation=0;
6093 weapons[i].smallrotation2=10;
6100 if(skeleton.free)calcrot=1;
6101 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6102 if(currentanimation!=targetanimation)calcrot=1;
6103 //if(id==0)calcrot=1;
6104 if(skeleton.free==2)calcrot=0;
6110 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6113 static float distance;
6114 static float olddistance;
6115 static int intersecting;
6116 static int firstintersecting;
6119 static XYZ start,end;
6120 static float slopethreshold=-.4;
6122 firstintersecting=-1;
6126 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6127 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6129 for (j=0;j<model->TriangleNum;j++){
6130 if(model->facenormals[j].y<=slopethreshold){
6132 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)));
6133 if(distance<radius){
6134 point=*p1-model->facenormals[j]*distance;
6135 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;
6136 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6137 &model->vertex[model->Triangles[j].vertex[1]],
6139 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6140 &model->vertex[model->Triangles[j].vertex[2]],
6142 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6143 &model->vertex[model->Triangles[j].vertex[2]],
6146 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6150 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)){
6151 p1->y=point.y+radius;
6152 if((targetanimation==jumpdownanim||isFlip())){
6153 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6155 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6161 pause_sound(whooshsound);
6162 OPENAL_SetVolume(channels[whooshsound], 0);
6165 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6166 if(isFlip())jumppower=-4;
6167 targetanimation=getLanding();
6168 emit_sound_at(landsound, coords, 128.);
6171 envsound[numenvsounds]=coords;
6172 envsoundvol[numenvsounds]=16;
6173 envsoundlife[numenvsounds]=.4;
6181 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6184 for (j=0;j<model->TriangleNum;j++){
6185 if(model->facenormals[j].y>slopethreshold){
6189 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)));
6190 if(distance<radius*.5){
6191 point=start-model->facenormals[j]*distance;
6192 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;
6193 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,
6194 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6195 p1->x, p1->y, p1->z, radius/2);
6196 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,
6197 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6198 p1->x, p1->y, p1->z, radius/2);
6199 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,
6200 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6201 p1->x, p1->y, p1->z, radius/2);
6203 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6204 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6206 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6207 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6209 *p1+=model->facenormals[j]*(distance-radius*.5);
6212 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6216 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6218 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6220 return firstintersecting;