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;
226 int Person::getLanding(){
227 if(creature==rabbittype)return landanim;
228 if(creature==wolftype)return wolflandanim;
233 bool Person::isLandhard(){
234 if(targetanimation==landhardanim||targetanimation==wolflandhardanim)return 1;
239 bool Person::wasLandhard(){
240 if(currentanimation==landhardanim||currentanimation==wolflandhardanim)return 1;
243 int Person::getLandhard(){
244 if(creature==rabbittype)return landhardanim;
245 if(creature==wolftype)return wolflandhardanim;
250 bool Person::isFlip(){
251 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==backflipanim||targetanimation==rightflipanim||targetanimation==leftflipanim||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)return 1;
255 bool Person::wasFlip(){
256 if(currentanimation==flipanim||currentanimation==frontflipanim||currentanimation==backflipanim||currentanimation==rightflipanim||currentanimation==leftflipanim||currentanimation==walljumprightkickanim||currentanimation==walljumpleftkickanim)return 1;
260 bool Person::isWallJump(){
261 if(targetanimation==walljumpfrontanim||targetanimation==walljumpbackanim||targetanimation==walljumpleftanim||targetanimation==walljumprightanim)return 1;
266 SolidHitBonus(int playerid)
268 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
269 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
271 award_bonus(playerid, solidhit);
274 void Person::DoBlood(float howmuch,int which){
275 static int bleedxint,bleedyint;
277 //if(howmuch&&id==0)blooddimamount=1;
278 if(bloodtoggle&&tutoriallevel!=1){
279 if(bleeding<=0&&spurt){
281 for(int i=0;i<3;i++){
285 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
288 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
290 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
291 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
293 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
294 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
297 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);
298 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);
302 for(int i=0;i<3;i++){
306 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
307 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
310 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
311 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
315 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
317 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);
319 Sprite::setLastSpriteSpecial(3);
324 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
327 int texdetailint=realtexdetail;
328 if(creature==rabbittype)
329 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){
330 bleedxint=abs(Random()%512);
331 bleedyint=abs(Random()%512);
333 if(creature==wolftype)
334 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){
335 bleedxint=abs(Random()%512);
336 bleedyint=abs(Random()%512);
340 bleedy/=realtexdetail;
341 bleedx/=realtexdetail;
342 direction=abs(Random()%2)*2-1;
346 if(bleeding>2)bleeding=2;
349 void Person::DoBloodBig(float howmuch,int which){
350 static int bleedxint,bleedyint,i,j;
352 if(howmuch&&id==0)blooddimamount=1;
354 if(tutoriallevel!=1||id==0)
355 if(aitype!=playercontrolled&&howmuch>0){
358 if(creature==wolftype){
359 int i=abs(Random()%2);
360 if(i==0)whichsound=snarlsound;
361 if(i==1)whichsound=snarl2sound;
362 envsound[numenvsounds]=coords;
363 envsoundvol[numenvsounds]=16;
364 envsoundlife[numenvsounds]=.4;
367 if(creature==rabbittype){
368 int i=abs(Random()%2);
369 if(i==0)whichsound=rabbitpainsound;
370 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
371 envsound[numenvsounds]=coords;
372 envsoundvol[numenvsounds]=16;
373 envsoundlife[numenvsounds]=.4;
375 //if(i==2)whichsound=rabbitpain2sound;
379 emit_sound_at(whichsound, coords);
382 if(id==0&&howmuch>0){
390 if(bloodtoggle&&decals&&tutoriallevel!=1){
391 if(bleeding<=0&&spurt){
393 for(int i=0;i<3;i++){
397 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
400 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
402 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
403 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
405 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
406 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
409 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);
410 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);
414 int offsetx=0,offsety=0;
417 offsetx=abs(Random()%60);
419 if(which==190||which==185){
421 offsetx=abs(Random()%100)-20;
431 if(which==220||which==215){
432 //offsety=Random()%20;
434 //offsetx=abs(Random()%80);
443 if(creature==rabbittype)
446 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
447 if(i<startx)startx=i;
448 if(j<starty)starty=j;
454 if(creature==wolftype)
457 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
458 if(i<startx)startx=i;
459 if(j<starty)starty=j;
471 if(startx<0)startx=0;
472 if(starty<0)starty=0;
473 if(endx>512-1)endx=512-1;
474 if(endy>512-1)endy=512-1;
475 if(endx<startx)endx=startx;
476 if(endy<starty)endy=starty;
478 startx/=realtexdetail;
479 starty/=realtexdetail;
483 int texdetailint=realtexdetail;
485 if(creature==rabbittype)
486 for(i=startx;i<endx;i++){
487 for(j=starty;j<endy;j++){
488 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){
489 color=Random()%85+170;
490 where=i*skeleton.skinsize*3+j*3;
491 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
492 skeleton.skinText[where+1]=0;
493 skeleton.skinText[where+2]=0;
497 if(creature==wolftype)
498 for(i=startx;i<endx;i++){
499 for(j=starty;j<endy;j++){
500 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){
501 color=Random()%85+170;
502 where=i*skeleton.skinsize*3+j*3;
503 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
504 skeleton.skinText[where+1]=0;
505 skeleton.skinText[where+2]=0;
509 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
510 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
511 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
515 if(creature==rabbittype)
516 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){
517 bleedxint=abs(Random()%512);
518 bleedyint=abs(Random()%512);
520 if(creature==wolftype)
521 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){
522 bleedxint=abs(Random()%512);
523 bleedyint=abs(Random()%512);
525 bleedy=bleedxint+offsetx;
526 bleedx=bleedyint+offsety;
527 bleedy/=realtexdetail;
528 bleedx/=realtexdetail;
529 if(bleedx<0)bleedx=0;
530 if(bleedy<0)bleedy=0;
531 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
532 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
533 direction=abs(Random()%2)*2-1;
536 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
537 deathbleeding+=bleeding;
538 bloodloss+=bleeding*3;
540 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
541 if(abs(Random()%2)==0){aitype=gethelptype;
544 else aitype=attacktypecutoff;
547 if(bleeding>2)bleeding=2;
550 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
551 static int bleedxint,bleedyint,i,j;
553 static XYZ startpoint,endpoint,colpoint,movepoint;
554 static float rotationpoint;
556 static XYZ p1,p2,p3,p0;
560 float coordsx,coordsy;
563 if(bloodtoggle&&decals&&tutoriallevel!=1){
565 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
573 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
576 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
577 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
578 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
580 CrossProduct(p2-p1,p3-p1,&N);
581 CrossProduct(p0-p1,p3-p1,&temp);
582 s = dotproduct(&temp,&N)/findLength(&N);
583 CrossProduct(p2-p1,p1-p0,&temp);
584 t = dotproduct(&temp,&N)/findLength(&N);
587 bary.x=findDistancefast(&p0,&p1);
588 bary.y=findDistancefast(&p0,&p2);
589 bary.z=findDistancefast(&p0,&p3);
591 total=bary.x+bary.y+bary.z;
600 total=bary.x+bary.y+bary.z;
606 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
607 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
608 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
609 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
610 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
611 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
612 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;
613 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;
615 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
616 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
618 if(bleeding<=0&&spurt){
620 for(int i=0;i<3;i++){
624 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
627 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
629 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
630 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
632 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
633 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
636 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);
637 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);
641 int offsetx=0,offsety=0;
644 offsetx=abs(Random()%120);
646 if(which==220||which==215){
648 offsetx=abs(Random()%80);
651 offsetx=(1+coordsy)*512-291;
652 offsety=coordsx*512-437;
659 if(creature==rabbittype)
662 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
663 if(i<startx)startx=i;
664 if(j<starty)starty=j;
670 if(creature==wolftype)
673 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
674 if(i<startx)startx=i;
675 if(j<starty)starty=j;
686 if(startx<0)startx=0;
687 if(starty<0)starty=0;
688 if(endx>512-1)endx=512-1;
689 if(endy>512-1)endy=512-1;
690 if(endx<startx)endx=startx;
691 if(endy<starty)endy=starty;
693 startx/=realtexdetail;
694 starty/=realtexdetail;
698 int texdetailint=realtexdetail;
700 if(creature==rabbittype)
701 for(i=startx;i<endx;i++){
702 for(j=starty;j<endy;j++){
703 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){
704 color=Random()%85+170;
705 where=i*skeleton.skinsize*3+j*3;
706 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
707 skeleton.skinText[where+1]=0;
708 skeleton.skinText[where+2]=0;
710 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){
711 color=Random()%85+170;
712 where=i*skeleton.skinsize*3+j*3;
713 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
714 skeleton.skinText[where+1]=0;
715 skeleton.skinText[where+2]=0;
719 if(creature==wolftype)
720 for(i=startx;i<endx;i++){
721 for(j=starty;j<endy;j++){
722 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){
723 color=Random()%85+170;
724 where=i*skeleton.skinsize*3+j*3;
725 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
726 skeleton.skinText[where+1]=0;
727 skeleton.skinText[where+2]=0;
729 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){
730 color=Random()%85+170;
731 where=i*skeleton.skinsize*3+j*3;
732 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
733 skeleton.skinText[where+1]=0;
734 skeleton.skinText[where+2]=0;
738 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
739 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
740 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
742 bleedy=(1+coordsy)*512;
744 bleedy/=realtexdetail;
745 bleedx/=realtexdetail;
746 if(bleedx<0)bleedx=0;
747 if(bleedy<0)bleedy=0;
748 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
749 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
750 direction=abs(Random()%2)*2-1;
752 if(whichtri==-1)return 0;
754 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
755 deathbleeding+=bleeding;
756 bloodloss+=bleeding*3;
758 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
759 if(abs(Random()%2)==0){aitype=gethelptype;
762 else aitype=attacktypecutoff;
765 if(bleeding>2)bleeding=2;
770 void Person::DoMipmaps(int howmanylevels,float startx, float endx, float starty, float endy){
773 static int bytesPerPixel=3;
774 static int newsize,totalsize,rowsize,bigstep,smallstep,sum;
775 static int newstartx,newstarty,newendx,newendy;
776 static int newnewstartx,newnewstarty,newnewendx,newnewendy;
778 static float sizemult;
780 for(i=0;i<skeleton.skinsize*skeleton.skinsize*bytesPerPixel;i++){
781 texture[i]=skeleton.skinText[i];
784 if((!osx||howmanylevels)){
786 if(startx<0)startx=0;
787 if(starty<0)starty=0;
788 if(endx>skeleton.skinsize-1)endx=skeleton.skinsize-1;
789 if(endy>skeleton.skinsize-1)endy=skeleton.skinsize-1;
790 if((endx>startx&&endy>starty)||howmanylevels){
797 for(i=startx;i<endx;i++){
798 for(j=starty;j<endy;j++){
799 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+0]=skeleton.skinText[i*skeleton.skinsize*3+j*3+0];
800 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+1]=skeleton.skinText[i*skeleton.skinsize*3+j*3+1];
801 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+2]=skeleton.skinText[i*skeleton.skinsize*3+j*3+2];
805 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
808 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
809 glTexSubImage2D(GL_TEXTURE_2D,0,starty,startx,endy-starty,endx-startx,GL_RGB,GL_UNSIGNED_BYTE,texturearray);
810 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
813 newsize=skeleton.skinsize;
816 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, skeleton.skinsize, skeleton.skinsize, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0] );
818 /*for(j=1;j<=howmanylevels;j++){
819 if(j==1)texpointer=&skeleton.skinText[0];
820 else texpointer=&texture[0];
822 totalsize=int( newsize*newsize*bytesPerPixel);
823 rowsize=int( newsize*bytesPerPixel );
824 bigstep=bytesPerPixel*newsize*2;
825 smallstep=bytesPerPixel*2;
831 glTexSubImage2D(GL_TEXTURE_2D,j,0,0,newsize/2,newsize/2,GL_RGB,GL_UNSIGNED_BYTE,texture);
838 void Person::Reverse(){
839 if(victim->aitype==playercontrolled||hostiletime>1)
840 if(victim->targetanimation!=jumpupanim&&victim->targetanimation!=jumpdownanim&&((tutoriallevel!=1||cananger)&&hostile)){
841 if(normaldotproduct(victim->facing,victim->coords-coords)>0&&!(victim->id==0&&difficulty<2)&&(creature!=wolftype||victim->creature==wolftype))return;
842 if(victim->aitype!=playercontrolled&&staggerdelay>0)return;
843 if(targetanimation==sweepanim){
844 targetanimation=sweepreversedanim;
845 currentanimation=sweepreversedanim;
846 victim->currentanimation=sweepreversalanim;
847 victim->targetanimation=sweepreversalanim;
849 if(targetanimation==spinkickanim){
850 targetanimation=spinkickreversedanim;
851 currentanimation=spinkickreversedanim;
852 victim->currentanimation=spinkickreversalanim;
853 victim->targetanimation=spinkickreversalanim;
855 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
856 if(targetanimation==rabbittacklinganim){
859 victim->currentframe=6;
860 victim->targetframe=7;
862 targetanimation=upunchreversedanim;
863 currentanimation=upunchreversedanim;
864 victim->currentanimation=upunchreversalanim;
865 victim->targetanimation=upunchreversalanim;
867 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
868 if(victim->weaponactive!=-1){
869 victim->throwtogglekeydown=1;
870 weapons.owner[victim->weaponids[0]]=-1;
871 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
872 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
873 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
874 weapons.missed[victim->weaponids[0]]=1;
875 weapons.freetime[victim->weaponids[0]]=0;
876 weapons.firstfree[victim->weaponids[0]]=1;
877 weapons.physics[victim->weaponids[0]]=1;
878 victim->num_weapons--;
879 if(victim->num_weapons){
880 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
881 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
884 victim->weaponactive=-1;
885 for(int j=0;j<numplayers;j++){
886 player[j].wentforweapon=0;
890 targetanimation=staffhitreversedanim;
891 currentanimation=staffhitreversedanim;
892 victim->currentanimation=staffhitreversalanim;
893 victim->targetanimation=staffhitreversalanim;
895 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
896 if(victim->weaponactive!=-1){
897 victim->throwtogglekeydown=1;
898 weapons.owner[victim->weaponids[0]]=-1;
899 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
900 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
901 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
902 weapons.missed[victim->weaponids[0]]=1;
903 weapons.freetime[victim->weaponids[0]]=0;
904 weapons.firstfree[victim->weaponids[0]]=1;
905 weapons.physics[victim->weaponids[0]]=1;
906 victim->num_weapons--;
907 if(victim->num_weapons){
908 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
909 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
912 victim->weaponactive=-1;
913 for(int j=0;j<numplayers;j++){
914 player[j].wentforweapon=0;
917 targetanimation=staffspinhitreversedanim;
918 currentanimation=staffspinhitreversedanim;
919 victim->currentanimation=staffspinhitreversalanim;
920 victim->targetanimation=staffspinhitreversalanim;
922 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
923 if(victim->weaponactive!=-1){
924 victim->throwtogglekeydown=1;
925 weapons.owner[victim->weaponids[0]]=-1;
926 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
927 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
928 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
929 weapons.missed[victim->weaponids[0]]=1;
930 weapons.freetime[victim->weaponids[0]]=0;
931 weapons.firstfree[victim->weaponids[0]]=1;
932 weapons.physics[victim->weaponids[0]]=1;
933 victim->num_weapons--;
934 if(victim->num_weapons){
935 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
936 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
939 victim->weaponactive=-1;
940 for(int j=0;j<numplayers;j++){
941 player[j].wentforweapon=0;
944 targetanimation=swordslashreversedanim;
945 currentanimation=swordslashreversedanim;
946 victim->currentanimation=swordslashreversalanim;
947 victim->targetanimation=swordslashreversalanim;
949 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
950 if(victim->weaponactive!=-1){
951 victim->throwtogglekeydown=1;
952 weapons.owner[victim->weaponids[0]]=-1;
953 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
954 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
955 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
956 weapons.missed[victim->weaponids[0]]=1;
957 weapons.freetime[victim->weaponids[0]]=0;
958 weapons.firstfree[victim->weaponids[0]]=1;
959 weapons.physics[victim->weaponids[0]]=1;
960 victim->num_weapons--;
961 if(victim->num_weapons){
962 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
963 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
966 victim->weaponactive=-1;
967 for(int j=0;j<numplayers;j++){
968 player[j].wentforweapon=0;
971 targetanimation=knifeslashreversedanim;
972 currentanimation=knifeslashreversedanim;
973 victim->currentanimation=knifeslashreversalanim;
974 victim->targetanimation=knifeslashreversalanim;
976 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
977 victim->targettilt2=targettilt2;
978 victim->currentframe=currentframe;
979 victim->targetframe=targetframe;
980 victim->target=target;
982 victim->oldcoords=victim->coords;
983 victim->coords=coords;
984 victim->targetrotation=targetrotation;
985 victim->rotation=targetrotation;
988 if(targetanimation==winduppunchanim){
989 targetanimation=winduppunchblockedanim;
990 victim->targetanimation=blockhighleftanim;
991 victim->targetframe=1;
994 victim->targetrotation=targetrotation+180;
996 if(targetanimation==wolfslapanim){
997 targetanimation=winduppunchblockedanim;
998 victim->targetanimation=blockhighleftanim;
999 victim->targetframe=1;
1001 victim->victim=this;
1002 victim->targetrotation=targetrotation+180;
1004 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
1005 targetanimation=swordslashparriedanim;
1007 victim->parriedrecently=0;
1008 victim->targetanimation=swordslashparryanim;
1009 victim->targetframe=1;
1011 victim->victim=this;
1012 victim->targetrotation=targetrotation+180;
1014 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
1015 if(victim->weaponactive!=-1){
1016 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1017 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1018 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1019 emit_sound_at(swordstaffsound, victim->coords);
1022 emit_sound_at(metalhitsound, victim->coords);
1026 victim->Puff(righthand);
1028 victim->targetframe=0;
1029 victim->targetanimation=staggerbackhighanim;
1030 victim->targetrotation=targetrotation+180;
1032 weapons.owner[victim->weaponids[0]]=-1;
1033 aim=DoRotation(facing,0,90,0)*21;
1035 weapons.velocity[victim->weaponids[0]]=aim*-.2;
1036 weapons.tipvelocity[victim->weaponids[0]]=aim;
1037 weapons.missed[victim->weaponids[0]]=1;
1038 weapons.hitsomething[victim->weaponids[0]]=0;
1039 weapons.freetime[victim->weaponids[0]]=0;
1040 weapons.firstfree[victim->weaponids[0]]=1;
1041 weapons.physics[victim->weaponids[0]]=1;
1042 victim->num_weapons--;
1043 if(victim->num_weapons){
1044 victim->weaponids[0]=victim->weaponids[num_weapons];
1045 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1047 victim->weaponactive=-1;
1048 for(int i=0;i<numplayers;i++){
1049 player[i].wentforweapon=0;
1056 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1057 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1058 OPENAL_SetVolume(channels[metalhitsound], 512);
1059 OPENAL_SetPaused(channels[metalhitsound], false);*/
1062 if(abs(Random()%20)==0){
1063 if(weaponactive!=-1){
1064 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1065 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1066 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1068 emit_sound_at(swordstaffsound, coords);
1071 emit_sound_at(metalhitsound, coords);
1079 targetanimation=staggerbackhighanim;
1080 targetrotation=targetrotation+180;
1082 weapons.owner[weaponids[0]]=-1;
1083 aim=DoRotation(facing,0,90,0)*21;
1085 weapons.velocity[weaponids[0]]=aim*-.2;
1086 weapons.tipvelocity[weaponids[0]]=aim;
1087 weapons.hitsomething[weaponids[0]]=0;
1088 weapons.missed[weaponids[0]]=1;
1089 weapons.freetime[weaponids[0]]=0;
1090 weapons.firstfree[weaponids[0]]=1;
1091 weapons.physics[weaponids[0]]=1;
1094 weaponids[0]=weaponids[num_weapons];
1095 if(weaponstuck==num_weapons)weaponstuck=0;
1098 for(int i=0;i<numplayers;i++){
1099 player[i].wentforweapon=0;
1103 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1104 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1105 OPENAL_SetVolume(channels[metalhitsound], 512);
1106 OPENAL_SetPaused(channels[metalhitsound], false);*/
1110 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1111 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1112 //victim->targetanimation=sweepanim;
1113 victim->targetanimation=dodgebackanim;
1114 victim->targetframe=0;
1116 //victim->velocity=0;
1119 rotatetarget=coords-victim->coords;
1120 Normalise(&rotatetarget);
1121 victim->targetrotation=-asin(0-rotatetarget.x);
1122 victim->targetrotation*=360/6.28;
1123 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1125 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1127 victim->lastattack3=victim->lastattack2;
1128 victim->lastattack2=victim->lastattack;
1129 victim->lastattack=victim->targetanimation;
1133 victim->targetanimation=sweepanim;
1134 victim->targetframe=0;
1138 rotatetarget=coords-victim->coords;
1139 Normalise(&rotatetarget);
1140 victim->targetrotation=-asin(0-rotatetarget.x);
1141 victim->targetrotation*=360/6.28;
1142 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1144 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1146 victim->lastattack3=victim->lastattack2;
1147 victim->lastattack2=victim->lastattack;
1148 victim->lastattack=victim->targetanimation;
1155 if(aitype!=playercontrolled)feint=0;
1156 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1157 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1158 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1160 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1164 void Person::DoDamage(float howmuch){
1165 if(tutoriallevel!=1)damage+=howmuch/power;
1166 if(id!=0)damagedealt+=howmuch/power;
1167 if(id==0)damagetaken+=howmuch/power;
1169 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1170 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1171 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1172 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1173 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1175 if(id==0)camerashake+=howmuch/100;
1176 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1177 if(blackout>1)blackout=1;
1179 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1180 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1181 if(abs(Random()%2)==0){aitype=gethelptype;
1184 else aitype=attacktypecutoff;
1188 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1191 for(int i=0;i<skeleton.num_joints; i++){
1192 if(!skeleton.free)flatvelocity2=velocity;
1193 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1194 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1195 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1196 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1197 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1198 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1199 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1200 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1201 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1204 emit_sound_at(splattersound, coords);
1213 if(!dead&&creature==wolftype){
1214 award_bonus(0, Wolfbonus);
1220 if(tutoriallevel!=1||id==0)
1221 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1224 if(creature==wolftype){
1225 int i=abs(Random()%2);
1226 if(i==0)whichsound=snarlsound;
1227 if(i==1)whichsound=snarl2sound;
1228 envsound[numenvsounds]=coords;
1229 envsoundvol[numenvsounds]=16;
1230 envsoundlife[numenvsounds]=.4;
1233 if(creature==rabbittype){
1234 int i=abs(Random()%2);
1235 if(i==0)whichsound=rabbitpainsound;
1236 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1237 envsound[numenvsounds]=coords;
1238 envsoundvol[numenvsounds]=16;
1239 envsoundlife[numenvsounds]=.4;
1241 //if(i==2)whichsound=rabbitpain2sound;
1245 emit_sound_at(whichsound, coords);
1250 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1251 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1254 void Person::DoHead(){
1255 static XYZ rotatearound;
1257 static float lookspeed=500;
1259 if(!freeze&&!winfreeze){
1262 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1263 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1265 while(targetheadrotation>180)targetheadrotation-=360;
1266 while(targetheadrotation<-180)targetheadrotation+=360;
1268 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1269 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1270 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1271 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1273 if(targetheadrotation2>120)targetheadrotation2=120;
1274 if(targetheadrotation2<-120)targetheadrotation2=-120;
1275 if(targetheadrotation>120)targetheadrotation=120;
1276 if(targetheadrotation<-120)targetheadrotation=-120;
1278 if(!isIdle())targetheadrotation2=0;
1280 if(targetheadrotation>80)targetheadrotation=80;
1281 if(targetheadrotation<-80)targetheadrotation=-80;
1282 if(targetheadrotation2>50)targetheadrotation2=50;
1283 if(targetheadrotation2<-50)targetheadrotation2=-50;
1286 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1287 else if(headrotation>targetheadrotation){
1288 headrotation-=multiplier*lookspeed;
1290 else if(headrotation<targetheadrotation){
1291 headrotation+=multiplier*lookspeed;
1294 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1295 else if(headrotation2>targetheadrotation2){
1296 headrotation2-=multiplier*lookspeed/2;
1298 else if(headrotation2<targetheadrotation2){
1299 headrotation2+=multiplier*lookspeed/2;
1302 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1303 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1307 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1308 facing=DoRotation(facing,headrotation2*.4,0,0);
1309 facing=DoRotation(facing,0,headrotation*.4,0);
1312 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1313 facing=DoRotation(facing,headrotation2*.8,0,0);
1314 facing=DoRotation(facing,0,headrotation*.8,0);
1317 if(targetanimation==walkanim){
1318 facing=DoRotation(facing,headrotation2*.6,0,0);
1319 facing=DoRotation(facing,0,headrotation*.6,0);
1322 skeleton.specialforward[0]=facing;
1323 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1325 for(i=0;i<skeleton.num_muscles;i++){
1326 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1328 skeleton.FindRotationMuscle(i,targetanimation);
1334 void Person::RagDoll(bool checkcollision){
1339 if(id==0)numfalls++;
1340 if(id==0&&isFlip())numflipfail++;
1346 facing=DoRotation(facing,0,rotation,0);
1348 skeleton.freetime=0;
1350 skeleton.longdead=0;
1356 skeleton.freefall=1;
1358 if(!isnormal(velocity.x))velocity.x=0;
1359 if(!isnormal(velocity.y))velocity.y=0;
1360 if(!isnormal(velocity.z))velocity.z=0;
1361 if(!isnormal(rotation))rotation=0;
1362 if(!isnormal(coords.x))coords=0;
1363 if(!isnormal(tilt))tilt=0;
1364 if(!isnormal(tilt2))tilt2=0;
1366 for(i=0;i<skeleton.num_joints;i++){
1367 skeleton.joints[i].delay=0;
1368 skeleton.joints[i].locked=0;
1369 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1370 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1371 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1372 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1373 skeleton.joints[i].position.y+=.1;
1374 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1375 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1378 for(i=0;i<skeleton.num_joints;i++){
1379 skeleton.joints[i].velocity=0;
1380 skeleton.joints[i].velchange=0;
1382 skeleton.DoConstraints(&coords,&scale);
1383 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1385 skeleton.DoConstraints(&coords,&scale);
1386 skeleton.DoConstraints(&coords,&scale);
1387 skeleton.DoConstraints(&coords,&scale);
1388 skeleton.DoConstraints(&coords,&scale);
1391 speed=animation[targetanimation].speed[targetframe]*2;
1392 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1393 speed=animation[currentanimation].speed[currentframe]*2;
1395 if(transspeed)speed=transspeed*2;
1399 for(i=0;i<skeleton.num_joints;i++){
1400 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);
1401 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1402 change.x=(float)(Random()%100)/100;
1403 change.y=(float)(Random()%100)/100;
1404 change.z=(float)(Random()%100)/100;
1405 skeleton.joints[i].velocity+=change;
1406 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1408 change.x=(float)(Random()%100)/100;
1409 change.y=(float)(Random()%100)/100;
1410 change.z=(float)(Random()%100)/100;
1411 skeleton.joints[i].velchange+=change;
1412 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1422 for(j=0;j<skeleton.num_joints;j++){
1423 average+=skeleton.joints[j].position;
1427 coords+=average*scale;
1428 for(j=0;j<skeleton.num_joints;j++){
1429 skeleton.joints[j].position-=average;
1432 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1433 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1434 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1435 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1436 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1439 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1440 coords.x=lowpoint.x;
1441 coords.z=lowpoint.z;
1450 for(i=0;i<skeleton.num_joints;i++){
1451 velocity+=skeleton.joints[i].velocity*scale;
1453 velocity/=skeleton.num_joints;
1456 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1457 weapons.owner[weaponids[0]]=-1;
1458 weapons.hitsomething[weaponids[0]]=0;
1459 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1460 weapons.velocity[weaponids[0]].x+=.01;
1461 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1462 weapons.missed[weaponids[0]]=1;
1463 weapons.freetime[weaponids[0]]=0;
1464 weapons.firstfree[weaponids[0]]=1;
1465 weapons.physics[weaponids[0]]=1;
1468 weaponids[0]=weaponids[num_weapons];
1469 if(weaponstuck==num_weapons)weaponstuck=0;
1472 for(i=0;i<numplayers;i++){
1473 player[i].wentforweapon=0;
1478 targetanimation=bounceidleanim;
1479 currentanimation=bounceidleanim;
1487 void Person::FootLand(int which, float opacity){
1488 static XYZ terrainlight;
1489 static XYZ footvel,footpoint;
1490 if(opacity>=1||skiddelay<=0)
1494 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1495 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1496 //footpoint.y=coords.y;
1497 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1499 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1501 if(footvel.y<.8)footvel.y=.8;
1502 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1503 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1504 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1505 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1506 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1507 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1509 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1511 if(footvel.y<.8)footvel.y=.8;
1512 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1513 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1514 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1515 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1516 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);
1518 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1520 if(footvel.y<.8)footvel.y=.8;
1521 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1522 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1523 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1524 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1525 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);
1526 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1528 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
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=coords.y;
1535 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1539 void Person::Puff(int whichlabel){
1540 static XYZ footvel,footpoint;
1543 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1544 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1548 void Person::DoAnimations(){
1551 static float oldtarget;
1553 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1555 if(targetanimation==tempanim||currentanimation==tempanim){
1556 animation[tempanim]=tempanimation;
1558 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1569 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1570 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1572 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1573 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1575 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1580 targfacing=DoRotation(targfacing,0,targetrotation,0);
1582 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1583 else targetanimation=backflipanim;
1584 crouchtogglekeydown=1;
1588 if(id==0)numflipped++;
1591 if(animation[targetanimation].attack!=reversed)feint=0;
1592 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1593 crouchtogglekeydown=0;
1594 if(aitype==playercontrolled)feint=0;
1598 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1599 if(!isFlip())crouchtogglekeydown=1;
1603 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1604 if(detail)normalsupdatedelay=0;
1608 if(targetanimation==rollanim&&targetframe==3&&onfire){
1610 emit_sound_at(fireendsound, coords);
1611 OPENAL_SetPaused(channels[stream_firesound], true);
1615 if(targetanimation==rabbittacklinganim&&targetframe==1){
1616 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1617 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1618 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1619 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1620 else victim->targetanimation=rabbittackledfrontanim;
1621 victim->targetframe=2;
1623 victim->rotation=rotation;
1624 victim->targetrotation=rotation;
1625 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1626 //victim->DoDamage(30);
1627 if(creature==wolftype){
1629 emit_sound_at(clawslicesound, victim->coords);
1631 victim->DoBloodBig(1/victim->armorhead,210);
1633 award_bonus(id, TackleBonus,
1634 victim->aitype == gethelptype ? 50 : 0);
1638 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1639 if(weapons.type[weaponids[0]]==knife){
1640 if(weaponactive==-1)weaponactive=0;
1641 else if(weaponactive==0)weaponactive=-1;
1643 if(weaponactive==-1){
1644 emit_sound_at(knifesheathesound, coords);
1646 if(weaponactive!=-1){
1647 emit_sound_at(knifedrawsound, coords, 128);
1650 drawtogglekeydown=1;
1653 if(tutoriallevel!=1||id==0)
1654 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1665 if(terrain.getOpacity(coords.x,coords.z)<.2){
1666 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1667 else whichsound=footstepsound2;
1668 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1669 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1670 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1676 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1677 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1678 else whichsound=footstepsound4;
1682 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1683 else whichsound=footstepsound4;
1685 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1686 if(animation[targetanimation].attack!=neutral){
1688 if(i==0)whichsound=lowwhooshsound;
1689 if(i==1)whichsound=midwhooshsound;
1690 if(i==2)whichsound=highwhooshsound;
1692 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1694 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1695 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1697 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1698 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1699 if(whichsound!=knifeswishsound)OPENAL_SetVolume(channels[whichsound], 128);
1700 if(whichsound!=knifeswishsound&&(targetanimation==staffhitanim||targetanimation==staffgroundsmashanim||targetanimation==staffspinhitanim))OPENAL_SetVolume(channels[whichsound], 256);
1701 if(whichsound==knifeswishsound)OPENAL_SetVolume(channels[whichsound], 512);
1702 OPENAL_SetPaused(channels[whichsound], false);
1705 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1706 envsound[numenvsounds]=coords;
1707 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1708 else envsoundvol[numenvsounds]=6;
1709 envsoundlife[numenvsounds]=.4;
1713 if(animation[targetanimation].label[targetframe]==3){
1715 emit_sound_at(whichsound, coords, 128.);
1720 if(tutoriallevel!=1||id==0)
1722 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1723 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1725 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1726 if(animation[targetanimation].attack!=neutral){
1728 if(creature==rabbittype){
1729 if(i==0)whichsound=rabbitattacksound;
1730 if(i==1)whichsound=rabbitattack2sound;
1731 if(i==2)whichsound=rabbitattack3sound;
1732 if(i==3)whichsound=rabbitattack4sound;
1734 if(creature==wolftype){
1735 if(i==0)whichsound=barksound;
1736 if(i==1)whichsound=bark2sound;
1737 if(i==2)whichsound=bark3sound;
1738 if(i==3)whichsound=barkgrowlsound;
1742 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1744 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1745 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1748 emit_sound_at(whichsound, coords);
1754 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1760 currentoffset=targetoffset;
1761 targetframe=currentframe;
1762 currentanimation=targetanimation;
1765 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1766 for(i=0;i<weapons.numweapons;i++){
1767 if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1768 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1769 if(findDistancefast(&coords,&weapons.position[i])>=1){
1770 if(weapons.type[i]!=staff){
1771 emit_sound_at(knifedrawsound, coords, 128.);
1775 weapons.owner[i]=id;
1777 weaponids[num_weapons]=weaponids[0];
1786 static bool willwork;
1787 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1788 for(i=0;i<weapons.numweapons;i++){
1790 if(weapons.owner[i]!=-1)
1791 if(player[weapons.owner[i]].weaponstuck!=-1)
1792 if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
1793 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
1794 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))
1795 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
1796 if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
1798 if(weapons.owner[i]!=-1)
1799 if(victim->weaponstuck!=-1){
1800 if(victim->weaponids[victim->weaponstuck]==i){
1805 if(weapons.type[i]!=staff){
1806 emit_sound_at(knifedrawsound, coords, 128.);
1810 emit_sound_at(fleshstabremovesound, coords, 128.);
1813 if(weapons.owner[i]!=-1){
1815 victim=&player[weapons.owner[i]];
1816 if(victim->num_weapons==1)victim->num_weapons=0;
1817 else victim->num_weapons=1;
1819 //victim->weaponactive=-1;
1820 victim->skeleton.longdead=0;
1821 victim->skeleton.free=1;
1822 victim->skeleton.broken=0;
1824 for(int j=0;j<victim->skeleton.num_joints;j++){
1825 victim->skeleton.joints[j].velchange=0;
1826 victim->skeleton.joints[j].locked=0;
1832 Normalise(&relative);
1833 XYZ footvel,footpoint;
1835 footpoint=weapons.position[i];
1836 if(victim->weaponstuck!=-1){
1837 if(victim->weaponids[victim->weaponstuck]==i){
1838 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1839 weapons.bloody[i]=2;
1840 weapons.blooddrip[i]=5;
1841 victim->weaponstuck=-1;
1844 if(victim->num_weapons>0){
1845 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1846 if(victim->weaponids[0]==i)
1847 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1850 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1851 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1852 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1853 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1855 weapons.owner[i]=id;
1857 weaponids[num_weapons]=weaponids[0];
1866 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1867 if(weaponactive==-1)weaponactive=0;
1868 else if(weaponactive==0){
1872 buffer=weaponids[0];
1873 weaponids[0]=weaponids[1];
1874 weaponids[1]=buffer;
1877 if(weaponactive==-1){
1878 emit_sound_at(knifesheathesound, coords, 128.);
1880 if(weaponactive!=-1){
1881 emit_sound_at(knifedrawsound, coords, 128.);
1886 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1887 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1888 Normalise(&rotatetarget);
1889 targetrotation=-asin(0-rotatetarget.x);
1890 targetrotation*=360/6.28;
1891 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1893 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1894 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1899 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1901 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;
1903 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1904 targetanimation=rabbittackleanim;
1906 emit_sound_at(jumpsound, coords);
1915 Normalise(&targetloc);
1917 for(i=0;i<numplayers;i++){
1919 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1920 closestdist=findDistancefast(&targetloc,&player[i].coords);
1925 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1927 victim=&player[closestid];
1928 coords=victim->coords;
1929 currentanimation=rabbittacklinganim;
1930 targetanimation=rabbittacklinganim;
1934 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
1935 rotatetarget=coords-victim->coords;
1936 Normalise(&rotatetarget);
1937 targetrotation=-asin(0-rotatetarget.x);
1938 targetrotation*=360/6.28;
1939 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1941 if(targetanimation!=rabbitrunninganim){
1942 emit_sound_at(jumpsound, coords, 128.);
1948 float damagemult=1*power;
1949 if(creature==wolftype)damagemult=2.5*power;
1950 if(hasvictim){damagemult/=victim->damagetolerance/200;}
1951 //if(onfire)damagemult=3;
1952 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
1953 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
1954 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1956 if(id==0)camerashake+=.4;
1957 if(Random()%2||creature==wolftype){
1960 if(creature==wolftype)DoBloodBig(0,250);
1962 if(tutoriallevel!=1){
1963 emit_sound_at(heavyimpactsound, victim->coords, 128.);
1965 if(creature==wolftype){
1966 emit_sound_at(clawslicesound, victim->coords, 128.);
1968 victim->DoBloodBig(2/victim->armorhead,175);
1972 relative=victim->coords-coords;
1974 Normalise(&relative);
1975 relative=DoRotation(relative,0,-90,0);
1976 for(i=0;i<victim->skeleton.num_joints;i++){
1977 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
1979 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
1982 victim->DoDamage(damagemult*100/victim->protectionhead);
1988 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
1989 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
1991 if(id==0)camerashake+=.4;
1992 if(Random()%2||creature==wolftype){
1994 if(creature==wolftype)DoBloodBig(0,235);
1996 emit_sound_at(whooshhitsound, victim->coords);
1997 if(creature==wolftype){
1998 emit_sound_at(clawslicesound, victim->coords, 128.);
2000 victim->DoBloodBig(2,175);
2004 relative=victim->coords-coords;
2006 Normalise(&relative);
2008 Normalise(&relative);
2009 relative=DoRotation(relative,0,90,0);
2010 for(i=0;i<victim->skeleton.num_joints;i++){
2011 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2013 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2016 victim->DoDamage(damagemult*50/victim->protectionhead);
2020 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
2021 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2023 if(id==0)camerashake+=.4;
2026 if(tutoriallevel!=1){
2027 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2029 if(creature==wolftype){
2030 emit_sound_at(clawslicesound, victim->coords, 128.);
2032 victim->DoBloodBig(2/victim->armorhead,175);
2038 Normalise(&relative);
2039 relative=DoRotation(relative,0,-90,0);
2040 for(i=0;i<victim->skeleton.num_joints;i++){
2041 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2043 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2046 victim->DoDamage(damagemult*150/victim->protectionhead);
2048 if(victim->damage>victim->damagetolerance)
2049 award_bonus(id, style);
2055 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2056 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2058 if(id==0)camerashake+=.4;
2061 if(tutoriallevel!=1){
2062 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2064 if(creature==wolftype){
2065 emit_sound_at(clawslicesound, victim->coords, 128.);
2067 victim->DoBloodBig(2/victim->armorhead,175);
2073 Normalise(&relative);
2074 relative=DoRotation(relative,0,90,0);
2075 for(i=0;i<victim->skeleton.num_joints;i++){
2076 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2078 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2081 victim->DoDamage(damagemult*150/victim->protectionhead);
2083 if(victim->damage>victim->damagetolerance)
2084 award_bonus(id, style);
2090 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2091 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2093 if(id==0)camerashake+=.4;
2098 emit_sound_at(whooshhitsound, victim->coords);
2101 relative=victim->coords-coords;
2103 Normalise(&relative);
2104 for(i=0;i<victim->skeleton.num_joints;i++){
2105 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2107 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2110 victim->DoDamage(damagemult*50/victim->protectionhead);
2114 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2115 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2117 if(id==0)camerashake+=.2;
2118 emit_sound_at(whooshhitsound, victim->coords, 128.);
2120 victim->skeleton.longdead=0;
2121 victim->skeleton.free=1;
2122 victim->skeleton.broken=0;
2123 victim->skeleton.spinny=1;
2125 for(i=0;i<victim->skeleton.num_joints;i++){
2126 victim->skeleton.joints[i].velchange=0;
2127 victim->skeleton.joints[i].delay=0;
2128 victim->skeleton.joints[i].locked=0;
2129 //victim->skeleton.joints[i].velocity=0;
2135 Normalise(&relative);
2136 for(i=0;i<victim->skeleton.num_joints;i++){
2137 victim->skeleton.joints[i].velocity.y=relative.y*10;
2138 victim->skeleton.joints[i].position.y+=relative.y*.3;
2139 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2140 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2142 victim->Puff(abdomen);
2143 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2147 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2148 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2150 if(id==0)camerashake+=.4;
2151 if(tutoriallevel!=1){
2152 emit_sound_at(heavyimpactsound, coords, 128.);
2155 relative=victim->coords-coords;
2157 Normalise(&relative);
2158 for(i=0;i<victim->skeleton.num_joints;i++){
2159 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2161 victim->Puff(abdomen);
2162 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2166 victim->DoDamage(damagemult*500/victim->protectionhigh);
2167 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2171 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2172 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2174 if(id==0)camerashake+=.4;
2175 if(tutoriallevel!=1){
2176 emit_sound_at(thudsound, coords);
2179 victim->skeleton.longdead=0;
2180 victim->skeleton.free=1;
2181 victim->skeleton.broken=0;
2182 victim->skeleton.spinny=1;
2184 for(i=0;i<victim->skeleton.num_joints;i++){
2185 victim->skeleton.joints[i].velchange=0;
2186 //victim->skeleton.joints[i].delay=0;
2187 victim->skeleton.joints[i].locked=0;
2190 relative=victim->coords-coords;
2191 Normalise(&relative);
2193 Normalise(&relative);
2194 for(i=0;i<victim->skeleton.num_joints;i++){
2195 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2200 victim->Puff(abdomen);
2201 victim->DoDamage(damagemult*20/victim->protectionhigh);
2202 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2204 if(!victim->dead)staggerdelay=1.2;
2210 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2211 //if(id==0)camerashake+=.4;
2214 if(!victim->skeleton.free)hasvictim=0;
2217 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2218 emit_sound_at(knifesheathesound, coords, 128.);
2221 if(victim&&hasvictim){
2222 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2224 XYZ where,startpoint,endpoint,movepoint,colpoint;
2225 float rotationpoint;
2227 if(weapons.type[weaponids[weaponactive]]==knife){
2228 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2229 where-=victim->coords;
2230 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2237 if(weapons.type[weaponids[weaponactive]]==sword){
2238 where=weapons.position[weaponids[weaponactive]];
2239 where-=victim->coords;
2240 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2242 where=weapons.tippoint[weaponids[weaponactive]];
2243 where-=victim->coords;
2244 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2247 if(weapons.type[weaponids[weaponactive]]==staff){
2248 where=weapons.position[weaponids[weaponactive]];
2249 where-=victim->coords;
2250 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2252 where=weapons.tippoint[weaponids[weaponactive]];
2253 where-=victim->coords;
2254 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2259 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2262 if(victim->dead!=2){
2263 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2265 award_bonus(id, FinishedBonus);
2267 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2269 victim->skeleton.longdead=0;
2270 victim->skeleton.free=1;
2271 victim->skeleton.broken=0;
2273 for(i=0;i<victim->skeleton.num_joints;i++){
2274 victim->skeleton.joints[i].velchange=0;
2275 victim->skeleton.joints[i].locked=0;
2276 //victim->skeleton.joints[i].velocity=0;
2278 emit_sound_at(fleshstabsound, coords, 128);
2281 if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2282 weapons.blooddrip[weaponids[weaponactive]]+=5;
2283 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2287 emit_sound_at(knifesheathesound, coords, 128.);
2293 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2295 emit_sound_at(knifedrawsound, coords, 128);
2298 if(victim&&hasvictim){
2299 XYZ footvel,footpoint;
2301 emit_sound_at(fleshstabremovesound, coords, 128.);
2304 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2306 if(weapons.type[weaponids[weaponactive]]==sword){
2307 XYZ where,startpoint,endpoint,movepoint;
2308 float rotationpoint;
2311 where=weapons.position[weaponids[weaponactive]];
2312 where-=victim->coords;
2313 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2315 where=weapons.tippoint[weaponids[weaponactive]];
2316 where-=victim->coords;
2317 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2322 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2323 footpoint+=victim->coords;
2326 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2329 if(weapons.type[weaponids[weaponactive]]==staff){
2330 XYZ where,startpoint,endpoint,movepoint;
2331 float rotationpoint;
2334 where=weapons.position[weaponids[weaponactive]];
2335 where-=victim->coords;
2336 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2338 where=weapons.tippoint[weaponids[weaponactive]];
2339 where-=victim->coords;
2340 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2345 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2346 footpoint+=victim->coords;
2349 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2352 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2354 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2355 victim->skeleton.longdead=0;
2356 victim->skeleton.free=1;
2357 victim->skeleton.broken=0;
2359 for(i=0;i<victim->skeleton.num_joints;i++){
2360 victim->skeleton.joints[i].velchange=0;
2361 victim->skeleton.joints[i].locked=0;
2362 //victim->skeleton.joints[i].velocity=0;
2368 Normalise(&relative);
2369 //victim->Puff(abdomen);
2370 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2372 if(victim->bloodloss<victim->damagetolerance){
2373 victim->bloodloss+=1000;
2377 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2381 if(!hasvictim&&onterrain){
2382 weapons.bloody[weaponids[weaponactive]]=0;
2383 weapons.blooddrip[weaponids[weaponactive]]=0;
2387 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2388 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2390 if(id==0)camerashake+=.4;
2395 if(tutoriallevel!=1){
2396 emit_sound_at(heavyimpactsound, victim->coords, 128);
2401 relative=victim->coords-coords;
2403 Normalise(&relative);
2404 for(i=0;i<victim->skeleton.num_joints;i++){
2405 victim->skeleton.joints[i].velocity=relative*30;
2407 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2409 victim->targetframe=0;
2410 victim->targetanimation=staggerbackhardanim;
2411 victim->targetrotation=targetrotation+180;
2416 victim->Puff(abdomen);
2417 victim->DoDamage(damagemult*60/victim->protectionhigh);
2424 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2425 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2427 if(id==0)camerashake+=.4;
2428 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2429 if(tutoriallevel!=1){
2430 emit_sound_at(thudsound, victim->coords);
2433 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2434 if(tutoriallevel!=1){
2435 emit_sound_at(whooshhitsound, victim->coords);
2439 if(tutoriallevel!=1){
2440 emit_sound_at(heavyimpactsound, victim->coords);
2444 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2447 relative=victim->coords-coords;
2449 Normalise(&relative);
2451 Normalise(&relative);
2452 for(i=0;i<victim->skeleton.num_joints;i++){
2453 victim->skeleton.joints[i].velocity=relative*5;
2455 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2457 victim->targetframe=0;
2458 victim->targetanimation=staggerbackhardanim;
2459 victim->targetrotation=targetrotation+180;
2463 victim->Puff(abdomen);
2464 victim->DoDamage(damagemult*60/victim->protectionhigh);
2470 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2471 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2472 if(victim->id==0)camerashake+=.4;
2473 emit_sound_at(landsound2, victim->coords);
2479 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2480 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2481 if(victim->id==0)camerashake+=.4;
2483 if(weaponactive!=-1){
2484 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2485 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2486 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2488 emit_sound_at(swordstaffsound, victim->coords);
2491 emit_sound_at(metalhitsound, victim->coords);
2499 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2500 if(weaponactive!=-1){
2503 weapons.owner[weaponids[0]]=-1;
2504 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);
2506 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2507 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2509 weapons.velocity[weaponids[0]]=aim*50;
2510 weapons.tipvelocity[weaponids[0]]=aim*50;
2511 weapons.missed[weaponids[0]]=0;
2512 weapons.hitsomething[weaponids[0]]=0;
2513 weapons.freetime[weaponids[0]]=0;
2514 weapons.firstfree[weaponids[0]]=1;
2515 weapons.physics[weaponids[0]]=0;
2518 weaponids[0]=weaponids[num_weapons];
2524 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2526 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2528 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2530 award_bonus(id, Slicebonus);
2531 if(tutoriallevel!=1){
2532 emit_sound_at(knifeslicesound, victim->coords);
2534 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2535 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2536 if(victim->id != 0 || difficulty==2){
2537 victim->targetframe=0;
2538 victim->targetanimation=staggerbackhardanim;
2539 victim->targetrotation=targetrotation+180;
2543 victim->lowreversaldelay=0;
2544 victim->highreversaldelay=0;
2545 if(aitype!=playercontrolled)weaponmissdelay=.6;
2547 if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2548 if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
2550 XYZ footvel,footpoint;
2553 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2556 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;
2558 if(tutoriallevel!=1){
2559 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2560 footvel=DoRotation(facing,0,90,0)*.8;
2562 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2563 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2564 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2565 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2567 if(tutoriallevel==1){
2568 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2570 victim->DoDamage(damagemult*0);
2573 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2574 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2575 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2576 award_bonus(id, Slashbonus);
2578 if(tutoriallevel!=1){
2579 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2580 else victim->DoBloodBig(2/victim->armorhigh,185);
2581 victim->deathbleeding=1;
2582 emit_sound_at(swordslicesound, victim->coords);
2584 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2585 if(tutoriallevel!=1){
2586 victim->targetframe=0;
2587 victim->targetanimation=staggerbackhardanim;
2588 victim->targetrotation=targetrotation+180;
2592 if(tutoriallevel!=1){
2593 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2594 weapons.blooddrip[weaponids[weaponactive]]+=3;
2596 float bloodlossamount;
2597 bloodlossamount=200+abs((float)(Random()%40))-20;
2598 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2599 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2600 victim->DoDamage(damagemult*0);
2602 XYZ footvel,footpoint;
2605 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2608 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;
2610 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2611 footvel=DoRotation(facing,0,90,0)*.8;
2613 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2614 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2615 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2616 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2620 if(victim->weaponactive!=-1){
2621 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2622 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2623 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2625 emit_sound_at(swordstaffsound, victim->coords);
2628 emit_sound_at(metalhitsound, victim->coords);
2634 victim->Puff(righthand);
2636 victim->targetframe=0;
2637 victim->targetanimation=staggerbackhighanim;
2638 victim->targetrotation=targetrotation+180;
2640 weapons.owner[victim->weaponids[0]]=-1;
2641 aim=DoRotation(facing,0,90,0)*21;
2643 weapons.velocity[victim->weaponids[0]]=aim*-.2;
2644 weapons.tipvelocity[victim->weaponids[0]]=aim;
2645 weapons.missed[victim->weaponids[0]]=1;
2646 weapons.hitsomething[weaponids[0]]=0;
2647 weapons.freetime[victim->weaponids[0]]=0;
2648 weapons.firstfree[victim->weaponids[0]]=1;
2649 weapons.physics[victim->weaponids[0]]=1;
2650 victim->num_weapons--;
2651 if(victim->num_weapons){
2652 victim->weaponids[0]=victim->weaponids[num_weapons];
2653 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2655 victim->weaponactive=-1;
2656 for(i=0;i<numplayers;i++){
2657 player[i].wentforweapon=0;
2660 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
2661 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
2662 OPENAL_SetVolume(channels[metalhitsound], 512);
2663 OPENAL_SetPaused(channels[metalhitsound], false);*/
2669 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2670 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2671 if(tutoriallevel!=1){
2672 weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
2674 if(id==0)camerashake+=.4;
2675 if(Random()%2||creature==wolftype){
2678 emit_sound_at(staffheadsound, victim->coords);
2682 relative=victim->coords-coords;
2684 Normalise(&relative);
2685 relative=DoRotation(relative,0,90,0);
2687 Normalise(&relative);
2688 for(i=0;i<victim->skeleton.num_joints;i++){
2689 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2691 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2692 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2695 if(tutoriallevel!=1){
2696 victim->DoDamage(damagemult*120/victim->protectionhigh);
2698 award_bonus(id, solidhit, 30);
2703 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2704 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2705 if(tutoriallevel!=1){
2706 weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
2708 if(id==0)camerashake+=.4;
2709 if(Random()%2||creature==wolftype){
2712 emit_sound_at(staffheadsound, victim->coords);
2716 relative=victim->coords-coords;
2718 Normalise(&relative);
2719 relative=DoRotation(relative,0,-90,0);
2720 for(i=0;i<victim->skeleton.num_joints;i++){
2721 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2723 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2724 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2727 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2729 award_bonus(id, solidhit, 60);
2734 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2735 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2737 if(tutoriallevel!=1){
2738 if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
2739 if(id==0)camerashake+=.4;
2740 if(Random()%2||creature==wolftype){
2743 emit_sound_at(staffbodysound, victim->coords);
2745 victim->skeleton.longdead=0;
2746 victim->skeleton.free=1;
2747 victim->skeleton.broken=0;
2749 for(i=0;i<victim->skeleton.num_joints;i++){
2750 victim->skeleton.joints[i].velchange=0;
2751 victim->skeleton.joints[i].locked=0;
2752 //victim->skeleton.joints[i].velocity=0;
2758 /*relative=victim->coords-coords;
2760 Normalise(&relative);
2761 relative=DoRotation(relative,0,90,0);*/
2763 Normalise(&relative);
2765 for(i=0;i<victim->skeleton.num_joints;i++){
2766 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2769 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2772 for(i=0;i<victim->skeleton.num_joints;i++){
2773 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2776 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2778 victim->Puff(abdomen);
2779 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2782 award_bonus(id, solidhit, 40);
2788 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2789 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2791 if(id==0)camerashake+=.4;
2793 relative=victim->coords-coords;
2795 Normalise(&relative);
2799 if(animation[victim->targetanimation].height==lowheight){
2805 for(i=0;i<victim->skeleton.num_joints;i++){
2806 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2808 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2809 if(tutoriallevel!=1){
2810 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2813 victim->DoDamage(damagemult*100/victim->protectionhead);
2814 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2815 if(creature==wolftype){
2816 emit_sound_at(clawslicesound, victim->coords, 128.);
2818 victim->DoBloodBig(2/victim->armorhead,175);
2822 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2823 for(i=0;i<victim->skeleton.num_joints;i++){
2824 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2826 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2827 victim->targetframe=0;
2828 victim->targetanimation=staggerbackhighanim;
2829 victim->targetrotation=targetrotation+180;
2831 if(tutoriallevel!=1){
2832 emit_sound_at(landsound2, victim->coords, 128.);
2834 victim->Puff(abdomen);
2835 victim->DoDamage(damagemult*30/victim->protectionhigh);
2836 if(creature==wolftype){
2837 emit_sound_at(clawslicesound, victim->coords, 128.);
2839 victim->DoBloodBig(2/victim->armorhigh,170);
2846 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2847 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2849 if(id==0)camerashake+=.2;
2850 if(tutoriallevel!=1){
2851 emit_sound_at(landsound2, victim->coords, 128.);
2854 relative=victim->coords-coords;
2856 Normalise(&relative);
2858 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2861 for(i=0;i<victim->skeleton.num_joints;i++){
2862 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2864 relative=DoRotation(relative,0,-90,0);
2866 for(i=0;i<victim->skeleton.num_joints;i++){
2867 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)
2868 victim->skeleton.joints[i].velocity=relative*80;
2870 victim->Puff(rightankle);
2871 victim->Puff(leftankle);
2872 victim->DoDamage(damagemult*40/victim->protectionlow);
2875 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2876 for(i=0;i<victim->skeleton.num_joints;i++){
2877 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2879 relative=DoRotation(relative,0,-90,0);
2880 for(i=0;i<victim->skeleton.num_joints;i++){
2881 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)
2882 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2884 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2885 victim->targetframe=0;
2886 victim->targetanimation=staggerbackhighanim;
2887 victim->targetrotation=targetrotation+180;
2889 if(tutoriallevel!=1){
2890 emit_sound_at(landsound2, victim->coords, 128.);
2892 victim->Puff(abdomen);
2893 victim->DoDamage(damagemult*30/victim->protectionlow);
2901 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2902 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2904 if(id==0)camerashake+=.4;
2909 if(tutoriallevel!=1){
2910 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2912 if(creature==wolftype){
2913 emit_sound_at(clawslicesound, victim->coords, 128);
2915 victim->DoBloodBig(2/victim->armorhigh,170);
2919 relative=victim->coords-oldcoords;
2921 Normalise(&relative);
2922 //relative=DoRotation(relative,0,-90,0);
2923 for(i=0;i<victim->skeleton.num_joints;i++){
2924 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2926 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2928 victim->Puff(abdomen);
2929 victim->DoDamage(damagemult*150/victim->protectionhigh);
2931 award_bonus(id, Reversal);
2934 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
2935 if(victim->weaponactive!=-1&&victim->num_weapons>0){
2936 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
2937 weapons.owner[victim->weaponids[victim->weaponactive]]=id;
2940 weaponids[num_weapons]=weaponids[victim->weaponactive];
2943 weaponids[0]=victim->weaponids[victim->weaponactive];
2944 victim->num_weapons--;
2945 if(victim->num_weapons>0){
2946 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
2947 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2949 victim->weaponactive=-1;
2954 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
2956 if(id==0)camerashake+=.4;
2961 emit_sound_at(whooshhitsound, victim->coords, 128.);
2964 relative=victim->coords-oldcoords;
2966 Normalise(&relative);
2967 //relative=DoRotation(relative,0,-90,0);
2968 for(i=0;i<victim->skeleton.num_joints;i++){
2969 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2971 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2974 victim->DoDamage(damagemult*70/victim->protectionhigh);
2977 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
2979 if(id==0)camerashake+=.4;
2985 award_bonus(id, staffreversebonus);
2987 if(tutoriallevel!=1){
2988 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2991 award_bonus(id, staffreversebonus); // Huh, again?
2994 relative=victim->coords-oldcoords;
2996 Normalise(&relative);
2997 //relative=DoRotation(relative,0,-90,0);
2998 for(i=0;i<victim->skeleton.num_joints;i++){
2999 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3001 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3004 victim->DoDamage(damagemult*70/victim->protectionhigh);
3007 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
3013 Normalise(&relative);
3016 for(i=0;i<victim->skeleton.num_joints;i++){
3017 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3019 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
3020 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
3021 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
3022 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
3023 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
3024 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
3025 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
3026 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
3028 victim->Puff(abdomen);
3029 victim->DoDamage(damagemult*90/victim->protectionhigh);
3031 award_bonus(id, Reversal);
3035 if(weaponactive!=-1||creature==wolftype)doslice=1;
3036 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3038 if(weaponactive!=-1){
3039 victim->DoBloodBig(2/victim->armorhigh,225);
3040 emit_sound_at(knifeslicesound, victim->coords);
3041 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3042 weapons.blooddrip[weaponids[weaponactive]]+=3;
3044 if(weaponactive==-1&&creature==wolftype){;
3045 emit_sound_at(clawslicesound, victim->coords, 128.);
3047 victim->DoBloodBig(2/victim->armorhigh,175);
3054 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3060 Normalise(&relative);
3063 for(i=0;i<victim->skeleton.num_joints;i++){
3064 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3066 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3067 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3068 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3069 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3070 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3071 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3072 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3073 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3075 award_bonus(id, swordreversebonus);
3078 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3080 if(id==0)camerashake+=.4;
3085 if(tutoriallevel!=1){
3086 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3090 relative=victim->coords-oldcoords;
3092 Normalise(&relative);
3093 relative=DoRotation(relative,0,-90,0);
3094 for(i=0;i<victim->skeleton.num_joints;i++){
3095 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3097 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3099 victim->Puff(abdomen);
3100 victim->DoDamage(damagemult*30/victim->protectionhigh);
3102 award_bonus(id, Reversal);
3105 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3108 victim->skeleton.spinny=0;
3112 Normalise(&relative);
3113 if(victim->id==0)relative/=30;
3114 for(i=0;i<victim->skeleton.num_joints;i++){
3115 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3117 //victim->DoDamage(1000);
3118 victim->damage=victim->damagetolerance;
3119 victim->permanentdamage=victim->damagetolerance-1;
3122 if(weaponactive!=-1||creature==wolftype)doslice=1;
3123 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3125 if(weaponactive!=-1){
3126 victim->DoBloodBig(200,225);
3127 emit_sound_at(knifeslicesound, victim->coords);
3128 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3129 weapons.blooddrip[weaponids[weaponactive]]+=5;
3132 if(creature==wolftype&&weaponactive==-1){
3133 emit_sound_at(clawslicesound, victim->coords, 128.);
3135 victim->DoBloodBig(2,175);
3138 award_bonus(id, spinecrusher);
3141 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3142 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3144 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3145 if(targetanimation==knifesneakattackanim){
3146 /*victim->DoBloodBig(200,195);
3151 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3152 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3154 XYZ footvel,footpoint;
3156 footpoint=weapons.tippoint[weaponids[0]];
3157 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3158 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3159 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3160 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3161 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3162 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3163 victim->DoBloodBig(200,195);
3164 award_bonus(id, tracheotomy);
3166 if(targetanimation==knifefollowanim){
3167 award_bonus(id, Stabbonus);
3168 XYZ footvel,footpoint;
3170 footpoint=weapons.tippoint[weaponids[0]];
3171 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3172 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3173 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3174 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3175 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3176 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3179 victim->bloodloss+=10000;
3181 emit_sound_at(fleshstabsound, victim->coords);
3182 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3183 weapons.blooddrip[weaponids[weaponactive]]+=5;
3187 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3190 for(i=0;i<victim->skeleton.num_joints;i++){
3191 victim->skeleton.joints[i].velocity=0;
3193 if(targetanimation==knifefollowanim){
3195 for(i=0;i<victim->skeleton.num_joints;i++){
3196 victim->skeleton.joints[i].velocity=0;
3199 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3200 emit_sound_at(fleshstabremovesound, victim->coords);
3201 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3202 weapons.blooddrip[weaponids[weaponactive]]+=5;
3204 XYZ footvel,footpoint;
3206 footpoint=weapons.tippoint[weaponids[0]];
3207 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3208 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3209 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3210 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3211 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3212 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3216 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3217 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3218 award_bonus(id, backstab);
3222 XYZ footvel,footpoint;
3224 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3225 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3226 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3227 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3228 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3229 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3230 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3231 victim->DoBloodBig(200,180);
3232 victim->DoBloodBig(200,215);
3233 victim->bloodloss+=10000;
3235 emit_sound_at(fleshstabsound, victim->coords);
3236 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3237 weapons.blooddrip[weaponids[weaponactive]]+=5;
3241 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3244 for(i=0;i<victim->skeleton.num_joints;i++){
3245 victim->skeleton.joints[i].velocity=0;
3247 if(weaponactive!=-1){
3248 emit_sound_at(fleshstabremovesound, victim->coords);
3249 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3250 weapons.blooddrip[weaponids[weaponactive]]+=5;
3252 XYZ footvel,footpoint;
3254 footpoint=weapons.tippoint[weaponids[0]];
3255 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3256 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3257 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3258 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3259 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3260 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3264 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3266 if(id==0)camerashake+=.4;
3271 if(weaponactive==-1){
3272 if(tutoriallevel!=1){
3273 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3278 if(weaponactive!=-1||creature==wolftype)doslice=1;
3279 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3281 if(weaponactive!=-1){
3282 victim->DoBloodBig(2/victim->armorhead,225);
3283 emit_sound_at(knifeslicesound, victim->coords);
3284 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3285 weapons.blooddrip[weaponids[weaponactive]]+=3;
3287 if(weaponactive==-1&&creature==wolftype){
3288 emit_sound_at(clawslicesound, victim->coords, 128.);
3290 victim->DoBloodBig(2/victim->armorhead,175);
3294 award_bonus(id, Reversal);
3299 //relative=victim->coords-oldcoords;
3302 Normalise(&relative);
3303 relative=DoRotation(relative,0,90,0);
3305 Normalise(&relative);
3306 for(i=0;i<victim->skeleton.num_joints;i++){
3307 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3309 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3310 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3311 victim->DoDamage(damagemult*100/victim->protectionhead);
3315 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3319 //relative=victim->coords-oldcoords;
3322 Normalise(&relative);
3323 relative=DoRotation(relative,0,90,0);
3325 Normalise(&relative);
3326 for(i=0;i<victim->skeleton.num_joints;i++){
3327 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3329 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3332 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3333 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3334 award_bonus(id, reverseko);
3340 if(targetframe>animation[currentanimation].numframes-1){
3343 targetanimation=getIdle();
3347 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3348 targetanimation=rollanim;
3350 emit_sound_at(movewhooshsound, coords, 128.);
3352 if(currentanimation==staggerbackhighanim){
3353 targetanimation=getIdle();
3355 if(currentanimation==staggerbackhardanim){
3356 targetanimation=getIdle();
3358 if(currentanimation==removeknifeanim){
3359 targetanimation=getIdle();
3361 if(currentanimation==crouchremoveknifeanim){
3362 targetanimation=getCrouch();
3364 if(currentanimation==backhandspringanim){
3365 targetanimation=getIdle();
3367 if(currentanimation==dodgebackanim){
3368 targetanimation=getIdle();
3370 if(currentanimation==drawleftanim){
3371 targetanimation=getIdle();
3373 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3374 targetanimation=getIdle();
3375 if(currentanimation==crouchdrawrightanim){
3376 targetanimation=getCrouch();
3378 if(weaponactive==-1)weaponactive=0;
3379 else if(weaponactive==0){
3383 buffer=weaponids[0];
3384 weaponids[0]=weaponids[1];
3385 weaponids[1]=buffer;
3389 if(weaponactive==-1){
3390 emit_sound_at(knifesheathesound, coords, 128.);
3392 if(weaponactive!=-1){
3393 emit_sound_at(knifedrawsound, coords, 128.);
3396 if(currentanimation==rollanim){
3397 targetanimation=getCrouch();
3402 if(targetanimation==walljumprightkickanim){
3405 if(targetanimation==walljumpleftkickanim){
3408 targetanimation=jumpdownanim;
3410 if(currentanimation==climbanim){
3411 targetanimation=getCrouch();
3414 if(!isnormal(coords.x))
3425 if(targetanimation==rabbitkickreversalanim){
3426 targetanimation=getCrouch();
3429 if(targetanimation==jumpreversalanim){
3430 targetanimation=getCrouch();
3433 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3434 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3436 float closestdist=-1;
3439 for(i=0;i<numplayers;i++){
3440 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3441 distance=findDistancefast(&player[i].coords,&coords);
3442 if(closestdist==-1||distance<closestdist){
3443 closestdist=distance;
3448 if(closestdist>0&&closest>=0&&closestdist<16){
3449 victim=&player[closest];
3450 targetanimation=walljumprightkickanim;
3452 XYZ rotatetarget=victim->coords-coords;
3453 Normalise(&rotatetarget);
3454 rotation=-asin(0-rotatetarget.x);
3456 if(rotatetarget.z<0)rotation=180-rotation;
3457 targettilt2=-asin(rotatetarget.y)*360/6.28;
3458 velocity=(victim->coords-coords)*4;
3463 if(targetanimation==walljumpbackanim){
3464 targetanimation=backflipanim;
3468 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3470 if(targetanimation==walljumprightanim){
3471 targetanimation=rightflipanim;
3475 velocity=DoRotation(facing,0,30,0)*-8;
3478 if(targetanimation==walljumpfrontanim){
3479 targetanimation=frontflipanim;
3481 //targetrotation-=180;
3486 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3488 if(targetanimation==walljumpleftanim){
3491 float closestdist=-1;
3494 for(i=0;i<numplayers;i++){
3495 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3496 distance=findDistancefast(&player[i].coords,&coords);
3497 if(closestdist==-1||distance<closestdist){
3498 closestdist=distance;
3503 if(closestdist>0&&closest>=0&&closestdist<16){
3504 victim=&player[closest];
3505 targetanimation=walljumpleftkickanim;
3507 XYZ rotatetarget=victim->coords-coords;
3508 Normalise(&rotatetarget);
3509 rotation=-asin(0-rotatetarget.x);
3511 if(rotatetarget.z<0)rotation=180-rotation;
3512 targettilt2=-asin(rotatetarget.y)*360/6.28;
3513 velocity=(victim->coords-coords)*4;
3518 if(targetanimation!=walljumpleftkickanim){
3519 targetanimation=leftflipanim;
3523 velocity=DoRotation(facing,0,-30,0)*-8;
3526 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3528 if(targetanimation==sneakattackanim){
3529 float ycoords=oldcoords.y;
3530 currentanimation=getCrouch();
3531 targetanimation=getCrouch();
3534 targetrotation+=180;
3539 targetheadrotation+=180;
3541 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3545 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3546 float ycoords=oldcoords.y;
3547 targetanimation=getIdle();
3549 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3553 if(currentanimation==knifefollowanim){
3554 targetanimation=getIdle();
3557 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3558 float ycoords=oldcoords.y;
3559 targetanimation=getStop();
3560 targetrotation+=180;
3565 targetheadrotation+=180;
3566 if(!isnormal(coords.x))
3568 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3569 oldcoords=coords+facing*.5;
3570 else if(currentanimation==sweepreversalanim)
3571 oldcoords=coords+facing*1.1;
3572 else if(currentanimation==upunchreversalanim){
3573 oldcoords=coords+facing*1.5;
3574 targetrotation+=180;
3576 targetheadrotation+=180;
3580 else if(currentanimation==knifeslashreversalanim){
3581 oldcoords=coords+facing*.5;
3584 targetheadrotation+=90;
3588 else if(currentanimation==staffspinhitreversalanim){
3589 targetrotation+=180;
3591 targetheadrotation+=180;
3595 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3596 else oldcoords.y=ycoords;
3597 currentoffset=coords-oldcoords;
3603 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3608 if(animation[targetanimation].attack==reversed){
3610 if(targetanimation==sweepreversedanim)targetrotation+=90;
3611 targetanimation=backhandspringanim;
3613 emit_sound_at(landsound, coords, 128);
3615 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3616 targetanimation=rollanim;
3619 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3620 coords.y=oldcoords.y;
3622 if(currentanimation==knifeslashreversedanim){
3623 targetanimation=rollanim;
3628 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3629 coords.y=oldcoords.y;
3633 targetanimation=jumpdownanim;
3635 if(wasLanding())targetanimation=getIdle();
3636 if(wasLandhard())targetanimation=getIdle();
3637 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3638 targetanimation=getIdle();
3640 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3641 coords.y=oldcoords.y;
3642 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3643 targetoffset.y=coords.y;
3644 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3645 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3646 currentoffset.y-=(coords.y-targetoffset.y);
3647 coords.y=targetoffset.y;
3649 normalsupdatedelay=0;
3651 if(currentanimation==upunchanim){
3652 targetanimation=getStop();
3653 normalsupdatedelay=0;
3656 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3657 targetrotation=rotation;
3660 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
3661 if(!hasstaff)DoDamage(35);
3664 rabbitkickragdoll=1;
3666 if(currentanimation==rabbitkickreversedanim){
3673 SolidHitBonus(!id); // FIXME: tricky id
3677 targetanimation=rollanim;
3679 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3683 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3689 if(currentanimation==jumpreversedanim){
3696 SolidHitBonus(!id); // FIXME: tricky id
3700 targetanimation=rollanim;
3702 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3707 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){
3708 targetanimation=getupfromfrontanim;
3711 else if(animation[currentanimation].attack==normalattack){
3712 targetanimation=getIdle();
3715 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3716 targetanimation=blockhighleftstrikeanim;
3718 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3719 targetanimation=getIdle();
3722 if(currentanimation==spinkickanim&&victim->skeleton.free){
3723 if(creature==rabbittype)targetanimation=fightidleanim;
3728 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3730 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3731 targetanimation=jumpdownanim;
3736 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3737 if(!isRun()||!wasRun()){
3738 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3739 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3740 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3741 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3743 if(isRun()&&wasRun()){
3746 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3747 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3750 else if(transspeed)target+=multiplier*transspeed*speed*2;
3752 if(!isRun()||!wasRun()){
3753 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3754 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3755 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3756 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3760 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3762 if(target>1){currentframe=targetframe; target=1;}
3764 rot=targetrot*target;
3765 rotation+=rot-oldrot;
3771 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3773 for(i=0;i<skeleton.num_joints;i++){
3774 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3777 skeleton.FindForwards();
3779 for(i=0;i<skeleton.num_muscles;i++){
3780 if(skeleton.muscles[i].visible)
3782 skeleton.FindRotationMuscle(i,targetanimation);
3785 for(i=0;i<skeleton.num_muscles;i++){
3786 if(skeleton.muscles[i].visible)
3788 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3789 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3790 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3795 for(i=0;i<skeleton.num_joints;i++){
3796 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3799 skeleton.FindForwards();
3801 for(i=0;i<skeleton.num_muscles;i++){
3802 if(skeleton.muscles[i].visible)
3804 skeleton.FindRotationMuscle(i,targetanimation);
3807 for(i=0;i<skeleton.num_muscles;i++){
3808 if(skeleton.muscles[i].visible)
3810 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3811 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3812 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3813 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3814 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3815 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3816 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3817 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3818 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3822 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3824 oldcurrentanimation=currentanimation;
3825 oldtargetanimation=targetanimation;
3826 oldtargetframe=targetframe;
3827 oldcurrentframe=currentframe;
3829 for(i=0;i<skeleton.num_joints;i++){
3830 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3831 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3833 offset=currentoffset*(1-target)+targetoffset*target;
3834 for(i=0;i<skeleton.num_muscles;i++){
3835 if(skeleton.muscles[i].visible)
3837 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3838 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3839 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3844 if(isLanding()&&landhard){
3845 if(id==0)camerashake+=.4;
3846 targetanimation=getLandhard();
3853 //skeleton.DoConstraints();
3856 void Person::DoStuff(){
3857 static XYZ terrainnormal;
3858 static XYZ flatfacing;
3859 static XYZ flatvelocity;
3860 static float flatvelspeed;
3864 static int bloodsize;
3865 static int startx,starty,endx,endy;
3866 static int texdetailint;
3867 static GLubyte color;
3868 static XYZ bloodvel;
3870 onfiredelay-=multiplier;
3871 if(onfiredelay<0&&onfire)
3879 crouchkeydowntime+=multiplier;
3880 if(!crouchkeydown)crouchkeydowntime=0;
3881 jumpkeydowntime+=multiplier;
3882 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3884 if(hostile||damage>0||bloodloss>0)immobile=0;
3886 if(isIdle()||isRun())targetoffset=0;
3888 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3890 if(id==0)blooddimamount-=multiplier*.3;
3891 speechdelay-=multiplier;
3892 texupdatedelay-=multiplier;
3893 interestdelay-=multiplier;
3894 flamedelay-=multiplier;
3895 parriedrecently-=multiplier;
3901 if(id==0)speed=1.1*speedmult;
3902 else speed=1.0*speedmult;
3903 if(!skeleton.free)rabbitkickragdoll=0;
3907 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3908 if(id!=0&&creature==wolftype&&difficulty==2){
3910 if(aitype!=passivetype){
3912 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){
3916 if(scale<0.2)superruntoggle=0;
3917 if(targetanimation==wolfrunninganim&&!superruntoggle){
3918 targetanimation=getRun();
3922 if(weaponactive==-1&&num_weapons>0){
3923 if(weapons.type[weaponids[0]]==staff){
3930 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3931 /*if(aitype!=playercontrolled)*/
3933 if(burnt>.6)burnt=.6;
3934 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
3936 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
3947 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
3948 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
3952 while(flamedelay<0&&onfire){
3954 howmany=abs(Random()%(skeleton.num_joints));
3955 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3956 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3957 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3958 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3959 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
3962 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
3964 howmany=abs(Random()%(skeleton.num_joints));
3965 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
3966 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
3967 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
3968 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
3969 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
3973 bleeding-=multiplier*.3;
3975 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
3976 if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
3980 if(neckspurtamount>0){
3981 neckspurtamount-=multiplier;
3982 neckspurtdelay-=multiplier*3;
3983 neckspurtparticledelay-=multiplier*3;
3984 if(neckspurtparticledelay<0&&neckspurtdelay>2){
3988 bloodvel.z=5*neckspurtamount;
3989 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3992 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
3994 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
3995 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
3996 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);
3997 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);
3998 neckspurtparticledelay=.05;
4000 if(neckspurtdelay<0){
4005 if(deathbleeding>0&&dead!=2){
4006 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
4007 else bleeddelay-=5*multiplier/4;
4008 if(bleeddelay<0&&bloodtoggle){
4013 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
4014 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
4015 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
4016 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);
4019 bloodloss+=deathbleeding*multiplier*80;
4020 deathbleeding-=multiplier*1.6;
4021 //if(id==0)deathbleeding-=multiplier*.2;
4022 if(deathbleeding<0)deathbleeding=0;
4023 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
4024 if(weaponactive!=-1){
4025 weapons.owner[weaponids[0]]=-1;
4026 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4027 weapons.velocity[weaponids[0]].x+=.01;
4028 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4029 weapons.missed[weaponids[0]]=1;
4030 weapons.hitsomething[weaponids[0]]=0;
4031 weapons.freetime[weaponids[0]]=0;
4032 weapons.firstfree[weaponids[0]]=1;
4033 weapons.physics[weaponids[0]]=1;
4036 weaponids[0]=weaponids[num_weapons];
4037 if(weaponstuck==num_weapons)weaponstuck=0;
4040 for(i=0;i<numplayers;i++){
4041 player[i].wentforweapon=0;
4053 if(!dead&&creature==wolftype){
4054 award_bonus(0, Wolfbonus);
4057 if(targetanimation==knifefollowedanim&&!skeleton.free){
4058 for(i=0;i<skeleton.num_joints;i++){
4059 skeleton.joints[i].velocity=0;
4060 skeleton.joints[i].velocity.y=-2;
4063 if(id!=0&&unconscioustime>.1){
4071 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
4074 bloodsize=5-realtexdetail;
4078 texdetailint=realtexdetail;
4079 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4080 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4081 endx=startx+bloodsize;
4082 endy=starty+bloodsize;
4084 if(startx<0){startx=0;bleeding=0;}
4085 if(starty<0){starty=0;bleeding=0;}
4086 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
4087 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
4088 if(endx<startx)endx=startx;
4089 if(endy<starty)endy=starty;
4091 for(i=startx;i<endx;i++){
4092 for(j=starty;j<endy;j++){
4094 color=Random()%85+170;
4095 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
4096 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
4097 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
4102 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4103 DoMipmaps(0,startx,endx,starty,endy);
4107 bleedy-=4/realtexdetail;
4108 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
4109 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
4112 bleedx+=4*direction/realtexdetail;
4113 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
4114 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4118 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4119 righthandmorphness=targetrighthandmorphness;
4120 righthandmorphstart=righthandmorphend;
4122 else if(righthandmorphness>targetrighthandmorphness){
4123 righthandmorphness-=multiplier*4;
4125 else if(righthandmorphness<targetrighthandmorphness){
4126 righthandmorphness+=multiplier*4;
4129 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4130 lefthandmorphness=targetlefthandmorphness;
4131 lefthandmorphstart=lefthandmorphend;
4133 else if(lefthandmorphness>targetlefthandmorphness){
4134 lefthandmorphness-=multiplier*4;
4136 else if(lefthandmorphness<targetlefthandmorphness){
4137 lefthandmorphness+=multiplier*4;
4140 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4141 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4142 tailmorphness=targettailmorphness;
4143 tailmorphstart=tailmorphend;
4145 else if(tailmorphness>targettailmorphness){
4146 tailmorphness-=multiplier*10;
4148 else if(tailmorphness<targettailmorphness){
4149 tailmorphness+=multiplier*10;
4153 if(creature==wolftype){
4154 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4155 tailmorphness=targettailmorphness;
4156 tailmorphstart=tailmorphend;
4158 else if(tailmorphness>targettailmorphness){
4159 tailmorphness-=multiplier*2;
4161 else if(tailmorphness<targettailmorphness){
4162 tailmorphness+=multiplier*2;
4166 if(headmorphend==3||headmorphstart==3){
4167 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4168 headmorphness=targetheadmorphness;
4169 headmorphstart=headmorphend;
4171 else if(headmorphness>targetheadmorphness){
4172 headmorphness-=multiplier*7;
4174 else if(headmorphness<targetheadmorphness){
4175 headmorphness+=multiplier*7;
4178 else if(headmorphend==5||headmorphstart==5){
4179 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4180 headmorphness=targetheadmorphness;
4181 headmorphstart=headmorphend;
4183 else if(headmorphness>targetheadmorphness){
4184 headmorphness-=multiplier*10;
4186 else if(headmorphness<targetheadmorphness){
4187 headmorphness+=multiplier*10;
4191 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4192 headmorphness=targetheadmorphness;
4193 headmorphstart=headmorphend;
4195 else if(headmorphness>targetheadmorphness){
4196 headmorphness-=multiplier*4;
4198 else if(headmorphness<targetheadmorphness){
4199 headmorphness+=multiplier*4;
4203 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4204 chestmorphness=targetchestmorphness;
4205 chestmorphstart=chestmorphend;
4207 else if(chestmorphness>targetchestmorphness){
4208 chestmorphness-=multiplier;
4210 else if(chestmorphness<targetchestmorphness){
4211 chestmorphness+=multiplier;
4214 if(dead!=2&&howactive<=typesleeping){
4215 if(chestmorphstart==0&&chestmorphend==0){
4217 targetchestmorphness=1;
4220 if(chestmorphstart!=0&&chestmorphend!=0){
4222 targetchestmorphness=1;
4224 if(environment==snowyenvironment){
4227 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4228 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4229 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4230 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4231 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4232 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4236 if(!dead&&howactive<typesleeping){
4237 blinkdelay-=multiplier*2;
4238 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4240 targetheadmorphness=1;
4242 blinkdelay=(float)(abs(Random()%40))/5;
4244 if(headmorphstart==3&&headmorphend==3){
4246 targetheadmorphness=1;
4251 twitchdelay-=multiplier*1.5;
4252 if(targetanimation!=hurtidleanim){
4253 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4255 targetheadmorphness=1;
4257 twitchdelay=(float)(abs(Random()%40))/5;
4259 if(headmorphstart==5&&headmorphend==5){
4261 targetheadmorphness=1;
4265 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4266 twitchdelay3-=multiplier*1;
4268 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4269 righthandmorphness=0;
4270 targetrighthandmorphness=1;
4271 righthandmorphend=1;
4272 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4274 if(righthandmorphstart==1&&righthandmorphend==1){
4275 righthandmorphness=0;
4276 targetrighthandmorphness=1;
4277 righthandmorphend=0;
4281 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4282 lefthandmorphness=0;
4283 targetlefthandmorphness=1;
4285 twitchdelay3=(float)(abs(Random()%40))/5;
4287 if(lefthandmorphstart==1&&lefthandmorphend==1){
4288 lefthandmorphness=0;
4289 targetlefthandmorphness=1;
4296 if(creature==rabbittype){
4297 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4298 else twitchdelay2-=multiplier*0.5;
4299 if(howactive<=typesleeping){
4300 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4302 targettailmorphness=1;
4304 twitchdelay2=(float)(abs(Random()%40))/5;
4306 if(tailmorphstart==1&&tailmorphend==1){
4308 targettailmorphness=1;
4311 if(tailmorphstart==2&&tailmorphend==2){
4313 targettailmorphness=1;
4320 if(creature==wolftype){
4321 twitchdelay2-=multiplier*1.5;
4323 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4325 targettailmorphness=1;
4330 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4332 targettailmorphness=1;
4336 if(twitchdelay2<=0){
4337 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4339 targettailmorphness=1;
4342 if(tailmorphstart==1&&tailmorphend==1){
4344 targettailmorphness=1;
4347 if(tailmorphstart==2&&tailmorphend==2){
4349 targettailmorphness=1;
4352 if(tailmorphstart==3&&tailmorphend==3){
4354 targettailmorphness=1;
4357 if(tailmorphstart==4&&tailmorphend==4){
4359 targettailmorphness=1;
4365 if(dead!=1)unconscioustime=0;
4367 if(dead==1||howactive==typesleeping){
4368 unconscioustime+=multiplier;
4369 //If unconscious, close eyes and mouth
4370 if(righthandmorphend!=0)righthandmorphness=0;
4371 righthandmorphend=0;
4372 targetrighthandmorphness=1;
4374 if(lefthandmorphend!=0)lefthandmorphness=0;
4376 targetlefthandmorphness=1;
4378 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4380 targetheadmorphness=1;
4384 if(howactive>typesleeping){
4387 if(bloodtoggle&&!bled){
4388 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4390 if(bloodtoggle&&!bled)
4391 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4392 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4393 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4397 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4402 if(dead==2||howactive>typesleeping){
4403 //If dead, open mouth and hands
4404 if(righthandmorphend!=0)righthandmorphness=0;
4405 righthandmorphend=0;
4406 targetrighthandmorphness=1;
4408 if(lefthandmorphend!=0)lefthandmorphness=0;
4410 targetlefthandmorphness=1;
4412 if(headmorphend!=2)headmorphness=0;
4414 targetheadmorphness=1;
4417 if(stunned>0&&!dead&&headmorphend!=2){
4418 if(headmorphend!=4)headmorphness=0;
4420 targetheadmorphness=1;
4423 if(damage>damagetolerance&&!dead){
4428 if(creature==wolftype){
4429 award_bonus(0, Wolfbonus);
4434 if(weaponactive!=-1){
4435 weapons.owner[weaponids[0]]=-1;
4436 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4437 weapons.velocity[weaponids[0]].x+=.01;
4438 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4439 weapons.missed[weaponids[0]]=1;
4440 weapons.hitsomething[weaponids[0]]=0;
4441 weapons.freetime[weaponids[0]]=0;
4442 weapons.firstfree[weaponids[0]]=1;
4443 weapons.physics[weaponids[0]]=1;
4446 weaponids[0]=weaponids[num_weapons];
4447 if(weaponstuck==num_weapons)weaponstuck=0;
4450 for(i=0;i<numplayers;i++){
4451 player[i].wentforweapon=0;
4457 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4465 //if(dead)damage-=multiplier/4;
4466 if(!dead)damage-=multiplier*13;
4467 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4468 if(!dead)permanentdamage-=multiplier*4;
4469 if(isIdle()||isCrouch()){
4470 if(!dead)permanentdamage-=multiplier*4;
4471 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4473 if(damage<0)damage=0;
4474 if(permanentdamage<0)permanentdamage=0;
4475 if(superpermanentdamage<0)superpermanentdamage=0;
4476 if(permanentdamage<superpermanentdamage){
4477 permanentdamage=superpermanentdamage;
4479 if(damage<permanentdamage){
4480 damage=permanentdamage;
4482 if(dead==1&&damage<damagetolerance){
4486 for(i=0;i<skeleton.num_joints;i++){
4487 skeleton.joints[i].velocity=0;
4490 if(permanentdamage>damagetolerance&&dead!=2){
4493 if(weaponactive!=-1){
4494 weapons.owner[weaponids[0]]=-1;
4495 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4496 weapons.velocity[weaponids[0]].x+=.01;
4497 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4498 weapons.missed[weaponids[0]]=1;
4499 weapons.hitsomething[weaponids[0]]=0;
4500 weapons.freetime[weaponids[0]]=0;
4501 weapons.firstfree[weaponids[0]]=1;
4502 weapons.physics[weaponids[0]]=1;
4505 weaponids[0]=weaponids[num_weapons];
4506 if(weaponstuck==num_weapons)weaponstuck=0;
4509 for(i=0;i<numplayers;i++){
4510 player[i].wentforweapon=0;
4516 if(!dead&&creature==wolftype){
4517 award_bonus(0, Wolfbonus);
4520 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4521 award_bonus(id, touchofdeath);
4522 if(id!=0&&unconscioustime>.1){
4530 emit_sound_at(breaksound, coords);
4531 /*if(id==0||findDistancefast(&coords,&viewer)<50){
4537 if(skeleton.free==1){
4538 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4541 //If knocked over, open hands and close mouth
4542 if(righthandmorphend!=0)righthandmorphness=0;
4543 righthandmorphend=0;
4544 targetrighthandmorphness=1;
4546 if(lefthandmorphend!=0)lefthandmorphness=0;
4548 targetlefthandmorphness=1;
4550 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4551 if(headmorphend!=0)headmorphness=0;
4553 targetheadmorphness=1;
4557 skeleton.DoGravity(&scale);
4559 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4560 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4561 award_bonus(id, deepimpact);
4562 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4566 for(j=0;j<skeleton.num_joints;j++){
4567 average+=skeleton.joints[j].position;
4571 coords+=average*scale;
4572 for(j=0;j<skeleton.num_joints;j++){
4573 skeleton.joints[j].position-=average;
4575 average/=multiplier;
4577 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4579 for(i=0;i<skeleton.num_joints;i++){
4580 velocity+=skeleton.joints[i].velocity*scale;
4582 velocity/=skeleton.num_joints;
4584 if(!isnormal(velocity.x)&&velocity.x){
4597 if(findLength(&average)<10&&dead&&skeleton.free){
4598 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4599 if(skeleton.longdead>2000){
4600 if(skeleton.longdead>6000){
4601 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4606 if(dead==2&&bloodloss<damagetolerance){
4608 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4610 if(bloodtoggle&&!bled){
4611 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4613 if(bloodtoggle&&!bled)
4614 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4615 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4616 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4620 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4624 if(dead==2&&bloodloss>=damagetolerance){
4626 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4627 if(bleeding<=0)DoBlood(1,255);
4628 if(bloodtoggle&&!bled){
4629 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4631 if(bloodtoggle&&!bled)
4632 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4633 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4634 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4638 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4645 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4647 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4651 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4652 if(velocity.y<-30)canrecover=0;
4653 for(i=0;i<objects.numobjects;i++){
4654 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4655 colviewer=startpoint;
4657 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4665 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4666 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4667 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4668 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4670 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4671 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4672 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4674 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4675 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4676 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4678 Normalise(&terrainnormal);
4680 targetrotation=-asin(0-terrainnormal.x);
4681 targetrotation*=360/6.28;
4682 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4683 rotation=targetrotation;
4687 targetanimation=flipanim;
4688 crouchtogglekeydown=1;
4693 currentanimation=tempanim;
4696 //tilt2=targettilt2;
4698 //if(middle.y>0)targetoffset.y=middle.y+1;
4700 for(i=0;i<skeleton.num_joints;i++){
4701 tempanimation.position[i][0]=skeleton.joints[i].position;
4702 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4707 if(findLength(&average)<10&&!dead&&skeleton.free){
4708 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4709 if(skeleton.longdead>(damage+500)*1.5){
4710 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4716 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4717 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4718 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4719 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4721 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4722 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4723 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4725 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4726 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4727 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4729 Normalise(&terrainnormal);
4731 targetrotation=-asin(0-terrainnormal.x);
4732 targetrotation*=360/6.28;
4733 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4734 rotation=targetrotation;
4737 terrainnormal=terrain.getNormal(coords.x,coords.z);
4738 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4742 /*XYZ otherterrainnormal;
4743 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
4744 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4745 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4746 targettilt2=asin(otherterrainnormal.y)*180/3.14;
4749 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4753 if(skeleton.forward.y<0){
4754 targetanimation=getupfrombackanim;
4758 if(skeleton.forward.y>-.3){
4759 targetanimation=getupfromfrontanim;
4761 targetrotation+=180;
4767 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4768 targetanimation=rollanim;
4769 targetrotation=lookrotation;
4773 if(forwardkeydown)targetrotation+=45;
4774 if(backkeydown)targetrotation-=45;
4778 if(forwardkeydown)targetrotation-=45;
4779 if(backkeydown)targetrotation+=45;
4782 if ( !leftkeydown&&!rightkeydown)
4783 targetrotation+=180;
4785 targetrotation+=180;
4789 if(abs(targettilt2)>50)targettilt2=0;
4790 currentanimation=tempanim;
4795 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4797 for(i=0;i<skeleton.num_joints;i++){
4798 tempanimation.position[i][0]=skeleton.joints[i].position;
4799 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4806 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4807 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4810 tempvelocity=velocity;
4811 Normalise(&tempvelocity);
4812 targetrotation=-asin(0-tempvelocity.x);
4813 targetrotation*=360/6.28;
4814 if(velocity.z<0)targetrotation=180-targetrotation;
4815 //targetrotation+=180;
4818 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4819 targetanimation=rollanim;
4823 targetanimation=backhandspringanim;
4824 targetrotation+=180;
4829 emit_sound_at(movewhooshsound, coords, 128.);
4831 currentanimation=targetanimation;
4832 currentframe=targetframe-1;
4837 rotation=targetrotation;
4844 if(skeleton.freefall==0)freefall=0;
4846 if(!isnormal(velocity.x)&&velocity.x){
4851 if(aitype!=passivetype||skeleton.free==1)
4852 if(findLengthfast(&velocity)>.1)
4853 for(i=0;i<objects.numobjects;i++){
4854 if(objects.type[i]==firetype)
4855 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){
4857 if(!objects.onfire[i]){
4858 emit_sound_at(firestartsound, objects.position[i]);
4860 objects.onfire[i]=1;
4863 if(objects.onfire[i]){
4868 if(objects.type[i]==bushtype)
4869 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){
4871 if(!objects.onfire[i]){
4872 emit_sound_at(firestartsound, objects.position[i]);
4874 objects.onfire[i]=1;
4878 if(objects.onfire[i]){
4882 if(objects.messedwith[i]<=0){
4886 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4889 envsound[numenvsounds]=coords;
4890 envsoundvol[numenvsounds]=4*findLength(&velocity);
4891 envsoundlife[numenvsounds]=.4;
4896 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4897 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4899 if(environment!=desertenvironment)
4900 for(j=0;j<howmany;j++){
4901 tempvel.x=float(abs(Random()%100)-50)/20;
4902 tempvel.y=float(abs(Random()%100)-50)/20;
4903 tempvel.z=float(abs(Random()%100)-50)/20;
4906 pos.x+=float(abs(Random()%100)-50)/200;
4907 pos.y+=float(abs(Random()%100)-50)/200;
4908 pos.z+=float(abs(Random()%100)-50)/200;
4909 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);
4910 Sprite::setLastSpriteSpecial(1);
4912 howmany=findLength(&velocity)*4;
4914 if(environment==snowyenvironment)
4915 for(j=0;j<howmany;j++){
4916 tempvel.x=float(abs(Random()%100)-50)/20;
4917 tempvel.y=float(abs(Random()%100)-50)/20;
4918 tempvel.z=float(abs(Random()%100)-50)/20;
4921 pos.x+=float(abs(Random()%100)-50)/200;
4922 pos.y+=float(abs(Random()%100)-50)/200;
4923 pos.z+=float(abs(Random()%100)-50)/200;
4924 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4925 Sprite::setLastSpriteSpecial(2);
4928 objects.rotx[i]+=velocity.x*multiplier*6;
4929 objects.roty[i]+=velocity.z*multiplier*6;
4930 objects.messedwith[i]=.5;
4933 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4934 if(objects.rotation2[i]==0)tempcoord=coords;
4936 tempcoord=coords-objects.position[i];
4937 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
4938 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
4939 tempcoord+=objects.position[i];
4941 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]){
4942 if(objects.messedwith[i]<=0){
4946 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4949 envsound[numenvsounds]=coords;
4950 envsoundvol[numenvsounds]=4*findLength(&velocity);
4951 envsoundlife[numenvsounds]=.4;
4956 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4957 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4959 if(environment!=desertenvironment)
4960 for(j=0;j<howmany;j++){
4961 tempvel.x=float(abs(Random()%100)-50)/20;
4962 tempvel.y=float(abs(Random()%100)-50)/20;
4963 tempvel.z=float(abs(Random()%100)-50)/20;
4967 pos.x+=float(abs(Random()%100)-50)/150;
4968 pos.y+=float(abs(Random()%100)-50)/150;
4969 pos.z+=float(abs(Random()%100)-50)/150;
4970 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);
4971 Sprite::setLastSpriteSpecial(1);
4973 howmany=findLength(&velocity)*4;
4975 if(environment==snowyenvironment)
4976 for(j=0;j<howmany;j++){
4977 tempvel.x=float(abs(Random()%100)-50)/20;
4978 tempvel.y=float(abs(Random()%100)-50)/20;
4979 tempvel.z=float(abs(Random()%100)-50)/20;
4983 pos.x+=float(abs(Random()%100)-50)/150;
4984 pos.y+=float(abs(Random()%100)-50)/150;
4985 pos.z+=float(abs(Random()%100)-50)/150;
4986 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4987 Sprite::setLastSpriteSpecial(2);
4990 objects.messedwith[i]=.5;
4998 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
5000 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
5001 if(tutoriallevel==1&&id!=0)play=0;
5002 if(play&&aitype!=playercontrolled){
5006 if(creature==rabbittype){
5007 if(i==0)whichsound=rabbitchitter;
5008 if(i==1)whichsound=rabbitchitter2;
5010 if(creature==wolftype){
5011 if(i==0)whichsound=growlsound;
5012 if(i==1)whichsound=growl2sound;
5018 emit_sound_at(whichsound, coords);
5022 if(targetanimation==staggerbackhighanim)staggerdelay=1;
5023 if(targetanimation==staggerbackhardanim)staggerdelay=1;
5024 staggerdelay-=multiplier;
5025 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
5026 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
5027 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
5028 targetanimation=getIdle();
5032 weaponmissdelay-=multiplier;
5033 highreversaldelay-=multiplier;
5034 lowreversaldelay-=multiplier;
5035 lastcollide-=multiplier;
5036 skiddelay-=multiplier;
5037 if(!isnormal(velocity.x)&&velocity.x){
5040 if(!isnormal(targettilt)&&targettilt){
5043 if(!isnormal(targettilt2)&&targettilt2){
5046 if(!isnormal(targetrotation)&&targetrotation){
5050 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
5051 //open hands and close mouth
5052 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5053 righthandmorphness=0;
5054 righthandmorphend=0;
5055 targetrighthandmorphness=1;
5058 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5059 lefthandmorphness=0;
5061 targetlefthandmorphness=1;
5064 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
5067 targetheadmorphness=1;
5071 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){
5072 //open hands and mouth
5073 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5074 righthandmorphness=0;
5075 righthandmorphend=0;
5076 targetrighthandmorphness=1;
5079 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5080 lefthandmorphness=0;
5082 targetlefthandmorphness=1;
5085 if(headmorphend!=1&&headmorphness==targetheadmorphness){
5088 targetheadmorphness=1;
5092 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
5093 //close hands and mouth
5094 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5095 righthandmorphness=0;
5096 righthandmorphend=1;
5097 targetrighthandmorphness=1;
5100 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5101 lefthandmorphness=0;
5103 targetlefthandmorphness=1;
5106 if(headmorphend!=0&&headmorphness==targetheadmorphness){
5109 targetheadmorphness=1;
5113 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){
5114 //close hands and yell
5115 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5116 righthandmorphness=0;
5117 righthandmorphend=1;
5118 targetrighthandmorphness=1;
5121 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5122 lefthandmorphness=0;
5124 targetlefthandmorphness=1;
5127 if(headmorphend!=2&&headmorphness==targetheadmorphness){
5130 targetheadmorphness=1;
5134 if(speechdelay>.25){
5135 if(headmorphend!=2)headmorphness=0;
5137 targetheadmorphness=1;
5143 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
5144 behind=(normaldotproduct(facing,coords-victim->coords)>0);
5148 if(!dead&&targetanimation!=hurtidleanim)
5149 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
5150 if(headmorphend!=4||headmorphness==targetheadmorphness){
5153 targetheadmorphness=1;
5157 if(weaponactive!=-1){
5158 if(weapons.type[weaponids[weaponactive]]!=staff){
5159 righthandmorphstart=1;
5160 righthandmorphend=1;
5162 if(weapons.type[weaponids[weaponactive]]==staff){
5163 righthandmorphstart=2;
5164 righthandmorphend=2;
5166 targetrighthandmorphness=1;
5169 terrainnormal=terrain.getNormal(coords.x,coords.z);
5171 if(animation[targetanimation].attack!=reversal){
5172 if(!isnormal(coords.x))
5180 flatfacing=DoRotation(flatfacing,0,rotation,0);
5182 ReflectVector(&facing,terrainnormal);
5185 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5186 if(onterrain)targettilt2=-facing.y*20;
5190 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5191 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5192 flatvelocity=velocity;
5194 flatvelspeed=findLength(&flatvelocity);
5195 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5196 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5197 if(velocity.y<0)targettilt2*=-1;
5198 if(velocity.y<0)targettilt*=-1;
5199 if(targettilt>25)targettilt=25;
5200 if(targettilt<-25)targettilt=-25;
5203 if(targettilt2>45)targettilt2=45;
5204 if(targettilt2<-45)targettilt2=-45;
5205 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5206 else if(tilt2>targettilt2){
5207 tilt2-=multiplier*400;
5209 else if(tilt2<targettilt2){
5210 tilt2+=multiplier*400;
5212 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5213 if(tilt2>25)tilt2=25;
5214 if(tilt2<-25)tilt2=-25;
5217 if(!isnormal(targettilt)&&targettilt){
5220 if(!isnormal(targettilt2)&&targettilt2){
5225 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5226 if(targetanimation==rabbittackleanim){
5227 velocity+=facing*multiplier*speed*700*scale;
5228 velspeed=findLength(&velocity);
5229 if(velspeed>speed*65*scale){
5231 velspeed=speed*65*scale;
5234 velocity.y+=gravity*multiplier*20;
5235 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5236 velspeed=findLength(&velocity);
5237 velocity=flatfacing*velspeed;
5239 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5240 if(isRun()||targetanimation==rabbitkickanim){
5241 velocity+=facing*multiplier*speed*700*scale;
5242 velspeed=findLength(&velocity);
5243 if(velspeed>speed*45*scale){
5245 velspeed=speed*45*scale;
5248 velocity.y+=gravity*multiplier*20;
5249 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5250 velspeed=findLength(&velocity);
5251 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5252 velocity=flatfacing*velspeed;
5256 velocity+=facing*multiplier*speed*700*scale;
5257 velspeed=findLength(&velocity);
5258 if(creature==rabbittype){
5259 if(velspeed>speed*55*scale){
5261 velspeed=speed*55*scale;
5265 if(creature==wolftype){
5266 if(velspeed>speed*75*scale){
5268 velspeed=speed*75*scale;
5272 velocity.y+=gravity*multiplier*20;
5273 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5274 velspeed=findLength(&velocity);
5275 velocity=flatfacing*velspeed;
5278 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5279 velocity+=facing*multiplier*speed*700*scale;
5280 velspeed=findLength(&velocity);
5281 if(velspeed>speed*45*scale){
5283 velspeed=speed*45*scale;
5286 velocity.y+=gravity*multiplier*20;
5287 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5288 velspeed=findLength(&velocity);
5289 velocity=flatfacing*velspeed;
5293 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5294 velocity+=facing*multiplier*speed*700*scale;
5295 velspeed=findLength(&velocity);
5296 if(velspeed>speed*25*scale){
5298 velspeed=speed*25*scale;
5301 velocity.y+=gravity*multiplier*20;
5302 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5303 velspeed=findLength(&velocity);
5304 velocity=flatfacing*velspeed;
5307 if(targetanimation==sneakanim||targetanimation==walkanim){
5308 velocity+=facing*multiplier*speed*700*scale;
5309 velspeed=findLength(&velocity);
5310 if(velspeed>speed*12*scale){
5312 velspeed=speed*12*scale;
5315 velocity.y+=gravity*multiplier*20;
5316 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5317 velspeed=findLength(&velocity);
5318 velocity=flatfacing*velspeed;
5321 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5322 velocity+=facing*multiplier*speed*700*scale;
5323 velspeed=findLength(&velocity);
5324 if(velspeed>speed*2*scale){
5326 velspeed=speed*2*scale;
5329 velocity.y+=gravity*multiplier*20;
5330 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5331 velspeed=findLength(&velocity);
5332 velocity=flatfacing*velspeed;
5336 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5337 velocity-=facing*multiplier*speed*700*scale;
5338 velspeed=findLength(&velocity);
5339 if(velspeed>speed*2*scale){
5341 velspeed=speed*2*scale;
5344 velocity.y+=gravity*multiplier*20;
5345 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5346 velspeed=findLength(&velocity);
5347 velocity=flatfacing*velspeed*-1;
5350 if(targetanimation==fightsidestep){
5351 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5352 velspeed=findLength(&velocity);
5353 if(velspeed>speed*12*scale){
5355 velspeed=speed*12*scale;
5358 velocity.y+=gravity*multiplier*20;
5359 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5360 velspeed=findLength(&velocity);
5361 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5364 if(targetanimation==staggerbackhighanim){
5365 coords-=facing*multiplier*speed*16*scale;
5368 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5369 coords-=facing*multiplier*speed*20*scale;
5373 if(targetanimation==backhandspringanim){
5374 //coords-=facing*multiplier*50*scale;
5375 velocity+=facing*multiplier*speed*700*scale*-1;
5376 velspeed=findLength(&velocity);
5377 if(velspeed>speed*50*scale){
5379 velspeed=speed*50*scale;
5382 velocity.y+=gravity*multiplier*20;
5383 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5384 velspeed=findLength(&velocity);
5385 velocity=flatfacing*velspeed*-1;
5387 if(targetanimation==dodgebackanim){
5388 //coords-=facing*multiplier*50*scale;
5389 velocity+=facing*multiplier*speed*700*scale*-1;
5390 velspeed=findLength(&velocity);
5391 if(velspeed>speed*60*scale){
5393 velspeed=speed*60*scale;
5396 velocity.y+=gravity*multiplier*20;
5397 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5398 velspeed=findLength(&velocity);
5399 velocity=flatfacing*velspeed*-1;
5402 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5403 velspeed=findLength(&velocity);
5407 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5408 velocity.y+=gravity*multiplier;
5411 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5413 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5414 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5416 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5422 OPENAL_SetPaused(channels[whooshsound], true);
5423 OPENAL_SetVolume(channels[whooshsound], 0);
5426 if(targetanimation==jumpdownanim||isFlip()){
5427 if(isFlip())jumppower=-4;
5428 targetanimation=getLanding();
5429 emit_sound_at(landsound, coords, 128.);
5432 envsound[numenvsounds]=coords;
5433 envsoundvol[numenvsounds]=16;
5434 envsoundlife[numenvsounds]=.4;
5440 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5441 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5442 coords.y=terrain.getHeight(coords.x,coords.z);
5447 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)){
5448 velspeed=findLength(&velocity);
5450 if(velspeed<multiplier*300*scale){
5452 } else velocity-=velocity/velspeed*multiplier*300*scale;
5453 if(velspeed>5&&(isLanding()||isLandhard())){
5454 skiddingdelay+=multiplier;
5461 else skiddingdelay=0;
5465 velspeed=findLength(&velocity);
5467 if(velspeed<multiplier*600*scale){
5469 } else velocity-=velocity/velspeed*multiplier*600*scale;
5471 if(velspeed>5&&(isLanding()||isLandhard())){
5472 skiddingdelay+=multiplier;
5479 else skiddingdelay=0;
5482 if(skiddingdelay<0)skiddingdelay+=multiplier;
5483 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5485 if(!onterrain||environment==grassyenvironment){
5486 emit_sound_at(skidsound, coords, 128*velspeed/10);
5489 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5493 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5494 terrainnormal=victim->coords-coords;
5495 Normalise(&terrainnormal);
5496 targetrotation=-asin(0-terrainnormal.x);
5497 targetrotation*=360/6.28;
5498 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5499 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5502 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5503 targetrotation=victim->targetrotation;
5505 if(targetanimation==rabbittacklinganim){
5506 coords=victim->coords;
5509 skeleton.oldfree=skeleton.free;
5513 midterrain.x=terrain.size*terrain.scale/2;
5514 midterrain.z=terrain.size*terrain.scale/2;
5515 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5517 tempposit=coords-midterrain;
5519 Normalise(&tempposit);
5520 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5521 coords.x=tempposit.x+midterrain.x;
5522 coords.z=tempposit.z+midterrain.z;
5526 int Person::DrawSkeleton(){
5527 int oldplayerdetail;
5528 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5529 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5539 glAlphaFunc(GL_GREATER, 0.0001);
5541 float terrainheight;
5543 if(!isnormal(rotation))rotation=0;
5544 if(!isnormal(tilt))tilt=0;
5545 if(!isnormal(tilt2))tilt2=0;
5546 oldplayerdetail=playerdetail;
5548 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5551 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5554 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5559 if(playerdetail!=oldplayerdetail) {
5561 normalsupdatedelay=0;
5563 static float updatedelaychange;
5564 static float morphness;
5565 static float framemult;
5567 skeleton.FindForwards();
5568 if(howactive==typesittingwall){
5569 skeleton.specialforward[1]=0;
5570 skeleton.specialforward[1].z=1;
5576 static int weaponattachmuscle;
5577 static int weaponrotatemuscle,weaponrotatemuscle2;
5578 static XYZ weaponpoint;
5579 static int start,endthing;
5580 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5581 if(!isSleeping()&&!isSitting()){
5582 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5583 XYZ point,newpoint,change,change2;
5584 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5585 heightleft=terrain.getHeight(point.x,point.z)+.04;
5587 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5588 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5589 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5590 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5591 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5593 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5594 heightright=terrain.getHeight(point.x,point.z)+.04;
5595 point.y=heightright;
5596 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5597 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5598 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5599 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5600 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5601 skeleton.DoConstraints(&coords,&scale);
5603 if(creature==wolftype){
5604 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5605 heightleft=terrain.getHeight(point.x,point.z)+.04;
5607 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5608 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5609 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5610 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5611 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5613 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5614 heightright=terrain.getHeight(point.x,point.z)+.04;
5615 point.y=heightright;
5616 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5617 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5618 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5619 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5620 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5621 skeleton.DoConstraints(&coords,&scale);
5624 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5625 XYZ point,newpoint,change,change2;
5626 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5627 heightleft=terrain.getHeight(point.x,point.z)+.04;
5629 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5630 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5631 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5632 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5633 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5635 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5636 heightright=terrain.getHeight(point.x,point.z)+.04;
5637 point.y=heightright;
5638 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5639 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5640 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5641 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5642 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5643 skeleton.DoConstraints(&coords,&scale);
5645 if(creature==wolftype){
5646 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5647 heightleft=terrain.getHeight(point.x,point.z)+.04;
5649 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5650 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5651 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5652 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5653 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5655 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5656 heightright=terrain.getHeight(point.x,point.z)+.04;
5657 point.y=heightright;
5658 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5659 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5660 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5661 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5662 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5663 skeleton.DoConstraints(&coords,&scale);
5667 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5668 XYZ point,newpoint,change,change2;
5669 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5670 heightleft=terrain.getHeight(point.x,point.z)+.04;
5672 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5673 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5674 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5675 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5676 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5678 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5679 heightright=terrain.getHeight(point.x,point.z)+.04;
5680 point.y=heightright;
5681 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5682 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5683 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5684 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5685 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5686 skeleton.DoConstraints(&coords,&scale);
5688 if(creature==wolftype){
5689 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5690 heightleft=terrain.getHeight(point.x,point.z)+.04;
5692 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5693 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5694 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5695 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5696 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5698 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5699 heightright=terrain.getHeight(point.x,point.z)+.04;
5700 point.y=heightright;
5701 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5702 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5703 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5704 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5705 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5706 skeleton.DoConstraints(&coords,&scale);
5710 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()))
5713 targetheadrotation=-targetrotation;
5714 targetheadrotation2=0;
5715 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5717 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5718 skeleton.drawmodel.vertex[i]=0;
5719 skeleton.drawmodel.vertex[i].y=999;
5721 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5722 skeleton.drawmodellow.vertex[i]=0;
5723 skeleton.drawmodellow.vertex[i].y=999;
5725 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5726 skeleton.drawmodelclothes.vertex[i]=0;
5727 skeleton.drawmodelclothes.vertex[i].y=999;
5729 for(i=0;i<skeleton.num_muscles;i++){
5730 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5734 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5735 morphness=righthandmorphness;
5736 start=righthandmorphstart;
5737 endthing=righthandmorphend;
5739 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5740 morphness=lefthandmorphness;
5741 start=lefthandmorphstart;
5742 endthing=lefthandmorphend;
5744 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5745 morphness=headmorphness;
5746 start=headmorphstart;
5747 endthing=headmorphend;
5749 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)){
5750 morphness=chestmorphness;
5751 start=chestmorphstart;
5752 endthing=chestmorphend;
5754 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)){
5755 morphness=tailmorphness;
5756 start=tailmorphstart;
5757 endthing=tailmorphend;
5759 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5760 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5761 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5764 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5765 if(!skeleton.free)glRotatef(tilt,0,0,1);
5768 glTranslatef(mid.x,mid.y,mid.z);
5770 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5771 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5773 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5774 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5776 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5777 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5779 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
5783 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
5787 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
5791 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
5796 if(playerdetail||skeleton.free==3)
5798 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5800 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
5801 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
5802 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
5803 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
5804 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
5805 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
5806 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
5807 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5809 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5810 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,
5811 (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,
5812 (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);
5813 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)
5814 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,
5815 (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,
5816 (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);
5817 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)
5818 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,
5819 (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,
5820 (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);
5821 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5822 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,
5823 (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,
5824 (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);
5825 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5826 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5827 //if(!isnormal(scale))test=1;
5828 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5829 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5830 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5835 if(!playerdetail||skeleton.free==3)
5837 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5839 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5841 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5842 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5843 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5844 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5845 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)
5846 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5847 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5848 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5849 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)
5850 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5851 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5852 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5853 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5854 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5855 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5856 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5858 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5859 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5860 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5861 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5867 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5868 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5870 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5873 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5874 if(!skeleton.free)glRotatef(tilt,0,0,1);
5875 glTranslatef(mid.x,mid.y,mid.z);
5876 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5877 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5879 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5880 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5882 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5883 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5885 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5886 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5888 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5889 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5890 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5891 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5892 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)
5893 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5894 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5895 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5896 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)
5897 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5898 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5899 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5900 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5901 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5902 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5903 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5904 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5905 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5906 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5907 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5912 updatedelay=1+(float)(Random()%100)/1000;
5914 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5915 normalsupdatedelay=1;
5916 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5917 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5918 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5922 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5923 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5924 if(skeleton.clothes){
5925 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5930 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5931 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5932 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5933 if(skeleton.free==1)updatedelaychange*=6;
5934 if(id==0)updatedelaychange*=8;
5935 updatedelay+=updatedelaychange;
5937 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5939 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5940 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
5941 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
5942 if(!skeleton.free)glRotatef(rotation,0,1,0);
5945 glColor4f(.4,1,.4,1);
5946 glDisable(GL_LIGHTING);
5947 glDisable(GL_TEXTURE_2D);
5950 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5951 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
5957 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
5958 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);
5959 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);
5960 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);
5961 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);
5962 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);
5963 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);
5969 terrainlight=terrain.getLighting(coords.x,coords.z);
5970 distance=findDistancefast(&viewer,&coords);
5971 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
5972 if(distance>1)distance=1;
5974 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
5975 if(terrainheight<1)terrainheight=1;
5976 if(terrainheight>1.7)terrainheight=1.7;
5979 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
5980 glDisable(GL_BLEND);
5981 glAlphaFunc(GL_GREATER, 0.0001);
5982 glEnable(GL_TEXTURE_2D);
5984 glDisable(GL_TEXTURE_2D);
5985 glColor4f(.7,.35,0,.5);
5987 glEnable(GL_LIGHTING);
5990 if(tutoriallevel&&id!=0){
5991 //glDisable(GL_TEXTURE_2D);
5992 glColor4f(.7,.7,.7,0.6);
5994 glEnable(GL_LIGHTING);
5996 if(canattack&&cananger)
5997 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
5998 glDisable(GL_TEXTURE_2D);
5999 glColor4f(1,0,0,0.8);
6001 glMatrixMode(GL_TEXTURE);
6003 glTranslatef(0,-smoketex,0);
6004 glTranslatef(-smoketex,0,0);
6008 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6009 else skeleton.drawmodel.draw();
6013 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6014 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6017 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
6018 if(tutoriallevel&&id!=0){
6020 glMatrixMode(GL_MODELVIEW);
6021 glEnable(GL_TEXTURE_2D);
6022 glColor4f(.7,.7,.7,0.6);
6024 glEnable(GL_LIGHTING);
6026 if(canattack&&cananger)
6027 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6028 glDisable(GL_TEXTURE_2D);
6029 glColor4f(1,0,0,0.8);
6031 glMatrixMode(GL_TEXTURE);
6033 glTranslatef(0,-smoketex*.6,0);
6034 glTranslatef(smoketex*.6,0,0);
6037 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6038 else skeleton.drawmodel.draw();
6042 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6043 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6048 if(tutoriallevel&&id!=0){
6050 glMatrixMode(GL_MODELVIEW);
6051 glEnable(GL_TEXTURE_2D);
6053 if(skeleton.clothes){
6056 if(!immediate)skeleton.drawmodelclothes.draw();
6057 if(immediate)skeleton.drawmodelclothes.drawimmediate();
6064 for(k=0;k<num_weapons;k++){
6066 if(weaponactive==k){
6067 if(weapons.type[i]!=staff){
6068 for(j=0;j<skeleton.num_muscles;j++){
6069 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6070 weaponattachmuscle=j;
6073 for(j=0;j<skeleton.num_muscles;j++){
6074 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){
6075 weaponrotatemuscle=j;
6078 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6079 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
6081 if(weapons.type[i]==staff){
6082 for(j=0;j<skeleton.num_muscles;j++){
6083 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6084 weaponattachmuscle=j;
6087 for(j=0;j<skeleton.num_muscles;j++){
6088 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){
6089 weaponrotatemuscle=j;
6092 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
6093 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6094 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6095 XYZ tempnormthing,vec1,vec2;
6096 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6097 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
6098 CrossProduct(&vec1,&vec2,&tempnormthing);
6099 Normalise(&tempnormthing);
6100 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);
6101 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
6103 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
6104 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6105 Normalise(&weaptargnorm);
6106 weaponpoint-=weaptargnorm*2;
6110 if(weaponactive!=k&&weaponstuck!=k){
6111 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;
6112 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;
6113 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;
6114 for(j=0;j<skeleton.num_muscles;j++){
6115 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){
6116 weaponrotatemuscle=j;
6121 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
6122 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
6123 for(j=0;j<skeleton.num_muscles;j++){
6124 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){
6125 weaponrotatemuscle=j;
6130 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;
6131 weapons.bigrotation[i]=rotation;
6132 weapons.bigtilt[i]=tilt;
6133 weapons.bigtilt2[i]=tilt2;
6136 weapons.position[i]=weaponpoint*scale+coords;
6137 weapons.bigrotation[i]=0;
6138 weapons.bigtilt[i]=0;
6139 weapons.bigtilt2[i]=0;
6141 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
6142 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
6143 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
6144 if(weaponactive==k){
6145 if(weapons.type[i]==knife){
6146 weapons.smallrotation[i]=180;
6147 weapons.smallrotation2[i]=0;
6148 if(isCrouch()||wasCrouch()){
6149 weapons.smallrotation2[i]=20;
6151 if(targetanimation==hurtidleanim){
6152 weapons.smallrotation2[i]=50;
6154 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
6155 XYZ temppoint1,temppoint2,tempforward;
6158 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6159 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6160 distance=findDistance(&temppoint1,&temppoint2);
6161 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6162 weapons.rotation2[i]*=360/6.28;
6165 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6166 weapons.rotation1[i]*=360/6.28;
6167 weapons.rotation3[i]=0;
6168 weapons.smallrotation[i]=-90;
6169 weapons.smallrotation2[i]=0;
6170 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6172 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
6173 XYZ temppoint1,temppoint2,tempforward;
6176 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6177 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6178 distance=findDistance(&temppoint1,&temppoint2);
6179 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6180 weapons.rotation2[i]*=360/6.28;
6183 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6184 weapons.rotation1[i]*=360/6.28;
6185 weapons.rotation3[i]=0;
6186 weapons.smallrotation[i]=90;
6187 weapons.smallrotation2[i]=0;
6188 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6190 if(targetanimation==knifethrowanim){
6191 weapons.smallrotation[i]=90;
6192 //weapons.smallrotation2[i]=-90;
6193 weapons.smallrotation2[i]=0;
6194 weapons.rotation1[i]=0;
6195 weapons.rotation2[i]=0;
6196 weapons.rotation3[i]=0;
6198 if(targetanimation==knifesneakattackanim&&targetframe<5){
6199 weapons.smallrotation[i]=-90;
6200 weapons.rotation1[i]=0;
6201 weapons.rotation2[i]=0;
6202 weapons.rotation3[i]=0;
6205 if(weapons.type[i]==sword){
6206 weapons.smallrotation[i]=0;
6207 weapons.smallrotation2[i]=0;
6208 if(targetanimation==knifethrowanim){
6209 weapons.smallrotation[i]=-90;
6210 weapons.smallrotation2[i]=0;
6211 weapons.rotation1[i]=0;
6212 weapons.rotation2[i]=0;
6213 weapons.rotation3[i]=0;
6215 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)){
6216 XYZ temppoint1,temppoint2,tempforward;
6219 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6220 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6221 distance=findDistance(&temppoint1,&temppoint2);
6222 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6223 weapons.rotation2[i]*=360/6.28;
6226 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6227 weapons.rotation1[i]*=360/6.28;
6228 weapons.rotation3[i]=0;
6229 weapons.smallrotation[i]=90;
6230 weapons.smallrotation2[i]=0;
6231 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6234 if(weapons.type[i]==staff){
6235 weapons.smallrotation[i]=100;
6236 weapons.smallrotation2[i]=0;
6237 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6238 XYZ temppoint1,temppoint2,tempforward;
6241 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6242 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6243 distance=findDistance(&temppoint1,&temppoint2);
6244 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6245 weapons.rotation2[i]*=360/6.28;
6248 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6249 weapons.rotation1[i]*=360/6.28;
6250 weapons.rotation3[i]=0;
6251 weapons.smallrotation[i]=90;
6252 weapons.smallrotation2[i]=0;
6253 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6257 if(weaponactive!=k&&weaponstuck!=k){
6258 if(weapons.type[i]==knife){
6259 weapons.smallrotation[i]=-70;
6260 weapons.smallrotation2[i]=10;
6262 if(weapons.type[i]==sword){
6263 weapons.smallrotation[i]=-100;
6264 weapons.smallrotation2[i]=-8;
6266 if(weapons.type[i]==staff){
6267 weapons.smallrotation[i]=-100;
6268 weapons.smallrotation2[i]=-8;
6272 if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
6273 else weapons.smallrotation[i]=0;
6274 weapons.smallrotation2[i]=10;
6281 if(skeleton.free)calcrot=1;
6282 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6283 if(currentanimation!=targetanimation)calcrot=1;
6284 //if(id==0)calcrot=1;
6285 if(skeleton.free==2)calcrot=0;
6291 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6294 static float distance;
6295 static float olddistance;
6296 static int intersecting;
6297 static int firstintersecting;
6300 static XYZ start,end;
6301 static float slopethreshold=-.4;
6303 firstintersecting=-1;
6307 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6308 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6310 for (j=0;j<model->TriangleNum;j++){
6311 if(model->facenormals[j].y<=slopethreshold){
6313 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)));
6314 if(distance<radius){
6315 point=*p1-model->facenormals[j]*distance;
6316 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;
6317 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6318 &model->vertex[model->Triangles[j].vertex[1]],
6320 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6321 &model->vertex[model->Triangles[j].vertex[2]],
6323 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6324 &model->vertex[model->Triangles[j].vertex[2]],
6327 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6331 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)){
6332 p1->y=point.y+radius;
6333 if((targetanimation==jumpdownanim||isFlip())){
6334 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6336 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6342 OPENAL_SetPaused(channels[whooshsound], true);
6343 OPENAL_SetVolume(channels[whooshsound], 0);
6346 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6347 if(isFlip())jumppower=-4;
6348 targetanimation=getLanding();
6349 emit_sound_at(landsound, coords, 128.);
6352 envsound[numenvsounds]=coords;
6353 envsoundvol[numenvsounds]=16;
6354 envsoundlife[numenvsounds]=.4;
6362 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6365 for (j=0;j<model->TriangleNum;j++){
6366 if(model->facenormals[j].y>slopethreshold){
6370 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)));
6371 if(distance<radius*.5){
6372 point=start-model->facenormals[j]*distance;
6373 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;
6374 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,
6375 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6376 p1->x, p1->y, p1->z, radius/2);
6377 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,
6378 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6379 p1->x, p1->y, p1->z, radius/2);
6380 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,
6381 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6382 p1->x, p1->y, p1->z, radius/2);
6384 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6385 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6387 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6388 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6390 *p1+=model->facenormals[j]*(distance-radius*.5);
6393 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6397 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6399 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6401 return firstintersecting;
6411 currentanimation = 0;
6412 targetanimation = 0;
6413 oldcurrentframe = 0;
6415 oldcurrentanimation = 0;
6416 oldtargetanimation = 0;
6420 parriedrecently = 0;
6424 lastattack = 0,lastattack2 = 0,lastattack3 = 0;
6426 currentoffset = 0,targetoffset = 0,offset = 0;
6444 unconscioustime = 0;
6462 rabbitkickenabled = 0;
6471 damagetolerance = 0;
6473 permanentdamage = 0;
6474 superpermanentdamage = 0; lastcollide = 0;
6494 headrotation = 0,headrotation2 = 0;
6495 targetheadrotation = 0,targetheadrotation2 = 0;
6506 normalsupdatedelay = 0;
6511 forwardstogglekeydown = 0;
6516 jumptogglekeydown = 0;
6518 crouchtogglekeydown = 0;
6520 drawtogglekeydown = 0;
6522 throwtogglekeydown = 0;
6528 crouchkeydowntime = 0;
6529 jumpkeydowntime = 0;
6546 whichdirectiondelay = 0;
6547 avoidsomething = 0; avoidwhere = 0;
6555 lefthandmorphness = 0;
6556 righthandmorphness = 0;
6560 targetlefthandmorphness = 0;
6561 targetrighthandmorphness = 0;
6562 targetheadmorphness = 0;
6563 targetchestmorphness = 0;
6564 targettailmorphness = 0;
6565 lefthandmorphstart = 0,lefthandmorphend = 0;
6566 righthandmorphstart = 0,righthandmorphend = 0;
6567 headmorphstart = 0,headmorphend = 0;
6568 chestmorphstart = 0,chestmorphend = 0;
6569 tailmorphstart = 0,tailmorphend = 0;
6571 weaponmissdelay = 0;
6572 highreversaldelay = 0;
6573 lowreversaldelay = 0;
6580 //Skeleton skeleton;
6599 memset(clothes, 0, sizeof(clothes));
6600 memset(clothestintr, 0, sizeof(clothestintr));
6601 memset(clothestintg, 0, sizeof(clothestintg));
6602 memset(clothestintb, 0, sizeof(clothestintb));
6608 onfiredelay = 0; burnt = 0;
6612 updatestuffdelay = 0;
6618 memset(weaponids, 0, sizeof(weaponids));
6622 weaponstuckwhere = 0;
6627 memset(waypoints, 0, sizeof(waypoints));
6628 memset(waypointtype, 0, sizeof(waypointtype));
6631 hastempwaypoint = 0;
6637 finalfinaltarget = 0;
6639 finalpathfindpoint = 0;
6640 targetpathfindpoint = 0;
6641 lastpathfindpoint = 0;
6642 lastpathfindpoint2 = 0;
6643 lastpathfindpoint3 = 0;
6644 lastpathfindpoint4 = 0;
6655 runninghowlong = 0; lastoccluded = 0;
6661 neckspurtparticledelay = 0;
6662 neckspurtamount = 0;
6665 rabbitkickragdoll = 0;
6670 //Animation tempanimation;