- if(attackweapon==sword){
- player[k].currentanimation=swordsneakattackanim;
- player[k].targetanimation=swordsneakattackanim;
- player[i].currentanimation=swordsneakattackedanim;
- player[i].targetanimation=swordsneakattackedanim;
- player[i].oldcoords=player[i].coords;
- player[i].coords=player[k].coords;
- }
- if(attackweapon!=staff){
- player[k].victim=&player[i];
- player[k].hasvictim=1;
- player[i].targettilt2=0;
- player[i].targetframe=1;
- player[i].currentframe=0;
- player[i].target=0;
- player[i].velocity=0;
- player[k].targettilt2=player[i].targettilt2;
- player[k].currentframe=player[i].currentframe;
- player[k].targetframe=player[i].targetframe;
- player[k].target=player[i].target;
- player[k].velocity=0;
- player[k].targetrotation=player[i].rotation;
- player[k].rotation=player[i].rotation;
- player[i].targetrotation=player[i].rotation;
- }
- }
- if(animation[player[k].targetanimation].attack==normalattack&&
- player[k].victim==&player[i]&&
- (!player[i].skeleton.free)){
- oldattackkey=1;
- player[k].targetframe=0;
- player[k].target=0;
-
- player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
- player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
- player[k].lastattack3=player[k].lastattack2;
- player[k].lastattack2=player[k].lastattack;
- player[k].lastattack=player[k].targetanimation;
- }
- if(player[k].targetanimation==knifefollowanim&&
- player[k].victim==&player[i]){
- oldattackkey=1;
- player[k].targetrotation=roughDirectionTo(player[k].coords,player[i].coords);
- player[k].targettilt2=pitchTo(player[k].coords,player[i].coords);
- player[k].victim=&player[i];
- player[k].hasvictim=1;
- player[i].targetanimation=knifefollowedanim;
- player[i].currentanimation=knifefollowedanim;
- player[i].targettilt2=0;
- player[i].targettilt2=player[k].targettilt2;
- player[i].targetframe=1;
- player[i].currentframe=0;
- player[i].target=0;
- player[i].velocity=0;
- player[k].currentanimation=knifefollowanim;
- player[k].targetanimation=knifefollowanim;
- player[k].targettilt2=player[i].targettilt2;
- player[k].currentframe=player[i].currentframe;
- player[k].targetframe=player[i].targetframe;
- player[k].target=player[i].target;
- player[k].velocity=0;
- player[k].oldcoords=player[k].coords;
- player[i].coords=player[k].coords;
- player[i].targetrotation=player[k].targetrotation;
- player[i].rotation=player[k].targetrotation;
- player[k].rotation=player[k].targetrotation;
- player[i].rotation=player[k].targetrotation;
- }
- }
- }
- const bool hasstaff=attackweapon==staff;
- if(k==0&&numplayers>1)
- for(int i=0;i<numplayers;i++){
- if(i==k)continue;
- if((playerrealattackkeydown||player[i].dead||!hasstaff)&&
- animation[player[k].targetanimation].attack==neutral){
- const float distance=findDistancefast(&player[k].coords,&player[i].coords);
- if(!player[i].dead||!realthreat||(!attackweapon&&player[k].crouchkeydown))
- if(player[i].skeleton.free)
- if(distance<3.5*sq(player[k].scale*5)&&
- (player[i].dead||
- player[i].skeleton.longdead>1000||
- player[k].isRun()||
- hasstaff||
- (attackweapon&&
- (player[i].skeleton.longdead>2000||
- player[i].damage>player[i].damagetolerance/8||
- player[i].bloodloss>player[i].damagetolerance/2)&&
- distance<1.5*sq(player[k].scale*5)))){
- player[k].victim=&player[i];
- player[k].hasvictim=1;
- if(attackweapon&&tutoriallevel!=1){
- //crouchstab
- if(player[k].crouchkeydown&&attackweapon==knife&&distance<1.5*sq(player[k].scale*5))
- player[k].targetanimation=crouchstabanim;
- //swordgroundstab
- if(player[k].crouchkeydown&&distance<1.5*sq(player[k].scale*5)&&attackweapon==sword)
- player[k].targetanimation=swordgroundstabanim;
- //staffgroundsmash
- if(distance<3.5*sq(player[k].scale*5)&&attackweapon==staff)
- player[k].targetanimation=staffgroundsmashanim;
- }
- if(distance<2.5&&
- player[k].crouchkeydown&&
- player[k].targetanimation!=crouchstabanim&&
- !attackweapon&&
- player[i].dead&&
- player[i].skeleton.free&&
- player[i].skeleton.longdead>1000){
- player[k].targetanimation=killanim;
- //TODO: refactor this out, what does it do?
- for(int j=0;j<terrain.numdecals;j++){
- if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
- terrain.decalalivetime[j]<2)
- terrain.DeleteDecal(j);
- }
- for(int l=0;l<objects.numobjects;l++){
- if(objects.model[l].type==decalstype)
- for(int j=0;j<objects.model[l].numdecals;j++){
- if((objects.model[l].decaltype[j]==blooddecal||
- objects.model[l].decaltype[j]==blooddecalslow)&&
- objects.model[l].decalalivetime[j]<2)
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- if(!player[i].dead||musictype!=2)
- if(distance<3.5&&
- (player[k].isRun()||player[k].isIdle()&&player[k].attackkeydown)&&
- player[k].staggerdelay<=0&&
- (player[i].dead||
- player[i].skeleton.longdead<300&&
- player[k].lastattack!=spinkickanim&&
- player[i].skeleton.free)&&
- (!player[i].dead||musictype!=stream_music2)){
- player[k].targetanimation=dropkickanim;
- for(int j=0;j<terrain.numdecals;j++){
- if((terrain.decaltype[j]==blooddecal||terrain.decaltype[j]==blooddecalslow)&&
- terrain.decalalivetime[j]<2){
- terrain.DeleteDecal(j);
- }
- }
- for(int l=0;l<objects.numobjects;l++){
- if(objects.model[l].type==decalstype)
- for(int j=0;j<objects.model[l].numdecals;j++){
- if((objects.model[l].decaltype[j]==blooddecal||
- objects.model[l].decaltype[j]==blooddecalslow)&&
- objects.model[l].decalalivetime[j]<2){
- objects.model[l].DeleteDecal(j);
- }
- }
- }
- }
- }
- if(animation[player[k].targetanimation].attack==normalattack&&
- player[k].victim==&player[i]&&
- (!player[i].skeleton.free||
- player[k].targetanimation==killanim||
- player[k].targetanimation==crouchstabanim||
- player[k].targetanimation==swordgroundstabanim||
- player[k].targetanimation==staffgroundsmashanim||
- player[k].targetanimation==dropkickanim)){
- oldattackkey=1;
- player[k].targetframe=0;
- player[k].target=0;
-
- XYZ targetpoint=player[i].coords;
- if(player[k].targetanimation==crouchstabanim||
- player[k].targetanimation==swordgroundstabanim||
- player[k].targetanimation==staffgroundsmashanim){
- targetpoint+=(playerJoint(i,abdomen).position+
- playerJoint(i,neck).position)/2*
- player[i].scale;
- }
- player[k].targetrotation=roughDirectionTo(player[k].coords,targetpoint);
- player[k].targettilt2=pitchTo(player[k].coords,targetpoint);
-
- if(player[k].targetanimation==crouchstabanim||player[k].targetanimation==swordgroundstabanim){
- player[k].targetrotation+=(float)(abs(Random()%100)-50)/4;
- }
-
- if(player[k].targetanimation==staffgroundsmashanim)
- player[k].targettilt2+=10;
-
- player[k].lastattack3=player[k].lastattack2;
- player[k].lastattack2=player[k].lastattack;
- player[k].lastattack=player[k].targetanimation;
-
- if(player[k].targetanimation==swordgroundstabanim){
- player[k].targetrotation+=30;
- }
- }
- }
- }
- if(!player[k].hasvictim){
- //find victim
- for(int i=0;i<numplayers;i++){
- if(i==k||!(i==0||k==0))continue;
- if(!player[i].skeleton.free){
- if(player[k].hasvictim){
- if(findDistancefast(&player[k].coords,&player[i].coords)<
- findDistancefast(&player[k].coords,&player[k].victim->coords))
- player[k].victim=&player[i];
- }else{
- player[k].victim=&player[i];
- player[k].hasvictim=1;
- }
- }
- }
- }
- if(player[k].aitype==playercontrolled)
- //rabbit kick
- if(player[k].attackkeydown&&
- player[k].isRun()&&
- player[k].wasRun()&&
- ((player[k].hasvictim&&
- findDistancefast(&player[k].coords,&player[k].victim->coords)<12*sq(player[k].scale*5)&&
- findDistancefast(&player[k].coords,&player[k].victim->coords)>7*sq(player[k].scale*5)&&
- !player[k].victim->skeleton.free&&
- player[k].victim->targetanimation!=getupfrombackanim&&
- player[k].victim->targetanimation!=getupfromfrontanim&&
- animation[player[k].victim->targetanimation].height!=lowheight&&
- player[k].aitype!=playercontrolled&& //wat???
- normaldotproduct(player[k].facing,player[k].victim->coords-player[k].coords)>0&&
- player[k].rabbitkickenabled)||
- player[k].jumpkeydown)){
- oldattackkey=1;
- setAnimation(k,rabbitkickanim);
- }
- //update counts
- if(animation[player[k].targetanimation].attack&&k==0){
- numattacks++;
- switch(attackweapon){
- case 0: numunarmedattack++; break;
- case knife: numknifeattack++; break;
- case sword: numswordattack++; break;
- case staff: numstaffattack++; break;
- }
- }
- }
- }
- }
- }
-}
-
-void Game::doPlayerCollisions(){
- static XYZ rotatetarget;
- static float collisionradius;
- if(numplayers>1)
- for(int k=0;k<numplayers;k++)
- for(int i=k+1;i<numplayers;i++){
- //neither player is part of a reversal
- if((animation[player[i].targetanimation].attack!=reversed&&
- animation[player[i].targetanimation].attack!=reversal&&
- animation[player[k].targetanimation].attack!=reversed&&
- animation[player[k].targetanimation].attack!=reversal)||(i!=0&&k!=0))
- if((animation[player[i].currentanimation].attack!=reversed&&
- animation[player[i].currentanimation].attack!=reversal&&
- animation[player[k].currentanimation].attack!=reversed&&
- animation[player[k].currentanimation].attack!=reversal)||(i!=0&&k!=0))
- //neither is sleeping
- if(player[i].howactive<=typesleeping&&player[k].howactive<=typesleeping)
- if(player[i].howactive!=typesittingwall&&player[k].howactive!=typesittingwall)
- //in same patch, neither is climbing
- if(player[i].whichpatchx==player[k].whichpatchx&&
- player[i].whichpatchz==player[k].whichpatchz&&
- player[k].skeleton.oldfree==player[k].skeleton.free&&
- player[i].skeleton.oldfree==player[i].skeleton.free&&
- player[i].targetanimation!=climbanim&&
- player[i].targetanimation!=hanganim&&
- player[k].targetanimation!=climbanim&&
- player[k].targetanimation!=hanganim)
- //players are close (bounding box test)
- if(player[i].coords.y>player[k].coords.y-3)
- if(player[i].coords.y<player[k].coords.y+3)
- if(player[i].coords.x>player[k].coords.x-3)
- if(player[i].coords.x<player[k].coords.x+3)
- if(player[i].coords.z>player[k].coords.z-3)
- if(player[i].coords.z<player[k].coords.z+3){
- //spread fire from player to player
- if(findDistancefast(&player[i].coords,&player[k].coords)
- <3*sq((player[i].scale+player[k].scale)*2.5)){
- if(player[i].onfire||player[k].onfire){
- if(!player[i].onfire)player[i].CatchFire();
- if(!player[k].onfire)player[k].CatchFire();
- }
- }
-
- XYZ tempcoords1=player[i].coords;
- XYZ tempcoords2=player[k].coords;
- if(!player[i].skeleton.oldfree)
- tempcoords1.y+=playerJoint(i,abdomen).position.y*player[i].scale;
- if(!player[k].skeleton.oldfree)
- tempcoords2.y+=playerJoint(k,abdomen).position.y*player[k].scale;
- collisionradius=1.2*sq((player[i].scale+player[k].scale)*2.5);
- if(player[0].hasvictim)
- if(player[0].targetanimation==rabbitkickanim&&(k==0||i==0)&&!player[0].victim->skeleton.free)
- collisionradius=3;
- if((!player[i].skeleton.oldfree||!player[k].skeleton.oldfree)&&
- (findDistancefast(&tempcoords1,&tempcoords2)<collisionradius||
- findDistancefast(&player[i].coords,&player[k].coords)<collisionradius)){
- //jump down on a dead body
- if(k==0||i==0){
- int l=i?i:k;
- if(player[0].targetanimation==jumpdownanim&&
- !player[0].skeleton.oldfree&&
- !player[0].skeleton.free&&
- player[l].skeleton.oldfree&&
- player[l].skeleton.free&&
- player[l].dead&&
- player[0].lastcollide<=0&&
- fabs(player[l].coords.y-player[0].coords.y)<.2&&
- findDistancefast(&player[0].coords,&player[l].coords)<.7*sq((player[l].scale+player[0].scale)*2.5)){
- player[0].coords.y=player[l].coords.y;
- player[l].velocity=player[0].velocity;
- player[l].skeleton.free=0;
- player[l].rotation=0;
- player[l].RagDoll(0);
- player[l].DoDamage(20);
- camerashake+=.3;
- player[l].skeleton.longdead=0;
- player[0].lastcollide=1;
- }
- }
-
- if( (player[i].skeleton.oldfree==1&&findLengthfast(&player[i].velocity)>1)||
- (player[k].skeleton.oldfree==1&&findLengthfast(&player[k].velocity)>1)||
- (player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0)){
- rotatetarget=player[k].velocity-player[i].velocity;
- if((player[i].targetanimation!=getupfrombackanim&&player[i].targetanimation!=getupfromfrontanim||
- player[i].skeleton.free)&&
- (player[k].targetanimation!=getupfrombackanim&&player[k].targetanimation!=getupfromfrontanim||
- player[k].skeleton.free))
- if((((k!=0&&findLengthfast(&rotatetarget)>150||
- k==0&&findLengthfast(&rotatetarget)>50&&player[0].rabbitkickragdoll)&&
- normaldotproduct(rotatetarget,player[k].coords-player[i].coords)>0)&&
- (k==0||
- k!=0&&player[i].skeleton.oldfree==1&&animation[player[k].currentanimation].attack==neutral||
- /*i!=0&&*/player[k].skeleton.oldfree==1&&animation[player[i].currentanimation].attack==neutral))||
- (player[i].targetanimation==jumpupanim||player[i].targetanimation==jumpdownanim||player[i].isFlip())&&
- (player[k].targetanimation==jumpupanim||player[k].targetanimation==jumpdownanim||player[k].isFlip())&&
- k==0&&!player[i].skeleton.oldfree&&!player[k].skeleton.oldfree){
- //If hit by body
- if( (i!=0||player[i].skeleton.free)&&
- (k!=0||player[k].skeleton.free)||
- (animation[player[i].targetanimation].height==highheight&&
- animation[player[k].targetanimation].height==highheight)){
- if(tutoriallevel!=1){
- emit_sound_at(heavyimpactsound, player[i].coords);
- }
-
- player[i].RagDoll(0);
- if(player[i].damage>player[i].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[i].dead){
- award_bonus(0, aimbonus);
- }
- player[i].DoDamage(findLengthfast(&rotatetarget)/4);
- player[k].RagDoll(0);
- if(player[k].damage>player[k].damagetolerance-findLengthfast(&rotatetarget)/4&&!player[k].dead){
- award_bonus(0, aimbonus); // Huh, again?
- }
- player[k].DoDamage(findLengthfast(&rotatetarget)/4);
-
- for(int j=0;j<player[i].skeleton.num_joints;j++){
- player[i].skeleton.joints[j].velocity=player[i].skeleton.joints[j].velocity/5+player[k].velocity;
- }
- for(int j=0;j<player[k].skeleton.num_joints;j++){
- player[k].skeleton.joints[j].velocity=player[k].skeleton.joints[j].velocity/5+player[i].velocity;
- }
-
- }
- }
- if( (animation[player[i].targetanimation].attack==neutral||
- animation[player[i].targetanimation].attack==normalattack)&&
- (animation[player[k].targetanimation].attack==neutral||
- animation[player[k].targetanimation].attack==normalattack)){
- //If bumped
- if(player[i].skeleton.oldfree==0&&player[k].skeleton.oldfree==0){
- if(findDistancefast(&player[k].coords,&player[i].coords)<.5*sq((player[i].scale+player[k].scale)*2.5)){
- rotatetarget=player[k].coords-player[i].coords;
- Normalise(&rotatetarget);
- player[k].coords=(player[k].coords+player[i].coords)/2;
- player[i].coords=player[k].coords-rotatetarget*fast_sqrt(.6)/2
- *sq((player[i].scale+player[k].scale)*2.5);
- player[k].coords+=rotatetarget*fast_sqrt(.6)/2*sq((player[i].scale+player[k].scale)*2.5);
- if(player[k].howactive==typeactive||hostile)
- if(player[k].isIdle()){
- if(player[k].howactive<typesleeping)
- setAnimation(k,player[k].getStop());
- else if(player[k].howactive==typesleeping)
- setAnimation(k,getupfromfrontanim);
- if(!editorenabled)
- player[k].howactive=typeactive;
- }
- if(player[i].howactive==typeactive||hostile)
- if(player[i].isIdle()){
- if(player[i].howactive<typesleeping)
- setAnimation(i,player[k].getStop());
- else
- setAnimation(i,getupfromfrontanim);
- if(!editorenabled)
- player[i].howactive=typeactive;
- }
- }
- //jump down on player
- if(hostile){
- if(k==0&&i!=0&&player[k].targetanimation==jumpdownanim&&
- !player[i].isCrouch()&&
- player[i].targetanimation!=rollanim&&
- !player[k].skeleton.oldfree&&!
- player[k].skeleton.free&&
- player[k].lastcollide<=0&&
- player[k].velocity.y<-10){
- player[i].velocity=player[k].velocity;
- player[k].velocity=player[k].velocity*-.5;
- player[k].velocity.y=player[i].velocity.y;
- player[i].DoDamage(20);
- player[i].RagDoll(0);
- player[k].lastcollide=1;
- award_bonus(k, AboveBonus);