Merge pull request #194 from lioncash/init

CProjectileInfo: Initialize result variable to false within PredictInterceptPos
This commit is contained in:
Phillip Stephens 2020-03-08 18:02:41 -07:00 committed by GitHub
commit 3011a839eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 8 deletions

View File

@ -18,9 +18,10 @@ CProjectileInfo::CProjectileInfo(CAssetId proj, const CDamageInfo& dInfo)
zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunPos, const zeus::CVector3f& aimPos, zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunPos, const zeus::CVector3f& aimPos,
const CPlayer& player, bool gravity, float speed, float dt) { const CPlayer& player, bool gravity, float speed, float dt) {
zeus::CVector3f ret; zeus::CVector3f ret;
zeus::CVector3f playerVel = player.GetDampedClampedVelocityWR(); const zeus::CVector3f playerVel = player.GetDampedClampedVelocityWR();
zeus::CVector3f gravVec(0.f, 0.f, player.GetGravity()); const zeus::CVector3f gravVec(0.f, 0.f, player.GetGravity());
bool result; bool result = false;
switch (player.GetOrbitState()) { switch (player.GetOrbitState()) {
case CPlayer::EPlayerOrbitState::OrbitObject: case CPlayer::EPlayerOrbitState::OrbitObject:
case CPlayer::EPlayerOrbitState::OrbitPoint: case CPlayer::EPlayerOrbitState::OrbitPoint:
@ -33,22 +34,28 @@ zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunP
break; break;
} }
zeus::CVector3f vel; zeus::CVector3f vel;
if (playerVel.canBeNormalized()) if (playerVel.canBeNormalized()) {
vel = playerVel.normalized() * player.GetAverageSpeed(); vel = playerVel.normalized() * player.GetAverageSpeed();
else } else {
vel = playerVel; vel = playerVel;
}
result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, vel, result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, vel,
player.GetOrbitPoint(), ret); player.GetOrbitPoint(), ret);
break; break;
} }
case CPlayer::EPlayerOrbitState::NoOrbit: case CPlayer::EPlayerOrbitState::NoOrbit:
if (gravity && player.GetPlayerMovementState() == CPlayer::EPlayerMovementState::ApplyJump) if (gravity && player.GetPlayerMovementState() == CPlayer::EPlayerMovementState::ApplyJump) {
result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, gravVec, ret); result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, gravVec, ret);
else } else {
result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, ret); result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, ret);
}
break;
} }
if (!result)
if (!result) {
ret = playerVel * 1.5f + aimPos; ret = playerVel * 1.5f + aimPos;
}
return ret; return ret;
} }