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){
412 if(creature==rabbittype)
415 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
416 if(i<startx)startx=i;
417 if(j<starty)starty=j;
423 if(creature==wolftype)
426 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
427 if(i<startx)startx=i;
428 if(j<starty)starty=j;
440 if(startx<0)startx=0;
441 if(starty<0)starty=0;
442 if(endx>512-1)endx=512-1;
443 if(endy>512-1)endy=512-1;
444 if(endx<startx)endx=startx;
445 if(endy<starty)endy=starty;
447 startx/=realtexdetail;
448 starty/=realtexdetail;
452 int texdetailint=realtexdetail;
454 if(creature==rabbittype)
455 for(i=startx;i<endx;i++){
456 for(j=starty;j<endy;j++){
457 if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
458 color=Random()%85+170;
459 where=i*skeleton.skinsize*3+j*3;
460 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
461 skeleton.skinText[where+1]=0;
462 skeleton.skinText[where+2]=0;
466 if(creature==wolftype)
467 for(i=startx;i<endx;i++){
468 for(j=starty;j<endy;j++){
469 if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
470 color=Random()%85+170;
471 where=i*skeleton.skinsize*3+j*3;
472 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
473 skeleton.skinText[where+1]=0;
474 skeleton.skinText[where+2]=0;
478 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
483 if(creature==rabbittype)
484 while(bloodText[bleedxint*512*3+bleedyint*3+0]>which+4||bloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
485 bleedxint=abs(Random()%512);
486 bleedyint=abs(Random()%512);
488 if(creature==wolftype)
489 while(wolfbloodText[bleedxint*512*3+bleedyint*3+0]>which+4||wolfbloodText[bleedxint*512*3+bleedyint*3+0]<which-4||bleedxint<10||bleedyint<10||bleedxint>500||bleedyint>500){
490 bleedxint=abs(Random()%512);
491 bleedyint=abs(Random()%512);
493 bleedy=bleedxint+offsetx;
494 bleedx=bleedyint+offsety;
495 bleedy/=realtexdetail;
496 bleedx/=realtexdetail;
497 if(bleedx<0)bleedx=0;
498 if(bleedy<0)bleedy=0;
499 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
500 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
501 direction=abs(Random()%2)*2-1;
504 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
505 deathbleeding+=bleeding;
506 bloodloss+=bleeding*3;
508 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
509 if(abs(Random()%2)==0){aitype=gethelptype;
512 else aitype=attacktypecutoff;
515 if(bleeding>2)bleeding=2;
518 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
521 static XYZ startpoint,endpoint,colpoint,movepoint;
522 static float rotationpoint;
524 static XYZ p1,p2,p3,p0;
528 float coordsx,coordsy;
531 if(bloodtoggle&&decals&&tutoriallevel!=1){
533 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
541 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
544 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
545 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
546 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
548 CrossProduct(p2-p1,p3-p1,&N);
549 CrossProduct(p0-p1,p3-p1,&temp);
550 s = dotproduct(&temp,&N)/findLength(&N);
551 CrossProduct(p2-p1,p1-p0,&temp);
552 t = dotproduct(&temp,&N)/findLength(&N);
555 bary.x=findDistancefast(&p0,&p1);
556 bary.y=findDistancefast(&p0,&p2);
557 bary.z=findDistancefast(&p0,&p3);
559 total=bary.x+bary.y+bary.z;
568 total=bary.x+bary.y+bary.z;
574 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
575 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
576 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
577 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
578 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
579 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
580 coordsx=skeleton.drawmodel.Triangles[whichtri].gx[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gx[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gx[2]*bary.z;
581 coordsy=skeleton.drawmodel.Triangles[whichtri].gy[0]*bary.x+skeleton.drawmodel.Triangles[whichtri].gy[1]*bary.y+skeleton.drawmodel.Triangles[whichtri].gy[2]*bary.z;
583 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
584 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
586 if(bleeding<=0&&spurt){
588 for(int i=0;i<3;i++){
592 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
595 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
597 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
598 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
600 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
601 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
604 Sprite::MakeSprite(bloodsprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
605 Sprite::MakeSprite(bloodflamesprite, DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .3, 1);
609 int offsetx=0,offsety=0;
612 offsetx=abs(Random()%120);
614 if(which==220||which==215){
616 offsetx=abs(Random()%80);
619 offsetx=(1+coordsy)*512-291;
620 offsety=coordsx*512-437;
627 if(creature==rabbittype)
630 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
631 if(i<startx)startx=i;
632 if(j<starty)starty=j;
638 if(creature==wolftype)
641 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
642 if(i<startx)startx=i;
643 if(j<starty)starty=j;
654 if(startx<0)startx=0;
655 if(starty<0)starty=0;
656 if(endx>512-1)endx=512-1;
657 if(endy>512-1)endy=512-1;
658 if(endx<startx)endx=startx;
659 if(endy<starty)endy=starty;
661 startx/=realtexdetail;
662 starty/=realtexdetail;
666 int texdetailint=realtexdetail;
668 if(creature==rabbittype)
669 for(i=startx;i<endx;i++){
670 for(j=starty;j<endy;j++){
671 if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
672 color=Random()%85+170;
673 where=i*skeleton.skinsize*3+j*3;
674 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
675 skeleton.skinText[where+1]=0;
676 skeleton.skinText[where+2]=0;
678 else if(bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&bloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
679 color=Random()%85+170;
680 where=i*skeleton.skinsize*3+j*3;
681 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
682 skeleton.skinText[where+1]=0;
683 skeleton.skinText[where+2]=0;
687 if(creature==wolftype)
688 for(i=startx;i<endx;i++){
689 for(j=starty;j<endy;j++){
690 if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=which+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=which-4){
691 color=Random()%85+170;
692 where=i*skeleton.skinsize*3+j*3;
693 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
694 skeleton.skinText[where+1]=0;
695 skeleton.skinText[where+2]=0;
697 else if(wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]<=160+4&&wolfbloodText[(i*texdetailint-offsetx)*512*3+(j*texdetailint-offsety)*3+0]>=160-4){
698 color=Random()%85+170;
699 where=i*skeleton.skinsize*3+j*3;
700 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
701 skeleton.skinText[where+1]=0;
702 skeleton.skinText[where+2]=0;
706 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
709 bleedy=(1+coordsy)*512;
711 bleedy/=realtexdetail;
712 bleedx/=realtexdetail;
713 if(bleedx<0)bleedx=0;
714 if(bleedy<0)bleedy=0;
715 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
716 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
717 direction=abs(Random()%2)*2-1;
719 if(whichtri==-1)return 0;
721 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
722 deathbleeding+=bleeding;
723 bloodloss+=bleeding*3;
725 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
726 if(abs(Random()%2)==0){aitype=gethelptype;
729 else aitype=attacktypecutoff;
732 if(bleeding>2)bleeding=2;
738 void Person::Reverse()
740 if (!((victim->aitype == playercontrolled
742 || staggerdelay <= 0)
743 && victim->targetanimation != jumpupanim
744 && victim->targetanimation != jumpdownanim
745 && (tutoriallevel != 1 || cananger)
749 if (normaldotproduct (victim->facing, victim->coords-coords) > 0
750 && (victim->id != 0 || difficulty >= 2)
751 && (creature != wolftype || victim->creature == wolftype))
754 if(targetanimation==sweepanim){
755 targetanimation=sweepreversedanim;
756 currentanimation=sweepreversedanim;
757 victim->currentanimation=sweepreversalanim;
758 victim->targetanimation=sweepreversalanim;
760 if(targetanimation==spinkickanim){
761 targetanimation=spinkickreversedanim;
762 currentanimation=spinkickreversedanim;
763 victim->currentanimation=spinkickreversalanim;
764 victim->targetanimation=spinkickreversalanim;
766 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
767 if(targetanimation==rabbittacklinganim){
770 victim->currentframe=6;
771 victim->targetframe=7;
773 targetanimation=upunchreversedanim;
774 currentanimation=upunchreversedanim;
775 victim->currentanimation=upunchreversalanim;
776 victim->targetanimation=upunchreversalanim;
778 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
779 if(victim->weaponactive!=-1){
780 victim->throwtogglekeydown=1;
781 weapons[victim->weaponids[0]].owner=-1;
782 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
783 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
784 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
785 weapons[victim->weaponids[0]].missed=1;
786 weapons[victim->weaponids[0]].freetime=0;
787 weapons[victim->weaponids[0]].firstfree=1;
788 weapons[victim->weaponids[0]].physics=1;
789 victim->num_weapons--;
790 if(victim->num_weapons){
791 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
792 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
795 victim->weaponactive=-1;
796 for(int j=0;j<numplayers;j++){
797 player[j].wentforweapon=0;
801 targetanimation=staffhitreversedanim;
802 currentanimation=staffhitreversedanim;
803 victim->currentanimation=staffhitreversalanim;
804 victim->targetanimation=staffhitreversalanim;
806 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
807 if(victim->weaponactive!=-1){
808 victim->throwtogglekeydown=1;
809 weapons[victim->weaponids[0]].owner=-1;
810 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
811 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
812 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
813 weapons[victim->weaponids[0]].missed=1;
814 weapons[victim->weaponids[0]].freetime=0;
815 weapons[victim->weaponids[0]].firstfree=1;
816 weapons[victim->weaponids[0]].physics=1;
817 victim->num_weapons--;
818 if(victim->num_weapons){
819 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
820 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
823 victim->weaponactive=-1;
824 for(int j=0;j<numplayers;j++){
825 player[j].wentforweapon=0;
828 targetanimation=staffspinhitreversedanim;
829 currentanimation=staffspinhitreversedanim;
830 victim->currentanimation=staffspinhitreversalanim;
831 victim->targetanimation=staffspinhitreversalanim;
833 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
834 if(victim->weaponactive!=-1){
835 victim->throwtogglekeydown=1;
836 weapons[victim->weaponids[0]].owner=-1;
837 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
838 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
839 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
840 weapons[victim->weaponids[0]].missed=1;
841 weapons[victim->weaponids[0]].freetime=0;
842 weapons[victim->weaponids[0]].firstfree=1;
843 weapons[victim->weaponids[0]].physics=1;
844 victim->num_weapons--;
845 if(victim->num_weapons){
846 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
847 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
850 victim->weaponactive=-1;
851 for(int j=0;j<numplayers;j++){
852 player[j].wentforweapon=0;
855 targetanimation=swordslashreversedanim;
856 currentanimation=swordslashreversedanim;
857 victim->currentanimation=swordslashreversalanim;
858 victim->targetanimation=swordslashreversalanim;
860 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
861 if(victim->weaponactive!=-1){
862 victim->throwtogglekeydown=1;
863 weapons[victim->weaponids[0]].owner=-1;
864 weapons[victim->weaponids[0]].velocity=victim->velocity*.2;
865 if(weapons[victim->weaponids[0]].velocity.x==0)weapons[victim->weaponids[0]].velocity.x=.1;
866 weapons[victim->weaponids[0]].tipvelocity=weapons[victim->weaponids[0]].velocity;
867 weapons[victim->weaponids[0]].missed=1;
868 weapons[victim->weaponids[0]].freetime=0;
869 weapons[victim->weaponids[0]].firstfree=1;
870 weapons[victim->weaponids[0]].physics=1;
871 victim->num_weapons--;
872 if(victim->num_weapons){
873 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
874 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
877 victim->weaponactive=-1;
878 for(int j=0;j<numplayers;j++){
879 player[j].wentforweapon=0;
882 targetanimation=knifeslashreversedanim;
883 currentanimation=knifeslashreversedanim;
884 victim->currentanimation=knifeslashreversalanim;
885 victim->targetanimation=knifeslashreversalanim;
887 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
888 victim->targettilt2=targettilt2;
889 victim->currentframe=currentframe;
890 victim->targetframe=targetframe;
891 victim->target=target;
893 victim->oldcoords=victim->coords;
894 victim->coords=coords;
895 victim->targetrotation=targetrotation;
896 victim->rotation=targetrotation;
899 if(targetanimation==winduppunchanim){
900 targetanimation=winduppunchblockedanim;
901 victim->targetanimation=blockhighleftanim;
902 victim->targetframe=1;
905 victim->targetrotation=targetrotation+180;
907 if(targetanimation==wolfslapanim){
908 targetanimation=winduppunchblockedanim;
909 victim->targetanimation=blockhighleftanim;
910 victim->targetframe=1;
913 victim->targetrotation=targetrotation+180;
915 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
916 targetanimation=swordslashparriedanim;
918 victim->parriedrecently=0;
919 victim->targetanimation=swordslashparryanim;
920 victim->targetframe=1;
923 victim->targetrotation=targetrotation+180;
925 if(abs(Random()%20)==0||weapons[victim->weaponids[victim->weaponactive]].getType()==knife){
926 if(victim->weaponactive!=-1){
927 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff) {
928 if(weapons[victim->weaponids[0]].getType()==staff)
929 weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
930 if(weapons[weaponids[0]].getType()==staff)
931 weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
932 emit_sound_at(swordstaffsound, victim->coords);
935 emit_sound_at(metalhitsound, victim->coords);
939 victim->Puff(righthand);
941 victim->targetframe=0;
942 victim->targetanimation=staggerbackhighanim;
943 victim->targetrotation=targetrotation+180;
945 weapons[victim->weaponids[0]].owner=-1;
946 aim=DoRotation(facing,0,90,0)*21;
948 weapons[victim->weaponids[0]].velocity=aim*-.2;
949 weapons[victim->weaponids[0]].tipvelocity=aim;
950 weapons[victim->weaponids[0]].missed=1;
951 weapons[victim->weaponids[0]].hitsomething=0;
952 weapons[victim->weaponids[0]].freetime=0;
953 weapons[victim->weaponids[0]].firstfree=1;
954 weapons[victim->weaponids[0]].physics=1;
955 victim->num_weapons--;
956 if(victim->num_weapons){
957 victim->weaponids[0]=victim->weaponids[num_weapons];
958 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
960 victim->weaponactive=-1;
961 for(int i=0;i<numplayers;i++){
962 player[i].wentforweapon=0;
966 if(abs(Random()%20)==0){
967 if(weaponactive!=-1){
968 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
969 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
970 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
972 emit_sound_at(swordstaffsound, coords);
975 emit_sound_at(metalhitsound, coords);
983 targetanimation=staggerbackhighanim;
984 targetrotation=targetrotation+180;
986 weapons[weaponids[0]].owner=-1;
987 aim=DoRotation(facing,0,90,0)*21;
989 weapons[weaponids[0]].velocity=aim*-.2;
990 weapons[weaponids[0]].tipvelocity=aim;
991 weapons[weaponids[0]].hitsomething=0;
992 weapons[weaponids[0]].missed=1;
993 weapons[weaponids[0]].freetime=0;
994 weapons[weaponids[0]].firstfree=1;
995 weapons[weaponids[0]].physics=1;
998 weaponids[0]=weaponids[num_weapons];
999 if(weaponstuck==num_weapons)weaponstuck=0;
1002 for(int i=0;i<numplayers;i++){
1003 player[i].wentforweapon=0;
1010 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1011 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1012 victim->targetanimation=dodgebackanim;
1013 victim->targetframe=0;
1017 rotatetarget=coords-victim->coords;
1018 Normalise(&rotatetarget);
1019 victim->targetrotation=-asin(0-rotatetarget.x);
1020 victim->targetrotation*=360/6.28;
1021 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1023 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1025 victim->lastattack3=victim->lastattack2;
1026 victim->lastattack2=victim->lastattack;
1027 victim->lastattack=victim->targetanimation;
1031 victim->targetanimation=sweepanim;
1032 victim->targetframe=0;
1036 rotatetarget=coords-victim->coords;
1037 Normalise(&rotatetarget);
1038 victim->targetrotation=-asin(0-rotatetarget.x);
1039 victim->targetrotation*=360/6.28;
1040 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1042 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1044 victim->lastattack3=victim->lastattack2;
1045 victim->lastattack2=victim->lastattack;
1046 victim->lastattack=victim->targetanimation;
1053 if(aitype!=playercontrolled)feint=0;
1054 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1055 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1056 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1058 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1061 void Person::DoDamage(float howmuch){
1062 if(tutoriallevel!=1)damage+=howmuch/power;
1063 if(id!=0)damagedealt+=howmuch/power;
1064 if(id==0)damagetaken+=howmuch/power;
1066 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1067 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1068 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1069 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1070 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1072 if(id==0)camerashake+=howmuch/100;
1073 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1074 if(blackout>1)blackout=1;
1076 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1077 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1078 if(abs(Random()%2)==0){aitype=gethelptype;
1081 else aitype=attacktypecutoff;
1085 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1088 for(int i=0;i<skeleton.num_joints; i++){
1089 if(!skeleton.free)flatvelocity2=velocity;
1090 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1091 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1092 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1093 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1094 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1095 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1096 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1097 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1098 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1101 emit_sound_at(splattersound, coords);
1110 if(!dead&&creature==wolftype){
1111 award_bonus(0, Wolfbonus);
1117 if(tutoriallevel!=1||id==0)
1118 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1121 if(creature==wolftype){
1122 int i=abs(Random()%2);
1123 if(i==0)whichsound=snarlsound;
1124 if(i==1)whichsound=snarl2sound;
1125 envsound[numenvsounds]=coords;
1126 envsoundvol[numenvsounds]=16;
1127 envsoundlife[numenvsounds]=.4;
1130 if(creature==rabbittype){
1131 int i=abs(Random()%2);
1132 if(i==0)whichsound=rabbitpainsound;
1133 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1134 envsound[numenvsounds]=coords;
1135 envsoundvol[numenvsounds]=16;
1136 envsoundlife[numenvsounds]=.4;
1138 //if(i==2)whichsound=rabbitpain2sound;
1142 emit_sound_at(whichsound, coords);
1147 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1148 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1151 void Person::DoHead(){
1152 static XYZ rotatearound;
1154 static float lookspeed=500;
1156 if(!freeze&&!winfreeze){
1159 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1160 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1162 while(targetheadrotation>180)targetheadrotation-=360;
1163 while(targetheadrotation<-180)targetheadrotation+=360;
1165 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1166 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1167 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1168 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1170 if(targetheadrotation2>120)targetheadrotation2=120;
1171 if(targetheadrotation2<-120)targetheadrotation2=-120;
1172 if(targetheadrotation>120)targetheadrotation=120;
1173 if(targetheadrotation<-120)targetheadrotation=-120;
1175 if(!isIdle())targetheadrotation2=0;
1177 if(targetheadrotation>80)targetheadrotation=80;
1178 if(targetheadrotation<-80)targetheadrotation=-80;
1179 if(targetheadrotation2>50)targetheadrotation2=50;
1180 if(targetheadrotation2<-50)targetheadrotation2=-50;
1183 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1184 else if(headrotation>targetheadrotation){
1185 headrotation-=multiplier*lookspeed;
1187 else if(headrotation<targetheadrotation){
1188 headrotation+=multiplier*lookspeed;
1191 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1192 else if(headrotation2>targetheadrotation2){
1193 headrotation2-=multiplier*lookspeed/2;
1195 else if(headrotation2<targetheadrotation2){
1196 headrotation2+=multiplier*lookspeed/2;
1199 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1200 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1204 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1205 facing=DoRotation(facing,headrotation2*.4,0,0);
1206 facing=DoRotation(facing,0,headrotation*.4,0);
1209 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1210 facing=DoRotation(facing,headrotation2*.8,0,0);
1211 facing=DoRotation(facing,0,headrotation*.8,0);
1214 if(targetanimation==walkanim){
1215 facing=DoRotation(facing,headrotation2*.6,0,0);
1216 facing=DoRotation(facing,0,headrotation*.6,0);
1219 skeleton.specialforward[0]=facing;
1220 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1222 for(i=0;i<skeleton.num_muscles;i++){
1223 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1225 skeleton.FindRotationMuscle(i,targetanimation);
1231 void Person::RagDoll(bool checkcollision){
1236 if(id==0)numfalls++;
1237 if(id==0&&isFlip())numflipfail++;
1243 facing=DoRotation(facing,0,rotation,0);
1245 skeleton.freetime=0;
1247 skeleton.longdead=0;
1253 skeleton.freefall=1;
1255 if(!isnormal(velocity.x))velocity.x=0;
1256 if(!isnormal(velocity.y))velocity.y=0;
1257 if(!isnormal(velocity.z))velocity.z=0;
1258 if(!isnormal(rotation))rotation=0;
1259 if(!isnormal(coords.x))coords=0;
1260 if(!isnormal(tilt))tilt=0;
1261 if(!isnormal(tilt2))tilt2=0;
1263 for(i=0;i<skeleton.num_joints;i++){
1264 skeleton.joints[i].delay=0;
1265 skeleton.joints[i].locked=0;
1266 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1267 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1268 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1269 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1270 skeleton.joints[i].position.y+=.1;
1271 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1272 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1275 for(i=0;i<skeleton.num_joints;i++){
1276 skeleton.joints[i].velocity=0;
1277 skeleton.joints[i].velchange=0;
1279 skeleton.DoConstraints(&coords,&scale);
1280 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1282 skeleton.DoConstraints(&coords,&scale);
1283 skeleton.DoConstraints(&coords,&scale);
1284 skeleton.DoConstraints(&coords,&scale);
1285 skeleton.DoConstraints(&coords,&scale);
1288 speed=animation[targetanimation].speed[targetframe]*2;
1289 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1290 speed=animation[currentanimation].speed[currentframe]*2;
1292 if(transspeed)speed=transspeed*2;
1296 for(i=0;i<skeleton.num_joints;i++){
1297 if((animation[currentanimation].attack!=reversed||currentanimation==swordslashreversedanim)&¤tanimation!=rabbitkickanim&&!isLanding()&&!wasLanding()&&animation[currentanimation].height==animation[targetanimation].height)skeleton.joints[i].velocity=velocity/scale+facing*5+DoRotation(DoRotation(DoRotation((animation[targetanimation].position[i][targetframe]-animation[currentanimation].position[i][currentframe])*speed,0,0,tilt),tilt2,0,0),0,rotation,0);
1298 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1299 change.x=(float)(Random()%100)/100;
1300 change.y=(float)(Random()%100)/100;
1301 change.z=(float)(Random()%100)/100;
1302 skeleton.joints[i].velocity+=change;
1303 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1305 change.x=(float)(Random()%100)/100;
1306 change.y=(float)(Random()%100)/100;
1307 change.z=(float)(Random()%100)/100;
1308 skeleton.joints[i].velchange+=change;
1309 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1319 for(j=0;j<skeleton.num_joints;j++){
1320 average+=skeleton.joints[j].position;
1324 coords+=average*scale;
1325 for(j=0;j<skeleton.num_joints;j++){
1326 skeleton.joints[j].position-=average;
1329 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale);
1330 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale);
1331 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1332 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1333 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1336 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1337 coords.x=lowpoint.x;
1338 coords.z=lowpoint.z;
1347 for(i=0;i<skeleton.num_joints;i++){
1348 velocity+=skeleton.joints[i].velocity*scale;
1350 velocity/=skeleton.num_joints;
1353 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1354 weapons[weaponids[0]].owner=-1;
1355 weapons[weaponids[0]].hitsomething=0;
1356 weapons[weaponids[0]].velocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1357 weapons[weaponids[0]].velocity.x+=.01;
1358 weapons[weaponids[0]].tipvelocity=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1359 weapons[weaponids[0]].missed=1;
1360 weapons[weaponids[0]].freetime=0;
1361 weapons[weaponids[0]].firstfree=1;
1362 weapons[weaponids[0]].physics=1;
1365 weaponids[0]=weaponids[num_weapons];
1366 if(weaponstuck==num_weapons)weaponstuck=0;
1369 for(i=0;i<numplayers;i++){
1370 player[i].wentforweapon=0;
1375 targetanimation=bounceidleanim;
1376 currentanimation=bounceidleanim;
1384 void Person::FootLand(int which, float opacity){
1385 static XYZ terrainlight;
1386 static XYZ footvel,footpoint;
1387 if(opacity>=1||skiddelay<=0)
1391 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1392 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1393 //footpoint.y=coords.y;
1394 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1396 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1398 if(footvel.y<.8)footvel.y=.8;
1399 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1400 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1401 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1402 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1403 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1404 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1406 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1408 if(footvel.y<.8)footvel.y=.8;
1409 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1410 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1411 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1412 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1413 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*90/255,terrainlight.y*70/255,terrainlight.z*8/255, .5, .5*opacity);
1415 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1417 if(footvel.y<.8)footvel.y=.8;
1418 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1419 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1420 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1421 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1422 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x*190/255,terrainlight.y*170/255,terrainlight.z*108/255, .5, .7*opacity);
1423 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1425 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1428 if(footvel.y<.8)footvel.y=.8;
1429 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1430 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1431 //footpoint.y=coords.y;
1432 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1436 void Person::Puff(int whichlabel){
1437 static XYZ footvel,footpoint;
1440 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1441 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1445 void Person::DoAnimations(){
1448 static float oldtarget;
1450 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1452 if(targetanimation==tempanim||currentanimation==tempanim){
1453 animation[tempanim]=tempanimation;
1455 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1466 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1467 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1469 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1470 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1472 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1477 targfacing=DoRotation(targfacing,0,targetrotation,0);
1479 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1480 else targetanimation=backflipanim;
1481 crouchtogglekeydown=1;
1485 if(id==0)numflipped++;
1488 if(animation[targetanimation].attack!=reversed)feint=0;
1489 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1490 crouchtogglekeydown=0;
1491 if(aitype==playercontrolled)feint=0;
1495 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1496 if(!isFlip())crouchtogglekeydown=1;
1500 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1501 if(detail)normalsupdatedelay=0;
1505 if(targetanimation==rollanim&&targetframe==3&&onfire){
1507 emit_sound_at(fireendsound, coords);
1508 pause_sound(stream_firesound);
1512 if(targetanimation==rabbittacklinganim&&targetframe==1){
1513 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1514 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1515 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1516 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1517 else victim->targetanimation=rabbittackledfrontanim;
1518 victim->targetframe=2;
1520 victim->rotation=rotation;
1521 victim->targetrotation=rotation;
1522 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1523 //victim->DoDamage(30);
1524 if(creature==wolftype){
1526 emit_sound_at(clawslicesound, victim->coords);
1528 victim->DoBloodBig(1/victim->armorhead,210);
1530 award_bonus(id, TackleBonus,
1531 victim->aitype == gethelptype ? 50 : 0);
1535 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1536 if(weapons[weaponids[0]].getType()==knife){
1537 if(weaponactive==-1)weaponactive=0;
1538 else if(weaponactive==0)weaponactive=-1;
1540 if(weaponactive==-1){
1541 emit_sound_at(knifesheathesound, coords);
1543 if(weaponactive!=-1){
1544 emit_sound_at(knifedrawsound, coords, 128);
1547 drawtogglekeydown=1;
1550 if(tutoriallevel!=1||id==0)
1551 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1554 if(terrain.getOpacity(coords.x,coords.z)<.2){
1555 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1556 else whichsound=footstepsound2;
1557 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1558 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1559 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1565 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1566 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1567 else whichsound=footstepsound4;
1571 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1572 else whichsound=footstepsound4;
1574 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1575 if(animation[targetanimation].attack!=neutral){
1577 if(i==0)whichsound=lowwhooshsound;
1578 if(i==1)whichsound=midwhooshsound;
1579 if(i==2)whichsound=highwhooshsound;
1581 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1583 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1584 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1586 emit_sound_at(whichsound, coords, 256.);
1589 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1590 envsound[numenvsounds]=coords;
1591 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1592 else envsoundvol[numenvsounds]=6;
1593 envsoundlife[numenvsounds]=.4;
1597 if(animation[targetanimation].label[targetframe]==3){
1599 emit_sound_at(whichsound, coords, 128.);
1604 if(tutoriallevel!=1||id==0)
1606 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1607 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1609 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1610 if(animation[targetanimation].attack!=neutral){
1612 if(creature==rabbittype){
1613 if(i==0)whichsound=rabbitattacksound;
1614 if(i==1)whichsound=rabbitattack2sound;
1615 if(i==2)whichsound=rabbitattack3sound;
1616 if(i==3)whichsound=rabbitattack4sound;
1618 if(creature==wolftype){
1619 if(i==0)whichsound=barksound;
1620 if(i==1)whichsound=bark2sound;
1621 if(i==2)whichsound=bark3sound;
1622 if(i==3)whichsound=barkgrowlsound;
1626 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1628 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1629 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1632 emit_sound_at(whichsound, coords);
1638 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1644 currentoffset=targetoffset;
1645 targetframe=currentframe;
1646 currentanimation=targetanimation;
1649 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1650 for(i=0;i<weapons.size();i++){
1651 if(weapons[i].owner==-1)
1652 if(findDistancefastflat(&coords,&weapons[i].position)<4&&weaponactive==-1){
1653 if(findDistancefast(&coords,&weapons[i].position)>=1){
1654 if(weapons[i].getType()!=staff){
1655 emit_sound_at(knifedrawsound, coords, 128.);
1659 weapons[i].owner=id;
1661 weaponids[num_weapons]=weaponids[0];
1670 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1671 for(i=0;i<weapons.size();i++){
1673 if(weapons[i].owner!=-1)
1674 if(player[weapons[i].owner].weaponstuck!=-1)
1675 if(player[weapons[i].owner].weaponids[player[weapons[i].owner].weaponstuck]==i)
1676 if(player[weapons[i].owner].num_weapons>1)willwork=0;
1677 if((weapons[i].owner==-1)||(hasvictim&&weapons[i].owner==victim->id&&victim->skeleton.free))
1678 if(willwork&&findDistancefastflat(&coords,&weapons[i].position)<3&&weaponactive==-1){
1679 if(findDistancefast(&coords,&weapons[i].position)<1||hasvictim){
1680 bool fleshstuck=false;
1681 if(weapons[i].owner!=-1)
1682 if(victim->weaponstuck!=-1){
1683 if(victim->weaponids[victim->weaponstuck]==i){
1688 emit_sound_at(fleshstabremovesound, coords, 128.);
1690 if(weapons[i].getType()!=staff){
1691 emit_sound_at(knifedrawsound, coords, 128.);
1695 if(weapons[i].owner!=-1){
1697 victim=&player[weapons[i].owner];
1698 if(victim->num_weapons==1)victim->num_weapons=0;
1699 else victim->num_weapons=1;
1701 //victim->weaponactive=-1;
1702 victim->skeleton.longdead=0;
1703 victim->skeleton.free=1;
1704 victim->skeleton.broken=0;
1706 for(int j=0;j<victim->skeleton.num_joints;j++){
1707 victim->skeleton.joints[j].velchange=0;
1708 victim->skeleton.joints[j].locked=0;
1714 Normalise(&relative);
1715 XYZ footvel,footpoint;
1717 footpoint=weapons[i].position;
1718 if(victim->weaponstuck!=-1){
1719 if(victim->weaponids[victim->weaponstuck]==i){
1720 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1721 weapons[i].bloody=2;
1722 weapons[i].blooddrip=5;
1723 victim->weaponstuck=-1;
1726 if(victim->num_weapons>0){
1727 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1728 if(victim->weaponids[0]==i)
1729 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1732 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1733 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1734 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1735 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1737 weapons[i].owner=id;
1739 weaponids[num_weapons]=weaponids[0];
1748 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1749 if(weaponactive==-1)weaponactive=0;
1750 else if(weaponactive==0){
1754 buffer=weaponids[0];
1755 weaponids[0]=weaponids[1];
1756 weaponids[1]=buffer;
1759 if(weaponactive==-1){
1760 emit_sound_at(knifesheathesound, coords, 128.);
1762 if(weaponactive!=-1){
1763 emit_sound_at(knifedrawsound, coords, 128.);
1768 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1769 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1770 Normalise(&rotatetarget);
1771 targetrotation=-asin(0-rotatetarget.x);
1772 targetrotation*=360/6.28;
1773 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1775 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1776 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1781 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1783 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;
1785 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1786 targetanimation=rabbittackleanim;
1788 emit_sound_at(jumpsound, coords);
1797 Normalise(&targetloc);
1799 for(i=0;i<numplayers;i++){
1801 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1802 closestdist=findDistancefast(&targetloc,&player[i].coords);
1807 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1809 victim=&player[closestid];
1810 coords=victim->coords;
1811 currentanimation=rabbittacklinganim;
1812 targetanimation=rabbittacklinganim;
1816 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1817 rotatetarget=coords-victim->coords;
1818 Normalise(&rotatetarget);
1819 targetrotation=-asin(0-rotatetarget.x);
1820 targetrotation*=360/6.28;
1821 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1823 if(targetanimation!=rabbitrunninganim){
1824 emit_sound_at(jumpsound, coords, 128.);
1830 float damagemult=1*power;
1831 if(creature==wolftype)damagemult=2.5*power;
1832 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1833 //if(onfire)damagemult=3;
1834 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1835 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1836 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1838 if(id==0)camerashake+=.4;
1839 if(Random()%2||creature==wolftype){
1842 if(creature==wolftype)DoBloodBig(0,250);
1844 if(tutoriallevel!=1){
1845 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1847 if(creature==wolftype){
1848 emit_sound_at(clawslicesound, victim->coords, 128.);
1850 victim->DoBloodBig(2/victim->armorhead,175);
1854 relative=victim->coords-coords;
1856 Normalise(&relative);
1857 relative=DoRotation(relative,0,-90,0);
1858 for(i=0;i<victim->skeleton.num_joints;i++){
1859 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1861 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1864 victim->DoDamage(damagemult*100/victim->protectionhead);
1870 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1871 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1873 if(id==0)camerashake+=.4;
1874 if(Random()%2||creature==wolftype){
1876 if(creature==wolftype)DoBloodBig(0,235);
1878 emit_sound_at(whooshhitsound, victim->coords);
1879 if(creature==wolftype){
1880 emit_sound_at(clawslicesound, victim->coords, 128.);
1882 victim->DoBloodBig(2,175);
1886 relative=victim->coords-coords;
1888 Normalise(&relative);
1890 Normalise(&relative);
1891 relative=DoRotation(relative,0,90,0);
1892 for(i=0;i<victim->skeleton.num_joints;i++){
1893 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
1895 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1898 victim->DoDamage(damagemult*50/victim->protectionhead);
1902 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
1903 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1905 if(id==0)camerashake+=.4;
1908 if(tutoriallevel!=1){
1909 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1911 if(creature==wolftype){
1912 emit_sound_at(clawslicesound, victim->coords, 128.);
1914 victim->DoBloodBig(2/victim->armorhead,175);
1920 Normalise(&relative);
1921 relative=DoRotation(relative,0,-90,0);
1922 for(i=0;i<victim->skeleton.num_joints;i++){
1923 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1925 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1928 victim->DoDamage(damagemult*150/victim->protectionhead);
1930 if(victim->damage>victim->damagetolerance)
1931 award_bonus(id, style);
1937 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
1938 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1940 if(id==0)camerashake+=.4;
1943 if(tutoriallevel!=1){
1944 emit_sound_at(heavyimpactsound, victim->coords, 160.);
1946 if(creature==wolftype){
1947 emit_sound_at(clawslicesound, victim->coords, 128.);
1949 victim->DoBloodBig(2/victim->armorhead,175);
1955 Normalise(&relative);
1956 relative=DoRotation(relative,0,90,0);
1957 for(i=0;i<victim->skeleton.num_joints;i++){
1958 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1960 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1963 victim->DoDamage(damagemult*150/victim->protectionhead);
1965 if(victim->damage>victim->damagetolerance)
1966 award_bonus(id, style);
1972 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
1973 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
1975 if(id==0)camerashake+=.4;
1980 emit_sound_at(whooshhitsound, victim->coords);
1983 relative=victim->coords-coords;
1985 Normalise(&relative);
1986 for(i=0;i<victim->skeleton.num_joints;i++){
1987 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
1989 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
1992 victim->DoDamage(damagemult*50/victim->protectionhead);
1996 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
1997 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
1999 if(id==0)camerashake+=.2;
2000 emit_sound_at(whooshhitsound, victim->coords, 128.);
2002 victim->skeleton.longdead=0;
2003 victim->skeleton.free=1;
2004 victim->skeleton.broken=0;
2005 victim->skeleton.spinny=1;
2007 for(i=0;i<victim->skeleton.num_joints;i++){
2008 victim->skeleton.joints[i].velchange=0;
2009 victim->skeleton.joints[i].delay=0;
2010 victim->skeleton.joints[i].locked=0;
2011 //victim->skeleton.joints[i].velocity=0;
2017 Normalise(&relative);
2018 for(i=0;i<victim->skeleton.num_joints;i++){
2019 victim->skeleton.joints[i].velocity.y=relative.y*10;
2020 victim->skeleton.joints[i].position.y+=relative.y*.3;
2021 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2022 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2024 victim->Puff(abdomen);
2025 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2029 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2030 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2032 if(id==0)camerashake+=.4;
2033 if(tutoriallevel!=1){
2034 emit_sound_at(heavyimpactsound, coords, 128.);
2037 relative=victim->coords-coords;
2039 Normalise(&relative);
2040 for(i=0;i<victim->skeleton.num_joints;i++){
2041 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2043 victim->Puff(abdomen);
2044 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2048 victim->DoDamage(damagemult*500/victim->protectionhigh);
2049 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2053 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2054 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2056 if(id==0)camerashake+=.4;
2057 if(tutoriallevel!=1){
2058 emit_sound_at(thudsound, coords);
2061 victim->skeleton.longdead=0;
2062 victim->skeleton.free=1;
2063 victim->skeleton.broken=0;
2064 victim->skeleton.spinny=1;
2066 for(i=0;i<victim->skeleton.num_joints;i++){
2067 victim->skeleton.joints[i].velchange=0;
2068 //victim->skeleton.joints[i].delay=0;
2069 victim->skeleton.joints[i].locked=0;
2072 relative=victim->coords-coords;
2073 Normalise(&relative);
2075 Normalise(&relative);
2076 for(i=0;i<victim->skeleton.num_joints;i++){
2077 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2082 victim->Puff(abdomen);
2083 victim->DoDamage(damagemult*20/victim->protectionhigh);
2084 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2086 if(!victim->dead)staggerdelay=1.2;
2092 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2093 //if(id==0)camerashake+=.4;
2096 if(!victim->skeleton.free)hasvictim=0;
2099 terrain.MakeDecal(blooddecalfast,(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2),.08,.6,Random()%360);
2100 emit_sound_at(knifesheathesound, coords, 128.);
2103 if(victim&&hasvictim){
2104 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2106 XYZ where,startpoint,endpoint,movepoint,colpoint;
2107 float rotationpoint;
2109 if(weapons[weaponids[weaponactive]].getType()==knife){
2110 where=(weapons[weaponids[weaponactive]].tippoint*.6+weapons[weaponids[weaponactive]].position*.4);
2111 where-=victim->coords;
2112 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2119 if(weapons[weaponids[weaponactive]].getType()==sword){
2120 where=weapons[weaponids[weaponactive]].position;
2121 where-=victim->coords;
2122 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2124 where=weapons[weaponids[weaponactive]].tippoint;
2125 where-=victim->coords;
2126 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2129 if(weapons[weaponids[weaponactive]].getType()==staff){
2130 where=weapons[weaponids[weaponactive]].position;
2131 where-=victim->coords;
2132 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2134 where=weapons[weaponids[weaponactive]].tippoint;
2135 where-=victim->coords;
2136 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2141 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2144 if(victim->dead!=2){
2145 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2147 award_bonus(id, FinishedBonus);
2149 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
2151 victim->skeleton.longdead=0;
2152 victim->skeleton.free=1;
2153 victim->skeleton.broken=0;
2155 for(i=0;i<victim->skeleton.num_joints;i++){
2156 victim->skeleton.joints[i].velchange=0;
2157 victim->skeleton.joints[i].locked=0;
2158 //victim->skeleton.joints[i].velocity=0;
2160 emit_sound_at(fleshstabsound, coords, 128);
2163 if(whichtri!=-1||weapons[weaponids[weaponactive]].bloody){
2164 weapons[weaponids[weaponactive]].blooddrip+=5;
2165 weapons[weaponids[weaponactive]].blooddripdelay=0;
2169 emit_sound_at(knifesheathesound, coords, 128.);
2175 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2177 emit_sound_at(knifedrawsound, coords, 128);
2180 if(victim&&hasvictim){
2181 XYZ footvel,footpoint;
2183 emit_sound_at(fleshstabremovesound, coords, 128.);
2186 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2188 if(weapons[weaponids[weaponactive]].getType()==sword){
2189 XYZ where,startpoint,endpoint,movepoint;
2190 float rotationpoint;
2193 where=weapons[weaponids[weaponactive]].position;
2194 where-=victim->coords;
2195 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2197 where=weapons[weaponids[weaponactive]].tippoint;
2198 where-=victim->coords;
2199 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2204 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2205 footpoint+=victim->coords;
2208 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2211 if(weapons[weaponids[weaponactive]].getType()==staff){
2212 XYZ where,startpoint,endpoint,movepoint;
2213 float rotationpoint;
2216 where=weapons[weaponids[weaponactive]].position;
2217 where-=victim->coords;
2218 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2220 where=weapons[weaponids[weaponactive]].tippoint;
2221 where-=victim->coords;
2222 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2227 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2228 footpoint+=victim->coords;
2231 footpoint=(weapons[weaponids[weaponactive]].tippoint*.8+weapons[weaponids[weaponactive]].position*.2);
2234 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2236 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2237 victim->skeleton.longdead=0;
2238 victim->skeleton.free=1;
2239 victim->skeleton.broken=0;
2241 for(i=0;i<victim->skeleton.num_joints;i++){
2242 victim->skeleton.joints[i].velchange=0;
2243 victim->skeleton.joints[i].locked=0;
2244 //victim->skeleton.joints[i].velocity=0;
2250 Normalise(&relative);
2251 //victim->Puff(abdomen);
2252 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2254 if(victim->bloodloss<victim->damagetolerance){
2255 victim->bloodloss+=1000;
2259 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2263 if(!hasvictim&&onterrain){
2264 weapons[weaponids[weaponactive]].bloody=0;
2265 weapons[weaponids[weaponactive]].blooddrip=0;
2269 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2270 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2272 if(id==0)camerashake+=.4;
2277 if(tutoriallevel!=1){
2278 emit_sound_at(heavyimpactsound, victim->coords, 128);
2283 relative=victim->coords-coords;
2285 Normalise(&relative);
2286 for(i=0;i<victim->skeleton.num_joints;i++){
2287 victim->skeleton.joints[i].velocity=relative*30;
2289 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2291 victim->targetframe=0;
2292 victim->targetanimation=staggerbackhardanim;
2293 victim->targetrotation=targetrotation+180;
2298 victim->Puff(abdomen);
2299 victim->DoDamage(damagemult*60/victim->protectionhigh);
2306 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2307 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2309 if(id==0)camerashake+=.4;
2310 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2311 if(tutoriallevel!=1){
2312 emit_sound_at(thudsound, victim->coords);
2315 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2316 if(tutoriallevel!=1){
2317 emit_sound_at(whooshhitsound, victim->coords);
2321 if(tutoriallevel!=1){
2322 emit_sound_at(heavyimpactsound, victim->coords);
2326 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2329 relative=victim->coords-coords;
2331 Normalise(&relative);
2333 Normalise(&relative);
2334 for(i=0;i<victim->skeleton.num_joints;i++){
2335 victim->skeleton.joints[i].velocity=relative*5;
2337 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2339 victim->targetframe=0;
2340 victim->targetanimation=staggerbackhardanim;
2341 victim->targetrotation=targetrotation+180;
2345 victim->Puff(abdomen);
2346 victim->DoDamage(damagemult*60/victim->protectionhigh);
2352 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2353 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2354 if(victim->id==0)camerashake+=.4;
2355 emit_sound_at(landsound2, victim->coords);
2361 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2362 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2363 if(victim->id==0)camerashake+=.4;
2365 if(weaponactive!=-1){
2366 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2367 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2368 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2370 emit_sound_at(swordstaffsound, victim->coords);
2373 emit_sound_at(metalhitsound, victim->coords);
2381 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2382 if(weaponactive!=-1){
2385 weapons[weaponids[0]].owner=-1;
2386 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);
2388 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2389 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2391 weapons[weaponids[0]].velocity=aim*50;
2392 weapons[weaponids[0]].tipvelocity=aim*50;
2393 weapons[weaponids[0]].missed=0;
2394 weapons[weaponids[0]].hitsomething=0;
2395 weapons[weaponids[0]].freetime=0;
2396 weapons[weaponids[0]].firstfree=1;
2397 weapons[weaponids[0]].physics=0;
2400 weaponids[0]=weaponids[num_weapons];
2406 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2408 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2410 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2412 award_bonus(id, Slicebonus);
2413 if(tutoriallevel!=1){
2414 emit_sound_at(knifeslicesound, victim->coords);
2416 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2417 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2418 if(victim->id != 0 || difficulty==2){
2419 victim->targetframe=0;
2420 victim->targetanimation=staggerbackhardanim;
2421 victim->targetrotation=targetrotation+180;
2425 victim->lowreversaldelay=0;
2426 victim->highreversaldelay=0;
2427 if(aitype!=playercontrolled)weaponmissdelay=.6;
2429 if(tutoriallevel!=1)if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2430 if(tutoriallevel!=1)weapons[weaponids[weaponactive]].blooddrip+=3;
2432 XYZ footvel,footpoint;
2435 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2438 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;
2440 if(tutoriallevel!=1){
2441 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2442 footvel=DoRotation(facing,0,90,0)*.8;
2444 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2445 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2446 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2447 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2449 if(tutoriallevel==1){
2450 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2452 victim->DoDamage(damagemult*0);
2455 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2456 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2457 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2458 award_bonus(id, Slashbonus);
2460 if(tutoriallevel!=1){
2461 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2462 else victim->DoBloodBig(2/victim->armorhigh,185);
2463 victim->deathbleeding=1;
2464 emit_sound_at(swordslicesound, victim->coords);
2466 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2467 if(tutoriallevel!=1){
2468 victim->targetframe=0;
2469 victim->targetanimation=staggerbackhardanim;
2470 victim->targetrotation=targetrotation+180;
2474 if(tutoriallevel!=1){
2475 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2476 weapons[weaponids[weaponactive]].blooddrip+=3;
2478 float bloodlossamount;
2479 bloodlossamount=200+abs((float)(Random()%40))-20;
2480 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2481 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2482 victim->DoDamage(damagemult*0);
2484 XYZ footvel,footpoint;
2487 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2490 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;
2492 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2493 footvel=DoRotation(facing,0,90,0)*.8;
2495 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2496 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2497 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2498 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2502 if(victim->weaponactive!=-1){
2503 if(weapons[victim->weaponids[0]].getType()==staff||weapons[weaponids[0]].getType()==staff){
2504 if(weapons[victim->weaponids[0]].getType()==staff)weapons[victim->weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2505 if(weapons[weaponids[0]].getType()==staff)weapons[weaponids[0]].damage+=.2+float(abs(Random()%100)-50)/250;
2507 emit_sound_at(swordstaffsound, victim->coords);
2510 emit_sound_at(metalhitsound, victim->coords);
2516 victim->Puff(righthand);
2518 victim->targetframe=0;
2519 victim->targetanimation=staggerbackhighanim;
2520 victim->targetrotation=targetrotation+180;
2522 weapons[victim->weaponids[0]].owner=-1;
2523 aim=DoRotation(facing,0,90,0)*21;
2525 weapons[victim->weaponids[0]].velocity=aim*-.2;
2526 weapons[victim->weaponids[0]].tipvelocity=aim;
2527 weapons[victim->weaponids[0]].missed=1;
2528 weapons[weaponids[0]].hitsomething=0;
2529 weapons[victim->weaponids[0]].freetime=0;
2530 weapons[victim->weaponids[0]].firstfree=1;
2531 weapons[victim->weaponids[0]].physics=1;
2532 victim->num_weapons--;
2533 if(victim->num_weapons){
2534 victim->weaponids[0]=victim->weaponids[num_weapons];
2535 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2537 victim->weaponactive=-1;
2538 for(i=0;i<numplayers;i++){
2539 player[i].wentforweapon=0;
2546 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2547 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2548 if(tutoriallevel!=1){
2549 weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/250;
2551 if(id==0)camerashake+=.4;
2552 if(Random()%2||creature==wolftype){
2555 emit_sound_at(staffheadsound, victim->coords);
2559 relative=victim->coords-coords;
2561 Normalise(&relative);
2562 relative=DoRotation(relative,0,90,0);
2564 Normalise(&relative);
2565 for(i=0;i<victim->skeleton.num_joints;i++){
2566 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2568 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2569 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2572 if(tutoriallevel!=1){
2573 victim->DoDamage(damagemult*120/victim->protectionhigh);
2575 award_bonus(id, solidhit, 30);
2580 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2581 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2582 if(tutoriallevel!=1){
2583 weapons[weaponids[0]].damage+=.6+float(abs(Random()%100)-50)/250;
2585 if(id==0)camerashake+=.4;
2586 if(Random()%2||creature==wolftype){
2589 emit_sound_at(staffheadsound, victim->coords);
2593 relative=victim->coords-coords;
2595 Normalise(&relative);
2596 relative=DoRotation(relative,0,-90,0);
2597 for(i=0;i<victim->skeleton.num_joints;i++){
2598 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2600 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2601 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2604 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2606 award_bonus(id, solidhit, 60);
2611 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2612 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2614 if(tutoriallevel!=1){
2615 if(!victim->dead)weapons[weaponids[0]].damage+=.4+float(abs(Random()%100)-50)/500;
2616 if(id==0)camerashake+=.4;
2617 if(Random()%2||creature==wolftype){
2620 emit_sound_at(staffbodysound, victim->coords);
2622 victim->skeleton.longdead=0;
2623 victim->skeleton.free=1;
2624 victim->skeleton.broken=0;
2626 for(i=0;i<victim->skeleton.num_joints;i++){
2627 victim->skeleton.joints[i].velchange=0;
2628 victim->skeleton.joints[i].locked=0;
2629 //victim->skeleton.joints[i].velocity=0;
2635 /*relative=victim->coords-coords;
2637 Normalise(&relative);
2638 relative=DoRotation(relative,0,90,0);*/
2640 Normalise(&relative);
2642 for(i=0;i<victim->skeleton.num_joints;i++){
2643 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2646 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2649 for(i=0;i<victim->skeleton.num_joints;i++){
2650 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2653 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2655 victim->Puff(abdomen);
2656 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2659 award_bonus(id, solidhit, 40);
2665 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2666 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2668 if(id==0)camerashake+=.4;
2670 relative=victim->coords-coords;
2672 Normalise(&relative);
2676 if(animation[victim->targetanimation].height==lowheight){
2682 for(i=0;i<victim->skeleton.num_joints;i++){
2683 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2685 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2686 if(tutoriallevel!=1){
2687 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2690 victim->DoDamage(damagemult*100/victim->protectionhead);
2691 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2692 if(creature==wolftype){
2693 emit_sound_at(clawslicesound, victim->coords, 128.);
2695 victim->DoBloodBig(2/victim->armorhead,175);
2699 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2700 for(i=0;i<victim->skeleton.num_joints;i++){
2701 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2703 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2704 victim->targetframe=0;
2705 victim->targetanimation=staggerbackhighanim;
2706 victim->targetrotation=targetrotation+180;
2708 if(tutoriallevel!=1){
2709 emit_sound_at(landsound2, victim->coords, 128.);
2711 victim->Puff(abdomen);
2712 victim->DoDamage(damagemult*30/victim->protectionhigh);
2713 if(creature==wolftype){
2714 emit_sound_at(clawslicesound, victim->coords, 128.);
2716 victim->DoBloodBig(2/victim->armorhigh,170);
2723 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2724 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2726 if(id==0)camerashake+=.2;
2727 if(tutoriallevel!=1){
2728 emit_sound_at(landsound2, victim->coords, 128.);
2731 relative=victim->coords-coords;
2733 Normalise(&relative);
2735 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2738 for(i=0;i<victim->skeleton.num_joints;i++){
2739 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2741 relative=DoRotation(relative,0,-90,0);
2743 for(i=0;i<victim->skeleton.num_joints;i++){
2744 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)
2745 victim->skeleton.joints[i].velocity=relative*80;
2747 victim->Puff(rightankle);
2748 victim->Puff(leftankle);
2749 victim->DoDamage(damagemult*40/victim->protectionlow);
2752 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2753 for(i=0;i<victim->skeleton.num_joints;i++){
2754 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2756 relative=DoRotation(relative,0,-90,0);
2757 for(i=0;i<victim->skeleton.num_joints;i++){
2758 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)
2759 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2761 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2762 victim->targetframe=0;
2763 victim->targetanimation=staggerbackhighanim;
2764 victim->targetrotation=targetrotation+180;
2766 if(tutoriallevel!=1){
2767 emit_sound_at(landsound2, victim->coords, 128.);
2769 victim->Puff(abdomen);
2770 victim->DoDamage(damagemult*30/victim->protectionlow);
2778 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2779 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2781 if(id==0)camerashake+=.4;
2786 if(tutoriallevel!=1){
2787 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2789 if(creature==wolftype){
2790 emit_sound_at(clawslicesound, victim->coords, 128);
2792 victim->DoBloodBig(2/victim->armorhigh,170);
2796 relative=victim->coords-oldcoords;
2798 Normalise(&relative);
2799 //relative=DoRotation(relative,0,-90,0);
2800 for(i=0;i<victim->skeleton.num_joints;i++){
2801 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2803 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2805 victim->Puff(abdomen);
2806 victim->DoDamage(damagemult*150/victim->protectionhigh);
2808 award_bonus(id, Reversal);
2811 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2812 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2813 if(weapons[victim->weaponids[victim->weaponactive]].owner==victim->id){
2814 weapons[victim->weaponids[victim->weaponactive]].owner=id;
2817 weaponids[num_weapons]=weaponids[victim->weaponactive];
2820 weaponids[0]=victim->weaponids[victim->weaponactive];
2821 victim->num_weapons--;
2822 if(victim->num_weapons>0){
2823 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2824 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2826 victim->weaponactive=-1;
2831 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2833 if(id==0)camerashake+=.4;
2838 emit_sound_at(whooshhitsound, victim->coords, 128.);
2841 relative=victim->coords-oldcoords;
2843 Normalise(&relative);
2844 //relative=DoRotation(relative,0,-90,0);
2845 for(i=0;i<victim->skeleton.num_joints;i++){
2846 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2848 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2851 victim->DoDamage(damagemult*70/victim->protectionhigh);
2854 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2856 if(id==0)camerashake+=.4;
2862 award_bonus(id, staffreversebonus);
2864 if(tutoriallevel!=1){
2865 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2868 award_bonus(id, staffreversebonus); // Huh, again?
2871 relative=victim->coords-oldcoords;
2873 Normalise(&relative);
2874 //relative=DoRotation(relative,0,-90,0);
2875 for(i=0;i<victim->skeleton.num_joints;i++){
2876 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2878 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2881 victim->DoDamage(damagemult*70/victim->protectionhigh);
2884 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
2890 Normalise(&relative);
2893 for(i=0;i<victim->skeleton.num_joints;i++){
2894 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2896 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
2897 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
2898 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
2899 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
2900 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
2901 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
2902 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
2903 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
2905 victim->Puff(abdomen);
2906 victim->DoDamage(damagemult*90/victim->protectionhigh);
2908 award_bonus(id, Reversal);
2912 if(weaponactive!=-1||creature==wolftype)doslice=1;
2913 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
2915 if(weaponactive!=-1){
2916 victim->DoBloodBig(2/victim->armorhigh,225);
2917 emit_sound_at(knifeslicesound, victim->coords);
2918 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
2919 weapons[weaponids[weaponactive]].blooddrip+=3;
2921 if(weaponactive==-1&&creature==wolftype){;
2922 emit_sound_at(clawslicesound, victim->coords, 128.);
2924 victim->DoBloodBig(2/victim->armorhigh,175);
2931 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2937 Normalise(&relative);
2940 for(i=0;i<victim->skeleton.num_joints;i++){
2941 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
2943 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
2944 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
2945 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
2946 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
2947 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
2948 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
2949 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
2950 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
2952 award_bonus(id, swordreversebonus);
2955 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
2957 if(id==0)camerashake+=.4;
2962 if(tutoriallevel!=1){
2963 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2967 relative=victim->coords-oldcoords;
2969 Normalise(&relative);
2970 relative=DoRotation(relative,0,-90,0);
2971 for(i=0;i<victim->skeleton.num_joints;i++){
2972 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2974 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2976 victim->Puff(abdomen);
2977 victim->DoDamage(damagemult*30/victim->protectionhigh);
2979 award_bonus(id, Reversal);
2982 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
2985 victim->skeleton.spinny=0;
2989 Normalise(&relative);
2990 if(victim->id==0)relative/=30;
2991 for(i=0;i<victim->skeleton.num_joints;i++){
2992 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2994 //victim->DoDamage(1000);
2995 victim->damage=victim->damagetolerance;
2996 victim->permanentdamage=victim->damagetolerance-1;
2999 if(weaponactive!=-1||creature==wolftype)doslice=1;
3000 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3002 if(weaponactive!=-1){
3003 victim->DoBloodBig(200,225);
3004 emit_sound_at(knifeslicesound, victim->coords);
3005 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3006 weapons[weaponids[weaponactive]].blooddrip+=5;
3009 if(creature==wolftype&&weaponactive==-1){
3010 emit_sound_at(clawslicesound, victim->coords, 128.);
3012 victim->DoBloodBig(2,175);
3015 award_bonus(id, spinecrusher);
3018 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3019 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3021 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3022 if(targetanimation==knifesneakattackanim){
3023 /*victim->DoBloodBig(200,195);
3028 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3029 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3031 XYZ footvel,footpoint;
3033 footpoint=weapons[weaponids[0]].tippoint;
3034 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3035 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3036 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3037 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3038 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3039 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3040 victim->DoBloodBig(200,195);
3041 award_bonus(id, tracheotomy);
3043 if(targetanimation==knifefollowanim){
3044 award_bonus(id, Stabbonus);
3045 XYZ footvel,footpoint;
3047 footpoint=weapons[weaponids[0]].tippoint;
3048 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3049 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3050 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3051 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3052 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3053 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3056 victim->bloodloss+=10000;
3058 emit_sound_at(fleshstabsound, victim->coords);
3059 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3060 weapons[weaponids[weaponactive]].blooddrip+=5;
3064 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3067 for(i=0;i<victim->skeleton.num_joints;i++){
3068 victim->skeleton.joints[i].velocity=0;
3070 if(targetanimation==knifefollowanim){
3072 for(i=0;i<victim->skeleton.num_joints;i++){
3073 victim->skeleton.joints[i].velocity=0;
3076 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3077 emit_sound_at(fleshstabremovesound, victim->coords);
3078 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3079 weapons[weaponids[weaponactive]].blooddrip+=5;
3081 XYZ footvel,footpoint;
3083 footpoint=weapons[weaponids[0]].tippoint;
3084 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3085 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3086 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3087 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3088 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3089 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3093 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3094 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3095 award_bonus(id, backstab);
3099 XYZ footvel,footpoint;
3101 footpoint=(weapons[weaponids[0]].tippoint+weapons[weaponids[0]].position)/2;
3102 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3103 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position);
3104 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3105 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3106 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3107 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3108 victim->DoBloodBig(200,180);
3109 victim->DoBloodBig(200,215);
3110 victim->bloodloss+=10000;
3112 emit_sound_at(fleshstabsound, victim->coords);
3113 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3114 weapons[weaponids[weaponactive]].blooddrip+=5;
3118 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3121 for(i=0;i<victim->skeleton.num_joints;i++){
3122 victim->skeleton.joints[i].velocity=0;
3124 if(weaponactive!=-1){
3125 emit_sound_at(fleshstabremovesound, victim->coords);
3126 if(bloodtoggle)weapons[weaponids[weaponactive]].bloody=2;
3127 weapons[weaponids[weaponactive]].blooddrip+=5;
3129 XYZ footvel,footpoint;
3131 footpoint=weapons[weaponids[0]].tippoint;
3132 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3133 footvel=(weapons[weaponids[0]].tippoint-weapons[weaponids[0]].position)*-1;
3134 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3135 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3136 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3137 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3141 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3143 if(id==0)camerashake+=.4;
3148 if(weaponactive==-1){
3149 if(tutoriallevel!=1){
3150 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3155 if(weaponactive!=-1||creature==wolftype)doslice=1;
3156 if(creature==rabbittype&&weaponactive!=-1)if(weapons[weaponids[0]].getType()==staff)doslice=0;
3158 if(weaponactive!=-1){
3159 victim->DoBloodBig(2/victim->armorhead,225);
3160 emit_sound_at(knifeslicesound, victim->coords);
3161 if(bloodtoggle&&!weapons[weaponids[weaponactive]].bloody)weapons[weaponids[weaponactive]].bloody=1;
3162 weapons[weaponids[weaponactive]].blooddrip+=3;
3164 if(weaponactive==-1&&creature==wolftype){
3165 emit_sound_at(clawslicesound, victim->coords, 128.);
3167 victim->DoBloodBig(2/victim->armorhead,175);
3171 award_bonus(id, Reversal);
3176 //relative=victim->coords-oldcoords;
3179 Normalise(&relative);
3180 relative=DoRotation(relative,0,90,0);
3182 Normalise(&relative);
3183 for(i=0;i<victim->skeleton.num_joints;i++){
3184 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3186 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3187 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3188 victim->DoDamage(damagemult*100/victim->protectionhead);
3192 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3196 //relative=victim->coords-oldcoords;
3199 Normalise(&relative);
3200 relative=DoRotation(relative,0,90,0);
3202 Normalise(&relative);
3203 for(i=0;i<victim->skeleton.num_joints;i++){
3204 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3206 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3209 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3210 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3211 award_bonus(id, reverseko);
3217 if(targetframe>animation[currentanimation].numframes-1){
3220 targetanimation=getIdle();
3224 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3225 targetanimation=rollanim;
3227 emit_sound_at(movewhooshsound, coords, 128.);
3229 if(currentanimation==staggerbackhighanim){
3230 targetanimation=getIdle();
3232 if(currentanimation==staggerbackhardanim){
3233 targetanimation=getIdle();
3235 if(currentanimation==removeknifeanim){
3236 targetanimation=getIdle();
3238 if(currentanimation==crouchremoveknifeanim){
3239 targetanimation=getCrouch();
3241 if(currentanimation==backhandspringanim){
3242 targetanimation=getIdle();
3244 if(currentanimation==dodgebackanim){
3245 targetanimation=getIdle();
3247 if(currentanimation==drawleftanim){
3248 targetanimation=getIdle();
3250 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3251 targetanimation=getIdle();
3252 if(currentanimation==crouchdrawrightanim){
3253 targetanimation=getCrouch();
3255 if(weaponactive==-1)weaponactive=0;
3256 else if(weaponactive==0){
3260 buffer=weaponids[0];
3261 weaponids[0]=weaponids[1];
3262 weaponids[1]=buffer;
3266 if(weaponactive==-1){
3267 emit_sound_at(knifesheathesound, coords, 128.);
3269 if(weaponactive!=-1){
3270 emit_sound_at(knifedrawsound, coords, 128.);
3273 if(currentanimation==rollanim){
3274 targetanimation=getCrouch();
3279 if(targetanimation==walljumprightkickanim){
3282 if(targetanimation==walljumpleftkickanim){
3285 targetanimation=jumpdownanim;
3287 if(currentanimation==climbanim){
3288 targetanimation=getCrouch();
3291 if(!isnormal(coords.x))
3302 if(targetanimation==rabbitkickreversalanim){
3303 targetanimation=getCrouch();
3306 if(targetanimation==jumpreversalanim){
3307 targetanimation=getCrouch();
3310 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3311 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3313 float closestdist=-1;
3316 for(i=0;i<numplayers;i++){
3317 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3318 distance=findDistancefast(&player[i].coords,&coords);
3319 if(closestdist==-1||distance<closestdist){
3320 closestdist=distance;
3325 if(closestdist>0&&closest>=0&&closestdist<16){
3326 victim=&player[closest];
3327 targetanimation=walljumprightkickanim;
3329 XYZ rotatetarget=victim->coords-coords;
3330 Normalise(&rotatetarget);
3331 rotation=-asin(0-rotatetarget.x);
3333 if(rotatetarget.z<0)rotation=180-rotation;
3334 targettilt2=-asin(rotatetarget.y)*360/6.28;
3335 velocity=(victim->coords-coords)*4;
3340 if(targetanimation==walljumpbackanim){
3341 targetanimation=backflipanim;
3346 resume_stream(whooshsound);
3348 if(targetanimation==walljumprightanim){
3349 targetanimation=rightflipanim;
3353 velocity=DoRotation(facing,0,30,0)*-8;
3356 if(targetanimation==walljumpfrontanim){
3357 targetanimation=frontflipanim;
3359 //targetrotation-=180;
3365 resume_stream(whooshsound);
3367 if(targetanimation==walljumpleftanim){
3370 float closestdist=-1;
3373 for(i=0;i<numplayers;i++){
3374 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3375 distance=findDistancefast(&player[i].coords,&coords);
3376 if(closestdist==-1||distance<closestdist){
3377 closestdist=distance;
3382 if(closestdist>0&&closest>=0&&closestdist<16){
3383 victim=&player[closest];
3384 targetanimation=walljumpleftkickanim;
3386 XYZ rotatetarget=victim->coords-coords;
3387 Normalise(&rotatetarget);
3388 rotation=-asin(0-rotatetarget.x);
3390 if(rotatetarget.z<0)rotation=180-rotation;
3391 targettilt2=-asin(rotatetarget.y)*360/6.28;
3392 velocity=(victim->coords-coords)*4;
3397 if(targetanimation!=walljumpleftkickanim){
3398 targetanimation=leftflipanim;
3402 velocity=DoRotation(facing,0,-30,0)*-8;
3406 resume_stream(whooshsound);
3408 if(targetanimation==sneakattackanim){
3409 currentanimation=getCrouch();
3410 targetanimation=getCrouch();
3413 targetrotation+=180;
3418 targetheadrotation+=180;
3420 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3424 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3425 targetanimation=getIdle();
3427 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3431 if(currentanimation==knifefollowanim){
3432 targetanimation=getIdle();
3435 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3436 float ycoords=oldcoords.y;
3437 targetanimation=getStop();
3438 targetrotation+=180;
3443 targetheadrotation+=180;
3444 if(!isnormal(coords.x))
3446 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3447 oldcoords=coords+facing*.5;
3448 else if(currentanimation==sweepreversalanim)
3449 oldcoords=coords+facing*1.1;
3450 else if(currentanimation==upunchreversalanim){
3451 oldcoords=coords+facing*1.5;
3452 targetrotation+=180;
3454 targetheadrotation+=180;
3458 else if(currentanimation==knifeslashreversalanim){
3459 oldcoords=coords+facing*.5;
3462 targetheadrotation+=90;
3466 else if(currentanimation==staffspinhitreversalanim){
3467 targetrotation+=180;
3469 targetheadrotation+=180;
3473 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3474 else oldcoords.y=ycoords;
3475 currentoffset=coords-oldcoords;
3481 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3486 if(animation[targetanimation].attack==reversed){
3488 if(targetanimation==sweepreversedanim)targetrotation+=90;
3489 targetanimation=backhandspringanim;
3491 emit_sound_at(landsound, coords, 128);
3493 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3494 targetanimation=rollanim;
3497 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3498 coords.y=oldcoords.y;
3500 if(currentanimation==knifeslashreversedanim){
3501 targetanimation=rollanim;
3506 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3507 coords.y=oldcoords.y;
3511 targetanimation=jumpdownanim;
3513 if(wasLanding())targetanimation=getIdle();
3514 if(wasLandhard())targetanimation=getIdle();
3515 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3516 targetanimation=getIdle();
3518 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3519 coords.y=oldcoords.y;
3520 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3521 targetoffset.y=coords.y;
3522 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3523 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3524 currentoffset.y-=(coords.y-targetoffset.y);
3525 coords.y=targetoffset.y;
3527 normalsupdatedelay=0;
3529 if(currentanimation==upunchanim){
3530 targetanimation=getStop();
3531 normalsupdatedelay=0;
3534 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3535 targetrotation=rotation;
3538 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
3539 if(!hasstaff)DoDamage(35);
3542 rabbitkickragdoll=1;
3544 if(currentanimation==rabbitkickreversedanim){
3551 SolidHitBonus(!id); // FIXME: tricky id
3555 targetanimation=rollanim;
3557 if(id==0)pause_sound(whooshsound);
3561 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3567 if(currentanimation==jumpreversedanim){
3574 SolidHitBonus(!id); // FIXME: tricky id
3578 targetanimation=rollanim;
3580 if(id==0)pause_sound(whooshsound);
3585 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){
3586 targetanimation=getupfromfrontanim;
3589 else if(animation[currentanimation].attack==normalattack){
3590 targetanimation=getIdle();
3593 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3594 targetanimation=blockhighleftstrikeanim;
3596 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3597 targetanimation=getIdle();
3600 if(currentanimation==spinkickanim&&victim->skeleton.free){
3601 if(creature==rabbittype)targetanimation=fightidleanim;
3606 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3608 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3609 targetanimation=jumpdownanim;
3614 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3615 if(!isRun()||!wasRun()){
3616 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3617 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3618 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3619 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3621 if(isRun()&&wasRun()){
3624 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3625 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3628 else if(transspeed)target+=multiplier*transspeed*speed*2;
3630 if(!isRun()||!wasRun()){
3631 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3632 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3633 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3634 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3638 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3640 if(target>1){currentframe=targetframe; target=1;}
3642 rot=targetrot*target;
3643 rotation+=rot-oldrot;
3649 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3651 for(i=0;i<skeleton.num_joints;i++){
3652 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3655 skeleton.FindForwards();
3657 for(i=0;i<skeleton.num_muscles;i++){
3658 if(skeleton.muscles[i].visible)
3660 skeleton.FindRotationMuscle(i,targetanimation);
3663 for(i=0;i<skeleton.num_muscles;i++){
3664 if(skeleton.muscles[i].visible)
3666 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3667 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3668 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3673 for(i=0;i<skeleton.num_joints;i++){
3674 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3677 skeleton.FindForwards();
3679 for(i=0;i<skeleton.num_muscles;i++){
3680 if(skeleton.muscles[i].visible)
3682 skeleton.FindRotationMuscle(i,targetanimation);
3685 for(i=0;i<skeleton.num_muscles;i++){
3686 if(skeleton.muscles[i].visible)
3688 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3689 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3690 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3691 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3692 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3693 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3694 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3695 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3696 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3700 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3702 oldcurrentanimation=currentanimation;
3703 oldtargetanimation=targetanimation;
3704 oldtargetframe=targetframe;
3705 oldcurrentframe=currentframe;
3707 for(i=0;i<skeleton.num_joints;i++){
3708 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3709 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3711 offset=currentoffset*(1-target)+targetoffset*target;
3712 for(i=0;i<skeleton.num_muscles;i++){
3713 if(skeleton.muscles[i].visible)
3715 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3716 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3717 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3722 if(isLanding()&&landhard){
3723 if(id==0)camerashake+=.4;
3724 targetanimation=getLandhard();
3731 //skeleton.DoConstraints();
3734 void Person::DoStuff(){
3735 static XYZ terrainnormal;
3736 static XYZ flatfacing;
3737 static XYZ flatvelocity;
3738 static float flatvelspeed;
3742 static int bloodsize;
3743 static int startx,starty,endx,endy;
3744 static GLubyte color;
3745 static XYZ bloodvel;
3747 onfiredelay-=multiplier;
3748 if(onfiredelay<0&&onfire)
3756 crouchkeydowntime+=multiplier;
3757 if(!crouchkeydown)crouchkeydowntime=0;
3758 jumpkeydowntime+=multiplier;
3759 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3761 if(hostile||damage>0||bloodloss>0)immobile=0;
3763 if(isIdle()||isRun())targetoffset=0;
3765 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3767 if(id==0)blooddimamount-=multiplier*.3;
3768 speechdelay-=multiplier;
3769 texupdatedelay-=multiplier;
3770 interestdelay-=multiplier;
3771 flamedelay-=multiplier;
3772 parriedrecently-=multiplier;
3778 if(id==0)speed=1.1*speedmult;
3779 else speed=1.0*speedmult;
3780 if(!skeleton.free)rabbitkickragdoll=0;
3784 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3785 if(id!=0&&creature==wolftype&&difficulty==2){
3787 if(aitype!=passivetype){
3789 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){
3793 if(scale<0.2)superruntoggle=0;
3794 if(targetanimation==wolfrunninganim&&!superruntoggle){
3795 targetanimation=getRun();
3799 if(weaponactive==-1&&num_weapons>0){
3800 if(weapons[weaponids[0]].getType()==staff){
3807 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3808 /*if(aitype!=playercontrolled)*/
3810 if(burnt>.6)burnt=.6;
3811 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3813 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3824 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3825 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3829 while(flamedelay<0&&onfire){
3831 howmany=abs(Random()%(skeleton.num_joints));
3832 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3833 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3834 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3835 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3836 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3839 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3841 howmany=abs(Random()%(skeleton.num_joints));
3842 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3843 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3844 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3845 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3846 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3850 bleeding-=multiplier*.3;
3852 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3853 if(bleeding<=0&&(detail!=2||osx))DoMipmaps();
3857 if(neckspurtamount>0){
3858 neckspurtamount-=multiplier;
3859 neckspurtdelay-=multiplier*3;
3860 neckspurtparticledelay-=multiplier*3;
3861 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3865 bloodvel.z=5*neckspurtamount;
3866 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3869 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3871 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3872 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3873 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);
3874 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);
3875 neckspurtparticledelay=.05;
3877 if(neckspurtdelay<0){
3882 if(deathbleeding>0&&dead!=2){
3883 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
3884 else bleeddelay-=5*multiplier/4;
3885 if(bleeddelay<0&&bloodtoggle){
3890 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3891 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
3892 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
3893 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);
3896 bloodloss+=deathbleeding*multiplier*80;
3897 deathbleeding-=multiplier*1.6;
3898 //if(id==0)deathbleeding-=multiplier*.2;
3899 if(deathbleeding<0)deathbleeding=0;
3900 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
3901 if(weaponactive!=-1){
3902 weapons[weaponids[0]].owner=-1;
3903 weapons[weaponids[0]].velocity=velocity*scale*-.3;
3904 weapons[weaponids[0]].velocity.x+=.01;
3905 weapons[weaponids[0]].tipvelocity=velocity*scale;
3906 weapons[weaponids[0]].missed=1;
3907 weapons[weaponids[0]].hitsomething=0;
3908 weapons[weaponids[0]].freetime=0;
3909 weapons[weaponids[0]].firstfree=1;
3910 weapons[weaponids[0]].physics=1;
3913 weaponids[0]=weaponids[num_weapons];
3914 if(weaponstuck==num_weapons)weaponstuck=0;
3917 for(i=0;i<numplayers;i++){
3918 player[i].wentforweapon=0;
3930 if(!dead&&creature==wolftype){
3931 award_bonus(0, Wolfbonus);
3934 if(targetanimation==knifefollowedanim&&!skeleton.free){
3935 for(i=0;i<skeleton.num_joints;i++){
3936 skeleton.joints[i].velocity=0;
3937 skeleton.joints[i].velocity.y=-2;
3940 if(id!=0&&unconscioustime>.1){
3948 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
3951 bloodsize=5-realtexdetail;
3955 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3956 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
3957 endx=startx+bloodsize;
3958 endy=starty+bloodsize;
3960 if(startx<0){startx=0;bleeding=0;}
3961 if(starty<0){starty=0;bleeding=0;}
3962 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
3963 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
3964 if(endx<startx)endx=startx;
3965 if(endy<starty)endy=starty;
3967 for(i=startx;i<endx;i++){
3968 for(j=starty;j<endy;j++){
3970 color=Random()%85+170;
3971 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
3972 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
3973 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
3978 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3983 bleedy-=4/realtexdetail;
3984 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
3985 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
3988 bleedx+=4*direction/realtexdetail;
3989 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
3990 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
3994 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
3995 righthandmorphness=targetrighthandmorphness;
3996 righthandmorphstart=righthandmorphend;
3998 else if(righthandmorphness>targetrighthandmorphness){
3999 righthandmorphness-=multiplier*4;
4001 else if(righthandmorphness<targetrighthandmorphness){
4002 righthandmorphness+=multiplier*4;
4005 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4006 lefthandmorphness=targetlefthandmorphness;
4007 lefthandmorphstart=lefthandmorphend;
4009 else if(lefthandmorphness>targetlefthandmorphness){
4010 lefthandmorphness-=multiplier*4;
4012 else if(lefthandmorphness<targetlefthandmorphness){
4013 lefthandmorphness+=multiplier*4;
4016 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4017 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4018 tailmorphness=targettailmorphness;
4019 tailmorphstart=tailmorphend;
4021 else if(tailmorphness>targettailmorphness){
4022 tailmorphness-=multiplier*10;
4024 else if(tailmorphness<targettailmorphness){
4025 tailmorphness+=multiplier*10;
4029 if(creature==wolftype){
4030 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4031 tailmorphness=targettailmorphness;
4032 tailmorphstart=tailmorphend;
4034 else if(tailmorphness>targettailmorphness){
4035 tailmorphness-=multiplier*2;
4037 else if(tailmorphness<targettailmorphness){
4038 tailmorphness+=multiplier*2;
4042 if(headmorphend==3||headmorphstart==3){
4043 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4044 headmorphness=targetheadmorphness;
4045 headmorphstart=headmorphend;
4047 else if(headmorphness>targetheadmorphness){
4048 headmorphness-=multiplier*7;
4050 else if(headmorphness<targetheadmorphness){
4051 headmorphness+=multiplier*7;
4054 else if(headmorphend==5||headmorphstart==5){
4055 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4056 headmorphness=targetheadmorphness;
4057 headmorphstart=headmorphend;
4059 else if(headmorphness>targetheadmorphness){
4060 headmorphness-=multiplier*10;
4062 else if(headmorphness<targetheadmorphness){
4063 headmorphness+=multiplier*10;
4067 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4068 headmorphness=targetheadmorphness;
4069 headmorphstart=headmorphend;
4071 else if(headmorphness>targetheadmorphness){
4072 headmorphness-=multiplier*4;
4074 else if(headmorphness<targetheadmorphness){
4075 headmorphness+=multiplier*4;
4079 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4080 chestmorphness=targetchestmorphness;
4081 chestmorphstart=chestmorphend;
4083 else if(chestmorphness>targetchestmorphness){
4084 chestmorphness-=multiplier;
4086 else if(chestmorphness<targetchestmorphness){
4087 chestmorphness+=multiplier;
4090 if(dead!=2&&howactive<=typesleeping){
4091 if(chestmorphstart==0&&chestmorphend==0){
4093 targetchestmorphness=1;
4096 if(chestmorphstart!=0&&chestmorphend!=0){
4098 targetchestmorphness=1;
4100 if(environment==snowyenvironment){
4103 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4104 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4105 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4106 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4107 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4108 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4112 if(!dead&&howactive<typesleeping){
4113 blinkdelay-=multiplier*2;
4114 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4116 targetheadmorphness=1;
4118 blinkdelay=(float)(abs(Random()%40))/5;
4120 if(headmorphstart==3&&headmorphend==3){
4122 targetheadmorphness=1;
4127 twitchdelay-=multiplier*1.5;
4128 if(targetanimation!=hurtidleanim){
4129 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4131 targetheadmorphness=1;
4133 twitchdelay=(float)(abs(Random()%40))/5;
4135 if(headmorphstart==5&&headmorphend==5){
4137 targetheadmorphness=1;
4141 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4142 twitchdelay3-=multiplier*1;
4144 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4145 righthandmorphness=0;
4146 targetrighthandmorphness=1;
4147 righthandmorphend=1;
4148 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4150 if(righthandmorphstart==1&&righthandmorphend==1){
4151 righthandmorphness=0;
4152 targetrighthandmorphness=1;
4153 righthandmorphend=0;
4157 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4158 lefthandmorphness=0;
4159 targetlefthandmorphness=1;
4161 twitchdelay3=(float)(abs(Random()%40))/5;
4163 if(lefthandmorphstart==1&&lefthandmorphend==1){
4164 lefthandmorphness=0;
4165 targetlefthandmorphness=1;
4172 if(creature==rabbittype){
4173 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4174 else twitchdelay2-=multiplier*0.5;
4175 if(howactive<=typesleeping){
4176 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4178 targettailmorphness=1;
4180 twitchdelay2=(float)(abs(Random()%40))/5;
4182 if(tailmorphstart==1&&tailmorphend==1){
4184 targettailmorphness=1;
4187 if(tailmorphstart==2&&tailmorphend==2){
4189 targettailmorphness=1;
4196 if(creature==wolftype){
4197 twitchdelay2-=multiplier*1.5;
4199 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4201 targettailmorphness=1;
4206 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4208 targettailmorphness=1;
4212 if(twitchdelay2<=0){
4213 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4215 targettailmorphness=1;
4218 if(tailmorphstart==1&&tailmorphend==1){
4220 targettailmorphness=1;
4223 if(tailmorphstart==2&&tailmorphend==2){
4225 targettailmorphness=1;
4228 if(tailmorphstart==3&&tailmorphend==3){
4230 targettailmorphness=1;
4233 if(tailmorphstart==4&&tailmorphend==4){
4235 targettailmorphness=1;
4241 if(dead!=1)unconscioustime=0;
4243 if(dead==1||howactive==typesleeping){
4244 unconscioustime+=multiplier;
4245 //If unconscious, close eyes and mouth
4246 if(righthandmorphend!=0)righthandmorphness=0;
4247 righthandmorphend=0;
4248 targetrighthandmorphness=1;
4250 if(lefthandmorphend!=0)lefthandmorphness=0;
4252 targetlefthandmorphness=1;
4254 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4256 targetheadmorphness=1;
4260 if(howactive>typesleeping){
4263 if(bloodtoggle&&!bled){
4264 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4266 if(bloodtoggle&&!bled)
4267 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4268 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4269 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4273 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4278 if(dead==2||howactive>typesleeping){
4279 //If dead, open mouth and hands
4280 if(righthandmorphend!=0)righthandmorphness=0;
4281 righthandmorphend=0;
4282 targetrighthandmorphness=1;
4284 if(lefthandmorphend!=0)lefthandmorphness=0;
4286 targetlefthandmorphness=1;
4288 if(headmorphend!=2)headmorphness=0;
4290 targetheadmorphness=1;
4293 if(stunned>0&&!dead&&headmorphend!=2){
4294 if(headmorphend!=4)headmorphness=0;
4296 targetheadmorphness=1;
4299 if(damage>damagetolerance&&!dead){
4304 if(creature==wolftype){
4305 award_bonus(0, Wolfbonus);
4310 if(weaponactive!=-1){
4311 weapons[weaponids[0]].owner=-1;
4312 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4313 weapons[weaponids[0]].velocity.x+=.01;
4314 weapons[weaponids[0]].tipvelocity=velocity*scale;
4315 weapons[weaponids[0]].missed=1;
4316 weapons[weaponids[0]].hitsomething=0;
4317 weapons[weaponids[0]].freetime=0;
4318 weapons[weaponids[0]].firstfree=1;
4319 weapons[weaponids[0]].physics=1;
4322 weaponids[0]=weaponids[num_weapons];
4323 if(weaponstuck==num_weapons)weaponstuck=0;
4326 for(i=0;i<numplayers;i++){
4327 player[i].wentforweapon=0;
4333 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4341 //if(dead)damage-=multiplier/4;
4342 if(!dead)damage-=multiplier*13;
4343 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4344 if(!dead)permanentdamage-=multiplier*4;
4345 if(isIdle()||isCrouch()){
4346 if(!dead)permanentdamage-=multiplier*4;
4347 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4349 if(damage<0)damage=0;
4350 if(permanentdamage<0)permanentdamage=0;
4351 if(superpermanentdamage<0)superpermanentdamage=0;
4352 if(permanentdamage<superpermanentdamage){
4353 permanentdamage=superpermanentdamage;
4355 if(damage<permanentdamage){
4356 damage=permanentdamage;
4358 if(dead==1&&damage<damagetolerance){
4362 for(i=0;i<skeleton.num_joints;i++){
4363 skeleton.joints[i].velocity=0;
4366 if(permanentdamage>damagetolerance&&dead!=2){
4369 if(weaponactive!=-1){
4370 weapons[weaponids[0]].owner=-1;
4371 weapons[weaponids[0]].velocity=velocity*scale*-.3;
4372 weapons[weaponids[0]].velocity.x+=.01;
4373 weapons[weaponids[0]].tipvelocity=velocity*scale;
4374 weapons[weaponids[0]].missed=1;
4375 weapons[weaponids[0]].hitsomething=0;
4376 weapons[weaponids[0]].freetime=0;
4377 weapons[weaponids[0]].firstfree=1;
4378 weapons[weaponids[0]].physics=1;
4381 weaponids[0]=weaponids[num_weapons];
4382 if(weaponstuck==num_weapons)weaponstuck=0;
4385 for(i=0;i<numplayers;i++){
4386 player[i].wentforweapon=0;
4392 if(!dead&&creature==wolftype){
4393 award_bonus(0, Wolfbonus);
4396 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4397 award_bonus(id, touchofdeath);
4398 if(id!=0&&unconscioustime>.1){
4406 emit_sound_at(breaksound, coords);
4409 if(skeleton.free==1){
4410 if(id==0)pause_sound(whooshsound);
4413 //If knocked over, open hands and close mouth
4414 if(righthandmorphend!=0)righthandmorphness=0;
4415 righthandmorphend=0;
4416 targetrighthandmorphness=1;
4418 if(lefthandmorphend!=0)lefthandmorphness=0;
4420 targetlefthandmorphness=1;
4422 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4423 if(headmorphend!=0)headmorphness=0;
4425 targetheadmorphness=1;
4429 skeleton.DoGravity(&scale);
4431 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4432 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4433 award_bonus(id, deepimpact);
4434 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4438 for(j=0;j<skeleton.num_joints;j++){
4439 average+=skeleton.joints[j].position;
4443 coords+=average*scale;
4444 for(j=0;j<skeleton.num_joints;j++){
4445 skeleton.joints[j].position-=average;
4447 average/=multiplier;
4449 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4451 for(i=0;i<skeleton.num_joints;i++){
4452 velocity+=skeleton.joints[i].velocity*scale;
4454 velocity/=skeleton.num_joints;
4456 if(!isnormal(velocity.x)&&velocity.x){
4460 if(findLength(&average)<10&&dead&&skeleton.free){
4461 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4462 if(skeleton.longdead>2000){
4463 if(skeleton.longdead>6000){
4464 if(id==0)pause_sound(whooshsound);
4469 if(dead==2&&bloodloss<damagetolerance){
4471 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4473 if(bloodtoggle&&!bled){
4474 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4476 if(bloodtoggle&&!bled)
4477 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4478 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4479 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4483 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4487 if(dead==2&&bloodloss>=damagetolerance){
4489 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4490 if(bleeding<=0)DoBlood(1,255);
4491 if(bloodtoggle&&!bled){
4492 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4494 if(bloodtoggle&&!bled)
4495 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4496 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4497 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4501 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4508 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4510 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4514 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4515 if(velocity.y<-30)canrecover=0;
4516 for(i=0;i<objects.numobjects;i++){
4517 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4518 colviewer=startpoint;
4520 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4528 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4529 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4530 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4531 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4533 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4534 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4535 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4537 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4538 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4539 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4541 Normalise(&terrainnormal);
4543 targetrotation=-asin(0-terrainnormal.x);
4544 targetrotation*=360/6.28;
4545 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4546 rotation=targetrotation;
4550 targetanimation=flipanim;
4551 crouchtogglekeydown=1;
4556 currentanimation=tempanim;
4559 //tilt2=targettilt2;
4561 //if(middle.y>0)targetoffset.y=middle.y+1;
4563 for(i=0;i<skeleton.num_joints;i++){
4564 tempanimation.position[i][0]=skeleton.joints[i].position;
4565 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4570 if(findLength(&average)<10&&!dead&&skeleton.free){
4571 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4572 if(skeleton.longdead>(damage+500)*1.5){
4573 if(id==0)pause_sound(whooshsound);
4579 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4580 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4581 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4582 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4584 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4585 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4586 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4588 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4589 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4590 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4592 Normalise(&terrainnormal);
4594 targetrotation=-asin(0-terrainnormal.x);
4595 targetrotation*=360/6.28;
4596 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4597 rotation=targetrotation;
4599 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4602 if(skeleton.forward.y<0){
4603 targetanimation=getupfrombackanim;
4607 if(skeleton.forward.y>-.3){
4608 targetanimation=getupfromfrontanim;
4610 targetrotation+=180;
4616 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4617 targetanimation=rollanim;
4618 targetrotation=lookrotation;
4622 if(forwardkeydown)targetrotation+=45;
4623 if(backkeydown)targetrotation-=45;
4627 if(forwardkeydown)targetrotation-=45;
4628 if(backkeydown)targetrotation+=45;
4631 if ( !leftkeydown&&!rightkeydown)
4632 targetrotation+=180;
4634 targetrotation+=180;
4638 if(abs(targettilt2)>50)targettilt2=0;
4639 currentanimation=tempanim;
4644 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4646 for(i=0;i<skeleton.num_joints;i++){
4647 tempanimation.position[i][0]=skeleton.joints[i].position;
4648 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4655 if(num_weapons>0)if(weapons[0].getType()==staff)hasstaff=1;
4656 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4659 tempvelocity=velocity;
4660 Normalise(&tempvelocity);
4661 targetrotation=-asin(0-tempvelocity.x);
4662 targetrotation*=360/6.28;
4663 if(velocity.z<0)targetrotation=180-targetrotation;
4664 //targetrotation+=180;
4667 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4668 targetanimation=rollanim;
4672 targetanimation=backhandspringanim;
4673 targetrotation+=180;
4678 emit_sound_at(movewhooshsound, coords, 128.);
4680 currentanimation=targetanimation;
4681 currentframe=targetframe-1;
4686 rotation=targetrotation;
4693 if(skeleton.freefall==0)freefall=0;
4697 if(aitype!=passivetype||skeleton.free==1)
4698 if(findLengthfast(&velocity)>.1)
4699 for(i=0;i<objects.numobjects;i++){
4700 if(objects.type[i]==firetype)
4701 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){
4703 if(!objects.onfire[i]){
4704 emit_sound_at(firestartsound, objects.position[i]);
4706 objects.onfire[i]=1;
4709 if(objects.onfire[i]){
4714 if(objects.type[i]==bushtype)
4715 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){
4717 if(!objects.onfire[i]){
4718 emit_sound_at(firestartsound, objects.position[i]);
4720 objects.onfire[i]=1;
4724 if(objects.onfire[i]){
4728 if(objects.messedwith[i]<=0){
4732 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4735 envsound[numenvsounds]=coords;
4736 envsoundvol[numenvsounds]=4*findLength(&velocity);
4737 envsoundlife[numenvsounds]=.4;
4742 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4743 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4745 if(environment!=desertenvironment)
4746 for(j=0;j<howmany;j++){
4747 tempvel.x=float(abs(Random()%100)-50)/20;
4748 tempvel.y=float(abs(Random()%100)-50)/20;
4749 tempvel.z=float(abs(Random()%100)-50)/20;
4752 pos.x+=float(abs(Random()%100)-50)/200;
4753 pos.y+=float(abs(Random()%100)-50)/200;
4754 pos.z+=float(abs(Random()%100)-50)/200;
4755 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);
4756 Sprite::setLastSpriteSpecial(1);
4758 howmany=findLength(&velocity)*4;
4760 if(environment==snowyenvironment)
4761 for(j=0;j<howmany;j++){
4762 tempvel.x=float(abs(Random()%100)-50)/20;
4763 tempvel.y=float(abs(Random()%100)-50)/20;
4764 tempvel.z=float(abs(Random()%100)-50)/20;
4767 pos.x+=float(abs(Random()%100)-50)/200;
4768 pos.y+=float(abs(Random()%100)-50)/200;
4769 pos.z+=float(abs(Random()%100)-50)/200;
4770 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4771 Sprite::setLastSpriteSpecial(2);
4774 objects.rotx[i]+=velocity.x*multiplier*6;
4775 objects.roty[i]+=velocity.z*multiplier*6;
4776 objects.messedwith[i]=.5;
4779 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4780 if(objects.rotation2[i]==0)tempcoord=coords;
4782 tempcoord=coords-objects.position[i];
4783 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4784 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4785 tempcoord+=objects.position[i];
4787 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]){
4788 if(objects.messedwith[i]<=0){
4792 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4795 envsound[numenvsounds]=coords;
4796 envsoundvol[numenvsounds]=4*findLength(&velocity);
4797 envsoundlife[numenvsounds]=.4;
4802 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4803 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4805 if(environment!=desertenvironment)
4806 for(j=0;j<howmany;j++){
4807 tempvel.x=float(abs(Random()%100)-50)/20;
4808 tempvel.y=float(abs(Random()%100)-50)/20;
4809 tempvel.z=float(abs(Random()%100)-50)/20;
4813 pos.x+=float(abs(Random()%100)-50)/150;
4814 pos.y+=float(abs(Random()%100)-50)/150;
4815 pos.z+=float(abs(Random()%100)-50)/150;
4816 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);
4817 Sprite::setLastSpriteSpecial(1);
4819 howmany=findLength(&velocity)*4;
4821 if(environment==snowyenvironment)
4822 for(j=0;j<howmany;j++){
4823 tempvel.x=float(abs(Random()%100)-50)/20;
4824 tempvel.y=float(abs(Random()%100)-50)/20;
4825 tempvel.z=float(abs(Random()%100)-50)/20;
4829 pos.x+=float(abs(Random()%100)-50)/150;
4830 pos.y+=float(abs(Random()%100)-50)/150;
4831 pos.z+=float(abs(Random()%100)-50)/150;
4832 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4833 Sprite::setLastSpriteSpecial(2);
4836 objects.messedwith[i]=.5;
4844 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
4846 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
4847 if(tutoriallevel==1&&id!=0)play=0;
4848 if(play&&aitype!=playercontrolled){
4852 if(creature==rabbittype){
4853 if(i==0)whichsound=rabbitchitter;
4854 if(i==1)whichsound=rabbitchitter2;
4856 if(creature==wolftype){
4857 if(i==0)whichsound=growlsound;
4858 if(i==1)whichsound=growl2sound;
4864 emit_sound_at(whichsound, coords);
4868 if(targetanimation==staggerbackhighanim)staggerdelay=1;
4869 if(targetanimation==staggerbackhardanim)staggerdelay=1;
4870 staggerdelay-=multiplier;
4871 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
4872 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
4873 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
4874 targetanimation=getIdle();
4878 weaponmissdelay-=multiplier;
4879 highreversaldelay-=multiplier;
4880 lowreversaldelay-=multiplier;
4881 lastcollide-=multiplier;
4882 skiddelay-=multiplier;
4883 if(!isnormal(velocity.x)&&velocity.x){
4886 if(!isnormal(targettilt)&&targettilt){
4889 if(!isnormal(targettilt2)&&targettilt2){
4892 if(!isnormal(targetrotation)&&targetrotation){
4896 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
4897 //open hands and close mouth
4898 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4899 righthandmorphness=0;
4900 righthandmorphend=0;
4901 targetrighthandmorphness=1;
4904 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4905 lefthandmorphness=0;
4907 targetlefthandmorphness=1;
4910 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
4913 targetheadmorphness=1;
4917 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){
4918 //open hands and mouth
4919 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
4920 righthandmorphness=0;
4921 righthandmorphend=0;
4922 targetrighthandmorphness=1;
4925 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
4926 lefthandmorphness=0;
4928 targetlefthandmorphness=1;
4931 if(headmorphend!=1&&headmorphness==targetheadmorphness){
4934 targetheadmorphness=1;
4938 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
4939 //close hands and mouth
4940 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4941 righthandmorphness=0;
4942 righthandmorphend=1;
4943 targetrighthandmorphness=1;
4946 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4947 lefthandmorphness=0;
4949 targetlefthandmorphness=1;
4952 if(headmorphend!=0&&headmorphness==targetheadmorphness){
4955 targetheadmorphness=1;
4959 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){
4960 //close hands and yell
4961 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
4962 righthandmorphness=0;
4963 righthandmorphend=1;
4964 targetrighthandmorphness=1;
4967 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
4968 lefthandmorphness=0;
4970 targetlefthandmorphness=1;
4973 if(headmorphend!=2&&headmorphness==targetheadmorphness){
4976 targetheadmorphness=1;
4983 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
4984 behind=(normaldotproduct(facing,coords-victim->coords)>0);
4988 if(!dead&&targetanimation!=hurtidleanim)
4989 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
4990 if(headmorphend!=4||headmorphness==targetheadmorphness){
4993 targetheadmorphness=1;
4997 if(weaponactive!=-1){
4998 if(weapons[weaponids[weaponactive]].getType()!=staff){
4999 righthandmorphstart=1;
5000 righthandmorphend=1;
5002 if(weapons[weaponids[weaponactive]].getType()==staff){
5003 righthandmorphstart=2;
5004 righthandmorphend=2;
5006 targetrighthandmorphness=1;
5009 terrainnormal=terrain.getNormal(coords.x,coords.z);
5011 if(animation[targetanimation].attack!=reversal){
5012 if(!isnormal(coords.x))
5020 flatfacing=DoRotation(flatfacing,0,rotation,0);
5022 ReflectVector(&facing,terrainnormal);
5025 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5026 if(onterrain)targettilt2=-facing.y*20;
5030 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5031 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5032 flatvelocity=velocity;
5034 flatvelspeed=findLength(&flatvelocity);
5035 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5036 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5037 if(velocity.y<0)targettilt2*=-1;
5038 if(velocity.y<0)targettilt*=-1;
5039 if(targettilt>25)targettilt=25;
5040 if(targettilt<-25)targettilt=-25;
5043 if(targettilt2>45)targettilt2=45;
5044 if(targettilt2<-45)targettilt2=-45;
5045 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5046 else if(tilt2>targettilt2){
5047 tilt2-=multiplier*400;
5049 else if(tilt2<targettilt2){
5050 tilt2+=multiplier*400;
5052 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5053 if(tilt2>25)tilt2=25;
5054 if(tilt2<-25)tilt2=-25;
5057 if(!isnormal(targettilt)&&targettilt){
5060 if(!isnormal(targettilt2)&&targettilt2){
5065 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5066 if(targetanimation==rabbittackleanim){
5067 velocity+=facing*multiplier*speed*700*scale;
5068 velspeed=findLength(&velocity);
5069 if(velspeed>speed*65*scale){
5071 velspeed=speed*65*scale;
5074 velocity.y+=gravity*multiplier*20;
5075 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5076 velspeed=findLength(&velocity);
5077 velocity=flatfacing*velspeed;
5079 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5080 if(isRun()||targetanimation==rabbitkickanim){
5081 velocity+=facing*multiplier*speed*700*scale;
5082 velspeed=findLength(&velocity);
5083 if(velspeed>speed*45*scale){
5085 velspeed=speed*45*scale;
5088 velocity.y+=gravity*multiplier*20;
5089 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5090 velspeed=findLength(&velocity);
5091 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5092 velocity=flatfacing*velspeed;
5096 velocity+=facing*multiplier*speed*700*scale;
5097 velspeed=findLength(&velocity);
5098 if(creature==rabbittype){
5099 if(velspeed>speed*55*scale){
5101 velspeed=speed*55*scale;
5105 if(creature==wolftype){
5106 if(velspeed>speed*75*scale){
5108 velspeed=speed*75*scale;
5112 velocity.y+=gravity*multiplier*20;
5113 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5114 velspeed=findLength(&velocity);
5115 velocity=flatfacing*velspeed;
5118 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5119 velocity+=facing*multiplier*speed*700*scale;
5120 velspeed=findLength(&velocity);
5121 if(velspeed>speed*45*scale){
5123 velspeed=speed*45*scale;
5126 velocity.y+=gravity*multiplier*20;
5127 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5128 velspeed=findLength(&velocity);
5129 velocity=flatfacing*velspeed;
5133 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5134 velocity+=facing*multiplier*speed*700*scale;
5135 velspeed=findLength(&velocity);
5136 if(velspeed>speed*25*scale){
5138 velspeed=speed*25*scale;
5141 velocity.y+=gravity*multiplier*20;
5142 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5143 velspeed=findLength(&velocity);
5144 velocity=flatfacing*velspeed;
5147 if(targetanimation==sneakanim||targetanimation==walkanim){
5148 velocity+=facing*multiplier*speed*700*scale;
5149 velspeed=findLength(&velocity);
5150 if(velspeed>speed*12*scale){
5152 velspeed=speed*12*scale;
5155 velocity.y+=gravity*multiplier*20;
5156 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5157 velspeed=findLength(&velocity);
5158 velocity=flatfacing*velspeed;
5161 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5162 velocity+=facing*multiplier*speed*700*scale;
5163 velspeed=findLength(&velocity);
5164 if(velspeed>speed*2*scale){
5166 velspeed=speed*2*scale;
5169 velocity.y+=gravity*multiplier*20;
5170 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5171 velspeed=findLength(&velocity);
5172 velocity=flatfacing*velspeed;
5176 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5177 velocity-=facing*multiplier*speed*700*scale;
5178 velspeed=findLength(&velocity);
5179 if(velspeed>speed*2*scale){
5181 velspeed=speed*2*scale;
5184 velocity.y+=gravity*multiplier*20;
5185 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5186 velspeed=findLength(&velocity);
5187 velocity=flatfacing*velspeed*-1;
5190 if(targetanimation==fightsidestep){
5191 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5192 velspeed=findLength(&velocity);
5193 if(velspeed>speed*12*scale){
5195 velspeed=speed*12*scale;
5198 velocity.y+=gravity*multiplier*20;
5199 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5200 velspeed=findLength(&velocity);
5201 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5204 if(targetanimation==staggerbackhighanim){
5205 coords-=facing*multiplier*speed*16*scale;
5208 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5209 coords-=facing*multiplier*speed*20*scale;
5213 if(targetanimation==backhandspringanim){
5214 //coords-=facing*multiplier*50*scale;
5215 velocity+=facing*multiplier*speed*700*scale*-1;
5216 velspeed=findLength(&velocity);
5217 if(velspeed>speed*50*scale){
5219 velspeed=speed*50*scale;
5222 velocity.y+=gravity*multiplier*20;
5223 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5224 velspeed=findLength(&velocity);
5225 velocity=flatfacing*velspeed*-1;
5227 if(targetanimation==dodgebackanim){
5228 //coords-=facing*multiplier*50*scale;
5229 velocity+=facing*multiplier*speed*700*scale*-1;
5230 velspeed=findLength(&velocity);
5231 if(velspeed>speed*60*scale){
5233 velspeed=speed*60*scale;
5236 velocity.y+=gravity*multiplier*20;
5237 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5238 velspeed=findLength(&velocity);
5239 velocity=flatfacing*velspeed*-1;
5242 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5243 velspeed=findLength(&velocity);
5247 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5248 velocity.y+=gravity*multiplier;
5251 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5253 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5254 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5256 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5262 pause_sound(whooshsound);
5263 OPENAL_SetVolume(channels[whooshsound], 0);
5266 if(targetanimation==jumpdownanim||isFlip()){
5267 if(isFlip())jumppower=-4;
5268 targetanimation=getLanding();
5269 emit_sound_at(landsound, coords, 128.);
5272 envsound[numenvsounds]=coords;
5273 envsoundvol[numenvsounds]=16;
5274 envsoundlife[numenvsounds]=.4;
5280 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5281 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5282 coords.y=terrain.getHeight(coords.x,coords.z);
5287 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)){
5288 velspeed=findLength(&velocity);
5290 if(velspeed<multiplier*300*scale){
5292 } else velocity-=velocity/velspeed*multiplier*300*scale;
5293 if(velspeed>5&&(isLanding()||isLandhard())){
5294 skiddingdelay+=multiplier;
5301 else skiddingdelay=0;
5305 velspeed=findLength(&velocity);
5307 if(velspeed<multiplier*600*scale){
5309 } else velocity-=velocity/velspeed*multiplier*600*scale;
5311 if(velspeed>5&&(isLanding()||isLandhard())){
5312 skiddingdelay+=multiplier;
5319 else skiddingdelay=0;
5322 if(skiddingdelay<0)skiddingdelay+=multiplier;
5323 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5325 if(!onterrain||environment==grassyenvironment){
5326 emit_sound_at(skidsound, coords, 128*velspeed/10);
5329 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5333 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5334 terrainnormal=victim->coords-coords;
5335 Normalise(&terrainnormal);
5336 targetrotation=-asin(0-terrainnormal.x);
5337 targetrotation*=360/6.28;
5338 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5339 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5342 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5343 targetrotation=victim->targetrotation;
5345 if(targetanimation==rabbittacklinganim){
5346 coords=victim->coords;
5349 skeleton.oldfree=skeleton.free;
5353 midterrain.x=terrain.size*terrain.scale/2;
5354 midterrain.z=terrain.size*terrain.scale/2;
5355 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5357 tempposit=coords-midterrain;
5359 Normalise(&tempposit);
5360 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5361 coords.x=tempposit.x+midterrain.x;
5362 coords.z=tempposit.z+midterrain.z;
5366 int Person::DrawSkeleton(){
5367 int oldplayerdetail;
5368 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5369 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5379 glAlphaFunc(GL_GREATER, 0.0001);
5381 float terrainheight;
5383 if(!isnormal(rotation))rotation=0;
5384 if(!isnormal(tilt))tilt=0;
5385 if(!isnormal(tilt2))tilt2=0;
5386 oldplayerdetail=playerdetail;
5388 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5391 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5394 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5399 if(playerdetail!=oldplayerdetail) {
5401 normalsupdatedelay=0;
5403 static float updatedelaychange;
5404 static float morphness;
5405 static float framemult;
5407 skeleton.FindForwards();
5408 if(howactive==typesittingwall){
5409 skeleton.specialforward[1]=0;
5410 skeleton.specialforward[1].z=1;
5416 static int weaponattachmuscle;
5417 static int weaponrotatemuscle;
5418 static XYZ weaponpoint;
5419 static int start,endthing;
5420 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5421 if(!isSleeping()&&!isSitting()){
5422 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5423 XYZ point,newpoint,change,change2;
5424 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5425 heightleft=terrain.getHeight(point.x,point.z)+.04;
5427 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5428 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5429 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5430 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5431 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5433 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5434 heightright=terrain.getHeight(point.x,point.z)+.04;
5435 point.y=heightright;
5436 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5437 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5438 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5439 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5440 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5441 skeleton.DoConstraints(&coords,&scale);
5443 if(creature==wolftype){
5444 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5445 heightleft=terrain.getHeight(point.x,point.z)+.04;
5447 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5448 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5449 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5450 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5451 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5453 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5454 heightright=terrain.getHeight(point.x,point.z)+.04;
5455 point.y=heightright;
5456 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5457 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5458 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5459 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5460 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5461 skeleton.DoConstraints(&coords,&scale);
5464 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5465 XYZ point,newpoint,change,change2;
5466 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5467 heightleft=terrain.getHeight(point.x,point.z)+.04;
5469 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5470 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5471 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5472 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5473 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5475 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5476 heightright=terrain.getHeight(point.x,point.z)+.04;
5477 point.y=heightright;
5478 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5479 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5480 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5481 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5482 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5483 skeleton.DoConstraints(&coords,&scale);
5485 if(creature==wolftype){
5486 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5487 heightleft=terrain.getHeight(point.x,point.z)+.04;
5489 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5490 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5491 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5492 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5493 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5495 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5496 heightright=terrain.getHeight(point.x,point.z)+.04;
5497 point.y=heightright;
5498 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5499 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5500 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5501 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5502 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5503 skeleton.DoConstraints(&coords,&scale);
5507 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5508 XYZ point,newpoint,change,change2;
5509 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5510 heightleft=terrain.getHeight(point.x,point.z)+.04;
5512 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5513 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5514 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5515 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5516 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5518 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5519 heightright=terrain.getHeight(point.x,point.z)+.04;
5520 point.y=heightright;
5521 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5522 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5523 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5524 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5525 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5526 skeleton.DoConstraints(&coords,&scale);
5528 if(creature==wolftype){
5529 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5530 heightleft=terrain.getHeight(point.x,point.z)+.04;
5532 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5533 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5534 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5535 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5536 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5538 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5539 heightright=terrain.getHeight(point.x,point.z)+.04;
5540 point.y=heightright;
5541 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5542 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5543 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5544 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5545 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5546 skeleton.DoConstraints(&coords,&scale);
5550 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()))
5553 targetheadrotation=-targetrotation;
5554 targetheadrotation2=0;
5555 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5557 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5558 skeleton.drawmodel.vertex[i]=0;
5559 skeleton.drawmodel.vertex[i].y=999;
5561 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5562 skeleton.drawmodellow.vertex[i]=0;
5563 skeleton.drawmodellow.vertex[i].y=999;
5565 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5566 skeleton.drawmodelclothes.vertex[i]=0;
5567 skeleton.drawmodelclothes.vertex[i].y=999;
5569 for(i=0;i<skeleton.num_muscles;i++){
5570 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5574 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5575 morphness=righthandmorphness;
5576 start=righthandmorphstart;
5577 endthing=righthandmorphend;
5579 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5580 morphness=lefthandmorphness;
5581 start=lefthandmorphstart;
5582 endthing=lefthandmorphend;
5584 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5585 morphness=headmorphness;
5586 start=headmorphstart;
5587 endthing=headmorphend;
5589 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)){
5590 morphness=chestmorphness;
5591 start=chestmorphstart;
5592 endthing=chestmorphend;
5594 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)){
5595 morphness=tailmorphness;
5596 start=tailmorphstart;
5597 endthing=tailmorphend;
5599 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5600 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5601 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5604 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5605 if(!skeleton.free)glRotatef(tilt,0,0,1);
5608 glTranslatef(mid.x,mid.y,mid.z);
5610 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5611 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5613 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5614 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5616 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5617 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5619 if(playerdetail||skeleton.free==3)
5621 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5623 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5625 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5626 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,
5627 (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,
5628 (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);
5629 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)
5630 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,
5631 (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,
5632 (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);
5633 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)
5634 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,
5635 (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,
5636 (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);
5637 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5638 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,
5639 (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,
5640 (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);
5641 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5642 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5643 //if(!isnormal(scale))test=1;
5644 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5645 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5646 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5651 if(!playerdetail||skeleton.free==3)
5653 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5655 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5657 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5658 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5659 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5660 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5661 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)
5662 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5663 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5664 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5665 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)
5666 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5667 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5668 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5669 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5670 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5671 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5672 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5674 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5675 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5676 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5677 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5683 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5684 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5686 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5689 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5690 if(!skeleton.free)glRotatef(tilt,0,0,1);
5691 glTranslatef(mid.x,mid.y,mid.z);
5692 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5693 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5695 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5696 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5698 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5699 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5701 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5702 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5704 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5705 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5706 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5707 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5708 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)
5709 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5710 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5711 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5712 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)
5713 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5714 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5715 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5716 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5717 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5718 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5719 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5720 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5721 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5722 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5723 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5728 updatedelay=1+(float)(Random()%100)/1000;
5730 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5731 normalsupdatedelay=1;
5732 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5733 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5734 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5738 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5739 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5740 if(skeleton.clothes){
5741 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5746 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5747 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5748 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5749 if(skeleton.free==1)updatedelaychange*=6;
5750 if(id==0)updatedelaychange*=8;
5751 updatedelay+=updatedelaychange;
5753 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5755 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5756 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5757 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5758 if(!skeleton.free)glRotatef(rotation,0,1,0);
5761 glColor4f(.4,1,.4,1);
5762 glDisable(GL_LIGHTING);
5763 glDisable(GL_TEXTURE_2D);
5766 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5767 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5773 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5774 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);
5775 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);
5776 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);
5777 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);
5778 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);
5779 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);
5785 terrainlight=terrain.getLighting(coords.x,coords.z);
5786 distance=findDistancefast(&viewer,&coords);
5787 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5788 if(distance>1)distance=1;
5790 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5791 if(terrainheight<1)terrainheight=1;
5792 if(terrainheight>1.7)terrainheight=1.7;
5795 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5796 glDisable(GL_BLEND);
5797 glAlphaFunc(GL_GREATER, 0.0001);
5798 glEnable(GL_TEXTURE_2D);
5800 glDisable(GL_TEXTURE_2D);
5801 glColor4f(.7,.35,0,.5);
5803 glEnable(GL_LIGHTING);
5806 if(tutoriallevel&&id!=0){
5807 //glDisable(GL_TEXTURE_2D);
5808 glColor4f(.7,.7,.7,0.6);
5810 glEnable(GL_LIGHTING);
5812 if(canattack&&cananger)
5813 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5814 glDisable(GL_TEXTURE_2D);
5815 glColor4f(1,0,0,0.8);
5817 glMatrixMode(GL_TEXTURE);
5819 glTranslatef(0,-smoketex,0);
5820 glTranslatef(-smoketex,0,0);
5824 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5825 else skeleton.drawmodel.draw();
5829 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5830 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5833 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
5834 if(tutoriallevel&&id!=0){
5836 glMatrixMode(GL_MODELVIEW);
5837 glEnable(GL_TEXTURE_2D);
5838 glColor4f(.7,.7,.7,0.6);
5840 glEnable(GL_LIGHTING);
5842 if(canattack&&cananger)
5843 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5844 glDisable(GL_TEXTURE_2D);
5845 glColor4f(1,0,0,0.8);
5847 glMatrixMode(GL_TEXTURE);
5849 glTranslatef(0,-smoketex*.6,0);
5850 glTranslatef(smoketex*.6,0,0);
5853 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
5854 else skeleton.drawmodel.draw();
5858 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
5859 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
5864 if(tutoriallevel&&id!=0){
5866 glMatrixMode(GL_MODELVIEW);
5867 glEnable(GL_TEXTURE_2D);
5869 if(skeleton.clothes){
5872 if(!immediate)skeleton.drawmodelclothes.draw();
5873 if(immediate)skeleton.drawmodelclothes.drawimmediate();
5880 for(k=0;k<num_weapons;k++){
5882 if(weaponactive==k){
5883 if(weapons[i].getType()!=staff){
5884 for(j=0;j<skeleton.num_muscles;j++){
5885 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5886 weaponattachmuscle=j;
5889 for(j=0;j<skeleton.num_muscles;j++){
5890 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){
5891 weaponrotatemuscle=j;
5894 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5895 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
5897 if(weapons[i].getType()==staff){
5898 for(j=0;j<skeleton.num_muscles;j++){
5899 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
5900 weaponattachmuscle=j;
5903 for(j=0;j<skeleton.num_muscles;j++){
5904 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){
5905 weaponrotatemuscle=j;
5908 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
5909 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
5910 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5911 XYZ tempnormthing,vec1,vec2;
5912 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
5913 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
5914 CrossProduct(&vec1,&vec2,&tempnormthing);
5915 Normalise(&tempnormthing);
5916 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);
5919 if(weaponactive!=k&&weaponstuck!=k){
5920 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;
5921 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;
5922 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;
5923 for(j=0;j<skeleton.num_muscles;j++){
5924 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){
5925 weaponrotatemuscle=j;
5930 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
5931 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
5932 for(j=0;j<skeleton.num_muscles;j++){
5933 if((skeleton.muscles[j].parent1->label==abdomen||skeleton.muscles[j].parent2->label==abdomen)&&(skeleton.muscles[j].parent1->label==neck||skeleton.muscles[j].parent2->label==neck)&&skeleton.muscles[j].numvertices>0){
5934 weaponrotatemuscle=j;
5939 weapons[i].position=weaponpoint*scale+coords;
5940 weapons[i].bigrotation=0;
5941 weapons[i].bigtilt=0;
5942 weapons[i].bigtilt2=0;
5944 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;
5945 weapons[i].bigrotation=rotation;
5946 weapons[i].bigtilt=tilt;
5947 weapons[i].bigtilt2=tilt2;
5949 weapons[i].rotation1=skeleton.muscles[weaponrotatemuscle].lastrotate1;
5950 weapons[i].rotation2=skeleton.muscles[weaponrotatemuscle].lastrotate2;
5951 weapons[i].rotation3=skeleton.muscles[weaponrotatemuscle].lastrotate3;
5952 if(weaponactive==k){
5953 if(weapons[i].getType()==knife){
5954 weapons[i].smallrotation=180;
5955 weapons[i].smallrotation2=0;
5956 if(isCrouch()||wasCrouch()){
5957 weapons[i].smallrotation2=20;
5959 if(targetanimation==hurtidleanim){
5960 weapons[i].smallrotation2=50;
5962 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
5963 XYZ temppoint1,temppoint2,tempforward;
5966 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5967 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5968 distance=findDistance(&temppoint1,&temppoint2);
5969 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5970 weapons[i].rotation2*=360/6.28;
5973 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
5974 weapons[i].rotation1*=360/6.28;
5975 weapons[i].rotation3=0;
5976 weapons[i].smallrotation=-90;
5977 weapons[i].smallrotation2=0;
5978 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
5980 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
5981 XYZ temppoint1,temppoint2,tempforward;
5984 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
5985 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
5986 distance=findDistance(&temppoint1,&temppoint2);
5987 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
5988 weapons[i].rotation2*=360/6.28;
5991 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
5992 weapons[i].rotation1*=360/6.28;
5993 weapons[i].rotation3=0;
5994 weapons[i].smallrotation=90;
5995 weapons[i].smallrotation2=0;
5996 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
5998 if(targetanimation==knifethrowanim){
5999 weapons[i].smallrotation=90;
6000 //weapons[i].smallrotation2=-90;
6001 weapons[i].smallrotation2=0;
6002 weapons[i].rotation1=0;
6003 weapons[i].rotation2=0;
6004 weapons[i].rotation3=0;
6006 if(targetanimation==knifesneakattackanim&&targetframe<5){
6007 weapons[i].smallrotation=-90;
6008 weapons[i].rotation1=0;
6009 weapons[i].rotation2=0;
6010 weapons[i].rotation3=0;
6013 if(weapons[i].getType()==sword){
6014 weapons[i].smallrotation=0;
6015 weapons[i].smallrotation2=0;
6016 if(targetanimation==knifethrowanim){
6017 weapons[i].smallrotation=-90;
6018 weapons[i].smallrotation2=0;
6019 weapons[i].rotation1=0;
6020 weapons[i].rotation2=0;
6021 weapons[i].rotation3=0;
6023 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)){
6024 XYZ temppoint1,temppoint2,tempforward;
6027 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6028 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6029 distance=findDistance(&temppoint1,&temppoint2);
6030 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6031 weapons[i].rotation2*=360/6.28;
6034 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6035 weapons[i].rotation1*=360/6.28;
6036 weapons[i].rotation3=0;
6037 weapons[i].smallrotation=90;
6038 weapons[i].smallrotation2=0;
6039 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6042 if(weapons[i].getType()==staff){
6043 weapons[i].smallrotation=100;
6044 weapons[i].smallrotation2=0;
6045 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6046 XYZ temppoint1,temppoint2,tempforward;
6049 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6050 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6051 distance=findDistance(&temppoint1,&temppoint2);
6052 weapons[i].rotation2=asin((temppoint1.y-temppoint2.y)/distance);
6053 weapons[i].rotation2*=360/6.28;
6056 weapons[i].rotation1=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6057 weapons[i].rotation1*=360/6.28;
6058 weapons[i].rotation3=0;
6059 weapons[i].smallrotation=90;
6060 weapons[i].smallrotation2=0;
6061 if(temppoint1.x>temppoint2.x)weapons[i].rotation1=360-weapons[i].rotation1;
6065 if(weaponactive!=k&&weaponstuck!=k){
6066 if(weapons[i].getType()==knife){
6067 weapons[i].smallrotation=-70;
6068 weapons[i].smallrotation2=10;
6070 if(weapons[i].getType()==sword){
6071 weapons[i].smallrotation=-100;
6072 weapons[i].smallrotation2=-8;
6074 if(weapons[i].getType()==staff){
6075 weapons[i].smallrotation=-100;
6076 weapons[i].smallrotation2=-8;
6080 if(weaponstuckwhere==0)
6081 weapons[i].smallrotation=180;
6083 weapons[i].smallrotation=0;
6084 weapons[i].smallrotation2=10;
6091 if(skeleton.free)calcrot=1;
6092 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6093 if(currentanimation!=targetanimation)calcrot=1;
6094 //if(id==0)calcrot=1;
6095 if(skeleton.free==2)calcrot=0;
6101 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6104 static float distance;
6105 static float olddistance;
6106 static int intersecting;
6107 static int firstintersecting;
6110 static XYZ start,end;
6111 static float slopethreshold=-.4;
6113 firstintersecting=-1;
6117 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6118 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6120 for (j=0;j<model->TriangleNum;j++){
6121 if(model->facenormals[j].y<=slopethreshold){
6123 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)));
6124 if(distance<radius){
6125 point=*p1-model->facenormals[j]*distance;
6126 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;
6127 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6128 &model->vertex[model->Triangles[j].vertex[1]],
6130 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6131 &model->vertex[model->Triangles[j].vertex[2]],
6133 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6134 &model->vertex[model->Triangles[j].vertex[2]],
6137 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6141 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)){
6142 p1->y=point.y+radius;
6143 if((targetanimation==jumpdownanim||isFlip())){
6144 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6146 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6152 pause_sound(whooshsound);
6153 OPENAL_SetVolume(channels[whooshsound], 0);
6156 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6157 if(isFlip())jumppower=-4;
6158 targetanimation=getLanding();
6159 emit_sound_at(landsound, coords, 128.);
6162 envsound[numenvsounds]=coords;
6163 envsoundvol[numenvsounds]=16;
6164 envsoundlife[numenvsounds]=.4;
6172 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6175 for (j=0;j<model->TriangleNum;j++){
6176 if(model->facenormals[j].y>slopethreshold){
6180 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)));
6181 if(distance<radius*.5){
6182 point=start-model->facenormals[j]*distance;
6183 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;
6184 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,
6185 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6186 p1->x, p1->y, p1->z, radius/2);
6187 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,
6188 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6189 p1->x, p1->y, p1->z, radius/2);
6190 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,
6191 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6192 p1->x, p1->y, p1->z, radius/2);
6194 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6195 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6197 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6198 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6200 *p1+=model->facenormals[j]*(distance-radius*.5);
6203 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6207 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6209 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6211 return firstintersecting;