diff options
Diffstat (limited to 'src/GameTick.cpp')
-rw-r--r-- | src/GameTick.cpp | 309 |
1 files changed, 113 insertions, 196 deletions
diff --git a/src/GameTick.cpp b/src/GameTick.cpp index ccf1a5c..16f00bc 100644 --- a/src/GameTick.cpp +++ b/src/GameTick.cpp @@ -329,14 +329,15 @@ void Game::setListener(XYZ& facing) alListenerfv(AL_ORIENTATION, ori); } -XYZ Game::fluidAim(int& j) +XYZ Game::aimPlayer() { - auto& joints = person[j].skeleton.joints; - auto& jointlabels = person[j].skeleton.jointlabels; + auto& joints = person[0].skeleton.joints; + auto& jointlabels = person[0].skeleton.jointlabels; auto point = joints[jointlabels[lefthand]].position - joints[jointlabels[righthand]].position; float aimrot = 0.0f, aimrot2 = 0.0f; - switch (person[j].whichgun) { + + switch (person[0].whichgun) { case assaultrifle: aimrot = -2.5f; break; @@ -350,18 +351,19 @@ XYZ Game::fluidAim(int& j) case handgun1: case handgun2: aimrot = -0.9f; + auto k = thirdperson ? 0.35 : 0.65; point = joints[jointlabels[righthand]].position - - joints[jointlabels[head]].position * 0.35f - - joints[jointlabels[neck]].position * 0.65f; + - joints[jointlabels[head]].position * k + - joints[jointlabels[neck]].position * (1 - k); break; } - XYZ aim = DoRotation(point, aimrot2, - person[j].playerrotation + aimrot, 0); - - if(j!=0&&person[person[j].killtarget].skeleton.free==0)aim=(DoRotation(person[person[j].killtarget].skeleton.joints[person[person[j].killtarget].skeleton.jointlabels[abdomen]].position,0,person[person[j].killtarget].playerrotation,0)+person[person[j].killtarget].playercoords)-(DoRotation(person[j].skeleton.joints[person[j].skeleton.jointlabels[lefthand]].position,0,person[j].playerrotation,0)+person[j].playercoords); - if(j!=0&&person[person[j].killtarget].skeleton.free!=0)aim=person[person[j].killtarget].skeleton.joints[person[person[j].killtarget].skeleton.jointlabels[abdomen]].position-(DoRotation(person[j].skeleton.joints[person[j].skeleton.jointlabels[lefthand]].position,0,person[j].playerrotation,0)+person[j].playercoords); + return DoRotation(point, aimrot2, + person[0].playerrotation + aimrot, 0); +} +XYZ Game::aimBot(int j) +{ float inaccuracy = 0.0f; switch (person[j].whichgun) { case handgun1: @@ -376,12 +378,28 @@ XYZ Game::fluidAim(int& j) inaccuracy = 2.0f; break; } - if (person[person[j].killtarget].skeleton.free == 1) + if (person[person[j].killtarget].skeleton.free) inaccuracy *= 3; - if(j!=0)aim=DoRotation(DoRotation(DoRotation(aim,0,-person[j].playerrotation,0),(float)(abs(Random()%2000))/2000*inaccuracy-inaccuracy/2,(float)(abs(Random()%2000))/2000*inaccuracy-inaccuracy/2,0),0,person[j].playerrotation,0); - Normalise(&aim); - return std::move(aim); + auto& target = person[person[j].killtarget]; + auto& joints = target.skeleton.joints; + auto& jointlabels = target.skeleton.jointlabels; + XYZ aim = joints[jointlabels[abdomen]].position; + if (target.skeleton.free) + inaccuracy *= 3; + else + aim = DoRotation(aim, 0, target.playerrotation, 0) + + target.playercoords; + + auto& lefthandpos = joints[jointlabels[lefthand]].position; + aim -= person[j].playercoords + + DoRotation(lefthandpos, 0, person[j].playerrotation, 0); + return DoRotation( + DoRotation( + DoRotation(aim, 0, -person[j].playerrotation, 0), + (abs(Random() % 2000) / 2000.0 - 0.5) * inaccuracy, + (abs(Random() % 2000) / 2000.0 - 0.5) * inaccuracy, 0), + 0, person[j].playerrotation, 0); } void Game::Tick() @@ -1455,10 +1473,12 @@ void Game::Tick() person[i].attacktarget=0; person[i].attackframe=0; - float gLoc[3]; - gLoc[0]=(camera.position.x+((person[i].playercoords.x+flatfacing.x)-camera.position.x)/2)/soundscalefactor; - gLoc[1]=(camera.position.y+((person[i].playercoords.y+flatfacing.y)-camera.position.y)/2)/soundscalefactor; - gLoc[2]=(camera.position.z+((person[i].playercoords.z+flatfacing.z)-camera.position.z)/2)/soundscalefactor; + auto stabpos = person[i].playercoords + flatfacing - camera.position; + ALfloat gLoc[] { + stabpos.x / 2 / soundscalefactor, + stabpos.y / 2 / soundscalefactor, + stabpos.z / 2 / soundscalefactor, + }; if(person[person[i].killtarget].type!=zombietype) { @@ -1810,185 +1830,109 @@ void Game::Tick() if(person[0].attackframe>1||(person[0].attackframe>=0&&person[0].currentanimation==joganim)){ if(person[person[0].killtarget].skeleton.free<1&&person[0].killtarget!=0&&(person[0].aiming<1||person[0].whichgun==nogun||person[0].whichgun==knife||person[0].targetanimation==joganim)){ + auto soundpos = person[0].playercoords + flatfacing + - camera.position; + float gLoc[] { + soundpos.x / 2 / soundscalefactor, + soundpos.y / 2 / soundscalefactor, + soundpos.z / 2 / soundscalefactor, + }; - float gLoc[3]; - - gLoc[0]=(camera.position.x+((person[0].playercoords.x+flatfacing.x)-camera.position.x)/2)/soundscalefactor; - - gLoc[1]=(camera.position.y+((person[0].playercoords.y+flatfacing.y)-camera.position.y)/2)/soundscalefactor; - - gLoc[2]=(camera.position.z+((person[0].playercoords.z+flatfacing.z)-camera.position.z)/2)/soundscalefactor; - - if(person[person[0].killtarget].type!=zombietype) - - { - - if(person[0].whichgun!=knife){ - + if (person[person[0].killtarget].type != zombietype) { + if (person[0].whichgun != knife) { alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[headwhacksound]); - - } - - if(person[0].whichgun==knife){ - + } else { alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[knifeslashsound]); person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]]; - person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]]; - person[person[0].killtarget].bleeding=1; - person[person[0].killtarget].bleeddelay=1; - person[0].bjoint1=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]]; - person[0].bjoint2=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]]; person[0].bleeding=1; - person[0].bleeddelay=1; velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2; - velocity.y+=30; - sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2); - sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3); - sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4); - } person[person[0].killtarget].health-=100; - person[person[0].killtarget].skeleton.free=1; - person[person[0].killtarget].longdead=1; for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){ - person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0); - person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords; - person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position; - person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity; - person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5; - person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5; - person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5; - } if(person[0].whichgun!=knife){ - person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=DoRotation(flatfacing,0,40,0)*50; - person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=person[0].velocity*2; - } - - } - - else - - { - + } else { if(whacked==0){ - whacked=1; - - if(person[0].whichgun!=knife){ - + if (person[0].whichgun!=knife) { alSourcefv(gSourceID[headwhacksound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[headwhacksound]); - - } - - if(person[0].whichgun==knife){ - + } else { alSourcefv(gSourceID[knifeslashsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[knifeslashsound]); person[person[0].killtarget].bjoint1=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]]; - person[person[0].killtarget].bjoint2=&person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]]; - person[person[0].killtarget].bleeding=1; - person[person[0].killtarget].bleeddelay=1; person[0].bjoint1=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]]; - person[0].bjoint2=&person[0].skeleton.joints[person[0].skeleton.jointlabels[righthand]]; person[0].bleeding=1; - person[0].bleeddelay=1; velocity=DoRotation(flatfacing,0,70,0)*50+person[0].velocity*2; - velocity.y+=30; sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.3, 2); - sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.2, 3); - sprites.MakeSprite(bloodspritedown, .8, 1, .2, .2,DoRotation(person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[neck]].position,0,person[person[0].killtarget].playerrotation,0)+person[person[0].killtarget].playercoords, velocity*.1, 4); - } person[person[0].killtarget].health-=200; - person[person[0].killtarget].maxhealth-=20; - person[person[0].killtarget].skeleton.free=1; - person[person[0].killtarget].longdead=1; for(int j=0;j<person[person[0].killtarget].skeleton.num_joints;j++){ - person[person[0].killtarget].skeleton.joints[j].position=DoRotation(person[person[0].killtarget].skeleton.joints[j].position,0,person[person[0].killtarget].playerrotation,0); - person[person[0].killtarget].skeleton.joints[j].position+=person[person[0].killtarget].playercoords; - person[person[0].killtarget].skeleton.joints[j].realoldposition=person[person[0].killtarget].skeleton.joints[j].position; - person[person[0].killtarget].skeleton.joints[j].velocity=person[person[0].killtarget].velocity; person[person[0].killtarget].skeleton.joints[j].velocity.x+=abs(Random()%10)-5; - person[person[0].killtarget].skeleton.joints[j].velocity.y+=abs(Random()%10)-5; - person[person[0].killtarget].skeleton.joints[j].velocity.z+=abs(Random()%10)-5; - } if(person[0].whichgun!=knife){ - person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=DoRotation(flatfacing,0,40,0)*50; - person[person[0].killtarget].skeleton.joints[person[person[0].killtarget].skeleton.jointlabels[head]].velocity+=person[0].velocity*2; - } - } - } - } - } //Tackle @@ -2001,9 +1945,9 @@ void Game::Tick() continue; float gLoc[] { - flatfacing.x / soundscalefactor, - flatfacing.y / soundscalefactor, - flatfacing.z / soundscalefactor, + flatfacing.x / soundscalefactor / 2, + flatfacing.y / soundscalefactor / 2, + flatfacing.z / soundscalefactor / 2, }; alSourcefv(gSourceID[headwhacksound], @@ -2114,7 +2058,15 @@ void Game::Tick() person[j].ammo--; for (int p = 0; p < numshots; p++) { - XYZ aim = (zoom && j == 0) ? facing : fluidAim(j); + XYZ aim; + if (j) + aim = aimBot(j); + else if (!zoom) + aim = aimPlayer(); + else + aim = facing; + Normalise(&aim); + if(person[j].whichgun==sniperrifle){ start=person[j].playercoords+DoRotation(person[j].skeleton.joints[(person[j].skeleton.jointlabels[lefthand])].position,0,person[j].playerrotation,0); @@ -2743,45 +2695,24 @@ void Game::Tick() } person[whichhit].bjoint1=hitstruct.joint1; - person[whichhit].bjoint2=hitstruct.joint2; - person[whichhit].bleeding=1; - person[whichhit].bleeddelay=1; - float gLoc[3]; - - gLoc[0]=(camera.position.x+(hitstruct.hitlocation.x-camera.position.x)/4)/soundscalefactor; - - gLoc[1]=(camera.position.y+(hitstruct.hitlocation.y-camera.position.y)/4)/soundscalefactor; - - gLoc[2]=(camera.position.z+(hitstruct.hitlocation.z-camera.position.z)/4)/soundscalefactor; - - if(!hitstruct.joint1->modelnum==headmodel){ - - if(!thirdperson)alSourcef(gSourceID[bodyhitsound], AL_MIN_GAIN, 1); - - if(thirdperson)alSourcef(gSourceID[bodyhitsound], AL_MIN_GAIN, .1); - - alSourcefv(gSourceID[bodyhitsound], AL_POSITION, gLoc); - - alSourcePlay(gSourceID[bodyhitsound]); - - } - - if(hitstruct.joint1->modelnum==headmodel){ - - if(!thirdperson)alSourcef(gSourceID[headshotsound], AL_MIN_GAIN, 1); - - if(thirdperson)alSourcef(gSourceID[headshotsound], AL_MIN_GAIN, .1); - - alSourcefv(gSourceID[headshotsound], AL_POSITION, gLoc); - - alSourcePlay(gSourceID[headshotsound]); - - } - + auto hitsound = (hitstruct.joint1->modelnum == headmodel) + ? gSourceID[headshotsound] + : gSourceID[bodyhitsound]; + auto hitpos = hitstruct.hitlocation + - camera.position; + ALfloat gLoc[] { + hitpos.x / soundscalefactor / 4, + hitpos.y / soundscalefactor / 4, + hitpos.z / soundscalefactor / 4, + }; + ALfloat gain = thirdperson ? 0.1f : 1.0f; + alSourcef(hitsound, AL_MIN_GAIN, gain); + alSourcefv(hitsound, AL_POSITION, gLoc); + alSourcePlay(hitsound); }//with wall if(oldend==finalwallhit){ @@ -2834,18 +2765,16 @@ void Game::Tick() } - float gLoc[3]; - - gLoc[0]=finalwallhit.x/soundscalefactor; - - gLoc[1]=finalwallhit.y/soundscalefactor; - - gLoc[2]=finalwallhit.z/soundscalefactor; - - alSourcefv(gSourceID[wallhitsound], AL_POSITION, gLoc); - + auto wallhitpos = finalwallhit + - camera.position; + ALfloat gLoc[] { + wallhitpos.x / soundscalefactor, + wallhitpos.y / soundscalefactor, + wallhitpos.z / soundscalefactor, + }; + alSourcefv(gSourceID[wallhitsound], + AL_POSITION, gLoc); alSourcePlay(gSourceID[wallhitsound]); - } lastshot[0]=start; @@ -2892,25 +2821,19 @@ void Game::Tick() } - if(nearest.x){ - - if(findDistancefast(nearest,camera.position)<10&&(thirdperson==2||j!=0)){ - - float gLoc[3]; - - gLoc[0]=(camera.position.x+(nearest.x-camera.position.x))/soundscalefactor; - - gLoc[1]=(camera.position.y+(nearest.y-camera.position.y))/soundscalefactor; - - gLoc[2]=(camera.position.z+(nearest.z-camera.position.z))/soundscalefactor; - - alSourcefv(gSourceID[nearbulletsound], AL_POSITION, gLoc); - - alSourcePlay(gSourceID[nearbulletsound]); - } + if (nearest.x + && findDistancefast(nearest, camera.position) < 10 + && (thirdperson == 2 || j != 0)) { + auto nearsound = nearest - camera.position; + ALfloat gLoc[] { + nearsound.x / soundscalefactor, + nearsound.y / soundscalefactor, + nearsound.z / soundscalefactor, + }; + alSourcefv(gSourceID[nearbulletsound], AL_POSITION, gLoc); + alSourcePlay(gSourceID[nearbulletsound]); } } - } } @@ -3286,15 +3209,14 @@ void Game::Tick() impact=1; - sprites.location[i]=hitstruct.hitlocation; - - float gLoc[3]; - - gLoc[0]=(((sprites.location[i].x)-camera.position.x)/findLengthfast(sprites.velocity[i])*5+camera.position.x)/soundscalefactor; - - gLoc[1]=(((sprites.location[i].y)-camera.position.y)/findLengthfast(sprites.velocity[i])*5+camera.position.y)/soundscalefactor; - - gLoc[2]=(((sprites.location[i].z)-camera.position.z)/findLengthfast(sprites.velocity[i])*5+camera.position.z)/soundscalefactor; + sprites.location[i] = hitstruct.hitlocation; + auto landpos = sprites.location[i] - camera.position; + auto v = findLengthfast(sprites.velocity[i]) * 0.2; + ALfloat gLoc[] { + landpos.x / v / soundscalefactor, + landpos.y / v / soundscalefactor, + landpos.z / v / soundscalefactor, + }; if(person[j].skeleton.free<1){ @@ -3399,23 +3321,18 @@ void Game::Tick() sprites.brightness[i]-=multiplier*.3; if(sprites.brightness[i]<=0||(impact&&sprites.size[i]>1)){ - sprites.brightness[i]=0; - sprites.MakeSprite(smokesprite, 1, 1, 1, 1, sprites.location[i], facing*0, 60); - sprites.MakeSprite(muzzleflashsprite, 1, 1, 1, 1, sprites.location[i], facing*0, 9); - float gLoc[3]; - - gLoc[0]=(((sprites.location[i].x)-camera.position.x)/3+camera.position.x)/soundscalefactor; - - gLoc[1]=(((sprites.location[i].y)-camera.position.y)/3+camera.position.y)/soundscalefactor; - - gLoc[2]=(((sprites.location[i].z)-camera.position.z)/3+camera.position.z)/soundscalefactor; - + auto explodepos = sprites.location[i] + - camera.position; + ALfloat gLoc[] { + explodepos.x / 3 / soundscalefactor, + explodepos.y / 3 / soundscalefactor, + explodepos.z / 3 / soundscalefactor, + }; alSourcefv(gSourceID[explosionsound], AL_POSITION, gLoc); - alSourcePlay(gSourceID[explosionsound]); XYZ relation; |