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->targetrotation=targetrotation;
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,rotation,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,rotation+((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,rotation+((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,rotation,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,rotation,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,rotation+((float)(Random()%100))/4,0)*scale;
282 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((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,rotation,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,rotation+((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,rotation+((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,rotation,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,rotation,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){
403 //offsety=Random()%20;
405 //offsetx=abs(Random()%80);
414 if(creature==rabbittype)
417 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
418 if(i<startx)startx=i;
419 if(j<starty)starty=j;
425 if(creature==wolftype)
428 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
429 if(i<startx)startx=i;
430 if(j<starty)starty=j;
442 if(startx<0)startx=0;
443 if(starty<0)starty=0;
444 if(endx>512-1)endx=512-1;
445 if(endy>512-1)endy=512-1;
446 if(endx<startx)endx=startx;
447 if(endy<starty)endy=starty;
449 startx/=realtexdetail;
450 starty/=realtexdetail;
454 int texdetailint=realtexdetail;
456 if(creature==rabbittype)
457 for(i=startx;i<endx;i++){
458 for(j=starty;j<endy;j++){
459 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){
460 color=Random()%85+170;
461 where=i*skeleton.skinsize*3+j*3;
462 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
463 skeleton.skinText[where+1]=0;
464 skeleton.skinText[where+2]=0;
468 if(creature==wolftype)
469 for(i=startx;i<endx;i++){
470 for(j=starty;j<endy;j++){
471 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){
472 color=Random()%85+170;
473 where=i*skeleton.skinsize*3+j*3;
474 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
475 skeleton.skinText[where+1]=0;
476 skeleton.skinText[where+2]=0;
480 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
485 if(creature==rabbittype)
486 while(bloodText[bleedxint*512*3+bleedyint*3+0]>which+4||bloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
487 bleedxint=abs(Random()%512);
488 bleedyint=abs(Random()%512);
490 if(creature==wolftype)
491 while(wolfbloodText[bleedxint*512*3+bleedyint*3+0]>which+4||wolfbloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
492 bleedxint=abs(Random()%512);
493 bleedyint=abs(Random()%512);
495 bleedy=bleedxint+offsetx;
496 bleedx=bleedyint+offsety;
497 bleedy/=realtexdetail;
498 bleedx/=realtexdetail;
499 if(bleedx<0)bleedx=0;
500 if(bleedy<0)bleedy=0;
501 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
502 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
503 direction=abs(Random()%2)*2-1;
506 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
507 deathbleeding+=bleeding;
508 bloodloss+=bleeding*3;
510 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
511 if(abs(Random()%2)==0){aitype=gethelptype;
514 else aitype=attacktypecutoff;
517 if(bleeding>2)bleeding=2;
520 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
523 static XYZ startpoint,endpoint,colpoint,movepoint;
524 static float rotationpoint;
526 static XYZ p1,p2,p3,p0;
530 float coordsx,coordsy;
533 if(bloodtoggle&&decals&&tutoriallevel!=1){
535 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
543 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
546 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
547 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
548 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
550 CrossProduct(p2-p1,p3-p1,&N);
551 CrossProduct(p0-p1,p3-p1,&temp);
552 s = dotproduct(&temp,&N)/findLength(&N);
553 CrossProduct(p2-p1,p1-p0,&temp);
554 t = dotproduct(&temp,&N)/findLength(&N);
557 bary.x=findDistancefast(&p0,&p1);
558 bary.y=findDistancefast(&p0,&p2);
559 bary.z=findDistancefast(&p0,&p3);
561 total=bary.x+bary.y+bary.z;
570 total=bary.x+bary.y+bary.z;
576 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
577 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
578 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
579 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
580 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
581 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
582 coordsx=skeleton.drawmodel.Triangles[whichtri].gx[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gx[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gx[2]*bary.z;
583 coordsy=skeleton.drawmodel.Triangles[whichtri].gy[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gy[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gy[2]*bary.z;
585 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
586 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
588 if(bleeding<=0&&spurt){
590 for(int i=0;i<3;i++){
594 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
597 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
599 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
600 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
602 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
603 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
606 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
607 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
611 int offsetx=0,offsety=0;
614 offsetx=abs(Random()%120);
616 if(which==220||which==215){
618 offsetx=abs(Random()%80);
621 offsetx=(1+coordsy)*512-291;
622 offsety=coordsx*512-437;
629 if(creature==rabbittype)
632 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
633 if(i<startx)startx=i;
634 if(j<starty)starty=j;
640 if(creature==wolftype)
643 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
644 if(i<startx)startx=i;
645 if(j<starty)starty=j;
656 if(startx<0)startx=0;
657 if(starty<0)starty=0;
658 if(endx>512-1)endx=512-1;
659 if(endy>512-1)endy=512-1;
660 if(endx<startx)endx=startx;
661 if(endy<starty)endy=starty;
663 startx/=realtexdetail;
664 starty/=realtexdetail;
668 int texdetailint=realtexdetail;
670 if(creature==rabbittype)
671 for(i=startx;i<endx;i++){
672 for(j=starty;j<endy;j++){
673 if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
674 color=Random()%85+170;
675 where=i*skeleton.skinsize*3+j*3;
676 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
677 skeleton.skinText[where+1]=0;
678 skeleton.skinText[where+2]=0;
680 else if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
681 color=Random()%85+170;
682 where=i*skeleton.skinsize*3+j*3;
683 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
684 skeleton.skinText[where+1]=0;
685 skeleton.skinText[where+2]=0;
689 if(creature==wolftype)
690 for(i=startx;i<endx;i++){
691 for(j=starty;j<endy;j++){
692 if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
693 color=Random()%85+170;
694 where=i*skeleton.skinsize*3+j*3;
695 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
696 skeleton.skinText[where+1]=0;
697 skeleton.skinText[where+2]=0;
699 else if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
700 color=Random()%85+170;
701 where=i*skeleton.skinsize*3+j*3;
702 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
703 skeleton.skinText[where+1]=0;
704 skeleton.skinText[where+2]=0;
708 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
711 bleedy=(1+coordsy)*512;
713 bleedy/=realtexdetail;
714 bleedx/=realtexdetail;
715 if(bleedx<0)bleedx=0;
716 if(bleedy<0)bleedy=0;
717 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
718 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
719 direction=abs(Random()%2)*2-1;
721 if(whichtri==-1)return 0;
723 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
724 deathbleeding+=bleeding;
725 bloodloss+=bleeding*3;
727 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
728 if(abs(Random()%2)==0){aitype=gethelptype;
731 else aitype=attacktypecutoff;
734 if(bleeding>2)bleeding=2;
740 void Person::Reverse()
742 if (!((victim->aitype == playercontrolled
744 || staggerdelay <= 0)
745 && victim->targetanimation != jumpupanim
746 && victim->targetanimation != jumpdownanim
747 && (tutoriallevel != 1 || cananger)
751 if (normaldotproduct (victim->facing, victim->coords-coords) > 0
752 && (victim->id != 0 || difficulty >= 2)
753 && (creature != wolftype || victim->creature == wolftype))
756 if(targetanimation==sweepanim){
757 targetanimation=sweepreversedanim;
758 currentanimation=sweepreversedanim;
759 victim->currentanimation=sweepreversalanim;
760 victim->targetanimation=sweepreversalanim;
762 if(targetanimation==spinkickanim){
763 targetanimation=spinkickreversedanim;
764 currentanimation=spinkickreversedanim;
765 victim->currentanimation=spinkickreversalanim;
766 victim->targetanimation=spinkickreversalanim;
768 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
769 if(targetanimation==rabbittacklinganim){
772 victim->currentframe=6;
773 victim->targetframe=7;
775 targetanimation=upunchreversedanim;
776 currentanimation=upunchreversedanim;
777 victim->currentanimation=upunchreversalanim;
778 victim->targetanimation=upunchreversalanim;
780 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
781 if(victim->weaponactive!=-1){
782 victim->throwtogglekeydown=1;
783 weapons[victim->weaponids[0]].owner=-1;
784 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
785 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
786 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
787 weapons[victim->weaponids[0]].missed=1;
788 weapons[victim->weaponids[0]].freetime=0;
789 weapons[victim->weaponids[0]].firstfree=1;
790 weapons[victim->weaponids[0]].physics=1;
791 victim->num_weapons--;
792 if(victim->num_weapons){
793 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
794 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
797 victim->weaponactive=-1;
798 for(int j=0;j<numplayers;j++){
799 player[j].wentforweapon=0;
803 targetanimation=staffhitreversedanim;
804 currentanimation=staffhitreversedanim;
805 victim->currentanimation=staffhitreversalanim;
806 victim->targetanimation=staffhitreversalanim;
808 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
809 if(victim->weaponactive!=-1){
810 victim->throwtogglekeydown=1;
811 weapons[victim->weaponids[0]].owner=-1;
812 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
813 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
814 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
815 weapons[victim->weaponids[0]].missed=1;
816 weapons[victim->weaponids[0]].freetime=0;
817 weapons[victim->weaponids[0]].firstfree=1;
818 weapons[victim->weaponids[0]].physics=1;
819 victim->num_weapons--;
820 if(victim->num_weapons){
821 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
822 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
825 victim->weaponactive=-1;
826 for(int j=0;j<numplayers;j++){
827 player[j].wentforweapon=0;
830 targetanimation=staffspinhitreversedanim;
831 currentanimation=staffspinhitreversedanim;
832 victim->currentanimation=staffspinhitreversalanim;
833 victim->targetanimation=staffspinhitreversalanim;
835 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
836 if(victim->weaponactive!=-1){
837 victim->throwtogglekeydown=1;
838 weapons[victim->weaponids[0]].owner=-1;
839 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
840 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
841 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
842 weapons[victim->weaponids[0]].missed=1;
843 weapons[victim->weaponids[0]].freetime=0;
844 weapons[victim->weaponids[0]].firstfree=1;
845 weapons[victim->weaponids[0]].physics=1;
846 victim->num_weapons--;
847 if(victim->num_weapons){
848 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
849 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
852 victim->weaponactive=-1;
853 for(int j=0;j<numplayers;j++){
854 player[j].wentforweapon=0;
857 targetanimation=swordslashreversedanim;
858 currentanimation=swordslashreversedanim;
859 victim->currentanimation=swordslashreversalanim;
860 victim->targetanimation=swordslashreversalanim;
862 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
863 if(victim->weaponactive!=-1){
864 victim->throwtogglekeydown=1;
865 weapons[victim->weaponids[0]].owner=-1;
866 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
867 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
868 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
869 weapons[victim->weaponids[0]].missed=1;
870 weapons[victim->weaponids[0]].freetime=0;
871 weapons[victim->weaponids[0]].firstfree=1;
872 weapons[victim->weaponids[0]].physics=1;
873 victim->num_weapons--;
874 if(victim->num_weapons){
875 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
876 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
879 victim->weaponactive=-1;
880 for(int j=0;j<numplayers;j++){
881 player[j].wentforweapon=0;
884 targetanimation=knifeslashreversedanim;
885 currentanimation=knifeslashreversedanim;
886 victim->currentanimation=knifeslashreversalanim;
887 victim->targetanimation=knifeslashreversalanim;
889 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
890 victim->targettilt2=targettilt2;
891 victim->currentframe=currentframe;
892 victim->targetframe=targetframe;
893 victim->target=target;
895 victim->oldcoords=victim->coords;
896 victim->coords=coords;
897 victim->targetrotation=targetrotation;
898 victim->rotation=targetrotation;
901 if(targetanimation==winduppunchanim){
902 targetanimation=winduppunchblockedanim;
903 victim->targetanimation=blockhighleftanim;
904 victim->targetframe=1;
907 victim->targetrotation=targetrotation+180;
909 if(targetanimation==wolfslapanim){
910 targetanimation=winduppunchblockedanim;
911 victim->targetanimation=blockhighleftanim;
912 victim->targetframe=1;
915 victim->targetrotation=targetrotation+180;
917 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
918 targetanimation=swordslashparriedanim;
920 victim->parriedrecently=0;
921 victim->targetanimation=swordslashparryanim;
922 victim->targetframe=1;
925 victim->targetrotation=targetrotation+180;
927 if(abs(Random()%20)==0||weapons[victim->weaponids[victim->weaponactive]].getType()==knife){
928 if(victim->weaponactive!=-1){
929 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff) {
930 if(weapons[victim->weaponids[0]].getType()==staff)
931 weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
932 if(weapons[weaponids[0]].getType()==staff)
933 weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
934 emit_sound_at(swordstaffsound, victim->coords);
937 emit_sound_at(metalhitsound, victim->coords);
941 victim->Puff(righthand);
943 victim->targetframe=0;
944 victim->targetanimation=staggerbackhighanim;
945 victim->targetrotation=targetrotation+180;
947 weapons[victim->weaponids[0]].owner=-1;
948 aim=DoRotation(facing,0,90,0)*21;
950 weapons[victim->weaponids[0]].velocity=aim*-.2;
951 weapons[victim->weaponids[0]].tipvelocity=aim;
952 weapons[victim->weaponids[0]].missed=1;
953 weapons[victim->weaponids[0]].hitsomething=0;
954 weapons[victim->weaponids[0]].freetime=0;
955 weapons[victim->weaponids[0]].firstfree=1;
956 weapons[victim->weaponids[0]].physics=1;
957 victim->num_weapons--;
958 if(victim->num_weapons){
959 victim->weaponids[0]=victim->weaponids[num_weapons];
960 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
962 victim->weaponactive=-1;
963 for(int i=0;i<numplayers;i++){
964 player[i].wentforweapon=0;
968 if(abs(Random()%20)==0){
969 if(weaponactive!=-1){
970 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
971 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
972 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
974 emit_sound_at(swordstaffsound, coords);
977 emit_sound_at(metalhitsound, coords);
985 targetanimation=staggerbackhighanim;
986 targetrotation=targetrotation+180;
988 weapons[weaponids[0]].owner=-1;
989 aim=DoRotation(facing,0,90,0)*21;
991 weapons[weaponids[0]].velocity=aim*-.2;
992 weapons[weaponids[0]].tipvelocity=aim;
993 weapons[weaponids[0]].hitsomething=0;
994 weapons[weaponids[0]].missed=1;
995 weapons[weaponids[0]].freetime=0;
996 weapons[weaponids[0]].firstfree=1;
997 weapons[weaponids[0]].physics=1;
1000 weaponids[0]=weaponids[num_weapons];
1001 if(weaponstuck==num_weapons)weaponstuck=0;
1004 for(int i=0;i<numplayers;i++){
1005 player[i].wentforweapon=0;
1012 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1013 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1014 victim->targetanimation=dodgebackanim;
1015 victim->targetframe=0;
1019 rotatetarget=coords-victim->coords;
1020 Normalise(&rotatetarget);
1021 victim->targetrotation=-asin(0-rotatetarget.x);
1022 victim->targetrotation*=360/6.28;
1023 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1025 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1027 victim->lastattack3=victim->lastattack2;
1028 victim->lastattack2=victim->lastattack;
1029 victim->lastattack=victim->targetanimation;
1033 victim->targetanimation=sweepanim;
1034 victim->targetframe=0;
1038 rotatetarget=coords-victim->coords;
1039 Normalise(&rotatetarget);
1040 victim->targetrotation=-asin(0-rotatetarget.x);
1041 victim->targetrotation*=360/6.28;
1042 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1044 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1046 victim->lastattack3=victim->lastattack2;
1047 victim->lastattack2=victim->lastattack;
1048 victim->lastattack=victim->targetanimation;
1055 if(aitype!=playercontrolled)feint=0;
1056 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1057 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1058 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1060 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1063 void Person::DoDamage(float howmuch){
1064 if(tutoriallevel!=1)damage+=howmuch/power;
1065 if(id!=0)damagedealt+=howmuch/power;
1066 if(id==0)damagetaken+=howmuch/power;
1068 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1069 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1070 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1071 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1072 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1074 if(id==0)camerashake+=howmuch/100;
1075 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1076 if(blackout>1)blackout=1;
1078 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1079 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1080 if(abs(Random()%2)==0){aitype=gethelptype;
1083 else aitype=attacktypecutoff;
1087 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1090 for(int i=0;i<skeleton.num_joints; i++){
1091 if(!skeleton.free)flatvelocity2=velocity;
1092 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1093 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1094 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1095 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1096 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1097 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1098 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1099 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1100 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1103 emit_sound_at(splattersound, coords);
1112 if(!dead&&creature==wolftype){
1113 award_bonus(0, Wolfbonus);
1119 if(tutoriallevel!=1||id==0)
1120 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1123 if(creature==wolftype){
1124 int i=abs(Random()%2);
1125 if(i==0)whichsound=snarlsound;
1126 if(i==1)whichsound=snarl2sound;
1127 envsound[numenvsounds]=coords;
1128 envsoundvol[numenvsounds]=16;
1129 envsoundlife[numenvsounds]=.4;
1132 if(creature==rabbittype){
1133 int i=abs(Random()%2);
1134 if(i==0)whichsound=rabbitpainsound;
1135 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1136 envsound[numenvsounds]=coords;
1137 envsoundvol[numenvsounds]=16;
1138 envsoundlife[numenvsounds]=.4;
1140 //if(i==2)whichsound=rabbitpain2sound;
1144 emit_sound_at(whichsound, coords);
1149 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1150 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1153 void Person::DoHead(){
1154 static XYZ rotatearound;
1156 static float lookspeed=500;
1158 if(!freeze&&!winfreeze){
1161 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1162 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1164 while(targetheadrotation>180)targetheadrotation-=360;
1165 while(targetheadrotation<-180)targetheadrotation+=360;
1167 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1168 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1169 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1170 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1172 if(targetheadrotation2>120)targetheadrotation2=120;
1173 if(targetheadrotation2<-120)targetheadrotation2=-120;
1174 if(targetheadrotation>120)targetheadrotation=120;
1175 if(targetheadrotation<-120)targetheadrotation=-120;
1177 if(!isIdle())targetheadrotation2=0;
1179 if(targetheadrotation>80)targetheadrotation=80;
1180 if(targetheadrotation<-80)targetheadrotation=-80;
1181 if(targetheadrotation2>50)targetheadrotation2=50;
1182 if(targetheadrotation2<-50)targetheadrotation2=-50;
1185 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1186 else if(headrotation>targetheadrotation){
1187 headrotation-=multiplier*lookspeed;
1189 else if(headrotation<targetheadrotation){
1190 headrotation+=multiplier*lookspeed;
1193 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1194 else if(headrotation2>targetheadrotation2){
1195 headrotation2-=multiplier*lookspeed/2;
1197 else if(headrotation2<targetheadrotation2){
1198 headrotation2+=multiplier*lookspeed/2;
1201 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1202 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1206 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1207 facing=DoRotation(facing,headrotation2*.4,0,0);
1208 facing=DoRotation(facing,0,headrotation*.4,0);
1211 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1212 facing=DoRotation(facing,headrotation2*.8,0,0);
1213 facing=DoRotation(facing,0,headrotation*.8,0);
1216 if(targetanimation==walkanim){
1217 facing=DoRotation(facing,headrotation2*.6,0,0);
1218 facing=DoRotation(facing,0,headrotation*.6,0);
1221 skeleton.specialforward[0]=facing;
1222 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1224 for(i=0;i<skeleton.num_muscles;i++){
1225 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1227 skeleton.FindRotationMuscle(i,targetanimation);
1233 void Person::RagDoll(bool checkcollision){
1238 if(id==0)numfalls++;
1239 if(id==0&&isFlip())numflipfail++;
1245 facing=DoRotation(facing,0,rotation,0);
1247 skeleton.freetime=0;
1249 skeleton.longdead=0;
1255 skeleton.freefall=1;
1257 if(!isnormal(velocity.x))velocity.x=0;
1258 if(!isnormal(velocity.y))velocity.y=0;
1259 if(!isnormal(velocity.z))velocity.z=0;
1260 if(!isnormal(rotation))rotation=0;
1261 if(!isnormal(coords.x))coords=0;
1262 if(!isnormal(tilt))tilt=0;
1263 if(!isnormal(tilt2))tilt2=0;
1265 for(i=0;i<skeleton.num_joints;i++){
1266 skeleton.joints[i].delay=0;
1267 skeleton.joints[i].locked=0;
1268 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1269 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1270 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1271 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1272 skeleton.joints[i].position.y+=.1;
1273 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1274 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1277 for(i=0;i<skeleton.num_joints;i++){
1278 skeleton.joints[i].velocity=0;
1279 skeleton.joints[i].velchange=0;
1281 skeleton.DoConstraints(&coords,&scale);
1282 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1284 skeleton.DoConstraints(&coords,&scale);
1285 skeleton.DoConstraints(&coords,&scale);
1286 skeleton.DoConstraints(&coords,&scale);
1287 skeleton.DoConstraints(&coords,&scale);
1290 speed=animation[targetanimation].speed[targetframe]*2;
1291 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1292 speed=animation[currentanimation].speed[currentframe]*2;
1294 if(transspeed)speed=transspeed*2;
1298 for(i=0;i<skeleton.num_joints;i++){
1299 if((animation[currentanimation].attack!=reversed||currentanimation==swordslashreversedanim)&¤tanimation!=rabbitkickanim&&!isLanding()&&!wasLanding()&&animation[currentanimation].height==animation[targetanimation].height)skeleton.joints[i].velocity=velocity/scale+facing*5+DoRotation(DoRotation(DoRotation((animation[targetanimation].position[i][targetframe]-animation[currentanimation].position[i][currentframe])*speed,0,0,tilt),tilt2,0,0),0,rotation,0);
1300 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1301 change.x=(float)(Random()%100)/100;
1302 change.y=(float)(Random()%100)/100;
1303 change.z=(float)(Random()%100)/100;
1304 skeleton.joints[i].velocity+=change;
1305 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1307 change.x=(float)(Random()%100)/100;
1308 change.y=(float)(Random()%100)/100;
1309 change.z=(float)(Random()%100)/100;
1310 skeleton.joints[i].velchange+=change;
1311 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1321 for(j=0;j<skeleton.num_joints;j++){
1322 average+=skeleton.joints[j].position;
1326 coords+=average*scale;
1327 for(j=0;j<skeleton.num_joints;j++){
1328 skeleton.joints[j].position-=average;
1331 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale);
1332 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale);
1333 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1334 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1335 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1338 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1339 coords.x=lowpoint.x;
1340 coords.z=lowpoint.z;
1349 for(i=0;i<skeleton.num_joints;i++){
1350 velocity+=skeleton.joints[i].velocity*scale;
1352 velocity/=skeleton.num_joints;
1355 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1356 weapons[weaponids[0]].owner=-1;
1357 weapons[weaponids[0]].hitsomething=0;
1358 weapons[weaponids[0]].velocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1359 weapons[weaponids[0]].velocity.x+=.01;
1360 weapons[weaponids[0]].tipvelocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1361 weapons[weaponids[0]].missed=1;
1362 weapons[weaponids[0]].freetime=0;
1363 weapons[weaponids[0]].firstfree=1;
1364 weapons[weaponids[0]].physics=1;
1367 weaponids[0]=weaponids[num_weapons];
1368 if(weaponstuck==num_weapons)weaponstuck=0;
1371 for(i=0;i<numplayers;i++){
1372 player[i].wentforweapon=0;
1377 targetanimation=bounceidleanim;
1378 currentanimation=bounceidleanim;
1386 void Person::FootLand(int which, float opacity){
1387 static XYZ terrainlight;
1388 static XYZ footvel,footpoint;
1389 if(opacity>=1||skiddelay<=0)
1393 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1394 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1395 //footpoint.y=coords.y;
1396 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1398 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1400 if(footvel.y<.8)footvel.y=.8;
1401 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1402 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1403 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1404 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1405 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1406 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1408 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1410 if(footvel.y<.8)footvel.y=.8;
1411 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1412 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1413 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1414 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1415 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);
1417 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1419 if(footvel.y<.8)footvel.y=.8;
1420 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1421 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1422 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1423 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1424 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);
1425 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1427 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1430 if(footvel.y<.8)footvel.y=.8;
1431 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1432 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1433 //footpoint.y=coords.y;
1434 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1438 void Person::Puff(int whichlabel){
1439 static XYZ footvel,footpoint;
1442 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1443 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1447 void Person::DoAnimations(){
1450 static float oldtarget;
1452 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1454 if(targetanimation==tempanim||currentanimation==tempanim){
1455 animation[tempanim]=tempanimation;
1457 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1468 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1469 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1471 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1472 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1474 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1479 targfacing=DoRotation(targfacing,0,targetrotation,0);
1481 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1482 else targetanimation=backflipanim;
1483 crouchtogglekeydown=1;
1487 if(id==0)numflipped++;
1490 if(animation[targetanimation].attack!=reversed)feint=0;
1491 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1492 crouchtogglekeydown=0;
1493 if(aitype==playercontrolled)feint=0;
1497 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1498 if(!isFlip())crouchtogglekeydown=1;
1502 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1503 if(detail)normalsupdatedelay=0;
1507 if(targetanimation==rollanim&&targetframe==3&&onfire){
1509 emit_sound_at(fireendsound, coords);
1510 pause_sound(stream_firesound);
1514 if(targetanimation==rabbittacklinganim&&targetframe==1){
1515 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1516 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1517 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1518 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1519 else victim->targetanimation=rabbittackledfrontanim;
1520 victim->targetframe=2;
1522 victim->rotation=rotation;
1523 victim->targetrotation=rotation;
1524 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1525 //victim->DoDamage(30);
1526 if(creature==wolftype){
1528 emit_sound_at(clawslicesound, victim->coords);
1530 victim->DoBloodBig(1/victim->armorhead,210);
1532 award_bonus(id, TackleBonus,
1533 victim->aitype == gethelptype ? 50 : 0);
1537 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1538 if(weapons[weaponids[0]].getType()==knife){
1539 if(weaponactive==-1)weaponactive=0;
1540 else if(weaponactive==0)weaponactive=-1;
1542 if(weaponactive==-1){
1543 emit_sound_at(knifesheathesound, coords);
1545 if(weaponactive!=-1){
1546 emit_sound_at(knifedrawsound, coords, 128);
1549 drawtogglekeydown=1;
1552 if(tutoriallevel!=1||id==0)
1553 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1556 if(terrain.getOpacity(coords.x,coords.z)<.2){
1557 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1558 else whichsound=footstepsound2;
1559 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1560 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1561 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1567 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1568 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1569 else whichsound=footstepsound4;
1573 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1574 else whichsound=footstepsound4;
1576 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1577 if(animation[targetanimation].attack!=neutral){
1579 if(i==0)whichsound=lowwhooshsound;
1580 if(i==1)whichsound=midwhooshsound;
1581 if(i==2)whichsound=highwhooshsound;
1583 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1585 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1586 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1588 emit_sound_at(whichsound, coords, 256.);
1591 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1592 envsound[numenvsounds]=coords;
1593 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1594 else envsoundvol[numenvsounds]=6;
1595 envsoundlife[numenvsounds]=.4;
1599 if(animation[targetanimation].label[targetframe]==3){
1601 emit_sound_at(whichsound, coords, 128.);
1606 if(tutoriallevel!=1||id==0)
1608 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1609 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1611 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1612 if(animation[targetanimation].attack!=neutral){
1614 if(creature==rabbittype){
1615 if(i==0)whichsound=rabbitattacksound;
1616 if(i==1)whichsound=rabbitattack2sound;
1617 if(i==2)whichsound=rabbitattack3sound;
1618 if(i==3)whichsound=rabbitattack4sound;
1620 if(creature==wolftype){
1621 if(i==0)whichsound=barksound;
1622 if(i==1)whichsound=bark2sound;
1623 if(i==2)whichsound=bark3sound;
1624 if(i==3)whichsound=barkgrowlsound;
1628 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1630 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1631 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1634 emit_sound_at(whichsound, coords);
1640 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1646 currentoffset=targetoffset;
1647 targetframe=currentframe;
1648 currentanimation=targetanimation;
1651 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1652 for(i=0;i<weapons.size();i++){
1653 if(weapons[i].owner==-1)
1654 if(findDistancefastflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
1655 if(findDistancefast(&coords,&weapons[i].position)>=1){
1656 if(weapons[i].getType()!=staff){
1657 emit_sound_at(knifedrawsound, coords, 128.);
1661 weapons[i].owner=id;
1663 weaponids[num_weapons]=weaponids[0];
1672 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1673 for(i=0;i<weapons.size();i++){
1675 if(weapons[i].owner!=-1)
1676 if(player[weapons[i].owner].weaponstuck!=-1)
1677 if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i)
1678 if(player[weapons[i].owner].num_weapons>1)willwork=0;
1679 if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free))
1680 if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
1681 if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){
1682 bool fleshstuck=false;
1683 if(weapons[i].owner!=-1)
1684 if(victim->weaponstuck!=-1){
1685 if(victim->weaponids[victim->weaponstuck]==i){
1690 emit_sound_at(fleshstabremovesound, coords, 128.);
1692 if(weapons[i].getType()!=staff){
1693 emit_sound_at(knifedrawsound, coords, 128.);
1697 if(weapons[i].owner!=-1){
1699 victim=&player[weapons[i].owner];
1700 if(victim->num_weapons==1)victim->num_weapons=0;
1701 else victim->num_weapons=1;
1703 //victim->weaponactive=-1;
1704 victim->skeleton.longdead=0;
1705 victim->skeleton.free=1;
1706 victim->skeleton.broken=0;
1708 for(int j=0;j<victim->skeleton.num_joints;j++){
1709 victim->skeleton.joints[j].velchange=0;
1710 victim->skeleton.joints[j].locked=0;
1716 Normalise(&relative);
1717 XYZ footvel,footpoint;
1719 footpoint=weapons[i].position;
1720 if(victim->weaponstuck!=-1){
1721 if(victim->weaponids[victim->weaponstuck]==i){
1722 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1723 weapons[i].bloody=2;
1724 weapons[i].blooddrip=5;
1725 victim->weaponstuck=-1;
1728 if(victim->num_weapons>0){
1729 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1730 if(victim->weaponids[0]==i)
1731 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1734 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1735 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1736 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1737 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1739 weapons[i].owner=id;
1741 weaponids[num_weapons]=weaponids[0];
1750 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1751 if(weaponactive==-1)weaponactive=0;
1752 else if(weaponactive==0){
1756 buffer=weaponids[0];
1757 weaponids[0]=weaponids[1];
1758 weaponids[1]=buffer;
1761 if(weaponactive==-1){
1762 emit_sound_at(knifesheathesound, coords, 128.);
1764 if(weaponactive!=-1){
1765 emit_sound_at(knifedrawsound, coords, 128.);
1770 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1771 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1772 Normalise(&rotatetarget);
1773 targetrotation=-asin(0-rotatetarget.x);
1774 targetrotation*=360/6.28;
1775 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1777 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1778 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1783 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1785 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;
1787 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1788 targetanimation=rabbittackleanim;
1790 emit_sound_at(jumpsound, coords);
1799 Normalise(&targetloc);
1801 for(i=0;i<numplayers;i++){
1803 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1804 closestdist=findDistancefast(&targetloc,&player[i].coords);
1809 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1811 victim=&player[closestid];
1812 coords=victim->coords;
1813 currentanimation=rabbittacklinganim;
1814 targetanimation=rabbittacklinganim;
1818 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1819 rotatetarget=coords-victim->coords;
1820 Normalise(&rotatetarget);
1821 targetrotation=-asin(0-rotatetarget.x);
1822 targetrotation*=360/6.28;
1823 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1825 if(targetanimation!=rabbitrunninganim){
1826 emit_sound_at(jumpsound, coords, 128.);
1832 float damagemult=1*power;
1833 if(creature==wolftype)damagemult=2.5*power;
1834 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1835 //if(onfire)damagemult=3;
1836 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1837 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1838 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1840 if(id==0)camerashake+=.4;
1841 if(Random()%2||creature==wolftype){
1844 if(creature==wolftype)DoBloodBig(0,250);
1846 if(tutoriallevel!=1){
1847 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1849 if(creature==wolftype){
1850 emit_sound_at(clawslicesound, victim->coords, 128.);
1852 victim->DoBloodBig(2/victim->armorhead,175);
1856 relative=victim->coords-coords;
1858 Normalise(&relative);
1859 relative=DoRotation(relative,0,-90,0);
1860 for(i=0;i<victim->skeleton.num_joints;i++){
1861 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1863 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1866 victim->DoDamage(damagemult*100/victim->protectionhead);
1872 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1873 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1875 if(id==0)camerashake+=.4;
1876 if(Random()%2||creature==wolftype){
1878 if(creature==wolftype)DoBloodBig(0,235);
1880 emit_sound_at(whooshhitsound, victim->coords);
1881 if(creature==wolftype){
1882 emit_sound_at(clawslicesound, victim->coords, 128.);
1884 victim->DoBloodBig(2,175);
1888 relative=victim->coords-coords;
1890 Normalise(&relative);
1892 Normalise(&relative);
1893 relative=DoRotation(relative,0,90,0);
1894 for(i=0;i<victim->skeleton.num_joints;i++){
1895 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
1897 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1900 victim->DoDamage(damagemult*50/victim->protectionhead);
1904 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
1905 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1907 if(id==0)camerashake+=.4;
1910 if(tutoriallevel!=1){
1911 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1913 if(creature==wolftype){
1914 emit_sound_at(clawslicesound, victim->coords, 128.);
1916 victim->DoBloodBig(2/victim->armorhead,175);
1922 Normalise(&relative);
1923 relative=DoRotation(relative,0,-90,0);
1924 for(i=0;i<victim->skeleton.num_joints;i++){
1925 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1927 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1930 victim->DoDamage(damagemult*150/victim->protectionhead);
1932 if(victim->damage>victim->damagetolerance)
1933 award_bonus(id, style);
1939 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
1940 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1942 if(id==0)camerashake+=.4;
1945 if(tutoriallevel!=1){
1946 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1948 if(creature==wolftype){
1949 emit_sound_at(clawslicesound, victim->coords, 128.);
1951 victim->DoBloodBig(2/victim->armorhead,175);
1957 Normalise(&relative);
1958 relative=DoRotation(relative,0,90,0);
1959 for(i=0;i<victim->skeleton.num_joints;i++){
1960 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1962 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1965 victim->DoDamage(damagemult*150/victim->protectionhead);
1967 if(victim->damage>victim->damagetolerance)
1968 award_bonus(id, style);
1974 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
1975 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1977 if(id==0)camerashake+=.4;
1982 emit_sound_at(whooshhitsound, victim->coords);
1985 relative=victim->coords-coords;
1987 Normalise(&relative);
1988 for(i=0;i<victim->skeleton.num_joints;i++){
1989 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
1991 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1994 victim->DoDamage(damagemult*50/victim->protectionhead);
1998 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
1999 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2001 if(id==0)camerashake+=.2;
2002 emit_sound_at(whooshhitsound, victim->coords, 128.);
2004 victim->skeleton.longdead=0;
2005 victim->skeleton.free=1;
2006 victim->skeleton.broken=0;
2007 victim->skeleton.spinny=1;
2009 for(i=0;i<victim->skeleton.num_joints;i++){
2010 victim->skeleton.joints[i].velchange=0;
2011 victim->skeleton.joints[i].delay=0;
2012 victim->skeleton.joints[i].locked=0;
2013 //victim->skeleton.joints[i].velocity=0;
2019 Normalise(&relative);
2020 for(i=0;i<victim->skeleton.num_joints;i++){
2021 victim->skeleton.joints[i].velocity.y=relative.y*10;
2022 victim->skeleton.joints[i].position.y+=relative.y*.3;
2023 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2024 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2026 victim->Puff(abdomen);
2027 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2031 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2032 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2034 if(id==0)camerashake+=.4;
2035 if(tutoriallevel!=1){
2036 emit_sound_at(heavyimpactsound, coords, 128.);
2039 relative=victim->coords-coords;
2041 Normalise(&relative);
2042 for(i=0;i<victim->skeleton.num_joints;i++){
2043 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2045 victim->Puff(abdomen);
2046 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2050 victim->DoDamage(damagemult*500/victim->protectionhigh);
2051 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2055 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2056 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2058 if(id==0)camerashake+=.4;
2059 if(tutoriallevel!=1){
2060 emit_sound_at(thudsound, coords);
2063 victim->skeleton.longdead=0;
2064 victim->skeleton.free=1;
2065 victim->skeleton.broken=0;
2066 victim->skeleton.spinny=1;
2068 for(i=0;i<victim->skeleton.num_joints;i++){
2069 victim->skeleton.joints[i].velchange=0;
2070 //victim->skeleton.joints[i].delay=0;
2071 victim->skeleton.joints[i].locked=0;
2074 relative=victim->coords-coords;
2075 Normalise(&relative);
2077 Normalise(&relative);
2078 for(i=0;i<victim->skeleton.num_joints;i++){
2079 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2084 victim->Puff(abdomen);
2085 victim->DoDamage(damagemult*20/victim->protectionhigh);
2086 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2088 if(!victim->dead)staggerdelay=1.2;
2094 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2095 //if(id==0)camerashake+=.4;
2098 if(!victim->skeleton.free)hasvictim=0;
2101 terrain.MakeDecal(blooddecalfast,(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2),.08,.6,Random()%360);
2102 emit_sound_at(knifesheathesound, coords, 128.);
2105 if(victim&&hasvictim){
2106 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2108 XYZ where,startpoint,endpoint,movepoint,colpoint;
2109 float rotationpoint;
2111 if(weapons[weaponids[weaponactive]].getType()==knife){
2112 where=(weapons[weaponids[weaponactive]].tippoint*.6+weapons[weaponids[weaponactive]].position*.4);
2113 where-=victim->coords;
2114 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2121 if(weapons[weaponids[weaponactive]].getType()==sword){
2122 where=weapons[weaponids[weaponactive]].position;
2123 where-=victim->coords;
2124 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2126 where=weapons[weaponids[weaponactive]].tippoint;
2127 where-=victim->coords;
2128 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2131 if(weapons[weaponids[weaponactive]].getType()==staff){
2132 where=weapons[weaponids[weaponactive]].position;
2133 where-=victim->coords;
2134 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2136 where=weapons[weaponids[weaponactive]].tippoint;
2137 where-=victim->coords;
2138 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2143 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2146 if(victim->dead!=2){
2147 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2149 award_bonus(id, FinishedBonus);
2151 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
2153 victim->skeleton.longdead=0;
2154 victim->skeleton.free=1;
2155 victim->skeleton.broken=0;
2157 for(i=0;i<victim->skeleton.num_joints;i++){
2158 victim->skeleton.joints[i].velchange=0;
2159 victim->skeleton.joints[i].locked=0;
2160 //victim->skeleton.joints[i].velocity=0;
2162 emit_sound_at(fleshstabsound, coords, 128);
2165 if(whichtri!=-1||weapons[weaponids[weaponactive]].bloody){
2166 weapons[weaponids[weaponactive]].blooddrip+=5;
2167 weapons[weaponids[weaponactive]].blooddripdelay=0;
2171 emit_sound_at(knifesheathesound, coords, 128.);
2177 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2179 emit_sound_at(knifedrawsound, coords, 128);
2182 if(victim&&hasvictim){
2183 XYZ footvel,footpoint;
2185 emit_sound_at(fleshstabremovesound, coords, 128.);
2188 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2190 if(weapons[weaponids[weaponactive]].getType()==sword){
2191 XYZ where,startpoint,endpoint,movepoint;
2192 float rotationpoint;
2195 where=weapons[weaponids[weaponactive]].position;
2196 where-=victim->coords;
2197 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2199 where=weapons[weaponids[weaponactive]].tippoint;
2200 where-=victim->coords;
2201 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2206 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2207 footpoint+=victim->coords;
2210 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2213 if(weapons[weaponids[weaponactive]].getType()==staff){
2214 XYZ where,startpoint,endpoint,movepoint;
2215 float rotationpoint;
2218 where=weapons[weaponids[weaponactive]].position;
2219 where-=victim->coords;
2220 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2222 where=weapons[weaponids[weaponactive]].tippoint;
2223 where-=victim->coords;
2224 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2229 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2230 footpoint+=victim->coords;
2233 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2236 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2238 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2239 victim->skeleton.longdead=0;
2240 victim->skeleton.free=1;
2241 victim->skeleton.broken=0;
2243 for(i=0;i<victim->skeleton.num_joints;i++){
2244 victim->skeleton.joints[i].velchange=0;
2245 victim->skeleton.joints[i].locked=0;
2246 //victim->skeleton.joints[i].velocity=0;
2252 Normalise(&relative);
2253 //victim->Puff(abdomen);
2254 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2256 if(victim->bloodloss<victim->damagetolerance){
2257 victim->bloodloss+=1000;
2261 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2265 if(!hasvictim&&onterrain){
2266 weapons[weaponids[weaponactive]].bloody=0;
2267 weapons[weaponids[weaponactive]].blooddrip=0;
2271 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2272 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2274 if(id==0)camerashake+=.4;
2279 if(tutoriallevel!=1){
2280 emit_sound_at(heavyimpactsound, victim->coords, 128);
2285 relative=victim->coords-coords;
2287 Normalise(&relative);
2288 for(i=0;i<victim->skeleton.num_joints;i++){
2289 victim->skeleton.joints[i].velocity=relative*30;
2291 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2293 victim->targetframe=0;
2294 victim->targetanimation=staggerbackhardanim;
2295 victim->targetrotation=targetrotation+180;
2300 victim->Puff(abdomen);
2301 victim->DoDamage(damagemult*60/victim->protectionhigh);
2308 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2309 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2311 if(id==0)camerashake+=.4;
2312 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2313 if(tutoriallevel!=1){
2314 emit_sound_at(thudsound, victim->coords);
2317 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2318 if(tutoriallevel!=1){
2319 emit_sound_at(whooshhitsound, victim->coords);
2323 if(tutoriallevel!=1){
2324 emit_sound_at(heavyimpactsound, victim->coords);
2328 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2331 relative=victim->coords-coords;
2333 Normalise(&relative);
2335 Normalise(&relative);
2336 for(i=0;i<victim->skeleton.num_joints;i++){
2337 victim->skeleton.joints[i].velocity=relative*5;
2339 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2341 victim->targetframe=0;
2342 victim->targetanimation=staggerbackhardanim;
2343 victim->targetrotation=targetrotation+180;
2347 victim->Puff(abdomen);
2348 victim->DoDamage(damagemult*60/victim->protectionhigh);
2354 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2355 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2356 if(victim->id==0)camerashake+=.4;
2357 emit_sound_at(landsound2, victim->coords);
2363 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2364 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2365 if(victim->id==0)camerashake+=.4;
2367 if(weaponactive!=-1){
2368 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2369 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2370 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2372 emit_sound_at(swordstaffsound, victim->coords);
2375 emit_sound_at(metalhitsound, victim->coords);
2383 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2384 if(weaponactive!=-1){
2387 weapons[weaponids[0]].owner=-1;
2388 aim=victim->coords+DoRotation(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position,0,victim->rotation,0)*victim->scale+victim->velocity*findDistance(&victim->coords,&coords)/50-(coords+DoRotation(skeleton.joints[skeleton.jointlabels[righthand]].position,0,rotation,0)*scale);
2390 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2391 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2393 weapons[weaponids[0]].velocity=aim*50;
2394 weapons[weaponids[0]].tipvelocity=aim*50;
2395 weapons[weaponids[0]].missed=0;
2396 weapons[weaponids[0]].hitsomething=0;
2397 weapons[weaponids[0]].freetime=0;
2398 weapons[weaponids[0]].firstfree=1;
2399 weapons[weaponids[0]].physics=0;
2402 weaponids[0]=weaponids[num_weapons];
2408 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2410 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2412 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2414 award_bonus(id, Slicebonus);
2415 if(tutoriallevel!=1){
2416 emit_sound_at(knifeslicesound, victim->coords);
2418 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2419 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2420 if(victim->id != 0 || difficulty==2){
2421 victim->targetframe=0;
2422 victim->targetanimation=staggerbackhardanim;
2423 victim->targetrotation=targetrotation+180;
2427 victim->lowreversaldelay=0;
2428 victim->highreversaldelay=0;
2429 if(aitype!=playercontrolled)weaponmissdelay=.6;
2431 if(tutoriallevel!=1)if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2432 if(tutoriallevel!=1)weapons[weaponids[weaponactive]].blooddrip+=3;
2434 XYZ footvel,footpoint;
2437 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2440 footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->rotation,0)*victim->scale+victim->coords;
2442 if(tutoriallevel!=1){
2443 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2444 footvel=DoRotation(facing,0,90,0)*.8;
2446 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2447 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2448 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2449 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2451 if(tutoriallevel==1){
2452 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2454 victim->DoDamage(damagemult*0);
2457 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2458 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2459 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2460 award_bonus(id, Slashbonus);
2462 if(tutoriallevel!=1){
2463 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2464 else victim->DoBloodBig(2/victim->armorhigh,185);
2465 victim->deathbleeding=1;
2466 emit_sound_at(swordslicesound, victim->coords);
2468 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2469 if(tutoriallevel!=1){
2470 victim->targetframe=0;
2471 victim->targetanimation=staggerbackhardanim;
2472 victim->targetrotation=targetrotation+180;
2476 if(tutoriallevel!=1){
2477 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2478 weapons[weaponids[weaponactive]].blooddrip+=3;
2480 float bloodlossamount;
2481 bloodlossamount=200+abs((float)(Random()%40))-20;
2482 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2483 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2484 victim->DoDamage(damagemult*0);
2486 XYZ footvel,footpoint;
2489 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2492 footpoint=DoRotation((victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2,0,victim->rotation,0)*victim->scale+victim->coords;
2494 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2495 footvel=DoRotation(facing,0,90,0)*.8;
2497 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2498 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2499 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2500 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2504 if(victim->weaponactive!=-1){
2505 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2506 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2507 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2509 emit_sound_at(swordstaffsound, victim->coords);
2512 emit_sound_at(metalhitsound, victim->coords);
2518 victim->Puff(righthand);
2520 victim->targetframe=0;
2521 victim->targetanimation=staggerbackhighanim;
2522 victim->targetrotation=targetrotation+180;
2524 weapons[victim->weaponids[0]].owner=-1;
2525 aim=DoRotation(facing,0,90,0)*21;
2527 weapons[victim->weaponids[0]].velocity=aim*-.2;
2528 weapons[victim->weaponids[0]].tipvelocity=aim;
2529 weapons[victim->weaponids[0]].missed=1;
2530 weapons[weaponids[0]].hitsomething=0;
2531 weapons[victim->weaponids[0]].freetime=0;
2532 weapons[victim->weaponids[0]].firstfree=1;
2533 weapons[victim->weaponids[0]].physics=1;
2534 victim->num_weapons--;
2535 if(victim->num_weapons){
2536 victim->weaponids[0]=victim->weaponids[num_weapons];
2537 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2539 victim->weaponactive=-1;
2540 for(i=0;i<numplayers;i++){
2541 player[i].wentforweapon=0;
2548 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2549 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2550 if(tutoriallevel!=1){
2551 weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250;
2553 if(id==0)camerashake+=.4;
2554 if(Random()%2||creature==wolftype){
2557 emit_sound_at(staffheadsound, victim->coords);
2561 relative=victim->coords-coords;
2563 Normalise(&relative);
2564 relative=DoRotation(relative,0,90,0);
2566 Normalise(&relative);
2567 for(i=0;i<victim->skeleton.num_joints;i++){
2568 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2570 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2571 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2574 if(tutoriallevel!=1){
2575 victim->DoDamage(damagemult*120/victim->protectionhigh);
2577 award_bonus(id, solidhit, 30);
2582 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2583 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2584 if(tutoriallevel!=1){
2585 weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250;
2587 if(id==0)camerashake+=.4;
2588 if(Random()%2||creature==wolftype){
2591 emit_sound_at(staffheadsound, victim->coords);
2595 relative=victim->coords-coords;
2597 Normalise(&relative);
2598 relative=DoRotation(relative,0,-90,0);
2599 for(i=0;i<victim->skeleton.num_joints;i++){
2600 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2602 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2603 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2606 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2608 award_bonus(id, solidhit, 60);
2613 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2614 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2616 if(tutoriallevel!=1){
2617 if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500;
2618 if(id==0)camerashake+=.4;
2619 if(Random()%2||creature==wolftype){
2622 emit_sound_at(staffbodysound, victim->coords);
2624 victim->skeleton.longdead=0;
2625 victim->skeleton.free=1;
2626 victim->skeleton.broken=0;
2628 for(i=0;i<victim->skeleton.num_joints;i++){
2629 victim->skeleton.joints[i].velchange=0;
2630 victim->skeleton.joints[i].locked=0;
2631 //victim->skeleton.joints[i].velocity=0;
2637 /*relative=victim->coords-coords;
2639 Normalise(&relative);
2640 relative=DoRotation(relative,0,90,0);*/
2642 Normalise(&relative);
2644 for(i=0;i<victim->skeleton.num_joints;i++){
2645 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2648 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2651 for(i=0;i<victim->skeleton.num_joints;i++){
2652 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2655 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2657 victim->Puff(abdomen);
2658 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2661 award_bonus(id, solidhit, 40);
2667 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2668 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2670 if(id==0)camerashake+=.4;
2672 relative=victim->coords-coords;
2674 Normalise(&relative);
2678 if(animation[victim->targetanimation].height==lowheight){
2684 for(i=0;i<victim->skeleton.num_joints;i++){
2685 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2687 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2688 if(tutoriallevel!=1){
2689 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2692 victim->DoDamage(damagemult*100/victim->protectionhead);
2693 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2694 if(creature==wolftype){
2695 emit_sound_at(clawslicesound, victim->coords, 128.);
2697 victim->DoBloodBig(2/victim->armorhead,175);
2701 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2702 for(i=0;i<victim->skeleton.num_joints;i++){
2703 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2705 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2706 victim->targetframe=0;
2707 victim->targetanimation=staggerbackhighanim;
2708 victim->targetrotation=targetrotation+180;
2710 if(tutoriallevel!=1){
2711 emit_sound_at(landsound2, victim->coords, 128.);
2713 victim->Puff(abdomen);
2714 victim->DoDamage(damagemult*30/victim->protectionhigh);
2715 if(creature==wolftype){
2716 emit_sound_at(clawslicesound, victim->coords, 128.);
2718 victim->DoBloodBig(2/victim->armorhigh,170);
2725 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2726 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2728 if(id==0)camerashake+=.2;
2729 if(tutoriallevel!=1){
2730 emit_sound_at(landsound2, victim->coords, 128.);
2733 relative=victim->coords-coords;
2735 Normalise(&relative);
2737 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2740 for(i=0;i<victim->skeleton.num_joints;i++){
2741 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2743 relative=DoRotation(relative,0,-90,0);
2745 for(i=0;i<victim->skeleton.num_joints;i++){
2746 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)
2747 victim->skeleton.joints[i].velocity=relative*80;
2749 victim->Puff(rightankle);
2750 victim->Puff(leftankle);
2751 victim->DoDamage(damagemult*40/victim->protectionlow);
2754 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2755 for(i=0;i<victim->skeleton.num_joints;i++){
2756 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2758 relative=DoRotation(relative,0,-90,0);
2759 for(i=0;i<victim->skeleton.num_joints;i++){
2760 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)
2761 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2763 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2764 victim->targetframe=0;
2765 victim->targetanimation=staggerbackhighanim;
2766 victim->targetrotation=targetrotation+180;
2768 if(tutoriallevel!=1){
2769 emit_sound_at(landsound2, victim->coords, 128.);
2771 victim->Puff(abdomen);
2772 victim->DoDamage(damagemult*30/victim->protectionlow);
2780 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2781 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2783 if(id==0)camerashake+=.4;
2788 if(tutoriallevel!=1){
2789 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2791 if(creature==wolftype){
2792 emit_sound_at(clawslicesound, victim->coords, 128);
2794 victim->DoBloodBig(2/victim->armorhigh,170);
2798 relative=victim->coords-oldcoords;
2800 Normalise(&relative);
2801 //relative=DoRotation(relative,0,-90,0);
2802 for(i=0;i<victim->skeleton.num_joints;i++){
2803 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2805 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2807 victim->Puff(abdomen);
2808 victim->DoDamage(damagemult*150/victim->protectionhigh);
2810 award_bonus(id, Reversal);
2813 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2814 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2815 if(weapons[victim->weaponids[victim->weaponactive]].owner==victim->id){
2816 weapons[victim->weaponids[victim->weaponactive]].owner=id;
2819 weaponids[num_weapons]=weaponids[victim->weaponactive];
2822 weaponids[0]=victim->weaponids[victim->weaponactive];
2823 victim->num_weapons--;
2824 if(victim->num_weapons>0){
2825 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2826 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2828 victim->weaponactive=-1;
2833 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2835 if(id==0)camerashake+=.4;
2840 emit_sound_at(whooshhitsound, victim->coords, 128.);
2843 relative=victim->coords-oldcoords;
2845 Normalise(&relative);
2846 //relative=DoRotation(relative,0,-90,0);
2847 for(i=0;i<victim->skeleton.num_joints;i++){
2848 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2850 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2853 victim->DoDamage(damagemult*70/victim->protectionhigh);
2856 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2858 if(id==0)camerashake+=.4;
2864 award_bonus(id, staffreversebonus);
2866 if(tutoriallevel!=1){
2867 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2870 award_bonus(id, staffreversebonus); // Huh, again?
2873 relative=victim->coords-oldcoords;
2875 Normalise(&relative);
2876 //relative=DoRotation(relative,0,-90,0);
2877 for(i=0;i<victim->skeleton.num_joints;i++){
2878 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2880 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2883 victim->DoDamage(damagemult*70/victim->protectionhigh);
2886 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
2892 Normalise(&relative);
2895 for(i=0;i<victim->skeleton.num_joints;i++){
2896 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2898 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
2899 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
2900 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
2901 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
2902 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
2903 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
2904 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
2905 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
2907 victim->Puff(abdomen);
2908 victim->DoDamage(damagemult*90/victim->protectionhigh);
2910 award_bonus(id, Reversal);
2914 if(weaponactive!=-1||creature==wolftype)doslice=1;
2915 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
2917 if(weaponactive!=-1){
2918 victim->DoBloodBig(2/victim->armorhigh,225);
2919 emit_sound_at(knifeslicesound, victim->coords);
2920 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2921 weapons[weaponids[weaponactive]].blooddrip+=3;
2923 if(weaponactive==-1&&creature==wolftype){;
2924 emit_sound_at(clawslicesound, victim->coords, 128.);
2926 victim->DoBloodBig(2/victim->armorhigh,175);
2933 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2939 Normalise(&relative);
2942 for(i=0;i<victim->skeleton.num_joints;i++){
2943 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2945 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
2946 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
2947 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
2948 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
2949 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
2950 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
2951 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
2952 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
2954 award_bonus(id, swordreversebonus);
2957 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2959 if(id==0)camerashake+=.4;
2964 if(tutoriallevel!=1){
2965 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2969 relative=victim->coords-oldcoords;
2971 Normalise(&relative);
2972 relative=DoRotation(relative,0,-90,0);
2973 for(i=0;i<victim->skeleton.num_joints;i++){
2974 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2976 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2978 victim->Puff(abdomen);
2979 victim->DoDamage(damagemult*30/victim->protectionhigh);
2981 award_bonus(id, Reversal);
2984 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
2987 victim->skeleton.spinny=0;
2991 Normalise(&relative);
2992 if(victim->id==0)relative/=30;
2993 for(i=0;i<victim->skeleton.num_joints;i++){
2994 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2996 //victim->DoDamage(1000);
2997 victim->damage=victim->damagetolerance;
2998 victim->permanentdamage=victim->damagetolerance-1;
3001 if(weaponactive!=-1||creature==wolftype)doslice=1;
3002 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3004 if(weaponactive!=-1){
3005 victim->DoBloodBig(200,225);
3006 emit_sound_at(knifeslicesound, victim->coords);
3007 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3008 weapons[weaponids[weaponactive]].blooddrip+=5;
3011 if(creature==wolftype&&weaponactive==-1){
3012 emit_sound_at(clawslicesound, victim->coords, 128.);
3014 victim->DoBloodBig(2,175);
3017 award_bonus(id, spinecrusher);
3020 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3021 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3023 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3024 if(targetanimation==knifesneakattackanim){
3025 /*victim->DoBloodBig(200,195);
3030 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3031 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3033 XYZ footvel,footpoint;
3035 footpoint=weapons[weaponids[0]].tippoint;
3036 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3037 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3038 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3039 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3040 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3041 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3042 victim->DoBloodBig(200,195);
3043 award_bonus(id, tracheotomy);
3045 if(targetanimation==knifefollowanim){
3046 award_bonus(id, Stabbonus);
3047 XYZ footvel,footpoint;
3049 footpoint=weapons[weaponids[0]].tippoint;
3050 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3051 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3052 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3053 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3054 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3055 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3058 victim->bloodloss+=10000;
3060 emit_sound_at(fleshstabsound, victim->coords);
3061 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3062 weapons[weaponids[weaponactive]].blooddrip+=5;
3066 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3069 for(i=0;i<victim->skeleton.num_joints;i++){
3070 victim->skeleton.joints[i].velocity=0;
3072 if(targetanimation==knifefollowanim){
3074 for(i=0;i<victim->skeleton.num_joints;i++){
3075 victim->skeleton.joints[i].velocity=0;
3078 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3079 emit_sound_at(fleshstabremovesound, victim->coords);
3080 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3081 weapons[weaponids[weaponactive]].blooddrip+=5;
3083 XYZ footvel,footpoint;
3085 footpoint=weapons[weaponids[0]].tippoint;
3086 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3087 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3088 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3089 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3090 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3091 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3095 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3096 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3097 award_bonus(id, backstab);
3101 XYZ footvel,footpoint;
3103 footpoint=(weapons[weaponids[0]].tippoint+weapons[weaponids[0]].position)/2;
3104 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3105 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3106 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3107 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3108 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3109 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3110 victim->DoBloodBig(200,180);
3111 victim->DoBloodBig(200,215);
3112 victim->bloodloss+=10000;
3114 emit_sound_at(fleshstabsound, victim->coords);
3115 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3116 weapons[weaponids[weaponactive]].blooddrip+=5;
3120 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3123 for(i=0;i<victim->skeleton.num_joints;i++){
3124 victim->skeleton.joints[i].velocity=0;
3126 if(weaponactive!=-1){
3127 emit_sound_at(fleshstabremovesound, victim->coords);
3128 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3129 weapons[weaponids[weaponactive]].blooddrip+=5;
3131 XYZ footvel,footpoint;
3133 footpoint=weapons[weaponids[0]].tippoint;
3134 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3135 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3136 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3137 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3138 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3139 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3143 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3145 if(id==0)camerashake+=.4;
3150 if(weaponactive==-1){
3151 if(tutoriallevel!=1){
3152 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3157 if(weaponactive!=-1||creature==wolftype)doslice=1;
3158 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3160 if(weaponactive!=-1){
3161 victim->DoBloodBig(2/victim->armorhead,225);
3162 emit_sound_at(knifeslicesound, victim->coords);
3163 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
3164 weapons[weaponids[weaponactive]].blooddrip+=3;
3166 if(weaponactive==-1&&creature==wolftype){
3167 emit_sound_at(clawslicesound, victim->coords, 128.);
3169 victim->DoBloodBig(2/victim->armorhead,175);
3173 award_bonus(id, Reversal);
3178 //relative=victim->coords-oldcoords;
3181 Normalise(&relative);
3182 relative=DoRotation(relative,0,90,0);
3184 Normalise(&relative);
3185 for(i=0;i<victim->skeleton.num_joints;i++){
3186 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3188 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3189 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3190 victim->DoDamage(damagemult*100/victim->protectionhead);
3194 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3198 //relative=victim->coords-oldcoords;
3201 Normalise(&relative);
3202 relative=DoRotation(relative,0,90,0);
3204 Normalise(&relative);
3205 for(i=0;i<victim->skeleton.num_joints;i++){
3206 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3208 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3211 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3212 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3213 award_bonus(id, reverseko);
3219 if(targetframe>animation[currentanimation].numframes-1){
3222 targetanimation=getIdle();
3226 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3227 targetanimation=rollanim;
3229 emit_sound_at(movewhooshsound, coords, 128.);
3231 if(currentanimation==staggerbackhighanim){
3232 targetanimation=getIdle();
3234 if(currentanimation==staggerbackhardanim){
3235 targetanimation=getIdle();
3237 if(currentanimation==removeknifeanim){
3238 targetanimation=getIdle();
3240 if(currentanimation==crouchremoveknifeanim){
3241 targetanimation=getCrouch();
3243 if(currentanimation==backhandspringanim){
3244 targetanimation=getIdle();
3246 if(currentanimation==dodgebackanim){
3247 targetanimation=getIdle();
3249 if(currentanimation==drawleftanim){
3250 targetanimation=getIdle();
3252 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3253 targetanimation=getIdle();
3254 if(currentanimation==crouchdrawrightanim){
3255 targetanimation=getCrouch();
3257 if(weaponactive==-1)weaponactive=0;
3258 else if(weaponactive==0){
3262 buffer=weaponids[0];
3263 weaponids[0]=weaponids[1];
3264 weaponids[1]=buffer;
3268 if(weaponactive==-1){
3269 emit_sound_at(knifesheathesound, coords, 128.);
3271 if(weaponactive!=-1){
3272 emit_sound_at(knifedrawsound, coords, 128.);
3275 if(currentanimation==rollanim){
3276 targetanimation=getCrouch();
3281 if(targetanimation==walljumprightkickanim){
3284 if(targetanimation==walljumpleftkickanim){
3287 targetanimation=jumpdownanim;
3289 if(currentanimation==climbanim){
3290 targetanimation=getCrouch();
3293 if(!isnormal(coords.x))
3304 if(targetanimation==rabbitkickreversalanim){
3305 targetanimation=getCrouch();
3308 if(targetanimation==jumpreversalanim){
3309 targetanimation=getCrouch();
3312 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3313 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3315 float closestdist=-1;
3318 for(i=0;i<numplayers;i++){
3319 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3320 distance=findDistancefast(&player[i].coords,&coords);
3321 if(closestdist==-1||distance<closestdist){
3322 closestdist=distance;
3327 if(closestdist>0&&closest>=0&&closestdist<16){
3328 victim=&player[closest];
3329 targetanimation=walljumprightkickanim;
3331 XYZ rotatetarget=victim->coords-coords;
3332 Normalise(&rotatetarget);
3333 rotation=-asin(0-rotatetarget.x);
3335 if(rotatetarget.z<0)rotation=180-rotation;
3336 targettilt2=-asin(rotatetarget.y)*360/6.28;
3337 velocity=(victim->coords-coords)*4;
3342 if(targetanimation==walljumpbackanim){
3343 targetanimation=backflipanim;
3348 resume_stream(whooshsound);
3350 if(targetanimation==walljumprightanim){
3351 targetanimation=rightflipanim;
3355 velocity=DoRotation(facing,0,30,0)*-8;
3358 if(targetanimation==walljumpfrontanim){
3359 targetanimation=frontflipanim;
3361 //targetrotation-=180;
3367 resume_stream(whooshsound);
3369 if(targetanimation==walljumpleftanim){
3372 float closestdist=-1;
3375 for(i=0;i<numplayers;i++){
3376 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3377 distance=findDistancefast(&player[i].coords,&coords);
3378 if(closestdist==-1||distance<closestdist){
3379 closestdist=distance;
3384 if(closestdist>0&&closest>=0&&closestdist<16){
3385 victim=&player[closest];
3386 targetanimation=walljumpleftkickanim;
3388 XYZ rotatetarget=victim->coords-coords;
3389 Normalise(&rotatetarget);
3390 rotation=-asin(0-rotatetarget.x);
3392 if(rotatetarget.z<0)rotation=180-rotation;
3393 targettilt2=-asin(rotatetarget.y)*360/6.28;
3394 velocity=(victim->coords-coords)*4;
3399 if(targetanimation!=walljumpleftkickanim){
3400 targetanimation=leftflipanim;
3404 velocity=DoRotation(facing,0,-30,0)*-8;
3408 resume_stream(whooshsound);
3410 if(targetanimation==sneakattackanim){
3411 currentanimation=getCrouch();
3412 targetanimation=getCrouch();
3415 targetrotation+=180;
3420 targetheadrotation+=180;
3422 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3426 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3427 targetanimation=getIdle();
3429 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3433 if(currentanimation==knifefollowanim){
3434 targetanimation=getIdle();
3437 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3438 float ycoords=oldcoords.y;
3439 targetanimation=getStop();
3440 targetrotation+=180;
3445 targetheadrotation+=180;
3446 if(!isnormal(coords.x))
3448 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3449 oldcoords=coords+facing*.5;
3450 else if(currentanimation==sweepreversalanim)
3451 oldcoords=coords+facing*1.1;
3452 else if(currentanimation==upunchreversalanim){
3453 oldcoords=coords+facing*1.5;
3454 targetrotation+=180;
3456 targetheadrotation+=180;
3460 else if(currentanimation==knifeslashreversalanim){
3461 oldcoords=coords+facing*.5;
3464 targetheadrotation+=90;
3468 else if(currentanimation==staffspinhitreversalanim){
3469 targetrotation+=180;
3471 targetheadrotation+=180;
3475 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3476 else oldcoords.y=ycoords;
3477 currentoffset=coords-oldcoords;
3483 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3488 if(animation[targetanimation].attack==reversed){
3490 if(targetanimation==sweepreversedanim)targetrotation+=90;
3491 targetanimation=backhandspringanim;
3493 emit_sound_at(landsound, coords, 128);
3495 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3496 targetanimation=rollanim;
3499 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3500 coords.y=oldcoords.y;
3502 if(currentanimation==knifeslashreversedanim){
3503 targetanimation=rollanim;
3508 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3509 coords.y=oldcoords.y;
3513 targetanimation=jumpdownanim;
3515 if(wasLanding())targetanimation=getIdle();
3516 if(wasLandhard())targetanimation=getIdle();
3517 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3518 targetanimation=getIdle();
3520 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3521 coords.y=oldcoords.y;
3522 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3523 targetoffset.y=coords.y;
3524 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3525 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3526 currentoffset.y-=(coords.y-targetoffset.y);
3527 coords.y=targetoffset.y;
3529 normalsupdatedelay=0;
3531 if(currentanimation==upunchanim){
3532 targetanimation=getStop();
3533 normalsupdatedelay=0;
3536 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3537 targetrotation=rotation;
3540 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
3541 if(!hasstaff)DoDamage(35);
3544 rabbitkickragdoll=1;
3546 if(currentanimation==rabbitkickreversedanim){
3553 SolidHitBonus(!id); // FIXME: tricky id
3557 targetanimation=rollanim;
3559 if(id==0)pause_sound(whooshsound);
3563 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3569 if(currentanimation==jumpreversedanim){
3576 SolidHitBonus(!id); // FIXME: tricky id
3580 targetanimation=rollanim;
3582 if(id==0)pause_sound(whooshsound);
3587 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){
3588 targetanimation=getupfromfrontanim;
3591 else if(animation[currentanimation].attack==normalattack){
3592 targetanimation=getIdle();
3595 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3596 targetanimation=blockhighleftstrikeanim;
3598 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3599 targetanimation=getIdle();
3602 if(currentanimation==spinkickanim&&victim->skeleton.free){
3603 if(creature==rabbittype)targetanimation=fightidleanim;
3608 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3610 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3611 targetanimation=jumpdownanim;
3616 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3617 if(!isRun()||!wasRun()){
3618 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3619 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3620 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3621 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3623 if(isRun()&&wasRun()){
3626 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3627 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3630 else if(transspeed)target+=multiplier*transspeed*speed*2;
3632 if(!isRun()||!wasRun()){
3633 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3634 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3635 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3636 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3640 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3642 if(target>1){currentframe=targetframe; target=1;}
3644 rot=targetrot*target;
3645 rotation+=rot-oldrot;
3651 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3653 for(i=0;i<skeleton.num_joints;i++){
3654 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3657 skeleton.FindForwards();
3659 for(i=0;i<skeleton.num_muscles;i++){
3660 if(skeleton.muscles[i].visible)
3662 skeleton.FindRotationMuscle(i,targetanimation);
3665 for(i=0;i<skeleton.num_muscles;i++){
3666 if(skeleton.muscles[i].visible)
3668 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3669 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3670 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3675 for(i=0;i<skeleton.num_joints;i++){
3676 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3679 skeleton.FindForwards();
3681 for(i=0;i<skeleton.num_muscles;i++){
3682 if(skeleton.muscles[i].visible)
3684 skeleton.FindRotationMuscle(i,targetanimation);
3687 for(i=0;i<skeleton.num_muscles;i++){
3688 if(skeleton.muscles[i].visible)
3690 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3691 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3692 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3693 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3694 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3695 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3696 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3697 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3698 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3702 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3704 oldcurrentanimation=currentanimation;
3705 oldtargetanimation=targetanimation;
3706 oldtargetframe=targetframe;
3707 oldcurrentframe=currentframe;
3709 for(i=0;i<skeleton.num_joints;i++){
3710 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3711 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3713 offset=currentoffset*(1-target)+targetoffset*target;
3714 for(i=0;i<skeleton.num_muscles;i++){
3715 if(skeleton.muscles[i].visible)
3717 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3718 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3719 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3724 if(isLanding()&&landhard){
3725 if(id==0)camerashake+=.4;
3726 targetanimation=getLandhard();
3733 //skeleton.DoConstraints();
3736 void Person::DoStuff(){
3737 static XYZ terrainnormal;
3738 static XYZ flatfacing;
3739 static XYZ flatvelocity;
3740 static float flatvelspeed;
3744 static int bloodsize;
3745 static int startx,starty,endx,endy;
3746 static GLubyte color;
3747 static XYZ bloodvel;
3749 onfiredelay-=multiplier;
3750 if(onfiredelay<0&&onfire)
3758 crouchkeydowntime+=multiplier;
3759 if(!crouchkeydown)crouchkeydowntime=0;
3760 jumpkeydowntime+=multiplier;
3761 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3763 if(hostile||damage>0||bloodloss>0)immobile=0;
3765 if(isIdle()||isRun())targetoffset=0;
3767 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3769 if(id==0)blooddimamount-=multiplier*.3;
3770 speechdelay-=multiplier;
3771 texupdatedelay-=multiplier;
3772 interestdelay-=multiplier;
3773 flamedelay-=multiplier;
3774 parriedrecently-=multiplier;
3780 if(id==0)speed=1.1*speedmult;
3781 else speed=1.0*speedmult;
3782 if(!skeleton.free)rabbitkickragdoll=0;
3786 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3787 if(id!=0&&creature==wolftype&&difficulty==2){
3789 if(aitype!=passivetype){
3791 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){
3795 if(scale<0.2)superruntoggle=0;
3796 if(targetanimation==wolfrunninganim&&!superruntoggle){
3797 targetanimation=getRun();
3801 if(weaponactive==-1&&num_weapons>0){
3802 if(weapons[weaponids[0]].getType()==staff){
3809 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3810 /*if(aitype!=playercontrolled)*/
3812 if(burnt>.6)burnt=.6;
3813 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3815 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3826 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3827 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3831 while(flamedelay<0&&onfire){
3833 howmany=abs(Random()%(skeleton.num_joints));
3834 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3835 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3836 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3837 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3838 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3841 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3843 howmany=abs(Random()%(skeleton.num_joints));
3844 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3845 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3846 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3847 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3848 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3852 bleeding-=multiplier*.3;
3854 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3855 if(bleeding<=0&&(detail!=2||osx))DoMipmaps();
3859 if(neckspurtamount>0){
3860 neckspurtamount-=multiplier;
3861 neckspurtdelay-=multiplier*3;
3862 neckspurtparticledelay-=multiplier*3;
3863 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3867 bloodvel.z=5*neckspurtamount;
3868 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3871 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3873 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3874 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3875 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);
3876 if(!skeleton.free)Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position+(skeleton.joints[skeleton.jointlabels[neck]].position-skeleton.joints[skeleton.jointlabels[head]].position)/5,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, .9);
3877 neckspurtparticledelay=.05;
3879 if(neckspurtdelay<0){
3884 if(deathbleeding>0&&dead!=2){
3885 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
3886 else bleeddelay-=5*multiplier/4;
3887 if(bleeddelay<0&&bloodtoggle){
3892 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3893 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
3894 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
3895 if(!skeleton.free)Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3898 bloodloss+=deathbleeding*multiplier*80;
3899 deathbleeding-=multiplier*1.6;
3900 //if(id==0)deathbleeding-=multiplier*.2;
3901 if(deathbleeding<0)deathbleeding=0;
3902 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
3903 if(weaponactive!=-1){
3904 weapons[weaponids[0]].owner=-1;
3905 weapons[weaponids[0]].velocity=velocity*scale*-.3;
3906 weapons[weaponids[0]].velocity.x+=.01;
3907 weapons[weaponids[0]].tipvelocity=velocity*scale;
3908 weapons[weaponids[0]].missed=1;
3909 weapons[weaponids[0]].hitsomething=0;
3910 weapons[weaponids[0]].freetime=0;
3911 weapons[weaponids[0]].firstfree=1;
3912 weapons[weaponids[0]].physics=1;
3915 weaponids[0]=weaponids[num_weapons];
3916 if(weaponstuck==num_weapons)weaponstuck=0;
3919 for(i=0;i<numplayers;i++){
3920 player[i].wentforweapon=0;
3932 if(!dead&&creature==wolftype){
3933 award_bonus(0, Wolfbonus);
3936 if(targetanimation==knifefollowedanim&&!skeleton.free){
3937 for(i=0;i<skeleton.num_joints;i++){
3938 skeleton.joints[i].velocity=0;
3939 skeleton.joints[i].velocity.y=-2;
3942 if(id!=0&&unconscioustime>.1){
3950 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
3953 bloodsize=5-realtexdetail;
3957 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3958 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3959 endx=startx+bloodsize;
3960 endy=starty+bloodsize;
3962 if(startx<0){startx=0;bleeding=0;}
3963 if(starty<0){starty=0;bleeding=0;}
3964 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
3965 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
3966 if(endx<startx)endx=startx;
3967 if(endy<starty)endy=starty;
3969 for(i=startx;i<endx;i++){
3970 for(j=starty;j<endy;j++){
3972 color=Random()%85+170;
3973 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
3974 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
3975 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
3980 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3985 bleedy-=4/realtexdetail;
3986 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
3987 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
3990 bleedx+=4*direction/realtexdetail;
3991 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
3992 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
3996 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
3997 righthandmorphness=targetrighthandmorphness;
3998 righthandmorphstart=righthandmorphend;
4000 else if(righthandmorphness>targetrighthandmorphness){
4001 righthandmorphness-=multiplier*4;
4003 else if(righthandmorphness<targetrighthandmorphness){
4004 righthandmorphness+=multiplier*4;
4007 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4008 lefthandmorphness=targetlefthandmorphness;
4009 lefthandmorphstart=lefthandmorphend;
4011 else if(lefthandmorphness>targetlefthandmorphness){
4012 lefthandmorphness-=multiplier*4;
4014 else if(lefthandmorphness<targetlefthandmorphness){
4015 lefthandmorphness+=multiplier*4;
4018 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4019 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4020 tailmorphness=targettailmorphness;
4021 tailmorphstart=tailmorphend;
4023 else if(tailmorphness>targettailmorphness){
4024 tailmorphness-=multiplier*10;
4026 else if(tailmorphness<targettailmorphness){
4027 tailmorphness+=multiplier*10;
4031 if(creature==wolftype){
4032 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4033 tailmorphness=targettailmorphness;
4034 tailmorphstart=tailmorphend;
4036 else if(tailmorphness>targettailmorphness){
4037 tailmorphness-=multiplier*2;
4039 else if(tailmorphness<targettailmorphness){
4040 tailmorphness+=multiplier*2;
4044 if(headmorphend==3||headmorphstart==3){
4045 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4046 headmorphness=targetheadmorphness;
4047 headmorphstart=headmorphend;
4049 else if(headmorphness>targetheadmorphness){
4050 headmorphness-=multiplier*7;
4052 else if(headmorphness<targetheadmorphness){
4053 headmorphness+=multiplier*7;
4056 else if(headmorphend==5||headmorphstart==5){
4057 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4058 headmorphness=targetheadmorphness;
4059 headmorphstart=headmorphend;
4061 else if(headmorphness>targetheadmorphness){
4062 headmorphness-=multiplier*10;
4064 else if(headmorphness<targetheadmorphness){
4065 headmorphness+=multiplier*10;
4069 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4070 headmorphness=targetheadmorphness;
4071 headmorphstart=headmorphend;
4073 else if(headmorphness>targetheadmorphness){
4074 headmorphness-=multiplier*4;
4076 else if(headmorphness<targetheadmorphness){
4077 headmorphness+=multiplier*4;
4081 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4082 chestmorphness=targetchestmorphness;
4083 chestmorphstart=chestmorphend;
4085 else if(chestmorphness>targetchestmorphness){
4086 chestmorphness-=multiplier;
4088 else if(chestmorphness<targetchestmorphness){
4089 chestmorphness+=multiplier;
4092 if(dead!=2&&howactive<=typesleeping){
4093 if(chestmorphstart==0&&chestmorphend==0){
4095 targetchestmorphness=1;
4098 if(chestmorphstart!=0&&chestmorphend!=0){
4100 targetchestmorphness=1;
4102 if(environment==snowyenvironment){
4105 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4106 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4107 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4108 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4109 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4110 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4114 if(!dead&&howactive<typesleeping){
4115 blinkdelay-=multiplier*2;
4116 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4118 targetheadmorphness=1;
4120 blinkdelay=(float)(abs(Random()%40))/5;
4122 if(headmorphstart==3&&headmorphend==3){
4124 targetheadmorphness=1;
4129 twitchdelay-=multiplier*1.5;
4130 if(targetanimation!=hurtidleanim){
4131 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4133 targetheadmorphness=1;
4135 twitchdelay=(float)(abs(Random()%40))/5;
4137 if(headmorphstart==5&&headmorphend==5){
4139 targetheadmorphness=1;
4143 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4144 twitchdelay3-=multiplier*1;
4146 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4147 righthandmorphness=0;
4148 targetrighthandmorphness=1;
4149 righthandmorphend=1;
4150 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4152 if(righthandmorphstart==1&&righthandmorphend==1){
4153 righthandmorphness=0;
4154 targetrighthandmorphness=1;
4155 righthandmorphend=0;
4159 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4160 lefthandmorphness=0;
4161 targetlefthandmorphness=1;
4163 twitchdelay3=(float)(abs(Random()%40))/5;
4165 if(lefthandmorphstart==1&&lefthandmorphend==1){
4166 lefthandmorphness=0;
4167 targetlefthandmorphness=1;
4174 if(creature==rabbittype){
4175 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4176 else twitchdelay2-=multiplier*0.5;
4177 if(howactive<=typesleeping){
4178 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4180 targettailmorphness=1;
4182 twitchdelay2=(float)(abs(Random()%40))/5;
4184 if(tailmorphstart==1&&tailmorphend==1){
4186 targettailmorphness=1;
4189 if(tailmorphstart==2&&tailmorphend==2){
4191 targettailmorphness=1;
4198 if(creature==wolftype){
4199 twitchdelay2-=multiplier*1.5;
4201 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4203 targettailmorphness=1;
4208 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4210 targettailmorphness=1;
4214 if(twitchdelay2<=0){
4215 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4217 targettailmorphness=1;
4220 if(tailmorphstart==1&&tailmorphend==1){
4222 targettailmorphness=1;
4225 if(tailmorphstart==2&&tailmorphend==2){
4227 targettailmorphness=1;
4230 if(tailmorphstart==3&&tailmorphend==3){
4232 targettailmorphness=1;
4235 if(tailmorphstart==4&&tailmorphend==4){
4237 targettailmorphness=1;
4243 if(dead!=1)unconscioustime=0;
4245 if(dead==1||howactive==typesleeping){
4246 unconscioustime+=multiplier;
4247 //If unconscious, close eyes and mouth
4248 if(righthandmorphend!=0)righthandmorphness=0;
4249 righthandmorphend=0;
4250 targetrighthandmorphness=1;
4252 if(lefthandmorphend!=0)lefthandmorphness=0;
4254 targetlefthandmorphness=1;
4256 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4258 targetheadmorphness=1;
4262 if(howactive>typesleeping){
4265 if(bloodtoggle&&!bled){
4266 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4268 if(bloodtoggle&&!bled)
4269 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4270 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4271 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4275 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4280 if(dead==2||howactive>typesleeping){
4281 //If dead, open mouth and hands
4282 if(righthandmorphend!=0)righthandmorphness=0;
4283 righthandmorphend=0;
4284 targetrighthandmorphness=1;
4286 if(lefthandmorphend!=0)lefthandmorphness=0;
4288 targetlefthandmorphness=1;
4290 if(headmorphend!=2)headmorphness=0;
4292 targetheadmorphness=1;
4295 if(stunned>0&&!dead&&headmorphend!=2){
4296 if(headmorphend!=4)headmorphness=0;
4298 targetheadmorphness=1;
4301 if(damage>damagetolerance&&!dead){
4306 if(creature==wolftype){
4307 award_bonus(0, Wolfbonus);
4312 if(weaponactive!=-1){
4313 weapons[weaponids[0]].owner=-1;
4314 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4315 weapons[weaponids[0]].velocity.x+=.01;
4316 weapons[weaponids[0]].tipvelocity=velocity*scale;
4317 weapons[weaponids[0]].missed=1;
4318 weapons[weaponids[0]].hitsomething=0;
4319 weapons[weaponids[0]].freetime=0;
4320 weapons[weaponids[0]].firstfree=1;
4321 weapons[weaponids[0]].physics=1;
4324 weaponids[0]=weaponids[num_weapons];
4325 if(weaponstuck==num_weapons)weaponstuck=0;
4328 for(i=0;i<numplayers;i++){
4329 player[i].wentforweapon=0;
4335 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4343 //if(dead)damage-=multiplier/4;
4344 if(!dead)damage-=multiplier*13;
4345 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4346 if(!dead)permanentdamage-=multiplier*4;
4347 if(isIdle()||isCrouch()){
4348 if(!dead)permanentdamage-=multiplier*4;
4349 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4351 if(damage<0)damage=0;
4352 if(permanentdamage<0)permanentdamage=0;
4353 if(superpermanentdamage<0)superpermanentdamage=0;
4354 if(permanentdamage<superpermanentdamage){
4355 permanentdamage=superpermanentdamage;
4357 if(damage<permanentdamage){
4358 damage=permanentdamage;
4360 if(dead==1&&damage<damagetolerance){
4364 for(i=0;i<skeleton.num_joints;i++){
4365 skeleton.joints[i].velocity=0;
4368 if(permanentdamage>damagetolerance&&dead!=2){
4371 if(weaponactive!=-1){
4372 weapons[weaponids[0]].owner=-1;
4373 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4374 weapons[weaponids[0]].velocity.x+=.01;
4375 weapons[weaponids[0]].tipvelocity=velocity*scale;
4376 weapons[weaponids[0]].missed=1;
4377 weapons[weaponids[0]].hitsomething=0;
4378 weapons[weaponids[0]].freetime=0;
4379 weapons[weaponids[0]].firstfree=1;
4380 weapons[weaponids[0]].physics=1;
4383 weaponids[0]=weaponids[num_weapons];
4384 if(weaponstuck==num_weapons)weaponstuck=0;
4387 for(i=0;i<numplayers;i++){
4388 player[i].wentforweapon=0;
4394 if(!dead&&creature==wolftype){
4395 award_bonus(0, Wolfbonus);
4398 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4399 award_bonus(id, touchofdeath);
4400 if(id!=0&&unconscioustime>.1){
4408 emit_sound_at(breaksound, coords);
4411 if(skeleton.free==1){
4412 if(id==0)pause_sound(whooshsound);
4415 //If knocked over, open hands and close mouth
4416 if(righthandmorphend!=0)righthandmorphness=0;
4417 righthandmorphend=0;
4418 targetrighthandmorphness=1;
4420 if(lefthandmorphend!=0)lefthandmorphness=0;
4422 targetlefthandmorphness=1;
4424 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4425 if(headmorphend!=0)headmorphness=0;
4427 targetheadmorphness=1;
4431 skeleton.DoGravity(&scale);
4433 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4434 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4435 award_bonus(id, deepimpact);
4436 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4440 for(j=0;j<skeleton.num_joints;j++){
4441 average+=skeleton.joints[j].position;
4445 coords+=average*scale;
4446 for(j=0;j<skeleton.num_joints;j++){
4447 skeleton.joints[j].position-=average;
4449 average/=multiplier;
4451 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4453 for(i=0;i<skeleton.num_joints;i++){
4454 velocity+=skeleton.joints[i].velocity*scale;
4456 velocity/=skeleton.num_joints;
4458 if(!isnormal(velocity.x)&&velocity.x){
4462 if(findLength(&average)<10&&dead&&skeleton.free){
4463 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4464 if(skeleton.longdead>2000){
4465 if(skeleton.longdead>6000){
4466 if(id==0)pause_sound(whooshsound);
4471 if(dead==2&&bloodloss<damagetolerance){
4473 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4475 if(bloodtoggle&&!bled){
4476 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4478 if(bloodtoggle&&!bled)
4479 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4480 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4481 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4485 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4489 if(dead==2&&bloodloss>=damagetolerance){
4491 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4492 if(bleeding<=0)DoBlood(1,255);
4493 if(bloodtoggle&&!bled){
4494 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4496 if(bloodtoggle&&!bled)
4497 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4498 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4499 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4503 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4510 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4512 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4516 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4517 if(velocity.y<-30)canrecover=0;
4518 for(i=0;i<objects.numobjects;i++){
4519 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4520 colviewer=startpoint;
4522 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4530 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4531 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4532 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4533 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4535 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4536 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4537 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4539 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4540 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4541 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4543 Normalise(&terrainnormal);
4545 targetrotation=-asin(0-terrainnormal.x);
4546 targetrotation*=360/6.28;
4547 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4548 rotation=targetrotation;
4552 targetanimation=flipanim;
4553 crouchtogglekeydown=1;
4558 currentanimation=tempanim;
4561 //tilt2=targettilt2;
4563 //if(middle.y>0)targetoffset.y=middle.y+1;
4565 for(i=0;i<skeleton.num_joints;i++){
4566 tempanimation.position[i][0]=skeleton.joints[i].position;
4567 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4572 if(findLength(&average)<10&&!dead&&skeleton.free){
4573 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4574 if(skeleton.longdead>(damage+500)*1.5){
4575 if(id==0)pause_sound(whooshsound);
4581 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4582 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4583 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4584 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4586 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4587 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4588 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4590 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4591 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4592 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4594 Normalise(&terrainnormal);
4596 targetrotation=-asin(0-terrainnormal.x);
4597 targetrotation*=360/6.28;
4598 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4599 rotation=targetrotation;
4601 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4604 if(skeleton.forward.y<0){
4605 targetanimation=getupfrombackanim;
4609 if(skeleton.forward.y>-.3){
4610 targetanimation=getupfromfrontanim;
4612 targetrotation+=180;
4618 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4619 targetanimation=rollanim;
4620 targetrotation=lookrotation;
4624 if(forwardkeydown)targetrotation+=45;
4625 if(backkeydown)targetrotation-=45;
4629 if(forwardkeydown)targetrotation-=45;
4630 if(backkeydown)targetrotation+=45;
4633 if ( !leftkeydown&&!rightkeydown)
4634 targetrotation+=180;
4636 targetrotation+=180;
4640 if(abs(targettilt2)>50)targettilt2=0;
4641 currentanimation=tempanim;
4646 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4648 for(i=0;i<skeleton.num_joints;i++){
4649 tempanimation.position[i][0]=skeleton.joints[i].position;
4650 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4657 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
4658 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4661 tempvelocity=velocity;
4662 Normalise(&tempvelocity);
4663 targetrotation=-asin(0-tempvelocity.x);
4664 targetrotation*=360/6.28;
4665 if(velocity.z<0)targetrotation=180-targetrotation;
4666 //targetrotation+=180;
4669 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4670 targetanimation=rollanim;
4674 targetanimation=backhandspringanim;
4675 targetrotation+=180;
4680 emit_sound_at(movewhooshsound, coords, 128.);
4682 currentanimation=targetanimation;
4683 currentframe=targetframe-1;
4688 rotation=targetrotation;
4695 if(skeleton.freefall==0)freefall=0;
4699 if(aitype!=passivetype||skeleton.free==1)
4700 if(findLengthfast(&velocity)>.1)
4701 for(i=0;i<objects.numobjects;i++){
4702 if(objects.type[i]==firetype)
4703 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){
4705 if(!objects.onfire[i]){
4706 emit_sound_at(firestartsound, objects.position[i]);
4708 objects.onfire[i]=1;
4711 if(objects.onfire[i]){
4716 if(objects.type[i]==bushtype)
4717 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){
4719 if(!objects.onfire[i]){
4720 emit_sound_at(firestartsound, objects.position[i]);
4722 objects.onfire[i]=1;
4726 if(objects.onfire[i]){
4730 if(objects.messedwith[i]<=0){
4734 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4737 envsound[numenvsounds]=coords;
4738 envsoundvol[numenvsounds]=4*findLength(&velocity);
4739 envsoundlife[numenvsounds]=.4;
4744 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4745 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4747 if(environment!=desertenvironment)
4748 for(j=0;j<howmany;j++){
4749 tempvel.x=float(abs(Random()%100)-50)/20;
4750 tempvel.y=float(abs(Random()%100)-50)/20;
4751 tempvel.z=float(abs(Random()%100)-50)/20;
4754 pos.x+=float(abs(Random()%100)-50)/200;
4755 pos.y+=float(abs(Random()%100)-50)/200;
4756 pos.z+=float(abs(Random()%100)-50)/200;
4757 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);
4758 Sprite::setLastSpriteSpecial(1);
4760 howmany=findLength(&velocity)*4;
4762 if(environment==snowyenvironment)
4763 for(j=0;j<howmany;j++){
4764 tempvel.x=float(abs(Random()%100)-50)/20;
4765 tempvel.y=float(abs(Random()%100)-50)/20;
4766 tempvel.z=float(abs(Random()%100)-50)/20;
4769 pos.x+=float(abs(Random()%100)-50)/200;
4770 pos.y+=float(abs(Random()%100)-50)/200;
4771 pos.z+=float(abs(Random()%100)-50)/200;
4772 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4773 Sprite::setLastSpriteSpecial(2);
4776 objects.rotx[i]+=velocity.x*multiplier*6;
4777 objects.roty[i]+=velocity.z*multiplier*6;
4778 objects.messedwith[i]=.5;
4781 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4782 if(objects.rotation2[i]==0)tempcoord=coords;
4784 tempcoord=coords-objects.position[i];
4785 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4786 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4787 tempcoord+=objects.position[i];
4789 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]){
4790 if(objects.messedwith[i]<=0){
4794 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4797 envsound[numenvsounds]=coords;
4798 envsoundvol[numenvsounds]=4*findLength(&velocity);
4799 envsoundlife[numenvsounds]=.4;
4804 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4805 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4807 if(environment!=desertenvironment)
4808 for(j=0;j<howmany;j++){
4809 tempvel.x=float(abs(Random()%100)-50)/20;
4810 tempvel.y=float(abs(Random()%100)-50)/20;
4811 tempvel.z=float(abs(Random()%100)-50)/20;
4815 pos.x+=float(abs(Random()%100)-50)/150;
4816 pos.y+=float(abs(Random()%100)-50)/150;
4817 pos.z+=float(abs(Random()%100)-50)/150;
4818 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);
4819 Sprite::setLastSpriteSpecial(1);
4821 howmany=findLength(&velocity)*4;
4823 if(environment==snowyenvironment)
4824 for(j=0;j<howmany;j++){
4825 tempvel.x=float(abs(Random()%100)-50)/20;
4826 tempvel.y=float(abs(Random()%100)-50)/20;
4827 tempvel.z=float(abs(Random()%100)-50)/20;
4831 pos.x+=float(abs(Random()%100)-50)/150;
4832 pos.y+=float(abs(Random()%100)-50)/150;
4833 pos.z+=float(abs(Random()%100)-50)/150;
4834 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4835 Sprite::setLastSpriteSpecial(2);
4838 objects.messedwith[i]=.5;
4846 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
4848 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
4849 if(tutoriallevel==1&&id!=0)play=0;
4850 if(play&&aitype!=playercontrolled){
4854 if(creature==rabbittype){
4855 if(i==0)whichsound=rabbitchitter;
4856 if(i==1)whichsound=rabbitchitter2;
4858 if(creature==wolftype){
4859 if(i==0)whichsound=growlsound;
4860 if(i==1)whichsound=growl2sound;
4866 emit_sound_at(whichsound, coords);
4870 if(targetanimation==staggerbackhighanim)staggerdelay=1;
4871 if(targetanimation==staggerbackhardanim)staggerdelay=1;
4872 staggerdelay-=multiplier;
4873 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
4874 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
4875 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
4876 targetanimation=getIdle();
4880 weaponmissdelay-=multiplier;
4881 highreversaldelay-=multiplier;
4882 lowreversaldelay-=multiplier;
4883 lastcollide-=multiplier;
4884 skiddelay-=multiplier;
4885 if(!isnormal(velocity.x)&&velocity.x){
4888 if(!isnormal(targettilt)&&targettilt){
4891 if(!isnormal(targettilt2)&&targettilt2){
4894 if(!isnormal(targetrotation)&&targetrotation){
4898 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
4899 //open hands and close mouth
4900 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4901 righthandmorphness=0;
4902 righthandmorphend=0;
4903 targetrighthandmorphness=1;
4906 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4907 lefthandmorphness=0;
4909 targetlefthandmorphness=1;
4912 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
4915 targetheadmorphness=1;
4919 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){
4920 //open hands and mouth
4921 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4922 righthandmorphness=0;
4923 righthandmorphend=0;
4924 targetrighthandmorphness=1;
4927 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4928 lefthandmorphness=0;
4930 targetlefthandmorphness=1;
4933 if(headmorphend!=1&&headmorphness==targetheadmorphness){
4936 targetheadmorphness=1;
4940 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
4941 //close hands and mouth
4942 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4943 righthandmorphness=0;
4944 righthandmorphend=1;
4945 targetrighthandmorphness=1;
4948 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4949 lefthandmorphness=0;
4951 targetlefthandmorphness=1;
4954 if(headmorphend!=0&&headmorphness==targetheadmorphness){
4957 targetheadmorphness=1;
4961 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){
4962 //close hands and yell
4963 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4964 righthandmorphness=0;
4965 righthandmorphend=1;
4966 targetrighthandmorphness=1;
4969 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4970 lefthandmorphness=0;
4972 targetlefthandmorphness=1;
4975 if(headmorphend!=2&&headmorphness==targetheadmorphness){
4978 targetheadmorphness=1;
4985 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
4986 behind=(normaldotproduct(facing,coords-victim->coords)>0);
4990 if(!dead&&targetanimation!=hurtidleanim)
4991 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
4992 if(headmorphend!=4||headmorphness==targetheadmorphness){
4995 targetheadmorphness=1;
4999 if(weaponactive!=-1){
5000 if(weapons[weaponids[weaponactive]].getType()!=staff){
5001 righthandmorphstart=1;
5002 righthandmorphend=1;
5004 if(weapons[weaponids[weaponactive]].getType()==staff){
5005 righthandmorphstart=2;
5006 righthandmorphend=2;
5008 targetrighthandmorphness=1;
5011 terrainnormal=terrain.getNormal(coords.x,coords.z);
5013 if(animation[targetanimation].attack!=reversal){
5014 if(!isnormal(coords.x))
5022 flatfacing=DoRotation(flatfacing,0,rotation,0);
5024 ReflectVector(&facing,terrainnormal);
5027 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5028 if(onterrain)targettilt2=-facing.y*20;
5032 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5033 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5034 flatvelocity=velocity;
5036 flatvelspeed=findLength(&flatvelocity);
5037 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5038 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5039 if(velocity.y<0)targettilt2*=-1;
5040 if(velocity.y<0)targettilt*=-1;
5041 if(targettilt>25)targettilt=25;
5042 if(targettilt<-25)targettilt=-25;
5045 if(targettilt2>45)targettilt2=45;
5046 if(targettilt2<-45)targettilt2=-45;
5047 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5048 else if(tilt2>targettilt2){
5049 tilt2-=multiplier*400;
5051 else if(tilt2<targettilt2){
5052 tilt2+=multiplier*400;
5054 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5055 if(tilt2>25)tilt2=25;
5056 if(tilt2<-25)tilt2=-25;
5059 if(!isnormal(targettilt)&&targettilt){
5062 if(!isnormal(targettilt2)&&targettilt2){
5067 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5068 if(targetanimation==rabbittackleanim){
5069 velocity+=facing*multiplier*speed*700*scale;
5070 velspeed=findLength(&velocity);
5071 if(velspeed>speed*65*scale){
5073 velspeed=speed*65*scale;
5076 velocity.y+=gravity*multiplier*20;
5077 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5078 velspeed=findLength(&velocity);
5079 velocity=flatfacing*velspeed;
5081 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5082 if(isRun()||targetanimation==rabbitkickanim){
5083 velocity+=facing*multiplier*speed*700*scale;
5084 velspeed=findLength(&velocity);
5085 if(velspeed>speed*45*scale){
5087 velspeed=speed*45*scale;
5090 velocity.y+=gravity*multiplier*20;
5091 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5092 velspeed=findLength(&velocity);
5093 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5094 velocity=flatfacing*velspeed;
5098 velocity+=facing*multiplier*speed*700*scale;
5099 velspeed=findLength(&velocity);
5100 if(creature==rabbittype){
5101 if(velspeed>speed*55*scale){
5103 velspeed=speed*55*scale;
5107 if(creature==wolftype){
5108 if(velspeed>speed*75*scale){
5110 velspeed=speed*75*scale;
5114 velocity.y+=gravity*multiplier*20;
5115 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5116 velspeed=findLength(&velocity);
5117 velocity=flatfacing*velspeed;
5120 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5121 velocity+=facing*multiplier*speed*700*scale;
5122 velspeed=findLength(&velocity);
5123 if(velspeed>speed*45*scale){
5125 velspeed=speed*45*scale;
5128 velocity.y+=gravity*multiplier*20;
5129 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5130 velspeed=findLength(&velocity);
5131 velocity=flatfacing*velspeed;
5135 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5136 velocity+=facing*multiplier*speed*700*scale;
5137 velspeed=findLength(&velocity);
5138 if(velspeed>speed*25*scale){
5140 velspeed=speed*25*scale;
5143 velocity.y+=gravity*multiplier*20;
5144 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5145 velspeed=findLength(&velocity);
5146 velocity=flatfacing*velspeed;
5149 if(targetanimation==sneakanim||targetanimation==walkanim){
5150 velocity+=facing*multiplier*speed*700*scale;
5151 velspeed=findLength(&velocity);
5152 if(velspeed>speed*12*scale){
5154 velspeed=speed*12*scale;
5157 velocity.y+=gravity*multiplier*20;
5158 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5159 velspeed=findLength(&velocity);
5160 velocity=flatfacing*velspeed;
5163 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5164 velocity+=facing*multiplier*speed*700*scale;
5165 velspeed=findLength(&velocity);
5166 if(velspeed>speed*2*scale){
5168 velspeed=speed*2*scale;
5171 velocity.y+=gravity*multiplier*20;
5172 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5173 velspeed=findLength(&velocity);
5174 velocity=flatfacing*velspeed;
5178 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5179 velocity-=facing*multiplier*speed*700*scale;
5180 velspeed=findLength(&velocity);
5181 if(velspeed>speed*2*scale){
5183 velspeed=speed*2*scale;
5186 velocity.y+=gravity*multiplier*20;
5187 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5188 velspeed=findLength(&velocity);
5189 velocity=flatfacing*velspeed*-1;
5192 if(targetanimation==fightsidestep){
5193 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5194 velspeed=findLength(&velocity);
5195 if(velspeed>speed*12*scale){
5197 velspeed=speed*12*scale;
5200 velocity.y+=gravity*multiplier*20;
5201 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5202 velspeed=findLength(&velocity);
5203 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5206 if(targetanimation==staggerbackhighanim){
5207 coords-=facing*multiplier*speed*16*scale;
5210 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5211 coords-=facing*multiplier*speed*20*scale;
5215 if(targetanimation==backhandspringanim){
5216 //coords-=facing*multiplier*50*scale;
5217 velocity+=facing*multiplier*speed*700*scale*-1;
5218 velspeed=findLength(&velocity);
5219 if(velspeed>speed*50*scale){
5221 velspeed=speed*50*scale;
5224 velocity.y+=gravity*multiplier*20;
5225 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5226 velspeed=findLength(&velocity);
5227 velocity=flatfacing*velspeed*-1;
5229 if(targetanimation==dodgebackanim){
5230 //coords-=facing*multiplier*50*scale;
5231 velocity+=facing*multiplier*speed*700*scale*-1;
5232 velspeed=findLength(&velocity);
5233 if(velspeed>speed*60*scale){
5235 velspeed=speed*60*scale;
5238 velocity.y+=gravity*multiplier*20;
5239 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5240 velspeed=findLength(&velocity);
5241 velocity=flatfacing*velspeed*-1;
5244 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5245 velspeed=findLength(&velocity);
5249 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5250 velocity.y+=gravity*multiplier;
5253 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5255 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5256 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5258 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5264 pause_sound(whooshsound);
5265 OPENAL_SetVolume(channels[whooshsound], 0);
5268 if(targetanimation==jumpdownanim||isFlip()){
5269 if(isFlip())jumppower=-4;
5270 targetanimation=getLanding();
5271 emit_sound_at(landsound, coords, 128.);
5274 envsound[numenvsounds]=coords;
5275 envsoundvol[numenvsounds]=16;
5276 envsoundlife[numenvsounds]=.4;
5282 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5283 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5284 coords.y=terrain.getHeight(coords.x,coords.z);
5289 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)){
5290 velspeed=findLength(&velocity);
5292 if(velspeed<multiplier*300*scale){
5294 } else velocity-=velocity/velspeed*multiplier*300*scale;
5295 if(velspeed>5&&(isLanding()||isLandhard())){
5296 skiddingdelay+=multiplier;
5303 else skiddingdelay=0;
5307 velspeed=findLength(&velocity);
5309 if(velspeed<multiplier*600*scale){
5311 } else velocity-=velocity/velspeed*multiplier*600*scale;
5313 if(velspeed>5&&(isLanding()||isLandhard())){
5314 skiddingdelay+=multiplier;
5321 else skiddingdelay=0;
5324 if(skiddingdelay<0)skiddingdelay+=multiplier;
5325 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5327 if(!onterrain||environment==grassyenvironment){
5328 emit_sound_at(skidsound, coords, 128*velspeed/10);
5331 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5335 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5336 terrainnormal=victim->coords-coords;
5337 Normalise(&terrainnormal);
5338 targetrotation=-asin(0-terrainnormal.x);
5339 targetrotation*=360/6.28;
5340 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5341 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5344 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5345 targetrotation=victim->targetrotation;
5347 if(targetanimation==rabbittacklinganim){
5348 coords=victim->coords;
5351 skeleton.oldfree=skeleton.free;
5355 midterrain.x=terrain.size*terrain.scale/2;
5356 midterrain.z=terrain.size*terrain.scale/2;
5357 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5359 tempposit=coords-midterrain;
5361 Normalise(&tempposit);
5362 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5363 coords.x=tempposit.x+midterrain.x;
5364 coords.z=tempposit.z+midterrain.z;
5368 int Person::DrawSkeleton(){
5369 int oldplayerdetail;
5370 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5371 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5381 glAlphaFunc(GL_GREATER, 0.0001);
5383 float terrainheight;
5385 if(!isnormal(rotation))rotation=0;
5386 if(!isnormal(tilt))tilt=0;
5387 if(!isnormal(tilt2))tilt2=0;
5388 oldplayerdetail=playerdetail;
5390 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5393 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5396 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5401 if(playerdetail!=oldplayerdetail) {
5403 normalsupdatedelay=0;
5405 static float updatedelaychange;
5406 static float morphness;
5407 static float framemult;
5409 skeleton.FindForwards();
5410 if(howactive==typesittingwall){
5411 skeleton.specialforward[1]=0;
5412 skeleton.specialforward[1].z=1;
5418 static int weaponattachmuscle;
5419 static int weaponrotatemuscle;
5420 static XYZ weaponpoint;
5421 static int start,endthing;
5422 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5423 if(!isSleeping()&&!isSitting()){
5424 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5425 XYZ point,newpoint,change,change2;
5426 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5427 heightleft=terrain.getHeight(point.x,point.z)+.04;
5429 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5430 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5431 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5432 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5433 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5435 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5436 heightright=terrain.getHeight(point.x,point.z)+.04;
5437 point.y=heightright;
5438 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5439 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5440 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5441 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5442 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5443 skeleton.DoConstraints(&coords,&scale);
5445 if(creature==wolftype){
5446 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5447 heightleft=terrain.getHeight(point.x,point.z)+.04;
5449 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5450 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5451 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5452 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5453 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5455 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5456 heightright=terrain.getHeight(point.x,point.z)+.04;
5457 point.y=heightright;
5458 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5459 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5460 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5461 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5462 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5463 skeleton.DoConstraints(&coords,&scale);
5466 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5467 XYZ point,newpoint,change,change2;
5468 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5469 heightleft=terrain.getHeight(point.x,point.z)+.04;
5471 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5472 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5473 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5474 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5475 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5477 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5478 heightright=terrain.getHeight(point.x,point.z)+.04;
5479 point.y=heightright;
5480 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5481 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5482 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5483 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5484 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5485 skeleton.DoConstraints(&coords,&scale);
5487 if(creature==wolftype){
5488 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5489 heightleft=terrain.getHeight(point.x,point.z)+.04;
5491 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5492 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5493 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5494 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5495 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5497 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5498 heightright=terrain.getHeight(point.x,point.z)+.04;
5499 point.y=heightright;
5500 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5501 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5502 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5503 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5504 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5505 skeleton.DoConstraints(&coords,&scale);
5509 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5510 XYZ point,newpoint,change,change2;
5511 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5512 heightleft=terrain.getHeight(point.x,point.z)+.04;
5514 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5515 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5516 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5517 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5518 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5520 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5521 heightright=terrain.getHeight(point.x,point.z)+.04;
5522 point.y=heightright;
5523 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5524 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5525 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5526 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5527 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5528 skeleton.DoConstraints(&coords,&scale);
5530 if(creature==wolftype){
5531 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5532 heightleft=terrain.getHeight(point.x,point.z)+.04;
5534 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5535 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5536 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5537 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5538 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5540 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5541 heightright=terrain.getHeight(point.x,point.z)+.04;
5542 point.y=heightright;
5543 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5544 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5545 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5546 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5547 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5548 skeleton.DoConstraints(&coords,&scale);
5552 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()))
5555 targetheadrotation=-targetrotation;
5556 targetheadrotation2=0;
5557 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5559 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5560 skeleton.drawmodel.vertex[i]=0;
5561 skeleton.drawmodel.vertex[i].y=999;
5563 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5564 skeleton.drawmodellow.vertex[i]=0;
5565 skeleton.drawmodellow.vertex[i].y=999;
5567 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5568 skeleton.drawmodelclothes.vertex[i]=0;
5569 skeleton.drawmodelclothes.vertex[i].y=999;
5571 for(i=0;i<skeleton.num_muscles;i++){
5572 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5576 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5577 morphness=righthandmorphness;
5578 start=righthandmorphstart;
5579 endthing=righthandmorphend;
5581 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5582 morphness=lefthandmorphness;
5583 start=lefthandmorphstart;
5584 endthing=lefthandmorphend;
5586 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5587 morphness=headmorphness;
5588 start=headmorphstart;
5589 endthing=headmorphend;
5591 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)){
5592 morphness=chestmorphness;
5593 start=chestmorphstart;
5594 endthing=chestmorphend;
5596 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)){
5597 morphness=tailmorphness;
5598 start=tailmorphstart;
5599 endthing=tailmorphend;
5601 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5602 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5603 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5606 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5607 if(!skeleton.free)glRotatef(tilt,0,0,1);
5610 glTranslatef(mid.x,mid.y,mid.z);
5612 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5613 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5615 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5616 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5618 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5619 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5621 if(playerdetail||skeleton.free==3)
5623 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5625 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5627 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5628 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,
5629 (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,
5630 (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);
5631 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)
5632 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,
5633 (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,
5634 (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);
5635 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)
5636 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,
5637 (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,
5638 (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);
5639 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5640 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,
5641 (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,
5642 (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);
5643 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5644 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5645 //if(!isnormal(scale))test=1;
5646 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5647 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5648 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5653 if(!playerdetail||skeleton.free==3)
5655 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5657 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5659 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5660 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5661 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5662 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5663 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)
5664 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5665 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5666 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5667 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)
5668 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5669 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5670 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5671 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5672 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5673 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5674 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5676 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5677 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5678 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5679 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5685 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5686 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5688 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5691 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5692 if(!skeleton.free)glRotatef(tilt,0,0,1);
5693 glTranslatef(mid.x,mid.y,mid.z);
5694 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5695 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5697 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5698 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5700 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5701 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5703 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5704 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5706 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5707 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5708 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5709 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5710 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)
5711 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5712 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5713 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5714 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)
5715 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5716 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5717 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5718 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5719 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5720 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5721 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5722 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5723 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5724 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5725 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5730 updatedelay=1+(float)(Random()%100)/1000;
5732 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5733 normalsupdatedelay=1;
5734 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5735 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5736 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5740 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5741 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5742 if(skeleton.clothes){
5743 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5748 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5749 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5750 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5751 if(skeleton.free==1)updatedelaychange*=6;
5752 if(id==0)updatedelaychange*=8;
5753 updatedelay+=updatedelaychange;
5755 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5757 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5758 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5759 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5760 if(!skeleton.free)glRotatef(rotation,0,1,0);
5763 glColor4f(.4,1,.4,1);
5764 glDisable(GL_LIGHTING);
5765 glDisable(GL_TEXTURE_2D);
5768 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5769 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5775 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5776 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);
5777 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);
5778 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);
5779 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);
5780 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);
5781 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);
5787 terrainlight=terrain.getLighting(coords.x,coords.z);
5788 distance=findDistancefast(&viewer,&coords);
5789 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5790 if(distance>1)distance=1;
5792 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5793 if(terrainheight<1)terrainheight=1;
5794 if(terrainheight>1.7)terrainheight=1.7;
5797 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5798 glDisable(GL_BLEND);
5799 glAlphaFunc(GL_GREATER, 0.0001);
5800 glEnable(GL_TEXTURE_2D);
5802 glDisable(GL_TEXTURE_2D);
5803 glColor4f(.7,.35,0,.5);
5805 glEnable(GL_LIGHTING);
5808 if(tutoriallevel&&id!=0){
5809 //glDisable(GL_TEXTURE_2D);
5810 glColor4f(.7,.7,.7,0.6);
5812 glEnable(GL_LIGHTING);
5814 if(canattack&&cananger)
5815 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5816 glDisable(GL_TEXTURE_2D);
5817 glColor4f(1,0,0,0.8);
5819 glMatrixMode(GL_TEXTURE);
5821 glTranslatef(0,-smoketex,0);
5822 glTranslatef(-smoketex,0,0);
5826 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5827 else skeleton.drawmodel.draw();
5831 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5832 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5835 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
5836 if(tutoriallevel&&id!=0){
5838 glMatrixMode(GL_MODELVIEW);
5839 glEnable(GL_TEXTURE_2D);
5840 glColor4f(.7,.7,.7,0.6);
5842 glEnable(GL_LIGHTING);
5844 if(canattack&&cananger)
5845 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5846 glDisable(GL_TEXTURE_2D);
5847 glColor4f(1,0,0,0.8);
5849 glMatrixMode(GL_TEXTURE);
5851 glTranslatef(0,-smoketex*.6,0);
5852 glTranslatef(smoketex*.6,0,0);
5855 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5856 else skeleton.drawmodel.draw();
5860 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5861 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5866 if(tutoriallevel&&id!=0){
5868 glMatrixMode(GL_MODELVIEW);
5869 glEnable(GL_TEXTURE_2D);
5871 if(skeleton.clothes){
5874 if(!immediate)skeleton.drawmodelclothes.draw();
5875 if(immediate)skeleton.drawmodelclothes.drawimmediate();
5882 for(k=0;k<num_weapons;k++){
5884 if(weaponactive==k){
5885 if(weapons[i].getType()!=staff){
5886 for(j=0;j<skeleton.num_muscles;j++){
5887 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5888 weaponattachmuscle=j;
5891 for(j=0;j<skeleton.num_muscles;j++){
5892 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){
5893 weaponrotatemuscle=j;
5896 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5897 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
5899 if(weapons[i].getType()==staff){
5900 for(j=0;j<skeleton.num_muscles;j++){
5901 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5902 weaponattachmuscle=j;
5905 for(j=0;j<skeleton.num_muscles;j++){
5906 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){
5907 weaponrotatemuscle=j;
5910 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
5911 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5912 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5913 XYZ tempnormthing,vec1,vec2;
5914 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5915 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
5916 CrossProduct(&vec1,&vec2,&tempnormthing);
5917 Normalise(&tempnormthing);
5918 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);
5921 if(weaponactive!=k&&weaponstuck!=k){
5922 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;
5923 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;
5924 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;
5925 for(j=0;j<skeleton.num_muscles;j++){
5926 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){
5927 weaponrotatemuscle=j;
5932 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
5933 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
5934 for(j=0;j<skeleton.num_muscles;j++){
5935 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){
5936 weaponrotatemuscle=j;
5941 weapons[i].position=weaponpoint*scale+coords;
5942 weapons[i].bigrotation=0;
5943 weapons[i].bigtilt=0;
5944 weapons[i].bigtilt2=0;
5946 weapons[i].position=DoRotation(DoRotation(DoRotation(weaponpoint,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords+currentoffset*(1-target)*scale+targetoffset*target*scale;
5947 weapons[i].bigrotation=rotation;
5948 weapons[i].bigtilt=tilt;
5949 weapons[i].bigtilt2=tilt2;
5951 weapons[i].rotation1=skeleton.muscles[weaponrotatemuscle].lastrotate1;
5952 weapons[i].rotation2=skeleton.muscles[weaponrotatemuscle].lastrotate2;
5953 weapons[i].rotation3=skeleton.muscles[weaponrotatemuscle].lastrotate3;
5954 if(weaponactive==k){
5955 if(weapons[i].getType()==knife){
5956 weapons[i].smallrotation=180;
5957 weapons[i].smallrotation2=0;
5958 if(isCrouch()||wasCrouch()){
5959 weapons[i].smallrotation2=20;
5961 if(targetanimation==hurtidleanim){
5962 weapons[i].smallrotation2=50;
5964 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
5965 XYZ temppoint1,temppoint2,tempforward;
5968 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5969 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5970 distance=findDistance(&temppoint1,&temppoint2);
5971 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5972 weapons[i].rotation2*=360/6.28;
5975 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
5976 weapons[i].rotation1*=360/6.28;
5977 weapons[i].rotation3=0;
5978 weapons[i].smallrotation=-90;
5979 weapons[i].smallrotation2=0;
5980 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
5982 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
5983 XYZ temppoint1,temppoint2,tempforward;
5986 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5987 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5988 distance=findDistance(&temppoint1,&temppoint2);
5989 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5990 weapons[i].rotation2*=360/6.28;
5993 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
5994 weapons[i].rotation1*=360/6.28;
5995 weapons[i].rotation3=0;
5996 weapons[i].smallrotation=90;
5997 weapons[i].smallrotation2=0;
5998 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6000 if(targetanimation==knifethrowanim){
6001 weapons[i].smallrotation=90;
6002 //weapons[i].smallrotation2=-90;
6003 weapons[i].smallrotation2=0;
6004 weapons[i].rotation1=0;
6005 weapons[i].rotation2=0;
6006 weapons[i].rotation3=0;
6008 if(targetanimation==knifesneakattackanim&&targetframe<5){
6009 weapons[i].smallrotation=-90;
6010 weapons[i].rotation1=0;
6011 weapons[i].rotation2=0;
6012 weapons[i].rotation3=0;
6015 if(weapons[i].getType()==sword){
6016 weapons[i].smallrotation=0;
6017 weapons[i].smallrotation2=0;
6018 if(targetanimation==knifethrowanim){
6019 weapons[i].smallrotation=-90;
6020 weapons[i].smallrotation2=0;
6021 weapons[i].rotation1=0;
6022 weapons[i].rotation2=0;
6023 weapons[i].rotation3=0;
6025 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)){
6026 XYZ temppoint1,temppoint2,tempforward;
6029 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6030 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6031 distance=findDistance(&temppoint1,&temppoint2);
6032 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6033 weapons[i].rotation2*=360/6.28;
6036 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6037 weapons[i].rotation1*=360/6.28;
6038 weapons[i].rotation3=0;
6039 weapons[i].smallrotation=90;
6040 weapons[i].smallrotation2=0;
6041 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6044 if(weapons[i].getType()==staff){
6045 weapons[i].smallrotation=100;
6046 weapons[i].smallrotation2=0;
6047 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6048 XYZ temppoint1,temppoint2,tempforward;
6051 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6052 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6053 distance=findDistance(&temppoint1,&temppoint2);
6054 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6055 weapons[i].rotation2*=360/6.28;
6058 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6059 weapons[i].rotation1*=360/6.28;
6060 weapons[i].rotation3=0;
6061 weapons[i].smallrotation=90;
6062 weapons[i].smallrotation2=0;
6063 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6067 if(weaponactive!=k&&weaponstuck!=k){
6068 if(weapons[i].getType()==knife){
6069 weapons[i].smallrotation=-70;
6070 weapons[i].smallrotation2=10;
6072 if(weapons[i].getType()==sword){
6073 weapons[i].smallrotation=-100;
6074 weapons[i].smallrotation2=-8;
6076 if(weapons[i].getType()==staff){
6077 weapons[i].smallrotation=-100;
6078 weapons[i].smallrotation2=-8;
6082 if(weaponstuckwhere==0)
6083 weapons[i].smallrotation=180;
6085 weapons[i].smallrotation=0;
6086 weapons[i].smallrotation2=10;
6093 if(skeleton.free)calcrot=1;
6094 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6095 if(currentanimation!=targetanimation)calcrot=1;
6096 //if(id==0)calcrot=1;
6097 if(skeleton.free==2)calcrot=0;
6103 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6106 static float distance;
6107 static float olddistance;
6108 static int intersecting;
6109 static int firstintersecting;
6112 static XYZ start,end;
6113 static float slopethreshold=-.4;
6115 firstintersecting=-1;
6119 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6120 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6122 for (j=0;j<model->TriangleNum;j++){
6123 if(model->facenormals[j].y<=slopethreshold){
6125 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)));
6126 if(distance<radius){
6127 point=*p1-model->facenormals[j]*distance;
6128 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;
6129 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6130 &model->vertex[model->Triangles[j].vertex[1]],
6132 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6133 &model->vertex[model->Triangles[j].vertex[2]],
6135 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6136 &model->vertex[model->Triangles[j].vertex[2]],
6139 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6143 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)){
6144 p1->y=point.y+radius;
6145 if((targetanimation==jumpdownanim||isFlip())){
6146 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6148 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6154 pause_sound(whooshsound);
6155 OPENAL_SetVolume(channels[whooshsound], 0);
6158 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6159 if(isFlip())jumppower=-4;
6160 targetanimation=getLanding();
6161 emit_sound_at(landsound, coords, 128.);
6164 envsound[numenvsounds]=coords;
6165 envsoundvol[numenvsounds]=16;
6166 envsoundlife[numenvsounds]=.4;
6174 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6177 for (j=0;j<model->TriangleNum;j++){
6178 if(model->facenormals[j].y>slopethreshold){
6182 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)));
6183 if(distance<radius*.5){
6184 point=start-model->facenormals[j]*distance;
6185 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;
6186 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,
6187 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6188 p1->x, p1->y, p1->z, radius/2);
6189 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,
6190 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6191 p1->x, p1->y, p1->z, radius/2);
6192 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,
6193 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6194 p1->x, p1->y, p1->z, radius/2);
6196 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6197 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6199 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6200 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6202 *p1+=model->facenormals[j]*(distance-radius*.5);
6205 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6209 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6211 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6213 return firstintersecting;