2 Copyright (C) 2003, 2010 - Wolfire Games
4 This file is part of Lugaru.
6 Lugaru is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 /**> HEADER FILES <**/
24 #include "openal_wrapper.h"
25 #include "Animation.h"
30 extern float multiplier;
31 extern int channels[100];
32 extern Terrain terrain;
34 extern int environment;
36 extern FRUSTUM frustum;
38 extern float realmultiplier;
40 extern float slomodelay;
41 extern bool cellophane;
42 extern float texdetail;
43 extern float realtexdetail;
44 extern GLubyte bloodText[512*512*3];
45 extern GLubyte wolfbloodText[512*512*3];
46 extern int bloodtoggle;
47 extern Objects objects;
49 extern bool autoslomo;
50 extern float camerashake;
52 extern float terraindetail;
53 extern float viewdistance;
54 extern float blackout;
55 extern int difficulty;
57 extern float fadestart;
59 extern bool winfreeze;
60 extern float flashamount,flashr,flashg,flashb;
61 extern int flashdelay;
62 extern bool showpoints;
63 extern bool immediate;
65 extern bool tilt2weird;
66 extern bool tiltweird;
68 extern bool proportionweird;
69 extern bool vertexweird[6];
70 extern GLubyte texturearray[512*512*3];
71 extern XYZ envsound[30];
72 extern float envsoundvol[30];
73 extern float envsoundlife[30];
74 extern int numenvsounds;
75 extern int tutoriallevel;
76 extern float smoketex;
77 extern int tutorialstage;
78 extern bool reversaltrain;
79 extern bool canattack;
81 extern float damagedealt;
83 extern float hostiletime;
85 extern int indialogue;
87 extern bool gamestarted;
89 extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
90 extern "C" void PlayStreamEx(int chan, OPENAL_STREAM *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
92 void Person::CheckKick(){
96 float damagemult=1*power;
97 if(creature==wolftype)damagemult=2.5*power;
101 if(targetanimation==rabbitkickanim&&victim&&victim!=this&¤tframe>=2&¤tanimation==rabbitkickanim){
102 if(findDistancefast(&coords,&victim->coords)<1.2){
103 if(!victim->skeleton.free){
105 Normalise(&relative);
106 relative=coords+relative*1;
107 if(animation[victim->targetanimation].height!=lowheight){
111 emit_sound_at(heavyimpactsound, victim->coords);
115 Normalise(&relative);
116 for(i=0;i<victim->skeleton.num_joints;i++){
117 victim->skeleton.joints[i].velocity+=relative*120*damagemult;
120 victim->DoDamage(100*damagemult/victim->protectionhigh);
121 if(id==0)camerashake+=.4;
125 targetanimation=backflipanim;
130 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
132 award_bonus(id, cannon);
134 else if (victim->isCrouch()){
135 targetanimation=rabbitkickreversedanim;
136 currentanimation=rabbitkickreversedanim;
137 victim->currentanimation=rabbitkickreversalanim;
138 victim->targetanimation=rabbitkickreversalanim;
144 victim->oldcoords=victim->coords;
145 coords=victim->coords;
146 victim->targetrotation=targetrotation;
154 void Person::CatchFire(){
155 XYZ flatfacing,flatvelocity;
157 for(int i=0;i<10;i++){
158 howmany=abs(Random()%(skeleton.num_joints));
159 if(!skeleton.free)flatvelocity=velocity;
160 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity;
161 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
162 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
163 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, 2, 1);
168 emit_sound_at(firestartsound, coords);
170 emit_stream_at(stream_firesound, coords);
177 int Person::getIdle(){
178 if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
179 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)){
180 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
181 if(creature==rabbittype)return fightidleanim;
182 if(creature==wolftype)return wolfidle;
184 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
185 if(weapons.type[weaponids[weaponactive]]==knife)return knifefightidleanim;
186 if(weapons.type[weaponids[weaponactive]]==sword&&victim->weaponactive!=-1)return swordfightidlebothanim;
187 if(weapons.type[weaponids[weaponactive]]==sword)return swordfightidleanim;
188 if(weapons.type[weaponids[weaponactive]]==staff)return swordfightidleanim;
190 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
192 if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
193 if(howactive==typesitting)return sitanim;
194 if(howactive==typesittingwall)return sitwallanim;
195 if(howactive==typesleeping)return sleepanim;
196 if(howactive==typedead1)return dead1anim;
197 if(howactive==typedead2)return dead2anim;
198 if(howactive==typedead3)return dead3anim;
199 if(howactive==typedead4)return dead4anim;
200 if(creature==rabbittype)return bounceidleanim;
201 if(creature==wolftype)return wolfidle;
205 int Person::getCrouch(){
206 if(creature==rabbittype)return crouchanim;
207 if(creature==wolftype)return wolfcrouchanim;
211 int Person::getRun(){
212 if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
213 if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
215 if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
216 if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
220 int Person::getStop(){
221 if(creature==rabbittype)return stopanim;
222 if(creature==wolftype)return wolfstopanim;
227 bool Person::isLanding(){
228 if(targetanimation==landanim||targetanimation==wolflandanim)return 1;
233 bool Person::wasLanding(){
234 if(currentanimation==landanim||currentanimation==wolflandanim)return 1;
237 int Person::getLanding(){
238 if(creature==rabbittype)return landanim;
239 if(creature==wolftype)return wolflandanim;
244 bool Person::isLandhard(){
245 if(targetanimation==landhardanim||targetanimation==wolflandhardanim)return 1;
250 bool Person::wasLandhard(){
251 if(currentanimation==landhardanim||currentanimation==wolflandhardanim)return 1;
254 int Person::getLandhard(){
255 if(creature==rabbittype)return landhardanim;
256 if(creature==wolftype)return wolflandhardanim;
261 bool Person::isFlip(){
262 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==backflipanim||targetanimation==rightflipanim||targetanimation==leftflipanim||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)return 1;
266 bool Person::wasFlip(){
267 if(currentanimation==flipanim||currentanimation==frontflipanim||currentanimation==backflipanim||currentanimation==rightflipanim||currentanimation==leftflipanim||currentanimation==walljumprightkickanim||currentanimation==walljumpleftkickanim)return 1;
271 bool Person::isWallJump(){
272 if(targetanimation==walljumpfrontanim||targetanimation==walljumpbackanim||targetanimation==walljumpleftanim||targetanimation==walljumprightanim)return 1;
277 SolidHitBonus(int playerid)
279 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
280 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
282 award_bonus(playerid, solidhit);
285 void Person::DoBlood(float howmuch,int which){
286 static int bleedxint,bleedyint;
288 //if(howmuch&&id==0)blooddimamount=1;
289 if(bloodtoggle&&tutoriallevel!=1){
290 if(bleeding<=0&&spurt){
292 for(int i=0;i<3;i++){
296 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
299 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
301 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
302 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
304 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
305 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
308 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);
309 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);
313 for(int i=0;i<3;i++){
317 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
318 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
321 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
322 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
326 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
328 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);
330 Sprite::setLastSpriteSpecial(3);
335 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
338 int texdetailint=realtexdetail;
339 if(creature==rabbittype)
340 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){
341 bleedxint=abs(Random()%512);
342 bleedyint=abs(Random()%512);
344 if(creature==wolftype)
345 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){
346 bleedxint=abs(Random()%512);
347 bleedyint=abs(Random()%512);
351 bleedy/=realtexdetail;
352 bleedx/=realtexdetail;
353 direction=abs(Random()%2)*2-1;
357 if(bleeding>2)bleeding=2;
360 void Person::DoBloodBig(float howmuch,int which){
361 static int bleedxint,bleedyint,i,j;
363 if(howmuch&&id==0)blooddimamount=1;
365 if(tutoriallevel!=1||id==0)
366 if(aitype!=playercontrolled&&howmuch>0){
369 if(creature==wolftype){
370 int i=abs(Random()%2);
371 if(i==0)whichsound=snarlsound;
372 if(i==1)whichsound=snarl2sound;
373 envsound[numenvsounds]=coords;
374 envsoundvol[numenvsounds]=16;
375 envsoundlife[numenvsounds]=.4;
378 if(creature==rabbittype){
379 int i=abs(Random()%2);
380 if(i==0)whichsound=rabbitpainsound;
381 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
382 envsound[numenvsounds]=coords;
383 envsoundvol[numenvsounds]=16;
384 envsoundlife[numenvsounds]=.4;
386 //if(i==2)whichsound=rabbitpain2sound;
390 emit_sound_at(whichsound, coords);
393 if(id==0&&howmuch>0){
401 if(bloodtoggle&&decals&&tutoriallevel!=1){
402 if(bleeding<=0&&spurt){
404 for(int i=0;i<3;i++){
408 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
411 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
413 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
414 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
416 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
417 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
420 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);
421 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);
425 int offsetx=0,offsety=0;
428 offsetx=abs(Random()%60);
430 if(which==190||which==185){
432 offsetx=abs(Random()%100)-20;
442 if(which==220||which==215){
443 //offsety=Random()%20;
445 //offsetx=abs(Random()%80);
454 if(creature==rabbittype)
457 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
458 if(i<startx)startx=i;
459 if(j<starty)starty=j;
465 if(creature==wolftype)
468 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
469 if(i<startx)startx=i;
470 if(j<starty)starty=j;
482 if(startx<0)startx=0;
483 if(starty<0)starty=0;
484 if(endx>512-1)endx=512-1;
485 if(endy>512-1)endy=512-1;
486 if(endx<startx)endx=startx;
487 if(endy<starty)endy=starty;
489 startx/=realtexdetail;
490 starty/=realtexdetail;
494 int texdetailint=realtexdetail;
496 if(creature==rabbittype)
497 for(i=startx;i<endx;i++){
498 for(j=starty;j<endy;j++){
499 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){
500 color=Random()%85+170;
501 where=i*skeleton.skinsize*3+j*3;
502 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
503 skeleton.skinText[where+1]=0;
504 skeleton.skinText[where+2]=0;
508 if(creature==wolftype)
509 for(i=startx;i<endx;i++){
510 for(j=starty;j<endy;j++){
511 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){
512 color=Random()%85+170;
513 where=i*skeleton.skinsize*3+j*3;
514 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
515 skeleton.skinText[where+1]=0;
516 skeleton.skinText[where+2]=0;
520 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
521 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
522 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
526 if(creature==rabbittype)
527 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){
528 bleedxint=abs(Random()%512);
529 bleedyint=abs(Random()%512);
531 if(creature==wolftype)
532 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){
533 bleedxint=abs(Random()%512);
534 bleedyint=abs(Random()%512);
536 bleedy=bleedxint+offsetx;
537 bleedx=bleedyint+offsety;
538 bleedy/=realtexdetail;
539 bleedx/=realtexdetail;
540 if(bleedx<0)bleedx=0;
541 if(bleedy<0)bleedy=0;
542 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
543 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
544 direction=abs(Random()%2)*2-1;
547 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
548 deathbleeding+=bleeding;
549 bloodloss+=bleeding*3;
551 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
552 if(abs(Random()%2)==0){aitype=gethelptype;
555 else aitype=attacktypecutoff;
558 if(bleeding>2)bleeding=2;
561 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
562 static int bleedxint,bleedyint,i,j;
564 static XYZ startpoint,endpoint,colpoint,movepoint;
565 static float rotationpoint;
567 static XYZ p1,p2,p3,p0;
571 float coordsx,coordsy;
574 if(bloodtoggle&&decals&&tutoriallevel!=1){
576 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
584 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
587 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
588 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
589 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
591 CrossProduct(p2-p1,p3-p1,&N);
592 CrossProduct(p0-p1,p3-p1,&temp);
593 s = dotproduct(&temp,&N)/findLength(&N);
594 CrossProduct(p2-p1,p1-p0,&temp);
595 t = dotproduct(&temp,&N)/findLength(&N);
598 bary.x=findDistancefast(&p0,&p1);
599 bary.y=findDistancefast(&p0,&p2);
600 bary.z=findDistancefast(&p0,&p3);
602 total=bary.x+bary.y+bary.z;
611 total=bary.x+bary.y+bary.z;
617 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
618 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
619 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
620 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
621 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
622 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
623 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;
624 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;
626 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
627 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
629 if(bleeding<=0&&spurt){
631 for(int i=0;i<3;i++){
635 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
638 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
640 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
641 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
643 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
644 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
647 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);
648 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);
652 int offsetx=0,offsety=0;
655 offsetx=abs(Random()%120);
657 if(which==220||which==215){
659 offsetx=abs(Random()%80);
662 offsetx=(1+coordsy)*512-291;
663 offsety=coordsx*512-437;
670 if(creature==rabbittype)
673 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
674 if(i<startx)startx=i;
675 if(j<starty)starty=j;
681 if(creature==wolftype)
684 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
685 if(i<startx)startx=i;
686 if(j<starty)starty=j;
697 if(startx<0)startx=0;
698 if(starty<0)starty=0;
699 if(endx>512-1)endx=512-1;
700 if(endy>512-1)endy=512-1;
701 if(endx<startx)endx=startx;
702 if(endy<starty)endy=starty;
704 startx/=realtexdetail;
705 starty/=realtexdetail;
709 int texdetailint=realtexdetail;
711 if(creature==rabbittype)
712 for(i=startx;i<endx;i++){
713 for(j=starty;j<endy;j++){
714 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){
715 color=Random()%85+170;
716 where=i*skeleton.skinsize*3+j*3;
717 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
718 skeleton.skinText[where+1]=0;
719 skeleton.skinText[where+2]=0;
721 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){
722 color=Random()%85+170;
723 where=i*skeleton.skinsize*3+j*3;
724 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
725 skeleton.skinText[where+1]=0;
726 skeleton.skinText[where+2]=0;
730 if(creature==wolftype)
731 for(i=startx;i<endx;i++){
732 for(j=starty;j<endy;j++){
733 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){
734 color=Random()%85+170;
735 where=i*skeleton.skinsize*3+j*3;
736 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
737 skeleton.skinText[where+1]=0;
738 skeleton.skinText[where+2]=0;
740 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){
741 color=Random()%85+170;
742 where=i*skeleton.skinsize*3+j*3;
743 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
744 skeleton.skinText[where+1]=0;
745 skeleton.skinText[where+2]=0;
749 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
750 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
751 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
753 bleedy=(1+coordsy)*512;
755 bleedy/=realtexdetail;
756 bleedx/=realtexdetail;
757 if(bleedx<0)bleedx=0;
758 if(bleedy<0)bleedy=0;
759 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
760 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
761 direction=abs(Random()%2)*2-1;
763 if(whichtri==-1)return 0;
765 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
766 deathbleeding+=bleeding;
767 bloodloss+=bleeding*3;
769 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
770 if(abs(Random()%2)==0){aitype=gethelptype;
773 else aitype=attacktypecutoff;
776 if(bleeding>2)bleeding=2;
781 void Person::DoMipmaps(int howmanylevels,float startx, float endx, float starty, float endy){
784 static int bytesPerPixel=3;
785 static int newsize,totalsize,rowsize,bigstep,smallstep,sum;
786 static int newstartx,newstarty,newendx,newendy;
787 static int newnewstartx,newnewstarty,newnewendx,newnewendy;
789 static float sizemult;
791 for(i=0;i<skeleton.skinsize*skeleton.skinsize*bytesPerPixel;i++){
792 texture[i]=skeleton.skinText[i];
795 if((!osx||howmanylevels)){
797 if(startx<0)startx=0;
798 if(starty<0)starty=0;
799 if(endx>skeleton.skinsize-1)endx=skeleton.skinsize-1;
800 if(endy>skeleton.skinsize-1)endy=skeleton.skinsize-1;
801 if((endx>startx&&endy>starty)||howmanylevels){
808 for(i=startx;i<endx;i++){
809 for(j=starty;j<endy;j++){
810 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+0]=skeleton.skinText[i*skeleton.skinsize*3+j*3+0];
811 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+1]=skeleton.skinText[i*skeleton.skinsize*3+j*3+1];
812 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+2]=skeleton.skinText[i*skeleton.skinsize*3+j*3+2];
816 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
819 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
820 glTexSubImage2D(GL_TEXTURE_2D,0,starty,startx,endy-starty,endx-startx,GL_RGB,GL_UNSIGNED_BYTE,texturearray);
821 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
824 newsize=skeleton.skinsize;
827 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, skeleton.skinsize, skeleton.skinsize, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0] );
829 /*for(j=1;j<=howmanylevels;j++){
830 if(j==1)texpointer=&skeleton.skinText[0];
831 else texpointer=&texture[0];
833 totalsize=int( newsize*newsize*bytesPerPixel);
834 rowsize=int( newsize*bytesPerPixel );
835 bigstep=bytesPerPixel*newsize*2;
836 smallstep=bytesPerPixel*2;
842 glTexSubImage2D(GL_TEXTURE_2D,j,0,0,newsize/2,newsize/2,GL_RGB,GL_UNSIGNED_BYTE,texture);
849 void Person::Reverse(){
850 if(victim->aitype==playercontrolled||hostiletime>1)
851 if(victim->targetanimation!=jumpupanim&&victim->targetanimation!=jumpdownanim&&((tutoriallevel!=1||cananger)&&hostile)){
852 if(normaldotproduct(victim->facing,victim->coords-coords)>0&&!(victim->id==0&&difficulty<2)&&(creature!=wolftype||victim->creature==wolftype))return;
853 if(victim->aitype!=playercontrolled&&staggerdelay>0)return;
854 if(targetanimation==sweepanim){
855 targetanimation=sweepreversedanim;
856 currentanimation=sweepreversedanim;
857 victim->currentanimation=sweepreversalanim;
858 victim->targetanimation=sweepreversalanim;
860 if(targetanimation==spinkickanim){
861 targetanimation=spinkickreversedanim;
862 currentanimation=spinkickreversedanim;
863 victim->currentanimation=spinkickreversalanim;
864 victim->targetanimation=spinkickreversalanim;
866 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
867 if(targetanimation==rabbittacklinganim){
870 victim->currentframe=6;
871 victim->targetframe=7;
873 targetanimation=upunchreversedanim;
874 currentanimation=upunchreversedanim;
875 victim->currentanimation=upunchreversalanim;
876 victim->targetanimation=upunchreversalanim;
878 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
879 if(victim->weaponactive!=-1){
880 victim->throwtogglekeydown=1;
881 weapons.owner[victim->weaponids[0]]=-1;
882 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
883 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
884 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
885 weapons.missed[victim->weaponids[0]]=1;
886 weapons.freetime[victim->weaponids[0]]=0;
887 weapons.firstfree[victim->weaponids[0]]=1;
888 weapons.physics[victim->weaponids[0]]=1;
889 victim->num_weapons--;
890 if(victim->num_weapons){
891 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
892 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
895 victim->weaponactive=-1;
896 for(int j=0;j<numplayers;j++){
897 player[j].wentforweapon=0;
901 targetanimation=staffhitreversedanim;
902 currentanimation=staffhitreversedanim;
903 victim->currentanimation=staffhitreversalanim;
904 victim->targetanimation=staffhitreversalanim;
906 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
907 if(victim->weaponactive!=-1){
908 victim->throwtogglekeydown=1;
909 weapons.owner[victim->weaponids[0]]=-1;
910 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
911 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
912 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
913 weapons.missed[victim->weaponids[0]]=1;
914 weapons.freetime[victim->weaponids[0]]=0;
915 weapons.firstfree[victim->weaponids[0]]=1;
916 weapons.physics[victim->weaponids[0]]=1;
917 victim->num_weapons--;
918 if(victim->num_weapons){
919 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
920 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
923 victim->weaponactive=-1;
924 for(int j=0;j<numplayers;j++){
925 player[j].wentforweapon=0;
928 targetanimation=staffspinhitreversedanim;
929 currentanimation=staffspinhitreversedanim;
930 victim->currentanimation=staffspinhitreversalanim;
931 victim->targetanimation=staffspinhitreversalanim;
933 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
934 if(victim->weaponactive!=-1){
935 victim->throwtogglekeydown=1;
936 weapons.owner[victim->weaponids[0]]=-1;
937 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
938 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
939 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
940 weapons.missed[victim->weaponids[0]]=1;
941 weapons.freetime[victim->weaponids[0]]=0;
942 weapons.firstfree[victim->weaponids[0]]=1;
943 weapons.physics[victim->weaponids[0]]=1;
944 victim->num_weapons--;
945 if(victim->num_weapons){
946 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
947 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
950 victim->weaponactive=-1;
951 for(int j=0;j<numplayers;j++){
952 player[j].wentforweapon=0;
955 targetanimation=swordslashreversedanim;
956 currentanimation=swordslashreversedanim;
957 victim->currentanimation=swordslashreversalanim;
958 victim->targetanimation=swordslashreversalanim;
960 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
961 if(victim->weaponactive!=-1){
962 victim->throwtogglekeydown=1;
963 weapons.owner[victim->weaponids[0]]=-1;
964 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
965 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
966 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
967 weapons.missed[victim->weaponids[0]]=1;
968 weapons.freetime[victim->weaponids[0]]=0;
969 weapons.firstfree[victim->weaponids[0]]=1;
970 weapons.physics[victim->weaponids[0]]=1;
971 victim->num_weapons--;
972 if(victim->num_weapons){
973 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
974 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
977 victim->weaponactive=-1;
978 for(int j=0;j<numplayers;j++){
979 player[j].wentforweapon=0;
982 targetanimation=knifeslashreversedanim;
983 currentanimation=knifeslashreversedanim;
984 victim->currentanimation=knifeslashreversalanim;
985 victim->targetanimation=knifeslashreversalanim;
987 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
988 victim->targettilt2=targettilt2;
989 victim->currentframe=currentframe;
990 victim->targetframe=targetframe;
991 victim->target=target;
993 victim->oldcoords=victim->coords;
994 victim->coords=coords;
995 victim->targetrotation=targetrotation;
996 victim->rotation=targetrotation;
999 if(targetanimation==winduppunchanim){
1000 targetanimation=winduppunchblockedanim;
1001 victim->targetanimation=blockhighleftanim;
1002 victim->targetframe=1;
1004 victim->victim=this;
1005 victim->targetrotation=targetrotation+180;
1007 if(targetanimation==wolfslapanim){
1008 targetanimation=winduppunchblockedanim;
1009 victim->targetanimation=blockhighleftanim;
1010 victim->targetframe=1;
1012 victim->victim=this;
1013 victim->targetrotation=targetrotation+180;
1015 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
1016 targetanimation=swordslashparriedanim;
1018 victim->parriedrecently=0;
1019 victim->targetanimation=swordslashparryanim;
1020 victim->targetframe=1;
1022 victim->victim=this;
1023 victim->targetrotation=targetrotation+180;
1025 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
1026 if(victim->weaponactive!=-1){
1027 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1028 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1029 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1030 emit_sound_at(swordstaffsound, victim->coords);
1033 emit_sound_at(metalhitsound, victim->coords);
1037 victim->Puff(righthand);
1039 victim->targetframe=0;
1040 victim->targetanimation=staggerbackhighanim;
1041 victim->targetrotation=targetrotation+180;
1043 weapons.owner[victim->weaponids[0]]=-1;
1044 aim=DoRotation(facing,0,90,0)*21;
1046 weapons.velocity[victim->weaponids[0]]=aim*-.2;
1047 weapons.tipvelocity[victim->weaponids[0]]=aim;
1048 weapons.missed[victim->weaponids[0]]=1;
1049 weapons.hitsomething[victim->weaponids[0]]=0;
1050 weapons.freetime[victim->weaponids[0]]=0;
1051 weapons.firstfree[victim->weaponids[0]]=1;
1052 weapons.physics[victim->weaponids[0]]=1;
1053 victim->num_weapons--;
1054 if(victim->num_weapons){
1055 victim->weaponids[0]=victim->weaponids[num_weapons];
1056 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1058 victim->weaponactive=-1;
1059 for(int i=0;i<numplayers;i++){
1060 player[i].wentforweapon=0;
1067 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1068 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1069 OPENAL_SetVolume(channels[metalhitsound], 512);
1070 OPENAL_SetPaused(channels[metalhitsound], false);*/
1073 if(abs(Random()%20)==0){
1074 if(weaponactive!=-1){
1075 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1076 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1077 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1079 emit_sound_at(swordstaffsound, coords);
1082 emit_sound_at(metalhitsound, coords);
1090 targetanimation=staggerbackhighanim;
1091 targetrotation=targetrotation+180;
1093 weapons.owner[weaponids[0]]=-1;
1094 aim=DoRotation(facing,0,90,0)*21;
1096 weapons.velocity[weaponids[0]]=aim*-.2;
1097 weapons.tipvelocity[weaponids[0]]=aim;
1098 weapons.hitsomething[weaponids[0]]=0;
1099 weapons.missed[weaponids[0]]=1;
1100 weapons.freetime[weaponids[0]]=0;
1101 weapons.firstfree[weaponids[0]]=1;
1102 weapons.physics[weaponids[0]]=1;
1105 weaponids[0]=weaponids[num_weapons];
1106 if(weaponstuck==num_weapons)weaponstuck=0;
1109 for(int i=0;i<numplayers;i++){
1110 player[i].wentforweapon=0;
1114 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1115 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1116 OPENAL_SetVolume(channels[metalhitsound], 512);
1117 OPENAL_SetPaused(channels[metalhitsound], false);*/
1121 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1122 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1123 //victim->targetanimation=sweepanim;
1124 victim->targetanimation=dodgebackanim;
1125 victim->targetframe=0;
1127 //victim->velocity=0;
1130 rotatetarget=coords-victim->coords;
1131 Normalise(&rotatetarget);
1132 victim->targetrotation=-asin(0-rotatetarget.x);
1133 victim->targetrotation*=360/6.28;
1134 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1136 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1138 victim->lastattack3=victim->lastattack2;
1139 victim->lastattack2=victim->lastattack;
1140 victim->lastattack=victim->targetanimation;
1144 victim->targetanimation=sweepanim;
1145 victim->targetframe=0;
1149 rotatetarget=coords-victim->coords;
1150 Normalise(&rotatetarget);
1151 victim->targetrotation=-asin(0-rotatetarget.x);
1152 victim->targetrotation*=360/6.28;
1153 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1155 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1157 victim->lastattack3=victim->lastattack2;
1158 victim->lastattack2=victim->lastattack;
1159 victim->lastattack=victim->targetanimation;
1166 if(aitype!=playercontrolled)feint=0;
1167 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1168 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1169 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1171 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1175 void Person::DoDamage(float howmuch){
1176 if(tutoriallevel!=1)damage+=howmuch/power;
1177 if(id!=0)damagedealt+=howmuch/power;
1178 if(id==0)damagetaken+=howmuch/power;
1180 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1181 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1182 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1183 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1184 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1186 if(id==0)camerashake+=howmuch/100;
1187 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1188 if(blackout>1)blackout=1;
1190 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1191 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1192 if(abs(Random()%2)==0){aitype=gethelptype;
1195 else aitype=attacktypecutoff;
1199 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1202 for(int i=0;i<skeleton.num_joints; i++){
1203 if(!skeleton.free)flatvelocity2=velocity;
1204 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1205 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1206 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1207 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1208 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1209 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1210 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1211 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1212 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1215 emit_sound_at(splattersound, coords);
1224 if(!dead&&creature==wolftype){
1225 award_bonus(0, Wolfbonus);
1231 if(tutoriallevel!=1||id==0)
1232 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1235 if(creature==wolftype){
1236 int i=abs(Random()%2);
1237 if(i==0)whichsound=snarlsound;
1238 if(i==1)whichsound=snarl2sound;
1239 envsound[numenvsounds]=coords;
1240 envsoundvol[numenvsounds]=16;
1241 envsoundlife[numenvsounds]=.4;
1244 if(creature==rabbittype){
1245 int i=abs(Random()%2);
1246 if(i==0)whichsound=rabbitpainsound;
1247 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1248 envsound[numenvsounds]=coords;
1249 envsoundvol[numenvsounds]=16;
1250 envsoundlife[numenvsounds]=.4;
1252 //if(i==2)whichsound=rabbitpain2sound;
1256 emit_sound_at(whichsound, coords);
1261 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1262 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1265 void Person::DoHead(){
1266 static XYZ rotatearound;
1268 static float lookspeed=500;
1270 if(!freeze&&!winfreeze){
1273 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1274 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1276 while(targetheadrotation>180)targetheadrotation-=360;
1277 while(targetheadrotation<-180)targetheadrotation+=360;
1279 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1280 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1281 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1282 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1284 if(targetheadrotation2>120)targetheadrotation2=120;
1285 if(targetheadrotation2<-120)targetheadrotation2=-120;
1286 if(targetheadrotation>120)targetheadrotation=120;
1287 if(targetheadrotation<-120)targetheadrotation=-120;
1289 if(!isIdle())targetheadrotation2=0;
1291 if(targetheadrotation>80)targetheadrotation=80;
1292 if(targetheadrotation<-80)targetheadrotation=-80;
1293 if(targetheadrotation2>50)targetheadrotation2=50;
1294 if(targetheadrotation2<-50)targetheadrotation2=-50;
1297 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1298 else if(headrotation>targetheadrotation){
1299 headrotation-=multiplier*lookspeed;
1301 else if(headrotation<targetheadrotation){
1302 headrotation+=multiplier*lookspeed;
1305 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1306 else if(headrotation2>targetheadrotation2){
1307 headrotation2-=multiplier*lookspeed/2;
1309 else if(headrotation2<targetheadrotation2){
1310 headrotation2+=multiplier*lookspeed/2;
1313 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1314 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1318 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1319 facing=DoRotation(facing,headrotation2*.4,0,0);
1320 facing=DoRotation(facing,0,headrotation*.4,0);
1323 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1324 facing=DoRotation(facing,headrotation2*.8,0,0);
1325 facing=DoRotation(facing,0,headrotation*.8,0);
1328 if(targetanimation==walkanim){
1329 facing=DoRotation(facing,headrotation2*.6,0,0);
1330 facing=DoRotation(facing,0,headrotation*.6,0);
1333 skeleton.specialforward[0]=facing;
1334 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1336 for(i=0;i<skeleton.num_muscles;i++){
1337 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1339 skeleton.FindRotationMuscle(i,targetanimation);
1345 void Person::RagDoll(bool checkcollision){
1350 if(id==0)numfalls++;
1351 if(id==0&&isFlip())numflipfail++;
1357 facing=DoRotation(facing,0,rotation,0);
1359 skeleton.freetime=0;
1361 skeleton.longdead=0;
1367 skeleton.freefall=1;
1369 if(!isnormal(velocity.x))velocity.x=0;
1370 if(!isnormal(velocity.y))velocity.y=0;
1371 if(!isnormal(velocity.z))velocity.z=0;
1372 if(!isnormal(rotation))rotation=0;
1373 if(!isnormal(coords.x))coords=0;
1374 if(!isnormal(tilt))tilt=0;
1375 if(!isnormal(tilt2))tilt2=0;
1377 for(i=0;i<skeleton.num_joints;i++){
1378 skeleton.joints[i].delay=0;
1379 skeleton.joints[i].locked=0;
1380 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1381 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1382 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1383 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1384 skeleton.joints[i].position.y+=.1;
1385 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1386 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1389 for(i=0;i<skeleton.num_joints;i++){
1390 skeleton.joints[i].velocity=0;
1391 skeleton.joints[i].velchange=0;
1393 skeleton.DoConstraints(&coords,&scale);
1394 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1396 skeleton.DoConstraints(&coords,&scale);
1397 skeleton.DoConstraints(&coords,&scale);
1398 skeleton.DoConstraints(&coords,&scale);
1399 skeleton.DoConstraints(&coords,&scale);
1402 speed=animation[targetanimation].speed[targetframe]*2;
1403 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1404 speed=animation[currentanimation].speed[currentframe]*2;
1406 if(transspeed)speed=transspeed*2;
1410 for(i=0;i<skeleton.num_joints;i++){
1411 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);
1412 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1413 change.x=(float)(Random()%100)/100;
1414 change.y=(float)(Random()%100)/100;
1415 change.z=(float)(Random()%100)/100;
1416 skeleton.joints[i].velocity+=change;
1417 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1419 change.x=(float)(Random()%100)/100;
1420 change.y=(float)(Random()%100)/100;
1421 change.z=(float)(Random()%100)/100;
1422 skeleton.joints[i].velchange+=change;
1423 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1433 for(j=0;j<skeleton.num_joints;j++){
1434 average+=skeleton.joints[j].position;
1438 coords+=average*scale;
1439 for(j=0;j<skeleton.num_joints;j++){
1440 skeleton.joints[j].position-=average;
1443 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1444 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1445 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1446 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1447 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1450 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1451 coords.x=lowpoint.x;
1452 coords.z=lowpoint.z;
1461 for(i=0;i<skeleton.num_joints;i++){
1462 velocity+=skeleton.joints[i].velocity*scale;
1464 velocity/=skeleton.num_joints;
1467 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1468 weapons.owner[weaponids[0]]=-1;
1469 weapons.hitsomething[weaponids[0]]=0;
1470 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1471 weapons.velocity[weaponids[0]].x+=.01;
1472 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1473 weapons.missed[weaponids[0]]=1;
1474 weapons.freetime[weaponids[0]]=0;
1475 weapons.firstfree[weaponids[0]]=1;
1476 weapons.physics[weaponids[0]]=1;
1479 weaponids[0]=weaponids[num_weapons];
1480 if(weaponstuck==num_weapons)weaponstuck=0;
1483 for(i=0;i<numplayers;i++){
1484 player[i].wentforweapon=0;
1489 targetanimation=bounceidleanim;
1490 currentanimation=bounceidleanim;
1498 void Person::FootLand(int which, float opacity){
1499 static XYZ terrainlight;
1500 static XYZ footvel,footpoint;
1501 if(opacity>=1||skiddelay<=0)
1505 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1506 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1507 //footpoint.y=coords.y;
1508 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1510 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1512 if(footvel.y<.8)footvel.y=.8;
1513 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1514 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1515 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1516 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1517 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1518 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1520 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1522 if(footvel.y<.8)footvel.y=.8;
1523 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1524 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1525 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1526 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1527 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);
1529 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1531 if(footvel.y<.8)footvel.y=.8;
1532 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1533 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1534 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1535 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1536 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);
1537 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1539 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1542 if(footvel.y<.8)footvel.y=.8;
1543 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1544 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1545 //footpoint.y=coords.y;
1546 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1550 void Person::Puff(int whichlabel){
1551 static XYZ footvel,footpoint;
1554 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1555 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1559 void Person::DoAnimations(){
1562 static float oldtarget;
1564 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1566 if(targetanimation==tempanim||currentanimation==tempanim){
1567 animation[tempanim]=tempanimation;
1569 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1580 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1581 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1583 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1584 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1586 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1591 targfacing=DoRotation(targfacing,0,targetrotation,0);
1593 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1594 else targetanimation=backflipanim;
1595 crouchtogglekeydown=1;
1599 if(id==0)numflipped++;
1602 if(animation[targetanimation].attack!=reversed)feint=0;
1603 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1604 crouchtogglekeydown=0;
1605 if(aitype==playercontrolled)feint=0;
1609 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1610 if(!isFlip())crouchtogglekeydown=1;
1614 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1615 if(detail)normalsupdatedelay=0;
1619 if(targetanimation==rollanim&&targetframe==3&&onfire){
1621 emit_sound_at(fireendsound, coords);
1622 OPENAL_SetPaused(channels[stream_firesound], true);
1626 if(targetanimation==rabbittacklinganim&&targetframe==1){
1627 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1628 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1629 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1630 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1631 else victim->targetanimation=rabbittackledfrontanim;
1632 victim->targetframe=2;
1634 victim->rotation=rotation;
1635 victim->targetrotation=rotation;
1636 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1637 //victim->DoDamage(30);
1638 if(creature==wolftype){
1640 emit_sound_at(clawslicesound, victim->coords);
1642 victim->DoBloodBig(1/victim->armorhead,210);
1644 award_bonus(id, TackleBonus,
1645 victim->aitype == gethelptype ? 50 : 0);
1649 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1650 if(weapons.type[weaponids[0]]==knife){
1651 if(weaponactive==-1)weaponactive=0;
1652 else if(weaponactive==0)weaponactive=-1;
1654 if(weaponactive==-1){
1655 emit_sound_at(knifesheathesound, coords);
1657 if(weaponactive!=-1){
1658 emit_sound_at(knifedrawsound, coords, 128);
1661 drawtogglekeydown=1;
1664 if(tutoriallevel!=1||id==0)
1665 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1676 if(terrain.getOpacity(coords.x,coords.z)<.2){
1677 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1678 else whichsound=footstepsound2;
1679 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1680 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1681 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1687 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1688 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1689 else whichsound=footstepsound4;
1693 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1694 else whichsound=footstepsound4;
1696 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1697 if(animation[targetanimation].attack!=neutral){
1699 if(i==0)whichsound=lowwhooshsound;
1700 if(i==1)whichsound=midwhooshsound;
1701 if(i==2)whichsound=highwhooshsound;
1703 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1705 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1706 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1708 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1709 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1710 if(whichsound!=knifeswishsound)OPENAL_SetVolume(channels[whichsound], 128);
1711 if(whichsound!=knifeswishsound&&(targetanimation==staffhitanim||targetanimation==staffgroundsmashanim||targetanimation==staffspinhitanim))OPENAL_SetVolume(channels[whichsound], 256);
1712 if(whichsound==knifeswishsound)OPENAL_SetVolume(channels[whichsound], 512);
1713 OPENAL_SetPaused(channels[whichsound], false);
1716 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1717 envsound[numenvsounds]=coords;
1718 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1719 else envsoundvol[numenvsounds]=6;
1720 envsoundlife[numenvsounds]=.4;
1724 if(animation[targetanimation].label[targetframe]==3){
1726 emit_sound_at(whichsound, coords, 128.);
1731 if(tutoriallevel!=1||id==0)
1733 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1734 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1736 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1737 if(animation[targetanimation].attack!=neutral){
1739 if(creature==rabbittype){
1740 if(i==0)whichsound=rabbitattacksound;
1741 if(i==1)whichsound=rabbitattack2sound;
1742 if(i==2)whichsound=rabbitattack3sound;
1743 if(i==3)whichsound=rabbitattack4sound;
1745 if(creature==wolftype){
1746 if(i==0)whichsound=barksound;
1747 if(i==1)whichsound=bark2sound;
1748 if(i==2)whichsound=bark3sound;
1749 if(i==3)whichsound=barkgrowlsound;
1753 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1755 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1756 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1759 emit_sound_at(whichsound, coords);
1765 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1771 currentoffset=targetoffset;
1772 targetframe=currentframe;
1773 currentanimation=targetanimation;
1776 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1777 for(i=0;i<weapons.numweapons;i++){
1778 if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1779 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1780 if(findDistancefast(&coords,&weapons.position[i])>=1){
1781 if(weapons.type[i]!=staff){
1782 emit_sound_at(knifedrawsound, coords, 128.);
1786 weapons.owner[i]=id;
1788 weaponids[num_weapons]=weaponids[0];
1797 static bool willwork;
1798 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1799 for(i=0;i<weapons.numweapons;i++){
1801 if(weapons.owner[i]!=-1)
1802 if(player[weapons.owner[i]].weaponstuck!=-1)
1803 if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
1804 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
1805 if((/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)||(hasvictim&&weapons.owner[i]==victim->id&&victim->skeleton.free))
1806 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
1807 if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
1809 if(weapons.owner[i]!=-1)
1810 if(victim->weaponstuck!=-1){
1811 if(victim->weaponids[victim->weaponstuck]==i){
1816 if(weapons.type[i]!=staff){
1817 emit_sound_at(knifedrawsound, coords, 128.);
1821 emit_sound_at(fleshstabremovesound, coords, 128.);
1824 if(weapons.owner[i]!=-1){
1826 victim=&player[weapons.owner[i]];
1827 if(victim->num_weapons==1)victim->num_weapons=0;
1828 else victim->num_weapons=1;
1830 //victim->weaponactive=-1;
1831 victim->skeleton.longdead=0;
1832 victim->skeleton.free=1;
1833 victim->skeleton.broken=0;
1835 for(int j=0;j<victim->skeleton.num_joints;j++){
1836 victim->skeleton.joints[j].velchange=0;
1837 victim->skeleton.joints[j].locked=0;
1843 Normalise(&relative);
1844 XYZ footvel,footpoint;
1846 footpoint=weapons.position[i];
1847 if(victim->weaponstuck!=-1){
1848 if(victim->weaponids[victim->weaponstuck]==i){
1849 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1850 weapons.bloody[i]=2;
1851 weapons.blooddrip[i]=5;
1852 victim->weaponstuck=-1;
1855 if(victim->num_weapons>0){
1856 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1857 if(victim->weaponids[0]==i)
1858 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1861 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1862 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1863 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1864 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1866 weapons.owner[i]=id;
1868 weaponids[num_weapons]=weaponids[0];
1877 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1878 if(weaponactive==-1)weaponactive=0;
1879 else if(weaponactive==0){
1883 buffer=weaponids[0];
1884 weaponids[0]=weaponids[1];
1885 weaponids[1]=buffer;
1888 if(weaponactive==-1){
1889 emit_sound_at(knifesheathesound, coords, 128.);
1891 if(weaponactive!=-1){
1892 emit_sound_at(knifedrawsound, coords, 128.);
1897 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1898 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1899 Normalise(&rotatetarget);
1900 targetrotation=-asin(0-rotatetarget.x);
1901 targetrotation*=360/6.28;
1902 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1904 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1905 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1910 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1912 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;
1914 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1915 targetanimation=rabbittackleanim;
1917 emit_sound_at(jumpsound, coords);
1926 Normalise(&targetloc);
1928 for(i=0;i<numplayers;i++){
1930 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1931 closestdist=findDistancefast(&targetloc,&player[i].coords);
1936 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1938 victim=&player[closestid];
1939 coords=victim->coords;
1940 currentanimation=rabbittacklinganim;
1941 targetanimation=rabbittacklinganim;
1945 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1946 rotatetarget=coords-victim->coords;
1947 Normalise(&rotatetarget);
1948 targetrotation=-asin(0-rotatetarget.x);
1949 targetrotation*=360/6.28;
1950 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1952 if(targetanimation!=rabbitrunninganim){
1953 emit_sound_at(jumpsound, coords, 128.);
1959 float damagemult=1*power;
1960 if(creature==wolftype)damagemult=2.5*power;
1961 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1962 //if(onfire)damagemult=3;
1963 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1964 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1965 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1967 if(id==0)camerashake+=.4;
1968 if(Random()%2||creature==wolftype){
1971 if(creature==wolftype)DoBloodBig(0,250);
1973 if(tutoriallevel!=1){
1974 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1976 if(creature==wolftype){
1977 emit_sound_at(clawslicesound, victim->coords, 128.);
1979 victim->DoBloodBig(2/victim->armorhead,175);
1983 relative=victim->coords-coords;
1985 Normalise(&relative);
1986 relative=DoRotation(relative,0,-90,0);
1987 for(i=0;i<victim->skeleton.num_joints;i++){
1988 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1990 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1993 victim->DoDamage(damagemult*100/victim->protectionhead);
1999 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
2000 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2002 if(id==0)camerashake+=.4;
2003 if(Random()%2||creature==wolftype){
2005 if(creature==wolftype)DoBloodBig(0,235);
2007 emit_sound_at(whooshhitsound, victim->coords);
2008 if(creature==wolftype){
2009 emit_sound_at(clawslicesound, victim->coords, 128.);
2011 victim->DoBloodBig(2,175);
2015 relative=victim->coords-coords;
2017 Normalise(&relative);
2019 Normalise(&relative);
2020 relative=DoRotation(relative,0,90,0);
2021 for(i=0;i<victim->skeleton.num_joints;i++){
2022 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2024 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2027 victim->DoDamage(damagemult*50/victim->protectionhead);
2031 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
2032 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2034 if(id==0)camerashake+=.4;
2037 if(tutoriallevel!=1){
2038 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2040 if(creature==wolftype){
2041 emit_sound_at(clawslicesound, victim->coords, 128.);
2043 victim->DoBloodBig(2/victim->armorhead,175);
2049 Normalise(&relative);
2050 relative=DoRotation(relative,0,-90,0);
2051 for(i=0;i<victim->skeleton.num_joints;i++){
2052 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2054 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2057 victim->DoDamage(damagemult*150/victim->protectionhead);
2059 if(victim->damage>victim->damagetolerance)
2060 award_bonus(id, style);
2066 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2067 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2069 if(id==0)camerashake+=.4;
2072 if(tutoriallevel!=1){
2073 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2075 if(creature==wolftype){
2076 emit_sound_at(clawslicesound, victim->coords, 128.);
2078 victim->DoBloodBig(2/victim->armorhead,175);
2084 Normalise(&relative);
2085 relative=DoRotation(relative,0,90,0);
2086 for(i=0;i<victim->skeleton.num_joints;i++){
2087 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2089 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2092 victim->DoDamage(damagemult*150/victim->protectionhead);
2094 if(victim->damage>victim->damagetolerance)
2095 award_bonus(id, style);
2101 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2102 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2104 if(id==0)camerashake+=.4;
2109 emit_sound_at(whooshhitsound, victim->coords);
2112 relative=victim->coords-coords;
2114 Normalise(&relative);
2115 for(i=0;i<victim->skeleton.num_joints;i++){
2116 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2118 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2121 victim->DoDamage(damagemult*50/victim->protectionhead);
2125 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2126 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2128 if(id==0)camerashake+=.2;
2129 emit_sound_at(whooshhitsound, victim->coords, 128.);
2131 victim->skeleton.longdead=0;
2132 victim->skeleton.free=1;
2133 victim->skeleton.broken=0;
2134 victim->skeleton.spinny=1;
2136 for(i=0;i<victim->skeleton.num_joints;i++){
2137 victim->skeleton.joints[i].velchange=0;
2138 victim->skeleton.joints[i].delay=0;
2139 victim->skeleton.joints[i].locked=0;
2140 //victim->skeleton.joints[i].velocity=0;
2146 Normalise(&relative);
2147 for(i=0;i<victim->skeleton.num_joints;i++){
2148 victim->skeleton.joints[i].velocity.y=relative.y*10;
2149 victim->skeleton.joints[i].position.y+=relative.y*.3;
2150 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2151 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2153 victim->Puff(abdomen);
2154 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2158 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2159 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2161 if(id==0)camerashake+=.4;
2162 if(tutoriallevel!=1){
2163 emit_sound_at(heavyimpactsound, coords, 128.);
2166 relative=victim->coords-coords;
2168 Normalise(&relative);
2169 for(i=0;i<victim->skeleton.num_joints;i++){
2170 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2172 victim->Puff(abdomen);
2173 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2177 victim->DoDamage(damagemult*500/victim->protectionhigh);
2178 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2182 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2183 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2185 if(id==0)camerashake+=.4;
2186 if(tutoriallevel!=1){
2187 emit_sound_at(thudsound, coords);
2190 victim->skeleton.longdead=0;
2191 victim->skeleton.free=1;
2192 victim->skeleton.broken=0;
2193 victim->skeleton.spinny=1;
2195 for(i=0;i<victim->skeleton.num_joints;i++){
2196 victim->skeleton.joints[i].velchange=0;
2197 //victim->skeleton.joints[i].delay=0;
2198 victim->skeleton.joints[i].locked=0;
2201 relative=victim->coords-coords;
2202 Normalise(&relative);
2204 Normalise(&relative);
2205 for(i=0;i<victim->skeleton.num_joints;i++){
2206 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2211 victim->Puff(abdomen);
2212 victim->DoDamage(damagemult*20/victim->protectionhigh);
2213 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2215 if(!victim->dead)staggerdelay=1.2;
2221 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2222 //if(id==0)camerashake+=.4;
2225 if(!victim->skeleton.free)hasvictim=0;
2228 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2229 emit_sound_at(knifesheathesound, coords, 128.);
2232 if(victim&&hasvictim){
2233 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2235 XYZ where,startpoint,endpoint,movepoint,colpoint;
2236 float rotationpoint;
2238 if(weapons.type[weaponids[weaponactive]]==knife){
2239 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2240 where-=victim->coords;
2241 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2248 if(weapons.type[weaponids[weaponactive]]==sword){
2249 where=weapons.position[weaponids[weaponactive]];
2250 where-=victim->coords;
2251 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2253 where=weapons.tippoint[weaponids[weaponactive]];
2254 where-=victim->coords;
2255 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2258 if(weapons.type[weaponids[weaponactive]]==staff){
2259 where=weapons.position[weaponids[weaponactive]];
2260 where-=victim->coords;
2261 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2263 where=weapons.tippoint[weaponids[weaponactive]];
2264 where-=victim->coords;
2265 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2270 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2273 if(victim->dead!=2){
2274 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2276 award_bonus(id, FinishedBonus);
2278 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2280 victim->skeleton.longdead=0;
2281 victim->skeleton.free=1;
2282 victim->skeleton.broken=0;
2284 for(i=0;i<victim->skeleton.num_joints;i++){
2285 victim->skeleton.joints[i].velchange=0;
2286 victim->skeleton.joints[i].locked=0;
2287 //victim->skeleton.joints[i].velocity=0;
2289 emit_sound_at(fleshstabsound, coords, 128);
2292 if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2293 weapons.blooddrip[weaponids[weaponactive]]+=5;
2294 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2298 emit_sound_at(knifesheathesound, coords, 128.);
2304 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2306 emit_sound_at(knifedrawsound, coords, 128);
2309 if(victim&&hasvictim){
2310 XYZ footvel,footpoint;
2312 emit_sound_at(fleshstabremovesound, coords, 128.);
2315 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2317 if(weapons.type[weaponids[weaponactive]]==sword){
2318 XYZ where,startpoint,endpoint,movepoint;
2319 float rotationpoint;
2322 where=weapons.position[weaponids[weaponactive]];
2323 where-=victim->coords;
2324 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2326 where=weapons.tippoint[weaponids[weaponactive]];
2327 where-=victim->coords;
2328 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2333 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2334 footpoint+=victim->coords;
2337 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2340 if(weapons.type[weaponids[weaponactive]]==staff){
2341 XYZ where,startpoint,endpoint,movepoint;
2342 float rotationpoint;
2345 where=weapons.position[weaponids[weaponactive]];
2346 where-=victim->coords;
2347 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2349 where=weapons.tippoint[weaponids[weaponactive]];
2350 where-=victim->coords;
2351 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2356 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2357 footpoint+=victim->coords;
2360 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2363 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2365 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2366 victim->skeleton.longdead=0;
2367 victim->skeleton.free=1;
2368 victim->skeleton.broken=0;
2370 for(i=0;i<victim->skeleton.num_joints;i++){
2371 victim->skeleton.joints[i].velchange=0;
2372 victim->skeleton.joints[i].locked=0;
2373 //victim->skeleton.joints[i].velocity=0;
2379 Normalise(&relative);
2380 //victim->Puff(abdomen);
2381 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2383 if(victim->bloodloss<victim->damagetolerance){
2384 victim->bloodloss+=1000;
2388 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2392 if(!hasvictim&&onterrain){
2393 weapons.bloody[weaponids[weaponactive]]=0;
2394 weapons.blooddrip[weaponids[weaponactive]]=0;
2398 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2399 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2401 if(id==0)camerashake+=.4;
2406 if(tutoriallevel!=1){
2407 emit_sound_at(heavyimpactsound, victim->coords, 128);
2412 relative=victim->coords-coords;
2414 Normalise(&relative);
2415 for(i=0;i<victim->skeleton.num_joints;i++){
2416 victim->skeleton.joints[i].velocity=relative*30;
2418 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2420 victim->targetframe=0;
2421 victim->targetanimation=staggerbackhardanim;
2422 victim->targetrotation=targetrotation+180;
2427 victim->Puff(abdomen);
2428 victim->DoDamage(damagemult*60/victim->protectionhigh);
2435 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2436 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2438 if(id==0)camerashake+=.4;
2439 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2440 if(tutoriallevel!=1){
2441 emit_sound_at(thudsound, victim->coords);
2444 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2445 if(tutoriallevel!=1){
2446 emit_sound_at(whooshhitsound, victim->coords);
2450 if(tutoriallevel!=1){
2451 emit_sound_at(heavyimpactsound, victim->coords);
2455 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2458 relative=victim->coords-coords;
2460 Normalise(&relative);
2462 Normalise(&relative);
2463 for(i=0;i<victim->skeleton.num_joints;i++){
2464 victim->skeleton.joints[i].velocity=relative*5;
2466 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2468 victim->targetframe=0;
2469 victim->targetanimation=staggerbackhardanim;
2470 victim->targetrotation=targetrotation+180;
2474 victim->Puff(abdomen);
2475 victim->DoDamage(damagemult*60/victim->protectionhigh);
2481 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2482 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2483 if(victim->id==0)camerashake+=.4;
2484 emit_sound_at(landsound2, victim->coords);
2490 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2491 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2492 if(victim->id==0)camerashake+=.4;
2494 if(weaponactive!=-1){
2495 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2496 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2497 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2499 emit_sound_at(swordstaffsound, victim->coords);
2502 emit_sound_at(metalhitsound, victim->coords);
2510 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2511 if(weaponactive!=-1){
2514 weapons.owner[weaponids[0]]=-1;
2515 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);
2517 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2518 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2520 weapons.velocity[weaponids[0]]=aim*50;
2521 weapons.tipvelocity[weaponids[0]]=aim*50;
2522 weapons.missed[weaponids[0]]=0;
2523 weapons.hitsomething[weaponids[0]]=0;
2524 weapons.freetime[weaponids[0]]=0;
2525 weapons.firstfree[weaponids[0]]=1;
2526 weapons.physics[weaponids[0]]=0;
2529 weaponids[0]=weaponids[num_weapons];
2535 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2537 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2539 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2541 award_bonus(id, Slicebonus);
2542 if(tutoriallevel!=1){
2543 emit_sound_at(knifeslicesound, victim->coords);
2545 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2546 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2547 if(victim->id != 0 || difficulty==2){
2548 victim->targetframe=0;
2549 victim->targetanimation=staggerbackhardanim;
2550 victim->targetrotation=targetrotation+180;
2554 victim->lowreversaldelay=0;
2555 victim->highreversaldelay=0;
2556 if(aitype!=playercontrolled)weaponmissdelay=.6;
2558 if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2559 if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
2561 XYZ footvel,footpoint;
2564 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2567 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;
2569 if(tutoriallevel!=1){
2570 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2571 footvel=DoRotation(facing,0,90,0)*.8;
2573 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2574 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2575 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2576 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2578 if(tutoriallevel==1){
2579 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2581 victim->DoDamage(damagemult*0);
2584 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2585 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2586 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2587 award_bonus(id, Slashbonus);
2589 if(tutoriallevel!=1){
2590 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2591 else victim->DoBloodBig(2/victim->armorhigh,185);
2592 victim->deathbleeding=1;
2593 emit_sound_at(swordslicesound, victim->coords);
2595 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2596 if(tutoriallevel!=1){
2597 victim->targetframe=0;
2598 victim->targetanimation=staggerbackhardanim;
2599 victim->targetrotation=targetrotation+180;
2603 if(tutoriallevel!=1){
2604 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2605 weapons.blooddrip[weaponids[weaponactive]]+=3;
2607 float bloodlossamount;
2608 bloodlossamount=200+abs((float)(Random()%40))-20;
2609 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2610 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2611 victim->DoDamage(damagemult*0);
2613 XYZ footvel,footpoint;
2616 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2619 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;
2621 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2622 footvel=DoRotation(facing,0,90,0)*.8;
2624 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2625 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2626 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2627 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2631 if(victim->weaponactive!=-1){
2632 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2633 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2634 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2636 emit_sound_at(swordstaffsound, victim->coords);
2639 emit_sound_at(metalhitsound, victim->coords);
2645 victim->Puff(righthand);
2647 victim->targetframe=0;
2648 victim->targetanimation=staggerbackhighanim;
2649 victim->targetrotation=targetrotation+180;
2651 weapons.owner[victim->weaponids[0]]=-1;
2652 aim=DoRotation(facing,0,90,0)*21;
2654 weapons.velocity[victim->weaponids[0]]=aim*-.2;
2655 weapons.tipvelocity[victim->weaponids[0]]=aim;
2656 weapons.missed[victim->weaponids[0]]=1;
2657 weapons.hitsomething[weaponids[0]]=0;
2658 weapons.freetime[victim->weaponids[0]]=0;
2659 weapons.firstfree[victim->weaponids[0]]=1;
2660 weapons.physics[victim->weaponids[0]]=1;
2661 victim->num_weapons--;
2662 if(victim->num_weapons){
2663 victim->weaponids[0]=victim->weaponids[num_weapons];
2664 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2666 victim->weaponactive=-1;
2667 for(i=0;i<numplayers;i++){
2668 player[i].wentforweapon=0;
2671 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
2672 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
2673 OPENAL_SetVolume(channels[metalhitsound], 512);
2674 OPENAL_SetPaused(channels[metalhitsound], false);*/
2680 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2681 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2682 if(tutoriallevel!=1){
2683 weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
2685 if(id==0)camerashake+=.4;
2686 if(Random()%2||creature==wolftype){
2689 emit_sound_at(staffheadsound, victim->coords);
2693 relative=victim->coords-coords;
2695 Normalise(&relative);
2696 relative=DoRotation(relative,0,90,0);
2698 Normalise(&relative);
2699 for(i=0;i<victim->skeleton.num_joints;i++){
2700 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2702 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2703 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2706 if(tutoriallevel!=1){
2707 victim->DoDamage(damagemult*120/victim->protectionhigh);
2709 award_bonus(id, solidhit, 30);
2714 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2715 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2716 if(tutoriallevel!=1){
2717 weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
2719 if(id==0)camerashake+=.4;
2720 if(Random()%2||creature==wolftype){
2723 emit_sound_at(staffheadsound, victim->coords);
2727 relative=victim->coords-coords;
2729 Normalise(&relative);
2730 relative=DoRotation(relative,0,-90,0);
2731 for(i=0;i<victim->skeleton.num_joints;i++){
2732 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2734 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2735 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2738 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2740 award_bonus(id, solidhit, 60);
2745 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2746 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2748 if(tutoriallevel!=1){
2749 if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
2750 if(id==0)camerashake+=.4;
2751 if(Random()%2||creature==wolftype){
2754 emit_sound_at(staffbodysound, victim->coords);
2756 victim->skeleton.longdead=0;
2757 victim->skeleton.free=1;
2758 victim->skeleton.broken=0;
2760 for(i=0;i<victim->skeleton.num_joints;i++){
2761 victim->skeleton.joints[i].velchange=0;
2762 victim->skeleton.joints[i].locked=0;
2763 //victim->skeleton.joints[i].velocity=0;
2769 /*relative=victim->coords-coords;
2771 Normalise(&relative);
2772 relative=DoRotation(relative,0,90,0);*/
2774 Normalise(&relative);
2776 for(i=0;i<victim->skeleton.num_joints;i++){
2777 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2780 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2783 for(i=0;i<victim->skeleton.num_joints;i++){
2784 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2787 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2789 victim->Puff(abdomen);
2790 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2793 award_bonus(id, solidhit, 40);
2799 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2800 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2802 if(id==0)camerashake+=.4;
2804 relative=victim->coords-coords;
2806 Normalise(&relative);
2810 if(animation[victim->targetanimation].height==lowheight){
2816 for(i=0;i<victim->skeleton.num_joints;i++){
2817 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2819 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2820 if(tutoriallevel!=1){
2821 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2824 victim->DoDamage(damagemult*100/victim->protectionhead);
2825 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2826 if(creature==wolftype){
2827 emit_sound_at(clawslicesound, victim->coords, 128.);
2829 victim->DoBloodBig(2/victim->armorhead,175);
2833 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2834 for(i=0;i<victim->skeleton.num_joints;i++){
2835 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2837 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2838 victim->targetframe=0;
2839 victim->targetanimation=staggerbackhighanim;
2840 victim->targetrotation=targetrotation+180;
2842 if(tutoriallevel!=1){
2843 emit_sound_at(landsound2, victim->coords, 128.);
2845 victim->Puff(abdomen);
2846 victim->DoDamage(damagemult*30/victim->protectionhigh);
2847 if(creature==wolftype){
2848 emit_sound_at(clawslicesound, victim->coords, 128.);
2850 victim->DoBloodBig(2/victim->armorhigh,170);
2857 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2858 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2860 if(id==0)camerashake+=.2;
2861 if(tutoriallevel!=1){
2862 emit_sound_at(landsound2, victim->coords, 128.);
2865 relative=victim->coords-coords;
2867 Normalise(&relative);
2869 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2872 for(i=0;i<victim->skeleton.num_joints;i++){
2873 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2875 relative=DoRotation(relative,0,-90,0);
2877 for(i=0;i<victim->skeleton.num_joints;i++){
2878 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)
2879 victim->skeleton.joints[i].velocity=relative*80;
2881 victim->Puff(rightankle);
2882 victim->Puff(leftankle);
2883 victim->DoDamage(damagemult*40/victim->protectionlow);
2886 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2887 for(i=0;i<victim->skeleton.num_joints;i++){
2888 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2890 relative=DoRotation(relative,0,-90,0);
2891 for(i=0;i<victim->skeleton.num_joints;i++){
2892 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)
2893 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2895 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2896 victim->targetframe=0;
2897 victim->targetanimation=staggerbackhighanim;
2898 victim->targetrotation=targetrotation+180;
2900 if(tutoriallevel!=1){
2901 emit_sound_at(landsound2, victim->coords, 128.);
2903 victim->Puff(abdomen);
2904 victim->DoDamage(damagemult*30/victim->protectionlow);
2912 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2913 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2915 if(id==0)camerashake+=.4;
2920 if(tutoriallevel!=1){
2921 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2923 if(creature==wolftype){
2924 emit_sound_at(clawslicesound, victim->coords, 128);
2926 victim->DoBloodBig(2/victim->armorhigh,170);
2930 relative=victim->coords-oldcoords;
2932 Normalise(&relative);
2933 //relative=DoRotation(relative,0,-90,0);
2934 for(i=0;i<victim->skeleton.num_joints;i++){
2935 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2937 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2939 victim->Puff(abdomen);
2940 victim->DoDamage(damagemult*150/victim->protectionhigh);
2942 award_bonus(id, Reversal);
2945 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2946 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2947 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
2948 weapons.owner[victim->weaponids[victim->weaponactive]]=id;
2951 weaponids[num_weapons]=weaponids[victim->weaponactive];
2954 weaponids[0]=victim->weaponids[victim->weaponactive];
2955 victim->num_weapons--;
2956 if(victim->num_weapons>0){
2957 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2958 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2960 victim->weaponactive=-1;
2965 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2967 if(id==0)camerashake+=.4;
2972 emit_sound_at(whooshhitsound, victim->coords, 128.);
2975 relative=victim->coords-oldcoords;
2977 Normalise(&relative);
2978 //relative=DoRotation(relative,0,-90,0);
2979 for(i=0;i<victim->skeleton.num_joints;i++){
2980 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2982 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2985 victim->DoDamage(damagemult*70/victim->protectionhigh);
2988 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2990 if(id==0)camerashake+=.4;
2996 award_bonus(id, staffreversebonus);
2998 if(tutoriallevel!=1){
2999 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3002 award_bonus(id, staffreversebonus); // Huh, again?
3005 relative=victim->coords-oldcoords;
3007 Normalise(&relative);
3008 //relative=DoRotation(relative,0,-90,0);
3009 for(i=0;i<victim->skeleton.num_joints;i++){
3010 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3012 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3015 victim->DoDamage(damagemult*70/victim->protectionhigh);
3018 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
3024 Normalise(&relative);
3027 for(i=0;i<victim->skeleton.num_joints;i++){
3028 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3030 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
3031 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
3032 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
3033 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
3034 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
3035 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
3036 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
3037 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
3039 victim->Puff(abdomen);
3040 victim->DoDamage(damagemult*90/victim->protectionhigh);
3042 award_bonus(id, Reversal);
3046 if(weaponactive!=-1||creature==wolftype)doslice=1;
3047 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3049 if(weaponactive!=-1){
3050 victim->DoBloodBig(2/victim->armorhigh,225);
3051 emit_sound_at(knifeslicesound, victim->coords);
3052 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3053 weapons.blooddrip[weaponids[weaponactive]]+=3;
3055 if(weaponactive==-1&&creature==wolftype){;
3056 emit_sound_at(clawslicesound, victim->coords, 128.);
3058 victim->DoBloodBig(2/victim->armorhigh,175);
3065 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3071 Normalise(&relative);
3074 for(i=0;i<victim->skeleton.num_joints;i++){
3075 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3077 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3078 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3079 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3080 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3081 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3082 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3083 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3084 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3086 award_bonus(id, swordreversebonus);
3089 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3091 if(id==0)camerashake+=.4;
3096 if(tutoriallevel!=1){
3097 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3101 relative=victim->coords-oldcoords;
3103 Normalise(&relative);
3104 relative=DoRotation(relative,0,-90,0);
3105 for(i=0;i<victim->skeleton.num_joints;i++){
3106 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3108 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3110 victim->Puff(abdomen);
3111 victim->DoDamage(damagemult*30/victim->protectionhigh);
3113 award_bonus(id, Reversal);
3116 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3119 victim->skeleton.spinny=0;
3123 Normalise(&relative);
3124 if(victim->id==0)relative/=30;
3125 for(i=0;i<victim->skeleton.num_joints;i++){
3126 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3128 //victim->DoDamage(1000);
3129 victim->damage=victim->damagetolerance;
3130 victim->permanentdamage=victim->damagetolerance-1;
3133 if(weaponactive!=-1||creature==wolftype)doslice=1;
3134 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3136 if(weaponactive!=-1){
3137 victim->DoBloodBig(200,225);
3138 emit_sound_at(knifeslicesound, victim->coords);
3139 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3140 weapons.blooddrip[weaponids[weaponactive]]+=5;
3143 if(creature==wolftype&&weaponactive==-1){
3144 emit_sound_at(clawslicesound, victim->coords, 128.);
3146 victim->DoBloodBig(2,175);
3149 award_bonus(id, spinecrusher);
3152 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3153 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3155 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3156 if(targetanimation==knifesneakattackanim){
3157 /*victim->DoBloodBig(200,195);
3162 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3163 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3165 XYZ footvel,footpoint;
3167 footpoint=weapons.tippoint[weaponids[0]];
3168 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3169 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3170 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3171 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3172 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3173 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3174 victim->DoBloodBig(200,195);
3175 award_bonus(id, tracheotomy);
3177 if(targetanimation==knifefollowanim){
3178 award_bonus(id, Stabbonus);
3179 XYZ footvel,footpoint;
3181 footpoint=weapons.tippoint[weaponids[0]];
3182 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3183 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3184 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3185 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3186 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3187 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3190 victim->bloodloss+=10000;
3192 emit_sound_at(fleshstabsound, victim->coords);
3193 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3194 weapons.blooddrip[weaponids[weaponactive]]+=5;
3198 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3201 for(i=0;i<victim->skeleton.num_joints;i++){
3202 victim->skeleton.joints[i].velocity=0;
3204 if(targetanimation==knifefollowanim){
3206 for(i=0;i<victim->skeleton.num_joints;i++){
3207 victim->skeleton.joints[i].velocity=0;
3210 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3211 emit_sound_at(fleshstabremovesound, victim->coords);
3212 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3213 weapons.blooddrip[weaponids[weaponactive]]+=5;
3215 XYZ footvel,footpoint;
3217 footpoint=weapons.tippoint[weaponids[0]];
3218 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3219 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3220 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3221 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3222 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3223 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3227 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3228 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3229 award_bonus(id, backstab);
3233 XYZ footvel,footpoint;
3235 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3236 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3237 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3238 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3239 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3240 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3241 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3242 victim->DoBloodBig(200,180);
3243 victim->DoBloodBig(200,215);
3244 victim->bloodloss+=10000;
3246 emit_sound_at(fleshstabsound, victim->coords);
3247 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3248 weapons.blooddrip[weaponids[weaponactive]]+=5;
3252 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3255 for(i=0;i<victim->skeleton.num_joints;i++){
3256 victim->skeleton.joints[i].velocity=0;
3258 if(weaponactive!=-1){
3259 emit_sound_at(fleshstabremovesound, victim->coords);
3260 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3261 weapons.blooddrip[weaponids[weaponactive]]+=5;
3263 XYZ footvel,footpoint;
3265 footpoint=weapons.tippoint[weaponids[0]];
3266 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3267 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3268 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3269 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3270 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3271 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3275 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3277 if(id==0)camerashake+=.4;
3282 if(weaponactive==-1){
3283 if(tutoriallevel!=1){
3284 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3289 if(weaponactive!=-1||creature==wolftype)doslice=1;
3290 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3292 if(weaponactive!=-1){
3293 victim->DoBloodBig(2/victim->armorhead,225);
3294 emit_sound_at(knifeslicesound, victim->coords);
3295 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3296 weapons.blooddrip[weaponids[weaponactive]]+=3;
3298 if(weaponactive==-1&&creature==wolftype){
3299 emit_sound_at(clawslicesound, victim->coords, 128.);
3301 victim->DoBloodBig(2/victim->armorhead,175);
3305 award_bonus(id, Reversal);
3310 //relative=victim->coords-oldcoords;
3313 Normalise(&relative);
3314 relative=DoRotation(relative,0,90,0);
3316 Normalise(&relative);
3317 for(i=0;i<victim->skeleton.num_joints;i++){
3318 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3320 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3321 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3322 victim->DoDamage(damagemult*100/victim->protectionhead);
3326 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3330 //relative=victim->coords-oldcoords;
3333 Normalise(&relative);
3334 relative=DoRotation(relative,0,90,0);
3336 Normalise(&relative);
3337 for(i=0;i<victim->skeleton.num_joints;i++){
3338 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3340 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3343 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3344 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3345 award_bonus(id, reverseko);
3351 if(targetframe>animation[currentanimation].numframes-1){
3354 targetanimation=getIdle();
3358 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3359 targetanimation=rollanim;
3361 emit_sound_at(movewhooshsound, coords, 128.);
3363 if(currentanimation==staggerbackhighanim){
3364 targetanimation=getIdle();
3366 if(currentanimation==staggerbackhardanim){
3367 targetanimation=getIdle();
3369 if(currentanimation==removeknifeanim){
3370 targetanimation=getIdle();
3372 if(currentanimation==crouchremoveknifeanim){
3373 targetanimation=getCrouch();
3375 if(currentanimation==backhandspringanim){
3376 targetanimation=getIdle();
3378 if(currentanimation==dodgebackanim){
3379 targetanimation=getIdle();
3381 if(currentanimation==drawleftanim){
3382 targetanimation=getIdle();
3384 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3385 targetanimation=getIdle();
3386 if(currentanimation==crouchdrawrightanim){
3387 targetanimation=getCrouch();
3389 if(weaponactive==-1)weaponactive=0;
3390 else if(weaponactive==0){
3394 buffer=weaponids[0];
3395 weaponids[0]=weaponids[1];
3396 weaponids[1]=buffer;
3400 if(weaponactive==-1){
3401 emit_sound_at(knifesheathesound, coords, 128.);
3403 if(weaponactive!=-1){
3404 emit_sound_at(knifedrawsound, coords, 128.);
3407 if(currentanimation==rollanim){
3408 targetanimation=getCrouch();
3413 if(targetanimation==walljumprightkickanim){
3416 if(targetanimation==walljumpleftkickanim){
3419 targetanimation=jumpdownanim;
3421 if(currentanimation==climbanim){
3422 targetanimation=getCrouch();
3425 if(!isnormal(coords.x))
3436 if(targetanimation==rabbitkickreversalanim){
3437 targetanimation=getCrouch();
3440 if(targetanimation==jumpreversalanim){
3441 targetanimation=getCrouch();
3444 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3445 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3447 float closestdist=-1;
3450 for(i=0;i<numplayers;i++){
3451 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3452 distance=findDistancefast(&player[i].coords,&coords);
3453 if(closestdist==-1||distance<closestdist){
3454 closestdist=distance;
3459 if(closestdist>0&&closest>=0&&closestdist<16){
3460 victim=&player[closest];
3461 targetanimation=walljumprightkickanim;
3463 XYZ rotatetarget=victim->coords-coords;
3464 Normalise(&rotatetarget);
3465 rotation=-asin(0-rotatetarget.x);
3467 if(rotatetarget.z<0)rotation=180-rotation;
3468 targettilt2=-asin(rotatetarget.y)*360/6.28;
3469 velocity=(victim->coords-coords)*4;
3474 if(targetanimation==walljumpbackanim){
3475 targetanimation=backflipanim;
3479 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3481 if(targetanimation==walljumprightanim){
3482 targetanimation=rightflipanim;
3486 velocity=DoRotation(facing,0,30,0)*-8;
3489 if(targetanimation==walljumpfrontanim){
3490 targetanimation=frontflipanim;
3492 //targetrotation-=180;
3497 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3499 if(targetanimation==walljumpleftanim){
3502 float closestdist=-1;
3505 for(i=0;i<numplayers;i++){
3506 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3507 distance=findDistancefast(&player[i].coords,&coords);
3508 if(closestdist==-1||distance<closestdist){
3509 closestdist=distance;
3514 if(closestdist>0&&closest>=0&&closestdist<16){
3515 victim=&player[closest];
3516 targetanimation=walljumpleftkickanim;
3518 XYZ rotatetarget=victim->coords-coords;
3519 Normalise(&rotatetarget);
3520 rotation=-asin(0-rotatetarget.x);
3522 if(rotatetarget.z<0)rotation=180-rotation;
3523 targettilt2=-asin(rotatetarget.y)*360/6.28;
3524 velocity=(victim->coords-coords)*4;
3529 if(targetanimation!=walljumpleftkickanim){
3530 targetanimation=leftflipanim;
3534 velocity=DoRotation(facing,0,-30,0)*-8;
3537 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3539 if(targetanimation==sneakattackanim){
3540 float ycoords=oldcoords.y;
3541 currentanimation=getCrouch();
3542 targetanimation=getCrouch();
3545 targetrotation+=180;
3550 targetheadrotation+=180;
3552 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3556 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3557 float ycoords=oldcoords.y;
3558 targetanimation=getIdle();
3560 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3564 if(currentanimation==knifefollowanim){
3565 targetanimation=getIdle();
3568 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3569 float ycoords=oldcoords.y;
3570 targetanimation=getStop();
3571 targetrotation+=180;
3576 targetheadrotation+=180;
3577 if(!isnormal(coords.x))
3579 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3580 oldcoords=coords+facing*.5;
3581 else if(currentanimation==sweepreversalanim)
3582 oldcoords=coords+facing*1.1;
3583 else if(currentanimation==upunchreversalanim){
3584 oldcoords=coords+facing*1.5;
3585 targetrotation+=180;
3587 targetheadrotation+=180;
3591 else if(currentanimation==knifeslashreversalanim){
3592 oldcoords=coords+facing*.5;
3595 targetheadrotation+=90;
3599 else if(currentanimation==staffspinhitreversalanim){
3600 targetrotation+=180;
3602 targetheadrotation+=180;
3606 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3607 else oldcoords.y=ycoords;
3608 currentoffset=coords-oldcoords;
3614 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3619 if(animation[targetanimation].attack==reversed){
3621 if(targetanimation==sweepreversedanim)targetrotation+=90;
3622 targetanimation=backhandspringanim;
3624 emit_sound_at(landsound, coords, 128);
3626 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3627 targetanimation=rollanim;
3630 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3631 coords.y=oldcoords.y;
3633 if(currentanimation==knifeslashreversedanim){
3634 targetanimation=rollanim;
3639 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3640 coords.y=oldcoords.y;
3644 targetanimation=jumpdownanim;
3646 if(wasLanding())targetanimation=getIdle();
3647 if(wasLandhard())targetanimation=getIdle();
3648 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3649 targetanimation=getIdle();
3651 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3652 coords.y=oldcoords.y;
3653 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3654 targetoffset.y=coords.y;
3655 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3656 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3657 currentoffset.y-=(coords.y-targetoffset.y);
3658 coords.y=targetoffset.y;
3660 normalsupdatedelay=0;
3662 if(currentanimation==upunchanim){
3663 targetanimation=getStop();
3664 normalsupdatedelay=0;
3667 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3668 targetrotation=rotation;
3671 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
3672 if(!hasstaff)DoDamage(35);
3675 rabbitkickragdoll=1;
3677 if(currentanimation==rabbitkickreversedanim){
3684 SolidHitBonus(!id); // FIXME: tricky id
3688 targetanimation=rollanim;
3690 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3694 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3700 if(currentanimation==jumpreversedanim){
3707 SolidHitBonus(!id); // FIXME: tricky id
3711 targetanimation=rollanim;
3713 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3718 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){
3719 targetanimation=getupfromfrontanim;
3722 else if(animation[currentanimation].attack==normalattack){
3723 targetanimation=getIdle();
3726 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3727 targetanimation=blockhighleftstrikeanim;
3729 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3730 targetanimation=getIdle();
3733 if(currentanimation==spinkickanim&&victim->skeleton.free){
3734 if(creature==rabbittype)targetanimation=fightidleanim;
3739 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3741 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3742 targetanimation=jumpdownanim;
3747 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3748 if(!isRun()||!wasRun()){
3749 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3750 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3751 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3752 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3754 if(isRun()&&wasRun()){
3757 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3758 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3761 else if(transspeed)target+=multiplier*transspeed*speed*2;
3763 if(!isRun()||!wasRun()){
3764 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3765 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3766 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3767 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3771 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3773 if(target>1){currentframe=targetframe; target=1;}
3775 rot=targetrot*target;
3776 rotation+=rot-oldrot;
3782 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3784 for(i=0;i<skeleton.num_joints;i++){
3785 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3788 skeleton.FindForwards();
3790 for(i=0;i<skeleton.num_muscles;i++){
3791 if(skeleton.muscles[i].visible)
3793 skeleton.FindRotationMuscle(i,targetanimation);
3796 for(i=0;i<skeleton.num_muscles;i++){
3797 if(skeleton.muscles[i].visible)
3799 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3800 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3801 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3806 for(i=0;i<skeleton.num_joints;i++){
3807 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3810 skeleton.FindForwards();
3812 for(i=0;i<skeleton.num_muscles;i++){
3813 if(skeleton.muscles[i].visible)
3815 skeleton.FindRotationMuscle(i,targetanimation);
3818 for(i=0;i<skeleton.num_muscles;i++){
3819 if(skeleton.muscles[i].visible)
3821 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3822 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3823 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3824 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3825 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3826 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3827 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3828 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3829 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3833 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3835 oldcurrentanimation=currentanimation;
3836 oldtargetanimation=targetanimation;
3837 oldtargetframe=targetframe;
3838 oldcurrentframe=currentframe;
3840 for(i=0;i<skeleton.num_joints;i++){
3841 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3842 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3844 offset=currentoffset*(1-target)+targetoffset*target;
3845 for(i=0;i<skeleton.num_muscles;i++){
3846 if(skeleton.muscles[i].visible)
3848 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3849 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3850 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3855 if(isLanding()&&landhard){
3856 if(id==0)camerashake+=.4;
3857 targetanimation=getLandhard();
3864 //skeleton.DoConstraints();
3867 void Person::DoStuff(){
3868 static XYZ terrainnormal;
3869 static XYZ flatfacing;
3870 static XYZ flatvelocity;
3871 static float flatvelspeed;
3875 static int bloodsize;
3876 static int startx,starty,endx,endy;
3877 static int texdetailint;
3878 static GLubyte color;
3879 static XYZ bloodvel;
3881 onfiredelay-=multiplier;
3882 if(onfiredelay<0&&onfire)
3890 crouchkeydowntime+=multiplier;
3891 if(!crouchkeydown)crouchkeydowntime=0;
3892 jumpkeydowntime+=multiplier;
3893 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3895 if(hostile||damage>0||bloodloss>0)immobile=0;
3897 if(isIdle()||isRun())targetoffset=0;
3899 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3901 if(id==0)blooddimamount-=multiplier*.3;
3902 speechdelay-=multiplier;
3903 texupdatedelay-=multiplier;
3904 interestdelay-=multiplier;
3905 flamedelay-=multiplier;
3906 parriedrecently-=multiplier;
3912 if(id==0)speed=1.1*speedmult;
3913 else speed=1.0*speedmult;
3914 if(!skeleton.free)rabbitkickragdoll=0;
3918 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3919 if(id!=0&&creature==wolftype&&difficulty==2){
3921 if(aitype!=passivetype){
3923 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){
3927 if(scale<0.2)superruntoggle=0;
3928 if(targetanimation==wolfrunninganim&&!superruntoggle){
3929 targetanimation=getRun();
3933 if(weaponactive==-1&&num_weapons>0){
3934 if(weapons.type[weaponids[0]]==staff){
3941 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3942 /*if(aitype!=playercontrolled)*/
3944 if(burnt>.6)burnt=.6;
3945 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3947 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3958 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3959 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3963 while(flamedelay<0&&onfire){
3965 howmany=abs(Random()%(skeleton.num_joints));
3966 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3967 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3968 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3969 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3970 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3973 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3975 howmany=abs(Random()%(skeleton.num_joints));
3976 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3977 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3978 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3979 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3980 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3984 bleeding-=multiplier*.3;
3986 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3987 if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
3991 if(neckspurtamount>0){
3992 neckspurtamount-=multiplier;
3993 neckspurtdelay-=multiplier*3;
3994 neckspurtparticledelay-=multiplier*3;
3995 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3999 bloodvel.z=5*neckspurtamount;
4000 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4003 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
4005 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4006 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
4007 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);
4008 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);
4009 neckspurtparticledelay=.05;
4011 if(neckspurtdelay<0){
4016 if(deathbleeding>0&&dead!=2){
4017 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
4018 else bleeddelay-=5*multiplier/4;
4019 if(bleeddelay<0&&bloodtoggle){
4024 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
4025 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
4026 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
4027 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);
4030 bloodloss+=deathbleeding*multiplier*80;
4031 deathbleeding-=multiplier*1.6;
4032 //if(id==0)deathbleeding-=multiplier*.2;
4033 if(deathbleeding<0)deathbleeding=0;
4034 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
4035 if(weaponactive!=-1){
4036 weapons.owner[weaponids[0]]=-1;
4037 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4038 weapons.velocity[weaponids[0]].x+=.01;
4039 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4040 weapons.missed[weaponids[0]]=1;
4041 weapons.hitsomething[weaponids[0]]=0;
4042 weapons.freetime[weaponids[0]]=0;
4043 weapons.firstfree[weaponids[0]]=1;
4044 weapons.physics[weaponids[0]]=1;
4047 weaponids[0]=weaponids[num_weapons];
4048 if(weaponstuck==num_weapons)weaponstuck=0;
4051 for(i=0;i<numplayers;i++){
4052 player[i].wentforweapon=0;
4064 if(!dead&&creature==wolftype){
4065 award_bonus(0, Wolfbonus);
4068 if(targetanimation==knifefollowedanim&&!skeleton.free){
4069 for(i=0;i<skeleton.num_joints;i++){
4070 skeleton.joints[i].velocity=0;
4071 skeleton.joints[i].velocity.y=-2;
4074 if(id!=0&&unconscioustime>.1){
4082 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
4085 bloodsize=5-realtexdetail;
4089 texdetailint=realtexdetail;
4090 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4091 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4092 endx=startx+bloodsize;
4093 endy=starty+bloodsize;
4095 if(startx<0){startx=0;bleeding=0;}
4096 if(starty<0){starty=0;bleeding=0;}
4097 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
4098 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
4099 if(endx<startx)endx=startx;
4100 if(endy<starty)endy=starty;
4102 for(i=startx;i<endx;i++){
4103 for(j=starty;j<endy;j++){
4105 color=Random()%85+170;
4106 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
4107 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
4108 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
4113 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4114 DoMipmaps(0,startx,endx,starty,endy);
4118 bleedy-=4/realtexdetail;
4119 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
4120 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
4123 bleedx+=4*direction/realtexdetail;
4124 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
4125 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4129 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4130 righthandmorphness=targetrighthandmorphness;
4131 righthandmorphstart=righthandmorphend;
4133 else if(righthandmorphness>targetrighthandmorphness){
4134 righthandmorphness-=multiplier*4;
4136 else if(righthandmorphness<targetrighthandmorphness){
4137 righthandmorphness+=multiplier*4;
4140 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4141 lefthandmorphness=targetlefthandmorphness;
4142 lefthandmorphstart=lefthandmorphend;
4144 else if(lefthandmorphness>targetlefthandmorphness){
4145 lefthandmorphness-=multiplier*4;
4147 else if(lefthandmorphness<targetlefthandmorphness){
4148 lefthandmorphness+=multiplier*4;
4151 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4152 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4153 tailmorphness=targettailmorphness;
4154 tailmorphstart=tailmorphend;
4156 else if(tailmorphness>targettailmorphness){
4157 tailmorphness-=multiplier*10;
4159 else if(tailmorphness<targettailmorphness){
4160 tailmorphness+=multiplier*10;
4164 if(creature==wolftype){
4165 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4166 tailmorphness=targettailmorphness;
4167 tailmorphstart=tailmorphend;
4169 else if(tailmorphness>targettailmorphness){
4170 tailmorphness-=multiplier*2;
4172 else if(tailmorphness<targettailmorphness){
4173 tailmorphness+=multiplier*2;
4177 if(headmorphend==3||headmorphstart==3){
4178 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4179 headmorphness=targetheadmorphness;
4180 headmorphstart=headmorphend;
4182 else if(headmorphness>targetheadmorphness){
4183 headmorphness-=multiplier*7;
4185 else if(headmorphness<targetheadmorphness){
4186 headmorphness+=multiplier*7;
4189 else if(headmorphend==5||headmorphstart==5){
4190 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4191 headmorphness=targetheadmorphness;
4192 headmorphstart=headmorphend;
4194 else if(headmorphness>targetheadmorphness){
4195 headmorphness-=multiplier*10;
4197 else if(headmorphness<targetheadmorphness){
4198 headmorphness+=multiplier*10;
4202 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4203 headmorphness=targetheadmorphness;
4204 headmorphstart=headmorphend;
4206 else if(headmorphness>targetheadmorphness){
4207 headmorphness-=multiplier*4;
4209 else if(headmorphness<targetheadmorphness){
4210 headmorphness+=multiplier*4;
4214 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4215 chestmorphness=targetchestmorphness;
4216 chestmorphstart=chestmorphend;
4218 else if(chestmorphness>targetchestmorphness){
4219 chestmorphness-=multiplier;
4221 else if(chestmorphness<targetchestmorphness){
4222 chestmorphness+=multiplier;
4225 if(dead!=2&&howactive<=typesleeping){
4226 if(chestmorphstart==0&&chestmorphend==0){
4228 targetchestmorphness=1;
4231 if(chestmorphstart!=0&&chestmorphend!=0){
4233 targetchestmorphness=1;
4235 if(environment==snowyenvironment){
4238 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4239 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4240 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4241 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4242 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4243 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4247 if(!dead&&howactive<typesleeping){
4248 blinkdelay-=multiplier*2;
4249 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4251 targetheadmorphness=1;
4253 blinkdelay=(float)(abs(Random()%40))/5;
4255 if(headmorphstart==3&&headmorphend==3){
4257 targetheadmorphness=1;
4262 twitchdelay-=multiplier*1.5;
4263 if(targetanimation!=hurtidleanim){
4264 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4266 targetheadmorphness=1;
4268 twitchdelay=(float)(abs(Random()%40))/5;
4270 if(headmorphstart==5&&headmorphend==5){
4272 targetheadmorphness=1;
4276 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4277 twitchdelay3-=multiplier*1;
4279 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4280 righthandmorphness=0;
4281 targetrighthandmorphness=1;
4282 righthandmorphend=1;
4283 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4285 if(righthandmorphstart==1&&righthandmorphend==1){
4286 righthandmorphness=0;
4287 targetrighthandmorphness=1;
4288 righthandmorphend=0;
4292 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4293 lefthandmorphness=0;
4294 targetlefthandmorphness=1;
4296 twitchdelay3=(float)(abs(Random()%40))/5;
4298 if(lefthandmorphstart==1&&lefthandmorphend==1){
4299 lefthandmorphness=0;
4300 targetlefthandmorphness=1;
4307 if(creature==rabbittype){
4308 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4309 else twitchdelay2-=multiplier*0.5;
4310 if(howactive<=typesleeping){
4311 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4313 targettailmorphness=1;
4315 twitchdelay2=(float)(abs(Random()%40))/5;
4317 if(tailmorphstart==1&&tailmorphend==1){
4319 targettailmorphness=1;
4322 if(tailmorphstart==2&&tailmorphend==2){
4324 targettailmorphness=1;
4331 if(creature==wolftype){
4332 twitchdelay2-=multiplier*1.5;
4334 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4336 targettailmorphness=1;
4341 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4343 targettailmorphness=1;
4347 if(twitchdelay2<=0){
4348 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4350 targettailmorphness=1;
4353 if(tailmorphstart==1&&tailmorphend==1){
4355 targettailmorphness=1;
4358 if(tailmorphstart==2&&tailmorphend==2){
4360 targettailmorphness=1;
4363 if(tailmorphstart==3&&tailmorphend==3){
4365 targettailmorphness=1;
4368 if(tailmorphstart==4&&tailmorphend==4){
4370 targettailmorphness=1;
4376 if(dead!=1)unconscioustime=0;
4378 if(dead==1||howactive==typesleeping){
4379 unconscioustime+=multiplier;
4380 //If unconscious, close eyes and mouth
4381 if(righthandmorphend!=0)righthandmorphness=0;
4382 righthandmorphend=0;
4383 targetrighthandmorphness=1;
4385 if(lefthandmorphend!=0)lefthandmorphness=0;
4387 targetlefthandmorphness=1;
4389 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4391 targetheadmorphness=1;
4395 if(howactive>typesleeping){
4398 if(bloodtoggle&&!bled){
4399 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4401 if(bloodtoggle&&!bled)
4402 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4403 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4404 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4408 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4413 if(dead==2||howactive>typesleeping){
4414 //If dead, open mouth and hands
4415 if(righthandmorphend!=0)righthandmorphness=0;
4416 righthandmorphend=0;
4417 targetrighthandmorphness=1;
4419 if(lefthandmorphend!=0)lefthandmorphness=0;
4421 targetlefthandmorphness=1;
4423 if(headmorphend!=2)headmorphness=0;
4425 targetheadmorphness=1;
4428 if(stunned>0&&!dead&&headmorphend!=2){
4429 if(headmorphend!=4)headmorphness=0;
4431 targetheadmorphness=1;
4434 if(damage>damagetolerance&&!dead){
4439 if(creature==wolftype){
4440 award_bonus(0, Wolfbonus);
4445 if(weaponactive!=-1){
4446 weapons.owner[weaponids[0]]=-1;
4447 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4448 weapons.velocity[weaponids[0]].x+=.01;
4449 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4450 weapons.missed[weaponids[0]]=1;
4451 weapons.hitsomething[weaponids[0]]=0;
4452 weapons.freetime[weaponids[0]]=0;
4453 weapons.firstfree[weaponids[0]]=1;
4454 weapons.physics[weaponids[0]]=1;
4457 weaponids[0]=weaponids[num_weapons];
4458 if(weaponstuck==num_weapons)weaponstuck=0;
4461 for(i=0;i<numplayers;i++){
4462 player[i].wentforweapon=0;
4468 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4476 //if(dead)damage-=multiplier/4;
4477 if(!dead)damage-=multiplier*13;
4478 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4479 if(!dead)permanentdamage-=multiplier*4;
4480 if(isIdle()||isCrouch()){
4481 if(!dead)permanentdamage-=multiplier*4;
4482 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4484 if(damage<0)damage=0;
4485 if(permanentdamage<0)permanentdamage=0;
4486 if(superpermanentdamage<0)superpermanentdamage=0;
4487 if(permanentdamage<superpermanentdamage){
4488 permanentdamage=superpermanentdamage;
4490 if(damage<permanentdamage){
4491 damage=permanentdamage;
4493 if(dead==1&&damage<damagetolerance){
4497 for(i=0;i<skeleton.num_joints;i++){
4498 skeleton.joints[i].velocity=0;
4501 if(permanentdamage>damagetolerance&&dead!=2){
4504 if(weaponactive!=-1){
4505 weapons.owner[weaponids[0]]=-1;
4506 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4507 weapons.velocity[weaponids[0]].x+=.01;
4508 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4509 weapons.missed[weaponids[0]]=1;
4510 weapons.hitsomething[weaponids[0]]=0;
4511 weapons.freetime[weaponids[0]]=0;
4512 weapons.firstfree[weaponids[0]]=1;
4513 weapons.physics[weaponids[0]]=1;
4516 weaponids[0]=weaponids[num_weapons];
4517 if(weaponstuck==num_weapons)weaponstuck=0;
4520 for(i=0;i<numplayers;i++){
4521 player[i].wentforweapon=0;
4527 if(!dead&&creature==wolftype){
4528 award_bonus(0, Wolfbonus);
4531 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4532 award_bonus(id, touchofdeath);
4533 if(id!=0&&unconscioustime>.1){
4541 emit_sound_at(breaksound, coords);
4542 /*if(id==0||findDistancefast(&coords,&viewer)<50){
4548 if(skeleton.free==1){
4549 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4552 //If knocked over, open hands and close mouth
4553 if(righthandmorphend!=0)righthandmorphness=0;
4554 righthandmorphend=0;
4555 targetrighthandmorphness=1;
4557 if(lefthandmorphend!=0)lefthandmorphness=0;
4559 targetlefthandmorphness=1;
4561 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4562 if(headmorphend!=0)headmorphness=0;
4564 targetheadmorphness=1;
4568 skeleton.DoGravity(&scale);
4570 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4571 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4572 award_bonus(id, deepimpact);
4573 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4577 for(j=0;j<skeleton.num_joints;j++){
4578 average+=skeleton.joints[j].position;
4582 coords+=average*scale;
4583 for(j=0;j<skeleton.num_joints;j++){
4584 skeleton.joints[j].position-=average;
4586 average/=multiplier;
4588 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4590 for(i=0;i<skeleton.num_joints;i++){
4591 velocity+=skeleton.joints[i].velocity*scale;
4593 velocity/=skeleton.num_joints;
4595 if(!isnormal(velocity.x)&&velocity.x){
4608 if(findLength(&average)<10&&dead&&skeleton.free){
4609 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4610 if(skeleton.longdead>2000){
4611 if(skeleton.longdead>6000){
4612 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4617 if(dead==2&&bloodloss<damagetolerance){
4619 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4621 if(bloodtoggle&&!bled){
4622 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4624 if(bloodtoggle&&!bled)
4625 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4626 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4627 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4631 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4635 if(dead==2&&bloodloss>=damagetolerance){
4637 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4638 if(bleeding<=0)DoBlood(1,255);
4639 if(bloodtoggle&&!bled){
4640 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4642 if(bloodtoggle&&!bled)
4643 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4644 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4645 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4649 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4656 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4658 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4662 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4663 if(velocity.y<-30)canrecover=0;
4664 for(i=0;i<objects.numobjects;i++){
4665 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4666 colviewer=startpoint;
4668 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4676 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4677 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4678 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4679 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4681 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4682 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4683 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4685 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4686 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4687 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4689 Normalise(&terrainnormal);
4691 targetrotation=-asin(0-terrainnormal.x);
4692 targetrotation*=360/6.28;
4693 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4694 rotation=targetrotation;
4698 targetanimation=flipanim;
4699 crouchtogglekeydown=1;
4704 currentanimation=tempanim;
4707 //tilt2=targettilt2;
4709 //if(middle.y>0)targetoffset.y=middle.y+1;
4711 for(i=0;i<skeleton.num_joints;i++){
4712 tempanimation.position[i][0]=skeleton.joints[i].position;
4713 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4718 if(findLength(&average)<10&&!dead&&skeleton.free){
4719 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4720 if(skeleton.longdead>(damage+500)*1.5){
4721 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4727 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4728 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4729 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4730 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4732 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4733 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4734 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4736 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4737 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4738 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4740 Normalise(&terrainnormal);
4742 targetrotation=-asin(0-terrainnormal.x);
4743 targetrotation*=360/6.28;
4744 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4745 rotation=targetrotation;
4748 terrainnormal=terrain.getNormal(coords.x,coords.z);
4749 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4753 /*XYZ otherterrainnormal;
4754 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
4755 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4756 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4757 targettilt2=asin(otherterrainnormal.y)*180/3.14;
4760 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4764 if(skeleton.forward.y<0){
4765 targetanimation=getupfrombackanim;
4769 if(skeleton.forward.y>-.3){
4770 targetanimation=getupfromfrontanim;
4772 targetrotation+=180;
4778 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4779 targetanimation=rollanim;
4780 targetrotation=lookrotation;
4784 if(forwardkeydown)targetrotation+=45;
4785 if(backkeydown)targetrotation-=45;
4789 if(forwardkeydown)targetrotation-=45;
4790 if(backkeydown)targetrotation+=45;
4793 if ( !leftkeydown&&!rightkeydown)
4794 targetrotation+=180;
4796 targetrotation+=180;
4800 if(abs(targettilt2)>50)targettilt2=0;
4801 currentanimation=tempanim;
4806 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4808 for(i=0;i<skeleton.num_joints;i++){
4809 tempanimation.position[i][0]=skeleton.joints[i].position;
4810 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4817 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4818 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4821 tempvelocity=velocity;
4822 Normalise(&tempvelocity);
4823 targetrotation=-asin(0-tempvelocity.x);
4824 targetrotation*=360/6.28;
4825 if(velocity.z<0)targetrotation=180-targetrotation;
4826 //targetrotation+=180;
4829 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4830 targetanimation=rollanim;
4834 targetanimation=backhandspringanim;
4835 targetrotation+=180;
4840 emit_sound_at(movewhooshsound, coords, 128.);
4842 currentanimation=targetanimation;
4843 currentframe=targetframe-1;
4848 rotation=targetrotation;
4855 if(skeleton.freefall==0)freefall=0;
4857 if(!isnormal(velocity.x)&&velocity.x){
4862 if(aitype!=passivetype||skeleton.free==1)
4863 if(findLengthfast(&velocity)>.1)
4864 for(i=0;i<objects.numobjects;i++){
4865 if(objects.type[i]==firetype)
4866 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){
4868 if(!objects.onfire[i]){
4869 emit_sound_at(firestartsound, objects.position[i]);
4871 objects.onfire[i]=1;
4874 if(objects.onfire[i]){
4879 if(objects.type[i]==bushtype)
4880 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){
4882 if(!objects.onfire[i]){
4883 emit_sound_at(firestartsound, objects.position[i]);
4885 objects.onfire[i]=1;
4889 if(objects.onfire[i]){
4893 if(objects.messedwith[i]<=0){
4897 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4900 envsound[numenvsounds]=coords;
4901 envsoundvol[numenvsounds]=4*findLength(&velocity);
4902 envsoundlife[numenvsounds]=.4;
4907 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4908 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4910 if(environment!=desertenvironment)
4911 for(j=0;j<howmany;j++){
4912 tempvel.x=float(abs(Random()%100)-50)/20;
4913 tempvel.y=float(abs(Random()%100)-50)/20;
4914 tempvel.z=float(abs(Random()%100)-50)/20;
4917 pos.x+=float(abs(Random()%100)-50)/200;
4918 pos.y+=float(abs(Random()%100)-50)/200;
4919 pos.z+=float(abs(Random()%100)-50)/200;
4920 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);
4921 Sprite::setLastSpriteSpecial(1);
4923 howmany=findLength(&velocity)*4;
4925 if(environment==snowyenvironment)
4926 for(j=0;j<howmany;j++){
4927 tempvel.x=float(abs(Random()%100)-50)/20;
4928 tempvel.y=float(abs(Random()%100)-50)/20;
4929 tempvel.z=float(abs(Random()%100)-50)/20;
4932 pos.x+=float(abs(Random()%100)-50)/200;
4933 pos.y+=float(abs(Random()%100)-50)/200;
4934 pos.z+=float(abs(Random()%100)-50)/200;
4935 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4936 Sprite::setLastSpriteSpecial(2);
4939 objects.rotx[i]+=velocity.x*multiplier*6;
4940 objects.roty[i]+=velocity.z*multiplier*6;
4941 objects.messedwith[i]=.5;
4944 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4945 if(objects.rotation2[i]==0)tempcoord=coords;
4947 tempcoord=coords-objects.position[i];
4948 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4949 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4950 tempcoord+=objects.position[i];
4952 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]){
4953 if(objects.messedwith[i]<=0){
4957 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4960 envsound[numenvsounds]=coords;
4961 envsoundvol[numenvsounds]=4*findLength(&velocity);
4962 envsoundlife[numenvsounds]=.4;
4967 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4968 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4970 if(environment!=desertenvironment)
4971 for(j=0;j<howmany;j++){
4972 tempvel.x=float(abs(Random()%100)-50)/20;
4973 tempvel.y=float(abs(Random()%100)-50)/20;
4974 tempvel.z=float(abs(Random()%100)-50)/20;
4978 pos.x+=float(abs(Random()%100)-50)/150;
4979 pos.y+=float(abs(Random()%100)-50)/150;
4980 pos.z+=float(abs(Random()%100)-50)/150;
4981 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);
4982 Sprite::setLastSpriteSpecial(1);
4984 howmany=findLength(&velocity)*4;
4986 if(environment==snowyenvironment)
4987 for(j=0;j<howmany;j++){
4988 tempvel.x=float(abs(Random()%100)-50)/20;
4989 tempvel.y=float(abs(Random()%100)-50)/20;
4990 tempvel.z=float(abs(Random()%100)-50)/20;
4994 pos.x+=float(abs(Random()%100)-50)/150;
4995 pos.y+=float(abs(Random()%100)-50)/150;
4996 pos.z+=float(abs(Random()%100)-50)/150;
4997 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4998 Sprite::setLastSpriteSpecial(2);
5001 objects.messedwith[i]=.5;
5009 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
5011 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
5012 if(tutoriallevel==1&&id!=0)play=0;
5013 if(play&&aitype!=playercontrolled){
5017 if(creature==rabbittype){
5018 if(i==0)whichsound=rabbitchitter;
5019 if(i==1)whichsound=rabbitchitter2;
5021 if(creature==wolftype){
5022 if(i==0)whichsound=growlsound;
5023 if(i==1)whichsound=growl2sound;
5029 emit_sound_at(whichsound, coords);
5033 if(targetanimation==staggerbackhighanim)staggerdelay=1;
5034 if(targetanimation==staggerbackhardanim)staggerdelay=1;
5035 staggerdelay-=multiplier;
5036 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
5037 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
5038 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
5039 targetanimation=getIdle();
5043 weaponmissdelay-=multiplier;
5044 highreversaldelay-=multiplier;
5045 lowreversaldelay-=multiplier;
5046 lastcollide-=multiplier;
5047 skiddelay-=multiplier;
5048 if(!isnormal(velocity.x)&&velocity.x){
5051 if(!isnormal(targettilt)&&targettilt){
5054 if(!isnormal(targettilt2)&&targettilt2){
5057 if(!isnormal(targetrotation)&&targetrotation){
5061 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
5062 //open hands and close mouth
5063 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5064 righthandmorphness=0;
5065 righthandmorphend=0;
5066 targetrighthandmorphness=1;
5069 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5070 lefthandmorphness=0;
5072 targetlefthandmorphness=1;
5075 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
5078 targetheadmorphness=1;
5082 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){
5083 //open hands and mouth
5084 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5085 righthandmorphness=0;
5086 righthandmorphend=0;
5087 targetrighthandmorphness=1;
5090 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5091 lefthandmorphness=0;
5093 targetlefthandmorphness=1;
5096 if(headmorphend!=1&&headmorphness==targetheadmorphness){
5099 targetheadmorphness=1;
5103 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
5104 //close hands and mouth
5105 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5106 righthandmorphness=0;
5107 righthandmorphend=1;
5108 targetrighthandmorphness=1;
5111 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5112 lefthandmorphness=0;
5114 targetlefthandmorphness=1;
5117 if(headmorphend!=0&&headmorphness==targetheadmorphness){
5120 targetheadmorphness=1;
5124 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){
5125 //close hands and yell
5126 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5127 righthandmorphness=0;
5128 righthandmorphend=1;
5129 targetrighthandmorphness=1;
5132 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5133 lefthandmorphness=0;
5135 targetlefthandmorphness=1;
5138 if(headmorphend!=2&&headmorphness==targetheadmorphness){
5141 targetheadmorphness=1;
5145 if(speechdelay>.25){
5146 if(headmorphend!=2)headmorphness=0;
5148 targetheadmorphness=1;
5154 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
5155 behind=(normaldotproduct(facing,coords-victim->coords)>0);
5159 if(!dead&&targetanimation!=hurtidleanim)
5160 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
5161 if(headmorphend!=4||headmorphness==targetheadmorphness){
5164 targetheadmorphness=1;
5168 if(weaponactive!=-1){
5169 if(weapons.type[weaponids[weaponactive]]!=staff){
5170 righthandmorphstart=1;
5171 righthandmorphend=1;
5173 if(weapons.type[weaponids[weaponactive]]==staff){
5174 righthandmorphstart=2;
5175 righthandmorphend=2;
5177 targetrighthandmorphness=1;
5180 terrainnormal=terrain.getNormal(coords.x,coords.z);
5182 if(animation[targetanimation].attack!=reversal){
5183 if(!isnormal(coords.x))
5191 flatfacing=DoRotation(flatfacing,0,rotation,0);
5193 ReflectVector(&facing,terrainnormal);
5196 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5197 if(onterrain)targettilt2=-facing.y*20;
5201 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5202 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5203 flatvelocity=velocity;
5205 flatvelspeed=findLength(&flatvelocity);
5206 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5207 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5208 if(velocity.y<0)targettilt2*=-1;
5209 if(velocity.y<0)targettilt*=-1;
5210 if(targettilt>25)targettilt=25;
5211 if(targettilt<-25)targettilt=-25;
5214 if(targettilt2>45)targettilt2=45;
5215 if(targettilt2<-45)targettilt2=-45;
5216 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5217 else if(tilt2>targettilt2){
5218 tilt2-=multiplier*400;
5220 else if(tilt2<targettilt2){
5221 tilt2+=multiplier*400;
5223 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5224 if(tilt2>25)tilt2=25;
5225 if(tilt2<-25)tilt2=-25;
5228 if(!isnormal(targettilt)&&targettilt){
5231 if(!isnormal(targettilt2)&&targettilt2){
5236 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5237 if(targetanimation==rabbittackleanim){
5238 velocity+=facing*multiplier*speed*700*scale;
5239 velspeed=findLength(&velocity);
5240 if(velspeed>speed*65*scale){
5242 velspeed=speed*65*scale;
5245 velocity.y+=gravity*multiplier*20;
5246 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5247 velspeed=findLength(&velocity);
5248 velocity=flatfacing*velspeed;
5250 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5251 if(isRun()||targetanimation==rabbitkickanim){
5252 velocity+=facing*multiplier*speed*700*scale;
5253 velspeed=findLength(&velocity);
5254 if(velspeed>speed*45*scale){
5256 velspeed=speed*45*scale;
5259 velocity.y+=gravity*multiplier*20;
5260 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5261 velspeed=findLength(&velocity);
5262 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5263 velocity=flatfacing*velspeed;
5267 velocity+=facing*multiplier*speed*700*scale;
5268 velspeed=findLength(&velocity);
5269 if(creature==rabbittype){
5270 if(velspeed>speed*55*scale){
5272 velspeed=speed*55*scale;
5276 if(creature==wolftype){
5277 if(velspeed>speed*75*scale){
5279 velspeed=speed*75*scale;
5283 velocity.y+=gravity*multiplier*20;
5284 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5285 velspeed=findLength(&velocity);
5286 velocity=flatfacing*velspeed;
5289 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5290 velocity+=facing*multiplier*speed*700*scale;
5291 velspeed=findLength(&velocity);
5292 if(velspeed>speed*45*scale){
5294 velspeed=speed*45*scale;
5297 velocity.y+=gravity*multiplier*20;
5298 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5299 velspeed=findLength(&velocity);
5300 velocity=flatfacing*velspeed;
5304 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5305 velocity+=facing*multiplier*speed*700*scale;
5306 velspeed=findLength(&velocity);
5307 if(velspeed>speed*25*scale){
5309 velspeed=speed*25*scale;
5312 velocity.y+=gravity*multiplier*20;
5313 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5314 velspeed=findLength(&velocity);
5315 velocity=flatfacing*velspeed;
5318 if(targetanimation==sneakanim||targetanimation==walkanim){
5319 velocity+=facing*multiplier*speed*700*scale;
5320 velspeed=findLength(&velocity);
5321 if(velspeed>speed*12*scale){
5323 velspeed=speed*12*scale;
5326 velocity.y+=gravity*multiplier*20;
5327 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5328 velspeed=findLength(&velocity);
5329 velocity=flatfacing*velspeed;
5332 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5333 velocity+=facing*multiplier*speed*700*scale;
5334 velspeed=findLength(&velocity);
5335 if(velspeed>speed*2*scale){
5337 velspeed=speed*2*scale;
5340 velocity.y+=gravity*multiplier*20;
5341 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5342 velspeed=findLength(&velocity);
5343 velocity=flatfacing*velspeed;
5347 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5348 velocity-=facing*multiplier*speed*700*scale;
5349 velspeed=findLength(&velocity);
5350 if(velspeed>speed*2*scale){
5352 velspeed=speed*2*scale;
5355 velocity.y+=gravity*multiplier*20;
5356 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5357 velspeed=findLength(&velocity);
5358 velocity=flatfacing*velspeed*-1;
5361 if(targetanimation==fightsidestep){
5362 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5363 velspeed=findLength(&velocity);
5364 if(velspeed>speed*12*scale){
5366 velspeed=speed*12*scale;
5369 velocity.y+=gravity*multiplier*20;
5370 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5371 velspeed=findLength(&velocity);
5372 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5375 if(targetanimation==staggerbackhighanim){
5376 coords-=facing*multiplier*speed*16*scale;
5379 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5380 coords-=facing*multiplier*speed*20*scale;
5384 if(targetanimation==backhandspringanim){
5385 //coords-=facing*multiplier*50*scale;
5386 velocity+=facing*multiplier*speed*700*scale*-1;
5387 velspeed=findLength(&velocity);
5388 if(velspeed>speed*50*scale){
5390 velspeed=speed*50*scale;
5393 velocity.y+=gravity*multiplier*20;
5394 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5395 velspeed=findLength(&velocity);
5396 velocity=flatfacing*velspeed*-1;
5398 if(targetanimation==dodgebackanim){
5399 //coords-=facing*multiplier*50*scale;
5400 velocity+=facing*multiplier*speed*700*scale*-1;
5401 velspeed=findLength(&velocity);
5402 if(velspeed>speed*60*scale){
5404 velspeed=speed*60*scale;
5407 velocity.y+=gravity*multiplier*20;
5408 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5409 velspeed=findLength(&velocity);
5410 velocity=flatfacing*velspeed*-1;
5413 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5414 velspeed=findLength(&velocity);
5418 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5419 velocity.y+=gravity*multiplier;
5422 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5424 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5425 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5427 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5433 OPENAL_SetPaused(channels[whooshsound], true);
5434 OPENAL_SetVolume(channels[whooshsound], 0);
5437 if(targetanimation==jumpdownanim||isFlip()){
5438 if(isFlip())jumppower=-4;
5439 targetanimation=getLanding();
5440 emit_sound_at(landsound, coords, 128.);
5443 envsound[numenvsounds]=coords;
5444 envsoundvol[numenvsounds]=16;
5445 envsoundlife[numenvsounds]=.4;
5451 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5452 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5453 coords.y=terrain.getHeight(coords.x,coords.z);
5458 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)){
5459 velspeed=findLength(&velocity);
5461 if(velspeed<multiplier*300*scale){
5463 } else velocity-=velocity/velspeed*multiplier*300*scale;
5464 if(velspeed>5&&(isLanding()||isLandhard())){
5465 skiddingdelay+=multiplier;
5472 else skiddingdelay=0;
5476 velspeed=findLength(&velocity);
5478 if(velspeed<multiplier*600*scale){
5480 } else velocity-=velocity/velspeed*multiplier*600*scale;
5482 if(velspeed>5&&(isLanding()||isLandhard())){
5483 skiddingdelay+=multiplier;
5490 else skiddingdelay=0;
5493 if(skiddingdelay<0)skiddingdelay+=multiplier;
5494 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5496 if(!onterrain||environment==grassyenvironment){
5497 emit_sound_at(skidsound, coords, 128*velspeed/10);
5500 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5504 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5505 terrainnormal=victim->coords-coords;
5506 Normalise(&terrainnormal);
5507 targetrotation=-asin(0-terrainnormal.x);
5508 targetrotation*=360/6.28;
5509 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5510 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5513 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5514 targetrotation=victim->targetrotation;
5516 if(targetanimation==rabbittacklinganim){
5517 coords=victim->coords;
5520 skeleton.oldfree=skeleton.free;
5524 midterrain.x=terrain.size*terrain.scale/2;
5525 midterrain.z=terrain.size*terrain.scale/2;
5526 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5528 tempposit=coords-midterrain;
5530 Normalise(&tempposit);
5531 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5532 coords.x=tempposit.x+midterrain.x;
5533 coords.z=tempposit.z+midterrain.z;
5537 int Person::DrawSkeleton(){
5538 int oldplayerdetail;
5539 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5540 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5550 glAlphaFunc(GL_GREATER, 0.0001);
5552 float terrainheight;
5554 if(!isnormal(rotation))rotation=0;
5555 if(!isnormal(tilt))tilt=0;
5556 if(!isnormal(tilt2))tilt2=0;
5557 oldplayerdetail=playerdetail;
5559 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5562 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5565 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5570 if(playerdetail!=oldplayerdetail) {
5572 normalsupdatedelay=0;
5574 static float updatedelaychange;
5575 static float morphness;
5576 static float framemult;
5578 skeleton.FindForwards();
5579 if(howactive==typesittingwall){
5580 skeleton.specialforward[1]=0;
5581 skeleton.specialforward[1].z=1;
5587 static int weaponattachmuscle;
5588 static int weaponrotatemuscle,weaponrotatemuscle2;
5589 static XYZ weaponpoint;
5590 static int start,endthing;
5591 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5592 if(!isSleeping()&&!isSitting()){
5593 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5594 XYZ point,newpoint,change,change2;
5595 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5596 heightleft=terrain.getHeight(point.x,point.z)+.04;
5598 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5599 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5600 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5601 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5602 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5604 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5605 heightright=terrain.getHeight(point.x,point.z)+.04;
5606 point.y=heightright;
5607 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5608 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5609 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5610 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5611 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5612 skeleton.DoConstraints(&coords,&scale);
5614 if(creature==wolftype){
5615 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5616 heightleft=terrain.getHeight(point.x,point.z)+.04;
5618 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5619 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5620 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5621 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5622 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5624 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5625 heightright=terrain.getHeight(point.x,point.z)+.04;
5626 point.y=heightright;
5627 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5628 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5629 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5630 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5631 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5632 skeleton.DoConstraints(&coords,&scale);
5635 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5636 XYZ point,newpoint,change,change2;
5637 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5638 heightleft=terrain.getHeight(point.x,point.z)+.04;
5640 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5641 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5642 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5643 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5644 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5646 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5647 heightright=terrain.getHeight(point.x,point.z)+.04;
5648 point.y=heightright;
5649 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5650 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5651 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5652 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5653 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5654 skeleton.DoConstraints(&coords,&scale);
5656 if(creature==wolftype){
5657 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5658 heightleft=terrain.getHeight(point.x,point.z)+.04;
5660 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5661 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5662 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5663 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5664 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5666 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5667 heightright=terrain.getHeight(point.x,point.z)+.04;
5668 point.y=heightright;
5669 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5670 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5671 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5672 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5673 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5674 skeleton.DoConstraints(&coords,&scale);
5678 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5679 XYZ point,newpoint,change,change2;
5680 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5681 heightleft=terrain.getHeight(point.x,point.z)+.04;
5683 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5684 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5685 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5686 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5687 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5689 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5690 heightright=terrain.getHeight(point.x,point.z)+.04;
5691 point.y=heightright;
5692 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5693 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5694 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5695 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5696 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5697 skeleton.DoConstraints(&coords,&scale);
5699 if(creature==wolftype){
5700 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5701 heightleft=terrain.getHeight(point.x,point.z)+.04;
5703 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5704 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5705 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5706 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5707 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5709 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5710 heightright=terrain.getHeight(point.x,point.z)+.04;
5711 point.y=heightright;
5712 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5713 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5714 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5715 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5716 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5717 skeleton.DoConstraints(&coords,&scale);
5721 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()))
5724 targetheadrotation=-targetrotation;
5725 targetheadrotation2=0;
5726 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5728 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5729 skeleton.drawmodel.vertex[i]=0;
5730 skeleton.drawmodel.vertex[i].y=999;
5732 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5733 skeleton.drawmodellow.vertex[i]=0;
5734 skeleton.drawmodellow.vertex[i].y=999;
5736 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5737 skeleton.drawmodelclothes.vertex[i]=0;
5738 skeleton.drawmodelclothes.vertex[i].y=999;
5740 for(i=0;i<skeleton.num_muscles;i++){
5741 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5745 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5746 morphness=righthandmorphness;
5747 start=righthandmorphstart;
5748 endthing=righthandmorphend;
5750 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5751 morphness=lefthandmorphness;
5752 start=lefthandmorphstart;
5753 endthing=lefthandmorphend;
5755 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5756 morphness=headmorphness;
5757 start=headmorphstart;
5758 endthing=headmorphend;
5760 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)){
5761 morphness=chestmorphness;
5762 start=chestmorphstart;
5763 endthing=chestmorphend;
5765 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)){
5766 morphness=tailmorphness;
5767 start=tailmorphstart;
5768 endthing=tailmorphend;
5770 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5771 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5772 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5775 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5776 if(!skeleton.free)glRotatef(tilt,0,0,1);
5779 glTranslatef(mid.x,mid.y,mid.z);
5781 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5782 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5784 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5785 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5787 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5788 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5790 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
5794 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
5798 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
5802 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
5807 if(playerdetail||skeleton.free==3)
5809 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5811 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
5812 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
5813 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
5814 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
5815 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
5816 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
5817 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
5818 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5820 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5821 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,
5822 (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,
5823 (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);
5824 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)
5825 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,
5826 (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,
5827 (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);
5828 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)
5829 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,
5830 (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,
5831 (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);
5832 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5833 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,
5834 (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,
5835 (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);
5836 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5837 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5838 //if(!isnormal(scale))test=1;
5839 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5840 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5841 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5846 if(!playerdetail||skeleton.free==3)
5848 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5850 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5852 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5853 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5854 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5855 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5856 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)
5857 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5858 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5859 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5860 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)
5861 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5862 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5863 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5864 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5865 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5866 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5867 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5869 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5870 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5871 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5872 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5878 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5879 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5881 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5884 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5885 if(!skeleton.free)glRotatef(tilt,0,0,1);
5886 glTranslatef(mid.x,mid.y,mid.z);
5887 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5888 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5890 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5891 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5893 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5894 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5896 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5897 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5899 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5900 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5901 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5902 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5903 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)
5904 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5905 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5906 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5907 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)
5908 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5909 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5910 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5911 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5912 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5913 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5914 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5915 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5916 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5917 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5918 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5923 updatedelay=1+(float)(Random()%100)/1000;
5925 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5926 normalsupdatedelay=1;
5927 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5928 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5929 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5933 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5934 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5935 if(skeleton.clothes){
5936 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5941 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5942 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5943 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5944 if(skeleton.free==1)updatedelaychange*=6;
5945 if(id==0)updatedelaychange*=8;
5946 updatedelay+=updatedelaychange;
5948 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5950 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5951 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5952 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5953 if(!skeleton.free)glRotatef(rotation,0,1,0);
5956 glColor4f(.4,1,.4,1);
5957 glDisable(GL_LIGHTING);
5958 glDisable(GL_TEXTURE_2D);
5961 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5962 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5968 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5969 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);
5970 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);
5971 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);
5972 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);
5973 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);
5974 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);
5980 terrainlight=terrain.getLighting(coords.x,coords.z);
5981 distance=findDistancefast(&viewer,&coords);
5982 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5983 if(distance>1)distance=1;
5985 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5986 if(terrainheight<1)terrainheight=1;
5987 if(terrainheight>1.7)terrainheight=1.7;
5990 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5991 glDisable(GL_BLEND);
5992 glAlphaFunc(GL_GREATER, 0.0001);
5993 glEnable(GL_TEXTURE_2D);
5995 glDisable(GL_TEXTURE_2D);
5996 glColor4f(.7,.35,0,.5);
5998 glEnable(GL_LIGHTING);
6001 if(tutoriallevel&&id!=0){
6002 //glDisable(GL_TEXTURE_2D);
6003 glColor4f(.7,.7,.7,0.6);
6005 glEnable(GL_LIGHTING);
6007 if(canattack&&cananger)
6008 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6009 glDisable(GL_TEXTURE_2D);
6010 glColor4f(1,0,0,0.8);
6012 glMatrixMode(GL_TEXTURE);
6014 glTranslatef(0,-smoketex,0);
6015 glTranslatef(-smoketex,0,0);
6019 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6020 else skeleton.drawmodel.draw();
6024 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6025 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6028 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
6029 if(tutoriallevel&&id!=0){
6031 glMatrixMode(GL_MODELVIEW);
6032 glEnable(GL_TEXTURE_2D);
6033 glColor4f(.7,.7,.7,0.6);
6035 glEnable(GL_LIGHTING);
6037 if(canattack&&cananger)
6038 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6039 glDisable(GL_TEXTURE_2D);
6040 glColor4f(1,0,0,0.8);
6042 glMatrixMode(GL_TEXTURE);
6044 glTranslatef(0,-smoketex*.6,0);
6045 glTranslatef(smoketex*.6,0,0);
6048 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6049 else skeleton.drawmodel.draw();
6053 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6054 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6059 if(tutoriallevel&&id!=0){
6061 glMatrixMode(GL_MODELVIEW);
6062 glEnable(GL_TEXTURE_2D);
6064 if(skeleton.clothes){
6067 if(!immediate)skeleton.drawmodelclothes.draw();
6068 if(immediate)skeleton.drawmodelclothes.drawimmediate();
6075 for(k=0;k<num_weapons;k++){
6077 if(weaponactive==k){
6078 if(weapons.type[i]!=staff){
6079 for(j=0;j<skeleton.num_muscles;j++){
6080 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6081 weaponattachmuscle=j;
6084 for(j=0;j<skeleton.num_muscles;j++){
6085 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){
6086 weaponrotatemuscle=j;
6089 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6090 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
6092 if(weapons.type[i]==staff){
6093 for(j=0;j<skeleton.num_muscles;j++){
6094 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6095 weaponattachmuscle=j;
6098 for(j=0;j<skeleton.num_muscles;j++){
6099 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){
6100 weaponrotatemuscle=j;
6103 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
6104 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6105 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6106 XYZ tempnormthing,vec1,vec2;
6107 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6108 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
6109 CrossProduct(&vec1,&vec2,&tempnormthing);
6110 Normalise(&tempnormthing);
6111 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);
6112 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
6114 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
6115 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6116 Normalise(&weaptargnorm);
6117 weaponpoint-=weaptargnorm*2;
6121 if(weaponactive!=k&&weaponstuck!=k){
6122 if(weapons.type[i]==knife)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[righthip]].position-skeleton.joints[skeleton.jointlabels[lefthip]].position)*.1+(skeleton.joints[skeleton.jointlabels[rightshoulder]].position-skeleton.joints[skeleton.jointlabels[leftshoulder]].position)*.35;
6123 if(weapons.type[i]==sword)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[lefthip]].position-skeleton.joints[skeleton.jointlabels[righthip]].position)*.09+(skeleton.joints[skeleton.jointlabels[leftshoulder]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position)*.33;
6124 if(weapons.type[i]==staff)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position+(skeleton.joints[skeleton.jointlabels[lefthip]].position-skeleton.joints[skeleton.jointlabels[righthip]].position)*.09+(skeleton.joints[skeleton.jointlabels[leftshoulder]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position)*.33;
6125 for(j=0;j<skeleton.num_muscles;j++){
6126 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){
6127 weaponrotatemuscle=j;
6132 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
6133 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
6134 for(j=0;j<skeleton.num_muscles;j++){
6135 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){
6136 weaponrotatemuscle=j;
6141 weapons.position[i]=DoRotation(DoRotation(DoRotation(weaponpoint,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords+currentoffset*(1-target)*scale+targetoffset*target*scale;
6142 weapons.bigrotation[i]=rotation;
6143 weapons.bigtilt[i]=tilt;
6144 weapons.bigtilt2[i]=tilt2;
6147 weapons.position[i]=weaponpoint*scale+coords;
6148 weapons.bigrotation[i]=0;
6149 weapons.bigtilt[i]=0;
6150 weapons.bigtilt2[i]=0;
6152 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
6153 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
6154 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
6155 if(weaponactive==k){
6156 if(weapons.type[i]==knife){
6157 weapons.smallrotation[i]=180;
6158 weapons.smallrotation2[i]=0;
6159 if(isCrouch()||wasCrouch()){
6160 weapons.smallrotation2[i]=20;
6162 if(targetanimation==hurtidleanim){
6163 weapons.smallrotation2[i]=50;
6165 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
6166 XYZ temppoint1,temppoint2,tempforward;
6169 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6170 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6171 distance=findDistance(&temppoint1,&temppoint2);
6172 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6173 weapons.rotation2[i]*=360/6.28;
6176 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6177 weapons.rotation1[i]*=360/6.28;
6178 weapons.rotation3[i]=0;
6179 weapons.smallrotation[i]=-90;
6180 weapons.smallrotation2[i]=0;
6181 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6183 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
6184 XYZ temppoint1,temppoint2,tempforward;
6187 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6188 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6189 distance=findDistance(&temppoint1,&temppoint2);
6190 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6191 weapons.rotation2[i]*=360/6.28;
6194 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6195 weapons.rotation1[i]*=360/6.28;
6196 weapons.rotation3[i]=0;
6197 weapons.smallrotation[i]=90;
6198 weapons.smallrotation2[i]=0;
6199 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6201 if(targetanimation==knifethrowanim){
6202 weapons.smallrotation[i]=90;
6203 //weapons.smallrotation2[i]=-90;
6204 weapons.smallrotation2[i]=0;
6205 weapons.rotation1[i]=0;
6206 weapons.rotation2[i]=0;
6207 weapons.rotation3[i]=0;
6209 if(targetanimation==knifesneakattackanim&&targetframe<5){
6210 weapons.smallrotation[i]=-90;
6211 weapons.rotation1[i]=0;
6212 weapons.rotation2[i]=0;
6213 weapons.rotation3[i]=0;
6216 if(weapons.type[i]==sword){
6217 weapons.smallrotation[i]=0;
6218 weapons.smallrotation2[i]=0;
6219 if(targetanimation==knifethrowanim){
6220 weapons.smallrotation[i]=-90;
6221 weapons.smallrotation2[i]=0;
6222 weapons.rotation1[i]=0;
6223 weapons.rotation2[i]=0;
6224 weapons.rotation3[i]=0;
6226 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)){
6227 XYZ temppoint1,temppoint2,tempforward;
6230 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6231 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6232 distance=findDistance(&temppoint1,&temppoint2);
6233 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6234 weapons.rotation2[i]*=360/6.28;
6237 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6238 weapons.rotation1[i]*=360/6.28;
6239 weapons.rotation3[i]=0;
6240 weapons.smallrotation[i]=90;
6241 weapons.smallrotation2[i]=0;
6242 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6245 if(weapons.type[i]==staff){
6246 weapons.smallrotation[i]=100;
6247 weapons.smallrotation2[i]=0;
6248 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6249 XYZ temppoint1,temppoint2,tempforward;
6252 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6253 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6254 distance=findDistance(&temppoint1,&temppoint2);
6255 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6256 weapons.rotation2[i]*=360/6.28;
6259 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6260 weapons.rotation1[i]*=360/6.28;
6261 weapons.rotation3[i]=0;
6262 weapons.smallrotation[i]=90;
6263 weapons.smallrotation2[i]=0;
6264 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6268 if(weaponactive!=k&&weaponstuck!=k){
6269 if(weapons.type[i]==knife){
6270 weapons.smallrotation[i]=-70;
6271 weapons.smallrotation2[i]=10;
6273 if(weapons.type[i]==sword){
6274 weapons.smallrotation[i]=-100;
6275 weapons.smallrotation2[i]=-8;
6277 if(weapons.type[i]==staff){
6278 weapons.smallrotation[i]=-100;
6279 weapons.smallrotation2[i]=-8;
6283 if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
6284 else weapons.smallrotation[i]=0;
6285 weapons.smallrotation2[i]=10;
6292 if(skeleton.free)calcrot=1;
6293 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6294 if(currentanimation!=targetanimation)calcrot=1;
6295 //if(id==0)calcrot=1;
6296 if(skeleton.free==2)calcrot=0;
6302 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6305 static float distance;
6306 static float olddistance;
6307 static int intersecting;
6308 static int firstintersecting;
6311 static XYZ start,end;
6312 static float slopethreshold=-.4;
6314 firstintersecting=-1;
6318 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6319 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6321 for (j=0;j<model->TriangleNum;j++){
6322 if(model->facenormals[j].y<=slopethreshold){
6324 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)));
6325 if(distance<radius){
6326 point=*p1-model->facenormals[j]*distance;
6327 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;
6328 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6329 &model->vertex[model->Triangles[j].vertex[1]],
6331 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6332 &model->vertex[model->Triangles[j].vertex[2]],
6334 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6335 &model->vertex[model->Triangles[j].vertex[2]],
6338 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6342 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)){
6343 p1->y=point.y+radius;
6344 if((targetanimation==jumpdownanim||isFlip())){
6345 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6347 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6353 OPENAL_SetPaused(channels[whooshsound], true);
6354 OPENAL_SetVolume(channels[whooshsound], 0);
6357 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6358 if(isFlip())jumppower=-4;
6359 targetanimation=getLanding();
6360 emit_sound_at(landsound, coords, 128.);
6363 envsound[numenvsounds]=coords;
6364 envsoundvol[numenvsounds]=16;
6365 envsoundlife[numenvsounds]=.4;
6373 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6376 for (j=0;j<model->TriangleNum;j++){
6377 if(model->facenormals[j].y>slopethreshold){
6381 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)));
6382 if(distance<radius*.5){
6383 point=start-model->facenormals[j]*distance;
6384 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;
6385 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,
6386 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6387 p1->x, p1->y, p1->z, radius/2);
6388 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,
6389 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6390 p1->x, p1->y, p1->z, radius/2);
6391 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,
6392 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6393 p1->x, p1->y, p1->z, radius/2);
6395 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6396 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6398 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6399 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6401 *p1+=model->facenormals[j]*(distance-radius*.5);
6404 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6408 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6410 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6412 return firstintersecting;
6422 currentanimation = 0;
6423 targetanimation = 0;
6424 oldcurrentframe = 0;
6426 oldcurrentanimation = 0;
6427 oldtargetanimation = 0;
6431 parriedrecently = 0;
6435 lastattack = 0,lastattack2 = 0,lastattack3 = 0;
6437 currentoffset = 0,targetoffset = 0,offset = 0;
6455 unconscioustime = 0;
6473 rabbitkickenabled = 0;
6482 damagetolerance = 0;
6484 permanentdamage = 0;
6485 superpermanentdamage = 0; lastcollide = 0;
6505 headrotation = 0,headrotation2 = 0;
6506 targetheadrotation = 0,targetheadrotation2 = 0;
6517 normalsupdatedelay = 0;
6522 forwardstogglekeydown = 0;
6527 jumptogglekeydown = 0;
6529 crouchtogglekeydown = 0;
6531 drawtogglekeydown = 0;
6533 throwtogglekeydown = 0;
6539 crouchkeydowntime = 0;
6540 jumpkeydowntime = 0;
6557 whichdirectiondelay = 0;
6558 avoidsomething = 0; avoidwhere = 0;
6566 lefthandmorphness = 0;
6567 righthandmorphness = 0;
6571 targetlefthandmorphness = 0;
6572 targetrighthandmorphness = 0;
6573 targetheadmorphness = 0;
6574 targetchestmorphness = 0;
6575 targettailmorphness = 0;
6576 lefthandmorphstart = 0,lefthandmorphend = 0;
6577 righthandmorphstart = 0,righthandmorphend = 0;
6578 headmorphstart = 0,headmorphend = 0;
6579 chestmorphstart = 0,chestmorphend = 0;
6580 tailmorphstart = 0,tailmorphend = 0;
6582 weaponmissdelay = 0;
6583 highreversaldelay = 0;
6584 lowreversaldelay = 0;
6591 //Skeleton skeleton;
6610 memset(clothes, 0, sizeof(clothes));
6611 memset(clothestintr, 0, sizeof(clothestintr));
6612 memset(clothestintg, 0, sizeof(clothestintg));
6613 memset(clothestintb, 0, sizeof(clothestintb));
6619 onfiredelay = 0; burnt = 0;
6623 updatestuffdelay = 0;
6629 memset(weaponids, 0, sizeof(weaponids));
6633 weaponstuckwhere = 0;
6638 memset(waypoints, 0, sizeof(waypoints));
6639 memset(waypointtype, 0, sizeof(waypointtype));
6642 hastempwaypoint = 0;
6648 finalfinaltarget = 0;
6650 finalpathfindpoint = 0;
6651 targetpathfindpoint = 0;
6652 lastpathfindpoint = 0;
6653 lastpathfindpoint2 = 0;
6654 lastpathfindpoint3 = 0;
6655 lastpathfindpoint4 = 0;
6666 runninghowlong = 0; lastoccluded = 0;
6672 neckspurtparticledelay = 0;
6673 neckspurtamount = 0;
6676 rabbitkickragdoll = 0;
6681 //Animation tempanimation;