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 bool Person::isIdle(){
178 if(targetanimation==sleepanim||targetanimation==sitanim||targetanimation==talkidleanim||targetanimation==hurtidleanim||targetanimation==bounceidleanim||targetanimation==talkidleanim||targetanimation==fightidleanim||targetanimation==knifefightidleanim||targetanimation==swordfightidleanim||targetanimation==swordfightidlebothanim||targetanimation==fightsidestep||targetanimation==wolfidle)return 1;
182 bool Person::isSitting(){
183 if(targetanimation==sitanim)return 1;
184 if(targetanimation==sitwallanim)return 1;
188 bool Person::isSleeping(){
189 if(targetanimation==sleepanim)return 1;
190 if(targetanimation==dead1anim)return 1;
191 if(targetanimation==dead2anim)return 1;
192 if(targetanimation==dead3anim)return 1;
193 if(targetanimation==dead4anim)return 1;
197 bool Person::wasIdle(){
198 if(currentanimation==sleepanim||currentanimation==talkidleanim||currentanimation==sitanim||currentanimation==hurtidleanim||currentanimation==bounceidleanim||currentanimation==fightidleanim||currentanimation==swordfightidleanim||currentanimation==swordfightidlebothanim||currentanimation==knifefightidleanim||currentanimation==fightsidestep||currentanimation==wolfidle)return 1;
201 int Person::getIdle(){
202 if(indialogue!=-1&&howactive==typeactive&&creature==rabbittype)return talkidleanim;
203 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)){
204 if((aitype==playercontrolled&&stunned<=0&&weaponactive==-1)||pause){
205 if(creature==rabbittype)return fightidleanim;
206 if(creature==wolftype)return wolfidle;
208 if(aitype==playercontrolled&&stunned<=0&&weaponactive!=-1){
209 if(weapons.type[weaponids[weaponactive]]==knife)return knifefightidleanim;
210 if(weapons.type[weaponids[weaponactive]]==sword&&victim->weaponactive!=-1)return swordfightidlebothanim;
211 if(weapons.type[weaponids[weaponactive]]==sword)return swordfightidleanim;
212 if(weapons.type[weaponids[weaponactive]]==staff)return swordfightidleanim;
214 if(aitype!=playercontrolled&&stunned<=0&&creature!=wolftype&&!pause)return fightsidestep;
216 if((damage>permanentdamage||damage>damagetolerance*.8||deathbleeding>0)&&creature!=wolftype)return hurtidleanim;
217 if(howactive==typesitting)return sitanim;
218 if(howactive==typesittingwall)return sitwallanim;
219 if(howactive==typesleeping)return sleepanim;
220 if(howactive==typedead1)return dead1anim;
221 if(howactive==typedead2)return dead2anim;
222 if(howactive==typedead3)return dead3anim;
223 if(howactive==typedead4)return dead4anim;
224 if(creature==rabbittype)return bounceidleanim;
225 if(creature==wolftype)return wolfidle;
229 bool Person::isCrouch(){
230 if(targetanimation==crouchanim||targetanimation==wolfcrouchanim)return 1;
235 bool Person::wasCrouch(){
236 if(currentanimation==crouchanim||currentanimation==wolfcrouchanim)return 1;
239 int Person::getCrouch(){
240 if(creature==rabbittype)return crouchanim;
241 if(creature==wolftype)return wolfcrouchanim;
245 bool Person::isRun(){
246 if(targetanimation==runanim||targetanimation==wolfrunanim||targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)return 1;
251 bool Person::wasRun(){
252 if(currentanimation==runanim||currentanimation==wolfrunanim||currentanimation==wolfrunninganim||currentanimation==rabbitrunninganim)return 1;
255 int Person::getRun(){
256 if(creature==rabbittype&&(!superruntoggle||weaponactive!=-1))return runanim;
257 if(creature==wolftype&&(!superruntoggle))return wolfrunanim;
259 if(creature==rabbittype&&(superruntoggle&&weaponactive==-1))return rabbitrunninganim;
260 if(creature==wolftype&&(superruntoggle))return wolfrunninganim;
264 bool Person::isStop(){
265 if(targetanimation==stopanim||targetanimation==wolfstopanim)return 1;
270 bool Person::wasStop(){
271 if(currentanimation==stopanim||currentanimation==wolfstopanim)return 1;
274 int Person::getStop(){
275 if(creature==rabbittype)return stopanim;
276 if(creature==wolftype)return wolfstopanim;
281 bool Person::isLanding(){
282 if(targetanimation==landanim||targetanimation==wolflandanim)return 1;
287 bool Person::wasLanding(){
288 if(currentanimation==landanim||currentanimation==wolflandanim)return 1;
291 int Person::getLanding(){
292 if(creature==rabbittype)return landanim;
293 if(creature==wolftype)return wolflandanim;
298 bool Person::isLandhard(){
299 if(targetanimation==landhardanim||targetanimation==wolflandhardanim)return 1;
304 bool Person::wasLandhard(){
305 if(currentanimation==landhardanim||currentanimation==wolflandhardanim)return 1;
308 int Person::getLandhard(){
309 if(creature==rabbittype)return landhardanim;
310 if(creature==wolftype)return wolflandhardanim;
315 bool Person::isFlip(){
316 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==backflipanim||targetanimation==rightflipanim||targetanimation==leftflipanim||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)return 1;
320 bool Person::wasFlip(){
321 if(currentanimation==flipanim||currentanimation==frontflipanim||currentanimation==backflipanim||currentanimation==rightflipanim||currentanimation==leftflipanim||currentanimation==walljumprightkickanim||currentanimation==walljumpleftkickanim)return 1;
325 bool Person::isWallJump(){
326 if(targetanimation==walljumpfrontanim||targetanimation==walljumpbackanim||targetanimation==walljumpleftanim||targetanimation==walljumprightanim)return 1;
331 SolidHitBonus(int playerid)
333 if (bonustime < 1.5 && bonus >= solidhit && bonus <= megacombo)
334 award_bonus(playerid, bonus == megacombo ? bonus : bonus + 1);
336 award_bonus(playerid, solidhit);
339 void Person::DoBlood(float howmuch,int which){
340 static int bleedxint,bleedyint;
342 //if(howmuch&&id==0)blooddimamount=1;
343 if(bloodtoggle&&tutoriallevel!=1){
344 if(bleeding<=0&&spurt){
346 for(int i=0;i<3;i++){
350 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
353 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
355 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
356 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
358 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
359 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
362 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);
363 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);
367 for(int i=0;i<3;i++){
371 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
372 bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
375 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
376 bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
380 Sprite::MakeSprite(splintersprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
382 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);
384 Sprite::setLastSpriteSpecial(3);
389 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
392 int texdetailint=realtexdetail;
393 if(creature==rabbittype)
394 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){
395 bleedxint=abs(Random()%512);
396 bleedyint=abs(Random()%512);
398 if(creature==wolftype)
399 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){
400 bleedxint=abs(Random()%512);
401 bleedyint=abs(Random()%512);
405 bleedy/=realtexdetail;
406 bleedx/=realtexdetail;
407 direction=abs(Random()%2)*2-1;
411 if(bleeding>2)bleeding=2;
414 void Person::DoBloodBig(float howmuch,int which){
415 static int bleedxint,bleedyint,i,j;
417 if(howmuch&&id==0)blooddimamount=1;
419 if(tutoriallevel!=1||id==0)
420 if(aitype!=playercontrolled&&howmuch>0){
423 if(creature==wolftype){
424 int i=abs(Random()%2);
425 if(i==0)whichsound=snarlsound;
426 if(i==1)whichsound=snarl2sound;
427 envsound[numenvsounds]=coords;
428 envsoundvol[numenvsounds]=16;
429 envsoundlife[numenvsounds]=.4;
432 if(creature==rabbittype){
433 int i=abs(Random()%2);
434 if(i==0)whichsound=rabbitpainsound;
435 if(i==1&&howmuch>=2)whichsound=rabbitpain1sound;
436 envsound[numenvsounds]=coords;
437 envsoundvol[numenvsounds]=16;
438 envsoundlife[numenvsounds]=.4;
440 //if(i==2)whichsound=rabbitpain2sound;
444 emit_sound_at(whichsound, coords);
447 if(id==0&&howmuch>0){
455 if(bloodtoggle&&decals&&tutoriallevel!=1){
456 if(bleeding<=0&&spurt){
458 for(int i=0;i<3;i++){
462 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
465 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
467 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
468 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
470 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
471 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
474 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);
475 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);
479 int offsetx=0,offsety=0;
482 offsetx=abs(Random()%60);
484 if(which==190||which==185){
486 offsetx=abs(Random()%100)-20;
496 if(which==220||which==215){
497 //offsety=Random()%20;
499 //offsetx=abs(Random()%80);
508 if(creature==rabbittype)
511 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
512 if(i<startx)startx=i;
513 if(j<starty)starty=j;
519 if(creature==wolftype)
522 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
523 if(i<startx)startx=i;
524 if(j<starty)starty=j;
536 if(startx<0)startx=0;
537 if(starty<0)starty=0;
538 if(endx>512-1)endx=512-1;
539 if(endy>512-1)endy=512-1;
540 if(endx<startx)endx=startx;
541 if(endy<starty)endy=starty;
543 startx/=realtexdetail;
544 starty/=realtexdetail;
548 int texdetailint=realtexdetail;
550 if(creature==rabbittype)
551 for(i=startx;i<endx;i++){
552 for(j=starty;j<endy;j++){
553 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){
554 color=Random()%85+170;
555 where=i*skeleton.skinsize*3+j*3;
556 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
557 skeleton.skinText[where+1]=0;
558 skeleton.skinText[where+2]=0;
562 if(creature==wolftype)
563 for(i=startx;i<endx;i++){
564 for(j=starty;j<endy;j++){
565 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){
566 color=Random()%85+170;
567 where=i*skeleton.skinsize*3+j*3;
568 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
569 skeleton.skinText[where+1]=0;
570 skeleton.skinText[where+2]=0;
574 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
575 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
576 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
580 if(creature==rabbittype)
581 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){
582 bleedxint=abs(Random()%512);
583 bleedyint=abs(Random()%512);
585 if(creature==wolftype)
586 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){
587 bleedxint=abs(Random()%512);
588 bleedyint=abs(Random()%512);
590 bleedy=bleedxint+offsetx;
591 bleedx=bleedyint+offsety;
592 bleedy/=realtexdetail;
593 bleedx/=realtexdetail;
594 if(bleedx<0)bleedx=0;
595 if(bleedy<0)bleedy=0;
596 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
597 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
598 direction=abs(Random()%2)*2-1;
601 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
602 deathbleeding+=bleeding;
603 bloodloss+=bleeding*3;
605 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
606 if(abs(Random()%2)==0){aitype=gethelptype;
609 else aitype=attacktypecutoff;
612 if(bleeding>2)bleeding=2;
615 bool Person::DoBloodBigWhere(float howmuch,int which, XYZ where){
616 static int bleedxint,bleedyint,i,j;
618 static XYZ startpoint,endpoint,colpoint,movepoint;
619 static float rotationpoint;
621 static XYZ p1,p2,p3,p0;
625 float coordsx,coordsy;
628 if(bloodtoggle&&decals&&tutoriallevel!=1){
630 if(!skeleton.free)where=DoRotation(where,0,-rotation,0);
638 whichtri=skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
641 p1=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[0]];
642 p2=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[1]];
643 p3=skeleton.drawmodel.vertex[skeleton.drawmodel.Triangles[whichtri].vertex[2]];
645 CrossProduct(p2-p1,p3-p1,&N);
646 CrossProduct(p0-p1,p3-p1,&temp);
647 s = dotproduct(&temp,&N)/findLength(&N);
648 CrossProduct(p2-p1,p1-p0,&temp);
649 t = dotproduct(&temp,&N)/findLength(&N);
652 bary.x=findDistancefast(&p0,&p1);
653 bary.y=findDistancefast(&p0,&p2);
654 bary.z=findDistancefast(&p0,&p3);
656 total=bary.x+bary.y+bary.z;
665 total=bary.x+bary.y+bary.z;
671 gxx.x=skeleton.drawmodel.Triangles[whichtri].gx[0];
672 gxx.y=skeleton.drawmodel.Triangles[whichtri].gx[1];
673 gxx.z=skeleton.drawmodel.Triangles[whichtri].gx[2];
674 gyy.x=skeleton.drawmodel.Triangles[whichtri].gy[0];
675 gyy.y=skeleton.drawmodel.Triangles[whichtri].gy[1];
676 gyy.z=skeleton.drawmodel.Triangles[whichtri].gy[2];
677 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;
678 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;
680 //coordsx=skeleton.drawmodel.Triangles[whichtri].gx[1];
681 //coordsy=skeleton.drawmodel.Triangles[whichtri].gy[1];
683 if(bleeding<=0&&spurt){
685 for(int i=0;i<3;i++){
689 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
692 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/4,((float)(Random()%100))/4,0);
694 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
695 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
697 Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
698 Sprite::MakeSprite(bloodflamesprite, skeleton.joints[skeleton.jointlabels[head]].position*scale+coords,bloodvel, 1,1,1, .3, 1);
701 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);
702 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);
706 int offsetx=0,offsety=0;
709 offsetx=abs(Random()%120);
711 if(which==220||which==215){
713 offsetx=abs(Random()%80);
716 offsetx=(1+coordsy)*512-291;
717 offsety=coordsx*512-437;
724 if(creature==rabbittype)
727 if(bloodText[i*512*3+j*3+0]<=which+4&&bloodText[i*512*3+j*3+0]>=which-4){
728 if(i<startx)startx=i;
729 if(j<starty)starty=j;
735 if(creature==wolftype)
738 if(wolfbloodText[i*512*3+j*3+0]<=which+4&&wolfbloodText[i*512*3+j*3+0]>=which-4){
739 if(i<startx)startx=i;
740 if(j<starty)starty=j;
751 if(startx<0)startx=0;
752 if(starty<0)starty=0;
753 if(endx>512-1)endx=512-1;
754 if(endy>512-1)endy=512-1;
755 if(endx<startx)endx=startx;
756 if(endy<starty)endy=starty;
758 startx/=realtexdetail;
759 starty/=realtexdetail;
763 int texdetailint=realtexdetail;
765 if(creature==rabbittype)
766 for(i=startx;i<endx;i++){
767 for(j=starty;j<endy;j++){
768 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){
769 color=Random()%85+170;
770 where=i*skeleton.skinsize*3+j*3;
771 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
772 skeleton.skinText[where+1]=0;
773 skeleton.skinText[where+2]=0;
775 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){
776 color=Random()%85+170;
777 where=i*skeleton.skinsize*3+j*3;
778 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
779 skeleton.skinText[where+1]=0;
780 skeleton.skinText[where+2]=0;
784 if(creature==wolftype)
785 for(i=startx;i<endx;i++){
786 for(j=starty;j<endy;j++){
787 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){
788 color=Random()%85+170;
789 where=i*skeleton.skinsize*3+j*3;
790 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
791 skeleton.skinText[where+1]=0;
792 skeleton.skinText[where+2]=0;
794 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){
795 color=Random()%85+170;
796 where=i*skeleton.skinsize*3+j*3;
797 if(skeleton.skinText[where+0]>color/2)skeleton.skinText[where+0]=color/2;
798 skeleton.skinText[where+1]=0;
799 skeleton.skinText[where+2]=0;
803 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
804 if(detail!=2||osx)DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
805 else DoMipmaps(0,startx/realtexdetail,endx/realtexdetail,starty/realtexdetail,endy/realtexdetail);
807 bleedy=(1+coordsy)*512;
809 bleedy/=realtexdetail;
810 bleedx/=realtexdetail;
811 if(bleedx<0)bleedx=0;
812 if(bleedy<0)bleedy=0;
813 if(bleedx>skeleton.skinsize-1)bleedx=skeleton.skinsize-1;
814 if(bleedy>skeleton.skinsize-1)bleedy=skeleton.skinsize-1;
815 direction=abs(Random()%2)*2-1;
817 if(whichtri==-1)return 0;
819 bleeding=howmuch+(float)abs(Random()%100)/200-.25;
820 deathbleeding+=bleeding;
821 bloodloss+=bleeding*3;
823 if(tutoriallevel!=1&&aitype!=playercontrolled&&bloodloss>damagetolerance*2/3&&bloodloss<damagetolerance&&creature==rabbittype){
824 if(abs(Random()%2)==0){aitype=gethelptype;
827 else aitype=attacktypecutoff;
830 if(bleeding>2)bleeding=2;
835 void Person::DoMipmaps(int howmanylevels,float startx, float endx, float starty, float endy){
838 static int bytesPerPixel=3;
839 static int newsize,totalsize,rowsize,bigstep,smallstep,sum;
840 static int newstartx,newstarty,newendx,newendy;
841 static int newnewstartx,newnewstarty,newnewendx,newnewendy;
843 static float sizemult;
845 for(i=0;i<skeleton.skinsize*skeleton.skinsize*bytesPerPixel;i++){
846 texture[i]=skeleton.skinText[i];
849 if((!osx||howmanylevels)){
851 if(startx<0)startx=0;
852 if(starty<0)starty=0;
853 if(endx>skeleton.skinsize-1)endx=skeleton.skinsize-1;
854 if(endy>skeleton.skinsize-1)endy=skeleton.skinsize-1;
855 if((endx>startx&&endy>starty)||howmanylevels){
862 for(i=startx;i<endx;i++){
863 for(j=starty;j<endy;j++){
864 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+0]=skeleton.skinText[i*skeleton.skinsize*3+j*3+0];
865 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+1]=skeleton.skinText[i*skeleton.skinsize*3+j*3+1];
866 texturearray[(i-newstartx)*(newendy-newstarty)*3+(j-newstarty)*3+2]=skeleton.skinText[i*skeleton.skinsize*3+j*3+2];
870 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
873 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_TRUE);
874 glTexSubImage2D(GL_TEXTURE_2D,0,starty,startx,endy-starty,endx-startx,GL_RGB,GL_UNSIGNED_BYTE,texturearray);
875 if(!osx)glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS,GL_FALSE);
878 newsize=skeleton.skinsize;
881 gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGB, skeleton.skinsize, skeleton.skinsize, GL_RGB, GL_UNSIGNED_BYTE, &skeleton.skinText[0] );
883 /*for(j=1;j<=howmanylevels;j++){
884 if(j==1)texpointer=&skeleton.skinText[0];
885 else texpointer=&texture[0];
887 totalsize=int( newsize*newsize*bytesPerPixel);
888 rowsize=int( newsize*bytesPerPixel );
889 bigstep=bytesPerPixel*newsize*2;
890 smallstep=bytesPerPixel*2;
896 glTexSubImage2D(GL_TEXTURE_2D,j,0,0,newsize/2,newsize/2,GL_RGB,GL_UNSIGNED_BYTE,texture);
903 void Person::Reverse(){
904 if(victim->aitype==playercontrolled||hostiletime>1)
905 if(victim->targetanimation!=jumpupanim&&victim->targetanimation!=jumpdownanim&&((tutoriallevel!=1||cananger)&&hostile)){
906 if(normaldotproduct(victim->facing,victim->coords-coords)>0&&!(victim->id==0&&difficulty<2)&&(creature!=wolftype||victim->creature==wolftype))return;
907 if(victim->aitype!=playercontrolled&&staggerdelay>0)return;
908 if(targetanimation==sweepanim){
909 targetanimation=sweepreversedanim;
910 currentanimation=sweepreversedanim;
911 victim->currentanimation=sweepreversalanim;
912 victim->targetanimation=sweepreversalanim;
914 if(targetanimation==spinkickanim){
915 targetanimation=spinkickreversedanim;
916 currentanimation=spinkickreversedanim;
917 victim->currentanimation=spinkickreversalanim;
918 victim->targetanimation=spinkickreversalanim;
920 if(targetanimation==upunchanim||targetanimation==rabbittacklinganim){
921 if(targetanimation==rabbittacklinganim){
924 victim->currentframe=6;
925 victim->targetframe=7;
927 targetanimation=upunchreversedanim;
928 currentanimation=upunchreversedanim;
929 victim->currentanimation=upunchreversalanim;
930 victim->targetanimation=upunchreversalanim;
932 if(targetanimation==staffhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
933 if(victim->weaponactive!=-1){
934 victim->throwtogglekeydown=1;
935 weapons.owner[victim->weaponids[0]]=-1;
936 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
937 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
938 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
939 weapons.missed[victim->weaponids[0]]=1;
940 weapons.freetime[victim->weaponids[0]]=0;
941 weapons.firstfree[victim->weaponids[0]]=1;
942 weapons.physics[victim->weaponids[0]]=1;
943 victim->num_weapons--;
944 if(victim->num_weapons){
945 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
946 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
949 victim->weaponactive=-1;
950 for(int j=0;j<numplayers;j++){
951 player[j].wentforweapon=0;
955 targetanimation=staffhitreversedanim;
956 currentanimation=staffhitreversedanim;
957 victim->currentanimation=staffhitreversalanim;
958 victim->targetanimation=staffhitreversalanim;
960 if(targetanimation==staffspinhitanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%2==0)){
961 if(victim->weaponactive!=-1){
962 victim->throwtogglekeydown=1;
963 weapons.owner[victim->weaponids[0]]=-1;
964 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
965 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
966 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
967 weapons.missed[victim->weaponids[0]]=1;
968 weapons.freetime[victim->weaponids[0]]=0;
969 weapons.firstfree[victim->weaponids[0]]=1;
970 weapons.physics[victim->weaponids[0]]=1;
971 victim->num_weapons--;
972 if(victim->num_weapons){
973 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
974 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
977 victim->weaponactive=-1;
978 for(int j=0;j<numplayers;j++){
979 player[j].wentforweapon=0;
982 targetanimation=staffspinhitreversedanim;
983 currentanimation=staffspinhitreversedanim;
984 victim->currentanimation=staffspinhitreversalanim;
985 victim->targetanimation=staffspinhitreversalanim;
987 if(targetanimation==swordslashanim&&findDistancefast(&victim->coords,&coords)<2&&((victim->id==0&&victim->crouchkeydown)||Random()%4==0)){
988 if(victim->weaponactive!=-1){
989 victim->throwtogglekeydown=1;
990 weapons.owner[victim->weaponids[0]]=-1;
991 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
992 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
993 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
994 weapons.missed[victim->weaponids[0]]=1;
995 weapons.freetime[victim->weaponids[0]]=0;
996 weapons.firstfree[victim->weaponids[0]]=1;
997 weapons.physics[victim->weaponids[0]]=1;
998 victim->num_weapons--;
999 if(victim->num_weapons){
1000 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1001 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1004 victim->weaponactive=-1;
1005 for(int j=0;j<numplayers;j++){
1006 player[j].wentforweapon=0;
1009 targetanimation=swordslashreversedanim;
1010 currentanimation=swordslashreversedanim;
1011 victim->currentanimation=swordslashreversalanim;
1012 victim->targetanimation=swordslashreversalanim;
1014 if(targetanimation==knifeslashstartanim&&findDistancefast(&victim->coords,&coords)<2&&(victim->id==0||Random()%4==0)){
1015 if(victim->weaponactive!=-1){
1016 victim->throwtogglekeydown=1;
1017 weapons.owner[victim->weaponids[0]]=-1;
1018 weapons.velocity[victim->weaponids[0]]=victim->velocity*.2;
1019 if(weapons.velocity[victim->weaponids[0]].x==0)weapons.velocity[victim->weaponids[0]].x=.1;
1020 weapons.tipvelocity[victim->weaponids[0]]=weapons.velocity[victim->weaponids[0]];
1021 weapons.missed[victim->weaponids[0]]=1;
1022 weapons.freetime[victim->weaponids[0]]=0;
1023 weapons.firstfree[victim->weaponids[0]]=1;
1024 weapons.physics[victim->weaponids[0]]=1;
1025 victim->num_weapons--;
1026 if(victim->num_weapons){
1027 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1028 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1031 victim->weaponactive=-1;
1032 for(int j=0;j<numplayers;j++){
1033 player[j].wentforweapon=0;
1036 targetanimation=knifeslashreversedanim;
1037 currentanimation=knifeslashreversedanim;
1038 victim->currentanimation=knifeslashreversalanim;
1039 victim->targetanimation=knifeslashreversalanim;
1041 if(targetanimation!=knifeslashstartanim&&targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim&&targetanimation!=winduppunchanim&&targetanimation!=wolfslapanim&&targetanimation!=swordslashanim&&targetanimation!=swordslashanim){
1042 victim->targettilt2=targettilt2;
1043 victim->currentframe=currentframe;
1044 victim->targetframe=targetframe;
1045 victim->target=target;
1047 victim->oldcoords=victim->coords;
1048 victim->coords=coords;
1049 victim->targetrotation=targetrotation;
1050 victim->rotation=targetrotation;
1051 victim->victim=this;
1053 if(targetanimation==winduppunchanim){
1054 targetanimation=winduppunchblockedanim;
1055 victim->targetanimation=blockhighleftanim;
1056 victim->targetframe=1;
1058 victim->victim=this;
1059 victim->targetrotation=targetrotation+180;
1061 if(targetanimation==wolfslapanim){
1062 targetanimation=winduppunchblockedanim;
1063 victim->targetanimation=blockhighleftanim;
1064 victim->targetframe=1;
1066 victim->victim=this;
1067 victim->targetrotation=targetrotation+180;
1069 if((targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim)&&victim->weaponactive!=-1){
1070 targetanimation=swordslashparriedanim;
1072 victim->parriedrecently=0;
1073 victim->targetanimation=swordslashparryanim;
1074 victim->targetframe=1;
1076 victim->victim=this;
1077 victim->targetrotation=targetrotation+180;
1079 if(abs(Random()%20)==0||weapons.type[victim->weaponids[victim->weaponactive]]==knife){
1080 if(victim->weaponactive!=-1){
1081 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1082 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1083 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1084 emit_sound_at(swordstaffsound, victim->coords);
1087 emit_sound_at(metalhitsound, victim->coords);
1091 victim->Puff(righthand);
1093 victim->targetframe=0;
1094 victim->targetanimation=staggerbackhighanim;
1095 victim->targetrotation=targetrotation+180;
1097 weapons.owner[victim->weaponids[0]]=-1;
1098 aim=DoRotation(facing,0,90,0)*21;
1100 weapons.velocity[victim->weaponids[0]]=aim*-.2;
1101 weapons.tipvelocity[victim->weaponids[0]]=aim;
1102 weapons.missed[victim->weaponids[0]]=1;
1103 weapons.hitsomething[victim->weaponids[0]]=0;
1104 weapons.freetime[victim->weaponids[0]]=0;
1105 weapons.firstfree[victim->weaponids[0]]=1;
1106 weapons.physics[victim->weaponids[0]]=1;
1107 victim->num_weapons--;
1108 if(victim->num_weapons){
1109 victim->weaponids[0]=victim->weaponids[num_weapons];
1110 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
1112 victim->weaponactive=-1;
1113 for(int i=0;i<numplayers;i++){
1114 player[i].wentforweapon=0;
1121 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1122 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1123 OPENAL_SetVolume(channels[metalhitsound], 512);
1124 OPENAL_SetPaused(channels[metalhitsound], false);*/
1127 if(abs(Random()%20)==0){
1128 if(weaponactive!=-1){
1129 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
1130 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1131 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
1133 emit_sound_at(swordstaffsound, coords);
1136 emit_sound_at(metalhitsound, coords);
1144 targetanimation=staggerbackhighanim;
1145 targetrotation=targetrotation+180;
1147 weapons.owner[weaponids[0]]=-1;
1148 aim=DoRotation(facing,0,90,0)*21;
1150 weapons.velocity[weaponids[0]]=aim*-.2;
1151 weapons.tipvelocity[weaponids[0]]=aim;
1152 weapons.hitsomething[weaponids[0]]=0;
1153 weapons.missed[weaponids[0]]=1;
1154 weapons.freetime[weaponids[0]]=0;
1155 weapons.firstfree[weaponids[0]]=1;
1156 weapons.physics[weaponids[0]]=1;
1159 weaponids[0]=weaponids[num_weapons];
1160 if(weaponstuck==num_weapons)weaponstuck=0;
1163 for(int i=0;i<numplayers;i++){
1164 player[i].wentforweapon=0;
1168 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
1169 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
1170 OPENAL_SetVolume(channels[metalhitsound], 512);
1171 OPENAL_SetPaused(channels[metalhitsound], false);*/
1175 if(targetanimation==knifeslashstartanim||targetanimation==swordslashanim||targetanimation==staffhitanim||targetanimation==staffspinhitanim){
1176 if((targetanimation!=staffhitanim&&targetanimation!=staffspinhitanim)||findDistancefast(&coords,&victim->coords)>.2){
1177 //victim->targetanimation=sweepanim;
1178 victim->targetanimation=dodgebackanim;
1179 victim->targetframe=0;
1181 //victim->velocity=0;
1184 rotatetarget=coords-victim->coords;
1185 Normalise(&rotatetarget);
1186 victim->targetrotation=-asin(0-rotatetarget.x);
1187 victim->targetrotation*=360/6.28;
1188 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1190 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1192 victim->lastattack3=victim->lastattack2;
1193 victim->lastattack2=victim->lastattack;
1194 victim->lastattack=victim->targetanimation;
1198 victim->targetanimation=sweepanim;
1199 victim->targetframe=0;
1203 rotatetarget=coords-victim->coords;
1204 Normalise(&rotatetarget);
1205 victim->targetrotation=-asin(0-rotatetarget.x);
1206 victim->targetrotation*=360/6.28;
1207 if(rotatetarget.z<0)victim->targetrotation=180-victim->targetrotation;
1209 victim->targettilt2=-asin(rotatetarget.y)*360/6.28;//*-70;
1211 victim->lastattack3=victim->lastattack2;
1212 victim->lastattack2=victim->lastattack;
1213 victim->lastattack=victim->targetanimation;
1220 if(aitype!=playercontrolled)feint=0;
1221 if(aitype!=playercontrolled&&Random()%3==0&&escapednum<2&&difficulty==2)feint=1;
1222 if(aitype!=playercontrolled&&Random()%5==0&&escapednum<2&&difficulty==1)feint=1;
1223 if(aitype!=playercontrolled&&Random()%10==0&&escapednum<2&&difficulty==0)feint=1;
1225 if(victim->id==0&&animation[victim->targetanimation].attack==reversal)numreversals++;
1229 void Person::DoDamage(float howmuch){
1230 if(tutoriallevel!=1)damage+=howmuch/power;
1231 if(id!=0)damagedealt+=howmuch/power;
1232 if(id==0)damagetaken+=howmuch/power;
1234 if(id==0&&(bonus==solidhit||bonus==twoxcombo||bonus==threexcombo||bonus==fourxcombo||bonus==megacombo))bonus=0;
1235 if(tutoriallevel!=1)permanentdamage+=howmuch/2/power;
1236 if(tutoriallevel!=1)superpermanentdamage+=howmuch/4/power;
1237 if(permanentdamage>damagetolerance/2&&permanentdamage-howmuch<damagetolerance/2&&Random()%2)DoBlood(1,255);
1238 if((permanentdamage>damagetolerance*.8&&Random()%2&&!deathbleeding)||spurt)DoBlood(1,255);
1240 if(id==0)camerashake+=howmuch/100;
1241 if(id==0&&((howmuch>50&&damage>damagetolerance/2)))blackout=damage/damagetolerance;
1242 if(blackout>1)blackout=1;
1244 if(aitype==passivetype&&damage<damagetolerance&&((tutoriallevel!=1||cananger)&&hostile))aitype=attacktypecutoff;
1245 if(tutoriallevel!=1&&aitype!=playercontrolled&&damage<damagetolerance&&damage>damagetolerance*2/3&&creature==rabbittype){
1246 if(abs(Random()%2)==0){aitype=gethelptype;
1249 else aitype=attacktypecutoff;
1253 if(howmuch>damagetolerance*50&&skeleton.free!=2){
1256 for(int i=0;i<skeleton.num_joints; i++){
1257 if(!skeleton.free)flatvelocity2=velocity;
1258 if(skeleton.free)flatvelocity2=skeleton.joints[i].velocity;
1259 if(!skeleton.free)flatfacing2=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
1260 if(skeleton.free)flatfacing2=skeleton.joints[i].position*scale+coords;
1261 flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
1262 flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
1263 flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
1264 Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
1265 Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
1266 Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
1269 emit_sound_at(splattersound, coords);
1278 if(!dead&&creature==wolftype){
1279 award_bonus(0, Wolfbonus);
1285 if(tutoriallevel!=1||id==0)
1286 if(speechdelay<=0&&!dead&&aitype!=playercontrolled){
1289 if(creature==wolftype){
1290 int i=abs(Random()%2);
1291 if(i==0)whichsound=snarlsound;
1292 if(i==1)whichsound=snarl2sound;
1293 envsound[numenvsounds]=coords;
1294 envsoundvol[numenvsounds]=16;
1295 envsoundlife[numenvsounds]=.4;
1298 if(creature==rabbittype){
1299 int i=abs(Random()%2);
1300 if(i==0)whichsound=rabbitpainsound;
1301 if(i==1&&damage>damagetolerance)whichsound=rabbitpain1sound;
1302 envsound[numenvsounds]=coords;
1303 envsoundvol[numenvsounds]=16;
1304 envsoundlife[numenvsounds]=.4;
1306 //if(i==2)whichsound=rabbitpain2sound;
1310 emit_sound_at(whichsound, coords);
1315 //if(permanentdamage>=damagetolerance&&howmuch<50)permanentdamage=damagetolerance-1;
1316 //if(damage>=damagetolerance&&howmuch<30&&!dead)damage=damagetolerance-1;
1319 void Person::DoHead(){
1320 static XYZ rotatearound;
1322 static float lookspeed=500;
1324 if(!freeze&&!winfreeze){
1327 targetheadrotation=(float)((int)((0-rotation-targetheadrotation+180)*100)%36000)/100;
1328 targetheadrotation2=(float)((int)(targetheadrotation2*100)%36000)/100;
1330 while(targetheadrotation>180)targetheadrotation-=360;
1331 while(targetheadrotation<-180)targetheadrotation+=360;
1333 if(targetheadrotation>160)targetheadrotation2=targetheadrotation2*-1;
1334 if(targetheadrotation<-160)targetheadrotation2=targetheadrotation2*-1;
1335 if(targetheadrotation>160)targetheadrotation=targetheadrotation-180;
1336 if(targetheadrotation<-160)targetheadrotation=targetheadrotation+180;
1338 if(targetheadrotation2>120)targetheadrotation2=120;
1339 if(targetheadrotation2<-120)targetheadrotation2=-120;
1340 if(targetheadrotation>120)targetheadrotation=120;
1341 if(targetheadrotation<-120)targetheadrotation=-120;
1343 if(!isIdle())targetheadrotation2=0;
1345 if(targetheadrotation>80)targetheadrotation=80;
1346 if(targetheadrotation<-80)targetheadrotation=-80;
1347 if(targetheadrotation2>50)targetheadrotation2=50;
1348 if(targetheadrotation2<-50)targetheadrotation2=-50;
1351 if(abs(headrotation-targetheadrotation)<multiplier*lookspeed)headrotation=targetheadrotation;
1352 else if(headrotation>targetheadrotation){
1353 headrotation-=multiplier*lookspeed;
1355 else if(headrotation<targetheadrotation){
1356 headrotation+=multiplier*lookspeed;
1359 if(abs(headrotation2-targetheadrotation2)<multiplier*lookspeed/2)headrotation2=targetheadrotation2;
1360 else if(headrotation2>targetheadrotation2){
1361 headrotation2-=multiplier*lookspeed/2;
1363 else if(headrotation2<targetheadrotation2){
1364 headrotation2+=multiplier*lookspeed/2;
1367 rotatearound=skeleton.joints[skeleton.jointlabels[neck]].position;
1368 skeleton.joints[skeleton.jointlabels[head]].position=rotatearound+DoRotation(skeleton.joints[skeleton.jointlabels[head]].position-rotatearound,headrotation2,0,0);
1372 if(targetanimation!=bounceidleanim&&targetanimation!=fightidleanim&&targetanimation!=wolfidle&&targetanimation!=knifefightidleanim&&targetanimation!=drawrightanim&&targetanimation!=drawleftanim&&targetanimation!=walkanim){
1373 facing=DoRotation(facing,headrotation2*.4,0,0);
1374 facing=DoRotation(facing,0,headrotation*.4,0);
1377 if(targetanimation==bounceidleanim||targetanimation==fightidleanim||targetanimation==wolfidle||targetanimation==knifefightidleanim||targetanimation==drawrightanim||targetanimation==drawleftanim){
1378 facing=DoRotation(facing,headrotation2*.8,0,0);
1379 facing=DoRotation(facing,0,headrotation*.8,0);
1382 if(targetanimation==walkanim){
1383 facing=DoRotation(facing,headrotation2*.6,0,0);
1384 facing=DoRotation(facing,0,headrotation*.6,0);
1387 skeleton.specialforward[0]=facing;
1388 //skeleton.specialforward[0]=DoRotation(facing,0,rotation,0);
1390 for(i=0;i<skeleton.num_muscles;i++){
1391 if(skeleton.muscles[i].visible&&(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head))
1393 skeleton.FindRotationMuscle(i,targetanimation);
1399 void Person::RagDoll(bool checkcollision){
1404 if(id==0)numfalls++;
1405 if(id==0&&isFlip())numflipfail++;
1411 facing=DoRotation(facing,0,rotation,0);
1413 skeleton.freetime=0;
1415 skeleton.longdead=0;
1421 skeleton.freefall=1;
1423 if(!isnormal(velocity.x))velocity.x=0;
1424 if(!isnormal(velocity.y))velocity.y=0;
1425 if(!isnormal(velocity.z))velocity.z=0;
1426 if(!isnormal(rotation))rotation=0;
1427 if(!isnormal(coords.x))coords=0;
1428 if(!isnormal(tilt))tilt=0;
1429 if(!isnormal(tilt2))tilt2=0;
1431 for(i=0;i<skeleton.num_joints;i++){
1432 skeleton.joints[i].delay=0;
1433 skeleton.joints[i].locked=0;
1434 skeleton.joints[i].position=DoRotation(DoRotation(DoRotation(skeleton.joints[i].position,0,0,tilt),tilt2,0,0),0,rotation,0);
1435 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=DoRotation(skeleton.joints[i].position,0,rotation,0);
1436 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=skeleton.joints[i].position;
1437 if(!isnormal(skeleton.joints[i].position.x))skeleton.joints[i].position=coords;
1438 skeleton.joints[i].position.y+=.1;
1439 skeleton.joints[i].oldposition=skeleton.joints[i].position;
1440 skeleton.joints[i].realoldposition=skeleton.joints[i].position*scale+coords;
1443 for(i=0;i<skeleton.num_joints;i++){
1444 skeleton.joints[i].velocity=0;
1445 skeleton.joints[i].velchange=0;
1447 skeleton.DoConstraints(&coords,&scale);
1448 if(animation[currentanimation].height==lowheight||animation[targetanimation].height==lowheight)
1450 skeleton.DoConstraints(&coords,&scale);
1451 skeleton.DoConstraints(&coords,&scale);
1452 skeleton.DoConstraints(&coords,&scale);
1453 skeleton.DoConstraints(&coords,&scale);
1456 speed=animation[targetanimation].speed[targetframe]*2;
1457 if(animation[currentanimation].speed[currentframe]>animation[targetanimation].speed[targetframe]){
1458 speed=animation[currentanimation].speed[currentframe]*2;
1460 if(transspeed)speed=transspeed*2;
1464 for(i=0;i<skeleton.num_joints;i++){
1465 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);
1466 else skeleton.joints[i].velocity=velocity/scale+facing*5;
1467 change.x=(float)(Random()%100)/100;
1468 change.y=(float)(Random()%100)/100;
1469 change.z=(float)(Random()%100)/100;
1470 skeleton.joints[i].velocity+=change;
1471 skeleton.joints[abs(Random()%skeleton.num_joints)].velocity-=change;
1473 change.x=(float)(Random()%100)/100;
1474 change.y=(float)(Random()%100)/100;
1475 change.z=(float)(Random()%100)/100;
1476 skeleton.joints[i].velchange+=change;
1477 skeleton.joints[abs(Random()%skeleton.num_joints)].velchange-=change;
1487 for(j=0;j<skeleton.num_joints;j++){
1488 average+=skeleton.joints[j].position;
1492 coords+=average*scale;
1493 for(j=0;j<skeleton.num_joints;j++){
1494 skeleton.joints[j].position-=average;
1497 whichpatchx=coords.x/(terrain.size/subdivision*terrain.scale*terraindetail);
1498 whichpatchz=coords.z/(terrain.size/subdivision*terrain.scale*terraindetail);
1499 if(terrain.patchobjectnum[whichpatchx][whichpatchz])
1500 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
1501 i=terrain.patchobjects[whichpatchx][whichpatchz][l];
1504 if(SphereCheck(&lowpoint, 3, &colpoint, &objects.position[i], &objects.rotation[i], &objects.model[i])!=-1){
1505 coords.x=lowpoint.x;
1506 coords.z=lowpoint.z;
1515 for(i=0;i<skeleton.num_joints;i++){
1516 velocity+=skeleton.joints[i].velocity*scale;
1518 velocity/=skeleton.num_joints;
1521 if(weaponactive!=-1&&targetanimation!=rabbitkickanim&&num_weapons>0){
1522 weapons.owner[weaponids[0]]=-1;
1523 weapons.hitsomething[weaponids[0]]=0;
1524 weapons.velocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale*-.3;
1525 weapons.velocity[weaponids[0]].x+=.01;
1526 weapons.tipvelocity[weaponids[0]]=skeleton.joints[skeleton.jointlabels[righthand]].velocity*scale;
1527 weapons.missed[weaponids[0]]=1;
1528 weapons.freetime[weaponids[0]]=0;
1529 weapons.firstfree[weaponids[0]]=1;
1530 weapons.physics[weaponids[0]]=1;
1533 weaponids[0]=weaponids[num_weapons];
1534 if(weaponstuck==num_weapons)weaponstuck=0;
1537 for(i=0;i<numplayers;i++){
1538 player[i].wentforweapon=0;
1543 targetanimation=bounceidleanim;
1544 currentanimation=bounceidleanim;
1552 void Person::FootLand(int which, float opacity){
1553 static XYZ terrainlight;
1554 static XYZ footvel,footpoint;
1555 if(opacity>=1||skiddelay<=0)
1559 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1560 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1561 //footpoint.y=coords.y;
1562 if(findDistancefast(&footpoint,&viewer))Sprite::MakeSprite(cloudsprite, footpoint,footvel, 1,1,1, .5, .2*opacity);
1564 else if(environment==snowyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1566 if(footvel.y<.8)footvel.y=.8;
1567 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1568 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1569 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1570 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1571 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, terrainlight.x,terrainlight.y,terrainlight.z, .5, .7*opacity);
1572 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,1*opacity,rotation);
1574 else if(environment==grassyenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1576 if(footvel.y<.8)footvel.y=.8;
1577 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1578 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1579 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1580 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1581 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);
1583 else if(environment==desertenvironment&&onterrain&&terrain.getOpacity(coords.x,coords.z)<.2){
1585 if(footvel.y<.8)footvel.y=.8;
1586 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1587 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1588 footpoint.y=terrain.getHeight(footpoint.x,footpoint.z);
1589 terrainlight=terrain.getLighting(footpoint.x,footpoint.z);
1590 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);
1591 if(opacity>=1||detail==2)if(detail==2)if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)terrain.MakeDecal(footprintdecal,footpoint,.2,.25*opacity,rotation);
1593 else if(isLanding()||targetanimation==jumpupanim||isLandhard())
1596 if(footvel.y<.8)footvel.y=.8;
1597 if(which==0)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
1598 if(which==1)footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
1599 //footpoint.y=coords.y;
1600 if(findDistancefast(&footpoint,&viewer)<viewdistance*viewdistance/4)Sprite::MakeSprite(cloudsprite, footpoint,footvel*.6, 1,1,1, .5, .2*opacity);
1604 void Person::Puff(int whichlabel){
1605 static XYZ footvel,footpoint;
1608 footpoint=DoRotation(skeleton.joints[skeleton.jointlabels[whichlabel]].position,0,rotation,0)*scale+coords;
1609 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .9, .3);
1613 void Person::DoAnimations(){
1616 static float oldtarget;
1618 if(isIdle()&¤tanimation!=getIdle())normalsupdatedelay=0;
1620 if(targetanimation==tempanim||currentanimation==tempanim){
1621 animation[tempanim]=tempanimation;
1623 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
1634 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
1635 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
1637 if(((velocity.y<-15)||(crouchkeydown&&velocity.y<-8))&&abs(velocity.y)*4>fast_sqrt(velocity.x*velocity.x*velocity.z*velocity.z))landhard=1;
1638 if(!crouchkeydown&&velocity.y>=-15)landhard=0;
1640 if((currentanimation==jumpupanim||targetanimation==jumpdownanim)/*&&velocity.y<40*/&&!isFlip()&&(!isLanding()&&!isLandhard())&&((crouchkeydown&&!crouchtogglekeydown))){
1645 targfacing=DoRotation(targfacing,0,targetrotation,0);
1647 if(normaldotproduct(targfacing,velocity)>=-.3)targetanimation=flipanim;
1648 else targetanimation=backflipanim;
1649 crouchtogglekeydown=1;
1653 if(id==0)numflipped++;
1656 if(animation[targetanimation].attack!=reversed)feint=0;
1657 if(!crouchkeydown||(isLanding()||isLandhard())||(wasLanding()||wasLandhard())){
1658 crouchtogglekeydown=0;
1659 if(aitype==playercontrolled)feint=0;
1663 if(!crouchtogglekeydown&&animation[targetanimation].attack==reversed&&aitype==playercontrolled&&(escapednum<2||reversaltrain))feint=1;
1664 if(!isFlip())crouchtogglekeydown=1;
1668 if(animation[targetanimation].attack||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim){
1669 if(detail)normalsupdatedelay=0;
1673 if(targetanimation==rollanim&&targetframe==3&&onfire){
1675 emit_sound_at(fireendsound, coords);
1676 OPENAL_SetPaused(channels[stream_firesound], true);
1680 if(targetanimation==rabbittacklinganim&&targetframe==1){
1681 //if(victim->aitype==attacktypecutoff&&Random()%2==0&&victim->stunned<=0&&animation[victim->targetanimation].attack==neutral&&victim->id!=0)Reverse();
1682 if(victim->aitype==attacktypecutoff&&victim->stunned<=0&&victim->surprised<=0&&victim->id!=0)Reverse();
1683 if(targetanimation==rabbittacklinganim&&targetframe==1&&!victim->isCrouch()&&victim->targetanimation!=backhandspringanim){
1684 if(normaldotproduct(victim->facing,facing)>0)victim->targetanimation=rabbittackledbackanim;
1685 else victim->targetanimation=rabbittackledfrontanim;
1686 victim->targetframe=2;
1688 victim->rotation=rotation;
1689 victim->targetrotation=rotation;
1690 if(victim->aitype==gethelptype)victim->DoDamage(victim->damagetolerance-victim->damage);
1691 //victim->DoDamage(30);
1692 if(creature==wolftype){
1694 emit_sound_at(clawslicesound, victim->coords);
1696 victim->DoBloodBig(1/victim->armorhead,210);
1698 award_bonus(id, TackleBonus,
1699 victim->aitype == gethelptype ? 50 : 0);
1703 if(!drawtogglekeydown&&drawkeydown&&(weaponactive==-1||num_weapons==1)&&(animation[targetanimation].label[targetframe]||(targetanimation!=currentanimation&¤tanimation==rollanim))&&num_weapons>0&&creature!=wolftype){
1704 if(weapons.type[weaponids[0]]==knife){
1705 if(weaponactive==-1)weaponactive=0;
1706 else if(weaponactive==0)weaponactive=-1;
1708 if(weaponactive==-1){
1709 emit_sound_at(knifesheathesound, coords);
1711 if(weaponactive!=-1){
1712 emit_sound_at(knifedrawsound, coords, 128);
1715 drawtogglekeydown=1;
1718 if(tutoriallevel!=1||id==0)
1719 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1730 if(terrain.getOpacity(coords.x,coords.z)<.2){
1731 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound;
1732 else whichsound=footstepsound2;
1733 if(animation[targetanimation].label[targetframe]==1)FootLand(0,1);
1734 if(animation[targetanimation].label[targetframe]==2)FootLand(1,1);
1735 if(animation[targetanimation].label[targetframe]==3&&isRun()){
1741 if(terrain.getOpacity(coords.x,coords.z)>=.2){
1742 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1743 else whichsound=footstepsound4;
1747 if(animation[targetanimation].label[targetframe]==1)whichsound=footstepsound3;
1748 else whichsound=footstepsound4;
1750 if(animation[targetanimation].label[targetframe]==4&&(weaponactive==-1||(targetanimation!=knifeslashstartanim&&targetanimation!=knifethrowanim&&targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=knifefollowanim))){
1751 if(animation[targetanimation].attack!=neutral){
1753 if(i==0)whichsound=lowwhooshsound;
1754 if(i==1)whichsound=midwhooshsound;
1755 if(i==2)whichsound=highwhooshsound;
1757 if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1759 else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1760 if(animation[targetanimation].label[targetframe]==8&&tutoriallevel!=1)whichsound=landsound2;
1762 PlaySoundEx( whichsound, samp[whichsound], NULL, true);
1763 OPENAL_3D_SetAttributes(channels[whichsound], gLoc, vel);
1764 if(whichsound!=knifeswishsound)OPENAL_SetVolume(channels[whichsound], 128);
1765 if(whichsound!=knifeswishsound&&(targetanimation==staffhitanim||targetanimation==staffgroundsmashanim||targetanimation==staffspinhitanim))OPENAL_SetVolume(channels[whichsound], 256);
1766 if(whichsound==knifeswishsound)OPENAL_SetVolume(channels[whichsound], 512);
1767 OPENAL_SetPaused(channels[whichsound], false);
1770 if(whichsound==footstepsound||whichsound==footstepsound2||whichsound==footstepsound3||whichsound==footstepsound4){
1771 envsound[numenvsounds]=coords;
1772 if(targetanimation==wolfrunninganim||targetanimation==rabbitrunninganim)envsoundvol[numenvsounds]=15;
1773 else envsoundvol[numenvsounds]=6;
1774 envsoundlife[numenvsounds]=.4;
1778 if(animation[targetanimation].label[targetframe]==3){
1780 emit_sound_at(whichsound, coords, 128.);
1785 if(tutoriallevel!=1||id==0)
1787 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)
1788 if((animation[targetanimation].label[targetframe]&&(animation[targetanimation].label[targetframe]<5||animation[targetanimation].label[targetframe]==8))/*||(targetanimation==rollanim&&targetframe==animation[rollanim].numframes-1)*/){
1790 if(animation[targetanimation].label[targetframe]==4&&aitype!=playercontrolled){
1791 if(animation[targetanimation].attack!=neutral){
1793 if(creature==rabbittype){
1794 if(i==0)whichsound=rabbitattacksound;
1795 if(i==1)whichsound=rabbitattack2sound;
1796 if(i==2)whichsound=rabbitattack3sound;
1797 if(i==3)whichsound=rabbitattack4sound;
1799 if(creature==wolftype){
1800 if(i==0)whichsound=barksound;
1801 if(i==1)whichsound=bark2sound;
1802 if(i==2)whichsound=bark3sound;
1803 if(i==3)whichsound=barkgrowlsound;
1807 //if(animation[targetanimation].attack==neutral)whichsound=movewhooshsound;
1809 //else if(animation[targetanimation].label[targetframe]==4)whichsound=knifeswishsound;
1810 //if(animation[targetanimation].label[targetframe]==8)whichsound=landsound2;
1813 emit_sound_at(whichsound, coords);
1819 if((!wasLanding()&&!wasLandhard())&¤tanimation!=getIdle()&&(isLanding()||isLandhard())){
1825 currentoffset=targetoffset;
1826 targetframe=currentframe;
1827 currentanimation=targetanimation;
1830 if(targetanimation==removeknifeanim&&animation[targetanimation].label[currentframe]==5){
1831 for(i=0;i<weapons.numweapons;i++){
1832 if(/*weapons.velocity[i].x==0&&weapons.velocity[i].y==0&&weapons.velocity[i].z==0&&*/weapons.owner[i]==-1)
1833 if(findDistancefastflat(&coords,&weapons.position[i])<4&&weaponactive==-1){
1834 if(findDistancefast(&coords,&weapons.position[i])>=1){
1835 if(weapons.type[i]!=staff){
1836 emit_sound_at(knifedrawsound, coords, 128.);
1840 weapons.owner[i]=id;
1842 weaponids[num_weapons]=weaponids[0];
1851 static bool willwork;
1852 if(targetanimation==crouchremoveknifeanim&&animation[targetanimation].label[currentframe]==5){
1853 for(i=0;i<weapons.numweapons;i++){
1855 if(weapons.owner[i]!=-1)
1856 if(player[weapons.owner[i]].weaponstuck!=-1)
1857 if(player[weapons.owner[i]].weaponids[player[weapons.owner[i]].weaponstuck]==i)
1858 if(player[weapons.owner[i]].num_weapons>1)willwork=0;
1859 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))
1860 if(willwork&&findDistancefastflat(&coords,&weapons.position[i])<3&&weaponactive==-1){
1861 if(findDistancefast(&coords,&weapons.position[i])<1||hasvictim){
1863 if(weapons.owner[i]!=-1)
1864 if(victim->weaponstuck!=-1){
1865 if(victim->weaponids[victim->weaponstuck]==i){
1870 if(weapons.type[i]!=staff){
1871 emit_sound_at(knifedrawsound, coords, 128.);
1875 emit_sound_at(fleshstabremovesound, coords, 128.);
1878 if(weapons.owner[i]!=-1){
1880 victim=&player[weapons.owner[i]];
1881 if(victim->num_weapons==1)victim->num_weapons=0;
1882 else victim->num_weapons=1;
1884 //victim->weaponactive=-1;
1885 victim->skeleton.longdead=0;
1886 victim->skeleton.free=1;
1887 victim->skeleton.broken=0;
1889 for(int j=0;j<victim->skeleton.num_joints;j++){
1890 victim->skeleton.joints[j].velchange=0;
1891 victim->skeleton.joints[j].locked=0;
1897 Normalise(&relative);
1898 XYZ footvel,footpoint;
1900 footpoint=weapons.position[i];
1901 if(victim->weaponstuck!=-1){
1902 if(victim->weaponids[victim->weaponstuck]==i){
1903 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
1904 weapons.bloody[i]=2;
1905 weapons.blooddrip[i]=5;
1906 victim->weaponstuck=-1;
1909 if(victim->num_weapons>0){
1910 if(victim->weaponstuck!=0&&victim->weaponstuck!=-1)victim->weaponstuck=0;
1911 if(victim->weaponids[0]==i)
1912 victim->weaponids[0]=victim->weaponids[victim->num_weapons];
1915 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*6;
1916 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*6;
1917 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity+=relative*6;
1918 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity+=relative*6;
1920 weapons.owner[i]=id;
1922 weaponids[num_weapons]=weaponids[0];
1931 if(currentanimation==drawleftanim&&animation[targetanimation].label[currentframe]==5){
1932 if(weaponactive==-1)weaponactive=0;
1933 else if(weaponactive==0){
1937 buffer=weaponids[0];
1938 weaponids[0]=weaponids[1];
1939 weaponids[1]=buffer;
1942 if(weaponactive==-1){
1943 emit_sound_at(knifesheathesound, coords, 128.);
1945 if(weaponactive!=-1){
1946 emit_sound_at(knifedrawsound, coords, 128.);
1951 if((currentanimation==walljumprightkickanim&&targetanimation==walljumprightkickanim)||(currentanimation==walljumpleftkickanim&&targetanimation==walljumpleftkickanim)){
1952 XYZ rotatetarget=DoRotation(skeleton.forward,0,rotation,0);
1953 Normalise(&rotatetarget);
1954 targetrotation=-asin(0-rotatetarget.x);
1955 targetrotation*=360/6.28;
1956 if(rotatetarget.z<0)targetrotation=180-targetrotation;
1958 if(targetanimation==walljumprightkickanim)targetrotation+=40;
1959 if(targetanimation==walljumpleftkickanim)targetrotation-=40;
1964 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&targetframe==3&&(jumpkeydown||attackkeydown||id!=0))dojumpattack=1;
1966 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;
1968 if((targetanimation==rabbitrunninganim||targetanimation==wolfrunninganim)&&id==0){
1969 targetanimation=rabbittackleanim;
1971 emit_sound_at(jumpsound, coords);
1980 Normalise(&targetloc);
1982 for(i=0;i<numplayers;i++){
1984 if(findDistancefast(&targetloc,&player[i].coords)<closestdist||closestdist==0){
1985 closestdist=findDistancefast(&targetloc,&player[i].coords);
1990 if(closestdist<5&&!player[closestid].dead&&animation[player[closestid].targetanimation].height!=lowheight&&player[closestid].targetanimation!=backhandspringanim){
1992 victim=&player[closestid];
1993 coords=victim->coords;
1994 currentanimation=rabbittacklinganim;
1995 targetanimation=rabbittacklinganim;
1999 if(coords.z!=victim->coords.z||coords.x!=victim->coords.x){
2000 rotatetarget=coords-victim->coords;
2001 Normalise(&rotatetarget);
2002 targetrotation=-asin(0-rotatetarget.x);
2003 targetrotation*=360/6.28;
2004 if(rotatetarget.z<0)targetrotation=180-targetrotation;
2006 if(targetanimation!=rabbitrunninganim){
2007 emit_sound_at(jumpsound, coords, 128.);
2013 float damagemult=1*power;
2014 if(creature==wolftype)damagemult=2.5*power;
2015 if(hasvictim){damagemult/=victim->damagetolerance/200;}
2016 //if(onfire)damagemult=3;
2017 if((animation[targetanimation].attack==normalattack||targetanimation==walljumprightkickanim||targetanimation==walljumpleftkickanim)&&(!feint)&&(victim->skeleton.free!=2||targetanimation==killanim||targetanimation==dropkickanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==staffgroundsmashanim)){
2018 if(targetanimation==spinkickanim&&animation[targetanimation].label[currentframe]==5){
2019 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2021 if(id==0)camerashake+=.4;
2022 if(Random()%2||creature==wolftype){
2025 if(creature==wolftype)DoBloodBig(0,250);
2027 if(tutoriallevel!=1){
2028 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2030 if(creature==wolftype){
2031 emit_sound_at(clawslicesound, victim->coords, 128.);
2033 victim->DoBloodBig(2/victim->armorhead,175);
2037 relative=victim->coords-coords;
2039 Normalise(&relative);
2040 relative=DoRotation(relative,0,-90,0);
2041 for(i=0;i<victim->skeleton.num_joints;i++){
2042 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2044 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2047 victim->DoDamage(damagemult*100/victim->protectionhead);
2053 if(targetanimation==wolfslapanim&&animation[targetanimation].label[currentframe]==5){
2054 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&3&&animation[victim->targetanimation].height!=lowheight){
2056 if(id==0)camerashake+=.4;
2057 if(Random()%2||creature==wolftype){
2059 if(creature==wolftype)DoBloodBig(0,235);
2061 emit_sound_at(whooshhitsound, victim->coords);
2062 if(creature==wolftype){
2063 emit_sound_at(clawslicesound, victim->coords, 128.);
2065 victim->DoBloodBig(2,175);
2069 relative=victim->coords-coords;
2071 Normalise(&relative);
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*20;
2078 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2081 victim->DoDamage(damagemult*50/victim->protectionhead);
2085 if(targetanimation==walljumprightkickanim&&animation[targetanimation].label[currentframe]==5){
2086 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2088 if(id==0)camerashake+=.4;
2091 if(tutoriallevel!=1){
2092 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2094 if(creature==wolftype){
2095 emit_sound_at(clawslicesound, victim->coords, 128.);
2097 victim->DoBloodBig(2/victim->armorhead,175);
2103 Normalise(&relative);
2104 relative=DoRotation(relative,0,-90,0);
2105 for(i=0;i<victim->skeleton.num_joints;i++){
2106 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2108 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2111 victim->DoDamage(damagemult*150/victim->protectionhead);
2113 if(victim->damage>victim->damagetolerance)
2114 award_bonus(id, style);
2120 if(targetanimation==walljumpleftkickanim&&animation[targetanimation].label[currentframe]==5){
2121 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2123 if(id==0)camerashake+=.4;
2126 if(tutoriallevel!=1){
2127 emit_sound_at(heavyimpactsound, victim->coords, 160.);
2129 if(creature==wolftype){
2130 emit_sound_at(clawslicesound, victim->coords, 128.);
2132 victim->DoBloodBig(2/victim->armorhead,175);
2138 Normalise(&relative);
2139 relative=DoRotation(relative,0,90,0);
2140 for(i=0;i<victim->skeleton.num_joints;i++){
2141 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2143 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2146 victim->DoDamage(damagemult*150/victim->protectionhead);
2148 if(victim->damage>victim->damagetolerance)
2149 award_bonus(id, style);
2155 if(targetanimation==blockhighleftstrikeanim&&animation[targetanimation].label[currentframe]==5){
2156 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=lowheight){
2158 if(id==0)camerashake+=.4;
2163 emit_sound_at(whooshhitsound, victim->coords);
2166 relative=victim->coords-coords;
2168 Normalise(&relative);
2169 for(i=0;i<victim->skeleton.num_joints;i++){
2170 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
2172 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*100;
2175 victim->DoDamage(damagemult*50/victim->protectionhead);
2179 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==8){
2180 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim->dead){
2182 if(id==0)camerashake+=.2;
2183 emit_sound_at(whooshhitsound, victim->coords, 128.);
2185 victim->skeleton.longdead=0;
2186 victim->skeleton.free=1;
2187 victim->skeleton.broken=0;
2188 victim->skeleton.spinny=1;
2190 for(i=0;i<victim->skeleton.num_joints;i++){
2191 victim->skeleton.joints[i].velchange=0;
2192 victim->skeleton.joints[i].delay=0;
2193 victim->skeleton.joints[i].locked=0;
2194 //victim->skeleton.joints[i].velocity=0;
2200 Normalise(&relative);
2201 for(i=0;i<victim->skeleton.num_joints;i++){
2202 victim->skeleton.joints[i].velocity.y=relative.y*10;
2203 victim->skeleton.joints[i].position.y+=relative.y*.3;
2204 victim->skeleton.joints[i].oldposition.y+=relative.y*.3;
2205 victim->skeleton.joints[i].realoldposition.y+=relative.y*.3;
2207 victim->Puff(abdomen);
2208 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity.y=relative.y*400;
2212 if(targetanimation==killanim&&animation[targetanimation].label[currentframe]==5){
2213 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->dead){
2215 if(id==0)camerashake+=.4;
2216 if(tutoriallevel!=1){
2217 emit_sound_at(heavyimpactsound, coords, 128.);
2220 relative=victim->coords-coords;
2222 Normalise(&relative);
2223 for(i=0;i<victim->skeleton.num_joints;i++){
2224 victim->skeleton.joints[i].velocity+=relative*damagemult*90;
2226 victim->Puff(abdomen);
2227 if(victim->dead!=2&&victim->permanentdamage>victim->damagetolerance-250&&autoslomo){
2231 victim->DoDamage(damagemult*500/victim->protectionhigh);
2232 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*300;
2236 if(targetanimation==dropkickanim&&animation[targetanimation].label[currentframe]==7){
2237 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*9&&victim->skeleton.free){
2239 if(id==0)camerashake+=.4;
2240 if(tutoriallevel!=1){
2241 emit_sound_at(thudsound, coords);
2244 victim->skeleton.longdead=0;
2245 victim->skeleton.free=1;
2246 victim->skeleton.broken=0;
2247 victim->skeleton.spinny=1;
2249 for(i=0;i<victim->skeleton.num_joints;i++){
2250 victim->skeleton.joints[i].velchange=0;
2251 //victim->skeleton.joints[i].delay=0;
2252 victim->skeleton.joints[i].locked=0;
2255 relative=victim->coords-coords;
2256 Normalise(&relative);
2258 Normalise(&relative);
2259 for(i=0;i<victim->skeleton.num_joints;i++){
2260 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
2265 victim->Puff(abdomen);
2266 victim->DoDamage(damagemult*20/victim->protectionhigh);
2267 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2269 if(!victim->dead)staggerdelay=1.2;
2275 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==5){
2276 //if(id==0)camerashake+=.4;
2279 if(!victim->skeleton.free)hasvictim=0;
2282 terrain.MakeDecal(blooddecalfast,(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2),.08,.6,Random()%360);
2283 emit_sound_at(knifesheathesound, coords, 128.);
2286 if(victim&&hasvictim){
2287 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2289 XYZ where,startpoint,endpoint,movepoint,colpoint;
2290 float rotationpoint;
2292 if(weapons.type[weaponids[weaponactive]]==knife){
2293 where=(weapons.tippoint[weaponids[weaponactive]]*.6+weapons.position[weaponids[weaponactive]]*.4);
2294 where-=victim->coords;
2295 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2302 if(weapons.type[weaponids[weaponactive]]==sword){
2303 where=weapons.position[weaponids[weaponactive]];
2304 where-=victim->coords;
2305 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2307 where=weapons.tippoint[weaponids[weaponactive]];
2308 where-=victim->coords;
2309 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2312 if(weapons.type[weaponids[weaponactive]]==staff){
2313 where=weapons.position[weaponids[weaponactive]];
2314 where-=victim->coords;
2315 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2317 where=weapons.tippoint[weaponids[weaponactive]];
2318 where-=victim->coords;
2319 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2324 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &colpoint, &movepoint, &rotationpoint);
2327 if(victim->dead!=2){
2328 victim->DoDamage(abs((victim->damagetolerance-victim->permanentdamage)*2));
2330 award_bonus(id, FinishedBonus);
2332 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
2334 victim->skeleton.longdead=0;
2335 victim->skeleton.free=1;
2336 victim->skeleton.broken=0;
2338 for(i=0;i<victim->skeleton.num_joints;i++){
2339 victim->skeleton.joints[i].velchange=0;
2340 victim->skeleton.joints[i].locked=0;
2341 //victim->skeleton.joints[i].velocity=0;
2343 emit_sound_at(fleshstabsound, coords, 128);
2346 if(whichtri!=-1||weapons.bloody[weaponids[weaponactive]]){
2347 weapons.blooddrip[weaponids[weaponactive]]+=5;
2348 weapons.blooddripdelay[weaponids[weaponactive]]=0;
2352 emit_sound_at(knifesheathesound, coords, 128.);
2358 if((targetanimation==crouchstabanim||targetanimation==swordgroundstabanim)&&animation[targetanimation].label[currentframe]==6){
2360 emit_sound_at(knifedrawsound, coords, 128);
2363 if(victim&&hasvictim){
2364 XYZ footvel,footpoint;
2366 emit_sound_at(fleshstabremovesound, coords, 128.);
2369 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2371 if(weapons.type[weaponids[weaponactive]]==sword){
2372 XYZ where,startpoint,endpoint,movepoint;
2373 float rotationpoint;
2376 where=weapons.position[weaponids[weaponactive]];
2377 where-=victim->coords;
2378 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2380 where=weapons.tippoint[weaponids[weaponactive]];
2381 where-=victim->coords;
2382 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2387 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2388 footpoint+=victim->coords;
2391 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2394 if(weapons.type[weaponids[weaponactive]]==staff){
2395 XYZ where,startpoint,endpoint,movepoint;
2396 float rotationpoint;
2399 where=weapons.position[weaponids[weaponactive]];
2400 where-=victim->coords;
2401 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2403 where=weapons.tippoint[weaponids[weaponactive]];
2404 where-=victim->coords;
2405 if(!victim->skeleton.free)where=DoRotation(where,0,-victim->rotation,0);
2410 whichtri=victim->skeleton.drawmodel.LineCheck(&startpoint,&endpoint, &footpoint, &movepoint, &rotationpoint);
2411 footpoint+=victim->coords;
2414 footpoint=(weapons.tippoint[weaponids[weaponactive]]*.8+weapons.position[weaponids[weaponactive]]*.2);
2417 hasvictim=victim->DoBloodBigWhere(2,220,footpoint);
2419 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2420 victim->skeleton.longdead=0;
2421 victim->skeleton.free=1;
2422 victim->skeleton.broken=0;
2424 for(i=0;i<victim->skeleton.num_joints;i++){
2425 victim->skeleton.joints[i].velchange=0;
2426 victim->skeleton.joints[i].locked=0;
2427 //victim->skeleton.joints[i].velocity=0;
2433 Normalise(&relative);
2434 //victim->Puff(abdomen);
2435 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
2437 if(victim->bloodloss<victim->damagetolerance){
2438 victim->bloodloss+=1000;
2442 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2446 if(!hasvictim&&onterrain){
2447 weapons.bloody[weaponids[weaponactive]]=0;
2448 weapons.blooddrip[weaponids[weaponactive]]=0;
2452 if(targetanimation==upunchanim&&animation[targetanimation].label[currentframe]==5){
2453 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3){
2455 if(id==0)camerashake+=.4;
2460 if(tutoriallevel!=1){
2461 emit_sound_at(heavyimpactsound, victim->coords, 128);
2466 relative=victim->coords-coords;
2468 Normalise(&relative);
2469 for(i=0;i<victim->skeleton.num_joints;i++){
2470 victim->skeleton.joints[i].velocity=relative*30;
2472 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*150;
2474 victim->targetframe=0;
2475 victim->targetanimation=staggerbackhardanim;
2476 victim->targetrotation=targetrotation+180;
2481 victim->Puff(abdomen);
2482 victim->DoDamage(damagemult*60/victim->protectionhigh);
2489 if(targetanimation==winduppunchanim&&animation[targetanimation].label[currentframe]==5){
2490 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*2){
2492 if(id==0)camerashake+=.4;
2493 if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height!=lowheight){
2494 if(tutoriallevel!=1){
2495 emit_sound_at(thudsound, victim->coords);
2498 else if(victim->damage<=victim->damagetolerance-60&&normaldotproduct(victim->facing,victim->coords-coords)<(scale*5)*(scale*5)*0&&animation[victim->targetanimation].height==lowheight){
2499 if(tutoriallevel!=1){
2500 emit_sound_at(whooshhitsound, victim->coords);
2504 if(tutoriallevel!=1){
2505 emit_sound_at(heavyimpactsound, victim->coords);
2509 if(victim->damage>victim->damagetolerance-60||normaldotproduct(victim->facing,victim->coords-coords)>0||animation[victim->targetanimation].height==lowheight)
2512 relative=victim->coords-coords;
2514 Normalise(&relative);
2516 Normalise(&relative);
2517 for(i=0;i<victim->skeleton.num_joints;i++){
2518 victim->skeleton.joints[i].velocity=relative*5;
2520 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*400;
2522 victim->targetframe=0;
2523 victim->targetanimation=staggerbackhardanim;
2524 victim->targetrotation=targetrotation+180;
2528 victim->Puff(abdomen);
2529 victim->DoDamage(damagemult*60/victim->protectionhigh);
2535 if(targetanimation==blockhighleftanim&&animation[targetanimation].label[currentframe]==5){
2536 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2537 if(victim->id==0)camerashake+=.4;
2538 emit_sound_at(landsound2, victim->coords);
2544 if(targetanimation==swordslashparryanim&&animation[targetanimation].label[currentframe]==5){
2545 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4){
2546 if(victim->id==0)camerashake+=.4;
2548 if(weaponactive!=-1){
2549 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2550 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2551 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2553 emit_sound_at(swordstaffsound, victim->coords);
2556 emit_sound_at(metalhitsound, victim->coords);
2564 if(targetanimation==knifethrowanim&&animation[targetanimation].label[currentframe]==5){
2565 if(weaponactive!=-1){
2568 weapons.owner[weaponids[0]]=-1;
2569 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);
2571 /*if(victim->targetanimation==jumpupanim||victim->targetanimation==jumpdownanim){
2572 aim=DoRotation(aim,(float)abs(Random()%15)-7,(float)abs(Random()%15)-7,0);
2574 weapons.velocity[weaponids[0]]=aim*50;
2575 weapons.tipvelocity[weaponids[0]]=aim*50;
2576 weapons.missed[weaponids[0]]=0;
2577 weapons.hitsomething[weaponids[0]]=0;
2578 weapons.freetime[weaponids[0]]=0;
2579 weapons.firstfree[weaponids[0]]=1;
2580 weapons.physics[weaponids[0]]=0;
2583 weaponids[0]=weaponids[num_weapons];
2589 if(targetanimation==knifeslashstartanim&&animation[targetanimation].label[currentframe]==5){
2591 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*4.5&&/*animation[victim->targetanimation].height!=lowheight&&*/victim->targetanimation!=dodgebackanim&&victim->targetanimation!=rollanim){
2593 if(tutoriallevel!=1)victim->DoBloodBig(1.5/victim->armorhigh,225);
2595 award_bonus(id, Slicebonus);
2596 if(tutoriallevel!=1){
2597 emit_sound_at(knifeslicesound, victim->coords);
2599 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2600 if(animation[victim->targetanimation].attack&&(victim->aitype!=playercontrolled||victim->targetanimation==knifeslashstartanim)&&(victim->creature==rabbittype||victim->deathbleeding<=0)){
2601 if(victim->id != 0 || difficulty==2){
2602 victim->targetframe=0;
2603 victim->targetanimation=staggerbackhardanim;
2604 victim->targetrotation=targetrotation+180;
2608 victim->lowreversaldelay=0;
2609 victim->highreversaldelay=0;
2610 if(aitype!=playercontrolled)weaponmissdelay=.6;
2612 if(tutoriallevel!=1)if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2613 if(tutoriallevel!=1)weapons.blooddrip[weaponids[weaponactive]]+=3;
2615 XYZ footvel,footpoint;
2618 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2621 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;
2623 if(tutoriallevel!=1){
2624 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .6, .3);
2625 footvel=DoRotation(facing,0,90,0)*.8;
2627 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2628 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2629 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
2630 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
2632 if(tutoriallevel==1){
2633 Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,1,1, .6, .3);
2635 victim->DoDamage(damagemult*0);
2638 if(targetanimation==swordslashanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2639 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim){
2640 if(victim->weaponactive==-1||normaldotproduct(victim->facing,victim->coords-coords)>0||(Random()%2==0)){
2641 award_bonus(id, Slashbonus);
2643 if(tutoriallevel!=1){
2644 if(normaldotproduct(victim->facing,victim->coords-coords)<0)victim->DoBloodBig(2/victim->armorhigh,190);
2645 else victim->DoBloodBig(2/victim->armorhigh,185);
2646 victim->deathbleeding=1;
2647 emit_sound_at(swordslicesound, victim->coords);
2649 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2650 if(tutoriallevel!=1){
2651 victim->targetframe=0;
2652 victim->targetanimation=staggerbackhardanim;
2653 victim->targetrotation=targetrotation+180;
2657 if(tutoriallevel!=1){
2658 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
2659 weapons.blooddrip[weaponids[weaponactive]]+=3;
2661 float bloodlossamount;
2662 bloodlossamount=200+abs((float)(Random()%40))-20;
2663 victim->bloodloss+=bloodlossamount/victim->armorhigh;
2664 //victim->bloodloss+=100*(6.5-findDistancefast(&coords,&victim->coords));
2665 victim->DoDamage(damagemult*0);
2667 XYZ footvel,footpoint;
2670 footpoint=(victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].position+victim->skeleton.joints[victim->skeleton.jointlabels[neck]].position)/2*victim->scale+victim->coords;
2673 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;
2675 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
2676 footvel=DoRotation(facing,0,90,0)*.8;
2678 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2679 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
2680 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
2681 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
2685 if(victim->weaponactive!=-1){
2686 if(weapons.type[victim->weaponids[0]]==staff||weapons.type[weaponids[0]]==staff){
2687 if(weapons.type[victim->weaponids[0]]==staff)weapons.damage[victim->weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2688 if(weapons.type[weaponids[0]]==staff)weapons.damage[weaponids[0]]+=.2+float(abs(Random()%100)-50)/250;
2690 emit_sound_at(swordstaffsound, victim->coords);
2693 emit_sound_at(metalhitsound, victim->coords);
2699 victim->Puff(righthand);
2701 victim->targetframe=0;
2702 victim->targetanimation=staggerbackhighanim;
2703 victim->targetrotation=targetrotation+180;
2705 weapons.owner[victim->weaponids[0]]=-1;
2706 aim=DoRotation(facing,0,90,0)*21;
2708 weapons.velocity[victim->weaponids[0]]=aim*-.2;
2709 weapons.tipvelocity[victim->weaponids[0]]=aim;
2710 weapons.missed[victim->weaponids[0]]=1;
2711 weapons.hitsomething[weaponids[0]]=0;
2712 weapons.freetime[victim->weaponids[0]]=0;
2713 weapons.firstfree[victim->weaponids[0]]=1;
2714 weapons.physics[victim->weaponids[0]]=1;
2715 victim->num_weapons--;
2716 if(victim->num_weapons){
2717 victim->weaponids[0]=victim->weaponids[num_weapons];
2718 if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
2720 victim->weaponactive=-1;
2721 for(i=0;i<numplayers;i++){
2722 player[i].wentforweapon=0;
2725 /*PlaySoundEx( metalhitsound, samp[metalhitsound], NULL, true);
2726 OPENAL_3D_SetAttributes(channels[metalhitsound], gLoc, vel);
2727 OPENAL_SetVolume(channels[metalhitsound], 512);
2728 OPENAL_SetPaused(channels[metalhitsound], false);*/
2734 if(targetanimation==staffhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2735 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2736 if(tutoriallevel!=1){
2737 weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/250;
2739 if(id==0)camerashake+=.4;
2740 if(Random()%2||creature==wolftype){
2743 emit_sound_at(staffheadsound, victim->coords);
2747 relative=victim->coords-coords;
2749 Normalise(&relative);
2750 relative=DoRotation(relative,0,90,0);
2752 Normalise(&relative);
2753 for(i=0;i<victim->skeleton.num_joints;i++){
2754 victim->skeleton.joints[i].velocity+=relative*damagemult*60;
2756 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*230;
2757 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*230;
2760 if(tutoriallevel!=1){
2761 victim->DoDamage(damagemult*120/victim->protectionhigh);
2763 award_bonus(id, solidhit, 30);
2768 if(targetanimation==staffspinhitanim&&animation[targetanimation].label[currentframe]==5&&victim->targetanimation!=rollanim){
2769 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5&&victim->targetanimation!=dodgebackanim&&victim->targetanimation!=sweepanim){
2770 if(tutoriallevel!=1){
2771 weapons.damage[weaponids[0]]+=.6+float(abs(Random()%100)-50)/250;
2773 if(id==0)camerashake+=.4;
2774 if(Random()%2||creature==wolftype){
2777 emit_sound_at(staffheadsound, victim->coords);
2781 relative=victim->coords-coords;
2783 Normalise(&relative);
2784 relative=DoRotation(relative,0,-90,0);
2785 for(i=0;i<victim->skeleton.num_joints;i++){
2786 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2788 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*220;
2789 victim->skeleton.joints[victim->skeleton.jointlabels[neck]].velocity+=relative*damagemult*220;
2792 if(tutoriallevel!=1){victim->DoDamage(damagemult*350/victim->protectionhead);
2794 award_bonus(id, solidhit, 60);
2799 if(targetanimation==staffgroundsmashanim&&animation[targetanimation].label[currentframe]==5){
2800 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*6.5){
2802 if(tutoriallevel!=1){
2803 if(!victim->dead)weapons.damage[weaponids[0]]+=.4+float(abs(Random()%100)-50)/500;
2804 if(id==0)camerashake+=.4;
2805 if(Random()%2||creature==wolftype){
2808 emit_sound_at(staffbodysound, victim->coords);
2810 victim->skeleton.longdead=0;
2811 victim->skeleton.free=1;
2812 victim->skeleton.broken=0;
2814 for(i=0;i<victim->skeleton.num_joints;i++){
2815 victim->skeleton.joints[i].velchange=0;
2816 victim->skeleton.joints[i].locked=0;
2817 //victim->skeleton.joints[i].velocity=0;
2823 /*relative=victim->coords-coords;
2825 Normalise(&relative);
2826 relative=DoRotation(relative,0,90,0);*/
2828 Normalise(&relative);
2830 for(i=0;i<victim->skeleton.num_joints;i++){
2831 victim->skeleton.joints[i].velocity=relative*damagemult*40;
2834 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*40;
2837 for(i=0;i<victim->skeleton.num_joints;i++){
2838 victim->skeleton.joints[i].velocity=relative*damagemult*abs(Random()%20);
2841 //victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*20;
2843 victim->Puff(abdomen);
2844 if(tutoriallevel!=1){victim->DoDamage(damagemult*100/victim->protectionhigh);
2847 award_bonus(id, solidhit, 40);
2853 if(targetanimation==lowkickanim&&animation[targetanimation].label[currentframe]==5){
2854 if(findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&animation[victim->targetanimation].height!=highheight){
2856 if(id==0)camerashake+=.4;
2858 relative=victim->coords-coords;
2860 Normalise(&relative);
2864 if(animation[victim->targetanimation].height==lowheight){
2870 for(i=0;i<victim->skeleton.num_joints;i++){
2871 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2873 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
2874 if(tutoriallevel!=1){
2875 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2878 victim->DoDamage(damagemult*100/victim->protectionhead);
2879 if(victim->howactive==typesleeping)victim->DoDamage(damagemult*150/victim->protectionhead);
2880 if(creature==wolftype){
2881 emit_sound_at(clawslicesound, victim->coords, 128.);
2883 victim->DoBloodBig(2/victim->armorhead,175);
2887 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2888 for(i=0;i<victim->skeleton.num_joints;i++){
2889 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2891 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2892 victim->targetframe=0;
2893 victim->targetanimation=staggerbackhighanim;
2894 victim->targetrotation=targetrotation+180;
2896 if(tutoriallevel!=1){
2897 emit_sound_at(landsound2, victim->coords, 128.);
2899 victim->Puff(abdomen);
2900 victim->DoDamage(damagemult*30/victim->protectionhigh);
2901 if(creature==wolftype){
2902 emit_sound_at(clawslicesound, victim->coords, 128.);
2904 victim->DoBloodBig(2/victim->armorhigh,170);
2911 if(targetanimation==sweepanim&&animation[targetanimation].label[currentframe]==5){
2912 if(victim->targetanimation!=jumpupanim&&findDistancefast(&coords,&victim->coords)<(scale*5)*(scale*5)*3&&victim!=this){
2914 if(id==0)camerashake+=.2;
2915 if(tutoriallevel!=1){
2916 emit_sound_at(landsound2, victim->coords, 128.);
2919 relative=victim->coords-coords;
2921 Normalise(&relative);
2923 if(animation[victim->targetanimation].height==middleheight||animation[victim->currentanimation].height==middleheight||victim->damage>=victim->damagetolerance-40){
2926 for(i=0;i<victim->skeleton.num_joints;i++){
2927 victim->skeleton.joints[i].velocity+=relative*damagemult*15;
2929 relative=DoRotation(relative,0,-90,0);
2931 for(i=0;i<victim->skeleton.num_joints;i++){
2932 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)
2933 victim->skeleton.joints[i].velocity=relative*80;
2935 victim->Puff(rightankle);
2936 victim->Puff(leftankle);
2937 victim->DoDamage(damagemult*40/victim->protectionlow);
2940 if(victim->damage>=victim->damagetolerance)victim->RagDoll(0);
2941 for(i=0;i<victim->skeleton.num_joints;i++){
2942 victim->skeleton.joints[i].velocity+=relative*damagemult*10;
2944 relative=DoRotation(relative,0,-90,0);
2945 for(i=0;i<victim->skeleton.num_joints;i++){
2946 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)
2947 victim->skeleton.joints[i].velocity+=relative*damagemult*80;
2949 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2950 victim->targetframe=0;
2951 victim->targetanimation=staggerbackhighanim;
2952 victim->targetrotation=targetrotation+180;
2954 if(tutoriallevel!=1){
2955 emit_sound_at(landsound2, victim->coords, 128.);
2957 victim->Puff(abdomen);
2958 victim->DoDamage(damagemult*30/victim->protectionlow);
2966 if(animation[targetanimation].attack==reversal&&(!victim->feint||(victim->lastattack==victim->lastattack2&&victim->lastattack2==victim->lastattack3&&Random()%2)||targetanimation==knifefollowanim)){
2967 if(targetanimation==spinkickreversalanim&&animation[targetanimation].label[currentframe]==7){
2969 if(id==0)camerashake+=.4;
2974 if(tutoriallevel!=1){
2975 emit_sound_at(heavyimpactsound, victim->coords, 128.);
2977 if(creature==wolftype){
2978 emit_sound_at(clawslicesound, victim->coords, 128);
2980 victim->DoBloodBig(2/victim->armorhigh,170);
2984 relative=victim->coords-oldcoords;
2986 Normalise(&relative);
2987 //relative=DoRotation(relative,0,-90,0);
2988 for(i=0;i<victim->skeleton.num_joints;i++){
2989 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
2991 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
2993 victim->Puff(abdomen);
2994 victim->DoDamage(damagemult*150/victim->protectionhigh);
2996 award_bonus(id, Reversal);
2999 if((targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim)&&animation[targetanimation].label[currentframe]==5){
3000 if(victim->weaponactive!=-1&&victim->num_weapons>0){
3001 if(weapons.owner[victim->weaponids[victim->weaponactive]]==victim->id){
3002 weapons.owner[victim->weaponids[victim->weaponactive]]=id;
3005 weaponids[num_weapons]=weaponids[victim->weaponactive];
3008 weaponids[0]=victim->weaponids[victim->weaponactive];
3009 victim->num_weapons--;
3010 if(victim->num_weapons>0){
3011 victim->weaponids[victim->weaponactive]=victim->weaponids[victim->num_weapons];
3012 //if(victim->weaponstuck==victim->num_weapons)victim->weaponstuck=0;
3014 victim->weaponactive=-1;
3019 if(targetanimation==staffhitreversalanim&&animation[targetanimation].label[currentframe]==5){
3021 if(id==0)camerashake+=.4;
3026 emit_sound_at(whooshhitsound, victim->coords, 128.);
3029 relative=victim->coords-oldcoords;
3031 Normalise(&relative);
3032 //relative=DoRotation(relative,0,-90,0);
3033 for(i=0;i<victim->skeleton.num_joints;i++){
3034 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3036 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3039 victim->DoDamage(damagemult*70/victim->protectionhigh);
3042 if(targetanimation==staffspinhitreversalanim&&animation[targetanimation].label[currentframe]==7){
3044 if(id==0)camerashake+=.4;
3050 award_bonus(id, staffreversebonus);
3052 if(tutoriallevel!=1){
3053 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3056 award_bonus(id, staffreversebonus); // Huh, again?
3059 relative=victim->coords-oldcoords;
3061 Normalise(&relative);
3062 //relative=DoRotation(relative,0,-90,0);
3063 for(i=0;i<victim->skeleton.num_joints;i++){
3064 victim->skeleton.joints[i].velocity+=relative*damagemult*30;
3066 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3069 victim->DoDamage(damagemult*70/victim->protectionhigh);
3072 if(targetanimation==upunchreversalanim&&animation[targetanimation].label[currentframe]==7){
3078 Normalise(&relative);
3081 for(i=0;i<victim->skeleton.num_joints;i++){
3082 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3084 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1;
3085 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2;
3086 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5;
3087 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7;
3088 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1;
3089 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2;
3090 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5;
3091 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7;
3093 victim->Puff(abdomen);
3094 victim->DoDamage(damagemult*90/victim->protectionhigh);
3096 award_bonus(id, Reversal);
3100 if(weaponactive!=-1||creature==wolftype)doslice=1;
3101 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3103 if(weaponactive!=-1){
3104 victim->DoBloodBig(2/victim->armorhigh,225);
3105 emit_sound_at(knifeslicesound, victim->coords);
3106 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3107 weapons.blooddrip[weaponids[weaponactive]]+=3;
3109 if(weaponactive==-1&&creature==wolftype){;
3110 emit_sound_at(clawslicesound, victim->coords, 128.);
3112 victim->DoBloodBig(2/victim->armorhigh,175);
3119 if(targetanimation==swordslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3125 Normalise(&relative);
3128 for(i=0;i<victim->skeleton.num_joints;i++){
3129 victim->skeleton.joints[i].velocity+=relative*damagemult*70;
3131 victim->skeleton.joints[victim->skeleton.jointlabels[lefthand]].velocity*=.1-1;
3132 victim->skeleton.joints[victim->skeleton.jointlabels[leftwrist]].velocity*=.2-1;
3133 victim->skeleton.joints[victim->skeleton.jointlabels[leftelbow]].velocity*=.5-1;
3134 victim->skeleton.joints[victim->skeleton.jointlabels[leftshoulder]].velocity*=.7-1;
3135 victim->skeleton.joints[victim->skeleton.jointlabels[righthand]].velocity*=.1-1;
3136 victim->skeleton.joints[victim->skeleton.jointlabels[rightwrist]].velocity*=.2-1;
3137 victim->skeleton.joints[victim->skeleton.jointlabels[rightelbow]].velocity*=.5-1;
3138 victim->skeleton.joints[victim->skeleton.jointlabels[rightshoulder]].velocity*=.7-1;
3140 award_bonus(id, swordreversebonus);
3143 if(hasvictim&&targetanimation==knifeslashreversalanim&&animation[targetanimation].label[currentframe]==7){
3145 if(id==0)camerashake+=.4;
3150 if(tutoriallevel!=1){
3151 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3155 relative=victim->coords-oldcoords;
3157 Normalise(&relative);
3158 relative=DoRotation(relative,0,-90,0);
3159 for(i=0;i<victim->skeleton.num_joints;i++){
3160 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3162 victim->skeleton.joints[victim->skeleton.jointlabels[abdomen]].velocity+=relative*damagemult*200;
3164 victim->Puff(abdomen);
3165 victim->DoDamage(damagemult*30/victim->protectionhigh);
3167 award_bonus(id, Reversal);
3170 if(hasvictim&&targetanimation==sneakattackanim&&animation[targetanimation].label[currentframe]==7){
3173 victim->skeleton.spinny=0;
3177 Normalise(&relative);
3178 if(victim->id==0)relative/=30;
3179 for(i=0;i<victim->skeleton.num_joints;i++){
3180 victim->skeleton.joints[i].velocity+=relative*damagemult*40;
3182 //victim->DoDamage(1000);
3183 victim->damage=victim->damagetolerance;
3184 victim->permanentdamage=victim->damagetolerance-1;
3187 if(weaponactive!=-1||creature==wolftype)doslice=1;
3188 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3190 if(weaponactive!=-1){
3191 victim->DoBloodBig(200,225);
3192 emit_sound_at(knifeslicesound, victim->coords);
3193 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3194 weapons.blooddrip[weaponids[weaponactive]]+=5;
3197 if(creature==wolftype&&weaponactive==-1){
3198 emit_sound_at(clawslicesound, victim->coords, 128.);
3200 victim->DoBloodBig(2,175);
3203 award_bonus(id, spinecrusher);
3206 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3207 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3209 if(targetanimation==knifefollowanim)victim->DoBloodBig(200,210);
3210 if(targetanimation==knifesneakattackanim){
3211 /*victim->DoBloodBig(200,195);
3216 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
3217 Sprite::MakeSprite(bloodsprite, DoRotation(skeleton.joints[skeleton.jointlabels[neck]].position,0,rotation,0)*scale+coords,bloodvel, 1,1,1, .05, 1);
3219 XYZ footvel,footpoint;
3221 footpoint=weapons.tippoint[weaponids[0]];
3222 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3223 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3224 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3225 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3226 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3227 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3228 victim->DoBloodBig(200,195);
3229 award_bonus(id, tracheotomy);
3231 if(targetanimation==knifefollowanim){
3232 award_bonus(id, Stabbonus);
3233 XYZ footvel,footpoint;
3235 footpoint=weapons.tippoint[weaponids[0]];
3236 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3237 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3238 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3239 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3240 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .2, 1);
3241 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .2, 1);
3244 victim->bloodloss+=10000;
3246 emit_sound_at(fleshstabsound, victim->coords);
3247 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3248 weapons.blooddrip[weaponids[weaponactive]]+=5;
3252 if(hasvictim&&(targetanimation==knifefollowanim||targetanimation==knifesneakattackanim)&&animation[targetanimation].label[currentframe]==6){
3255 for(i=0;i<victim->skeleton.num_joints;i++){
3256 victim->skeleton.joints[i].velocity=0;
3258 if(targetanimation==knifefollowanim){
3260 for(i=0;i<victim->skeleton.num_joints;i++){
3261 victim->skeleton.joints[i].velocity=0;
3264 if(weaponactive!=-1&&animation[victim->targetanimation].attack!=reversal){
3265 emit_sound_at(fleshstabremovesound, victim->coords);
3266 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3267 weapons.blooddrip[weaponids[weaponactive]]+=5;
3269 XYZ footvel,footpoint;
3271 footpoint=weapons.tippoint[weaponids[0]];
3272 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3273 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3274 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3275 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3276 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3277 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3281 if(hasvictim&&(targetanimation==swordsneakattackanim)&&animation[targetanimation].label[currentframe]==5){
3282 if(weaponactive!=-1&&victim->bloodloss<victim->damagetolerance){
3283 award_bonus(id, backstab);
3287 XYZ footvel,footpoint;
3289 footpoint=(weapons.tippoint[weaponids[0]]+weapons.position[weaponids[0]])/2;
3290 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3291 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]]);
3292 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3293 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3294 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*5,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3295 Sprite::MakeSprite(bloodflamesprite, footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .3, 1);
3296 victim->DoBloodBig(200,180);
3297 victim->DoBloodBig(200,215);
3298 victim->bloodloss+=10000;
3300 emit_sound_at(fleshstabsound, victim->coords);
3301 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3302 weapons.blooddrip[weaponids[weaponactive]]+=5;
3306 if(hasvictim&&targetanimation==swordsneakattackanim&&animation[targetanimation].label[currentframe]==6){
3309 for(i=0;i<victim->skeleton.num_joints;i++){
3310 victim->skeleton.joints[i].velocity=0;
3312 if(weaponactive!=-1){
3313 emit_sound_at(fleshstabremovesound, victim->coords);
3314 if(bloodtoggle)weapons.bloody[weaponids[weaponactive]]=2;
3315 weapons.blooddrip[weaponids[weaponactive]]+=5;
3317 XYZ footvel,footpoint;
3319 footpoint=weapons.tippoint[weaponids[0]];
3320 if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .9, .3);
3321 footvel=(weapons.tippoint[weaponids[0]]-weapons.position[weaponids[0]])*-1;
3322 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*7,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3323 Sprite::MakeSprite(bloodsprite,footpoint,DoRotation(footvel*3,(float)(Random()%20),(float)(Random()%20),0), 1,1,1, .05, .9);
3324 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*5, 1,1,1, .3, 1);
3325 Sprite::MakeSprite(bloodflamesprite, footpoint,footvel*2, 1,1,1, .3, 1);
3329 if(targetanimation==sweepreversalanim&&animation[targetanimation].label[currentframe]==7){
3331 if(id==0)camerashake+=.4;
3336 if(weaponactive==-1){
3337 if(tutoriallevel!=1){
3338 emit_sound_at(heavyimpactsound, victim->coords, 128.);
3343 if(weaponactive!=-1||creature==wolftype)doslice=1;
3344 if(creature==rabbittype&&weaponactive!=-1)if(weapons.type[weaponids[0]]==staff)doslice=0;
3346 if(weaponactive!=-1){
3347 victim->DoBloodBig(2/victim->armorhead,225);
3348 emit_sound_at(knifeslicesound, victim->coords);
3349 if(bloodtoggle&&!weapons.bloody[weaponids[weaponactive]])weapons.bloody[weaponids[weaponactive]]=1;
3350 weapons.blooddrip[weaponids[weaponactive]]+=3;
3352 if(weaponactive==-1&&creature==wolftype){
3353 emit_sound_at(clawslicesound, victim->coords, 128.);
3355 victim->DoBloodBig(2/victim->armorhead,175);
3359 award_bonus(id, Reversal);
3364 //relative=victim->coords-oldcoords;
3367 Normalise(&relative);
3368 relative=DoRotation(relative,0,90,0);
3370 Normalise(&relative);
3371 for(i=0;i<victim->skeleton.num_joints;i++){
3372 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3374 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3375 if(victim->damage<victim->damagetolerance-100)victim->velocity=relative*200;
3376 victim->DoDamage(damagemult*100/victim->protectionhead);
3380 if(targetanimation==sweepreversalanim&&((animation[targetanimation].label[currentframe]==9&&victim->damage<victim->damagetolerance)||(animation[targetanimation].label[currentframe]==7&&victim->damage>victim->damagetolerance))){
3384 //relative=victim->coords-oldcoords;
3387 Normalise(&relative);
3388 relative=DoRotation(relative,0,90,0);
3390 Normalise(&relative);
3391 for(i=0;i<victim->skeleton.num_joints;i++){
3392 victim->skeleton.joints[i].velocity+=relative*damagemult*20;
3394 victim->skeleton.joints[victim->skeleton.jointlabels[head]].velocity+=relative*damagemult*200;
3397 if(hasvictim&&(targetanimation==spinkickreversalanim||targetanimation==sweepreversalanim||targetanimation==rabbitkickreversalanim||targetanimation==upunchreversalanim||targetanimation==jumpreversalanim||targetanimation==swordslashreversalanim||targetanimation==knifeslashreversalanim||targetanimation==rabbittacklereversal||targetanimation==wolftacklereversal||targetanimation==staffhitreversalanim||targetanimation==staffspinhitreversalanim))
3398 if(victim->damage>victim->damagetolerance&&bonus!=reverseko){
3399 award_bonus(id, reverseko);
3405 if(targetframe>animation[currentanimation].numframes-1){
3408 targetanimation=getIdle();
3412 if(currentanimation==rabbittackleanim||currentanimation==rabbittacklinganim){
3413 targetanimation=rollanim;
3415 emit_sound_at(movewhooshsound, coords, 128.);
3417 if(currentanimation==staggerbackhighanim){
3418 targetanimation=getIdle();
3420 if(currentanimation==staggerbackhardanim){
3421 targetanimation=getIdle();
3423 if(currentanimation==removeknifeanim){
3424 targetanimation=getIdle();
3426 if(currentanimation==crouchremoveknifeanim){
3427 targetanimation=getCrouch();
3429 if(currentanimation==backhandspringanim){
3430 targetanimation=getIdle();
3432 if(currentanimation==dodgebackanim){
3433 targetanimation=getIdle();
3435 if(currentanimation==drawleftanim){
3436 targetanimation=getIdle();
3438 if(currentanimation==drawrightanim||currentanimation==crouchdrawrightanim){
3439 targetanimation=getIdle();
3440 if(currentanimation==crouchdrawrightanim){
3441 targetanimation=getCrouch();
3443 if(weaponactive==-1)weaponactive=0;
3444 else if(weaponactive==0){
3448 buffer=weaponids[0];
3449 weaponids[0]=weaponids[1];
3450 weaponids[1]=buffer;
3454 if(weaponactive==-1){
3455 emit_sound_at(knifesheathesound, coords, 128.);
3457 if(weaponactive!=-1){
3458 emit_sound_at(knifedrawsound, coords, 128.);
3461 if(currentanimation==rollanim){
3462 targetanimation=getCrouch();
3467 if(targetanimation==walljumprightkickanim){
3470 if(targetanimation==walljumpleftkickanim){
3473 targetanimation=jumpdownanim;
3475 if(currentanimation==climbanim){
3476 targetanimation=getCrouch();
3479 if(!isnormal(coords.x))
3490 if(targetanimation==rabbitkickreversalanim){
3491 targetanimation=getCrouch();
3494 if(targetanimation==jumpreversalanim){
3495 targetanimation=getCrouch();
3498 if(targetanimation==walljumprightanim||targetanimation==walljumpbackanim||targetanimation==walljumpfrontanim){
3499 if(attackkeydown&&targetanimation!=walljumpfrontanim){
3501 float closestdist=-1;
3504 for(i=0;i<numplayers;i++){
3505 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3506 distance=findDistancefast(&player[i].coords,&coords);
3507 if(closestdist==-1||distance<closestdist){
3508 closestdist=distance;
3513 if(closestdist>0&&closest>=0&&closestdist<16){
3514 victim=&player[closest];
3515 targetanimation=walljumprightkickanim;
3517 XYZ rotatetarget=victim->coords-coords;
3518 Normalise(&rotatetarget);
3519 rotation=-asin(0-rotatetarget.x);
3521 if(rotatetarget.z<0)rotation=180-rotation;
3522 targettilt2=-asin(rotatetarget.y)*360/6.28;
3523 velocity=(victim->coords-coords)*4;
3528 if(targetanimation==walljumpbackanim){
3529 targetanimation=backflipanim;
3533 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3535 if(targetanimation==walljumprightanim){
3536 targetanimation=rightflipanim;
3540 velocity=DoRotation(facing,0,30,0)*-8;
3543 if(targetanimation==walljumpfrontanim){
3544 targetanimation=frontflipanim;
3546 //targetrotation-=180;
3551 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3553 if(targetanimation==walljumpleftanim){
3556 float closestdist=-1;
3559 for(i=0;i<numplayers;i++){
3560 if(id!=i&&player[i].coords.y<coords.y&&!player[i].skeleton.free){
3561 distance=findDistancefast(&player[i].coords,&coords);
3562 if(closestdist==-1||distance<closestdist){
3563 closestdist=distance;
3568 if(closestdist>0&&closest>=0&&closestdist<16){
3569 victim=&player[closest];
3570 targetanimation=walljumpleftkickanim;
3572 XYZ rotatetarget=victim->coords-coords;
3573 Normalise(&rotatetarget);
3574 rotation=-asin(0-rotatetarget.x);
3576 if(rotatetarget.z<0)rotation=180-rotation;
3577 targettilt2=-asin(rotatetarget.y)*360/6.28;
3578 velocity=(victim->coords-coords)*4;
3583 if(targetanimation!=walljumpleftkickanim){
3584 targetanimation=leftflipanim;
3588 velocity=DoRotation(facing,0,-30,0)*-8;
3591 if(id==0)OPENAL_SetPaused(channels[whooshsound], false);
3593 if(targetanimation==sneakattackanim){
3594 float ycoords=oldcoords.y;
3595 currentanimation=getCrouch();
3596 targetanimation=getCrouch();
3599 targetrotation+=180;
3604 targetheadrotation+=180;
3606 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3610 if(targetanimation==knifesneakattackanim||targetanimation==swordsneakattackanim){
3611 float ycoords=oldcoords.y;
3612 targetanimation=getIdle();
3614 if(onterrain)coords.y=terrain.getHeight(coords.x,coords.z);
3618 if(currentanimation==knifefollowanim){
3619 targetanimation=getIdle();
3622 if(animation[targetanimation].attack==reversal&¤tanimation!=sneakattackanim&¤tanimation!=knifesneakattackanim&¤tanimation!=swordsneakattackanim&¤tanimation!=knifefollowanim){
3623 float ycoords=oldcoords.y;
3624 targetanimation=getStop();
3625 targetrotation+=180;
3630 targetheadrotation+=180;
3631 if(!isnormal(coords.x))
3633 if(currentanimation==spinkickreversalanim||currentanimation==swordslashreversalanim)
3634 oldcoords=coords+facing*.5;
3635 else if(currentanimation==sweepreversalanim)
3636 oldcoords=coords+facing*1.1;
3637 else if(currentanimation==upunchreversalanim){
3638 oldcoords=coords+facing*1.5;
3639 targetrotation+=180;
3641 targetheadrotation+=180;
3645 else if(currentanimation==knifeslashreversalanim){
3646 oldcoords=coords+facing*.5;
3649 targetheadrotation+=90;
3653 else if(currentanimation==staffspinhitreversalanim){
3654 targetrotation+=180;
3656 targetheadrotation+=180;
3660 if(onterrain)oldcoords.y=terrain.getHeight(oldcoords.x,oldcoords.z);
3661 else oldcoords.y=ycoords;
3662 currentoffset=coords-oldcoords;
3668 if(currentanimation==knifesneakattackedanim||currentanimation==swordsneakattackedanim){
3673 if(animation[targetanimation].attack==reversed){
3675 if(targetanimation==sweepreversedanim)targetrotation+=90;
3676 targetanimation=backhandspringanim;
3678 emit_sound_at(landsound, coords, 128);
3680 if(currentanimation==upunchreversedanim||currentanimation==swordslashreversedanim){
3681 targetanimation=rollanim;
3684 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3685 coords.y=oldcoords.y;
3687 if(currentanimation==knifeslashreversedanim){
3688 targetanimation=rollanim;
3693 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3694 coords.y=oldcoords.y;
3698 targetanimation=jumpdownanim;
3700 if(wasLanding())targetanimation=getIdle();
3701 if(wasLandhard())targetanimation=getIdle();
3702 if(currentanimation==spinkickanim||currentanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==lowkickanim){
3703 targetanimation=getIdle();
3705 coords+=(DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)+DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0))/2*scale;
3706 coords.y=oldcoords.y;
3707 //coords+=DoRotation(animation[currentanimation].offset,0,rotation,0)*scale;
3708 targetoffset.y=coords.y;
3709 if(onterrain)targetoffset.y=terrain.getHeight(coords.x,coords.z);
3710 currentoffset=DoRotation(animation[currentanimation].offset*-1,0,rotation,0)*scale;
3711 currentoffset.y-=(coords.y-targetoffset.y);
3712 coords.y=targetoffset.y;
3714 normalsupdatedelay=0;
3716 if(currentanimation==upunchanim){
3717 targetanimation=getStop();
3718 normalsupdatedelay=0;
3721 if(currentanimation==rabbitkickanim&&targetanimation!=backflipanim){
3722 targetrotation=rotation;
3725 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
3726 if(!hasstaff)DoDamage(35);
3729 rabbitkickragdoll=1;
3731 if(currentanimation==rabbitkickreversedanim){
3738 SolidHitBonus(!id); // FIXME: tricky id
3742 targetanimation=rollanim;
3744 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3748 if(currentanimation==rabbittackledbackanim||currentanimation==rabbittackledfrontanim){
3754 if(currentanimation==jumpreversedanim){
3761 SolidHitBonus(!id); // FIXME: tricky id
3765 targetanimation=rollanim;
3767 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
3772 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){
3773 targetanimation=getupfromfrontanim;
3776 else if(animation[currentanimation].attack==normalattack){
3777 targetanimation=getIdle();
3780 if(currentanimation==blockhighleftanim&&aitype!=playercontrolled){
3781 targetanimation=blockhighleftstrikeanim;
3783 if(currentanimation==knifeslashstartanim||currentanimation==knifethrowanim||currentanimation==swordslashanim||currentanimation==staffhitanim||currentanimation==staffgroundsmashanim||currentanimation==staffspinhitanim){
3784 targetanimation=getIdle();
3787 if(currentanimation==spinkickanim&&victim->skeleton.free){
3788 if(creature==rabbittype)targetanimation=fightidleanim;
3793 if(isIdle()&&!wasIdle())normalsupdatedelay=0;
3795 if(currentanimation==jumpupanim&&velocity.y<0&&!isFlip()){
3796 targetanimation=jumpdownanim;
3801 if(!transspeed&&animation[targetanimation].attack!=2&&animation[targetanimation].attack!=3){
3802 if(!isRun()||!wasRun()){
3803 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3804 target+=multiplier*animation[targetanimation].speed[targetframe]*speed*2;
3805 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3806 target+=multiplier*animation[currentanimation].speed[currentframe]*speed*2;
3808 if(isRun()&&wasRun()){
3811 if(tempspeed<10*speedmult)tempspeed=10*speedmult;
3812 target+=multiplier*animation[targetanimation].speed[currentframe]*speed*1.7*tempspeed/(speed*45*scale);
3815 else if(transspeed)target+=multiplier*transspeed*speed*2;
3817 if(!isRun()||!wasRun()){
3818 if(animation[targetanimation].speed[targetframe]>animation[currentanimation].speed[currentframe])
3819 target+=multiplier*animation[targetanimation].speed[targetframe]*2;
3820 if(animation[targetanimation].speed[targetframe]<=animation[currentanimation].speed[currentframe])
3821 target+=multiplier*animation[currentanimation].speed[currentframe]*2;
3825 if(currentanimation!=targetanimation)target=(target+oldtarget)/2;
3827 if(target>1){currentframe=targetframe; target=1;}
3829 rot=targetrot*target;
3830 rotation+=rot-oldrot;
3836 if(currentanimation!=oldcurrentanimation||targetanimation!=oldtargetanimation||((currentframe!=oldcurrentframe||targetframe!=oldtargetframe)&&!calcrot)){
3838 for(i=0;i<skeleton.num_joints;i++){
3839 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe];
3842 skeleton.FindForwards();
3844 for(i=0;i<skeleton.num_muscles;i++){
3845 if(skeleton.muscles[i].visible)
3847 skeleton.FindRotationMuscle(i,targetanimation);
3850 for(i=0;i<skeleton.num_muscles;i++){
3851 if(skeleton.muscles[i].visible)
3853 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].oldrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3854 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].oldrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3855 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].oldrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3860 for(i=0;i<skeleton.num_joints;i++){
3861 skeleton.joints[i].position=animation[targetanimation].position[i][targetframe];
3864 skeleton.FindForwards();
3866 for(i=0;i<skeleton.num_muscles;i++){
3867 if(skeleton.muscles[i].visible)
3869 skeleton.FindRotationMuscle(i,targetanimation);
3872 for(i=0;i<skeleton.num_muscles;i++){
3873 if(skeleton.muscles[i].visible)
3875 if(isnormal((float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100))skeleton.muscles[i].newrotate1=(float)((int)(skeleton.muscles[i].rotate1*100)%36000)/100;
3876 if(isnormal((float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100))skeleton.muscles[i].newrotate2=(float)((int)(skeleton.muscles[i].rotate2*100)%36000)/100;
3877 if(isnormal((float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100))skeleton.muscles[i].newrotate3=(float)((int)(skeleton.muscles[i].rotate3*100)%36000)/100;
3878 if(skeleton.muscles[i].newrotate3>skeleton.muscles[i].oldrotate3+180)skeleton.muscles[i].newrotate3-=360;
3879 if(skeleton.muscles[i].newrotate3<skeleton.muscles[i].oldrotate3-180)skeleton.muscles[i].newrotate3+=360;
3880 if(skeleton.muscles[i].newrotate2>skeleton.muscles[i].oldrotate2+180)skeleton.muscles[i].newrotate2-=360;
3881 if(skeleton.muscles[i].newrotate2<skeleton.muscles[i].oldrotate2-180)skeleton.muscles[i].newrotate2+=360;
3882 if(skeleton.muscles[i].newrotate1>skeleton.muscles[i].oldrotate1+180)skeleton.muscles[i].newrotate1-=360;
3883 if(skeleton.muscles[i].newrotate1<skeleton.muscles[i].oldrotate1-180)skeleton.muscles[i].newrotate1+=360;
3887 if(currentframe>=animation[currentanimation].numframes)currentframe=animation[currentanimation].numframes-1;
3889 oldcurrentanimation=currentanimation;
3890 oldtargetanimation=targetanimation;
3891 oldtargetframe=targetframe;
3892 oldcurrentframe=currentframe;
3894 for(i=0;i<skeleton.num_joints;i++){
3895 skeleton.joints[i].velocity=(animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target)-skeleton.joints[i].position)/multiplier;
3896 skeleton.joints[i].position=animation[currentanimation].position[i][currentframe]*(1-target)+animation[targetanimation].position[i][targetframe]*(target);
3898 offset=currentoffset*(1-target)+targetoffset*target;
3899 for(i=0;i<skeleton.num_muscles;i++){
3900 if(skeleton.muscles[i].visible)
3902 skeleton.muscles[i].rotate1=skeleton.muscles[i].oldrotate1*(1-target)+skeleton.muscles[i].newrotate1*(target);
3903 skeleton.muscles[i].rotate2=skeleton.muscles[i].oldrotate2*(1-target)+skeleton.muscles[i].newrotate2*(target);
3904 skeleton.muscles[i].rotate3=skeleton.muscles[i].oldrotate3*(1-target)+skeleton.muscles[i].newrotate3*(target);
3909 if(isLanding()&&landhard){
3910 if(id==0)camerashake+=.4;
3911 targetanimation=getLandhard();
3918 //skeleton.DoConstraints();
3921 void Person::DoStuff(){
3922 static XYZ terrainnormal;
3923 static XYZ flatfacing;
3924 static XYZ flatvelocity;
3925 static float flatvelspeed;
3929 static int bloodsize;
3930 static int startx,starty,endx,endy;
3931 static int texdetailint;
3932 static GLubyte color;
3933 static XYZ bloodvel;
3935 onfiredelay-=multiplier;
3936 if(onfiredelay<0&&onfire)
3944 crouchkeydowntime+=multiplier;
3945 if(!crouchkeydown)crouchkeydowntime=0;
3946 jumpkeydowntime+=multiplier;
3947 if(!jumpkeydown&&skeleton.free)jumpkeydowntime=0;
3949 if(hostile||damage>0||bloodloss>0)immobile=0;
3951 if(isIdle()||isRun())targetoffset=0;
3953 if(num_weapons==1&&weaponactive!=-1)weaponstuck=-1;
3955 if(id==0)blooddimamount-=multiplier*.3;
3956 speechdelay-=multiplier;
3957 texupdatedelay-=multiplier;
3958 interestdelay-=multiplier;
3959 flamedelay-=multiplier;
3960 parriedrecently-=multiplier;
3966 if(id==0)speed=1.1*speedmult;
3967 else speed=1.0*speedmult;
3968 if(!skeleton.free)rabbitkickragdoll=0;
3972 if(id!=0&&(creature==rabbittype||difficulty!=2))superruntoggle=0;
3973 if(id!=0&&creature==wolftype&&difficulty==2){
3975 if(aitype!=passivetype){
3977 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){
3981 if(scale<0.2)superruntoggle=0;
3982 if(targetanimation==wolfrunninganim&&!superruntoggle){
3983 targetanimation=getRun();
3987 if(weaponactive==-1&&num_weapons>0){
3988 if(weapons.type[weaponids[0]]==staff){
3995 /*if(aitype!=playercontrolled)*///deathbleeding=5;
3996 /*if(aitype!=playercontrolled)*/
3998 if(burnt>.6)burnt=.6;
3999 OPENAL_SetVolume(channels[stream_firesound], 256+256*findLength(&velocity)/3);
4001 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
4012 OPENAL_3D_SetAttributes(channels[whooshsound], gLoc, vel);
4013 OPENAL_SetVolume(channels[whooshsound], 64*findLength(&velocity)/5);
4017 while(flamedelay<0&&onfire){
4019 howmany=abs(Random()%(skeleton.num_joints));
4020 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4021 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4022 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4023 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4024 Sprite::MakeSprite(flamesprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
4027 while(flamedelay<0&&!onfire&&tutoriallevel==1&&id!=0){
4029 howmany=abs(Random()%(skeleton.num_joints));
4030 if(!skeleton.free)flatvelocity=(coords-oldcoords)/multiplier/2;//velocity/2;
4031 if(skeleton.free)flatvelocity=skeleton.joints[howmany].velocity*scale/2;
4032 if(!skeleton.free)flatfacing=DoRotation(DoRotation(DoRotation(skeleton.joints[howmany].position,0,0,tilt),tilt2,0,0),0,rotation,0)*scale+coords;
4033 if(skeleton.free)flatfacing=skeleton.joints[howmany].position*scale+coords;
4034 Sprite::MakeSprite(breathsprite, flatfacing,flatvelocity, 1,1,1, .6+(float)abs(Random()%100)/200-.25, .3);
4038 bleeding-=multiplier*.3;
4040 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4041 if(bleeding<=0&&(detail!=2||osx))DoMipmaps(5,0,0,skeleton.skinsize,skeleton.skinsize);
4045 if(neckspurtamount>0){
4046 neckspurtamount-=multiplier;
4047 neckspurtdelay-=multiplier*3;
4048 neckspurtparticledelay-=multiplier*3;
4049 if(neckspurtparticledelay<0&&neckspurtdelay>2){
4053 bloodvel.z=5*neckspurtamount;
4054 bloodvel=DoRotation(bloodvel,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4057 bloodvel-=DoRotation(skeleton.forward*10*scale,((float)(Random()%100))/40,((float)(Random()%100))/40,0);
4059 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[head]].velocity,((float)(Random()%100))/40,rotation+((float)(Random()%100))/40,0)*scale;
4060 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/40,((float)(Random()%100))/40,0)*scale;
4061 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);
4062 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);
4063 neckspurtparticledelay=.05;
4065 if(neckspurtdelay<0){
4070 if(deathbleeding>0&&dead!=2){
4071 if(deathbleeding<5)bleeddelay-=deathbleeding*multiplier/4;
4072 else bleeddelay-=5*multiplier/4;
4073 if(bleeddelay<0&&bloodtoggle){
4078 if(skeleton.free)bloodvel+=DoRotation(skeleton.joints[skeleton.jointlabels[abdomen]].velocity,((float)(Random()%100))/4,rotation+((float)(Random()%100))/4,0)*scale;
4079 if(!skeleton.free)bloodvel+=DoRotation(velocity,((float)(Random()%100))/4,((float)(Random()%100))/4,0)*scale;
4080 if(skeleton.free)Sprite::MakeSprite(bloodsprite, skeleton.joints[skeleton.jointlabels[abdomen]].position*scale+coords,bloodvel, 1,1,1, .05, 1);
4081 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);
4084 bloodloss+=deathbleeding*multiplier*80;
4085 deathbleeding-=multiplier*1.6;
4086 //if(id==0)deathbleeding-=multiplier*.2;
4087 if(deathbleeding<0)deathbleeding=0;
4088 if(bloodloss>damagetolerance&&animation[targetanimation].attack==neutral){
4089 if(weaponactive!=-1){
4090 weapons.owner[weaponids[0]]=-1;
4091 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4092 weapons.velocity[weaponids[0]].x+=.01;
4093 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4094 weapons.missed[weaponids[0]]=1;
4095 weapons.hitsomething[weaponids[0]]=0;
4096 weapons.freetime[weaponids[0]]=0;
4097 weapons.firstfree[weaponids[0]]=1;
4098 weapons.physics[weaponids[0]]=1;
4101 weaponids[0]=weaponids[num_weapons];
4102 if(weaponstuck==num_weapons)weaponstuck=0;
4105 for(i=0;i<numplayers;i++){
4106 player[i].wentforweapon=0;
4118 if(!dead&&creature==wolftype){
4119 award_bonus(0, Wolfbonus);
4122 if(targetanimation==knifefollowedanim&&!skeleton.free){
4123 for(i=0;i<skeleton.num_joints;i++){
4124 skeleton.joints[i].velocity=0;
4125 skeleton.joints[i].velocity.y=-2;
4128 if(id!=0&&unconscioustime>.1){
4136 if(texupdatedelay<0&&bleeding>0&&bloodtoggle==2&&findDistancefast(&viewer,&coords)<9){
4139 bloodsize=5-realtexdetail;
4143 texdetailint=realtexdetail;
4144 startx=bleedy;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4145 starty=bleedx;//abs(Random()%(skeleton.skinsize-bloodsize-1));
4146 endx=startx+bloodsize;
4147 endy=starty+bloodsize;
4149 if(startx<0){startx=0;bleeding=0;}
4150 if(starty<0){starty=0;bleeding=0;}
4151 if(endx>skeleton.skinsize-1){endx=skeleton.skinsize-1;bleeding=0;}
4152 if(endy>skeleton.skinsize-1){endy=skeleton.skinsize-1;bleeding=0;}
4153 if(endx<startx)endx=startx;
4154 if(endy<starty)endy=starty;
4156 for(i=startx;i<endx;i++){
4157 for(j=starty;j<endy;j++){
4159 color=Random()%85+170;
4160 if(skeleton.skinText[i*skeleton.skinsize*3+j*3+0]>color/2)skeleton.skinText[i*skeleton.skinsize*3+j*3+0]=color/2;
4161 skeleton.skinText[i*skeleton.skinsize*3+j*3+1]=0;
4162 skeleton.skinText[i*skeleton.skinsize*3+j*3+2]=0;
4167 glBindTexture(GL_TEXTURE_2D,skeleton.drawmodel.textureptr);
4168 DoMipmaps(0,startx,endx,starty,endy);
4172 bleedy-=4/realtexdetail;
4173 if(detail==2)bleedx+=(abs(Random()%3)-1)*2/realtexdetail;
4174 else bleedx+=(abs(Random()%3)-1)*4/realtexdetail;
4177 bleedx+=4*direction/realtexdetail;
4178 if(detail==2)bleedy+=(abs(Random()%3)-1)*2/realtexdetail;
4179 else bleedy+=(abs(Random()%3)-1)*4/realtexdetail;
4183 if(abs(righthandmorphness-targetrighthandmorphness)<multiplier*4){
4184 righthandmorphness=targetrighthandmorphness;
4185 righthandmorphstart=righthandmorphend;
4187 else if(righthandmorphness>targetrighthandmorphness){
4188 righthandmorphness-=multiplier*4;
4190 else if(righthandmorphness<targetrighthandmorphness){
4191 righthandmorphness+=multiplier*4;
4194 if(abs(lefthandmorphness-targetlefthandmorphness)<multiplier*4){
4195 lefthandmorphness=targetlefthandmorphness;
4196 lefthandmorphstart=lefthandmorphend;
4198 else if(lefthandmorphness>targetlefthandmorphness){
4199 lefthandmorphness-=multiplier*4;
4201 else if(lefthandmorphness<targetlefthandmorphness){
4202 lefthandmorphness+=multiplier*4;
4205 if(creature==rabbittype||targettailmorphness==5||targettailmorphness==0){
4206 if(abs(tailmorphness-targettailmorphness)<multiplier*10){
4207 tailmorphness=targettailmorphness;
4208 tailmorphstart=tailmorphend;
4210 else if(tailmorphness>targettailmorphness){
4211 tailmorphness-=multiplier*10;
4213 else if(tailmorphness<targettailmorphness){
4214 tailmorphness+=multiplier*10;
4218 if(creature==wolftype){
4219 if(abs(tailmorphness-targettailmorphness)<multiplier*4){
4220 tailmorphness=targettailmorphness;
4221 tailmorphstart=tailmorphend;
4223 else if(tailmorphness>targettailmorphness){
4224 tailmorphness-=multiplier*2;
4226 else if(tailmorphness<targettailmorphness){
4227 tailmorphness+=multiplier*2;
4231 if(headmorphend==3||headmorphstart==3){
4232 if(abs(headmorphness-targetheadmorphness)<multiplier*7){
4233 headmorphness=targetheadmorphness;
4234 headmorphstart=headmorphend;
4236 else if(headmorphness>targetheadmorphness){
4237 headmorphness-=multiplier*7;
4239 else if(headmorphness<targetheadmorphness){
4240 headmorphness+=multiplier*7;
4243 else if(headmorphend==5||headmorphstart==5){
4244 if(abs(headmorphness-targetheadmorphness)<multiplier*10){
4245 headmorphness=targetheadmorphness;
4246 headmorphstart=headmorphend;
4248 else if(headmorphness>targetheadmorphness){
4249 headmorphness-=multiplier*10;
4251 else if(headmorphness<targetheadmorphness){
4252 headmorphness+=multiplier*10;
4256 if(abs(headmorphness-targetheadmorphness)<multiplier*4){
4257 headmorphness=targetheadmorphness;
4258 headmorphstart=headmorphend;
4260 else if(headmorphness>targetheadmorphness){
4261 headmorphness-=multiplier*4;
4263 else if(headmorphness<targetheadmorphness){
4264 headmorphness+=multiplier*4;
4268 if(abs(chestmorphness-targetchestmorphness)<multiplier){
4269 chestmorphness=targetchestmorphness;
4270 chestmorphstart=chestmorphend;
4272 else if(chestmorphness>targetchestmorphness){
4273 chestmorphness-=multiplier;
4275 else if(chestmorphness<targetchestmorphness){
4276 chestmorphness+=multiplier;
4279 if(dead!=2&&howactive<=typesleeping){
4280 if(chestmorphstart==0&&chestmorphend==0){
4282 targetchestmorphness=1;
4285 if(chestmorphstart!=0&&chestmorphend!=0){
4287 targetchestmorphness=1;
4289 if(environment==snowyenvironment){
4292 if(!skeleton.free)footvel=DoRotation(skeleton.specialforward[0],0,rotation,0)*-1;
4293 if(skeleton.free)footvel=skeleton.specialforward[0]*-1;
4294 if(!skeleton.free)footpoint=DoRotation((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2,0,rotation,0)*scale+coords;
4295 if(skeleton.free)footpoint=((skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2)*scale+coords;
4296 if(targetanimation==sleepanim)footvel=DoRotation(footvel,0,90,0);
4297 Sprite::MakeSprite(breathsprite, footpoint+footvel*.2,footvel*.4, 1,1,1, .4, .3);
4301 if(!dead&&howactive<typesleeping){
4302 blinkdelay-=multiplier*2;
4303 if(headmorphstart==0&&headmorphend==0&&blinkdelay<=0){
4305 targetheadmorphness=1;
4307 blinkdelay=(float)(abs(Random()%40))/5;
4309 if(headmorphstart==3&&headmorphend==3){
4311 targetheadmorphness=1;
4316 twitchdelay-=multiplier*1.5;
4317 if(targetanimation!=hurtidleanim){
4318 if(headmorphstart==0&&headmorphend==0&&twitchdelay<=0){
4320 targetheadmorphness=1;
4322 twitchdelay=(float)(abs(Random()%40))/5;
4324 if(headmorphstart==5&&headmorphend==5){
4326 targetheadmorphness=1;
4330 if((isIdle()||isCrouch())&&targetanimation!=hurtidleanim){
4331 twitchdelay3-=multiplier*1;
4333 if(righthandmorphstart==0&&righthandmorphend==0&&twitchdelay3<=0){
4334 righthandmorphness=0;
4335 targetrighthandmorphness=1;
4336 righthandmorphend=1;
4337 if(Random()%2==0)twitchdelay3=(float)(abs(Random()%40))/5;
4339 if(righthandmorphstart==1&&righthandmorphend==1){
4340 righthandmorphness=0;
4341 targetrighthandmorphness=1;
4342 righthandmorphend=0;
4346 if(lefthandmorphstart==0&&lefthandmorphend==0&&twitchdelay3<=0){
4347 lefthandmorphness=0;
4348 targetlefthandmorphness=1;
4350 twitchdelay3=(float)(abs(Random()%40))/5;
4352 if(lefthandmorphstart==1&&lefthandmorphend==1){
4353 lefthandmorphness=0;
4354 targetlefthandmorphness=1;
4361 if(creature==rabbittype){
4362 if(howactive<typesleeping)twitchdelay2-=multiplier*1.5;
4363 else twitchdelay2-=multiplier*0.5;
4364 if(howactive<=typesleeping){
4365 if(tailmorphstart==0&&tailmorphend==0&&twitchdelay2<=0){
4367 targettailmorphness=1;
4369 twitchdelay2=(float)(abs(Random()%40))/5;
4371 if(tailmorphstart==1&&tailmorphend==1){
4373 targettailmorphness=1;
4376 if(tailmorphstart==2&&tailmorphend==2){
4378 targettailmorphness=1;
4385 if(creature==wolftype){
4386 twitchdelay2-=multiplier*1.5;
4388 if((isRun()||targetanimation==jumpupanim||targetanimation==jumpdownanim||targetanimation==backflipanim)&&!skeleton.free){
4390 targettailmorphness=1;
4395 if(targetanimation==flipanim||targetanimation==frontflipanim||targetanimation==rollanim||skeleton.free){
4397 targettailmorphness=1;
4401 if(twitchdelay2<=0){
4402 if(((tailmorphstart==0&&tailmorphend==0)||(tailmorphstart==5&&tailmorphend==5))){
4404 targettailmorphness=1;
4407 if(tailmorphstart==1&&tailmorphend==1){
4409 targettailmorphness=1;
4412 if(tailmorphstart==2&&tailmorphend==2){
4414 targettailmorphness=1;
4417 if(tailmorphstart==3&&tailmorphend==3){
4419 targettailmorphness=1;
4422 if(tailmorphstart==4&&tailmorphend==4){
4424 targettailmorphness=1;
4430 if(dead!=1)unconscioustime=0;
4432 if(dead==1||howactive==typesleeping){
4433 unconscioustime+=multiplier;
4434 //If unconscious, close eyes and mouth
4435 if(righthandmorphend!=0)righthandmorphness=0;
4436 righthandmorphend=0;
4437 targetrighthandmorphness=1;
4439 if(lefthandmorphend!=0)lefthandmorphness=0;
4441 targetlefthandmorphness=1;
4443 if(headmorphend!=3&&headmorphend!=5)headmorphness=0;
4445 targetheadmorphness=1;
4449 if(howactive>typesleeping){
4452 if(bloodtoggle&&!bled){
4453 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4455 if(bloodtoggle&&!bled)
4456 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4457 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4458 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4462 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4467 if(dead==2||howactive>typesleeping){
4468 //If dead, open mouth and hands
4469 if(righthandmorphend!=0)righthandmorphness=0;
4470 righthandmorphend=0;
4471 targetrighthandmorphness=1;
4473 if(lefthandmorphend!=0)lefthandmorphness=0;
4475 targetlefthandmorphness=1;
4477 if(headmorphend!=2)headmorphness=0;
4479 targetheadmorphness=1;
4482 if(stunned>0&&!dead&&headmorphend!=2){
4483 if(headmorphend!=4)headmorphness=0;
4485 targetheadmorphness=1;
4488 if(damage>damagetolerance&&!dead){
4493 if(creature==wolftype){
4494 award_bonus(0, Wolfbonus);
4499 if(weaponactive!=-1){
4500 weapons.owner[weaponids[0]]=-1;
4501 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4502 weapons.velocity[weaponids[0]].x+=.01;
4503 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4504 weapons.missed[weaponids[0]]=1;
4505 weapons.hitsomething[weaponids[0]]=0;
4506 weapons.freetime[weaponids[0]]=0;
4507 weapons.firstfree[weaponids[0]]=1;
4508 weapons.physics[weaponids[0]]=1;
4511 weaponids[0]=weaponids[num_weapons];
4512 if(weaponstuck==num_weapons)weaponstuck=0;
4515 for(i=0;i<numplayers;i++){
4516 player[i].wentforweapon=0;
4522 if((id==0||findDistancefast(&coords,&viewer)<50)&&autoslomo){
4530 //if(dead)damage-=multiplier/4;
4531 if(!dead)damage-=multiplier*13;
4532 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4533 if(!dead)permanentdamage-=multiplier*4;
4534 if(isIdle()||isCrouch()){
4535 if(!dead)permanentdamage-=multiplier*4;
4536 //if(!dead&&deathbleeding<=0&&id==0)bloodloss-=multiplier*4;
4538 if(damage<0)damage=0;
4539 if(permanentdamage<0)permanentdamage=0;
4540 if(superpermanentdamage<0)superpermanentdamage=0;
4541 if(permanentdamage<superpermanentdamage){
4542 permanentdamage=superpermanentdamage;
4544 if(damage<permanentdamage){
4545 damage=permanentdamage;
4547 if(dead==1&&damage<damagetolerance){
4551 for(i=0;i<skeleton.num_joints;i++){
4552 skeleton.joints[i].velocity=0;
4555 if(permanentdamage>damagetolerance&&dead!=2){
4558 if(weaponactive!=-1){
4559 weapons.owner[weaponids[0]]=-1;
4560 weapons.velocity[weaponids[0]]=velocity*scale*-.3;
4561 weapons.velocity[weaponids[0]].x+=.01;
4562 weapons.tipvelocity[weaponids[0]]=velocity*scale;
4563 weapons.missed[weaponids[0]]=1;
4564 weapons.hitsomething[weaponids[0]]=0;
4565 weapons.freetime[weaponids[0]]=0;
4566 weapons.firstfree[weaponids[0]]=1;
4567 weapons.physics[weaponids[0]]=1;
4570 weaponids[0]=weaponids[num_weapons];
4571 if(weaponstuck==num_weapons)weaponstuck=0;
4574 for(i=0;i<numplayers;i++){
4575 player[i].wentforweapon=0;
4581 if(!dead&&creature==wolftype){
4582 award_bonus(0, Wolfbonus);
4585 if(unconscioustime<.1&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=FinishedBonus||bonustime>1)&&bloodloss<damagetolerance)
4586 award_bonus(id, touchofdeath);
4587 if(id!=0&&unconscioustime>.1){
4595 emit_sound_at(breaksound, coords);
4596 /*if(id==0||findDistancefast(&coords,&viewer)<50){
4602 if(skeleton.free==1){
4603 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4606 //If knocked over, open hands and close mouth
4607 if(righthandmorphend!=0)righthandmorphness=0;
4608 righthandmorphend=0;
4609 targetrighthandmorphness=1;
4611 if(lefthandmorphend!=0)lefthandmorphness=0;
4613 targetlefthandmorphness=1;
4615 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5){
4616 if(headmorphend!=0)headmorphness=0;
4618 targetheadmorphness=1;
4622 skeleton.DoGravity(&scale);
4624 damageamount=skeleton.DoConstraints(&coords,&scale)*5;
4625 if(damage>damagetolerance-damageamount&&!dead&&(bonus!=spinecrusher||bonustime>1)&&(bonus!=style||bonustime>1)&&(bonus!=cannon||bonustime>1))
4626 award_bonus(id, deepimpact);
4627 DoDamage(damageamount/((protectionhigh+protectionhead+protectionlow)/3));
4631 for(j=0;j<skeleton.num_joints;j++){
4632 average+=skeleton.joints[j].position;
4636 coords+=average*scale;
4637 for(j=0;j<skeleton.num_joints;j++){
4638 skeleton.joints[j].position-=average;
4640 average/=multiplier;
4642 //velocity=skeleton.joints[skeleton.jointlabels[groin]].velocity*scale;
4644 for(i=0;i<skeleton.num_joints;i++){
4645 velocity+=skeleton.joints[i].velocity*scale;
4647 velocity/=skeleton.num_joints;
4649 if(!isnormal(velocity.x)&&velocity.x){
4662 if(findLength(&average)<10&&dead&&skeleton.free){
4663 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4664 if(skeleton.longdead>2000){
4665 if(skeleton.longdead>6000){
4666 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4671 if(dead==2&&bloodloss<damagetolerance){
4673 headpoint=(skeleton.joints[skeleton.jointlabels[head]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4675 if(bloodtoggle&&!bled){
4676 terrain.MakeDecal(blooddecal,headpoint,.2*1.2,.5,0);
4678 if(bloodtoggle&&!bled)
4679 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4680 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4681 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4685 objects.model[j].MakeDecal(blooddecal,&point,&size,&opacity,&rotation);
4689 if(dead==2&&bloodloss>=damagetolerance){
4691 headpoint=(skeleton.joints[skeleton.jointlabels[abdomen]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2*scale+coords;
4692 if(bleeding<=0)DoBlood(1,255);
4693 if(bloodtoggle&&!bled){
4694 terrain.MakeDecal(blooddecalslow,headpoint,.8,.5,0);
4696 if(bloodtoggle&&!bled)
4697 for(l=0;l<terrain.patchobjectnum[whichpatchx][whichpatchz];l++){
4698 j=terrain.patchobjects[whichpatchx][whichpatchz][l];
4699 XYZ point=DoRotation(headpoint-objects.position[j],0,-objects.rotation[j],0);
4703 objects.model[j].MakeDecal(blooddecalslow,&point,&size,&opacity,&rotation);
4710 if(!dead&&crouchkeydown&&skeleton.freetime>.5&&id==0&&skeleton.free){
4712 XYZ startpoint,endpoint,colpoint,colviewer,coltarget;
4716 if(terrain.lineTerrain(startpoint,endpoint,&colpoint)!=-1)canrecover=0;
4717 if(velocity.y<-30)canrecover=0;
4718 for(i=0;i<objects.numobjects;i++){
4719 if(objects.type[i]!=treeleavestype&&objects.type[i]!=bushtype&&objects.type[i]!=firetype){
4720 colviewer=startpoint;
4722 if(objects.model[i].LineCheck(&colviewer,&coltarget,&colpoint,&objects.position[i],&objects.rotation[i])!=-1)canrecover=0;
4730 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4731 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4732 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4733 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4735 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4736 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4737 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4739 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4740 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4741 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4743 Normalise(&terrainnormal);
4745 targetrotation=-asin(0-terrainnormal.x);
4746 targetrotation*=360/6.28;
4747 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4748 rotation=targetrotation;
4752 targetanimation=flipanim;
4753 crouchtogglekeydown=1;
4758 currentanimation=tempanim;
4761 //tilt2=targettilt2;
4763 //if(middle.y>0)targetoffset.y=middle.y+1;
4765 for(i=0;i<skeleton.num_joints;i++){
4766 tempanimation.position[i][0]=skeleton.joints[i].position;
4767 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4772 if(findLength(&average)<10&&!dead&&skeleton.free){
4773 skeleton.longdead+=(2000-findLength(&average))*multiplier+multiplier;
4774 if(skeleton.longdead>(damage+500)*1.5){
4775 if(id==0)OPENAL_SetPaused(channels[whooshsound], true);
4781 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4782 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[abdomen]].locked){
4783 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[abdomen]].position;
4784 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4786 if(skeleton.joints[skeleton.jointlabels[abdomen]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4787 terrainnormal=skeleton.joints[skeleton.jointlabels[abdomen]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4788 middle=(skeleton.joints[skeleton.jointlabels[neck]].position+skeleton.joints[skeleton.jointlabels[abdomen]].position)/2;
4790 if(skeleton.joints[skeleton.jointlabels[groin]].locked&&skeleton.joints[skeleton.jointlabels[neck]].locked){
4791 terrainnormal=skeleton.joints[skeleton.jointlabels[groin]].position-skeleton.joints[skeleton.jointlabels[neck]].position;
4792 middle=(skeleton.joints[skeleton.jointlabels[groin]].position+skeleton.joints[skeleton.jointlabels[neck]].position)/2;
4794 Normalise(&terrainnormal);
4796 targetrotation=-asin(0-terrainnormal.x);
4797 targetrotation*=360/6.28;
4798 if(terrainnormal.z<0)targetrotation=180-targetrotation;
4799 rotation=targetrotation;
4802 terrainnormal=terrain.getNormal(coords.x,coords.z);
4803 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4807 /*XYZ otherterrainnormal;
4808 otherterrainnormal=terrain.getNormal(coords.x,coords.y);
4809 otherterrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4810 if(abs(terrainnormal.y)<abs(otherterrainnormal.y))terrainnormal.y=fast_sqrt(otherterrainnormal.x*otherterrainnormal.x+otherterrainnormal.z*otherterrainnormal.z)*-1;
4811 targettilt2=asin(otherterrainnormal.y)*180/3.14;
4814 targettilt2=asin(terrainnormal.y)*180/3.14*-1;
4818 if(skeleton.forward.y<0){
4819 targetanimation=getupfrombackanim;
4823 if(skeleton.forward.y>-.3){
4824 targetanimation=getupfromfrontanim;
4826 targetrotation+=180;
4832 if((Random()%8==0&&id!=0&&creature==rabbittype)||(Random()%2==0&&id!=0&&creature==wolftype)||(id==0&&crouchkeydown&&(forwardkeydown||backkeydown||leftkeydown||rightkeydown))){
4833 targetanimation=rollanim;
4834 targetrotation=lookrotation;
4838 if(forwardkeydown)targetrotation+=45;
4839 if(backkeydown)targetrotation-=45;
4843 if(forwardkeydown)targetrotation-=45;
4844 if(backkeydown)targetrotation+=45;
4847 if ( !leftkeydown&&!rightkeydown)
4848 targetrotation+=180;
4850 targetrotation+=180;
4854 if(abs(targettilt2)>50)targettilt2=0;
4855 currentanimation=tempanim;
4860 if(middle.y>0&&targetanimation!=rollanim)targetoffset.y=middle.y+1;
4862 for(i=0;i<skeleton.num_joints;i++){
4863 tempanimation.position[i][0]=skeleton.joints[i].position;
4864 tempanimation.position[i][0]=DoRotation(tempanimation.position[i][0],0,-rotation,0);
4871 if(num_weapons>0)if(weapons.type[0]==staff)hasstaff=1;
4872 if(!skeleton.freefall&&freefall&&((jumpkeydown&&jumpkeydowntime<.2)||(hasstaff&&rabbitkickragdoll))&&!dead){
4875 tempvelocity=velocity;
4876 Normalise(&tempvelocity);
4877 targetrotation=-asin(0-tempvelocity.x);
4878 targetrotation*=360/6.28;
4879 if(velocity.z<0)targetrotation=180-targetrotation;
4880 //targetrotation+=180;
4883 if(dotproduct(&skeleton.forward,&tempvelocity)<0){
4884 targetanimation=rollanim;
4888 targetanimation=backhandspringanim;
4889 targetrotation+=180;
4894 emit_sound_at(movewhooshsound, coords, 128.);
4896 currentanimation=targetanimation;
4897 currentframe=targetframe-1;
4902 rotation=targetrotation;
4909 if(skeleton.freefall==0)freefall=0;
4911 if(!isnormal(velocity.x)&&velocity.x){
4916 if(aitype!=passivetype||skeleton.free==1)
4917 if(findLengthfast(&velocity)>.1)
4918 for(i=0;i<objects.numobjects;i++){
4919 if(objects.type[i]==firetype)
4920 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){
4922 if(!objects.onfire[i]){
4923 emit_sound_at(firestartsound, objects.position[i]);
4925 objects.onfire[i]=1;
4928 if(objects.onfire[i]){
4933 if(objects.type[i]==bushtype)
4934 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){
4936 if(!objects.onfire[i]){
4937 emit_sound_at(firestartsound, objects.position[i]);
4939 objects.onfire[i]=1;
4943 if(objects.onfire[i]){
4947 if(objects.messedwith[i]<=0){
4951 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
4954 envsound[numenvsounds]=coords;
4955 envsoundvol[numenvsounds]=4*findLength(&velocity);
4956 envsoundlife[numenvsounds]=.4;
4961 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
4962 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
4964 if(environment!=desertenvironment)
4965 for(j=0;j<howmany;j++){
4966 tempvel.x=float(abs(Random()%100)-50)/20;
4967 tempvel.y=float(abs(Random()%100)-50)/20;
4968 tempvel.z=float(abs(Random()%100)-50)/20;
4971 pos.x+=float(abs(Random()%100)-50)/200;
4972 pos.y+=float(abs(Random()%100)-50)/200;
4973 pos.z+=float(abs(Random()%100)-50)/200;
4974 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);
4975 Sprite::setLastSpriteSpecial(1);
4977 howmany=findLength(&velocity)*4;
4979 if(environment==snowyenvironment)
4980 for(j=0;j<howmany;j++){
4981 tempvel.x=float(abs(Random()%100)-50)/20;
4982 tempvel.y=float(abs(Random()%100)-50)/20;
4983 tempvel.z=float(abs(Random()%100)-50)/20;
4986 pos.x+=float(abs(Random()%100)-50)/200;
4987 pos.y+=float(abs(Random()%100)-50)/200;
4988 pos.z+=float(abs(Random()%100)-50)/200;
4989 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
4990 Sprite::setLastSpriteSpecial(2);
4993 objects.rotx[i]+=velocity.x*multiplier*6;
4994 objects.roty[i]+=velocity.z*multiplier*6;
4995 objects.messedwith[i]=.5;
4998 if(objects.type[i]==treeleavestype&&environment!=desertenvironment){
4999 if(objects.rotation2[i]==0)tempcoord=coords;
5001 tempcoord=coords-objects.position[i];
5002 tempcoord=DoRotation(tempcoord,0,-objects.rotation[i],0);
5003 tempcoord=DoRotation(tempcoord,-objects.rotation2[i],0,0);
5004 tempcoord+=objects.position[i];
5006 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]){
5007 if(objects.messedwith[i]<=0){
5011 emit_sound_at(bushrustle, coords, 40*findLength(&velocity));
5014 envsound[numenvsounds]=coords;
5015 envsoundvol[numenvsounds]=4*findLength(&velocity);
5016 envsoundlife[numenvsounds]=.4;
5021 if(environment==grassyenvironment)howmany=findLength(&velocity)*4;
5022 if(environment==snowyenvironment)howmany=findLength(&velocity)*2;
5024 if(environment!=desertenvironment)
5025 for(j=0;j<howmany;j++){
5026 tempvel.x=float(abs(Random()%100)-50)/20;
5027 tempvel.y=float(abs(Random()%100)-50)/20;
5028 tempvel.z=float(abs(Random()%100)-50)/20;
5032 pos.x+=float(abs(Random()%100)-50)/150;
5033 pos.y+=float(abs(Random()%100)-50)/150;
5034 pos.z+=float(abs(Random()%100)-50)/150;
5035 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);
5036 Sprite::setLastSpriteSpecial(1);
5038 howmany=findLength(&velocity)*4;
5040 if(environment==snowyenvironment)
5041 for(j=0;j<howmany;j++){
5042 tempvel.x=float(abs(Random()%100)-50)/20;
5043 tempvel.y=float(abs(Random()%100)-50)/20;
5044 tempvel.z=float(abs(Random()%100)-50)/20;
5048 pos.x+=float(abs(Random()%100)-50)/150;
5049 pos.y+=float(abs(Random()%100)-50)/150;
5050 pos.z+=float(abs(Random()%100)-50)/150;
5051 Sprite::MakeSprite(splintersprite, pos,tempvel*.3+velocity*float(abs(Random()%100))/100/2, 1,1,1, .1, 1);
5052 Sprite::setLastSpriteSpecial(2);
5055 objects.messedwith[i]=.5;
5063 if((stunned>0||surprised>0)&&numplayers>2&&aitype!=passivetype)play=1;
5065 if(aitype!=passivetype&&victim->skeleton.free&&!victim->dead)play=1;
5066 if(tutoriallevel==1&&id!=0)play=0;
5067 if(play&&aitype!=playercontrolled){
5071 if(creature==rabbittype){
5072 if(i==0)whichsound=rabbitchitter;
5073 if(i==1)whichsound=rabbitchitter2;
5075 if(creature==wolftype){
5076 if(i==0)whichsound=growlsound;
5077 if(i==1)whichsound=growl2sound;
5083 emit_sound_at(whichsound, coords);
5087 if(targetanimation==staggerbackhighanim)staggerdelay=1;
5088 if(targetanimation==staggerbackhardanim)staggerdelay=1;
5089 staggerdelay-=multiplier;
5090 if(targetanimation!=crouchstabanim&&targetanimation!=swordgroundstabanim&&targetanimation!=staffgroundsmashanim)hasvictim=1;
5091 if(velocity.y<-30&&targetanimation==jumpdownanim)RagDoll(0);
5092 if(currentanimation!=getIdle()&&wasIdle()&&targetanimation!=getIdle()&&isIdle()){
5093 targetanimation=getIdle();
5097 weaponmissdelay-=multiplier;
5098 highreversaldelay-=multiplier;
5099 lowreversaldelay-=multiplier;
5100 lastcollide-=multiplier;
5101 skiddelay-=multiplier;
5102 if(!isnormal(velocity.x)&&velocity.x){
5105 if(!isnormal(targettilt)&&targettilt){
5108 if(!isnormal(targettilt2)&&targettilt2){
5111 if(!isnormal(targetrotation)&&targetrotation){
5115 if(targetanimation==bounceidleanim||targetanimation==wolfidle||targetanimation==walkanim||targetanimation==drawrightanim||targetanimation==crouchdrawrightanim||targetanimation==drawleftanim||targetanimation==fightidleanim||targetanimation==fightsidestep||targetanimation==hanganim||isCrouch()||targetanimation==backhandspringanim){
5116 //open hands and close mouth
5117 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5118 righthandmorphness=0;
5119 righthandmorphend=0;
5120 targetrighthandmorphness=1;
5123 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5124 lefthandmorphness=0;
5126 targetlefthandmorphness=1;
5129 if(headmorphend!=3&&headmorphend!=5&&headmorphstart!=3&&headmorphstart!=5&&headmorphend!=0&&headmorphness==targetheadmorphness){
5132 targetheadmorphness=1;
5136 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){
5137 //open hands and mouth
5138 if(righthandmorphend!=0&&righthandmorphness==targetrighthandmorphness){
5139 righthandmorphness=0;
5140 righthandmorphend=0;
5141 targetrighthandmorphness=1;
5144 if(lefthandmorphend!=0&&lefthandmorphness==targetlefthandmorphness){
5145 lefthandmorphness=0;
5147 targetlefthandmorphness=1;
5150 if(headmorphend!=1&&headmorphness==targetheadmorphness){
5153 targetheadmorphness=1;
5157 if(targetanimation==jumpupanim||targetanimation==crouchstabanim||targetanimation==swordgroundstabanim||targetanimation==swordfightidlebothanim||targetanimation==blockhighleftanim||targetanimation==blockhighleftanim){
5158 //close hands and mouth
5159 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5160 righthandmorphness=0;
5161 righthandmorphend=1;
5162 targetrighthandmorphness=1;
5165 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5166 lefthandmorphness=0;
5168 targetlefthandmorphness=1;
5171 if(headmorphend!=0&&headmorphness==targetheadmorphness){
5174 targetheadmorphness=1;
5178 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){
5179 //close hands and yell
5180 if(righthandmorphend!=1&&righthandmorphness==targetrighthandmorphness){
5181 righthandmorphness=0;
5182 righthandmorphend=1;
5183 targetrighthandmorphness=1;
5186 if(lefthandmorphend!=1&&lefthandmorphness==targetlefthandmorphness){
5187 lefthandmorphness=0;
5189 targetlefthandmorphness=1;
5192 if(headmorphend!=2&&headmorphness==targetheadmorphness){
5195 targetheadmorphness=1;
5199 if(speechdelay>.25){
5200 if(headmorphend!=2)headmorphness=0;
5202 targetheadmorphness=1;
5208 if(victim!=this&&!victim->dead&&victim->aitype!=passivetype&&victim->aitype!=searchtype&&aitype!=passivetype&&aitype!=searchtype&&victim->id<numplayers&&aitype!=passivetype){
5209 behind=(normaldotproduct(facing,coords-victim->coords)>0);
5213 if(!dead&&targetanimation!=hurtidleanim)
5214 if(behind||targetanimation==killanim||targetanimation==knifethrowanim||targetanimation==knifefollowanim||targetanimation==spinkickreversalanim||targetanimation==rabbitkickreversedanim||targetanimation==jumpreversedanim){
5215 if(headmorphend!=4||headmorphness==targetheadmorphness){
5218 targetheadmorphness=1;
5222 if(weaponactive!=-1){
5223 if(weapons.type[weaponids[weaponactive]]!=staff){
5224 righthandmorphstart=1;
5225 righthandmorphend=1;
5227 if(weapons.type[weaponids[weaponactive]]==staff){
5228 righthandmorphstart=2;
5229 righthandmorphend=2;
5231 targetrighthandmorphness=1;
5234 terrainnormal=terrain.getNormal(coords.x,coords.z);
5236 if(animation[targetanimation].attack!=reversal){
5237 if(!isnormal(coords.x))
5245 flatfacing=DoRotation(flatfacing,0,rotation,0);
5247 ReflectVector(&facing,terrainnormal);
5250 if(isRun()||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim){
5251 if(onterrain)targettilt2=-facing.y*20;
5255 if(!isRun()&&!animation[targetanimation].attack&&targetanimation!=getupfromfrontanim&&targetanimation!=getupfrombackanim&&targetanimation!=sneakanim)targettilt2=0;
5256 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5257 flatvelocity=velocity;
5259 flatvelspeed=findLength(&flatvelocity);
5260 targettilt=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(DoRotation(flatfacing,0,-90,0),flatvelocity);
5261 targettilt2=flatvelspeed*fast_sqrt(abs(velocity.y)*.7)*normaldotproduct(flatfacing,flatvelocity);
5262 if(velocity.y<0)targettilt2*=-1;
5263 if(velocity.y<0)targettilt*=-1;
5264 if(targettilt>25)targettilt=25;
5265 if(targettilt<-25)targettilt=-25;
5268 if(targettilt2>45)targettilt2=45;
5269 if(targettilt2<-45)targettilt2=-45;
5270 if(abs(tilt2-targettilt2)<multiplier*400)tilt2=targettilt2;
5271 else if(tilt2>targettilt2){
5272 tilt2-=multiplier*400;
5274 else if(tilt2<targettilt2){
5275 tilt2+=multiplier*400;
5277 if(!animation[targetanimation].attack&&targetanimation!=getupfrombackanim&&targetanimation!=getupfromfrontanim){
5278 if(tilt2>25)tilt2=25;
5279 if(tilt2<-25)tilt2=-25;
5282 if(!isnormal(targettilt)&&targettilt){
5285 if(!isnormal(targettilt2)&&targettilt2){
5290 //if(!creature==wolftype||targetanimation==rabbitkickanim)
5291 if(targetanimation==rabbittackleanim){
5292 velocity+=facing*multiplier*speed*700*scale;
5293 velspeed=findLength(&velocity);
5294 if(velspeed>speed*65*scale){
5296 velspeed=speed*65*scale;
5299 velocity.y+=gravity*multiplier*20;
5300 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5301 velspeed=findLength(&velocity);
5302 velocity=flatfacing*velspeed;
5304 if(targetanimation!=rabbitrunninganim&&targetanimation!=wolfrunninganim){
5305 if(isRun()||targetanimation==rabbitkickanim){
5306 velocity+=facing*multiplier*speed*700*scale;
5307 velspeed=findLength(&velocity);
5308 if(velspeed>speed*45*scale){
5310 velspeed=speed*45*scale;
5313 velocity.y+=gravity*multiplier*20;
5314 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5315 velspeed=findLength(&velocity);
5316 if(velspeed<speed*30*scale)velspeed=speed*30*scale;
5317 velocity=flatfacing*velspeed;
5321 velocity+=facing*multiplier*speed*700*scale;
5322 velspeed=findLength(&velocity);
5323 if(creature==rabbittype){
5324 if(velspeed>speed*55*scale){
5326 velspeed=speed*55*scale;
5330 if(creature==wolftype){
5331 if(velspeed>speed*75*scale){
5333 velspeed=speed*75*scale;
5337 velocity.y+=gravity*multiplier*20;
5338 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5339 velspeed=findLength(&velocity);
5340 velocity=flatfacing*velspeed;
5343 if(targetanimation==rollanim&&animation[targetanimation].label[targetframe]!=6){
5344 velocity+=facing*multiplier*speed*700*scale;
5345 velspeed=findLength(&velocity);
5346 if(velspeed>speed*45*scale){
5348 velspeed=speed*45*scale;
5351 velocity.y+=gravity*multiplier*20;
5352 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5353 velspeed=findLength(&velocity);
5354 velocity=flatfacing*velspeed;
5358 /*if(currentanimation==rollanim&&(isCrouch()||isIdle())){
5359 velocity+=facing*multiplier*speed*700*scale;
5360 velspeed=findLength(&velocity);
5361 if(velspeed>speed*25*scale){
5363 velspeed=speed*25*scale;
5366 velocity.y+=gravity*multiplier*20;
5367 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5368 velspeed=findLength(&velocity);
5369 velocity=flatfacing*velspeed;
5372 if(targetanimation==sneakanim||targetanimation==walkanim){
5373 velocity+=facing*multiplier*speed*700*scale;
5374 velspeed=findLength(&velocity);
5375 if(velspeed>speed*12*scale){
5377 velspeed=speed*12*scale;
5380 velocity.y+=gravity*multiplier*20;
5381 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5382 velspeed=findLength(&velocity);
5383 velocity=flatfacing*velspeed;
5386 if((targetanimation==fightidleanim||targetanimation==knifefightidleanim)&&(currentanimation==bounceidleanim||currentanimation==hurtidleanim)){
5387 velocity+=facing*multiplier*speed*700*scale;
5388 velspeed=findLength(&velocity);
5389 if(velspeed>speed*2*scale){
5391 velspeed=speed*2*scale;
5394 velocity.y+=gravity*multiplier*20;
5395 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5396 velspeed=findLength(&velocity);
5397 velocity=flatfacing*velspeed;
5401 if((targetanimation==bounceidleanim||currentanimation==hurtidleanim)&&(currentanimation==fightidleanim||currentanimation==knifefightidleanim)){
5402 velocity-=facing*multiplier*speed*700*scale;
5403 velspeed=findLength(&velocity);
5404 if(velspeed>speed*2*scale){
5406 velspeed=speed*2*scale;
5409 velocity.y+=gravity*multiplier*20;
5410 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5411 velspeed=findLength(&velocity);
5412 velocity=flatfacing*velspeed*-1;
5415 if(targetanimation==fightsidestep){
5416 velocity+=DoRotation(facing*multiplier*speed*700*scale,0,-90,0);
5417 velspeed=findLength(&velocity);
5418 if(velspeed>speed*12*scale){
5420 velspeed=speed*12*scale;
5423 velocity.y+=gravity*multiplier*20;
5424 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5425 velspeed=findLength(&velocity);
5426 velocity=DoRotation(flatfacing*velspeed,0,-90,0);
5429 if(targetanimation==staggerbackhighanim){
5430 coords-=facing*multiplier*speed*16*scale;
5433 if(targetanimation==staggerbackhardanim&&animation[staggerbackhardanim].label[targetframe]!=6){
5434 coords-=facing*multiplier*speed*20*scale;
5438 if(targetanimation==backhandspringanim){
5439 //coords-=facing*multiplier*50*scale;
5440 velocity+=facing*multiplier*speed*700*scale*-1;
5441 velspeed=findLength(&velocity);
5442 if(velspeed>speed*50*scale){
5444 velspeed=speed*50*scale;
5447 velocity.y+=gravity*multiplier*20;
5448 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5449 velspeed=findLength(&velocity);
5450 velocity=flatfacing*velspeed*-1;
5452 if(targetanimation==dodgebackanim){
5453 //coords-=facing*multiplier*50*scale;
5454 velocity+=facing*multiplier*speed*700*scale*-1;
5455 velspeed=findLength(&velocity);
5456 if(velspeed>speed*60*scale){
5458 velspeed=speed*60*scale;
5461 velocity.y+=gravity*multiplier*20;
5462 ReflectVector(&velocity,terrain.getNormal(coords.x,coords.z));
5463 velspeed=findLength(&velocity);
5464 velocity=flatfacing*velspeed*-1;
5467 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5468 velspeed=findLength(&velocity);
5472 if(targetanimation==jumpupanim||targetanimation==jumpdownanim||isFlip()){
5473 velocity.y+=gravity*multiplier;
5476 if(targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords+=velocity*multiplier;
5478 if(coords.y<terrain.getHeight(coords.x,coords.z)&&(targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
5479 if(isFlip()&&animation[targetanimation].label[targetframe]==7)RagDoll(0);
5481 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
5487 OPENAL_SetPaused(channels[whooshsound], true);
5488 OPENAL_SetVolume(channels[whooshsound], 0);
5491 if(targetanimation==jumpdownanim||isFlip()){
5492 if(isFlip())jumppower=-4;
5493 targetanimation=getLanding();
5494 emit_sound_at(landsound, coords, 128.);
5497 envsound[numenvsounds]=coords;
5498 envsoundvol[numenvsounds]=16;
5499 envsoundlife[numenvsounds]=.4;
5505 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&targetanimation!=climbanim&&targetanimation!=hanganim&&!isWallJump())coords.y+=gravity*multiplier*2;
5506 if(targetanimation!=jumpupanim&&targetanimation!=jumpdownanim&&!isFlip()&&coords.y<terrain.getHeight(coords.x,coords.z)){
5507 coords.y=terrain.getHeight(coords.x,coords.z);
5512 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)){
5513 velspeed=findLength(&velocity);
5515 if(velspeed<multiplier*300*scale){
5517 } else velocity-=velocity/velspeed*multiplier*300*scale;
5518 if(velspeed>5&&(isLanding()||isLandhard())){
5519 skiddingdelay+=multiplier;
5526 else skiddingdelay=0;
5530 velspeed=findLength(&velocity);
5532 if(velspeed<multiplier*600*scale){
5534 } else velocity-=velocity/velspeed*multiplier*600*scale;
5536 if(velspeed>5&&(isLanding()||isLandhard())){
5537 skiddingdelay+=multiplier;
5544 else skiddingdelay=0;
5547 if(skiddingdelay<0)skiddingdelay+=multiplier;
5548 if(skiddingdelay>.02&&!forwardkeydown&&!backkeydown&&!leftkeydown&&!rightkeydown&&!jumpkeydown&&isLanding()&&!landhard){
5550 if(!onterrain||environment==grassyenvironment){
5551 emit_sound_at(skidsound, coords, 128*velspeed/10);
5554 emit_sound_at(snowskidsound, coords, 128*velspeed/10);
5558 if(animation[targetanimation].attack==normalattack&&targetanimation!=rabbitkickanim&&!victim->skeleton.free){
5559 terrainnormal=victim->coords-coords;
5560 Normalise(&terrainnormal);
5561 targetrotation=-asin(0-terrainnormal.x);
5562 targetrotation*=360/6.28;
5563 if(terrainnormal.z<0)targetrotation=180-targetrotation;
5564 targettilt2=-asin(terrainnormal.y)*360/6.28;//*-70;
5567 if(animation[targetanimation].attack==reversal&&targetanimation!=rabbittacklinganim){
5568 targetrotation=victim->targetrotation;
5570 if(targetanimation==rabbittacklinganim){
5571 coords=victim->coords;
5574 skeleton.oldfree=skeleton.free;
5578 midterrain.x=terrain.size*terrain.scale/2;
5579 midterrain.z=terrain.size*terrain.scale/2;
5580 if(findDistancefastflat(&coords,&midterrain)>(terrain.size*terrain.scale/2-viewdistance)*(terrain.size*terrain.scale/2-viewdistance)){
5582 tempposit=coords-midterrain;
5584 Normalise(&tempposit);
5585 tempposit*=(terrain.size*terrain.scale/2-viewdistance);
5586 coords.x=tempposit.x+midterrain.x;
5587 coords.z=tempposit.z+midterrain.z;
5591 int Person::DrawSkeleton(){
5592 int oldplayerdetail;
5593 if((frustum.SphereInFrustum(coords.x,coords.y+scale*3,coords.z,scale*8)&&findDistancefast(&viewer,&coords)<viewdistance*viewdistance)||skeleton.free==3){
5594 if(onterrain&&(isIdle()||isCrouch()||wasIdle()||wasCrouch())&&!skeleton.free){
5604 glAlphaFunc(GL_GREATER, 0.0001);
5606 float terrainheight;
5608 if(!isnormal(rotation))rotation=0;
5609 if(!isnormal(tilt))tilt=0;
5610 if(!isnormal(tilt2))tilt2=0;
5611 oldplayerdetail=playerdetail;
5613 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/32&&detail==2){
5616 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/128&&detail==1){
5619 if(findDistancefast(&viewer,&coords)<viewdistance*viewdistance/256&&(detail!=1&&detail!=2)){
5624 if(playerdetail!=oldplayerdetail) {
5626 normalsupdatedelay=0;
5628 static float updatedelaychange;
5629 static float morphness;
5630 static float framemult;
5632 skeleton.FindForwards();
5633 if(howactive==typesittingwall){
5634 skeleton.specialforward[1]=0;
5635 skeleton.specialforward[1].z=1;
5641 static int weaponattachmuscle;
5642 static int weaponrotatemuscle,weaponrotatemuscle2;
5643 static XYZ weaponpoint;
5644 static int start,endthing;
5645 if((dead!=2||skeleton.free!=2)&&updatedelay<=0){
5646 if(!isSleeping()&&!isSitting()){
5647 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5648 XYZ point,newpoint,change,change2;
5649 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5650 heightleft=terrain.getHeight(point.x,point.z)+.04;
5652 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5653 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5654 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5655 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5656 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5658 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5659 heightright=terrain.getHeight(point.x,point.z)+.04;
5660 point.y=heightright;
5661 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5662 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5663 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0);
5664 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5665 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5666 skeleton.DoConstraints(&coords,&scale);
5668 if(creature==wolftype){
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);
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);
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);
5689 if(onterrain&&((isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&!(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5690 XYZ point,newpoint,change,change2;
5691 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5692 heightleft=terrain.getHeight(point.x,point.z)+.04;
5694 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5695 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5696 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5697 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5698 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5700 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5701 heightright=terrain.getHeight(point.x,point.z)+.04;
5702 point.y=heightright;
5703 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5704 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5705 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5706 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5707 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5708 skeleton.DoConstraints(&coords,&scale);
5710 if(creature==wolftype){
5711 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5712 heightleft=terrain.getHeight(point.x,point.z)+.04;
5714 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5715 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5716 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[leftfoot]].position*(1-target);
5717 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5718 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5720 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5721 heightright=terrain.getHeight(point.x,point.z)+.04;
5722 point.y=heightright;
5723 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5724 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5725 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*target+skeleton.joints[skeleton.jointlabels[rightfoot]].position*(1-target);
5726 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5727 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5728 skeleton.DoConstraints(&coords,&scale);
5732 if(onterrain&&(!(isIdle()||isCrouch()||isLanding()||isLandhard()||targetanimation==drawrightanim||targetanimation==drawleftanim||targetanimation==crouchdrawrightanim)&&(wasIdle()||wasCrouch()||wasLanding()||wasLandhard()||currentanimation==drawrightanim||currentanimation==drawleftanim||currentanimation==crouchdrawrightanim))&&!skeleton.free){
5733 XYZ point,newpoint,change,change2;
5734 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5735 heightleft=terrain.getHeight(point.x,point.z)+.04;
5737 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5738 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5739 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5740 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5741 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5743 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5744 heightright=terrain.getHeight(point.x,point.z)+.04;
5745 point.y=heightright;
5746 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5747 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5748 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5749 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5750 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5751 skeleton.DoConstraints(&coords,&scale);
5753 if(creature==wolftype){
5754 point=DoRotation(skeleton.joints[skeleton.jointlabels[leftfoot]].position,0,rotation,0)*scale+coords;
5755 heightleft=terrain.getHeight(point.x,point.z)+.04;
5757 change=skeleton.joints[skeleton.jointlabels[leftankle]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5758 change2=skeleton.joints[skeleton.jointlabels[leftknee]].position-skeleton.joints[skeleton.jointlabels[leftfoot]].position;
5759 skeleton.joints[skeleton.jointlabels[leftfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[leftfoot]].position*target;
5760 skeleton.joints[skeleton.jointlabels[leftankle]].position=skeleton.joints[skeleton.jointlabels[leftfoot]].position+change;
5761 skeleton.joints[skeleton.jointlabels[leftknee]].position=(skeleton.joints[skeleton.jointlabels[leftfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[leftknee]].position)/2;
5763 point=DoRotation(skeleton.joints[skeleton.jointlabels[rightfoot]].position,0,rotation,0)*scale+coords;
5764 heightright=terrain.getHeight(point.x,point.z)+.04;
5765 point.y=heightright;
5766 change=skeleton.joints[skeleton.jointlabels[rightankle]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5767 change2=skeleton.joints[skeleton.jointlabels[rightknee]].position-skeleton.joints[skeleton.jointlabels[rightfoot]].position;
5768 skeleton.joints[skeleton.jointlabels[rightfoot]].position=DoRotation((point-coords)/scale,0,-rotation,0)*(1-target)+skeleton.joints[skeleton.jointlabels[rightfoot]].position*target;
5769 skeleton.joints[skeleton.jointlabels[rightankle]].position=skeleton.joints[skeleton.jointlabels[rightfoot]].position+change;
5770 skeleton.joints[skeleton.jointlabels[rightknee]].position=(skeleton.joints[skeleton.jointlabels[rightfoot]].position+change2)/2+(skeleton.joints[skeleton.jointlabels[rightknee]].position)/2;
5771 skeleton.DoConstraints(&coords,&scale);
5775 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()))
5778 targetheadrotation=-targetrotation;
5779 targetheadrotation2=0;
5780 if(animation[targetanimation].attack==3)targetheadrotation+=180;
5782 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
5783 skeleton.drawmodel.vertex[i]=0;
5784 skeleton.drawmodel.vertex[i].y=999;
5786 for(i=0;i<skeleton.drawmodellow.vertexNum;i++){
5787 skeleton.drawmodellow.vertex[i]=0;
5788 skeleton.drawmodellow.vertex[i].y=999;
5790 for(i=0;i<skeleton.drawmodelclothes.vertexNum;i++){
5791 skeleton.drawmodelclothes.vertex[i]=0;
5792 skeleton.drawmodelclothes.vertex[i].y=999;
5794 for(i=0;i<skeleton.num_muscles;i++){
5795 if((skeleton.muscles[i].numvertices>0&&playerdetail)||(skeleton.muscles[i].numverticeslow>0&&!playerdetail)){
5799 if(skeleton.muscles[i].parent1->label==righthand||skeleton.muscles[i].parent2->label==righthand){
5800 morphness=righthandmorphness;
5801 start=righthandmorphstart;
5802 endthing=righthandmorphend;
5804 if(skeleton.muscles[i].parent1->label==lefthand||skeleton.muscles[i].parent2->label==lefthand){
5805 morphness=lefthandmorphness;
5806 start=lefthandmorphstart;
5807 endthing=lefthandmorphend;
5809 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head){
5810 morphness=headmorphness;
5811 start=headmorphstart;
5812 endthing=headmorphend;
5814 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)){
5815 morphness=chestmorphness;
5816 start=chestmorphstart;
5817 endthing=chestmorphend;
5819 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)){
5820 morphness=tailmorphness;
5821 start=tailmorphstart;
5822 endthing=tailmorphend;
5824 if(calcrot)skeleton.FindRotationMuscle(i,targetanimation);
5825 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5826 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5829 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5830 if(!skeleton.free)glRotatef(tilt,0,0,1);
5833 glTranslatef(mid.x,mid.y,mid.z);
5835 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5836 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5838 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5839 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5841 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5842 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5844 if(!isnormal(proportionbody.x)||!isnormal(proportionbody.y)||!isnormal(proportionbody.z)){
5848 if(!isnormal(proportionarms.x)||!isnormal(proportionarms.y)||!isnormal(proportionarms.z)){
5852 if(!isnormal(proportionhead.x)||!isnormal(proportionhead.y)||!isnormal(proportionhead.z)){
5856 if(!isnormal(proportionlegs.x)||!isnormal(proportionlegs.y)||!isnormal(proportionlegs.z)){
5861 if(playerdetail||skeleton.free==3)
5863 for(j=0;j<skeleton.muscles[i].numvertices;j++)
5865 /*if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[0]=1;
5866 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[1]=1;
5867 if(!isnormal(skeleton.model[start].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[2]=1;
5868 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].x))vertexweird[3]=1;
5869 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].y))vertexweird[4]=1;
5870 if(!isnormal(skeleton.model[endthing].vertex[skeleton.muscles[i].vertices[j]].z))vertexweird[5]=1;
5871 if(skeleton.muscles[i].vertices[j]<skeleton.model[start].vertexNum&&skeleton.muscles[i].vertices[j]>=0){*/
5872 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5874 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5875 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,
5876 (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,
5877 (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);
5878 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)
5879 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,
5880 (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,
5881 (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);
5882 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)
5883 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,
5884 (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,
5885 (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);
5886 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5887 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,
5888 (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,
5889 (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);
5890 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5891 //if(!isnormal(M[12])||!isnormal(M[13])||!isnormal(M[14]))test=0;
5892 //if(!isnormal(scale))test=1;
5893 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].x=M[12]*scale;
5894 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].y=M[13]*scale;
5895 skeleton.drawmodel.vertex[skeleton.muscles[i].vertices[j]].z=M[14]*scale;
5900 if(!playerdetail||skeleton.free==3)
5902 for(j=0;j<skeleton.muscles[i].numverticeslow;j++)
5904 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5906 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5907 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionbody.x,
5908 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionbody.y,
5909 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionbody.z);
5910 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)
5911 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionarms.x,
5912 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionarms.y,
5913 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionarms.z);
5914 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)
5915 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionlegs.x,
5916 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionlegs.y,
5917 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionlegs.z);
5918 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5919 glTranslatef((skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].x)*proportionhead.x,
5920 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].y)*proportionhead.y,
5921 (skeleton.modellow.vertex[skeleton.muscles[i].verticeslow[j]].z)*proportionhead.z);
5923 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5924 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].x=M[12]*scale;
5925 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].y=M[13]*scale;
5926 skeleton.drawmodellow.vertex[skeleton.muscles[i].verticeslow[j]].z=M[14]*scale;
5932 if(skeleton.clothes&&skeleton.muscles[i].numverticesclothes>0){
5933 mid=(skeleton.muscles[i].parent1->position+skeleton.muscles[i].parent2->position)/2;
5935 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5938 if(!skeleton.free)glRotatef(tilt2,1,0,0);
5939 if(!skeleton.free)glRotatef(tilt,0,0,1);
5940 glTranslatef(mid.x,mid.y,mid.z);
5941 skeleton.muscles[i].lastrotate1=skeleton.muscles[i].rotate1;
5942 glRotatef(-skeleton.muscles[i].lastrotate1+90,0,1,0);
5944 skeleton.muscles[i].lastrotate2=skeleton.muscles[i].rotate2;
5945 glRotatef(-skeleton.muscles[i].lastrotate2+90,0,0,1);
5947 skeleton.muscles[i].lastrotate3=skeleton.muscles[i].rotate3;
5948 glRotatef(-skeleton.muscles[i].lastrotate3,0,1,0);
5950 for(j=0;j<skeleton.muscles[i].numverticesclothes;j++){
5951 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
5953 if(skeleton.muscles[i].parent1->label==abdomen||skeleton.muscles[i].parent2->label==abdomen)
5954 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionbody.x,
5955 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionbody.y,
5956 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionbody.z);
5957 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)
5958 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionarms.x,
5959 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionarms.y,
5960 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionarms.z);
5961 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)
5962 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionlegs.x,
5963 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionlegs.y,
5964 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionlegs.z);
5965 if(skeleton.muscles[i].parent1->label==head||skeleton.muscles[i].parent2->label==head)
5966 glTranslatef((skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x)*proportionhead.x,
5967 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y)*proportionhead.y,
5968 (skeleton.modelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z)*proportionhead.z);
5969 glGetFloatv(GL_MODELVIEW_MATRIX,M);
5970 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].x=M[12]*scale;
5971 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].y=M[13]*scale;
5972 skeleton.drawmodelclothes.vertex[skeleton.muscles[i].verticesclothes[j]].z=M[14]*scale;
5977 updatedelay=1+(float)(Random()%100)/1000;
5979 if(skeleton.free!=2&&(skeleton.free==1||skeleton.free==3||id==0||(normalsupdatedelay<=0)||targetanimation==getupfromfrontanim||targetanimation==getupfrombackanim||currentanimation==getupfromfrontanim||currentanimation==getupfrombackanim)){
5980 normalsupdatedelay=1;
5981 if(playerdetail||skeleton.free==3)skeleton.drawmodel.CalculateNormals(0);
5982 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.CalculateNormals(0);
5983 if(skeleton.clothes)skeleton.drawmodelclothes.CalculateNormals(0);
5987 if(playerdetail||skeleton.free==3)skeleton.drawmodel.UpdateVertexArrayNoTexNoNorm();
5988 if(!playerdetail||skeleton.free==3)skeleton.drawmodellow.UpdateVertexArrayNoTexNoNorm();
5989 if(skeleton.clothes){
5990 skeleton.drawmodelclothes.UpdateVertexArrayNoTexNoNorm();
5995 updatedelaychange=-framemult*4*(45-findDistance(&viewer,&coords)*1);
5996 if(updatedelaychange>-realmultiplier*30)updatedelaychange=-realmultiplier*30;
5997 if(updatedelaychange>-framemult*4)updatedelaychange=-framemult*4;
5998 if(skeleton.free==1)updatedelaychange*=6;
5999 if(id==0)updatedelaychange*=8;
6000 updatedelay+=updatedelaychange;
6002 glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
6004 if(!skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
6005 if(skeleton.free)glTranslatef(coords.x,coords.y-.02,coords.z);
6006 if(!skeleton.free)glTranslatef(offset.x*scale,offset.y*scale,offset.z*scale);
6007 if(!skeleton.free)glRotatef(rotation,0,1,0);
6010 glColor4f(.4,1,.4,1);
6011 glDisable(GL_LIGHTING);
6012 glDisable(GL_TEXTURE_2D);
6015 for(i=0;i<skeleton.drawmodel.vertexNum;i++){
6016 glVertex3f(skeleton.drawmodel.vertex[i].x,skeleton.drawmodel.vertex[i].y,skeleton.drawmodel.vertex[i].z);
6022 for(i=0;i<skeleton.drawmodel.TriangleNum;i++){
6023 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);
6024 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);
6025 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);
6026 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);
6027 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);
6028 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);
6034 terrainlight=terrain.getLighting(coords.x,coords.z);
6035 distance=findDistancefast(&viewer,&coords);
6036 distance=(viewdistance*viewdistance-(distance-(viewdistance*viewdistance*fadestart))*(1/(1-fadestart)))/viewdistance/viewdistance;
6037 if(distance>1)distance=1;
6039 terrainheight=(coords.y-terrain.getHeight(coords.x,coords.z))/3+1;
6040 if(terrainheight<1)terrainheight=1;
6041 if(terrainheight>1.7)terrainheight=1.7;
6044 glColor4f((1-(1-terrainlight.x)/terrainheight)-burnt,(1-(1-terrainlight.y)/terrainheight)-burnt,(1-(1-terrainlight.z)/terrainheight)-burnt,distance);
6045 glDisable(GL_BLEND);
6046 glAlphaFunc(GL_GREATER, 0.0001);
6047 glEnable(GL_TEXTURE_2D);
6049 glDisable(GL_TEXTURE_2D);
6050 glColor4f(.7,.35,0,.5);
6052 glEnable(GL_LIGHTING);
6055 if(tutoriallevel&&id!=0){
6056 //glDisable(GL_TEXTURE_2D);
6057 glColor4f(.7,.7,.7,0.6);
6059 glEnable(GL_LIGHTING);
6061 if(canattack&&cananger)
6062 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6063 glDisable(GL_TEXTURE_2D);
6064 glColor4f(1,0,0,0.8);
6066 glMatrixMode(GL_TEXTURE);
6068 glTranslatef(0,-smoketex,0);
6069 glTranslatef(-smoketex,0,0);
6073 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6074 else skeleton.drawmodel.draw();
6078 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6079 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6082 if(!(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed))
6083 if(tutoriallevel&&id!=0){
6085 glMatrixMode(GL_MODELVIEW);
6086 glEnable(GL_TEXTURE_2D);
6087 glColor4f(.7,.7,.7,0.6);
6089 glEnable(GL_LIGHTING);
6091 if(canattack&&cananger)
6092 if(animation[targetanimation].attack==normalattack||animation[targetanimation].attack==reversed){
6093 glDisable(GL_TEXTURE_2D);
6094 glColor4f(1,0,0,0.8);
6096 glMatrixMode(GL_TEXTURE);
6098 glTranslatef(0,-smoketex*.6,0);
6099 glTranslatef(smoketex*.6,0,0);
6102 if((tutoriallevel&&id!=0))skeleton.drawmodel.drawdifftex(Sprite::cloudimpacttexture);
6103 else skeleton.drawmodel.draw();
6107 if((tutoriallevel&&id!=0))skeleton.drawmodellow.drawdifftex(Sprite::cloudimpacttexture);
6108 else skeleton.drawmodellow.drawdifftex(skeleton.drawmodel.textureptr);
6113 if(tutoriallevel&&id!=0){
6115 glMatrixMode(GL_MODELVIEW);
6116 glEnable(GL_TEXTURE_2D);
6118 if(skeleton.clothes){
6121 if(!immediate)skeleton.drawmodelclothes.draw();
6122 if(immediate)skeleton.drawmodelclothes.drawimmediate();
6129 for(k=0;k<num_weapons;k++){
6131 if(weaponactive==k){
6132 if(weapons.type[i]!=staff){
6133 for(j=0;j<skeleton.num_muscles;j++){
6134 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6135 weaponattachmuscle=j;
6138 for(j=0;j<skeleton.num_muscles;j++){
6139 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){
6140 weaponrotatemuscle=j;
6143 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6144 if(creature==wolftype)weaponpoint=(skeleton.joints[skeleton.jointlabels[rightwrist]].position*.7+skeleton.joints[skeleton.jointlabels[righthand]].position*.3);
6146 if(weapons.type[i]==staff){
6147 for(j=0;j<skeleton.num_muscles;j++){
6148 if((skeleton.muscles[j].parent1->label==righthand||skeleton.muscles[j].parent2->label==righthand)&&skeleton.muscles[j].numvertices>0){
6149 weaponattachmuscle=j;
6152 for(j=0;j<skeleton.num_muscles;j++){
6153 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){
6154 weaponrotatemuscle=j;
6157 //weaponpoint=skeleton.joints[skeleton.jointlabels[rightwrist]].position;
6158 weaponpoint=(skeleton.muscles[weaponattachmuscle].parent1->position+skeleton.muscles[weaponattachmuscle].parent2->position)/2;
6159 //weaponpoint+=skeleton.specialforward[1]*.1+(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6160 XYZ tempnormthing,vec1,vec2;
6161 vec1=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightelbow]].position);
6162 vec2=(skeleton.joints[skeleton.jointlabels[rightwrist]].position-skeleton.joints[skeleton.jointlabels[rightshoulder]].position);
6163 CrossProduct(&vec1,&vec2,&tempnormthing);
6164 Normalise(&tempnormthing);
6165 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);
6166 /*if(targetanimation==staffhitanim||currentanimation==staffhitanim){
6168 weaptargnorm=DoRotation(weapons.tippoint[i]-weapons.position[i],0,-rotation,0);
6169 //weaptargnorm=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6170 Normalise(&weaptargnorm);
6171 weaponpoint-=weaptargnorm*2;
6175 if(weaponactive!=k&&weaponstuck!=k){
6176 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;
6177 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;
6178 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;
6179 for(j=0;j<skeleton.num_muscles;j++){
6180 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){
6181 weaponrotatemuscle=j;
6186 if(weaponstuckwhere==0)weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5-skeleton.forward*.8;
6187 else weaponpoint=skeleton.joints[skeleton.jointlabels[abdomen]].position*.5+skeleton.joints[skeleton.jointlabels[neck]].position*.5+skeleton.forward*.8;
6188 for(j=0;j<skeleton.num_muscles;j++){
6189 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){
6190 weaponrotatemuscle=j;
6195 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;
6196 weapons.bigrotation[i]=rotation;
6197 weapons.bigtilt[i]=tilt;
6198 weapons.bigtilt2[i]=tilt2;
6201 weapons.position[i]=weaponpoint*scale+coords;
6202 weapons.bigrotation[i]=0;
6203 weapons.bigtilt[i]=0;
6204 weapons.bigtilt2[i]=0;
6206 weapons.rotation1[i]=skeleton.muscles[weaponrotatemuscle].lastrotate1;
6207 weapons.rotation2[i]=skeleton.muscles[weaponrotatemuscle].lastrotate2;
6208 weapons.rotation3[i]=skeleton.muscles[weaponrotatemuscle].lastrotate3;
6209 if(weaponactive==k){
6210 if(weapons.type[i]==knife){
6211 weapons.smallrotation[i]=180;
6212 weapons.smallrotation2[i]=0;
6213 if(isCrouch()||wasCrouch()){
6214 weapons.smallrotation2[i]=20;
6216 if(targetanimation==hurtidleanim){
6217 weapons.smallrotation2[i]=50;
6219 if((currentanimation==crouchstabanim&&targetanimation==crouchstabanim)||(currentanimation==backhandspringanim&&targetanimation==backhandspringanim)){
6220 XYZ temppoint1,temppoint2,tempforward;
6223 temppoint1=skeleton.joints[skeleton.jointlabels[righthand]].position;
6224 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6225 distance=findDistance(&temppoint1,&temppoint2);
6226 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6227 weapons.rotation2[i]*=360/6.28;
6230 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6231 weapons.rotation1[i]*=360/6.28;
6232 weapons.rotation3[i]=0;
6233 weapons.smallrotation[i]=-90;
6234 weapons.smallrotation2[i]=0;
6235 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6237 if((currentanimation==knifeslashreversalanim&&targetanimation==knifeslashreversalanim)||(currentanimation==knifeslashreversedanim&&targetanimation==knifeslashreversedanim)){
6238 XYZ temppoint1,temppoint2,tempforward;
6241 temppoint1=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];
6255 if(targetanimation==knifethrowanim){
6256 weapons.smallrotation[i]=90;
6257 //weapons.smallrotation2[i]=-90;
6258 weapons.smallrotation2[i]=0;
6259 weapons.rotation1[i]=0;
6260 weapons.rotation2[i]=0;
6261 weapons.rotation3[i]=0;
6263 if(targetanimation==knifesneakattackanim&&targetframe<5){
6264 weapons.smallrotation[i]=-90;
6265 weapons.rotation1[i]=0;
6266 weapons.rotation2[i]=0;
6267 weapons.rotation3[i]=0;
6270 if(weapons.type[i]==sword){
6271 weapons.smallrotation[i]=0;
6272 weapons.smallrotation2[i]=0;
6273 if(targetanimation==knifethrowanim){
6274 weapons.smallrotation[i]=-90;
6275 weapons.smallrotation2[i]=0;
6276 weapons.rotation1[i]=0;
6277 weapons.rotation2[i]=0;
6278 weapons.rotation3[i]=0;
6280 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)){
6281 XYZ temppoint1,temppoint2,tempforward;
6284 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6285 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6286 distance=findDistance(&temppoint1,&temppoint2);
6287 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6288 weapons.rotation2[i]*=360/6.28;
6291 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6292 weapons.rotation1[i]*=360/6.28;
6293 weapons.rotation3[i]=0;
6294 weapons.smallrotation[i]=90;
6295 weapons.smallrotation2[i]=0;
6296 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6299 if(weapons.type[i]==staff){
6300 weapons.smallrotation[i]=100;
6301 weapons.smallrotation2[i]=0;
6302 if((targetanimation==staffhitanim&¤tanimation==staffhitanim)||(targetanimation==staffhitreversedanim&¤tanimation==staffhitreversedanim)||(targetanimation==staffspinhitreversedanim&¤tanimation==staffspinhitreversedanim)||(targetanimation==staffgroundsmashanim&¤tanimation==staffgroundsmashanim)||(targetanimation==staffspinhitanim&¤tanimation==staffspinhitanim)){
6303 XYZ temppoint1,temppoint2,tempforward;
6306 temppoint1=animation[currentanimation].position[skeleton.jointlabels[righthand]][currentframe]*(1-target)+animation[targetanimation].position[skeleton.jointlabels[righthand]][targetframe]*(target); //skeleton.joints[skeleton.jointlabels[righthand]].position;
6307 temppoint2=animation[currentanimation].weapontarget[currentframe]*(1-target)+animation[targetanimation].weapontarget[targetframe]*(target);
6308 distance=findDistance(&temppoint1,&temppoint2);
6309 weapons.rotation2[i]=asin((temppoint1.y-temppoint2.y)/distance);
6310 weapons.rotation2[i]*=360/6.28;
6313 weapons.rotation1[i]=acos((temppoint1.z-temppoint2.z)/findDistance(&temppoint1,&temppoint2));
6314 weapons.rotation1[i]*=360/6.28;
6315 weapons.rotation3[i]=0;
6316 weapons.smallrotation[i]=90;
6317 weapons.smallrotation2[i]=0;
6318 if(temppoint1.x>temppoint2.x)weapons.rotation1[i]=360-weapons.rotation1[i];
6322 if(weaponactive!=k&&weaponstuck!=k){
6323 if(weapons.type[i]==knife){
6324 weapons.smallrotation[i]=-70;
6325 weapons.smallrotation2[i]=10;
6327 if(weapons.type[i]==sword){
6328 weapons.smallrotation[i]=-100;
6329 weapons.smallrotation2[i]=-8;
6331 if(weapons.type[i]==staff){
6332 weapons.smallrotation[i]=-100;
6333 weapons.smallrotation2[i]=-8;
6337 if(weaponstuckwhere==0)weapons.smallrotation[i]=180;
6338 else weapons.smallrotation[i]=0;
6339 weapons.smallrotation2[i]=10;
6346 if(skeleton.free)calcrot=1;
6347 if(animation[targetanimation].attack||isRun()||targetanimation==staggerbackhardanim||isFlip()||targetanimation==climbanim||targetanimation==sneakanim||targetanimation==rollanim||targetanimation==walkanim||targetanimation==backhandspringanim||isFlip()||isWallJump())calcrot=1;
6348 if(currentanimation!=targetanimation)calcrot=1;
6349 //if(id==0)calcrot=1;
6350 if(skeleton.free==2)calcrot=0;
6356 int Person::SphereCheck(XYZ *p1,float radius, XYZ *p, XYZ *move, float *rotate, Model *model)
6359 static float distance;
6360 static float olddistance;
6361 static int intersecting;
6362 static int firstintersecting;
6365 static XYZ start,end;
6366 static float slopethreshold=-.4;
6368 firstintersecting=-1;
6372 if(findDistancefast(p1,&model->boundingspherecenter)>radius*radius+model->boundingsphereradius*model->boundingsphereradius)return -1;
6373 if(*rotate)*p1=DoRotation(*p1,0,-*rotate,0);
6375 for (j=0;j<model->TriangleNum;j++){
6376 if(model->facenormals[j].y<=slopethreshold){
6378 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)));
6379 if(distance<radius){
6380 point=*p1-model->facenormals[j]*distance;
6381 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;
6382 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6383 &model->vertex[model->Triangles[j].vertex[1]],
6385 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[1]],
6386 &model->vertex[model->Triangles[j].vertex[2]],
6388 if(!intersecting)intersecting=sphere_line_intersection(&model->vertex[model->Triangles[j].vertex[0]],
6389 &model->vertex[model->Triangles[j].vertex[2]],
6392 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6396 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)){
6397 p1->y=point.y+radius;
6398 if((targetanimation==jumpdownanim||isFlip())){
6399 if(isFlip()&&(targetframe<5||animation[targetanimation].label[targetframe]==7||animation[targetanimation].label[targetframe]==4))RagDoll(0);
6401 if(targetanimation==jumpupanim){jumppower=-4;targetanimation=getIdle();}
6407 OPENAL_SetPaused(channels[whooshsound], true);
6408 OPENAL_SetVolume(channels[whooshsound], 0);
6411 if((targetanimation==jumpdownanim||isFlip())&&!wasLanding()&&!wasLandhard()){
6412 if(isFlip())jumppower=-4;
6413 targetanimation=getLanding();
6414 emit_sound_at(landsound, coords, 128.);
6417 envsound[numenvsounds]=coords;
6418 envsoundvol[numenvsounds]=16;
6419 envsoundlife[numenvsounds]=.4;
6427 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6430 for (j=0;j<model->TriangleNum;j++){
6431 if(model->facenormals[j].y>slopethreshold){
6435 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)));
6436 if(distance<radius*.5){
6437 point=start-model->facenormals[j]*distance;
6438 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;
6439 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,
6440 model->vertex[model->Triangles[j].vertex[1]].x,model->vertex[model->Triangles[j].vertex[1]].y,model->vertex[model->Triangles[j].vertex[1]].z,
6441 p1->x, p1->y, p1->z, radius/2);
6442 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,
6443 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6444 p1->x, p1->y, p1->z, radius/2);
6445 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,
6446 model->vertex[model->Triangles[j].vertex[2]].x,model->vertex[model->Triangles[j].vertex[2]].y,model->vertex[model->Triangles[j].vertex[2]].z,
6447 p1->x, p1->y, p1->z, radius/2);
6449 if(dotproduct(&model->facenormals[j],&end)>0&&intersecting){
6450 if((targetanimation==jumpdownanim||targetanimation==jumpupanim||isFlip())){
6452 velocity-=DoRotation(model->facenormals[j],0,*rotate,0)*findLength(&velocity)*abs(normaldotproduct(velocity,DoRotation(model->facenormals[j],0,*rotate,0)));//(distance-radius*.5)/multiplier;
6453 if(findLengthfast(&start)<findLengthfast(&velocity))velocity=start;
6455 *p1+=model->facenormals[j]*(distance-radius*.5);
6458 if((distance<olddistance||firstintersecting==-1)&&intersecting){olddistance=distance; firstintersecting=j; *p=point;}
6462 if(*rotate)*p=DoRotation(*p,0,*rotate,0);
6464 if(*rotate)*p1=DoRotation(*p1,0,*rotate,0);
6466 return firstintersecting;
6476 currentanimation = 0;
6477 targetanimation = 0;
6478 oldcurrentframe = 0;
6480 oldcurrentanimation = 0;
6481 oldtargetanimation = 0;
6485 parriedrecently = 0;
6489 lastattack = 0,lastattack2 = 0,lastattack3 = 0;
6491 currentoffset = 0,targetoffset = 0,offset = 0;
6509 unconscioustime = 0;
6527 rabbitkickenabled = 0;
6536 damagetolerance = 0;
6538 permanentdamage = 0;
6539 superpermanentdamage = 0; lastcollide = 0;
6559 headrotation = 0,headrotation2 = 0;
6560 targetheadrotation = 0,targetheadrotation2 = 0;
6571 normalsupdatedelay = 0;
6576 forwardstogglekeydown = 0;
6581 jumptogglekeydown = 0;
6583 crouchtogglekeydown = 0;
6585 drawtogglekeydown = 0;
6587 throwtogglekeydown = 0;
6593 crouchkeydowntime = 0;
6594 jumpkeydowntime = 0;
6611 whichdirectiondelay = 0;
6612 avoidsomething = 0; avoidwhere = 0;
6620 lefthandmorphness = 0;
6621 righthandmorphness = 0;
6625 targetlefthandmorphness = 0;
6626 targetrighthandmorphness = 0;
6627 targetheadmorphness = 0;
6628 targetchestmorphness = 0;
6629 targettailmorphness = 0;
6630 lefthandmorphstart = 0,lefthandmorphend = 0;
6631 righthandmorphstart = 0,righthandmorphend = 0;
6632 headmorphstart = 0,headmorphend = 0;
6633 chestmorphstart = 0,chestmorphend = 0;
6634 tailmorphstart = 0,tailmorphend = 0;
6636 weaponmissdelay = 0;
6637 highreversaldelay = 0;
6638 lowreversaldelay = 0;
6645 //Skeleton skeleton;
6664 memset(clothes, 0, sizeof(clothes));
6665 memset(clothestintr, 0, sizeof(clothestintr));
6666 memset(clothestintg, 0, sizeof(clothestintg));
6667 memset(clothestintb, 0, sizeof(clothestintb));
6673 onfiredelay = 0; burnt = 0;
6677 updatestuffdelay = 0;
6683 memset(weaponids, 0, sizeof(weaponids));
6687 weaponstuckwhere = 0;
6692 memset(waypoints, 0, sizeof(waypoints));
6693 memset(waypointtype, 0, sizeof(waypointtype));
6696 hastempwaypoint = 0;
6702 finalfinaltarget = 0;
6704 finalpathfindpoint = 0;
6705 targetpathfindpoint = 0;
6706 lastpathfindpoint = 0;
6707 lastpathfindpoint2 = 0;
6708 lastpathfindpoint3 = 0;
6709 lastpathfindpoint4 = 0;
6720 runninghowlong = 0; lastoccluded = 0;
6726 neckspurtparticledelay = 0;
6727 neckspurtamount = 0;
6730 rabbitkickragdoll = 0;
6735 //Animation tempanimation;