metaforce/Runtime/Weapon/CProjectileInfo.cpp

76 lines
3.0 KiB
C++
Raw Normal View History

2018-06-04 19:30:04 +00:00
#include "CProjectileInfo.hpp"
#include "World/CDamageInfo.hpp"
#include "GameGlobalObjects.hpp"
2018-12-13 07:39:16 +00:00
#include "CProjectileWeapon.hpp"
#include "World/CPlayer.hpp"
#include "Character/CSteeringBehaviors.hpp"
2018-06-04 19:30:04 +00:00
#include "CSimplePool.hpp"
2018-12-08 05:30:43 +00:00
namespace urde {
2018-06-04 19:30:04 +00:00
CProjectileInfo::CProjectileInfo(urde::CInputStream& in)
2018-12-17 03:52:51 +00:00
: x0_weaponDescription(g_SimplePool->GetObj({SBIG('WPSC'), CAssetId(in)})), xc_damageInfo(in) {
if (x0_weaponDescription.GetObjectTag()->id == 0xB4CB4495)
printf("");
}
2018-12-08 05:30:43 +00:00
CProjectileInfo::CProjectileInfo(CAssetId proj, const CDamageInfo& dInfo)
2018-12-17 03:52:51 +00:00
: x0_weaponDescription(g_SimplePool->GetObj({SBIG('WPSC'), proj})), xc_damageInfo(dInfo) {
if (x0_weaponDescription.GetObjectTag()->id == 0xB4CB4495)
printf("");
}
2018-06-04 19:30:04 +00:00
2018-12-13 07:39:16 +00:00
zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunPos, const zeus::CVector3f& aimPos,
const CPlayer& player, bool gravity, float speed, float dt) {
zeus::CVector3f ret;
zeus::CVector3f playerVel = player.GetDampedClampedVelocityWR();
zeus::CVector3f gravVec(0.f, 0.f, player.GetGravity());
bool result;
switch (player.GetOrbitState()) {
case CPlayer::EPlayerOrbitState::OrbitObject:
case CPlayer::EPlayerOrbitState::OrbitPoint:
case CPlayer::EPlayerOrbitState::OrbitCarcass:
case CPlayer::EPlayerOrbitState::ForcedOrbitObject:
case CPlayer::EPlayerOrbitState::Grapple: {
if (gravity && player.GetPlayerMovementState() == CPlayer::EPlayerMovementState::ApplyJump) {
result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, playerVel, gravVec,
player.GetOrbitPoint(), ret);
break;
}
zeus::CVector3f vel;
if (playerVel.canBeNormalized())
vel = playerVel.normalized() * player.GetAverageSpeed();
else
vel = playerVel;
result = CSteeringBehaviors::ProjectOrbitalIntersection(gunPos, speed, dt, aimPos, vel,
player.GetOrbitPoint(), ret);
break;
}
case CPlayer::EPlayerOrbitState::NoOrbit:
if (gravity && player.GetPlayerMovementState() == CPlayer::EPlayerMovementState::ApplyJump)
result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, gravVec, ret);
else
result = CSteeringBehaviors::ProjectLinearIntersection(gunPos, speed, aimPos, playerVel, ret);
}
if (!result)
ret = playerVel * 1.5f + aimPos;
return ret;
}
float CProjectileInfo::GetProjectileSpeed() const {
auto wpsc = x0_weaponDescription;
if (wpsc->x4_IVEC) {
zeus::CVector3f vec;
wpsc->x4_IVEC->GetValue(0, vec);
return vec.magnitude() / CProjectileWeapon::GetTickPeriod();
}
return 45000.0f;
}
zeus::CVector3f CProjectileInfo::PredictInterceptPos(const zeus::CVector3f& gunPos, const zeus::CVector3f& aimPos,
const CPlayer& player, bool gravity, float dt) {
return PredictInterceptPos(gunPos, aimPos, player, gravity, GetProjectileSpeed(), dt);
2018-06-04 19:30:04 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde