metaforce/Runtime/World/CPlayer.cpp

6280 lines
229 KiB
C++
Raw Normal View History

2019-09-18 15:37:36 +00:00
#include "Runtime/World/CPlayer.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <string>
2019-09-18 15:37:36 +00:00
#include "Runtime/CDependencyGroup.hpp"
#include "Runtime/CGameState.hpp"
#include "Runtime/Factory/CSimplePool.hpp"
2019-09-18 15:37:36 +00:00
#include "Runtime/CStateManager.hpp"
#include "Runtime/Audio/CStreamAudioManager.hpp"
#include "Runtime/Camera/CBallCamera.hpp"
#include "Runtime/Camera/CCinematicCamera.hpp"
#include "Runtime/Camera/CFirstPersonCamera.hpp"
#include "Runtime/Character/CSteeringBehaviors.hpp"
#include "Runtime/Collision/CGameCollision.hpp"
#include "Runtime/Collision/CMetroidAreaCollider.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/Input/ControlMapper.hpp"
#include "Runtime/MP1/CSamusHud.hpp"
#include "Runtime/MP1/World/CMetroidBeta.hpp"
#include "Runtime/MP1/World/CThardusRockProjectile.hpp"
#include "Runtime/Weapon/CEnergyProjectile.hpp"
#include "Runtime/World/CActorParameters.hpp"
#include "Runtime/World/CHUDBillboardEffect.hpp"
#include "Runtime/World/CPatterned.hpp"
#include "Runtime/World/CScriptAreaAttributes.hpp"
#include "Runtime/World/CScriptGrapplePoint.hpp"
#include "Runtime/World/CScriptPlayerHint.hpp"
#include "Runtime/World/CScriptWater.hpp"
#include <logvisor/logvisor.hpp>
#include "TCastTo.hpp" // Generated file, do not modify include path
2021-04-10 08:42:06 +00:00
namespace metaforce {
namespace {
2021-04-10 08:42:06 +00:00
logvisor::Module Log("metaforce::CPlayer");
constexpr CMaterialFilter SolidMaterialFilter = CMaterialFilter::MakeInclude(CMaterialList(EMaterialTypes::Solid));
2017-07-18 06:11:37 +00:00
constexpr CMaterialFilter LineOfSightFilter = CMaterialFilter::MakeIncludeExclude(
2018-12-08 05:30:43 +00:00
{EMaterialTypes::Solid},
{EMaterialTypes::ProjectilePassthrough, EMaterialTypes::ScanPassthrough, EMaterialTypes::Player});
2017-07-18 06:11:37 +00:00
constexpr CMaterialFilter OccluderFilter = CMaterialFilter::MakeIncludeExclude(
2018-12-08 05:30:43 +00:00
{EMaterialTypes::Solid, EMaterialTypes::Occluder},
{EMaterialTypes::ProjectilePassthrough, EMaterialTypes::ScanPassthrough, EMaterialTypes::Player});
2017-07-27 05:15:51 +00:00
constexpr CMaterialFilter BallTransitionCollide = CMaterialFilter::MakeIncludeExclude(
{EMaterialTypes::Solid}, {EMaterialTypes::ProjectilePassthrough, EMaterialTypes::Player, EMaterialTypes::Character,
EMaterialTypes::CameraPassthrough});
constexpr std::array<float, 8> skStrafeDistances{
11.8f, 11.8f, 11.8f, 5.0f, 6.0f, 5.0f, 5.0f, 6.0f,
};
constexpr std::array<float, 8> skDashStrafeDistances{
11.8f, 30.0f, 22.6f, 10.0f, 10.0f, 10.0f, 10.0f, 10.0f,
};
constexpr std::array<float, 8> skOrbitForwardDistances{
11.8f, 11.8f, 11.8f, 5.0f, 6.0f, 5.0f, 5.0f, 6.0f,
};
constexpr std::array<const char*, 2> UnlockMessageResBases{
"STRG_SlideShow_Unlock1_",
"STRG_SlideShow_Unlock2_",
};
constexpr std::array<u16, 24> skPlayerLandSfxSoft{
0xFFFF,
SFXsam_landstone_00,
SFXsam_landmetl_00,
SFXsam_landgrass_00,
SFXsam_landice_00,
0xFFFF,
SFXsam_landgrate_00,
SFXsam_landphazon_00,
SFXsam_landdirt_00,
SFXlav_landlava_00,
SFXsam_landlavastone_00,
SFXsam_landsnow_00,
SFXsam_landmud_00,
0xFFFF,
SFXsam_landgrass_00,
SFXsam_landmetl_00,
SFXsam_landmetl_00,
SFXsam_landdirt_00,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
SFXsam_landwood_00,
SFXsam_b_landorg_00,
};
constexpr std::array<u16, 24> skPlayerLandSfxHard{
0xFFFF,
SFXsam_landstone_02,
SFXsam_b_landmetl_02,
SFXsam_landgrass_02,
SFXsam_landice_02,
0xFFFF,
SFXsam_landgrate_02,
SFXsam_landphazon_02,
SFXsam_landdirt_02,
SFXlav_landlava_02,
SFXsam_landlavastone_02,
SFXsam_landsnow_02,
SFXsam_landmud_02,
0xFFFF,
SFXsam_landgrass_02,
SFXsam_b_landmetl_02,
SFXsam_b_landmetl_02,
SFXsam_landdirt_02,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
SFXsam_landwood_02,
SFXsam_landorg_02,
};
constexpr std::array<u16, 24> skLeftStepSounds{
0xFFFF,
SFXsam_wlkstone_00,
SFXsam_wlkmetal_00,
SFXsam_b_wlkgrass_00,
SFXsam_wlkice_00,
0xFFFF,
SFXsam_wlkgrate_00,
SFXsam_wlkphazon_00,
SFXsam_wlkdirt_00,
SFXlav_wlklava_00,
SFXsam_wlklavastone_00,
SFXsam_wlksnow_00,
SFXsam_wlkmud_00,
0xFFFF,
SFXsam_b_wlkorg_00,
SFXsam_wlkmetal_00,
SFXsam_wlkmetal_00,
SFXsam_wlkdirt_00,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
SFXsam_wlkwood_00,
SFXsam_b_wlkorg_00,
};
constexpr std::array<u16, 24> skRightStepSounds{
0xFFFF,
SFXsam_wlkstone_01,
SFXsam_wlkmetal_01,
SFXsam_b_wlkgrass_01,
SFXsam_wlkice_01,
0xFFFF,
SFXsam_wlkgrate_01,
SFXsam_wlkphazon_01,
SFXsam_wlkdirt_01,
SFXlav_wlklava_01,
SFXsam_wlklavastone_01,
SFXsam_wlksnow_01,
SFXsam_wlkmud_01,
0xFFFF,
SFXsam_b_wlkorg_01,
SFXsam_wlkmetal_01,
SFXsam_wlkmetal_01,
SFXsam_wlkdirt_01,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
SFXsam_wlkwood_01,
SFXsam_b_wlkorg_01,
};
constexpr float RCP_2PI = 0.15915494;
constexpr std::array<std::pair<CPlayerState::EItemType, ControlMapper::ECommands>, 4> skVisorToItemMapping{{
{CPlayerState::EItemType::CombatVisor, ControlMapper::ECommands::NoVisor},
{CPlayerState::EItemType::XRayVisor, ControlMapper::ECommands::XrayVisor},
{CPlayerState::EItemType::ScanVisor, ControlMapper::ECommands::InviroVisor},
{CPlayerState::EItemType::ThermalVisor, ControlMapper::ECommands::ThermoVisor},
}};
CModelData MakePlayerAnimRes(CAssetId resId, const zeus::CVector3f& scale) {
2022-02-01 00:06:54 +00:00
return CModelData{CAnimRes(resId, 0, scale, 0, true)};
}
uint32_t GetOrbitScreenBoxHalfExtentXScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitScreenBoxHalfExtentX(zone) * g_Viewport.x8_width / 640;
2018-05-08 02:11:07 +00:00
}
uint32_t GetOrbitScreenBoxHalfExtentYScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitScreenBoxHalfExtentY(zone) * g_Viewport.xc_height / 448;
2018-05-08 02:11:07 +00:00
}
uint32_t GetOrbitScreenBoxCenterXScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitScreenBoxCenterX(zone) * g_Viewport.x8_width / 640;
2018-05-08 02:11:07 +00:00
}
uint32_t GetOrbitScreenBoxCenterYScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitScreenBoxCenterY(zone) * g_Viewport.xc_height / 448;
2018-05-08 02:11:07 +00:00
}
uint32_t GetOrbitZoneIdealXScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitZoneIdealX(zone) * g_Viewport.x8_width / 640;
2018-05-08 02:11:07 +00:00
}
uint32_t GetOrbitZoneIdealYScaled(int zone) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetOrbitZoneIdealY(zone) * g_Viewport.xc_height / 448;
2018-05-08 02:11:07 +00:00
}
} // Anonymous namespace
2018-05-08 02:11:07 +00:00
2017-08-13 05:26:14 +00:00
CPlayer::CPlayer(TUniqueId uid, const zeus::CTransform& xf, const zeus::CAABox& aabb, CAssetId resId,
2017-08-16 05:34:02 +00:00
const zeus::CVector3f& playerScale, float mass, float stepUp, float stepDown, float ballRadius,
2016-09-01 09:31:18 +00:00
const CMaterialList& ml)
: CPhysicsActor(uid, true, "CPlayer", CEntityInfo(kInvalidAreaId, CEntity::NullConnectionList), xf,
MakePlayerAnimRes(resId, playerScale), ml, aabb, SMoverData(mass), CActorParameters::None(), stepUp,
2018-12-08 05:30:43 +00:00
stepDown)
, x2d8_fpBounds(aabb)
, x7d0_animRes(resId, 0, playerScale, 0, true)
, x7d8_beamScale(playerScale) {
x490_gun = std::make_unique<CPlayerGun>(uid);
2018-12-08 05:30:43 +00:00
x49c_gunHolsterRemTime = g_tweakPlayerGun->GetGunNotFiringTime();
x4a0_failsafeTest = std::make_unique<CFailsafeTest>();
x76c_cameraBob =
std::make_unique<CPlayerCameraBob>(CPlayerCameraBob::ECameraBobType::One, CPlayerCameraBob::GetCameraBobExtent(),
CPlayerCameraBob::GetCameraBobPeriod());
const CAssetId beamId = g_tweakPlayerRes->GetBeamBallTransitionModel(x7ec_beam);
2018-12-08 05:30:43 +00:00
x7f0_ballTransitionBeamModel = std::make_unique<CModelData>(CStaticRes(beamId, playerScale));
x730_transitionModels.reserve(3);
x768_morphball = std::make_unique<CMorphBall>(*this, ballRadius);
2018-12-08 05:30:43 +00:00
SetInertiaTensorScalar(xe8_mass);
x1f4_lastNonCollidingState = GetMotionState();
x490_gun->SetTransform(x34_transform);
x490_gun->GetGrappleArm().SetTransform(x34_transform);
InitializeBallTransition();
const zeus::CAABox ballTransAABB = x64_modelData->GetBounds();
2018-12-08 05:30:43 +00:00
x2f0_ballTransHeight = ballTransAABB.max.z() - ballTransAABB.min.z();
SetCalculateLighting(true);
x90_actorLights->SetCastShadows(true);
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x50c_moveDir.normalize();
}
2018-12-08 05:30:43 +00:00
x2b4_accelerationTable.push_back(20.f);
x2b4_accelerationTable.push_back(80.f);
x2b4_accelerationTable.push_back(80.f);
x2b4_accelerationTable.push_back(270.f);
SetMaximumCollisionVelocity(25.f);
x354_onScreenOrbitObjects.reserve(64);
x344_nearbyOrbitObjects.reserve(64);
x364_offScreenOrbitObjects.reserve(64);
x64_modelData->SetScale(playerScale);
x7f0_ballTransitionBeamModel->SetScale(playerScale);
LoadAnimationTokens();
2019-06-01 03:41:01 +00:00
_CreateReflectionCube();
2018-12-08 05:30:43 +00:00
}
void CPlayer::InitializeBallTransition() {
if (x64_modelData && x64_modelData->HasAnimData()) {
x64_modelData->GetAnimationData()->SetAnimation(CAnimPlaybackParms(2, -1, 1.f, true), false);
}
}
bool CPlayer::IsTransparent() const { return x588_alpha < 1.f; }
2018-12-08 05:30:43 +00:00
float CPlayer::GetTransitionAlpha(const zeus::CVector3f& camPos, float zNear) const {
const float zLimit = (x2d8_fpBounds.max.x() - x2d8_fpBounds.min.x()) * 0.5f + zNear;
const float zStart = 1.f + zLimit;
const float dist = (camPos - GetEyePosition()).magnitude();
if (dist >= zLimit && dist <= zStart) {
2018-12-08 05:30:43 +00:00
return (dist - zLimit) / (zStart - zLimit);
}
if (dist > zStart) {
2018-12-08 05:30:43 +00:00
return 1.f;
}
return 0.f;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
s32 CPlayer::ChooseTransitionToAnimation(float dt, CStateManager& mgr) const {
if (x258_movementState == EPlayerMovementState::ApplyJump) {
2018-12-08 05:30:43 +00:00
return 3; // B_airposetoball_samus
}
const zeus::CVector3f localVel = x34_transform.transposeRotate(x138_velocity);
2018-12-08 05:30:43 +00:00
zeus::CVector3f localVelFlat = localVel;
localVelFlat.z() = 0.f;
const float localVelFlatMag = localVelFlat.magnitude();
if (localVelFlatMag <= 1.f) {
2018-12-08 05:30:43 +00:00
return 2; // B_readytoball_samus
}
float velAng = std::atan2(-localVelFlat.x(), localVelFlat.y());
constexpr float twoPi = zeus::degToRad(360.f);
if (velAng > twoPi) {
velAng = velAng - static_cast<int>(velAng * RCP_2PI) * twoPi;
} else if (velAng < 0.f) {
velAng = twoPi + (velAng - static_cast<int>(velAng * RCP_2PI) * twoPi);
}
const float velDeg = zeus::radToDeg(velAng);
if (velDeg >= 45.f && velDeg <= 315.f) {
return 1; // B_readytostationarybackwards_samus
}
if (localVelFlatMag < 0.5f * GetActualFirstPersonMaxVelocity(dt)) {
return 0; // B_forwardtoballforward_samus
}
return 4; // B_runtoballfoward_samus
2018-12-08 05:30:43 +00:00
}
void CPlayer::TransitionToMorphBallState(float dt, CStateManager& mgr) {
x584_ballTransitionAnim = ChooseTransitionToAnimation(dt, mgr);
x58c_transitionVel = x138_velocity.magnitude();
if (x64_modelData && x64_modelData->HasAnimData()) {
const CAnimPlaybackParms parms(x584_ballTransitionAnim, -1, 1.f, true);
x64_modelData->GetAnimationData()->SetAnimation(parms, false);
x64_modelData->GetAnimationData()->SetAnimDir(CAnimData::EAnimDir::Forward);
2018-12-08 05:30:43 +00:00
}
x64_modelData->EnableLooping(false);
x64_modelData->Touch(mgr, 0);
x150_momentum = zeus::skZero3f;
2018-12-08 05:30:43 +00:00
CPhysicsActor::Stop();
SetMorphBallState(EPlayerMorphBallState::Morphing, mgr);
SetCameraState(EPlayerCameraState::Transitioning, mgr);
x500_lookDir = x34_transform.basis[1];
x50c_moveDir = x500_lookDir;
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
x50c_moveDir.normalize();
} else {
x500_lookDir = zeus::skForward;
x50c_moveDir = zeus::skForward;
2018-12-08 05:30:43 +00:00
}
CBallCamera* ballCam = mgr.GetCameraManager()->GetBallCamera();
mgr.GetCameraManager()->SetPlayerCamera(mgr, ballCam->GetUniqueId());
if (!mgr.GetCameraManager()->HasBallCameraInitialPositionHint(mgr)) {
mgr.GetCameraManager()->SetupBallCamera(mgr);
ballCam->SetState(CBallCamera::EBallCameraState::ToBall, mgr);
} else {
ballCam->SetState(CBallCamera::EBallCameraState::Default, mgr);
SetCameraState(EPlayerCameraState::Ball, mgr);
const zeus::CTransform newXf = mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform();
2018-12-08 05:30:43 +00:00
ballCam->SetTransform(newXf);
ballCam->TeleportCamera(newXf.origin, mgr);
mgr.GetCameraManager()->SetupBallCamera(mgr);
ballCam->SetFovInterpolation(mgr.GetCameraManager()->GetFirstPersonCamera()->GetFov(),
CCameraManager::ThirdPersonFOV(), 1.f, 0.f);
}
SetOrbitRequest(EPlayerOrbitRequest::EnterMorphBall, mgr);
x490_gun->CancelFiring(mgr);
HolsterGun(mgr);
}
void CPlayer::TransitionFromMorphBallState(CStateManager& mgr) {
x584_ballTransitionAnim = 14; // B_ball_unfurl
x58c_transitionVel = zeus::CVector2f(x138_velocity.x(), x138_velocity.y()).magnitude();
if (x58c_transitionVel < 1.f) {
2018-12-08 05:30:43 +00:00
x584_ballTransitionAnim = 5; // ballstationarytoready_random
}
2018-12-08 05:30:43 +00:00
if (x258_movementState != EPlayerMovementState::OnGround) {
const zeus::CVector3f ballPos = GetBallPosition();
if (mgr.RayCollideWorld(ballPos, ballPos + zeus::CVector3f(0.f, 0.f, -7.f), BallTransitionCollide, this)) {
2018-12-08 05:30:43 +00:00
x584_ballTransitionAnim = 7; // B_balljumptoairpose
}
2018-12-08 05:30:43 +00:00
}
if (x64_modelData && x64_modelData->HasAnimData()) {
const CAnimPlaybackParms parms(x584_ballTransitionAnim, -1, 1.f, true);
x64_modelData->GetAnimationData()->SetAnimation(parms, false);
x64_modelData->GetAnimationData()->SetAnimDir(CAnimData::EAnimDir::Forward);
2018-12-08 05:30:43 +00:00
}
x64_modelData->EnableLooping(false);
x64_modelData->Touch(mgr, 0);
SetMorphBallState(EPlayerMorphBallState::Unmorphing, mgr);
x768_morphball->LeaveMorphBallState(mgr);
mgr.GetCameraManager()->SetPlayerCamera(mgr, mgr.GetCameraManager()->GetFirstPersonCamera()->GetUniqueId());
2018-12-08 05:30:43 +00:00
zeus::CVector3f camToPlayer = GetTranslation() - mgr.GetCameraManager()->GetBallCamera()->GetTranslation();
if (camToPlayer.canBeNormalized()) {
camToPlayer.normalize();
zeus::CVector3f vecFlat = x500_lookDir;
vecFlat.z() = 0.f;
zeus::CVector3f f31 = vecFlat.canBeNormalized() && vecFlat.magnitude() >= 0.1f ? x518_leaveMorphDir : camToPlayer;
if (x9c6_26_outOfBallLookAtHint) {
if (const TCastToConstPtr<CScriptPlayerHint> hint = mgr.GetObjectById(x830_playerHint)) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f deltaFlat = hint->GetTranslation() - GetTranslation();
deltaFlat.z() = 0.f;
if (deltaFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
f31 = deltaFlat.normalized();
}
2018-12-08 05:30:43 +00:00
}
}
if (x9c7_25_outOfBallLookAtHintActor) {
if (const TCastToConstPtr<CScriptPlayerHint> hint = mgr.GetObjectById(x830_playerHint)) {
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(hint->GetActorId())) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f deltaFlat = act->GetOrbitPosition(mgr) - GetTranslation();
deltaFlat.z() = 0.f;
if (deltaFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
f31 = deltaFlat.normalized();
}
2018-12-08 05:30:43 +00:00
}
}
}
2018-12-08 05:30:43 +00:00
if (std::acos(zeus::clamp(-1.f, camToPlayer.dot(f31), 1.f)) < M_PIF / 1.2f || x9c7_25_outOfBallLookAtHintActor) {
SetTransform(zeus::lookAt(GetTranslation(), GetTranslation() + f31));
} else {
SetTransform(zeus::lookAt(GetTranslation(), GetTranslation() + camToPlayer));
UpdateArmAndGunTransforms(0.01f, mgr);
}
} else {
SetTransform(CreateTransformFromMovementDirection());
}
CBallCamera* ballCam = mgr.GetCameraManager()->GetBallCamera();
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(ballCam->GetTooCloseActorId())) {
2018-12-08 05:30:43 +00:00
if (ballCam->GetTooCloseActorDistance() < 20.f && ballCam->GetTooCloseActorDistance() > 1.f) {
zeus::CVector3f deltaFlat = act->GetTranslation() - GetTranslation();
deltaFlat.z() = 0.f;
zeus::CVector3f deltaFlat2 = act->GetTranslation() - ballCam->GetTranslation();
deltaFlat2.z() = 0.f;
if (deltaFlat.canBeNormalized() && deltaFlat2.canBeNormalized()) {
deltaFlat.normalize();
zeus::CVector3f camLookFlat = ballCam->GetTransform().basis[1];
camLookFlat.z() = 0.f;
camLookFlat.normalize();
deltaFlat2.normalize();
if (deltaFlat.dot(deltaFlat2) >= 0.3f && deltaFlat2.dot(camLookFlat) >= 0.7f) {
SetTransform(zeus::lookAt(GetTranslation(), GetTranslation() + deltaFlat));
}
}
}
}
ForceGunOrientation(x34_transform, mgr);
DrawGun(mgr);
ballCam->SetState(CBallCamera::EBallCameraState::FromBall, mgr);
ClearForcesAndTorques();
SetAngularVelocityWR(zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
AddMaterial(EMaterialTypes::GroundCollider, mgr);
x150_momentum = zeus::skZero3f;
2018-12-08 05:30:43 +00:00
SetCameraState(EPlayerCameraState::Transitioning, mgr);
x824_transitionFilterTimer = 0.01f;
x57c_ = 0;
x580_ = 0;
if (!ballCam->TransitionFromMorphBallState(mgr)) {
x824_transitionFilterTimer = 0.95f;
LeaveMorphBallState(mgr);
}
}
s32 CPlayer::GetNextBallTransitionAnim(float dt, bool& loopOut, CStateManager& mgr) {
loopOut = false;
const zeus::CVector2f vel(x138_velocity.x(), x138_velocity.y());
if (!vel.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
return 12; // B_ball_ready_samus
}
const float velMag = vel.magnitude();
const float maxVel = GetActualFirstPersonMaxVelocity(dt);
if (velMag <= 0.2f * maxVel) {
2018-12-08 05:30:43 +00:00
return 12; // B_ball_ready_samus
}
2018-12-08 05:30:43 +00:00
loopOut = true;
const s32 ret = velMag >= maxVel ? 13 : 15; // B_ball_runloop_samus : B_ball_walkloop_samus
if (x50c_moveDir.dot(mgr.GetCameraManager()->GetBallCamera()->GetTransform().basis[1]) < -0.5f) {
2018-12-08 05:30:43 +00:00
return 12; // B_ball_ready_samus
}
2018-12-08 05:30:43 +00:00
return ret;
}
void CPlayer::UpdateMorphBallTransition(float dt, CStateManager& mgr) {
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
case EPlayerMorphBallState::Morphed: {
2020-03-11 13:48:30 +00:00
CPlayerState::EPlayerSuit suit = mgr.GetPlayerState()->GetCurrentSuitRaw();
if (mgr.GetPlayerState()->IsFusionEnabled()) {
2018-12-08 05:30:43 +00:00
suit = CPlayerState::EPlayerSuit(int(suit) + 4);
}
2018-12-08 05:30:43 +00:00
if (x7cc_transitionSuit != suit) {
x7cc_transitionSuit = suit;
CAnimRes useRes = x7d0_animRes;
useRes.SetCharacterNodeId(s32(x7cc_transitionSuit));
SetModelData(std::make_unique<CModelData>(useRes));
SetIntoBallReadyAnimation(mgr);
}
return;
}
case EPlayerMorphBallState::Unmorphing:
if (x584_ballTransitionAnim == 14) // B_ball_unfurl
{
const float dur = x64_modelData->GetAnimationData()->GetAnimationDuration(x584_ballTransitionAnim);
const float facRemaining = x64_modelData->GetAnimationData()->GetAnimTimeRemaining("Whole Body") / dur;
2018-12-08 05:30:43 +00:00
if (facRemaining < 0.5f) {
bool loop = false;
x584_ballTransitionAnim = GetNextBallTransitionAnim(dt, loop, mgr);
if (x64_modelData && x64_modelData->HasAnimData()) {
const CAnimPlaybackParms parms(x584_ballTransitionAnim, -1, 1.f, true);
x64_modelData->GetAnimationData()->SetAnimation(parms, false);
x64_modelData->GetAnimationData()->EnableLooping(loop);
2018-12-08 05:30:43 +00:00
}
}
} else if (x584_ballTransitionAnim != 5 && x584_ballTransitionAnim != 7)
// ballstationarytoready_random, B_balljumptoairpose
{
const float velMag = zeus::CVector2f(x138_velocity.x(), x138_velocity.y()).magnitude();
2018-12-08 05:30:43 +00:00
if (std::fabs(x58c_transitionVel - velMag) > 0.04f * GetActualFirstPersonMaxVelocity(dt) || velMag < 1.f) {
bool loop = false;
const s32 nextAnim = GetNextBallTransitionAnim(dt, loop, mgr);
2018-12-08 05:30:43 +00:00
if (x64_modelData && x64_modelData->HasAnimData() && x584_ballTransitionAnim != nextAnim &&
x584_ballTransitionAnim != 7) {
x584_ballTransitionAnim = nextAnim;
const CAnimPlaybackParms parms(x584_ballTransitionAnim, -1, 1.f, true);
x64_modelData->GetAnimationData()->SetAnimation(parms, false);
x64_modelData->GetAnimationData()->EnableLooping(loop);
2018-12-08 05:30:43 +00:00
x58c_transitionVel = velMag;
}
}
}
break;
default:
break;
}
const SAdvancementDeltas deltas = UpdateAnimation(dt, mgr, true);
2018-12-08 05:30:43 +00:00
MoveInOneFrameOR(deltas.x0_posDelta, dt);
RotateInOneFrameOR(deltas.xc_rotDelta, dt);
x574_morphTime = std::min(x574_morphTime + dt, x578_morphDuration);
const float morphT = x574_morphTime / x578_morphDuration;
if ((morphT >= 0.7f || x574_morphTime <= 2.f * dt) && x730_transitionModels.size() != 0) {
2018-12-08 05:30:43 +00:00
x730_transitionModels.erase(x730_transitionModels.begin());
}
2018-12-08 05:30:43 +00:00
for (auto& m : x730_transitionModels) {
2018-12-08 05:30:43 +00:00
m->AdvanceAnimation(dt, mgr, kInvalidAreaId, true);
}
2018-12-08 05:30:43 +00:00
const CGameCamera* cam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
2018-12-08 05:30:43 +00:00
x588_alpha = GetTransitionAlpha(cam->GetTranslation(), cam->GetNearClipDistance());
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing && morphT > 0.93f) {
x588_alpha *= std::min(1.f, 1.f - (morphT - 0.93f) / 0.07f + 0.2f);
xb4_drawFlags = CModelFlags(5, 0, 1, zeus::CColor(1.f, x588_alpha));
} else if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphing && x588_alpha < 1.f) {
if (x588_alpha > 0.05f) {
2018-12-08 05:30:43 +00:00
xb4_drawFlags = CModelFlags(5, 0, 0x21, zeus::CColor(1.f, x588_alpha));
} else {
2018-12-08 05:30:43 +00:00
xb4_drawFlags = CModelFlags(5, 0, 1, zeus::CColor(1.f, x588_alpha));
}
2018-12-08 05:30:43 +00:00
} else {
xb4_drawFlags = CModelFlags(5, 0, 3, zeus::CColor(1.f, x588_alpha));
}
x594_transisionBeamXfs.AddValue(x7f4_gunWorldXf);
x658_transitionModelXfs.AddValue(x34_transform);
x71c_transitionModelAlphas.AddValue(x588_alpha);
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphing:
2020-03-05 02:40:03 +00:00
(void)GetCollisionPrimitive()->CalculateAABox(GetPrimitiveTransform()).center();
2017-08-18 01:30:15 +00:00
ClearForcesAndTorques();
SetAngularVelocityWR(zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
if (x574_morphTime >= x578_morphDuration || mgr.GetCameraManager()->IsInCinematicCamera()) {
x824_transitionFilterTimer = std::max(x824_transitionFilterTimer, 0.95f);
zeus::CVector3f pos;
if (CanLeaveMorphBallState(mgr, pos)) {
SetTranslation(GetTranslation() + pos);
2017-08-18 01:30:15 +00:00
LeaveMorphBallState(mgr);
xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite);
2018-12-08 05:30:43 +00:00
} else {
x574_morphTime = x578_morphDuration - x574_morphTime;
TransitionToMorphBallState(dt, mgr);
}
}
break;
case EPlayerMorphBallState::Morphing:
ClearForcesAndTorques();
SetAngularVelocityWR(zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
if (x574_morphTime >= x578_morphDuration || mgr.GetCameraManager()->IsInCinematicCamera()) {
if (CanEnterMorphBallState(mgr, 1.f)) {
ActivateMorphBallCamera(mgr);
EnterMorphBallState(mgr);
xb4_drawFlags = CModelFlags(0, 0, 3, zeus::skWhite);
2018-12-08 05:30:43 +00:00
} else {
x574_morphTime = x578_morphDuration - x574_morphTime;
TransitionFromMorphBallState(mgr);
}
}
if (x578_morphDuration != 0.f) {
if (zeus::clamp(0.f, x574_morphTime, 1.f) >= 0.5f) {
if (!x768_morphball->IsMorphBallTransitionFlashValid()) {
2018-12-08 05:30:43 +00:00
x768_morphball->ResetMorphBallTransitionFlash();
}
2018-12-08 05:30:43 +00:00
}
}
break;
default:
break;
}
}
void CPlayer::UpdateGunAlpha() {
switch (x498_gunHolsterState) {
case EGunHolsterState::Holstered:
x494_gunAlpha = 0.f;
break;
case EGunHolsterState::Holstering:
x494_gunAlpha = zeus::clamp(0.f, x49c_gunHolsterRemTime / g_tweakPlayerGun->GetGunHolsterTime(), 1.f);
break;
case EGunHolsterState::Drawing:
x494_gunAlpha = 1.f - zeus::clamp(0.f, x49c_gunHolsterRemTime / 0.45f, 1.f);
break;
case EGunHolsterState::Drawn:
x494_gunAlpha = 1.f;
break;
}
}
void CPlayer::UpdatePlayerSounds(float dt) {
if (x784_damageSfxTimer <= 0.f) {
return;
}
x784_damageSfxTimer -= dt;
2018-12-08 05:30:43 +00:00
if (x784_damageSfxTimer > 0.f) {
return;
2018-12-08 05:30:43 +00:00
}
CSfxManager::SfxStop(x770_damageLoopSfx);
x770_damageLoopSfx.reset();
2018-12-08 05:30:43 +00:00
}
void CPlayer::Update(float dt, CStateManager& mgr) {
SetCoefficientOfRestitutionModifier(0.f);
UpdateMorphBallTransition(dt, mgr);
const CPlayerState::EBeamId newBeam = mgr.GetPlayerState()->GetCurrentBeam();
2018-12-08 05:30:43 +00:00
if (newBeam != x7ec_beam) {
x7ec_beam = newBeam;
x7f0_ballTransitionBeamModel = std::make_unique<CModelData>(
CStaticRes(g_tweakPlayerRes->GetBeamBallTransitionModel(x7ec_beam), x7d8_beamScale));
2018-12-08 05:30:43 +00:00
}
if (!mgr.GetPlayerState()->IsPlayerAlive()) {
if (x9f4_deathTime == 0.f) {
CSfxManager::KillAll(CSfxManager::ESfxChannels::Game);
CStreamAudioManager::StopAll();
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_death, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
}
const float prevDeathTime = x9f4_deathTime;
2018-12-08 05:30:43 +00:00
x9f4_deathTime += dt;
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed) {
if (x9f4_deathTime >= 1.f && prevDeathTime < 1.f) {
2018-12-08 05:30:43 +00:00
xa00_deathPowerBomb = x490_gun->DropPowerBomb(mgr);
}
2018-12-08 05:30:43 +00:00
if (x9f4_deathTime >= 4.f && prevDeathTime < 4.f) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_death, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
}
}
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
case EPlayerMorphBallState::Morphing:
case EPlayerMorphBallState::Unmorphing:
x7f4_gunWorldXf = x34_transform * x64_modelData->GetScaledLocatorTransform("GUN_LCTR");
2019-02-18 05:47:46 +00:00
break;
2018-12-08 05:30:43 +00:00
case EPlayerMorphBallState::Morphed:
break;
}
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
UpdateAimTargetTimer(dt);
UpdateAimTarget(mgr);
UpdateOrbitModeTimer(dt);
}
UpdateOrbitPreventionTimer(dt);
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
x768_morphball->Update(dt, mgr);
} else {
2018-12-08 05:30:43 +00:00
x768_morphball->StopSounds();
}
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphing ||
x2f8_morphBallState == EPlayerMorphBallState::Morphing) {
2018-12-08 05:30:43 +00:00
x768_morphball->UpdateEffects(dt, mgr);
}
2018-12-08 05:30:43 +00:00
UpdateGunAlpha();
UpdateDebugCamera(mgr);
UpdateVisorTransition(dt, mgr);
mgr.SetActorAreaId(*this, mgr.GetWorld()->GetCurrentAreaId());
UpdatePlayerSounds(dt);
if (x26c_attachedActor != kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
x270_attachedActorTime += dt;
}
2018-12-08 05:30:43 +00:00
x740_staticTimer = std::max(0.f, x740_staticTimer - dt);
if (x740_staticTimer > 0.f) {
2018-12-08 05:30:43 +00:00
x74c_visorStaticAlpha = std::max(0.f, x74c_visorStaticAlpha - x744_staticOutSpeed * dt);
} else {
2018-12-08 05:30:43 +00:00
x74c_visorStaticAlpha = std::min(1.f, x74c_visorStaticAlpha + x748_staticInSpeed * dt);
}
2018-12-08 05:30:43 +00:00
x274_energyDrain.ProcessEnergyDrain(mgr, dt);
x4a4_moveSpeedAvg.AddValue(x4f8_moveSpeed);
mgr.GetPlayerState()->UpdateStaticInterference(mgr, dt);
if (!ShouldSampleFailsafe(mgr)) {
2018-12-08 05:30:43 +00:00
CPhysicsActor::Stop();
}
2017-08-18 01:30:15 +00:00
if (IsEnergyLow(mgr)) {
2018-12-08 05:30:43 +00:00
xa30_samusExhaustedVoiceTimer -= dt;
} else {
2018-12-08 05:30:43 +00:00
xa30_samusExhaustedVoiceTimer = 4.f;
}
2017-08-18 01:30:15 +00:00
2018-12-08 05:30:43 +00:00
if (!mgr.GetCameraManager()->IsInCinematicCamera() && xa30_samusExhaustedVoiceTimer <= 0.f) {
StartSamusVoiceSfx(SFXsam_vox_exhausted, 1.f, 7);
xa30_samusExhaustedVoiceTimer = 4.f;
}
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
float CPlayer::UpdateCameraBob(float dt, CStateManager& mgr) {
float bobMag = 0.f;
CPlayerCameraBob::ECameraBobState state;
const zeus::CVector3f backupVel = x138_velocity;
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::NoOrbit) {
bobMag = std::fabs(backupVel.dot(x34_transform.basis[1]) / GetActualFirstPersonMaxVelocity(dt));
state = CPlayerCameraBob::ECameraBobState::Walk;
if (bobMag < 0.01f) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::WalkNoBob;
2017-08-18 01:30:15 +00:00
}
2018-12-08 05:30:43 +00:00
} else {
state = CPlayerCameraBob::ECameraBobState::Orbit;
const float f29 = backupVel.dot(x34_transform.basis[0]);
const float f30 = backupVel.dot(x34_transform.basis[1]);
const float maxVel = GetActualFirstPersonMaxVelocity(dt);
const float strafeDist =
skStrafeDistances[size_t(x2b0_outOfWaterTicks == 2 ? x2ac_surfaceRestraint : ESurfaceRestraints::Water)];
2018-12-08 05:30:43 +00:00
bobMag = std::min(std::sqrt(f30 * f30 + f29 * f29) / std::sqrt(strafeDist * strafeDist + maxVel * maxVel) *
CPlayerCameraBob::GetOrbitBobScale(),
CPlayerCameraBob::GetMaxOrbitBobScale());
if (bobMag < 0.01f) {
2018-12-08 05:30:43 +00:00
bobMag = 0.f;
}
2018-12-08 05:30:43 +00:00
}
if (x258_movementState != EPlayerMovementState::OnGround) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::InAir;
} else if (bobMag < 0.01f) {
if (x490_gun->GetLastFireButtonStates() != 0) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::GunFireNoBob;
} else if (std::fabs(GetAngularVelocityOR().angle()) > 0.1f) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::TurningNoBob;
}
}
if (x3dc_inFreeLook || x3dd_lookButtonHeld) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::FreeLookNoBob;
}
if (x304_orbitState == EPlayerOrbitState::Grapple) {
bobMag = 0.f;
state = CPlayerCameraBob::ECameraBobState::GrappleNoBob;
}
if (x3a8_scanState == EPlayerScanState::ScanComplete) {
bobMag = 0.f;
}
if (x38c_doneSidewaysDashing) {
bobMag *= 0.1f;
state = CPlayerCameraBob::ECameraBobState::FreeLookNoBob;
if (x258_movementState == EPlayerMovementState::OnGround) {
2018-12-08 05:30:43 +00:00
x38c_doneSidewaysDashing = false;
}
2018-12-08 05:30:43 +00:00
}
2017-08-18 01:30:15 +00:00
if (mgr.GetCameraManager()->IsInCinematicCamera()) {
2018-12-08 05:30:43 +00:00
bobMag = 0.f;
}
2017-08-18 01:30:15 +00:00
2018-12-08 05:30:43 +00:00
bobMag *= mgr.GetCameraManager()->GetCameraBobMagnitude();
x76c_cameraBob->SetPlayerVelocity(backupVel);
x76c_cameraBob->SetState(state, mgr);
x76c_cameraBob->SetBobMagnitude(bobMag);
x76c_cameraBob->SetBobTimeScale((1.f - CPlayerCameraBob::GetSlowSpeedPeriodScale()) * bobMag +
CPlayerCameraBob::GetSlowSpeedPeriodScale());
2018-12-08 05:30:43 +00:00
x76c_cameraBob->Update(dt, mgr);
return bobMag;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
float CPlayer::GetAcceleration() const {
if (x2d0_curAcceleration >= x2b4_accelerationTable.size()) {
2018-12-08 05:30:43 +00:00
return x2b4_accelerationTable.back();
}
2018-12-08 05:30:43 +00:00
return x2b4_accelerationTable[x2d0_curAcceleration];
2017-08-18 01:30:15 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
float CPlayer::CalculateOrbitMinDistance(EPlayerOrbitType type) const {
return zeus::clamp(1.f, std::fabs(x314_orbitPoint.z() - GetTranslation().z()) / 20.f, 4.f) *
g_tweakPlayer->GetOrbitMinDistance(int(type));
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::PostUpdate(float dt, CStateManager& mgr) {
UpdateArmAndGunTransforms(dt, mgr);
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
float grappleSwingT;
if (x3b8_grappleState != EGrappleState::Swinging) {
2018-12-08 05:30:43 +00:00
grappleSwingT = 0.f;
} else {
2018-12-08 05:30:43 +00:00
grappleSwingT = x3bc_grappleSwingTimer / g_tweakPlayer->GetGrappleSwingPeriod();
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
float cameraBobT = 0.f;
if (mgr.GetCameraManager()->IsInCinematicCamera()) {
x76c_cameraBob = std::make_unique<CPlayerCameraBob>(CPlayerCameraBob::ECameraBobType::One,
CPlayerCameraBob::GetCameraBobExtent(),
CPlayerCameraBob::GetCameraBobPeriod());
2018-12-08 05:30:43 +00:00
} else {
cameraBobT = UpdateCameraBob(dt, mgr);
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
x490_gun->Update(grappleSwingT, cameraBobT, dt, mgr);
UpdateOrbitTarget(mgr);
UpdateOrbitOrientation(mgr);
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
bool CPlayer::StartSamusVoiceSfx(u16 sfx, float vol, int prio) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
bool started = true;
if (x77c_samusVoiceSfx) {
if (CSfxManager::IsPlaying(x77c_samusVoiceSfx)) {
started = false;
if (prio > x780_samusVoicePriority) {
CSfxManager::SfxStop(x77c_samusVoiceSfx);
started = true;
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
if (started) {
x77c_samusVoiceSfx = CSfxManager::SfxStart(sfx, vol, 0.f, false, 0x7f, false, kInvalidAreaId);
x780_samusVoicePriority = prio;
}
}
2018-12-08 05:30:43 +00:00
return started;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
bool CPlayer::IsPlayerDeadEnough() const {
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
2018-12-08 05:30:43 +00:00
return x9f4_deathTime > 2.5f;
}
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
return x9f4_deathTime > 6.f;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
return false;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::AsyncLoadSuit(CStateManager& mgr) { x490_gun->AsyncLoadSuit(mgr); }
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::LoadAnimationTokens() {
TLockedToken<CDependencyGroup> transGroup = g_SimplePool->GetObj("BallTransition_DGRP");
CDependencyGroup& group = *transGroup;
x25c_ballTransitionsRes.reserve(group.GetObjectTagVector().size());
for (const SObjectTag& tag : group.GetObjectTagVector()) {
if (tag.type == FOURCC('CMDL') || tag.type == FOURCC('CSKR') || tag.type == FOURCC('TXTR')) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
x25c_ballTransitionsRes.push_back(g_SimplePool->GetObj(tag));
}
}
bool CPlayer::HasTransitionBeamModel() const {
return x7f0_ballTransitionBeamModel && !x7f0_ballTransitionBeamModel->IsNull();
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::CanRenderUnsorted(const CStateManager& mgr) const { return false; }
const CDamageVulnerability* CPlayer::GetDamageVulnerability(const zeus::CVector3f& v1, const zeus::CVector3f& v2,
const CDamageInfo& info) const {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed && x570_immuneTimer > 0.f && !info.NoImmunity()) {
2018-12-08 05:30:43 +00:00
return &CDamageVulnerability::ImmuneVulnerabilty();
}
2018-12-08 05:30:43 +00:00
return &CDamageVulnerability::NormalVulnerabilty();
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
const CDamageVulnerability* CPlayer::GetDamageVulnerability() const {
constexpr CDamageInfo info(CWeaponMode(EWeaponType::Power, false, false, false), 0.f, 0.f, 0.f);
return GetDamageVulnerability(zeus::skZero3f, zeus::skUp, info);
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector3f CPlayer::GetHomingPosition(const CStateManager& mgr, float dt) const {
if (dt > 0.f) {
2018-12-08 05:30:43 +00:00
return x34_transform.origin + PredictMotion(dt).x0_translation;
}
2018-12-08 05:30:43 +00:00
return x34_transform.origin;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector3f CPlayer::GetAimPosition(const CStateManager& mgr, float dt) const {
zeus::CVector3f ret = x34_transform.origin;
if (dt > 0.f) {
if (x304_orbitState == EPlayerOrbitState::NoOrbit) {
2018-12-08 05:30:43 +00:00
ret += PredictMotion(dt).x0_translation;
} else {
2018-12-08 05:30:43 +00:00
ret = CSteeringBehaviors::ProjectOrbitalPosition(ret, x138_velocity, x314_orbitPoint, dt, xa04_preThinkDt);
}
2018-12-08 05:30:43 +00:00
}
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
ret.z() += g_tweakPlayer->GetPlayerBallHalfExtent();
} else {
2018-12-08 05:30:43 +00:00
ret.z() += GetEyeHeight();
}
2018-12-08 05:30:43 +00:00
return ret;
}
void CPlayer::FluidFXThink(EFluidState state, CScriptWater& water, CStateManager& mgr) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
x768_morphball->FluidFXThink(state, water, mgr);
if (state == EFluidState::InFluid) {
2018-12-08 05:30:43 +00:00
x9c5_30_selectFluidBallSound = true;
}
2018-12-08 05:30:43 +00:00
} else if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed) {
if (mgr.GetFluidPlaneManager()->GetLastSplashDeltaTime(x8_uid) >= 0.2f) {
zeus::CVector3f position(x34_transform.origin);
position.z() = float(water.GetTriggerBoundsWR().max.z());
mgr.GetFluidPlaneManager()->CreateSplash(x8_uid, mgr, water, position, 0.1f, state == EFluidState::EnteredFluid);
}
} else {
if (mgr.GetFluidPlaneManager()->GetLastSplashDeltaTime(x8_uid) >= 0.2f) {
zeus::CVector3f posOffset = x50c_moveDir;
if (posOffset.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
posOffset = posOffset.normalized() * zeus::CVector3f(1.2f, 1.2f, 0.f);
}
2018-12-08 05:30:43 +00:00
switch (state) {
case EFluidState::EnteredFluid: {
bool doSplash = true;
if (x4fc_flatMoveSpeed > 12.5f) {
const zeus::CVector3f lookDir = x34_transform.basis[1].normalized();
2018-12-08 05:30:43 +00:00
zeus::CVector3f dcVel = GetDampedClampedVelocityWR();
dcVel.z() = 0.f;
if (lookDir.dot(dcVel.normalized()) > 0.75f) {
2018-12-08 05:30:43 +00:00
doSplash = false;
}
2018-12-08 05:30:43 +00:00
}
if (doSplash) {
zeus::CVector3f position = x34_transform.origin + posOffset;
position.z() = float(water.GetTriggerBoundsWR().max.z());
mgr.GetFluidPlaneManager()->CreateSplash(x8_uid, mgr, water, position, 0.3f, true);
if (water.GetFluidPlane().GetFluidType() == EFluidType::NormalWater) {
const float velMag = mgr.GetPlayer().GetVelocity().magnitude() / 10.f;
2018-12-08 05:30:43 +00:00
mgr.GetEnvFxManager()->SetSplashRate(10.f * std::max(1.f, velMag));
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
break;
}
case EFluidState::InFluid: {
if (x138_velocity.magnitude() > 1.f && mgr.GetFluidPlaneManager()->GetLastRippleDeltaTime(x8_uid) >= 0.2f) {
zeus::CVector3f position(x34_transform.origin);
position.z() = float(water.GetTriggerBoundsWR().max.z());
water.GetFluidPlane().AddRipple(0.5f, x8_uid, position, water, mgr);
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
break;
}
case EFluidState::LeftFluid: {
zeus::CVector3f position = x34_transform.origin + posOffset;
position.z() = float(water.GetTriggerBoundsWR().max.z());
mgr.GetFluidPlaneManager()->CreateSplash(x8_uid, mgr, water, position, 0.15f, true);
break;
}
default:
break;
}
}
}
}
void CPlayer::TakeDamage(bool significant, const zeus::CVector3f& location, float dam, EWeaponType type,
CStateManager& mgr) {
if (!significant) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (dam >= 0.f) {
x570_immuneTimer = 0.5f;
x55c_damageAmt = dam;
x560_prevDamageAmt = (type == EWeaponType::AI && dam == 0.00002f) ? 10.f : dam;
x564_damageLocation = location;
x558_wasDamaged = true;
bool doRumble = false;
u16 suitDamageSfx = 0;
u16 damageLoopSfx = 0;
u16 damageSamusVoiceSfx = 0;
2018-12-08 05:30:43 +00:00
switch (type) {
case EWeaponType::Phazon:
case EWeaponType::OrangePhazon:
damageLoopSfx = SFXphz_damage_lp;
damageSamusVoiceSfx = SFXsam_vox_damage_phazon;
break;
case EWeaponType::PoisonWater:
damageLoopSfx = SFXsam_damage_poison_lp;
damageSamusVoiceSfx = SFXsam_vox_damage_poison;
break;
case EWeaponType::Lava:
damageLoopSfx = SFXpds_lava_damage_lp;
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case EWeaponType::Heat:
damageSamusVoiceSfx = SFXsam_vox_damage_heat;
break;
default:
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
if (dam > 30.f) {
2018-12-08 05:30:43 +00:00
damageSamusVoiceSfx = SFXsam_vox_damage30;
} else if (dam > 15.f) {
2018-12-08 05:30:43 +00:00
damageSamusVoiceSfx = SFXsam_vox_damage15;
} else {
2018-12-08 05:30:43 +00:00
damageSamusVoiceSfx = SFXsam_vox_damage;
}
2018-12-08 05:30:43 +00:00
suitDamageSfx = SFXsam_suit_damage;
} else {
if (dam > 30.f) {
2018-12-08 05:30:43 +00:00
suitDamageSfx = SFXsam_ball_damage30;
} else if (dam > 15.f) {
2018-12-08 05:30:43 +00:00
suitDamageSfx = SFXsam_ball_damage15;
} else {
2018-12-08 05:30:43 +00:00
suitDamageSfx = SFXsam_ball_damage;
}
2018-12-08 05:30:43 +00:00
}
break;
2017-08-16 05:34:02 +00:00
}
if (damageSamusVoiceSfx != 0 && x774_samusVoiceTimeout <= 0.f) {
2018-12-08 05:30:43 +00:00
StartSamusVoiceSfx(damageSamusVoiceSfx, 1.f, 8);
x774_samusVoiceTimeout = mgr.GetActiveRandom()->Range(3.f, 4.f);
doRumble = true;
2017-08-16 05:34:02 +00:00
}
if (damageLoopSfx != 0 && !x9c7_24_noDamageLoopSfx && xa2c_damageLoopSfxDelayTicks >= 2) {
2018-12-08 05:30:43 +00:00
if (!x770_damageLoopSfx || x788_damageLoopSfxId != damageLoopSfx) {
if (x770_damageLoopSfx && x788_damageLoopSfxId != damageLoopSfx) {
2018-12-08 05:30:43 +00:00
CSfxManager::SfxStop(x770_damageLoopSfx);
}
2018-12-08 05:30:43 +00:00
x770_damageLoopSfx = CSfxManager::SfxStart(damageLoopSfx, 1.f, 0.f, false, 0x7f, true, kInvalidAreaId);
x788_damageLoopSfxId = damageLoopSfx;
}
x784_damageSfxTimer = 0.5f;
2017-08-16 05:34:02 +00:00
}
if (suitDamageSfx != 0) {
2018-12-08 05:30:43 +00:00
if (x770_damageLoopSfx) {
CSfxManager::SfxStop(x770_damageLoopSfx);
x770_damageLoopSfx.reset();
}
2019-01-23 07:52:19 +00:00
CSfxManager::SfxStart(suitDamageSfx, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
2018-12-08 05:30:43 +00:00
x788_damageLoopSfxId = suitDamageSfx;
xa2c_damageLoopSfxDelayTicks = 0;
doRumble = true;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
if (doRumble) {
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
2018-12-08 05:30:43 +00:00
x490_gun->DamageRumble(location, dam, mgr);
}
2018-12-08 05:30:43 +00:00
float tmp = x55c_damageAmt / 25.f;
if (std::fabs(tmp) > 1.f) {
2018-12-08 05:30:43 +00:00
tmp = tmp > 0.f ? 1.f : -1.f;
}
2018-12-08 05:30:43 +00:00
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerBump, tmp, ERumblePriority::One);
}
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed) {
x768_morphball->TakeDamage(x55c_damageAmt);
x768_morphball->SetDamageTimer(0.4f);
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
if (x3b8_grappleState != EGrappleState::None) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::DamageOnGrapple, mgr);
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::Accept(IVisitor& visitor) { visitor.Visit(this); }
2017-08-16 05:34:02 +00:00
CHealthInfo* CPlayer::HealthInfo(CStateManager& mgr) { return &mgr.GetPlayerState()->GetHealthInfo(); }
2017-08-16 05:34:02 +00:00
bool CPlayer::IsUnderBetaMetroidAttack(const CStateManager& mgr) const {
2018-12-08 05:30:43 +00:00
if (x274_energyDrain.GetEnergyDrainIntensity() > 0.f) {
for (const CEnergyDrainSource& source : x274_energyDrain.GetEnergyDrainSources()) {
if (CPatterned::CastTo<MP1::CMetroidBeta>(mgr.GetObjectById(source.GetEnergyDrainSourceId()))) {
2018-12-08 05:30:43 +00:00
return true;
}
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
return false;
2017-08-16 05:34:02 +00:00
}
std::optional<zeus::CAABox> CPlayer::GetTouchBounds() const {
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
return GetBoundingBox();
2018-12-08 05:30:43 +00:00
}
const float ballTouchRad = x768_morphball->GetBallTouchRadius();
const zeus::CVector3f ballCenter = GetTranslation() + zeus::CVector3f(0.f, 0.f, x768_morphball->GetBallRadius());
return zeus::CAABox(ballCenter - ballTouchRad, ballCenter + ballTouchRad);
2017-08-16 05:34:02 +00:00
}
2017-08-02 07:13:11 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::DoPreThink(float dt, CStateManager& mgr) {
PreThink(dt, mgr);
if (CEntity* ent = mgr.ObjectById(xa00_deathPowerBomb)) {
2018-12-08 05:30:43 +00:00
ent->PreThink(dt, mgr);
}
2017-08-19 06:52:13 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::DoThink(float dt, CStateManager& mgr) {
Think(dt, mgr);
if (CEntity* ent = mgr.ObjectById(xa00_deathPowerBomb)) {
2018-12-08 05:30:43 +00:00
ent->Think(dt, mgr);
}
2018-12-08 05:30:43 +00:00
}
2017-08-02 07:13:11 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateScanningState(const CFinalInput& input, CStateManager& mgr, float dt) {
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
SetScanningState(EPlayerScanState::NotScanning, mgr);
return;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
if (x3a8_scanState != EPlayerScanState::NotScanning && x3b4_scanningObject != x310_orbitTargetId &&
x310_orbitTargetId != kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
SetScanningState(EPlayerScanState::NotScanning, mgr);
}
2018-12-08 05:30:43 +00:00
switch (x3a8_scanState) {
case EPlayerScanState::NotScanning:
if (ValidateScanning(input, mgr)) {
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId)) {
2018-12-08 05:30:43 +00:00
const CScannableObjectInfo* scanInfo = act->GetScannableObjectInfo();
float scanTime = mgr.GetPlayerState()->GetScanTime(scanInfo->GetScannableObjectId());
if (scanTime >= 1.f) {
x9c6_30_newScanScanning = false;
scanTime = 1.f;
} else {
x9c6_30_newScanScanning = true;
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
SetScanningState(EPlayerScanState::Scanning, mgr);
x3ac_scanningTime = scanTime * scanInfo->GetTotalDownloadTime();
x3b0_curScanTime = 0.f;
}
}
break;
case EPlayerScanState::Scanning:
if (ValidateScanning(input, mgr)) {
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId)) {
2018-12-08 05:30:43 +00:00
if (const CScannableObjectInfo* scanInfo = act->GetScannableObjectInfo()) {
x3ac_scanningTime = std::min(scanInfo->GetTotalDownloadTime(), x3ac_scanningTime + dt);
x3b0_curScanTime += dt;
mgr.GetPlayerState()->SetScanTime(scanInfo->GetScannableObjectId(),
x3ac_scanningTime / scanInfo->GetTotalDownloadTime());
if (x3ac_scanningTime >= scanInfo->GetTotalDownloadTime() &&
x3b0_curScanTime >= g_tweakGui->GetScanSidesStartTime()) {
2018-12-08 05:30:43 +00:00
SetScanningState(EPlayerScanState::ScanComplete, mgr);
}
2018-12-08 05:30:43 +00:00
}
} else {
SetScanningState(EPlayerScanState::NotScanning, mgr);
}
} else {
SetScanningState(EPlayerScanState::NotScanning, mgr);
}
break;
case EPlayerScanState::ScanComplete:
if (!ValidateScanning(input, mgr)) {
2018-12-08 05:30:43 +00:00
SetScanningState(EPlayerScanState::NotScanning, mgr);
}
2018-12-08 05:30:43 +00:00
break;
}
}
bool CPlayer::ValidateScanning(const CFinalInput& input, const CStateManager& mgr) const {
2018-12-08 05:30:43 +00:00
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::ScanItem, input)) {
if (x304_orbitState == EPlayerOrbitState::OrbitObject) {
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId)) {
2018-12-08 05:30:43 +00:00
if (act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) {
const zeus::CVector3f targetToPlayer = GetTranslation() - act->GetTranslation();
if (targetToPlayer.canBeNormalized() && targetToPlayer.magnitude() < g_tweakPlayer->GetScanningRange()) {
2018-12-08 05:30:43 +00:00
return true;
}
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-06-12 04:23:34 +00:00
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
static bool IsDataLoreResearchScan(CAssetId id) {
const auto it = g_MemoryCardSys->LookupScanState(id);
if (it == g_MemoryCardSys->GetScanStates().cend()) {
2016-09-25 18:20:58 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
switch (it->second) {
case CWorldSaveGameInfo::EScanCategory::Data:
case CWorldSaveGameInfo::EScanCategory::Lore:
case CWorldSaveGameInfo::EScanCategory::Research:
2018-12-08 05:30:43 +00:00
return true;
default:
return false;
}
2016-09-25 18:20:58 +00:00
}
2018-12-08 05:30:43 +00:00
static CAssetId UpdatePersistentScanPercent(u32 prevLogScans, u32 logScans, u32 totalLogScans) {
if (prevLogScans == logScans) {
2018-12-08 05:30:43 +00:00
return {};
}
2018-12-08 05:30:43 +00:00
const float scanPercent = logScans / float(totalLogScans) * 100.f;
const float prevScanPercent = prevLogScans / float(totalLogScans) * 100.f;
const float scanMessageInterval = g_tweakSlideShow->GetScanPercentInterval();
const auto scanPercentProgStep = int(scanPercent / scanMessageInterval);
const auto prevScanPercentProgStep = int(prevScanPercent / scanMessageInterval);
const bool firstTime = scanPercent > g_GameState->SystemOptions().GetLogScanPercent();
2018-12-08 05:30:43 +00:00
if (firstTime) {
2018-12-08 05:30:43 +00:00
g_GameState->SystemOptions().SetLogScanPercent(u32(scanPercent));
}
2018-12-08 05:30:43 +00:00
if (scanPercentProgStep > prevScanPercentProgStep) {
const char* const messageResBase = UnlockMessageResBases[zeus::clamp(0, scanPercentProgStep - 1, 1)];
2021-05-26 02:49:24 +00:00
const auto message = std::string(messageResBase).append(1, firstTime ? '1' : '2');
const auto* const id = g_ResFactory->GetResourceIdByName(message);
if (id != nullptr) {
2018-12-08 05:30:43 +00:00
return id->id;
}
2018-12-08 05:30:43 +00:00
}
return {};
}
void CPlayer::FinishNewScan(CStateManager& mgr) {
const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId);
if (!act) {
return;
}
if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) {
return;
}
const auto* const scanInfo = act->GetScannableObjectInfo();
if (!scanInfo) {
return;
}
if (mgr.GetPlayerState()->GetScanTime(scanInfo->GetScannableObjectId()) < 1.f) {
return;
}
if (!IsDataLoreResearchScan(scanInfo->GetScannableObjectId())) {
return;
}
const auto scanCompletion = mgr.CalculateScanCompletionRate();
2021-06-07 19:29:18 +00:00
const CAssetId message =
UpdatePersistentScanPercent(mgr.GetPlayerState()->GetLogScans(), scanCompletion.first, scanCompletion.second);
if (message.IsValid()) {
mgr.ShowPausedHUDMemo(message, 0.f);
}
mgr.GetPlayerState()->SetScanCompletionRate(scanCompletion);
2018-12-08 05:30:43 +00:00
}
void CPlayer::SetScanningState(EPlayerScanState state, CStateManager& mgr) {
if (x3a8_scanState == state) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
mgr.SetGameState(CStateManager::EGameState::Running);
if (x3a8_scanState == EPlayerScanState::ScanComplete) {
if (TCastToPtr<CActor> act = mgr.ObjectById(x3b4_scanningObject)) {
2018-12-08 05:30:43 +00:00
act->OnScanStateChanged(EScanState::Done, mgr);
}
}
2018-12-08 05:30:43 +00:00
switch (state) {
case EPlayerScanState::NotScanning:
if (x3a8_scanState == EPlayerScanState::Scanning || x3a8_scanState == EPlayerScanState::ScanComplete) {
if (x9c6_30_newScanScanning) {
2018-12-08 05:30:43 +00:00
FinishNewScan(mgr);
}
}
2018-12-08 05:30:43 +00:00
x3ac_scanningTime = 0.f;
x3b0_curScanTime = 0.f;
if (!g_tweakPlayer->GetScanRetention()) {
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId)) {
if (act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) {
if (const auto* scanInfo = act->GetScannableObjectInfo()) {
if (mgr.GetPlayerState()->GetScanTime(scanInfo->GetScannableObjectId()) < 1.f) {
2018-12-08 05:30:43 +00:00
mgr.GetPlayerState()->SetScanTime(scanInfo->GetScannableObjectId(), 0.f);
}
}
}
}
}
2018-12-08 05:30:43 +00:00
x3b4_scanningObject = kInvalidUniqueId;
break;
case EPlayerScanState::Scanning:
x3b4_scanningObject = x310_orbitTargetId;
break;
case EPlayerScanState::ScanComplete:
if (g_tweakPlayer->GetScanFreezesGame()) {
2018-12-08 05:30:43 +00:00
mgr.SetGameState(CStateManager::EGameState::SoftPaused);
}
2018-12-08 05:30:43 +00:00
x3b4_scanningObject = x310_orbitTargetId;
break;
}
x3a8_scanState = state;
}
bool CPlayer::GetExplorationMode() const {
switch (x498_gunHolsterState) {
case EGunHolsterState::Holstering:
case EGunHolsterState::Holstered:
return true;
default:
return false;
}
}
2018-12-08 05:30:43 +00:00
bool CPlayer::GetCombatMode() const {
switch (x498_gunHolsterState) {
case EGunHolsterState::Drawing:
case EGunHolsterState::Drawn:
return true;
default:
return false;
}
}
2018-12-08 05:30:43 +00:00
void CPlayer::RenderGun(const CStateManager& mgr, const zeus::CVector3f& pos) const {
if (mgr.GetCameraManager()->IsInCinematicCamera()) {
2018-12-08 05:30:43 +00:00
return;
}
if (x490_gun->GetGrappleArm().GetActive() &&
x490_gun->GetGrappleArm().GetAnimState() != CGrappleArm::EArmState::Done) {
2018-12-08 05:30:43 +00:00
x490_gun->GetGrappleArm().RenderGrappleBeam(mgr, pos);
}
2018-12-08 05:30:43 +00:00
if (mgr.GetPlayerState()->GetActiveVisor(mgr) == CPlayerState::EPlayerVisor::Scan &&
mgr.GetPlayerState()->GetVisorTransitionFactor() >= 1.f) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if ((mgr.GetCameraManager()->IsInFirstPersonCamera() && x2f4_cameraState == EPlayerCameraState::FirstPerson) ||
(x2f8_morphBallState == EPlayerMorphBallState::Morphing &&
x498_gunHolsterState == EGunHolsterState::Holstering)) {
// CBooModel::SetReflectionCube(m_reflectionCube);
2018-12-08 05:30:43 +00:00
CModelFlags flags(5, 0, 3, zeus::CColor(1.f, x494_gunAlpha));
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x490_gun->Render(mgr, pos, flags);
}
}
void CPlayer::Render(CStateManager& mgr) {
2018-12-08 05:30:43 +00:00
bool doRender = x2f4_cameraState != EPlayerCameraState::Spawned;
if (!doRender) {
if (TCastToConstPtr<CCinematicCamera> cam = mgr.GetCameraManager()->GetCurrentCamera(mgr)) {
2018-12-08 05:30:43 +00:00
doRender = (x2f8_morphBallState == EPlayerMorphBallState::Morphed && cam->GetFlags() & 0x40);
}
}
2018-12-08 05:30:43 +00:00
if (x2f4_cameraState != EPlayerCameraState::FirstPerson && doRender) {
2019-07-21 08:42:52 +00:00
SCOPED_GRAPHICS_DEBUG_GROUP("CPlayer::Render", zeus::skOrange);
// CBooModel::SetReflectionCube(m_reflectionCube);
2018-12-08 05:30:43 +00:00
bool doTransitionRender = false;
bool doBallRender = false;
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
x64_modelData->Touch(mgr, 0);
CPhysicsActor::Render(mgr);
if (HasTransitionBeamModel()) {
x7f0_ballTransitionBeamModel->Touch(mgr, 0);
CModelFlags flags(0, 0, 3, zeus::skWhite);
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x7f0_ballTransitionBeamModel->Render(mgr, x7f4_gunWorldXf, x90_actorLights.get(), flags);
}
break;
case EPlayerMorphBallState::Morphing:
x768_morphball->TouchModel(mgr);
doTransitionRender = true;
doBallRender = true;
break;
case EPlayerMorphBallState::Unmorphing:
x490_gun->TouchModel(mgr);
doTransitionRender = true;
doBallRender = true;
break;
case EPlayerMorphBallState::Morphed:
x64_modelData->Touch(mgr, 0);
x768_morphball->Render(mgr, x90_actorLights.get());
break;
}
if (doTransitionRender) {
CPhysicsActor::Render(mgr);
if (HasTransitionBeamModel()) {
CModelFlags flags(5, 0, 3, zeus::CColor(1.f, x588_alpha));
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x7f0_ballTransitionBeamModel->Render(CModelData::EWhichModel::Normal, x7f4_gunWorldXf, x90_actorLights.get(),
flags);
}
float morphFactor = x574_morphTime / x578_morphDuration;
float transitionAlpha;
if (morphFactor < 0.05f) {
2018-12-08 05:30:43 +00:00
transitionAlpha = 0.f;
} else if (morphFactor < 0.1f) {
2018-12-08 05:30:43 +00:00
transitionAlpha = (morphFactor - 0.05f) / 0.05f;
} else if (morphFactor < 0.8f) {
2018-12-08 05:30:43 +00:00
transitionAlpha = 1.f;
} else {
2018-12-08 05:30:43 +00:00
transitionAlpha = 1.f - (morphFactor - 0.8f) / 0.2f;
}
2018-12-08 05:30:43 +00:00
const auto mdsp1 = int(x730_transitionModels.size() + 1);
2018-12-08 05:30:43 +00:00
for (int i = 0; i < x730_transitionModels.size(); ++i) {
const int ni = i + 1;
2021-06-07 19:29:18 +00:00
const float alpha =
transitionAlpha * (1.f - (ni + 1) / float(mdsp1)) * *x71c_transitionModelAlphas.GetEntry(ni);
2018-12-08 05:30:43 +00:00
if (alpha != 0.f) {
CModelData& data = *x730_transitionModels[i];
CModelFlags flags(5, 0, 3, zeus::CColor(1.f, alpha));
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
data.Render(CModelData::GetRenderingModel(mgr), *x658_transitionModelXfs.GetEntry(ni), x90_actorLights.get(),
flags);
if (HasTransitionBeamModel()) {
CModelFlags transFlags(5, 0, 3, zeus::CColor(1.f, alpha));
// transFlags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x7f0_ballTransitionBeamModel->Render(CModelData::EWhichModel::Normal, *x594_transisionBeamXfs.GetEntry(ni),
x90_actorLights.get(), transFlags);
2018-12-08 05:30:43 +00:00
}
}
}
if (doBallRender) {
float morphFactor = x574_morphTime / x578_morphDuration;
float ballAlphaStart = 0.75f;
float ballAlphaMag = 4.f;
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphing) {
ballAlphaStart = 0.875f;
morphFactor = 1.f - morphFactor;
ballAlphaMag = 8.f;
}
if (morphFactor > ballAlphaStart) {
CModelFlags flags(5, u8(x768_morphball->GetMorphballModelShader()), 3,
zeus::CColor(1.f, ballAlphaMag * (morphFactor - ballAlphaStart)));
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x768_morphball->GetMorphballModelData().Render(mgr, x768_morphball->GetBallToWorld(), x90_actorLights.get(),
flags);
}
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing) {
if (morphFactor > 0.5f) {
float tmp = (morphFactor - 0.5f) / 0.5f;
float rotate = 1.f - tmp;
float scale = 0.75f * rotate + 1.f;
float ballAlpha;
if (tmp < 0.1f) {
2018-12-08 05:30:43 +00:00
ballAlpha = 0.f;
} else if (tmp < 0.2f) {
2018-12-08 05:30:43 +00:00
ballAlpha = (tmp - 0.1f) / 0.1f;
} else if (tmp < 0.9f) {
2018-12-08 05:30:43 +00:00
ballAlpha = 1.f;
} else {
2018-12-08 05:30:43 +00:00
ballAlpha = 1.f - (morphFactor - 0.9f) / 0.1f;
}
2018-12-08 05:30:43 +00:00
const float theta = zeus::degToRad(360.f * rotate);
2018-12-08 05:30:43 +00:00
ballAlpha *= 0.5f;
if (ballAlpha > 0.f) {
CModelFlags flags(7, 0, 3, zeus::CColor(1.f, ballAlpha));
// flags.m_extendedShader = EExtendedShader::LightingCubeReflection;
2018-12-08 05:30:43 +00:00
x768_morphball->GetMorphballModelData().Render(
mgr,
x768_morphball->GetBallToWorld() * zeus::CTransform::RotateZ(theta) * zeus::CTransform::Scale(scale),
x90_actorLights.get(), flags);
}
}
x768_morphball->RenderMorphBallTransitionFlash(mgr);
}
}
}
}
}
2018-12-08 05:30:43 +00:00
void CPlayer::RenderReflectedPlayer(CStateManager& mgr) {
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
case EPlayerMorphBallState::Morphing:
case EPlayerMorphBallState::Unmorphing:
SetCalculateLighting(true);
if (x2f4_cameraState == EPlayerCameraState::FirstPerson) {
const zeus::CFrustum frustum;
2018-12-08 05:30:43 +00:00
CActor::PreRender(mgr, frustum);
}
2018-12-08 05:30:43 +00:00
CPhysicsActor::Render(mgr);
if (HasTransitionBeamModel()) {
constexpr CModelFlags flags(0, 0, 3, zeus::skWhite);
2018-12-08 05:30:43 +00:00
x7f0_ballTransitionBeamModel->Render(mgr, x7f4_gunWorldXf, nullptr, flags);
}
break;
case EPlayerMorphBallState::Morphed:
x768_morphball->Render(mgr, x90_actorLights.get());
break;
}
}
void CPlayer::PreRender(CStateManager& mgr, const zeus::CFrustum& frustum) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
SetCalculateLighting(false);
x768_morphball->PreRender(mgr, frustum);
} else {
SetCalculateLighting(true);
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
x490_gun->PreRender(mgr, frustum, mgr.GetCameraManager()->GetGlobalCameraTranslation(mgr));
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed || mgr.GetCameraManager()->IsInCinematicCamera()) {
x768_morphball->DeleteBallShadow();
} else {
x768_morphball->CreateBallShadow();
x768_morphball->RenderToShadowTex(mgr);
}
for (auto& model : x730_transitionModels) {
model->GetAnimationData()->PreRender();
}
2018-12-08 05:30:43 +00:00
if (x2f4_cameraState != EPlayerCameraState::FirstPerson) {
2018-12-08 05:30:43 +00:00
CActor::PreRender(mgr, frustum);
}
}
2018-12-08 05:30:43 +00:00
void CPlayer::CalculateRenderBounds() {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
const float rad = x768_morphball->GetBallRadius();
2018-12-08 05:30:43 +00:00
x9c_renderBounds = zeus::CAABox(GetTranslation() - zeus::CVector3f(rad, rad, 0.f),
GetTranslation() + zeus::CVector3f(rad, rad, rad * 2.f));
} else {
CActor::CalculateRenderBounds();
}
}
void CPlayer::AddToRenderer(const zeus::CFrustum& frustum, CStateManager& mgr) {
2018-12-08 05:30:43 +00:00
if (x2f4_cameraState != EPlayerCameraState::FirstPerson && x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
if (x768_morphball->IsInFrustum(frustum)) {
2018-12-08 05:30:43 +00:00
CActor::AddToRenderer(frustum, mgr);
} else {
2018-12-08 05:30:43 +00:00
x768_morphball->TouchModel(mgr);
}
2018-12-08 05:30:43 +00:00
} else {
x490_gun->AddToRenderer(frustum, mgr);
CActor::AddToRenderer(frustum, mgr);
}
}
void CPlayer::ComputeFreeLook(const CFinalInput& input) {
const float lookLeft = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookLeft, input);
const float lookRight = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookRight, input);
2018-12-08 05:30:43 +00:00
float lookUp = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookUp, input);
float lookDown = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookDown, input);
if (g_GameState->GameOptions().GetInvertYAxis()) {
lookUp = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookDown, input);
lookDown = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookUp, input);
}
if (!g_tweakPlayer->GetStayInFreeLookWhileFiring() &&
(ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) ||
x304_orbitState != EPlayerOrbitState::NoOrbit)) {
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
} else {
if (x3dc_inFreeLook) {
x3e8_horizFreeLookAngleVel = (lookLeft - lookRight) * g_tweakPlayer->GetHorizontalFreeLookAngleVel();
x3f0_vertFreeLookAngleVel = (lookUp - lookDown) * g_tweakPlayer->GetVerticalFreeLookAngleVel();
}
2018-12-08 05:30:43 +00:00
if (!x3de_lookAnalogHeld || !x3dd_lookButtonHeld) {
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
if (g_tweakPlayer->GetHoldButtonsForFreeLook()) {
if ((g_tweakPlayer->GetTwoButtonsForFreeLook() &&
(!ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold1, input) ||
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold2, input))) ||
(!ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold1, input) &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold2, input))) {
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
2017-07-20 06:04:40 +00:00
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
if (IsMorphBallTransitioning()) {
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
}
2017-03-24 05:30:16 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateFreeLookState(const CFinalInput& input, float dt, CStateManager& mgr) {
if (x304_orbitState == EPlayerOrbitState::ForcedOrbitObject || IsMorphBallTransitioning() ||
x2f8_morphBallState != EPlayerMorphBallState::Unmorphed ||
(x3b8_grappleState != EGrappleState::None && x3b8_grappleState != EGrappleState::Firing)) {
x3dc_inFreeLook = false;
x3dd_lookButtonHeld = false;
x3de_lookAnalogHeld = false;
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
x9c4_25_showCrosshairs = false;
return;
}
if (g_tweakPlayer->GetHoldButtonsForFreeLook()) {
if ((g_tweakPlayer->GetTwoButtonsForFreeLook() &&
(ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold1, input) &&
ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold2, input))) ||
(!g_tweakPlayer->GetTwoButtonsForFreeLook() &&
(ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold1, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::LookHold2, input)))) {
if (!x3dd_lookButtonHeld) {
const zeus::CVector3f lookDir = mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform().basis[1];
2018-12-08 05:30:43 +00:00
zeus::CVector3f lookDirFlat = lookDir;
lookDirFlat.z() = 0.f;
x3e4_freeLookYawAngle = 0.f;
if (lookDirFlat.canBeNormalized()) {
lookDirFlat.normalize();
x3ec_freeLookPitchAngle = std::acos(zeus::clamp(-1.f, lookDirFlat.dot(lookDir), 1.f));
if (lookDir.z() < 0.f)
x3ec_freeLookPitchAngle = -x3ec_freeLookPitchAngle;
}
}
x3dc_inFreeLook = true;
x3dd_lookButtonHeld = true;
x3de_lookAnalogHeld = (ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookLeft, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookRight, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookDown, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookUp, input) >= 0.1f);
} else {
x3dc_inFreeLook = false;
x3dd_lookButtonHeld = false;
x3de_lookAnalogHeld = false;
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
}
} else {
x3de_lookAnalogHeld = (ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookLeft, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookRight, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookDown, input) >= 0.1f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookUp, input) >= 0.1f);
x3dd_lookButtonHeld = false;
if (std::fabs(x3e4_freeLookYawAngle) < g_tweakPlayer->GetFreeLookCenteredThresholdAngle() &&
std::fabs(x3ec_freeLookPitchAngle) < g_tweakPlayer->GetFreeLookCenteredThresholdAngle()) {
if (x3e0_curFreeLookCenteredTime > g_tweakPlayer->GetFreeLookCenteredTime()) {
x3dc_inFreeLook = false;
x3e8_horizFreeLookAngleVel = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
} else {
x3e0_curFreeLookCenteredTime += dt;
}
} else {
x3dc_inFreeLook = true;
x3e0_curFreeLookCenteredTime = 0.f;
}
}
UpdateCrosshairsState(input);
}
void CPlayer::UpdateFreeLook(float dt) {
if (GetFrozenState()) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
float lookDeltaAngle = dt * g_tweakPlayer->GetFreeLookSpeed();
if (!x3de_lookAnalogHeld) {
2018-12-08 05:30:43 +00:00
lookDeltaAngle = dt * g_tweakPlayer->GetFreeLookSnapSpeed();
}
2018-12-08 05:30:43 +00:00
float angleVelP = x3f0_vertFreeLookAngleVel - x3ec_freeLookPitchAngle;
const float vertLookDamp = zeus::clamp(0.f, std::fabs(angleVelP / 1.0471976f), 1.f);
2018-12-08 05:30:43 +00:00
float dx = lookDeltaAngle * (2.f * vertLookDamp - std::sin((M_PIF / 2.f) * vertLookDamp));
if (0.f <= angleVelP) {
2018-12-08 05:30:43 +00:00
x3ec_freeLookPitchAngle += dx;
} else {
2018-12-08 05:30:43 +00:00
x3ec_freeLookPitchAngle -= dx;
}
2018-12-08 05:30:43 +00:00
angleVelP = x3e8_horizFreeLookAngleVel - x3e4_freeLookYawAngle;
dx = lookDeltaAngle * zeus::clamp(0.f, std::fabs(angleVelP / g_tweakPlayer->GetHorizontalFreeLookAngleVel()), 1.f);
if (0.f <= angleVelP) {
2018-12-08 05:30:43 +00:00
x3e4_freeLookYawAngle += dx;
} else {
2018-12-08 05:30:43 +00:00
x3e4_freeLookYawAngle -= dx;
}
if (g_tweakPlayer->GetFreeLookTurnsPlayer()) {
2018-12-08 05:30:43 +00:00
x3e4_freeLookYawAngle = 0.f;
}
2017-03-26 05:53:04 +00:00
}
2018-12-08 05:30:43 +00:00
float CPlayer::GetMaximumPlayerPositiveVerticalVelocity(CStateManager& mgr) const {
return mgr.GetPlayerState()->GetItemAmount(CPlayerState::EItemType::SpaceJumpBoots) ? 14.f : 11.666666f;
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::StartLandingControlFreeze() {
x760_controlsFrozen = true;
x764_controlsFrozenTimeout = 0.75f;
}
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::EndLandingControlFreeze() {
x760_controlsFrozen = false;
x764_controlsFrozenTimeout = 0.f;
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::ProcessFrozenInput(float dt, CStateManager& mgr) {
x764_controlsFrozenTimeout -= dt;
if (x764_controlsFrozenTimeout <= 0.f) {
EndLandingControlFreeze();
} else {
const CFinalInput dummy;
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
x768_morphball->ComputeBallMovement(dummy, mgr, dt);
x768_morphball->UpdateBallDynamics(mgr, dt);
} else {
ComputeMovement(dummy, mgr, dt);
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::ProcessInput(const CFinalInput& input, CStateManager& mgr) {
if (input.ControllerIdx() != 0) {
2018-12-08 05:30:43 +00:00
return;
}
2017-07-31 05:19:05 +00:00
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
UpdateScanningState(input, mgr, input.DeltaTime());
}
2017-07-31 05:19:05 +00:00
if (mgr.GetGameState() != CStateManager::EGameState::Running) {
2018-12-08 05:30:43 +00:00
return;
}
2017-07-31 05:19:05 +00:00
if (!mgr.GetPlayerState()->IsPlayerAlive()) {
2018-12-08 05:30:43 +00:00
return;
}
2017-07-31 05:19:05 +00:00
if (GetFrozenState()) {
2018-12-08 05:30:43 +00:00
UpdateFrozenState(input, mgr);
}
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
if (GetFrozenState()) {
if (x258_movementState == EPlayerMovementState::OnGround ||
x258_movementState == EPlayerMovementState::FallingMorphed) {
2018-12-08 05:30:43 +00:00
return;
}
2017-07-31 05:19:05 +00:00
const CFinalInput dummyInput;
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
x768_morphball->ComputeBallMovement(dummyInput, mgr, input.DeltaTime());
x768_morphball->UpdateBallDynamics(mgr, input.DeltaTime());
} else {
ComputeMovement(dummyInput, mgr, input.DeltaTime());
}
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (x760_controlsFrozen) {
ProcessFrozenInput(input.DeltaTime(), mgr);
return;
}
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed && x4a0_failsafeTest->Passes()) {
const auto* prim = static_cast<const CCollidableAABox*>(GetCollisionPrimitive());
const zeus::CAABox tmpAABB(prim->GetBox().min - 0.2f, prim->GetBox().max + 0.2f);
const CCollidableAABox tmpBox(tmpAABB, prim->GetMaterial());
2018-12-08 05:30:43 +00:00
CPhysicsActor::Stop();
const zeus::CAABox testBounds = prim->GetBox().getTransformedAABox(x34_transform);
const zeus::CAABox expandedBounds(testBounds.min - 3.f, testBounds.max + 3.f);
2018-12-08 05:30:43 +00:00
CAreaCollisionCache cache(expandedBounds);
CGameCollision::BuildAreaCollisionCache(mgr, cache);
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildColliderList(nearList, *this, expandedBounds);
const std::optional<zeus::CVector3f> nonIntVec =
CGameCollision::FindNonIntersectingVector(mgr, cache, *this, tmpBox, nearList);
2018-12-08 05:30:43 +00:00
if (nonIntVec) {
x4a0_failsafeTest->Reset();
SetTranslation(GetTranslation() + *nonIntVec);
}
}
UpdateGrappleState(input, mgr);
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
float leftDiv = g_tweakBall->GetLeftStickDivisor();
const float rightDiv = g_tweakBall->GetRightStickDivisor();
if (x26c_attachedActor != kInvalidUniqueId || IsUnderBetaMetroidAttack(mgr)) {
2018-12-08 05:30:43 +00:00
leftDiv = 2.f;
}
const CFinalInput scaledInput = input.ScaleAnalogueSticks(leftDiv, rightDiv);
2018-12-08 05:30:43 +00:00
x768_morphball->ComputeBallMovement(scaledInput, mgr, input.DeltaTime());
x768_morphball->UpdateBallDynamics(mgr, input.DeltaTime());
x4a0_failsafeTest->Reset();
} else {
if (x304_orbitState == EPlayerOrbitState::Grapple) {
ApplyGrappleForces(input, mgr, input.DeltaTime());
} else {
const CFinalInput scaledInput = input.ScaleAnalogueSticks(IsUnderBetaMetroidAttack(mgr) ? 3.f : 1.f, 1.f);
2018-12-08 05:30:43 +00:00
ComputeMovement(scaledInput, mgr, input.DeltaTime());
}
if (ShouldSampleFailsafe(mgr)) {
CFailsafeTest::EInputState inputState = CFailsafeTest::EInputState::Moving;
if (x258_movementState == EPlayerMovementState::ApplyJump) {
2018-12-08 05:30:43 +00:00
inputState = CFailsafeTest::EInputState::StartingJump;
} else if (x258_movementState == EPlayerMovementState::Jump) {
2018-12-08 05:30:43 +00:00
inputState = CFailsafeTest::EInputState::Jump;
}
2018-12-08 05:30:43 +00:00
x4a0_failsafeTest->AddSample(inputState, GetTranslation(), x138_velocity,
zeus::CVector2f(input.ALeftX(), input.ALeftY()));
}
}
ComputeFreeLook(input);
UpdateFreeLookState(input, input.DeltaTime(), mgr);
UpdateOrbitInput(input, mgr);
UpdateOrbitZone(mgr);
UpdateGunState(input, mgr);
UpdateVisorState(input, input.DeltaTime(), mgr);
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed ||
(x2f8_morphBallState == EPlayerMorphBallState::Unmorphed && x498_gunHolsterState == EGunHolsterState::Drawn)) {
x490_gun->ProcessInput(input, mgr);
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed && x26c_attachedActor != kInvalidUniqueId) {
if (ControlMapper::GetPressInput(ControlMapper::ECommands::TurnLeft, input) ||
ControlMapper::GetPressInput(ControlMapper::ECommands::TurnRight, input) ||
ControlMapper::GetPressInput(ControlMapper::ECommands::Forward, input) ||
ControlMapper::GetPressInput(ControlMapper::ECommands::Backward, input) ||
ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input)) {
xa28_attachedActorStruggle += input.DeltaTime() * 600.f * input.DeltaTime();
if (xa28_attachedActorStruggle > 1.f) {
2018-12-08 05:30:43 +00:00
xa28_attachedActorStruggle = 1.f;
}
2018-12-08 05:30:43 +00:00
} else {
const float tmp = 7.5f * input.DeltaTime();
2018-12-08 05:30:43 +00:00
xa28_attachedActorStruggle -= input.DeltaTime() * std::min(1.f, xa28_attachedActorStruggle * tmp + tmp);
if (xa28_attachedActorStruggle < 0.f) {
2018-12-08 05:30:43 +00:00
xa28_attachedActorStruggle = 0.f;
}
2018-12-08 05:30:43 +00:00
}
}
}
UpdateCameraState(mgr);
UpdateMorphBallState(input.DeltaTime(), input, mgr);
UpdateCameraTimers(input.DeltaTime(), input);
UpdateFootstepSounds(input, mgr, input.DeltaTime());
x2a8_timeSinceJump += input.DeltaTime();
if (CheckSubmerged()) {
2018-12-08 05:30:43 +00:00
SetSoundEventPitchBend(0);
} else {
2018-12-08 05:30:43 +00:00
SetSoundEventPitchBend(8192);
}
2018-12-08 05:30:43 +00:00
CalculateLeaveMorphBallDirection(input);
}
bool CPlayer::ShouldSampleFailsafe(CStateManager& mgr) const {
const TCastToConstPtr<CCinematicCamera> cineCam = mgr.GetCameraManager()->GetCurrentCamera(mgr);
if (!mgr.GetPlayerState()->IsPlayerAlive()) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
return x2f4_cameraState != EPlayerCameraState::Spawned || !cineCam || (cineCam->GetFlags() & 0x80) == 0;
}
void CPlayer::CalculateLeaveMorphBallDirection(const CFinalInput& input) {
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
x518_leaveMorphDir = x50c_moveDir;
} else {
if (ControlMapper::GetAnalogInput(ControlMapper::ECommands::Forward, input) > 0.3f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input) > 0.3f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnLeft, input) > 0.3f ||
ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnRight, input) > 0.3f) {
if (x138_velocity.magnitude() > 0.5f) {
2018-12-08 05:30:43 +00:00
x518_leaveMorphDir = x50c_moveDir;
}
2018-12-08 05:30:43 +00:00
}
}
}
void CPlayer::CalculatePlayerControlDirection(CStateManager& mgr) {
if (x9c4_30_controlDirOverride) {
if (x9d8_controlDirOverrideDir.canBeNormalized()) {
x540_controlDir = x9d8_controlDirOverrideDir.normalized();
x54c_controlDirFlat = x9d8_controlDirOverrideDir;
x54c_controlDirFlat.z() = 0.f;
if (x54c_controlDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x54c_controlDirFlat.normalize();
} else {
x540_controlDir = x54c_controlDirFlat = zeus::skForward;
}
2018-12-08 05:30:43 +00:00
} else {
x540_controlDir = x54c_controlDirFlat = zeus::skForward;
2018-12-08 05:30:43 +00:00
}
} else {
2021-06-07 19:29:18 +00:00
const zeus::CVector3f camToPlayer =
GetTranslation() - mgr.GetCameraManager()->GetCurrentCamera(mgr)->GetTranslation();
2018-12-08 05:30:43 +00:00
if (!camToPlayer.canBeNormalized()) {
x540_controlDir = x54c_controlDirFlat = zeus::skForward;
2018-12-08 05:30:43 +00:00
} else {
zeus::CVector3f camToPlayerFlat(camToPlayer.x(), camToPlayer.y(), 0.f);
if (camToPlayerFlat.canBeNormalized()) {
if (camToPlayerFlat.magnitude() > g_tweakBall->GetBallCameraControlDistance()) {
x540_controlDir = camToPlayer.normalized();
if (camToPlayerFlat.canBeNormalized()) {
camToPlayerFlat.normalize();
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphed:
x54c_controlDirFlat = camToPlayerFlat;
break;
default:
x540_controlDir = GetTransform().basis[1];
x54c_controlDirFlat = x540_controlDir;
x54c_controlDirFlat.z() = 0.f;
if (x54c_controlDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x54c_controlDirFlat.normalize();
}
2018-12-08 05:30:43 +00:00
}
} else if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
x540_controlDir = GetTransform().basis[1];
x54c_controlDirFlat.z() = 0.f;
if (x54c_controlDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x54c_controlDirFlat.normalize();
}
2018-12-08 05:30:43 +00:00
}
} else {
if (x4fc_flatMoveSpeed < 0.25f) {
x540_controlDir = camToPlayer;
x54c_controlDirFlat = camToPlayerFlat;
} else if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
x540_controlDir = GetTransform().basis[1];
x54c_controlDirFlat.z() = 0.f;
if (x54c_controlDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x54c_controlDirFlat.normalize();
}
2018-12-08 05:30:43 +00:00
}
}
}
}
}
}
void CPlayer::CalculatePlayerMovementDirection(float dt) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing ||
x2f8_morphBallState == EPlayerMorphBallState::Unmorphing) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
const zeus::CVector3f delta = GetTranslation() - x524_lastPosForDirCalc;
2018-12-08 05:30:43 +00:00
if (delta.canBeNormalized() && delta.magnitude() > 0.02f) {
x53c_timeMoving += dt;
x4f8_moveSpeed = std::fabs(delta.magnitude() / dt);
x500_lookDir = delta.normalized();
zeus::CVector3f flatDelta(delta.x(), delta.y(), 0.f);
if (flatDelta.canBeNormalized()) {
x4fc_flatMoveSpeed = std::fabs(flatDelta.magnitude() / dt);
flatDelta.normalize();
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphed:
if (x4fc_flatMoveSpeed > 0.25f) {
2018-12-08 05:30:43 +00:00
x50c_moveDir = flatDelta;
}
2018-12-08 05:30:43 +00:00
x530_gunDir = x50c_moveDir;
x524_lastPosForDirCalc = GetTranslation();
2017-07-31 05:19:05 +00:00
break;
2018-12-08 05:30:43 +00:00
default:
x500_lookDir = GetTransform().basis[1];
x50c_moveDir = x500_lookDir;
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x50c_moveDir.normalize();
}
2018-12-08 05:30:43 +00:00
x530_gunDir = x50c_moveDir;
x524_lastPosForDirCalc = GetTranslation();
2017-07-31 05:19:05 +00:00
break;
2018-12-08 05:30:43 +00:00
}
} else {
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
x500_lookDir = GetTransform().basis[1];
x50c_moveDir = x500_lookDir;
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x50c_moveDir.normalize();
}
2018-12-08 05:30:43 +00:00
x530_gunDir = x50c_moveDir;
x524_lastPosForDirCalc = GetTranslation();
}
x4fc_flatMoveSpeed = 0.f;
}
} else {
x53c_timeMoving = 0.f;
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphed:
case EPlayerMorphBallState::Morphing:
case EPlayerMorphBallState::Unmorphing:
x500_lookDir = x50c_moveDir;
break;
2017-07-30 01:06:06 +00:00
default:
2018-12-08 05:30:43 +00:00
x500_lookDir = GetTransform().basis[1];
x50c_moveDir = x500_lookDir;
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x50c_moveDir.normalize();
}
2018-12-08 05:30:43 +00:00
x530_gunDir = x50c_moveDir;
x524_lastPosForDirCalc = GetTranslation();
break;
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
x4f8_moveSpeed = 0.f;
x4fc_flatMoveSpeed = 0.f;
}
2018-12-08 05:30:43 +00:00
x50c_moveDir.z() = 0.f;
if (x50c_moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x500_lookDir.normalize();
}
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UnFreeze(CStateManager& stateMgr) {
if (!GetFrozenState()) {
return;
}
x750_frozenTimeout = 0.f;
x754_iceBreakJumps = 0;
CPhysicsActor::Stop();
ClearForcesAndTorques();
RemoveMaterial(EMaterialTypes::Immovable, stateMgr);
if (!stateMgr.GetCameraManager()->IsInCinematicCamera() && xa0c_iceTextureId.IsValid()) {
std::optional<TToken<CGenDescription>> gpsm;
gpsm.emplace(g_SimplePool->GetObj(SObjectTag(FOURCC('PART'), xa0c_iceTextureId)));
auto* effect = new CHUDBillboardEffect(gpsm, {}, stateMgr.AllocateUniqueId(), true, "FrostExplosion",
CHUDBillboardEffect::GetNearClipDistance(stateMgr),
CHUDBillboardEffect::GetScaleForPOV(stateMgr), zeus::skWhite, zeus::skOne3f,
zeus::skZero3f);
stateMgr.AddObject(effect);
CSfxHandle hnd = CSfxManager::SfxStart(SFXcrk_break_final, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
2018-12-08 05:30:43 +00:00
}
x768_morphball->Stop();
SetVisorSteam(0.f, 6.f / 14.f, 1.f / 14.f, xa08_steamTextureId, false);
2018-12-08 05:30:43 +00:00
}
void CPlayer::Freeze(CStateManager& stateMgr, CAssetId steamTxtr, u16 sfx, CAssetId iceTxtr) {
if (stateMgr.GetCameraManager()->IsInCinematicCamera() || GetFrozenState()) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
bool showMsg;
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
2018-12-08 05:30:43 +00:00
showMsg = g_GameState->SystemOptions().GetShowFrozenFpsMessage();
} else {
2018-12-08 05:30:43 +00:00
showMsg = g_GameState->SystemOptions().GetShowFrozenBallMessage();
}
2018-12-08 05:30:43 +00:00
if (showMsg) {
const char16_t* msg = g_MainStringTable->GetString(int(x2f8_morphBallState >= EPlayerMorphBallState::Morphed) + 19);
const CHUDMemoParms parms(5.f, true, false, false);
2018-12-08 05:30:43 +00:00
MP1::CSamusHud::DisplayHudMemo(msg, parms);
}
x750_frozenTimeout = x758_frozenTimeoutBias + g_tweakPlayer->GetFrozenTimeout();
x754_iceBreakJumps = -x75c_additionalIceBreakJumps;
CPhysicsActor::Stop();
ClearForcesAndTorques();
if (x3b8_grappleState != EGrappleState::None) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::Freeze, stateMgr);
} else {
2018-12-08 05:30:43 +00:00
SetOrbitRequest(EPlayerOrbitRequest::Freeze, stateMgr);
}
2018-12-08 05:30:43 +00:00
AddMaterial(EMaterialTypes::Immovable, stateMgr);
xa08_steamTextureId = steamTxtr;
xa0c_iceTextureId = iceTxtr;
CSfxHandle hnd = CSfxManager::SfxStart(sfx, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
EndLandingControlFreeze();
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::GetFrozenState() const { return x750_frozenTimeout > 0.f; }
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateFrozenState(const CFinalInput& input, CStateManager& mgr) {
x750_frozenTimeout -= input.DeltaTime();
2019-07-07 08:22:35 +00:00
if (x750_frozenTimeout > 0.f) {
SetVisorSteam(0.7f, 6.f / 14.f, 1.f / 14.f, xa08_steamTextureId, false);
} else {
2018-12-08 05:30:43 +00:00
UnFreeze(mgr);
2019-07-07 08:22:35 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (x258_movementState == EPlayerMovementState::OnGround ||
x258_movementState == EPlayerMovementState::FallingMorphed) {
2019-07-07 08:22:35 +00:00
Stop();
2018-12-08 05:30:43 +00:00
ClearForcesAndTorques();
}
x7a0_visorSteam.Update(input.DeltaTime());
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphed:
x490_gun->ProcessInput(input, mgr);
break;
case EPlayerMorphBallState::Unmorphed:
case EPlayerMorphBallState::Morphing:
case EPlayerMorphBallState::Unmorphing:
if (ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input)) {
if (x754_iceBreakJumps != 0) {
/* Subsequent Breaks */
CSfxHandle hnd = CSfxManager::SfxStart(SFXcrk_break_subsequent, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
} else {
/* Initial Break */
CSfxHandle hnd = CSfxManager::SfxStart(SFXcrk_break_initial, 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
x754_iceBreakJumps += 1;
if (x754_iceBreakJumps > g_tweakPlayer->GetIceBreakJumpCount()) {
g_GameState->SystemOptions().IncrementFrozenFpsCount();
const CHUDMemoParms info(0.f, true, true, true);
2018-12-08 05:30:43 +00:00
MP1::CSamusHud::DisplayHudMemo(u"", info);
UnFreeze(mgr);
}
}
break;
}
}
void CPlayer::UpdateStepCameraZBias(float dt) {
float newBias = GetTranslation().z() + GetUnbiasedEyeHeight();
if (x258_movementState == EPlayerMovementState::OnGround && !IsMorphBallTransitioning()) {
const float oldBias = newBias;
2018-12-08 05:30:43 +00:00
if (!x9c5_31_stepCameraZBiasDirty) {
const float delta = newBias - x9cc_stepCameraZBias;
2018-12-08 05:30:43 +00:00
float newDelta = 5.f * dt;
if (delta > 0.f) {
if (delta > dt * x138_velocity.z() && delta > newDelta) {
if (delta > GetStepUpHeight()) {
2018-12-08 05:30:43 +00:00
newDelta += delta - GetStepUpHeight();
}
2018-12-08 05:30:43 +00:00
newBias = x9cc_stepCameraZBias + newDelta;
}
} else {
if (delta < dt * x138_velocity.z() && delta < -newDelta) {
if (delta < -GetStepDownHeight()) {
2018-12-08 05:30:43 +00:00
newDelta += -delta - GetStepDownHeight();
}
2018-12-08 05:30:43 +00:00
newBias = x9cc_stepCameraZBias - newDelta;
}
}
}
x9c8_eyeZBias = newBias - oldBias;
} else {
x9c8_eyeZBias = 0.f;
}
x9cc_stepCameraZBias = newBias;
x9c5_31_stepCameraZBiasDirty = false;
}
void CPlayer::UpdateWaterSurfaceCameraBias(CStateManager& mgr) {
const TCastToConstPtr<CScriptWater> water = mgr.GetObjectById(xc4_fluidId);
if (!water) {
return;
}
const float waterZ = water->GetTriggerBoundsWR().max.z();
const float biasToEyeDelta = GetEyePosition().z() - x9c8_eyeZBias;
const float waterToDeltaDelta = biasToEyeDelta - waterZ;
if (biasToEyeDelta >= waterZ && waterToDeltaDelta <= 0.25f) {
x9c8_eyeZBias += waterZ + 0.25f - biasToEyeDelta;
} else if (biasToEyeDelta < waterZ && waterToDeltaDelta >= -0.2f) {
x9c8_eyeZBias += waterZ - 0.2f - biasToEyeDelta;
2018-12-08 05:30:43 +00:00
}
}
void CPlayer::UpdateEnvironmentDamageCameraShake(float dt, CStateManager& mgr) {
2018-12-08 05:30:43 +00:00
xa2c_damageLoopSfxDelayTicks = std::min(2, xa2c_damageLoopSfxDelayTicks + 1);
if (xa10_envDmgCounter == 0) {
return;
}
if (xa14_envDmgCameraShakeTimer == 0.f) {
mgr.GetCameraManager()->AddCameraShaker(CCameraShakeData::BuildPhazonCameraShakeData(1.f, 0.075f), false);
}
xa14_envDmgCameraShakeTimer += dt;
if (xa14_envDmgCameraShakeTimer > 2.f) {
xa14_envDmgCameraShakeTimer = 0.f;
2018-12-08 05:30:43 +00:00
}
}
void CPlayer::UpdatePhazonDamage(float dt, CStateManager& mgr) {
if (x4_areaId == kInvalidAreaId) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(x4_areaId);
if (!area->IsPostConstructed()) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
bool touchingPhazon = false;
EPhazonType phazonType;
if (const CScriptAreaAttributes* attr = area->GetPostConstructed()->x10d8_areaAttributes) {
2018-12-08 05:30:43 +00:00
phazonType = attr->GetPhazonType();
} else {
2018-12-08 05:30:43 +00:00
phazonType = EPhazonType::None;
}
2018-12-08 05:30:43 +00:00
if (phazonType == EPhazonType::Orange ||
(!mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::PhazonSuit) && phazonType == EPhazonType::Blue)) {
constexpr CMaterialFilter filter = CMaterialFilter::MakeInclude({EMaterialTypes::Phazon});
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
touchingPhazon = x768_morphball->BallCloseToCollision(mgr, 2.9f, filter);
} else {
constexpr CMaterialList primMaterial(EMaterialTypes::Player, EMaterialTypes::Solid);
const CCollidableSphere prim(
zeus::CSphere(GetCollisionPrimitive()->CalculateAABox(x34_transform).center(), 4.25f), primMaterial);
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildColliderList(nearList, *this, prim.CalculateLocalAABox());
if (CGameCollision::DetectStaticCollisionBoolean(mgr, prim, zeus::CTransform(), filter)) {
2018-12-08 05:30:43 +00:00
touchingPhazon = true;
} else {
for (const auto& id : nearList) {
if (const TCastToConstPtr<CPhysicsActor> act = mgr.GetObjectById(id)) {
const CInternalCollisionStructure::CPrimDesc prim0(prim, filter, zeus::CTransform());
const CInternalCollisionStructure::CPrimDesc prim1(
2018-12-08 05:30:43 +00:00
*act->GetCollisionPrimitive(), CMaterialFilter::skPassEverything, act->GetPrimitiveTransform());
if (CCollisionPrimitive::CollideBoolean(prim0, prim1)) {
touchingPhazon = true;
break;
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
}
}
}
}
}
if (touchingPhazon) {
xa18_phazonDamageLag += dt;
xa18_phazonDamageLag = std::min(xa18_phazonDamageLag, 3.f);
if (xa18_phazonDamageLag > 0.2f) {
const float damage = (xa18_phazonDamageLag - 0.2f) / 3.f * 60.f * dt;
const CDamageInfo dInfo(
2018-12-08 05:30:43 +00:00
CWeaponMode(phazonType == EPhazonType::Orange ? EWeaponType::OrangePhazon : EWeaponType::Phazon), damage, 0.f,
0.f);
mgr.ApplyDamage(kInvalidUniqueId, GetUniqueId(), kInvalidUniqueId, dInfo,
CMaterialFilter::MakeIncludeExclude({EMaterialTypes::Solid}, {}), zeus::skZero3f);
2018-12-08 05:30:43 +00:00
}
} else {
xa18_phazonDamageLag -= dt;
xa18_phazonDamageLag = std::min(0.2f, xa18_phazonDamageLag);
xa18_phazonDamageLag = std::max(0.f, xa18_phazonDamageLag);
}
xa1c_threatOverride = std::min(1.f, xa18_phazonDamageLag / 0.2f);
}
void CPlayer::ResetPlayerHintState() {
x9c4_26_ = true;
x9c4_27_canEnterMorphBall = true;
x9c4_28_canLeaveMorphBall = true;
x9c4_30_controlDirOverride = false;
x9c6_24_extendTargetDistance = false;
x9c6_26_outOfBallLookAtHint = false;
x9c4_29_spiderBallControlXY = false;
x9c6_29_disableInput = false;
x9c7_25_outOfBallLookAtHintActor = false;
x768_morphball->SetBoostEnabed(true);
ResetControlDirectionInterpolation();
}
bool CPlayer::SetAreaPlayerHint(const CScriptPlayerHint& hint, CStateManager& mgr) {
x9c4_26_ = (hint.GetOverrideFlags() & 0x1) != 0;
x9c4_27_canEnterMorphBall = (hint.GetOverrideFlags() & 0x40) == 0;
x9c4_28_canLeaveMorphBall = (hint.GetOverrideFlags() & 0x20) == 0;
x9c4_30_controlDirOverride = (hint.GetOverrideFlags() & 0x2) != 0;
if (x9c4_30_controlDirOverride) {
2018-12-08 05:30:43 +00:00
x9d8_controlDirOverrideDir = hint.GetTransform().basis[1];
}
2018-12-08 05:30:43 +00:00
x9c6_24_extendTargetDistance = (hint.GetOverrideFlags() & 0x4) != 0;
x9c6_26_outOfBallLookAtHint = (hint.GetOverrideFlags() & 0x8) != 0;
x9c4_29_spiderBallControlXY = (hint.GetOverrideFlags() & 0x10) != 0;
x9c6_29_disableInput = (hint.GetOverrideFlags() & 0x80) != 0;
x9c7_25_outOfBallLookAtHintActor = (hint.GetOverrideFlags() & 0x4000) != 0;
x768_morphball->SetBoostEnabed((hint.GetOverrideFlags() & 0x100) == 0);
bool switchedVisor = false;
if ((hint.GetOverrideFlags() & 0x200) != 0) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::CombatVisor)) {
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::Combat);
}
2018-12-08 05:30:43 +00:00
switchedVisor = true;
}
if ((hint.GetOverrideFlags() & 0x400) != 0) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::ScanVisor)) {
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::Scan);
}
2018-12-08 05:30:43 +00:00
switchedVisor = true;
}
if ((hint.GetOverrideFlags() & 0x800) != 0) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::ThermalVisor)) {
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::Thermal);
}
2018-12-08 05:30:43 +00:00
switchedVisor = true;
}
if ((hint.GetOverrideFlags() & 0x1000) != 0) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::XRayVisor)) {
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::XRay);
}
2018-12-08 05:30:43 +00:00
switchedVisor = true;
}
return switchedVisor;
}
void CPlayer::AddToPlayerHintRemoveList(TUniqueId id, CStateManager& mgr) {
const TCastToConstPtr<CScriptPlayerHint> hint = mgr.ObjectById(id);
if (!hint) {
return;
}
for (const auto& existId : x93c_playerHintsToRemove) {
if (id == existId) {
return;
}
2018-12-08 05:30:43 +00:00
}
if (x93c_playerHintsToRemove.size() != 32) {
x93c_playerHintsToRemove.push_back(id);
}
2018-12-08 05:30:43 +00:00
}
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::AddToPlayerHintAddList(TUniqueId id, CStateManager& mgr) {
const TCastToConstPtr<CScriptPlayerHint> hint = mgr.ObjectById(id);
if (!hint) {
return;
}
for (const auto& existId : x980_playerHintsToAdd) {
if (id == existId) {
return;
}
2018-12-08 05:30:43 +00:00
}
if (x980_playerHintsToAdd.size() != 32) {
x980_playerHintsToAdd.push_back(id);
}
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::DeactivatePlayerHint(TUniqueId id, CStateManager& mgr) {
const TCastToPtr<CScriptPlayerHint> hint = mgr.ObjectById(id);
if (!hint) {
return;
}
for (const auto& existId : x93c_playerHintsToRemove) {
if (id == existId) {
return;
2018-12-08 05:30:43 +00:00
}
}
if (x93c_playerHintsToRemove.size() != 32) {
x93c_playerHintsToRemove.push_back(id);
hint->ClearObjectList();
hint->SetDeactivated();
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::UpdatePlayerHints(CStateManager& mgr) {
bool removedHint = false;
for (auto it = x838_playerHints.begin(); it != x838_playerHints.end();) {
auto& p = *it;
const TCastToConstPtr<CScriptPlayerHint> hint = mgr.ObjectById(p.second);
2018-12-08 05:30:43 +00:00
if (!hint) {
it = x838_playerHints.erase(it);
removedHint = true;
} else {
++it;
}
}
bool needsNewHint = false;
for (const auto& id : x93c_playerHintsToRemove) {
2018-12-08 05:30:43 +00:00
for (auto it = x838_playerHints.begin(); it != x838_playerHints.end();) {
if (it->second == id) {
it = x838_playerHints.erase(it);
if (id == x830_playerHint) {
2018-12-08 05:30:43 +00:00
needsNewHint = true;
}
2017-07-31 05:19:05 +00:00
break;
2018-12-08 05:30:43 +00:00
}
++it;
2017-07-31 05:19:05 +00:00
}
2018-12-08 05:30:43 +00:00
}
x93c_playerHintsToRemove.clear();
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
bool addedHint = false;
for (const auto& id : x980_playerHintsToAdd) {
if (const TCastToConstPtr<CScriptPlayerHint> hint = mgr.ObjectById(id)) {
2018-12-08 05:30:43 +00:00
bool exists = false;
for (auto& p : x838_playerHints) {
2018-12-08 05:30:43 +00:00
if (p.second == id) {
exists = true;
break;
2017-07-31 05:19:05 +00:00
}
}
2018-12-08 05:30:43 +00:00
if (!exists) {
x838_playerHints.emplace_back(hint->GetPriority(), id);
addedHint = true;
}
}
}
x980_playerHintsToAdd.clear();
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
if (needsNewHint || addedHint || removedHint) {
std::sort(x838_playerHints.begin(), x838_playerHints.end(),
[](const auto& a, const auto& b) { return a.first < b.first; });
if ((needsNewHint || removedHint) && x838_playerHints.empty()) {
x830_playerHint = kInvalidUniqueId;
x834_playerHintPriority = 1000;
ResetPlayerHintState();
return;
}
const CScriptPlayerHint* foundHint = nullptr;
2018-12-08 05:30:43 +00:00
bool foundHintInArea = false;
for (const auto& p : x838_playerHints) {
if (const TCastToConstPtr<CScriptPlayerHint> hint = mgr.ObjectById(p.second)) {
2018-12-08 05:30:43 +00:00
foundHint = hint.GetPtr();
if (hint->GetAreaIdAlways() == mgr.GetNextAreaId()) {
foundHintInArea = true;
break;
}
}
}
if (!foundHintInArea) {
x830_playerHint = kInvalidUniqueId;
x834_playerHintPriority = 1000;
ResetPlayerHintState();
}
if (foundHint != nullptr && foundHintInArea && x830_playerHint != foundHint->GetUniqueId()) {
x830_playerHint = foundHint->GetUniqueId();
x834_playerHintPriority = foundHint->GetPriority();
if (SetAreaPlayerHint(*foundHint, mgr)) {
2018-12-08 05:30:43 +00:00
DeactivatePlayerHint(x830_playerHint, mgr);
}
2018-12-08 05:30:43 +00:00
}
}
}
void CPlayer::UpdateBombJumpStuff() {
if (x9d0_bombJumpCount == 0) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
x9d4_bombJumpCheckDelayFrames -= 1;
if (x9d4_bombJumpCheckDelayFrames > 0) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f velFlat = x138_velocity;
velFlat.z() = 0.f;
if (x258_movementState == EPlayerMovementState::OnGround ||
(velFlat.canBeNormalized() && velFlat.magnitude() > 6.f)) {
2018-12-08 05:30:43 +00:00
x9d0_bombJumpCount = 0;
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::UpdateTransitionFilter(float dt, CStateManager& mgr) {
if (x824_transitionFilterTimer <= 0.f) {
mgr.GetCameraFilterPass(8).DisableFilter(0.f);
return;
}
x824_transitionFilterTimer += dt;
if (x824_transitionFilterTimer > 1.25f) {
x824_transitionFilterTimer = 0.f;
mgr.GetCameraFilterPass(8).DisableFilter(0.f);
return;
}
if (x824_transitionFilterTimer < 0.95f) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
const float time = x824_transitionFilterTimer - 0.95f;
2018-12-08 05:30:43 +00:00
zeus::CColor color(1.f, 0.87f, 0.54f, 1.f);
if (time < 0.1f) {
2018-12-08 05:30:43 +00:00
color.a() = 0.3f * time / 0.1f;
} else if (time >= 0.15f) {
2018-12-08 05:30:43 +00:00
color.a() = 1.f - zeus::clamp(-1.f, (time - 0.15f) / 0.15f, 1.f) * 0.3f;
} else {
2018-12-08 05:30:43 +00:00
color.a() = 0.3f;
}
2018-12-08 05:30:43 +00:00
mgr.GetCameraFilterPass(8).SetFilter(EFilterType::Add, EFilterShape::ScanLinesEven, 0.f, color, {});
}
void CPlayer::ResetControlDirectionInterpolation() {
x9c6_25_interpolatingControlDir = false;
x9f8_controlDirInterpTime = 0.f;
}
void CPlayer::SetControlDirectionInterpolation(float time) {
x9c6_25_interpolatingControlDir = true;
x9f8_controlDirInterpTime = 0.f;
x9fc_controlDirInterpDur = time;
}
void CPlayer::UpdatePlayerControlDirection(float dt, CStateManager& mgr) {
const zeus::CVector3f oldControlDir = x540_controlDir;
const zeus::CVector3f oldControlDirFlat = x54c_controlDirFlat;
2018-12-08 05:30:43 +00:00
CalculatePlayerControlDirection(mgr);
if (!x9c6_25_interpolatingControlDir || x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
return;
}
x9f8_controlDirInterpTime += dt;
if (x9f8_controlDirInterpTime > x9fc_controlDirInterpDur) {
x9f8_controlDirInterpTime = x9fc_controlDirInterpDur;
ResetControlDirectionInterpolation();
2018-12-08 05:30:43 +00:00
}
const float t = zeus::clamp(-1.f, x9f8_controlDirInterpTime / x9fc_controlDirInterpDur, 1.f);
x540_controlDir = zeus::CVector3f::lerp(oldControlDir, x540_controlDir, t);
x54c_controlDirFlat = zeus::CVector3f::lerp(oldControlDirFlat, x540_controlDir, t);
2018-12-08 05:30:43 +00:00
}
void CPlayer::Think(float dt, CStateManager& mgr) {
UpdateStepCameraZBias(dt);
UpdateWaterSurfaceCameraBias(mgr);
UpdateEnvironmentDamageCameraShake(dt, mgr);
2018-12-08 05:30:43 +00:00
UpdatePhazonDamage(dt, mgr);
UpdateFreeLook(dt);
UpdatePlayerHints(mgr);
if (x2b0_outOfWaterTicks < 2) {
2018-12-08 05:30:43 +00:00
x2b0_outOfWaterTicks += 1;
}
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
x9c5_24_ = x9c4_24_visorChangeRequested;
2019-01-16 04:22:44 +00:00
x9c4_31_inWaterMovement = x9c5_25_splashUpdated;
2018-12-08 05:30:43 +00:00
x9c5_25_splashUpdated = false;
UpdateBombJumpStuff();
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
if (0.f < x288_startingJumpTimeout) {
x288_startingJumpTimeout -= dt;
if (0.f >= x288_startingJumpTimeout) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
}
2018-12-08 05:30:43 +00:00
}
if (x2a0_ > 0.f) {
2018-12-08 05:30:43 +00:00
x2a0_ += dt;
}
if (x774_samusVoiceTimeout > 0.f) {
2018-12-08 05:30:43 +00:00
x774_samusVoiceTimeout -= dt;
}
if (0.f < x28c_sjTimer) {
2018-12-08 05:30:43 +00:00
x28c_sjTimer -= dt;
}
2018-12-08 05:30:43 +00:00
x300_fallingTime += dt;
if (x258_movementState == EPlayerMovementState::FallingMorphed && x300_fallingTime > 0.4f) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
}
2018-12-08 05:30:43 +00:00
if (x570_immuneTimer > 0.f) {
2018-12-08 05:30:43 +00:00
x570_immuneTimer -= dt;
}
2018-12-08 05:30:43 +00:00
Update(dt, mgr);
UpdateTransitionFilter(dt, mgr);
CalculatePlayerMovementDirection(dt);
UpdatePlayerControlDirection(dt, mgr);
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
#if 0
if (g_factoryManager == 4) {
2018-12-08 05:30:43 +00:00
x2b0_ = 0;
} else {
2018-12-08 05:30:43 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Normal;
}
2018-12-08 05:30:43 +00:00
#endif
2017-07-31 05:19:05 +00:00
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed && x9c5_27_camSubmerged &&
mgr.GetCameraManager()->GetFluidCounter() == 0) {
if (const auto* water = GetVisorRunoffEffect(mgr)) {
2018-12-08 05:30:43 +00:00
if (const auto& effect = water->GetVisorRunoffEffect()) {
auto* sheets = new CHUDBillboardEffect(
2018-12-08 05:30:43 +00:00
*effect, {}, mgr.AllocateUniqueId(), true, "WaterSheets", CHUDBillboardEffect::GetNearClipDistance(mgr),
CHUDBillboardEffect::GetScaleForPOV(mgr), zeus::skWhite, zeus::skOne3f, zeus::skZero3f);
2018-12-08 05:30:43 +00:00
mgr.AddObject(sheets);
}
CSfxHandle hnd = CSfxManager::SfxStart(water->GetVisorRunoffSfx(), 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
}
x9c5_27_camSubmerged = mgr.GetCameraManager()->GetFluidCounter() != 0;
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
if (std::fabs(x34_transform.basis[0].z()) > FLT_EPSILON || std::fabs(x34_transform.basis[1].z()) > FLT_EPSILON) {
const zeus::CVector3f backupTranslation = GetTranslation();
const zeus::CVector3f lookDirFlat(x34_transform.basis[1].x(), x34_transform.basis[1].y(), 0.f);
2018-12-08 05:30:43 +00:00
if (lookDirFlat.canBeNormalized()) {
SetTransform(zeus::lookAt(zeus::skZero3f, lookDirFlat.normalized()));
2018-12-08 05:30:43 +00:00
} else {
SetTransform(zeus::CTransform());
2018-12-08 05:30:43 +00:00
}
SetTranslation(backupTranslation);
}
}
x794_lastVelocity = x138_velocity;
}
void CPlayer::PreThink(float dt, CStateManager& mgr) {
x558_wasDamaged = false;
x55c_damageAmt = 0.f;
x560_prevDamageAmt = 0.f;
x564_damageLocation = zeus::skZero3f;
2018-12-08 05:30:43 +00:00
xa04_preThinkDt = dt;
}
void CPlayer::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {
switch (msg) {
case EScriptObjectMessage::OnFloor:
if (x258_movementState != EPlayerMovementState::OnGround && x2f8_morphBallState != EPlayerMorphBallState::Morphed &&
x300_fallingTime > 0.3f) {
if (x258_movementState != EPlayerMovementState::Falling) {
float hardThres = 30.f * 2.f * -g_tweakPlayer->GetNormalGravAccel();
2020-04-22 00:43:34 +00:00
hardThres = (hardThres != 0.f) ? hardThres * (1.f / std::sqrt(hardThres)) : 0.f;
const float landVol = zeus::clamp(95.f, 1.6f * -x794_lastVelocity.z() + 95.f, 127.f) / 127.f;
2018-12-08 05:30:43 +00:00
u16 landSfx;
if (-x794_lastVelocity.z() < hardThres) {
landSfx = GetMaterialSoundUnderPlayer(mgr, skPlayerLandSfxSoft.data(), skPlayerLandSfxSoft.size(), 0xffff);
2018-12-08 05:30:43 +00:00
} else {
landSfx = GetMaterialSoundUnderPlayer(mgr, skPlayerLandSfxHard.data(), skPlayerLandSfxHard.size(), 0xffff);
2018-12-08 05:30:43 +00:00
StartSamusVoiceSfx(SFXsam_voxland_02, 1.f, 5);
x55c_damageAmt = 0.f;
x560_prevDamageAmt = 10.f;
x564_damageLocation = x34_transform.origin;
x558_wasDamaged = true;
mgr.GetCameraManager()->AddCameraShaker(CCameraShakeData::BuildLandingCameraShakeData(0.3f, 1.25f), false);
StartLandingControlFreeze();
}
CSfxHandle handle = CSfxManager::SfxStart(landSfx, landVol, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(handle);
float rumbleMag = -x794_lastVelocity.z() / 110.f;
if (rumbleMag > 0.f) {
if (std::fabs(rumbleMag) > 0.8f) {
2018-12-08 05:30:43 +00:00
rumbleMag = (rumbleMag > 0.f) ? 0.8f : -0.8f;
}
2018-12-08 05:30:43 +00:00
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerLand, rumbleMag, ERumblePriority::One);
}
x2a0_ = 0.f;
}
} else if (x258_movementState != EPlayerMovementState::OnGround &&
x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
if (x138_velocity.z() < -40.f && !x768_morphball->GetIsInHalfPipeMode() &&
x258_movementState == EPlayerMovementState::ApplyJump && x300_fallingTime > 0.75f) {
2018-12-08 05:30:43 +00:00
SetCoefficientOfRestitutionModifier(0.2f);
}
2018-12-08 05:30:43 +00:00
x768_morphball->StartLandingSfx();
if (x138_velocity.z() < -5.f) {
float rumbleMag = -x138_velocity.z() / 110.f * 0.5f;
if (std::fabs(rumbleMag) > 0.8f) {
2018-12-08 05:30:43 +00:00
rumbleMag = (rumbleMag > 0.f) ? 0.8f : -0.8f;
}
2018-12-08 05:30:43 +00:00
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerLand, rumbleMag, ERumblePriority::One);
x2a0_ = 0.f;
}
if (x138_velocity.z() < -30.f) {
float rumbleMag = -x138_velocity.z() / 110.f;
if (std::fabs(rumbleMag) > 0.8f) {
2018-12-08 05:30:43 +00:00
rumbleMag = (rumbleMag > 0.f) ? 0.8f : -0.8f;
}
2018-12-08 05:30:43 +00:00
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerLand, rumbleMag, ERumblePriority::One);
x2a0_ = 0.f;
}
}
x300_fallingTime = 0.f;
SetMoveState(EPlayerMovementState::OnGround, mgr);
break;
case EScriptObjectMessage::Falling:
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
if (x768_morphball->GetSpiderBallState() == CMorphBall::ESpiderBallState::Active) {
2018-12-08 05:30:43 +00:00
break;
}
}
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::Falling, mgr);
} else if (x258_movementState == EPlayerMovementState::OnGround) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::FallingMorphed, mgr);
}
2018-12-08 05:30:43 +00:00
break;
case EScriptObjectMessage::LandOnNotFloor:
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed &&
x768_morphball->GetSpiderBallState() == CMorphBall::ESpiderBallState::Active &&
x258_movementState != EPlayerMovementState::ApplyJump) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
}
2018-12-08 05:30:43 +00:00
break;
case EScriptObjectMessage::OnIceSurface:
x2ac_surfaceRestraint = ESurfaceRestraints::Ice;
break;
case EScriptObjectMessage::OnMudSlowSurface:
2019-01-20 06:43:11 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Organic;
2018-12-08 05:30:43 +00:00
break;
case EScriptObjectMessage::OnNormalSurface:
x2ac_surfaceRestraint = ESurfaceRestraints::Normal;
break;
case EScriptObjectMessage::InSnakeWeed:
2019-01-20 06:43:11 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Shrubbery;
2018-12-08 05:30:43 +00:00
break;
case EScriptObjectMessage::AddSplashInhabitant: {
SetInFluid(true, sender);
UpdateSubmerged(mgr);
const CRayCastResult result =
mgr.RayStaticIntersection(x34_transform.origin, zeus::skDown, 0.5f * GetEyeHeight(), SolidMaterialFilter);
2018-12-08 05:30:43 +00:00
if (result.IsInvalid()) {
SetVelocityWR(x138_velocity * 0.095f);
xfc_constantForce *= zeus::CVector3f(0.095f);
}
break;
}
case EScriptObjectMessage::UpdateSplashInhabitant:
UpdateSubmerged(mgr);
if (CheckSubmerged() && !mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) {
if (const TCastToConstPtr<CScriptWater> water = mgr.ObjectById(xc4_fluidId)) {
2018-12-08 05:30:43 +00:00
switch (water->GetFluidPlane().GetFluidType()) {
case EFluidType::NormalWater:
x2b0_outOfWaterTicks = 0;
break;
case EFluidType::Lava:
case EFluidType::ThickLava:
x2ac_surfaceRestraint = ESurfaceRestraints::Lava;
break;
case EFluidType::PoisonWater:
x2b0_outOfWaterTicks = 0;
break;
case EFluidType::PhazonFluid:
2019-01-20 06:43:11 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Phazon;
2018-12-08 05:30:43 +00:00
break;
default:
break;
}
}
}
x9c5_25_splashUpdated = true;
break;
case EScriptObjectMessage::RemoveSplashInhabitant:
SetInFluid(false, kInvalidUniqueId);
UpdateSubmerged(mgr);
break;
case EScriptObjectMessage::ProjectileCollide:
x378_orbitPreventionTimer = g_tweakPlayer->GetOrbitPreventionTime();
SetOrbitRequest(EPlayerOrbitRequest::ProjectileCollide, mgr);
break;
case EScriptObjectMessage::AddPlatformRider:
x82e_ridingPlatform = sender;
break;
case EScriptObjectMessage::Damage:
if (const TCastToConstPtr<CEnergyProjectile> energ = mgr.ObjectById(sender)) {
2019-04-03 04:32:31 +00:00
if (True(energ->GetAttribField() & EProjectileAttrib::StaticInterference)) {
2018-12-08 05:30:43 +00:00
mgr.GetPlayerState()->GetStaticInterference().AddSource(GetUniqueId(), 0.3f, energ->GetInterferenceDuration());
}
}
break;
case EScriptObjectMessage::Deleted:
mgr.GetPlayerState()->ResetVisor();
x730_transitionModels.clear();
break;
default:
break;
}
x490_gun->AcceptScriptMsg(msg, sender, mgr);
x768_morphball->AcceptScriptMsg(msg, sender, mgr);
CActor::AcceptScriptMsg(msg, sender, mgr);
}
void CPlayer::SetVisorSteam(float targetAlpha, float alphaInDur, float alphaOutDur, CAssetId txtr,
bool affectsThermal) {
x7a0_visorSteam.SetSteam(targetAlpha, alphaInDur, alphaOutDur, txtr, affectsThermal);
}
void CPlayer::UpdateFootstepSounds(const CFinalInput& input, CStateManager& mgr, float dt) {
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed || x258_movementState != EPlayerMovementState::OnGround ||
x3dc_inFreeLook || x3dd_lookButtonHeld) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
float sfxVol = 1.f;
x78c_footstepSfxTimer += dt;
float turn = TurnInput(input);
const float forward = std::fabs(ForwardInput(input, turn));
2018-12-08 05:30:43 +00:00
turn = std::fabs(turn);
float sfxDelay = 0.f;
if (forward > 0.05f || x304_orbitState != EPlayerOrbitState::NoOrbit) {
const float vel = std::min(1.f, x138_velocity.magnitude() / GetActualFirstPersonMaxVelocity(dt));
2018-12-08 05:30:43 +00:00
if (vel > 0.05f) {
sfxDelay = -0.475f * vel + 0.85f;
if (x790_footstepSfxSel == EFootstepSfx::None) {
2018-12-08 05:30:43 +00:00
x790_footstepSfxSel = EFootstepSfx::Left;
}
2018-12-08 05:30:43 +00:00
} else {
x78c_footstepSfxTimer = 0.f;
x790_footstepSfxSel = EFootstepSfx::None;
}
sfxVol = 0.3f * vel + 0.7f;
} else if (turn > 0.05f) {
if (x790_footstepSfxSel == EFootstepSfx::Left) {
2018-12-08 05:30:43 +00:00
sfxDelay = -0.813f * turn + 1.f;
} else {
2018-12-08 05:30:43 +00:00
sfxDelay = -2.438f * turn + 3.f;
}
2018-12-08 05:30:43 +00:00
if (x790_footstepSfxSel == EFootstepSfx::None) {
x790_footstepSfxSel = EFootstepSfx::Left;
sfxDelay = x78c_footstepSfxTimer;
}
sfxVol = 0.75f;
} else {
x78c_footstepSfxTimer = 0.f;
x790_footstepSfxSel = EFootstepSfx::None;
}
if (x790_footstepSfxSel != EFootstepSfx::None && x78c_footstepSfxTimer > sfxDelay) {
static float EarHeight = GetEyeHeight() - 0.1f;
if (xe6_24_fluidCounter != 0 && x828_distanceUnderWater > 0.f && x828_distanceUnderWater < EarHeight) {
if (x82c_inLava) {
if (x790_footstepSfxSel == EFootstepSfx::Left) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXlav_wlklava_00, sfxVol, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
} else {
CSfxHandle hnd = CSfxManager::SfxStart(SFXlav_wlklava_01, sfxVol, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
} else {
if (x790_footstepSfxSel == EFootstepSfx::Left) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_wlkwater_00, sfxVol, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
} else {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_wlkwater_01, sfxVol, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
}
} else {
u16 sfx;
if (x790_footstepSfxSel == EFootstepSfx::Left) {
sfx = GetMaterialSoundUnderPlayer(mgr, skLeftStepSounds.data(), skLeftStepSounds.size(), 0xffff);
} else {
sfx = GetMaterialSoundUnderPlayer(mgr, skRightStepSounds.data(), skRightStepSounds.size(), 0xffff);
}
2018-12-08 05:30:43 +00:00
CSfxHandle hnd = CSfxManager::SfxStart(sfx, sfxVol, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
x78c_footstepSfxTimer = 0.f;
if (x790_footstepSfxSel == EFootstepSfx::Left) {
2018-12-08 05:30:43 +00:00
x790_footstepSfxSel = EFootstepSfx::Right;
} else {
2018-12-08 05:30:43 +00:00
x790_footstepSfxSel = EFootstepSfx::Left;
}
2018-12-08 05:30:43 +00:00
}
2017-07-31 05:19:05 +00:00
}
u16 CPlayer::GetMaterialSoundUnderPlayer(const CStateManager& mgr, const u16* table, size_t length, u16 defId) const {
2018-12-08 05:30:43 +00:00
u16 ret = defId;
zeus::CAABox aabb = GetBoundingBox();
aabb.accumulateBounds(x34_transform.origin + zeus::skDown);
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildNearList(nearList, aabb, SolidMaterialFilter, nullptr);
TUniqueId collideId = kInvalidUniqueId;
const CRayCastResult result =
mgr.RayWorldIntersection(collideId, x34_transform.origin, zeus::skDown, 1.5f, SolidMaterialFilter, nearList);
if (result.IsValid()) {
2018-12-08 05:30:43 +00:00
ret = SfxIdFromMaterial(result.GetMaterial(), table, length, defId);
}
2018-12-08 05:30:43 +00:00
return ret;
2017-07-17 03:04:14 +00:00
}
u16 CPlayer::SfxIdFromMaterial(const CMaterialList& mat, const u16* idList, size_t tableLen, u16 defId) {
2018-12-08 05:30:43 +00:00
u16 id = defId;
for (size_t i = 0; i < tableLen; ++i) {
if (mat.HasMaterial(EMaterialTypes(i)) && idList[i] != 0xFFFF) {
2018-12-08 05:30:43 +00:00
id = idList[i];
}
2018-12-08 05:30:43 +00:00
}
return id;
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateCrosshairsState(const CFinalInput& input) {
x9c4_25_showCrosshairs = ControlMapper::GetDigitalInput(ControlMapper::ECommands::ShowCrosshairs, input);
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateVisorTransition(float dt, CStateManager& mgr) {
if (mgr.GetPlayerState()->GetIsVisorTransitioning()) {
2018-12-08 05:30:43 +00:00
mgr.GetPlayerState()->UpdateVisorTransition(dt);
}
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateVisorState(const CFinalInput& input, float dt, CStateManager& mgr) {
x7a0_visorSteam.Update(dt);
if (x7a0_visorSteam.AffectsThermal()) {
2018-12-08 05:30:43 +00:00
mgr.SetThermalColdScale2(mgr.GetThermalColdScale2() + x7a0_visorSteam.GetAlpha());
}
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::Grapple ||
TCastToPtr<CScriptGrapplePoint>(mgr.ObjectById(x310_orbitTargetId)) ||
x2f8_morphBallState != EPlayerMorphBallState::Unmorphed || mgr.GetPlayerState()->GetIsVisorTransitioning() ||
x3a8_scanState != EPlayerScanState::NotScanning) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (mgr.GetPlayerState()->GetTransitioningVisor() == CPlayerState::EPlayerVisor::Scan &&
(ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::MissileOrPowerBomb, input)) &&
mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::CombatVisor)) {
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::Combat);
2018-12-08 05:30:43 +00:00
DrawGun(mgr);
}
for (size_t i = 0; i < skVisorToItemMapping.size(); ++i) {
const auto mapping = skVisorToItemMapping[i];
if (mgr.GetPlayerState()->HasPowerUp(mapping.first) && ControlMapper::GetPressInput(mapping.second, input)) {
2018-12-08 05:30:43 +00:00
x9c4_24_visorChangeRequested = true;
const auto visor = CPlayerState::EPlayerVisor(i);
2018-12-08 05:30:43 +00:00
if (mgr.GetPlayerState()->GetTransitioningVisor() != visor) {
mgr.GetPlayerState()->StartTransitionToVisor(visor);
if (visor == CPlayerState::EPlayerVisor::Scan) {
2018-12-08 05:30:43 +00:00
HolsterGun(mgr);
} else {
2018-12-08 05:30:43 +00:00
DrawGun(mgr);
}
2018-12-08 05:30:43 +00:00
}
}
}
}
void CPlayer::UpdateGunState(const CFinalInput& input, CStateManager& mgr) {
switch (x498_gunHolsterState) {
case EGunHolsterState::Drawn: {
bool needsHolster = false;
if (g_tweakPlayer->GetGunButtonTogglesHolster()) {
if (ControlMapper::GetPressInput(ControlMapper::ECommands::ToggleHolster, input)) {
2018-12-08 05:30:43 +00:00
needsHolster = true;
}
2018-12-08 05:30:43 +00:00
if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::MissileOrPowerBomb, input) &&
g_tweakPlayer->GetGunNotFiringHolstersGun()) {
x49c_gunHolsterRemTime -= input.DeltaTime();
if (x49c_gunHolsterRemTime <= 0.f) {
2018-12-08 05:30:43 +00:00
needsHolster = true;
}
2018-12-08 05:30:43 +00:00
}
} else {
if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::MissileOrPowerBomb, input) &&
x490_gun->IsFidgeting()) {
if (g_tweakPlayer->GetGunNotFiringHolstersGun()) {
2018-12-08 05:30:43 +00:00
x49c_gunHolsterRemTime -= input.DeltaTime();
}
2018-12-08 05:30:43 +00:00
} else {
x49c_gunHolsterRemTime = g_tweakPlayerGun->GetGunNotFiringTime();
}
}
if (needsHolster) {
2018-12-08 05:30:43 +00:00
HolsterGun(mgr);
}
2018-12-08 05:30:43 +00:00
break;
}
case EGunHolsterState::Drawing: {
if (x49c_gunHolsterRemTime > 0.f) {
x49c_gunHolsterRemTime -= input.DeltaTime();
} else {
x498_gunHolsterState = EGunHolsterState::Drawn;
x49c_gunHolsterRemTime = g_tweakPlayerGun->GetGunNotFiringTime();
}
break;
}
case EGunHolsterState::Holstered: {
bool needsDraw = false;
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::MissileOrPowerBomb, input) ||
x3b8_grappleState == EGrappleState::None ||
(g_tweakPlayer->GetGunButtonTogglesHolster() &&
ControlMapper::GetPressInput(ControlMapper::ECommands::ToggleHolster, input))) {
2018-12-08 05:30:43 +00:00
needsDraw = true;
}
2018-12-08 05:30:43 +00:00
if (x3b8_grappleState == EGrappleState::None &&
(mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan ||
mgr.GetPlayerState()->GetTransitioningVisor() == CPlayerState::EPlayerVisor::Scan)) {
2018-12-08 05:30:43 +00:00
needsDraw = false;
}
2018-12-08 05:30:43 +00:00
if (needsDraw) {
2018-12-08 05:30:43 +00:00
DrawGun(mgr);
}
2018-12-08 05:30:43 +00:00
break;
}
case EGunHolsterState::Holstering:
if (x49c_gunHolsterRemTime > 0.f) {
2018-12-08 05:30:43 +00:00
x49c_gunHolsterRemTime -= input.DeltaTime();
} else {
2018-12-08 05:30:43 +00:00
x498_gunHolsterState = EGunHolsterState::Holstered;
}
2018-12-08 05:30:43 +00:00
break;
}
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::ResetGun(CStateManager& mgr) {
x498_gunHolsterState = EGunHolsterState::Holstered;
x49c_gunHolsterRemTime = 0.f;
x490_gun->CancelFiring(mgr);
ResetAimTargetPrediction(kInvalidUniqueId);
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateArmAndGunTransforms(float dt, CStateManager& mgr) {
zeus::CVector3f grappleOffset;
zeus::CVector3f gunOffset;
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed) {
gunOffset = {0.f, 0.f, 0.6f};
} else {
gunOffset = g_tweakPlayerGun->GetGunPosition();
grappleOffset =
x490_gun->GetGrappleArm().IsArmMoving() ? zeus::skZero3f : g_tweakPlayerGun->GetGrapplingArmPosition();
2018-12-08 05:30:43 +00:00
gunOffset.z() += GetEyeHeight();
grappleOffset.z() += GetEyeHeight();
}
UpdateGunTransform(gunOffset + x76c_cameraBob->GetGunBobTransformation().origin, mgr);
UpdateGrappleArmTransform(grappleOffset, mgr, dt);
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::ForceGunOrientation(const zeus::CTransform& xf, CStateManager& mgr) {
ResetGun(mgr);
x530_gunDir = xf.basis[1];
x490_gun->SetTransform(xf);
UpdateArmAndGunTransforms(0.01f, mgr);
2017-07-30 01:06:06 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateCameraState(CStateManager& mgr) { UpdateCinematicState(mgr); }
2017-08-19 06:52:13 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateDebugCamera(CStateManager& mgr) {
// Empty
2017-08-19 06:52:13 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateCameraTimers(float dt, const CFinalInput& input) {
if (x3dc_inFreeLook || x3dd_lookButtonHeld) {
x294_jumpCameraTimer = 0.f;
x29c_fallCameraTimer = 0.f;
return;
}
if (g_tweakPlayer->GetFiringCancelsCameraPitch()) {
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::MissileOrPowerBomb, input)) {
if (x288_startingJumpTimeout > 0.f) {
x2a4_cancelCameraPitch = true;
return;
}
}
}
if (ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input)) {
2018-12-08 05:30:43 +00:00
++x298_jumpPresses;
}
2018-12-08 05:30:43 +00:00
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::JumpOrBoost, input) && x294_jumpCameraTimer > 0.f &&
!x2a4_cancelCameraPitch && x298_jumpPresses <= 2) {
2018-12-08 05:30:43 +00:00
x294_jumpCameraTimer += dt;
}
2018-12-08 05:30:43 +00:00
if (x29c_fallCameraTimer > 0.f && !x2a4_cancelCameraPitch) {
2018-12-08 05:30:43 +00:00
x29c_fallCameraTimer += dt;
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::UpdateMorphBallState(float dt, const CFinalInput& input, CStateManager& mgr) {
if (!ControlMapper::GetPressInput(ControlMapper::ECommands::Morph, input)) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::MorphBall) && CanEnterMorphBallState(mgr, 0.f)) {
x574_morphTime = 0.f;
x578_morphDuration = 1.f;
TransitionToMorphBallState(dt, mgr);
} else {
CSfxHandle hnd = CSfxManager::SfxStart(SFXwpn_invalid_action, 1.f, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
break;
case EPlayerMorphBallState::Morphed: {
zeus::CVector3f posDelta;
if (CanLeaveMorphBallState(mgr, posDelta)) {
SetTranslation(x34_transform.origin + posDelta);
x574_morphTime = 0.f;
x578_morphDuration = 1.f;
TransitionFromMorphBallState(mgr);
} else {
CSfxHandle hnd = CSfxManager::SfxStart(SFXwpn_invalid_action, 1.f, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
break;
}
default:
break;
}
}
CFirstPersonCamera& CPlayer::GetFirstPersonCamera(CStateManager& mgr) {
return *mgr.GetCameraManager()->GetFirstPersonCamera();
}
void CPlayer::UpdateGunTransform(const zeus::CVector3f& gunPos, CStateManager& mgr) {
const float eyeHeight = GetEyeHeight();
const zeus::CTransform camXf = mgr.GetCameraManager()->GetCurrentCameraTransform(mgr);
2018-12-08 05:30:43 +00:00
zeus::CTransform gunXf = camXf;
zeus::CVector3f viewGunPos;
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing) {
2018-12-08 05:30:43 +00:00
viewGunPos = camXf * (gunPos - zeus::CVector3f(0.f, 0.f, eyeHeight));
} else {
2018-12-08 05:30:43 +00:00
viewGunPos = camXf.rotate(gunPos - zeus::CVector3f(0.f, 0.f, eyeHeight)) + GetEyePosition();
}
2018-12-08 05:30:43 +00:00
const zeus::CUnitVector3f rightDir(gunXf.basis[0]);
2018-12-08 05:30:43 +00:00
gunXf.origin = viewGunPos;
switch (x498_gunHolsterState) {
case EGunHolsterState::Drawing: {
const float liftAngle = zeus::clamp(-1.f, x49c_gunHolsterRemTime / 0.45f, 1.f);
2018-12-08 05:30:43 +00:00
if (liftAngle > 0.01f) {
gunXf = zeus::CQuaternion::fromAxisAngle(rightDir, -liftAngle * g_tweakPlayerGun->GetFixedVerticalAim())
.toTransform() *
camXf.getRotation();
gunXf.origin = viewGunPos;
}
break;
}
case EGunHolsterState::Holstered: {
gunXf = zeus::CQuaternion::fromAxisAngle(rightDir, -g_tweakPlayerGun->GetFixedVerticalAim()).toTransform() *
camXf.getRotation();
gunXf.origin = viewGunPos;
break;
}
case EGunHolsterState::Holstering: {
float liftAngle = 1.f - zeus::clamp(-1.f, x49c_gunHolsterRemTime / g_tweakPlayerGun->GetGunHolsterTime(), 1.f);
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing) {
2018-12-08 05:30:43 +00:00
liftAngle = 1.f - zeus::clamp(-1.f, x49c_gunHolsterRemTime / 0.1f, 1.f);
}
2018-12-08 05:30:43 +00:00
if (liftAngle > 0.01f) {
gunXf = zeus::CQuaternion::fromAxisAngle(rightDir, -liftAngle * g_tweakPlayerGun->GetFixedVerticalAim())
.toTransform() *
camXf.getRotation();
gunXf.origin = viewGunPos;
}
break;
}
default:
break;
}
x490_gun->SetTransform(gunXf);
UpdateAimTargetPrediction(gunXf, mgr);
UpdateAssistedAiming(gunXf, mgr);
}
void CPlayer::UpdateAssistedAiming(const zeus::CTransform& xf, const CStateManager& mgr) {
zeus::CTransform assistXf = xf;
const TCastToConstPtr<CActor> target = mgr.GetObjectById(x3f4_aimTarget);
if (target) {
2018-12-08 05:30:43 +00:00
zeus::CVector3f gunToTarget = x480_assistedTargetAim - xf.origin;
zeus::CVector3f gunToTargetFlat = gunToTarget;
gunToTargetFlat.z() = 0.f;
const float gunToTargetFlatMag = gunToTargetFlat.magnitude();
2018-12-08 05:30:43 +00:00
zeus::CVector3f gunDirFlat = xf.basis[1];
gunDirFlat.z() = 0.f;
const float gunDirFlatMag = gunDirFlat.magnitude();
2018-12-08 05:30:43 +00:00
if (gunToTargetFlat.canBeNormalized() && gunDirFlat.canBeNormalized()) {
gunToTargetFlat = gunToTargetFlat / gunToTargetFlatMag;
gunDirFlat = gunDirFlat / gunDirFlatMag;
float vAngleDelta = std::atan2(gunToTarget.z(), gunToTargetFlatMag) - std::atan2(xf.basis[1].z(), gunDirFlatMag);
bool hasVAngleDelta = true;
if (!x9c6_27_aimingAtProjectile && std::fabs(vAngleDelta) > g_tweakPlayer->GetAimAssistVerticalAngle()) {
if (g_tweakPlayer->GetAssistedAimingIgnoreVertical()) {
vAngleDelta = 0.f;
hasVAngleDelta = false;
} else if (vAngleDelta > 0.f) {
vAngleDelta = g_tweakPlayer->GetAimAssistVerticalAngle();
} else {
vAngleDelta = -g_tweakPlayer->GetAimAssistVerticalAngle();
}
}
const bool targetToLeft = gunDirFlat.cross(gunToTargetFlat).z() > 0.f;
2018-12-08 05:30:43 +00:00
float hAngleDelta = std::acos(zeus::clamp(-1.f, gunDirFlat.dot(gunToTargetFlat), 1.f));
bool hasHAngleDelta = true;
if (!x9c6_27_aimingAtProjectile && std::fabs(hAngleDelta) > g_tweakPlayer->GetAimAssistHorizontalAngle()) {
hAngleDelta = g_tweakPlayer->GetAimAssistHorizontalAngle();
if (g_tweakPlayer->GetAssistedAimingIgnoreHorizontal()) {
hAngleDelta = 0.f;
hasHAngleDelta = false;
}
}
if (targetToLeft)
hAngleDelta = -hAngleDelta;
if (!hasVAngleDelta || !hasHAngleDelta) {
vAngleDelta = 0.f;
hAngleDelta = 0.f;
}
gunToTarget.x() = std::sin(hAngleDelta) * std::cos(vAngleDelta);
gunToTarget.y() = std::cos(hAngleDelta) * std::cos(vAngleDelta);
gunToTarget.z() = std::sin(vAngleDelta);
gunToTarget = xf.rotate(gunToTarget);
assistXf = zeus::lookAt(zeus::skZero3f, gunToTarget, zeus::skUp);
2018-12-08 05:30:43 +00:00
}
}
x490_gun->SetAssistAimTransform(assistXf);
}
void CPlayer::UpdateAimTargetPrediction(const zeus::CTransform& xf, const CStateManager& mgr) {
if (x3f4_aimTarget == kInvalidUniqueId) {
return;
}
const TCastToConstPtr<CActor> target = mgr.GetObjectById(x3f4_aimTarget);
if (!target) {
return;
}
x9c6_27_aimingAtProjectile = TCastToConstPtr<CGameProjectile>(target.GetPtr()).IsValid();
const zeus::CVector3f instantTarget = target->GetAimPosition(mgr, 0.f);
const zeus::CVector3f gunToTarget = instantTarget - xf.origin;
const float timeToTarget = gunToTarget.magnitude() / x490_gun->GetBeamVelocity();
const zeus::CVector3f predictTarget = target->GetAimPosition(mgr, timeToTarget);
const zeus::CVector3f predictOffset = predictTarget - instantTarget;
x3f8_targetAimPosition = instantTarget;
if (predictOffset.magnitude() < 0.1f) {
x404_aimTargetAverage.AddValue(zeus::skZero3f);
} else {
x404_aimTargetAverage.AddValue(predictOffset);
}
if (auto avg = x404_aimTargetAverage.GetAverage()) {
x480_assistedTargetAim = instantTarget + *avg;
} else {
x480_assistedTargetAim = predictTarget;
2018-12-08 05:30:43 +00:00
}
}
void CPlayer::ResetAimTargetPrediction(TUniqueId target) {
if (target == kInvalidUniqueId || x3f4_aimTarget != target) {
2018-12-08 05:30:43 +00:00
x404_aimTargetAverage.Clear();
}
2018-12-08 05:30:43 +00:00
x3f4_aimTarget = target;
}
void CPlayer::DrawGun(CStateManager& mgr) {
if (x498_gunHolsterState != EGunHolsterState::Holstered || InGrappleJumpCooldown()) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
x498_gunHolsterState = EGunHolsterState::Drawing;
x49c_gunHolsterRemTime = 0.45f;
x490_gun->ResetIdle(mgr);
}
void CPlayer::HolsterGun(CStateManager& mgr) {
if (x498_gunHolsterState == EGunHolsterState::Holstered || x498_gunHolsterState == EGunHolsterState::Holstering) {
2018-12-08 05:30:43 +00:00
return;
}
const float time =
x2f8_morphBallState == EPlayerMorphBallState::Morphing ? 0.1f : g_tweakPlayerGun->GetGunHolsterTime();
if (x498_gunHolsterState == EGunHolsterState::Drawing) {
2018-12-08 05:30:43 +00:00
x49c_gunHolsterRemTime = time * (1.f - x49c_gunHolsterRemTime / 0.45f);
} else {
2018-12-08 05:30:43 +00:00
x49c_gunHolsterRemTime = time;
}
2018-12-08 05:30:43 +00:00
x498_gunHolsterState = EGunHolsterState::Holstering;
x490_gun->CancelFiring(mgr);
ResetAimTargetPrediction(kInvalidUniqueId);
}
bool CPlayer::IsMorphBallTransitioning() const {
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphing:
case EPlayerMorphBallState::Unmorphing:
return true;
default:
return false;
}
}
void CPlayer::UpdateGrappleArmTransform(const zeus::CVector3f& offset, CStateManager& mgr, float dt) {
zeus::CTransform armXf = x34_transform;
zeus::CVector3f armPosition = x34_transform.rotate(offset) + x34_transform.origin;
armXf.origin = armPosition;
2018-12-08 05:30:43 +00:00
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed) {
x490_gun->GetGrappleArm().SetTransform(armXf);
} else if (!x490_gun->GetGrappleArm().IsArmMoving()) {
zeus::CVector3f lookDir = x34_transform.basis[1];
zeus::CVector3f armToTarget = x490_gun->GetGrappleArm().GetTransform().basis[1];
if (lookDir.canBeNormalized()) {
lookDir.normalize();
if (x3b8_grappleState != EGrappleState::None) {
if (const TCastToConstPtr<CActor> target = mgr.ObjectById(x310_orbitTargetId)) {
2018-12-08 05:30:43 +00:00
armToTarget = target->GetTranslation() - armPosition;
zeus::CVector3f armToTargetFlat = armToTarget;
armToTargetFlat.z() = 0.f;
if (armToTarget.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
armToTarget.normalize();
}
2018-12-08 05:30:43 +00:00
if (armToTargetFlat.canBeNormalized() && x3b8_grappleState != EGrappleState::Firing) {
const zeus::CQuaternion adjRot =
zeus::CQuaternion::lookAt(armToTargetFlat.normalized(), lookDir, 2.f * M_PIF);
2018-12-08 05:30:43 +00:00
armToTarget = adjRot.transform(armToTarget);
if (x3bc_grappleSwingTimer >= 0.25f * g_tweakPlayer->GetGrappleSwingPeriod() &&
x3bc_grappleSwingTimer < 0.75f * g_tweakPlayer->GetGrappleSwingPeriod()) {
2018-12-08 05:30:43 +00:00
armToTarget = x490_gun->GetGrappleArm().GetTransform().basis[1];
}
2018-12-08 05:30:43 +00:00
}
}
}
armXf = zeus::lookAt(zeus::skZero3f, armToTarget, zeus::skUp);
2018-12-08 05:30:43 +00:00
armXf.origin = armPosition;
x490_gun->GetGrappleArm().SetTransform(armXf);
}
}
}
float CPlayer::GetGravity() const {
if (!g_GameState->GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit) && CheckSubmerged()) {
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetFluidGravAccel();
}
if (x37c_sidewaysDashing) {
2018-12-08 05:30:43 +00:00
return -100.f;
}
2018-12-08 05:30:43 +00:00
return g_tweakPlayer->GetNormalGravAccel();
}
void CPlayer::ApplyGrappleForces(const CFinalInput& input, CStateManager& mgr, float dt) {
if (const TCastToConstPtr<CScriptGrapplePoint> point = mgr.ObjectById(x310_orbitTargetId)) {
2018-12-08 05:30:43 +00:00
switch (x3b8_grappleState) {
case EGrappleState::Pull: {
const zeus::CVector3f playerToPoint = point->GetTranslation() - GetTranslation();
2018-12-08 05:30:43 +00:00
if (playerToPoint.canBeNormalized()) {
zeus::CVector3f playerToSwingLow = point->GetTranslation() +
zeus::CVector3f(0.f, 0.f, -g_tweakPlayer->GetGrappleSwingLength()) -
GetTranslation();
if (playerToSwingLow.canBeNormalized()) {
const float distToSwingLow = playerToSwingLow.magnitude();
2018-12-08 05:30:43 +00:00
playerToSwingLow.normalize();
2021-06-07 19:29:18 +00:00
const float timeToLow =
zeus::clamp(-1.f, distToSwingLow / g_tweakPlayer->GetGrapplePullSpeedProportion(), 1.f);
const float pullSpeed =
2018-12-08 05:30:43 +00:00
timeToLow * (g_tweakPlayer->GetGrapplePullSpeedMax() - g_tweakPlayer->GetGrapplePullSpeedMin()) +
g_tweakPlayer->GetGrapplePullSpeedMin();
SetVelocityWR(playerToSwingLow * pullSpeed);
if (distToSwingLow < g_tweakPlayer->GetMaxGrappleLockedTurnAlignDistance()) {
x3b8_grappleState = EGrappleState::Swinging;
x3bc_grappleSwingTimer = 0.25f * g_tweakPlayer->GetGrappleSwingPeriod();
x3d8_grappleJumpTimeout = 0.f;
x9c6_28_aligningGrappleSwingTurn = point->GetGrappleParameters().GetLockSwingTurn();
} else {
const CMotionState mState = PredictMotion(dt);
2018-12-08 05:30:43 +00:00
zeus::CVector3f lookDirFlat = x34_transform.basis[1];
lookDirFlat.z() = 0.f;
zeus::CVector3f newPlayerToPointFlat = point->GetTranslation() - (GetTranslation() + mState.x0_translation);
newPlayerToPointFlat.z() = 0.f;
if (lookDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
lookDirFlat.normalize();
}
if (newPlayerToPointFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
newPlayerToPointFlat.normalize();
}
const float lookToPointAngle = std::acos(zeus::clamp(-1.f, lookDirFlat.dot(newPlayerToPointFlat), 1.f));
2018-12-08 05:30:43 +00:00
if (lookToPointAngle > 0.001f) {
float deltaAngle = dt * g_tweakPlayer->GetGrappleLookCenterSpeed();
if (lookToPointAngle >= deltaAngle) {
zeus::CVector3f leftDirFlat(lookDirFlat.y(), -lookDirFlat.x(), 0.f);
if (leftDirFlat.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
leftDirFlat.normalize();
}
if (newPlayerToPointFlat.dot(leftDirFlat) >= 0.f) {
2018-12-08 05:30:43 +00:00
deltaAngle = -deltaAngle;
}
RotateToOR(zeus::CQuaternion::fromAxisAngle(zeus::skUp, deltaAngle), dt);
2018-12-08 05:30:43 +00:00
} else if (std::fabs(lookToPointAngle - M_PIF) > 0.001f) {
RotateToOR(zeus::CQuaternion::shortestRotationArc(lookDirFlat, newPlayerToPointFlat), dt);
}
} else {
SetAngularVelocityWR(zeus::CAxisAngle());
x174_torque = zeus::CAxisAngle();
2017-08-19 06:52:13 +00:00
}
2018-12-08 05:30:43 +00:00
}
} else {
x3b8_grappleState = EGrappleState::Swinging;
x3bc_grappleSwingTimer = 0.25f * g_tweakPlayer->GetGrappleSwingPeriod();
x3d8_grappleJumpTimeout = 0.f;
}
}
break;
}
case EGrappleState::Swinging: {
float turnAngleSpeed = zeus::degToRad(g_tweakPlayer->GetMaxGrappleTurnSpeed());
if (g_tweakPlayer->GetInvertGrappleTurn()) {
2018-12-08 05:30:43 +00:00
turnAngleSpeed *= -1.f;
}
const zeus::CVector3f pointToPlayer = GetTranslation() - point->GetTranslation();
const float pointToPlayerZProj = zeus::clamp(-1.f, std::fabs(pointToPlayer.z() / pointToPlayer.magnitude()), 1.f);
2018-12-08 05:30:43 +00:00
bool enableTurn = false;
if (!point->GetGrappleParameters().GetLockSwingTurn()) {
if (ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnLeft, input) > 0.05f) {
enableTurn = true;
turnAngleSpeed *= -ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnLeft, input);
}
if (ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnRight, input) > 0.05f) {
enableTurn = true;
turnAngleSpeed *= ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnRight, input);
}
} else if (x9c6_28_aligningGrappleSwingTurn) {
enableTurn = true;
}
x3bc_grappleSwingTimer += dt;
if (x3bc_grappleSwingTimer > g_tweakPlayer->GetGrappleSwingPeriod()) {
2018-12-08 05:30:43 +00:00
x3bc_grappleSwingTimer -= g_tweakPlayer->GetGrappleSwingPeriod();
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f swingAxis = x3c0_grappleSwingAxis;
if (x3bc_grappleSwingTimer < 0.5f * g_tweakPlayer->GetGrappleSwingPeriod()) {
swingAxis *= zeus::skNegOne3f;
}
2018-12-08 05:30:43 +00:00
const float pullSpeed =
2018-12-08 05:30:43 +00:00
std::fabs(zeus::clamp(
-1.f,
std::cos(2.f * M_PIF * (x3bc_grappleSwingTimer / g_tweakPlayer->GetGrappleSwingPeriod()) + (M_PIF / 2.f)),
1.f)) *
g_tweakPlayer->GetGrapplePullSpeedMin();
zeus::CVector3f pullVec = pointToPlayer.normalized().cross(swingAxis) * pullSpeed;
pullVec += pointToPlayer *
zeus::clamp(-1.f,
(pointToPlayer.magnitude() - g_tweakPlayer->GetGrappleSwingLength()) /
g_tweakPlayer->GetGrappleSwingLength(),
1.f) *
-32.f * pointToPlayerZProj;
const zeus::CVector3f backupVel = x138_velocity;
2018-12-08 05:30:43 +00:00
SetVelocityWR(pullVec);
const zeus::CTransform backupXf = x34_transform;
const CMotionState predMotion = PredictMotion(dt);
const zeus::CVector3f newPos = x34_transform.origin + predMotion.x0_translation;
2018-12-08 05:30:43 +00:00
if (ValidateFPPosition(newPos, mgr)) {
if (enableTurn) {
zeus::CQuaternion turnRot;
turnRot.rotateZ(turnAngleSpeed * dt);
if (point->GetGrappleParameters().GetLockSwingTurn() && x9c6_28_aligningGrappleSwingTurn) {
zeus::CVector3f pointDir = point->GetTransform().basis[1].normalized();
const zeus::CVector3f playerDir = x34_transform.basis[1].normalized();
2018-12-08 05:30:43 +00:00
float playerPointProj = zeus::clamp(-1.f, playerDir.dot(pointDir), 1.f);
if (std::fabs(playerPointProj) == 1.f) {
2018-12-08 05:30:43 +00:00
x9c6_28_aligningGrappleSwingTurn = false;
}
2018-12-08 05:30:43 +00:00
if (playerPointProj < 0.f) {
playerPointProj = -playerPointProj;
pointDir = -pointDir;
2017-08-19 06:52:13 +00:00
}
const float turnAngleAdj = std::acos(playerPointProj) * dt;
2018-12-08 05:30:43 +00:00
turnRot = zeus::CQuaternion::lookAt(playerDir, pointDir, turnAngleAdj);
}
2018-12-08 05:30:43 +00:00
if (pointToPlayer.magSquared() > 0.04f) {
zeus::CVector3f pointToPlayerFlat = pointToPlayer;
pointToPlayerFlat.z() = 0.f;
zeus::CVector3f pointAtPlayerHeight = point->GetTranslation();
pointAtPlayerHeight.z() = GetTranslation().z();
const zeus::CVector3f playerToGrapplePlane =
2018-12-08 05:30:43 +00:00
pointAtPlayerHeight + turnRot.transform(pointToPlayerFlat) - GetTranslation();
if (playerToGrapplePlane.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
pullVec += playerToGrapplePlane / dt;
}
2018-12-08 05:30:43 +00:00
}
const zeus::CVector3f swingAxisBackup = x3c0_grappleSwingAxis;
2018-12-08 05:30:43 +00:00
x3c0_grappleSwingAxis = turnRot.transform(x3c0_grappleSwingAxis);
x3c0_grappleSwingAxis.normalize();
const zeus::CVector3f swingForward(-x3c0_grappleSwingAxis.y(), x3c0_grappleSwingAxis.x(), 0.f);
SetTransform(zeus::CTransform(x3c0_grappleSwingAxis, swingForward, zeus::skUp, GetTranslation()));
2018-12-08 05:30:43 +00:00
SetVelocityWR(pullVec);
if (!ValidateFPPosition(GetTranslation(), mgr)) {
x3c0_grappleSwingAxis = swingAxisBackup;
SetTransform(backupXf);
SetVelocityWR(backupVel);
}
}
} else {
BreakGrapple(EPlayerOrbitRequest::InvalidateTarget, mgr);
}
break;
}
case EGrappleState::JumpOff: {
const zeus::CVector3f gravForce = {0.f, 0.f, GetGravity() * xe8_mass};
ApplyForceOR(gravForce, zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
break;
2017-08-19 06:52:13 +00:00
}
2017-07-16 06:13:37 +00:00
default:
2018-12-08 05:30:43 +00:00
break;
2017-07-16 06:13:37 +00:00
}
2018-12-08 05:30:43 +00:00
}
const zeus::CVector3f newAngVel = {0.f, 0.f, 0.9f * GetAngularVelocityOR().getVector().z()};
2018-12-08 05:30:43 +00:00
SetAngularVelocityOR(newAngVel);
}
bool CPlayer::ValidateFPPosition(const zeus::CVector3f& pos, const CStateManager& mgr) const {
constexpr CMaterialFilter solidFilter = CMaterialFilter::MakeInclude({EMaterialTypes::Solid});
const zeus::CAABox aabb(x2d8_fpBounds.min - 1.f + pos, x2d8_fpBounds.max + 1.f + pos);
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildColliderList(nearList, *this, aabb);
const CCollidableAABox colAABB({GetBaseBoundingBox().min + pos, GetBaseBoundingBox().max + pos}, {});
return !CGameCollision::DetectCollisionBoolean(mgr, colAABB, zeus::CTransform(), solidFilter, nearList);
2017-09-17 03:13:03 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateGrappleState(const CFinalInput& input, CStateManager& mgr) {
if (!mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GrappleBeam) ||
x2f8_morphBallState == EPlayerMorphBallState::Morphed ||
mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan ||
mgr.GetPlayerState()->GetTransitioningVisor() == CPlayerState::EPlayerVisor::Scan) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (x310_orbitTargetId == kInvalidUniqueId) {
x3b8_grappleState = EGrappleState::None;
AddMaterial(EMaterialTypes::GroundCollider, mgr);
return;
}
const TCastToConstPtr<CScriptGrapplePoint> point = mgr.ObjectById(x310_orbitTargetId);
2018-12-08 05:30:43 +00:00
if (point) {
const zeus::CVector3f eyePosition = GetEyePosition();
2018-12-08 05:30:43 +00:00
zeus::CVector3f playerToPoint = point->GetTranslation() - eyePosition;
zeus::CVector3f playerToPointFlat = playerToPoint;
playerToPointFlat.z() = 0.f;
if (playerToPoint.canBeNormalized() && playerToPointFlat.canBeNormalized() && playerToPointFlat.magnitude() > 2.f) {
switch (x304_orbitState) {
case EPlayerOrbitState::Grapple:
switch (g_tweakPlayer->GetGrappleJumpMode()) {
case 0:
case 1:
if (ControlMapper::GetPressInput(ControlMapper::ECommands::FireOrBomb, input)) {
if (const TCastToConstPtr<CScriptGrapplePoint> point2 = mgr.ObjectById(x33c_orbitNextTargetId)) {
2018-12-08 05:30:43 +00:00
playerToPoint = point2->GetTranslation() - eyePosition;
playerToPoint.z() = 0.f;
if (playerToPoint.canBeNormalized()) {
x490_gun->GetGrappleArm().GrappleBeamDisconnected();
x3c0_grappleSwingAxis.x() = float(playerToPoint.y());
x3c0_grappleSwingAxis.y() = -playerToPoint.x();
x3c0_grappleSwingAxis.normalize();
x3bc_grappleSwingTimer = 0.f;
SetOrbitTargetId(x33c_orbitNextTargetId, mgr);
x3b8_grappleState = EGrappleState::Pull;
x33c_orbitNextTargetId = kInvalidUniqueId;
x490_gun->GetGrappleArm().GrappleBeamConnected();
}
} else {
if (g_tweakPlayer->GetGrappleJumpMode() == 0 && x3d8_grappleJumpTimeout <= 0.f) {
2018-12-08 05:30:43 +00:00
ApplyGrappleJump(mgr);
}
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
break;
default:
break;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
2017-08-16 05:34:02 +00:00
break;
2018-12-08 05:30:43 +00:00
case EPlayerOrbitState::OrbitObject:
if (playerToPoint.canBeNormalized()) {
const CRayCastResult result = mgr.RayStaticIntersection(eyePosition, playerToPoint.normalized(),
playerToPoint.magnitude(), LineOfSightFilter);
2018-12-08 05:30:43 +00:00
if (result.IsInvalid()) {
HolsterGun(mgr);
switch (x3b8_grappleState) {
case EGrappleState::Firing:
case EGrappleState::Swinging:
switch (g_tweakPlayer->GetGrappleJumpMode()) {
case 0:
switch (x490_gun->GetGrappleArm().GetAnimState()) {
case CGrappleArm::EArmState::IntoGrappleIdle:
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input)) {
2018-12-08 05:30:43 +00:00
x490_gun->GetGrappleArm().SetAnimState(CGrappleArm::EArmState::FireGrapple);
}
2018-12-08 05:30:43 +00:00
break;
case CGrappleArm::EArmState::Connected:
BeginGrapple(playerToPoint, mgr);
break;
default:
break;
}
break;
case 1:
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input)) {
switch (x490_gun->GetGrappleArm().GetAnimState()) {
case CGrappleArm::EArmState::IntoGrappleIdle:
x490_gun->GetGrappleArm().SetAnimState(CGrappleArm::EArmState::FireGrapple);
break;
case CGrappleArm::EArmState::Connected:
BeginGrapple(playerToPoint, mgr);
break;
default:
break;
}
break;
}
break;
case 2:
switch (x490_gun->GetGrappleArm().GetAnimState()) {
case CGrappleArm::EArmState::IntoGrappleIdle:
x490_gun->GetGrappleArm().SetAnimState(CGrappleArm::EArmState::FireGrapple);
break;
case CGrappleArm::EArmState::Connected:
BeginGrapple(playerToPoint, mgr);
break;
default:
break;
}
break;
default:
break;
}
break;
case EGrappleState::None:
x3b8_grappleState = EGrappleState::Firing;
x490_gun->GetGrappleArm().Activate(true);
break;
default:
break;
}
}
2017-08-16 05:34:02 +00:00
}
break;
2018-12-08 05:30:43 +00:00
default:
2017-08-16 05:34:02 +00:00
break;
2018-12-08 05:30:43 +00:00
}
}
}
if (x304_orbitState != EPlayerOrbitState::Grapple) {
if (x304_orbitState >= EPlayerOrbitState::Grapple) {
2018-12-08 05:30:43 +00:00
return;
}
if (x304_orbitState != EPlayerOrbitState::OrbitObject) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
} else {
if (!point) {
BreakGrapple(EPlayerOrbitRequest::Default, mgr);
return;
}
switch (g_tweakPlayer->GetGrappleJumpMode()) {
case 0:
if (x3b8_grappleState == EGrappleState::JumpOff) {
x3d8_grappleJumpTimeout -= input.DeltaTime();
if (x3d8_grappleJumpTimeout <= 0.f) {
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
ComputeMovement(input, mgr, input.DeltaTime());
PreventFallingCameraPitch();
}
}
break;
case 1:
switch (x3b8_grappleState) {
case EGrappleState::Swinging:
if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input) &&
x3d8_grappleJumpTimeout <= 0.f) {
x3d8_grappleJumpTimeout = g_tweakPlayer->GetGrappleReleaseTime();
x3b8_grappleState = EGrappleState::JumpOff;
ApplyGrappleJump(mgr);
2017-08-16 05:34:02 +00:00
}
break;
2018-12-08 05:30:43 +00:00
case EGrappleState::JumpOff:
x3d8_grappleJumpTimeout -= input.DeltaTime();
if (x3d8_grappleJumpTimeout <= 0.f) {
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
ComputeMovement(input, mgr, input.DeltaTime());
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
PreventFallingCameraPitch();
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
break;
case EGrappleState::Firing:
case EGrappleState::Pull:
if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input)) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
}
2018-12-08 05:30:43 +00:00
break;
default:
break;
}
break;
default:
break;
2017-08-16 05:34:02 +00:00
}
const zeus::CVector3f eyePos = GetEyePosition();
const zeus::CVector3f playerToPoint = point->GetTranslation() - eyePos;
2018-12-08 05:30:43 +00:00
if (playerToPoint.canBeNormalized()) {
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayStaticIntersection(eyePos, playerToPoint.normalized(), playerToPoint.magnitude(), LineOfSightFilter);
if (result.IsValid()) {
BreakGrapple(EPlayerOrbitRequest::LostGrappleLineOfSight, mgr);
}
}
return;
}
if (x490_gun->GetGrappleArm().BeamActive() && g_tweakPlayer->GetGrappleJumpMode() == 1 &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::FireOrBomb, input)) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::ApplyGrappleJump(CStateManager& mgr) {
const TCastToConstPtr<CScriptGrapplePoint> point = mgr.ObjectById(x310_orbitTargetId);
if (!point) {
return;
}
zeus::CVector3f tmp = x3c0_grappleSwingAxis;
if (x3bc_grappleSwingTimer < 0.5f * g_tweakPlayer->GetGrappleSwingPeriod()) {
tmp *= zeus::skNegOne3f;
}
const zeus::CVector3f pointToPlayer = GetTranslation() - point->GetTranslation();
const zeus::CVector3f cross = pointToPlayer.normalized().cross(tmp);
const zeus::CVector3f pointToPlayerFlat(pointToPlayer.x(), pointToPlayer.y(), 0.f);
float dot = 1.f;
if (pointToPlayerFlat.canBeNormalized() && cross.canBeNormalized()) {
dot = zeus::clamp(-1.f, std::fabs(cross.normalized().dot(pointToPlayerFlat.normalized())), 1.f);
2018-12-08 05:30:43 +00:00
}
ApplyForceWR(g_tweakPlayer->GetGrappleJumpForce() * cross * 10000.f * dot, zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
}
void CPlayer::BeginGrapple(zeus::CVector3f& vec, CStateManager& mgr) {
vec.z() = 0.f;
if (vec.canBeNormalized()) {
x3c0_grappleSwingAxis.x() = float(vec.y());
x3c0_grappleSwingAxis.y() = -vec.x();
x3c0_grappleSwingAxis.normalize();
x3bc_grappleSwingTimer = 0.f;
SetOrbitState(EPlayerOrbitState::Grapple, mgr);
x3b8_grappleState = EGrappleState::Pull;
RemoveMaterial(EMaterialTypes::GroundCollider, mgr);
}
}
void CPlayer::BreakGrapple(EPlayerOrbitRequest req, CStateManager& mgr) {
x294_jumpCameraTimer = 0.f;
x29c_fallCameraTimer = 0.f;
if (g_tweakPlayer->GetGrappleJumpMode() == 2 && x3b8_grappleState == EGrappleState::Swinging) {
ApplyGrappleJump(mgr);
PreventFallingCameraPitch();
}
SetOrbitRequest(req, mgr);
x3b8_grappleState = EGrappleState::None;
AddMaterial(EMaterialTypes::GroundCollider, mgr);
x490_gun->GetGrappleArm().SetAnimState(CGrappleArm::EArmState::OutOfGrapple);
if (!InGrappleJumpCooldown() && x3b8_grappleState != EGrappleState::JumpOff) {
2018-12-08 05:30:43 +00:00
DrawGun(mgr);
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::SetOrbitRequest(EPlayerOrbitRequest req, CStateManager& mgr) {
x30c_orbitRequest = req;
switch (req) {
case EPlayerOrbitRequest::ActivateOrbitSource:
ActivateOrbitSource(mgr);
break;
case EPlayerOrbitRequest::BadVerticalAngle:
SetOrbitState(EPlayerOrbitState::OrbitPoint, mgr);
x314_orbitPoint =
g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)) * x34_transform.basis[1] + x34_transform.origin;
break;
default:
SetOrbitState(EPlayerOrbitState::NoOrbit, mgr);
break;
}
}
void CPlayer::SetOrbitRequestForTarget(TUniqueId id, EPlayerOrbitRequest req, CStateManager& mgr) {
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitObject:
case EPlayerOrbitState::ForcedOrbitObject:
case EPlayerOrbitState::Grapple:
if (id == x310_orbitTargetId)
SetOrbitRequest(req, mgr);
break;
default:
break;
}
}
bool CPlayer::InGrappleJumpCooldown() const {
if (x258_movementState == EPlayerMovementState::OnGround) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
return x3d8_grappleJumpTimeout > 0.f || x294_jumpCameraTimer == 0.f;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::PreventFallingCameraPitch() {
x294_jumpCameraTimer = 0.f;
x29c_fallCameraTimer = 0.01f;
x2a4_cancelCameraPitch = true;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::OrbitCarcass(CStateManager& mgr) {
if (x304_orbitState != EPlayerOrbitState::OrbitObject) {
return;
2018-12-08 05:30:43 +00:00
}
x308_orbitType = EPlayerOrbitType::Default;
SetOrbitState(EPlayerOrbitState::OrbitCarcass, mgr);
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::OrbitPoint(EPlayerOrbitType type, CStateManager& mgr) {
x308_orbitType = type;
SetOrbitState(EPlayerOrbitState::OrbitPoint, mgr);
SetOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
zeus::CVector3f CPlayer::GetHUDOrbitTargetPosition() const {
return x314_orbitPoint + x76c_cameraBob->GetCameraBobTransformation().origin;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::SetOrbitState(EPlayerOrbitState state, CStateManager& mgr) {
x304_orbitState = state;
CFirstPersonCamera* cam = mgr.GetCameraManager()->GetFirstPersonCamera();
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitObject:
2018-12-27 06:26:34 +00:00
#ifndef NDEBUG
if (x310_orbitTargetId != kInvalidUniqueId) {
if (const CEntity* ent = mgr.GetObjectById(x310_orbitTargetId)) {
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Info, FMT_STRING("Orbiting {} {}"), ent->GetEditorId(), ent->GetName());
}
2018-12-27 06:26:34 +00:00
}
#endif
2018-12-08 05:30:43 +00:00
cam->SetLockCamera(false);
break;
case EPlayerOrbitState::OrbitCarcass: {
cam->SetLockCamera(true);
const zeus::CVector3f playerToPoint = x314_orbitPoint - GetTranslation();
if (playerToPoint.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
x340_ = playerToPoint.magnitude();
} else {
2018-12-08 05:30:43 +00:00
x340_ = 0.f;
}
2018-12-08 05:30:43 +00:00
SetOrbitTargetId(kInvalidUniqueId, mgr);
x33c_orbitNextTargetId = kInvalidUniqueId;
break;
}
case EPlayerOrbitState::NoOrbit:
x32c_orbitModeTimer = g_tweakPlayer->GetOrbitModeTimer();
x32c_orbitModeTimer = 0.28f;
SetOrbitTargetId(kInvalidUniqueId, mgr);
x33c_orbitNextTargetId = kInvalidUniqueId;
break;
case EPlayerOrbitState::OrbitPoint:
SetOrbitTargetId(kInvalidUniqueId, mgr);
x33c_orbitNextTargetId = kInvalidUniqueId;
break;
default:
break;
}
}
void CPlayer::SetOrbitTargetId(TUniqueId id, CStateManager& mgr) {
if (id != kInvalidUniqueId) {
x394_orbitingEnemy =
(TCastToPtr<CPatterned>(mgr.ObjectById(id)) || TCastToPtr<CWallCrawlerSwarm>(mgr.ObjectById(id)) ||
CPatterned::CastTo<MP1::CThardusRockProjectile>(mgr.ObjectById(id)) ||
2018-12-08 05:30:43 +00:00
TCastToPtr<CScriptGunTurret>(mgr.ObjectById(id)));
}
x310_orbitTargetId = id;
if (x310_orbitTargetId == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
x374_orbitLockEstablished = false;
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::UpdateOrbitPosition(float dist, CStateManager& mgr) {
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitPoint:
case EPlayerOrbitState::OrbitCarcass:
SetOrbitPosition(dist, mgr);
break;
case EPlayerOrbitState::OrbitObject:
case EPlayerOrbitState::ForcedOrbitObject:
case EPlayerOrbitState::Grapple:
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(x310_orbitTargetId)) {
if (x310_orbitTargetId != kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
x314_orbitPoint = act->GetOrbitPosition(mgr);
}
}
2018-12-08 05:30:43 +00:00
break;
default:
break;
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitZPosition() {
if (x304_orbitState != EPlayerOrbitState::OrbitPoint) {
return;
}
if (std::fabs(x320_orbitVector.z()) >= g_tweakPlayer->GetOrbitZRange()) {
return;
2018-12-08 05:30:43 +00:00
}
x314_orbitPoint.z() = x320_orbitVector.z() + x34_transform.origin.z() + GetEyeHeight();
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitFixedPosition() {
x314_orbitPoint = x34_transform.rotate(x320_orbitVector) + GetEyePosition();
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
void CPlayer::SetOrbitPosition(float dist, CStateManager& mgr) {
zeus::CTransform camXf = GetFirstPersonCameraTransform(mgr);
if (x304_orbitState == EPlayerOrbitState::OrbitPoint && x30c_orbitRequest == EPlayerOrbitRequest::BadVerticalAngle) {
2018-12-08 05:30:43 +00:00
camXf = x34_transform;
}
const zeus::CVector3f fwd = camXf.basis[1];
2018-12-08 05:30:43 +00:00
float dot = fwd.normalized().dot(fwd);
if (std::fabs(dot) > 1.f) {
2018-12-08 05:30:43 +00:00
dot = (dot > 0.f) ? 1.f : -1.f;
}
2018-12-08 05:30:43 +00:00
x314_orbitPoint = camXf.rotate(zeus::CVector3f(0.f, dist / dot, 0.f)) + camXf.origin;
x320_orbitVector = zeus::CVector3f(0.f, dist, x314_orbitPoint.z() - camXf.origin.z());
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateAimTarget(CStateManager& mgr) {
if (!ValidateAimTargetId(x3f4_aimTarget, mgr)) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(kInvalidUniqueId);
}
2018-12-08 05:30:43 +00:00
if (!GetCombatMode()) {
ResetAimTargetPrediction(kInvalidUniqueId);
x48c_aimTargetTimer = 0.f;
return;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
#if 0
if (!0 && 0)
2017-08-16 05:34:02 +00:00
{
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(kInvalidUniqueId);
x48c_aimTargetTimer = 0.f;
if (x304_orbitState == EPlayerOrbitState::One ||
x304_orbitState == EPlayerOrbitState::Four) {
if (!ValidateOrbitTargetId(x310_orbitTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
}
}
2018-12-08 05:30:43 +00:00
return;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
#endif
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
bool needsReset = false;
const TCastToConstPtr<CActor> act = mgr.ObjectById(x3f4_aimTarget);
const CActor* actp = act.GetPtr();
if (act) {
if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Target)) {
2018-12-08 05:30:43 +00:00
actp = nullptr;
}
}
2018-12-08 05:30:43 +00:00
if (g_tweakPlayer->GetAimWhenOrbitingPoint()) {
if (x304_orbitState == EPlayerOrbitState::OrbitObject || x304_orbitState == EPlayerOrbitState::ForcedOrbitObject) {
if (ValidateOrbitTargetId(x310_orbitTargetId, mgr) == EOrbitValidationResult::OK) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
} else {
2018-12-08 05:30:43 +00:00
needsReset = true;
}
2018-12-08 05:30:43 +00:00
} else {
needsReset = true;
}
} else {
if (x304_orbitState == EPlayerOrbitState::NoOrbit) {
2018-12-08 05:30:43 +00:00
needsReset = true;
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
if (!needsReset) {
return;
}
if (actp && ValidateObjectForMode(x3f4_aimTarget, mgr)) {
ResetAimTargetPrediction(kInvalidUniqueId);
} else {
ResetAimTargetPrediction(FindAimTargetId(mgr));
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateAimTargetTimer(float dt) {
if (x3f4_aimTarget == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
return;
}
if (x48c_aimTargetTimer <= 0.f) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
x48c_aimTargetTimer -= dt;
}
2018-12-08 05:30:43 +00:00
bool CPlayer::ValidateAimTargetId(TUniqueId uid, CStateManager& mgr) {
if (uid == kInvalidUniqueId) {
x404_aimTargetAverage.Clear();
x48c_aimTargetTimer = 0.f;
2017-08-16 05:34:02 +00:00
return false;
2018-12-08 05:30:43 +00:00
}
const TCastToConstPtr<CActor> act = mgr.ObjectById(uid);
if (!act || !act->GetMaterialList().HasMaterial(EMaterialTypes::Target) || !act->GetIsTargetable()) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::OrbitObject || x304_orbitState == EPlayerOrbitState::ForcedOrbitObject) {
if (ValidateOrbitTargetId(x310_orbitTargetId, mgr) != EOrbitValidationResult::OK) {
ResetAimTargetPrediction(kInvalidUniqueId);
x48c_aimTargetTimer = 0.f;
return false;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
return true;
}
if (act->GetMaterialList().HasMaterial(EMaterialTypes::Target) && uid != kInvalidUniqueId &&
ValidateObjectForMode(uid, mgr)) {
const float vpWHalf = g_Viewport.x8_width / 2;
const float vpHHalf = g_Viewport.xc_height / 2;
const zeus::CVector3f aimPos = act->GetAimPosition(mgr, 0.f);
const zeus::CVector3f eyePos = GetEyePosition();
2018-12-08 05:30:43 +00:00
zeus::CVector3f eyeToAim = aimPos - eyePos;
const zeus::CVector3f screenPos = mgr.GetCameraManager()->GetFirstPersonCamera()->ConvertToScreenSpace(aimPos);
const zeus::CVector3f posInBox(vpWHalf + screenPos.x() * vpWHalf, vpHHalf + screenPos.y() * vpHHalf, screenPos.z());
2018-12-08 05:30:43 +00:00
if (WithinOrbitScreenBox(posInBox, x330_orbitZoneMode, x334_orbitType) ||
(x330_orbitZoneMode != EPlayerZoneInfo::Targeting &&
WithinOrbitScreenBox(posInBox, EPlayerZoneInfo::Targeting, x334_orbitType))) {
const float eyeToAimMag = eyeToAim.magnitude();
2018-12-08 05:30:43 +00:00
if (eyeToAimMag <= g_tweakPlayer->GetAimMaxDistance()) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId intersectId = kInvalidUniqueId;
eyeToAim.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToAim, eyeToAimMag, OccluderFilter, act);
eyeToAim.normalize();
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayWorldIntersection(intersectId, eyePos, eyeToAim, eyeToAimMag, LineOfSightFilter, nearList);
if (result.IsInvalid()) {
x48c_aimTargetTimer = g_tweakPlayer->GetAimTargetTimer();
return true;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
}
if (x48c_aimTargetTimer > 0.f) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
}
ResetAimTargetPrediction(kInvalidUniqueId);
x48c_aimTargetTimer = 0.f;
return false;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::ValidateObjectForMode(TUniqueId uid, CStateManager& mgr) const {
const TCastToPtr<CActor> act = mgr.ObjectById(uid);
if (!act || uid == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
return false;
}
2017-08-16 05:34:02 +00:00
if (TCastToConstPtr<CScriptDoor>(mgr.ObjectById(uid))) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
if (GetCombatMode()) {
if (const CHealthInfo* hInfo = act->HealthInfo(mgr)) {
if (hInfo->GetHP() > 0.f) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
} else {
if (act->GetMaterialList().HasMaterial(EMaterialTypes::Projectile) ||
act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) {
2018-12-08 05:30:43 +00:00
return true;
}
2017-08-16 05:34:02 +00:00
if (const TCastToConstPtr<CScriptGrapplePoint> point = mgr.ObjectById(uid)) {
const zeus::CVector3f playerToPoint = point->GetTranslation() - GetTranslation();
if (playerToPoint.canBeNormalized() && playerToPoint.magnitude() < g_tweakPlayer->GetOrbitDistanceMax()) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
}
}
}
if (GetExplorationMode()) {
if (!act->HealthInfo(mgr)) {
if (const TCastToConstPtr<CScriptGrapplePoint> point = mgr.ObjectById(uid)) {
const zeus::CVector3f playerToPoint = point->GetTranslation() - GetTranslation();
if (playerToPoint.canBeNormalized() && playerToPoint.magnitude() < g_tweakPlayer->GetOrbitDistanceMax()) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
} else {
return true;
}
} else {
return true;
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
return false;
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
static zeus::CAABox BuildNearListBox(bool cropBottom, const zeus::CTransform& xf, float x, float z, float y) {
const zeus::CAABox aabb(-x, cropBottom ? 0.f : -y, -z, x, y, z);
2018-12-08 05:30:43 +00:00
return aabb.getTransformedAABox(xf);
}
2017-08-16 05:34:02 +00:00
TUniqueId CPlayer::FindAimTargetId(CStateManager& mgr) const {
2018-12-08 05:30:43 +00:00
float dist = g_tweakPlayer->GetAimMaxDistance();
if (x9c6_24_extendTargetDistance) {
2018-12-08 05:30:43 +00:00
dist *= 5.f;
}
const zeus::CAABox aabb = BuildNearListBox(true, GetFirstPersonCameraTransform(mgr), g_tweakPlayer->GetAimBoxWidth(),
g_tweakPlayer->GetAimBoxHeight(), dist);
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildNearList(nearList, aabb, CMaterialFilter::MakeInclude({EMaterialTypes::Target}), this);
return CheckEnemiesAgainstOrbitZone(nearList, EPlayerZoneInfo::Targeting, EPlayerZoneType::Ellipse, mgr);
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
const zeus::CTransform& CPlayer::GetFirstPersonCameraTransform(const CStateManager& mgr) const {
return mgr.GetCameraManager()->GetFirstPersonCamera()->GetGunFollowTransform();
}
2017-08-16 05:34:02 +00:00
2021-06-07 19:29:18 +00:00
TUniqueId CPlayer::CheckEnemiesAgainstOrbitZone(const EntityList& list, EPlayerZoneInfo info, EPlayerZoneType zone,
CStateManager& mgr) const {
const zeus::CVector3f eyePos = GetEyePosition();
2018-12-08 05:30:43 +00:00
float minEyeToAimMag = 10000.f;
float minPosInBoxMagSq = 10000.f;
TUniqueId bestId = kInvalidUniqueId;
const float vpWHalf = g_Viewport.x8_width / 2;
const float vpHHalf = g_Viewport.xc_height / 2;
const float boxLeft = (GetOrbitZoneIdealXScaled(int(info)) - vpWHalf) / vpWHalf;
const float boxTop = (GetOrbitZoneIdealYScaled(int(info)) - vpHHalf) / vpHHalf;
const CFirstPersonCamera* fpCam = mgr.GetCameraManager()->GetFirstPersonCamera();
for (const auto& id : list) {
if (const auto* act = static_cast<CActor*>(mgr.ObjectById(id))) {
2018-12-08 05:30:43 +00:00
if (act->GetUniqueId() != GetUniqueId() && ValidateObjectForMode(act->GetUniqueId(), mgr)) {
const zeus::CVector3f aimPos = act->GetAimPosition(mgr, 0.f);
const zeus::CVector3f screenPos = fpCam->ConvertToScreenSpace(aimPos);
2021-06-07 19:29:18 +00:00
const zeus::CVector3f posInBox(vpWHalf + screenPos.x() * vpWHalf, vpHHalf + screenPos.y() * vpHHalf,
screenPos.z());
2018-12-08 05:30:43 +00:00
if (WithinOrbitScreenBox(posInBox, info, zone)) {
zeus::CVector3f eyeToAim = aimPos - eyePos;
const float eyeToAimMag = eyeToAim.magnitude();
2018-12-08 05:30:43 +00:00
if (eyeToAimMag <= g_tweakPlayer->GetAimMaxDistance()) {
if (minEyeToAimMag - eyeToAimMag > g_tweakPlayer->GetAimThresholdDistance()) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId intersectId = kInvalidUniqueId;
eyeToAim.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToAim, eyeToAimMag, OccluderFilter, act);
eyeToAim.normalize();
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayWorldIntersection(intersectId, eyePos, eyeToAim, eyeToAimMag, LineOfSightFilter, nearList);
if (result.IsInvalid()) {
bestId = act->GetUniqueId();
const float posInBoxLeft = posInBox.x() - boxLeft;
const float posInBoxTop = posInBox.y() - boxTop;
2018-12-08 05:30:43 +00:00
minEyeToAimMag = eyeToAimMag;
minPosInBoxMagSq = posInBoxLeft * posInBoxLeft + posInBoxTop * posInBoxTop;
}
} else if (std::fabs(eyeToAimMag - minEyeToAimMag) < g_tweakPlayer->GetAimThresholdDistance()) {
const float posInBoxLeft = posInBox.x() - boxLeft;
const float posInBoxTop = posInBox.y() - boxTop;
const float posInBoxMagSq = posInBoxLeft * posInBoxLeft + posInBoxTop * posInBoxTop;
2018-12-08 05:30:43 +00:00
if (posInBoxMagSq < minPosInBoxMagSq) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId intersectId = kInvalidUniqueId;
eyeToAim.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToAim, eyeToAimMag, OccluderFilter, act);
eyeToAim.normalize();
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayWorldIntersection(intersectId, eyePos, eyeToAim, eyeToAimMag, LineOfSightFilter, nearList);
if (result.IsInvalid()) {
bestId = act->GetUniqueId();
minEyeToAimMag = eyeToAimMag;
minPosInBoxMagSq = posInBoxMagSq;
}
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-16 05:34:02 +00:00
2018-12-08 05:30:43 +00:00
return bestId;
2017-08-16 05:34:02 +00:00
}
TUniqueId CPlayer::FindOrbitTargetId(CStateManager& mgr) const {
2018-12-08 05:30:43 +00:00
return FindBestOrbitableObject(x354_onScreenOrbitObjects, x330_orbitZoneMode, mgr);
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitableObjects(CStateManager& mgr) {
x354_onScreenOrbitObjects.clear();
x344_nearbyOrbitObjects.clear();
x364_offScreenOrbitObjects.clear();
2017-08-19 06:52:13 +00:00
if (CheckOrbitDisableSourceList(mgr)) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
float dist = GetOrbitMaxTargetDistance(mgr);
if (x9c6_24_extendTargetDistance) {
2018-12-08 05:30:43 +00:00
dist *= 5.f;
}
const zeus::CAABox nearAABB = BuildNearListBox(true, GetFirstPersonCameraTransform(mgr),
g_tweakPlayer->GetOrbitNearX(), g_tweakPlayer->GetOrbitNearZ(), dist);
const CMaterialFilter filter = mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan
? CMaterialFilter::MakeInclude({EMaterialTypes::Scannable})
: CMaterialFilter::MakeInclude({EMaterialTypes::Orbit});
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildNearList(nearList, nearAABB, filter, nullptr);
FindOrbitableObjects(nearList, x344_nearbyOrbitObjects, x330_orbitZoneMode, EPlayerZoneType::Always, mgr, true);
FindOrbitableObjects(nearList, x354_onScreenOrbitObjects, x330_orbitZoneMode, x334_orbitType, mgr, true);
FindOrbitableObjects(nearList, x364_offScreenOrbitObjects, x330_orbitZoneMode, x334_orbitType, mgr, false);
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
TUniqueId CPlayer::FindBestOrbitableObject(const std::vector<TUniqueId>& ids, EPlayerZoneInfo info,
CStateManager& mgr) const {
const zeus::CVector3f eyePos = GetEyePosition();
2018-12-08 05:30:43 +00:00
float minEyeToOrbitMag = 10000.f;
float minPosInBoxMagSq = 10000.f;
TUniqueId bestId = kInvalidUniqueId;
const float vpWidthHalf = g_Viewport.x8_width / 2;
const float vpHeightHalf = g_Viewport.xc_height / 2;
const float boxLeft = (GetOrbitZoneIdealXScaled(int(info)) - vpWidthHalf) / vpWidthHalf;
const float boxTop = (GetOrbitZoneIdealYScaled(int(info)) - vpHeightHalf) / vpHeightHalf;
2017-08-02 07:13:11 +00:00
const CFirstPersonCamera* fpCam = mgr.GetCameraManager()->GetFirstPersonCamera();
2017-08-02 07:13:11 +00:00
for (const auto& id : ids) {
if (const TCastToConstPtr<CActor> act = mgr.ObjectById(id)) {
const zeus::CVector3f orbitPos = act->GetOrbitPosition(mgr);
2018-12-08 05:30:43 +00:00
zeus::CVector3f eyeToOrbit = orbitPos - eyePos;
const float eyeToOrbitMag = eyeToOrbit.magnitude();
const zeus::CVector3f orbitPosScreen = fpCam->ConvertToScreenSpace(orbitPos);
2018-12-08 05:30:43 +00:00
if (orbitPosScreen.z() >= 0.f) {
if (x310_orbitTargetId != id) {
if (const TCastToConstPtr<CScriptGrapplePoint> point = act.GetPtr()) {
2018-12-08 05:30:43 +00:00
if (x310_orbitTargetId != point->GetUniqueId()) {
if (mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GrappleBeam) &&
eyeToOrbitMag < minEyeToOrbitMag && eyeToOrbitMag < g_tweakPlayer->GetOrbitDistanceMax()) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId intersectId = kInvalidUniqueId;
eyeToOrbit.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToOrbit, eyeToOrbitMag, OccluderFilter, act.GetPtr());
eyeToOrbit.normalize();
const CRayCastResult result = mgr.RayWorldIntersection(intersectId, eyePos, eyeToOrbit, eyeToOrbitMag,
LineOfSightFilter, nearList);
2018-12-08 05:30:43 +00:00
if (result.IsInvalid()) {
if (point->GetGrappleParameters().GetLockSwingTurn()) {
zeus::CVector3f pointToPlayer = GetTranslation() - point->GetTranslation();
if (pointToPlayer.canBeNormalized()) {
pointToPlayer.z() = 0.f;
if (std::fabs(point->GetTransform().basis[1].normalized().dot(pointToPlayer.normalized())) <=
M_SQRT1_2F) {
2018-12-08 05:30:43 +00:00
continue;
}
2018-12-08 05:30:43 +00:00
}
}
bestId = act->GetUniqueId();
const float posInBoxLeft = orbitPosScreen.x() - boxLeft;
const float posInBoxTop = orbitPosScreen.y() - boxTop;
2018-12-08 05:30:43 +00:00
minEyeToOrbitMag = eyeToOrbitMag;
minPosInBoxMagSq = posInBoxLeft * posInBoxLeft + posInBoxTop * posInBoxTop;
}
}
continue;
}
}
if (minEyeToOrbitMag - eyeToOrbitMag > g_tweakPlayer->GetOrbitDistanceThreshold() &&
mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId idOut = kInvalidUniqueId;
eyeToOrbit.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToOrbit, eyeToOrbitMag, OccluderFilter, act.GetPtr());
for (auto it = nearList.begin(); it != nearList.end();) {
if (const CEntity* obj = mgr.ObjectById(*it)) {
2018-12-08 05:30:43 +00:00
if (obj->GetAreaIdAlways() != kInvalidAreaId) {
if (mgr.GetNextAreaId() != obj->GetAreaIdAlways()) {
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(obj->GetAreaIdAlways());
const CGameArea::EOcclusionState state =
2018-12-08 05:30:43 +00:00
area->IsPostConstructed() ? area->GetOcclusionState() : CGameArea::EOcclusionState::Occluded;
if (state == CGameArea::EOcclusionState::Occluded) {
it = nearList.erase(it);
continue;
}
}
} else {
it = nearList.erase(it);
continue;
}
}
++it;
}
eyeToOrbit.normalize();
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayWorldIntersection(idOut, eyePos, eyeToOrbit, eyeToOrbitMag, LineOfSightFilter, nearList);
if (result.IsInvalid()) {
bestId = act->GetUniqueId();
const float posInBoxLeft = orbitPosScreen.x() - boxLeft;
const float posInBoxTop = orbitPosScreen.y() - boxTop;
2018-12-08 05:30:43 +00:00
minEyeToOrbitMag = eyeToOrbitMag;
minPosInBoxMagSq = posInBoxLeft * posInBoxLeft + posInBoxTop * posInBoxTop;
}
continue;
}
if (std::fabs(eyeToOrbitMag - minEyeToOrbitMag) < g_tweakPlayer->GetOrbitDistanceThreshold() ||
mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan) {
const float posInBoxLeft = orbitPosScreen.x() - boxLeft;
const float posInBoxTop = orbitPosScreen.y() - boxTop;
const float posInBoxMagSq = posInBoxLeft * posInBoxLeft + posInBoxTop * posInBoxTop;
2018-12-08 05:30:43 +00:00
if (posInBoxMagSq < minPosInBoxMagSq) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
TUniqueId idOut = kInvalidUniqueId;
eyeToOrbit.normalize();
mgr.BuildNearList(nearList, eyePos, eyeToOrbit, eyeToOrbitMag, OccluderFilter, act.GetPtr());
for (auto it = nearList.begin(); it != nearList.end();) {
if (const CEntity* obj = mgr.ObjectById(*it)) {
2018-12-08 05:30:43 +00:00
if (obj->GetAreaIdAlways() != kInvalidAreaId) {
if (mgr.GetNextAreaId() != obj->GetAreaIdAlways()) {
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(obj->GetAreaIdAlways());
const CGameArea::EOcclusionState state =
2018-12-08 05:30:43 +00:00
area->IsPostConstructed() ? area->GetOcclusionState() : CGameArea::EOcclusionState::Occluded;
if (state == CGameArea::EOcclusionState::Occluded) {
it = nearList.erase(it);
continue;
}
}
} else {
it = nearList.erase(it);
continue;
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
++it;
}
eyeToOrbit.normalize();
const CRayCastResult result =
2018-12-08 05:30:43 +00:00
mgr.RayWorldIntersection(idOut, eyePos, eyeToOrbit, eyeToOrbitMag, LineOfSightFilter, nearList);
if (result.IsInvalid()) {
bestId = act->GetUniqueId();
minPosInBoxMagSq = posInBoxMagSq;
minEyeToOrbitMag = eyeToOrbitMag;
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
}
return bestId;
2017-08-02 07:13:11 +00:00
}
2021-06-07 19:29:18 +00:00
void CPlayer::FindOrbitableObjects(const EntityList& nearObjects, std::vector<TUniqueId>& listOut, EPlayerZoneInfo zone,
EPlayerZoneType type, CStateManager& mgr, bool onScreenTest) const {
const CFirstPersonCamera* fpCam = mgr.GetCameraManager()->GetFirstPersonCamera();
const zeus::CVector3f eyePos = GetEyePosition();
2018-12-08 05:30:43 +00:00
for (const auto& id : nearObjects) {
if (const TCastToConstPtr<CActor> act = mgr.GetObjectById(id)) {
if (GetUniqueId() == act->GetUniqueId()) {
2018-12-08 05:30:43 +00:00
continue;
}
if (ValidateOrbitTargetId(act->GetUniqueId(), mgr) != EOrbitValidationResult::OK) {
2018-12-08 05:30:43 +00:00
continue;
}
const zeus::CVector3f orbitPos = act->GetOrbitPosition(mgr);
2018-12-08 05:30:43 +00:00
zeus::CVector3f screenPos = fpCam->ConvertToScreenSpace(orbitPos);
screenPos.x() = g_Viewport.x8_width * screenPos.x() / 2.f + g_Viewport.x8_width / 2.f;
screenPos.y() = g_Viewport.xc_height * screenPos.y() / 2.f + g_Viewport.xc_height / 2.f;
bool pass = false;
if (onScreenTest) {
if (WithinOrbitScreenBox(screenPos, zone, type)) {
2018-12-08 05:30:43 +00:00
pass = true;
}
2018-12-08 05:30:43 +00:00
} else {
if (!WithinOrbitScreenBox(screenPos, zone, type)) {
2018-12-08 05:30:43 +00:00
pass = true;
}
2018-12-08 05:30:43 +00:00
}
if (pass &&
(!act->GetDoTargetDistanceTest() || (orbitPos - eyePos).magnitude() <= GetOrbitMaxTargetDistance(mgr))) {
2018-12-08 05:30:43 +00:00
listOut.push_back(id);
}
2018-12-08 05:30:43 +00:00
}
}
}
bool CPlayer::WithinOrbitScreenBox(const zeus::CVector3f& screenCoords, EPlayerZoneInfo zone,
EPlayerZoneType type) const {
if (screenCoords.z() >= 1.f) {
2017-08-02 07:13:11 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
switch (type) {
case EPlayerZoneType::Box:
return std::fabs(screenCoords.x() - GetOrbitScreenBoxCenterXScaled(int(zone))) <
GetOrbitScreenBoxHalfExtentXScaled(int(zone)) &&
std::fabs(screenCoords.y() - GetOrbitScreenBoxCenterYScaled(int(zone))) <
GetOrbitScreenBoxHalfExtentYScaled(int(zone)) &&
screenCoords.z() < 1.f;
case EPlayerZoneType::Ellipse:
return WithinOrbitScreenEllipse(screenCoords, zone);
default:
return true;
}
}
bool CPlayer::WithinOrbitScreenEllipse(const zeus::CVector3f& screenCoords, EPlayerZoneInfo zone) const {
if (screenCoords.z() >= 1.f) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
float heYSq = GetOrbitScreenBoxHalfExtentYScaled(int(zone));
heYSq *= heYSq;
float heXSq = GetOrbitScreenBoxHalfExtentXScaled(int(zone));
heXSq *= heXSq;
const float tmpY = std::fabs(screenCoords.y() - GetOrbitScreenBoxCenterYScaled(int(zone)));
const float tmpX = std::fabs(screenCoords.x() - GetOrbitScreenBoxCenterXScaled(int(zone)));
2018-12-08 05:30:43 +00:00
return tmpX * tmpX <= (1.f - tmpY * tmpY / heYSq) * heXSq;
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::CheckOrbitDisableSourceList(CStateManager& mgr) {
for (auto it = x9e4_orbitDisableList.begin(); it != x9e4_orbitDisableList.end();) {
if (mgr.GetObjectById(*it) == nullptr) {
it = x9e4_orbitDisableList.erase(it);
continue;
}
++it;
}
return !x9e4_orbitDisableList.empty();
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::RemoveOrbitDisableSource(TUniqueId uid) {
for (auto it = x9e4_orbitDisableList.begin(); it != x9e4_orbitDisableList.end();) {
if (*it == uid) {
it = x9e4_orbitDisableList.erase(it);
return;
}
++it;
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::AddOrbitDisableSource(CStateManager& mgr, TUniqueId addId) {
if (x9e4_orbitDisableList.size() >= 5) {
2018-12-08 05:30:43 +00:00
return;
}
for (const auto& uid : x9e4_orbitDisableList) {
if (uid == addId) {
2018-12-08 05:30:43 +00:00
return;
}
}
2018-12-08 05:30:43 +00:00
x9e4_orbitDisableList.push_back(addId);
ResetAimTargetPrediction(kInvalidUniqueId);
if (!TCastToConstPtr<CScriptGrapplePoint>(mgr.GetObjectById(x310_orbitTargetId))) {
2018-12-08 05:30:43 +00:00
SetOrbitTargetId(kInvalidUniqueId, mgr);
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitPreventionTimer(float dt) {
if (x378_orbitPreventionTimer <= 0.f) {
return;
}
x378_orbitPreventionTimer -= dt;
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitModeTimer(float dt) {
if (x304_orbitState == EPlayerOrbitState::NoOrbit && x32c_orbitModeTimer > 0.f) {
2018-12-08 05:30:43 +00:00
x32c_orbitModeTimer -= dt;
return;
}
2018-12-08 05:30:43 +00:00
x32c_orbitModeTimer = 0.f;
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitZone(CStateManager& mgr) {
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
x334_orbitType = EPlayerZoneType::Ellipse;
x338_ = 1;
x330_orbitZoneMode = EPlayerZoneInfo::Targeting;
} else {
x334_orbitType = EPlayerZoneType::Box;
x338_ = 2;
x330_orbitZoneMode = EPlayerZoneInfo::Scan;
}
2017-08-02 07:13:11 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateOrbitInput(const CFinalInput& input, CStateManager& mgr) {
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed || x378_orbitPreventionTimer > 0.f) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
UpdateOrbitableObjects(mgr);
if (x304_orbitState == EPlayerOrbitState::NoOrbit) {
2018-12-08 05:30:43 +00:00
x33c_orbitNextTargetId = FindOrbitTargetId(mgr);
}
2018-12-08 05:30:43 +00:00
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitClose, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitFar, input) ||
ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitObject, input)) {
switch (x304_orbitState) {
case EPlayerOrbitState::NoOrbit:
/* Disabled transitions directly from NoOrbit to OrbitObject for better keyboard handling */
#if 0
2019-02-08 01:08:15 +00:00
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitObject, input)) {
SetOrbitTargetId(x33c_orbitNextTargetId, mgr);
if (x310_orbitTargetId != kInvalidUniqueId) {
if (ValidateAimTargetId(x310_orbitTargetId, mgr)) {
2019-02-08 01:08:15 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
}
2019-02-08 01:08:15 +00:00
SetOrbitState(EPlayerOrbitState::OrbitObject, mgr);
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
} else {
2018-12-08 05:30:43 +00:00
#else
m_deferredOrbitObject = ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitObject, input);
#endif
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitFar, input)) {
2018-12-08 05:30:43 +00:00
OrbitPoint(EPlayerOrbitType::Far, mgr);
}
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitClose, input)) {
2018-12-08 05:30:43 +00:00
OrbitPoint(EPlayerOrbitType::Close, mgr);
}
2018-12-08 05:30:43 +00:00
#if 0
2019-02-08 01:08:15 +00:00
}
2018-12-08 05:30:43 +00:00
#endif
break;
case EPlayerOrbitState::Grapple:
if (x310_orbitTargetId == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
}
2018-12-08 05:30:43 +00:00
break;
case EPlayerOrbitState::OrbitObject:
if (TCastToConstPtr<CScriptGrapplePoint>(mgr.GetObjectById(x310_orbitTargetId))) {
if (ValidateCurrentOrbitTargetId(mgr) == EOrbitValidationResult::OK) {
2018-12-08 05:30:43 +00:00
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
} else {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::InvalidateTarget, mgr);
}
2018-12-08 05:30:43 +00:00
} else {
const EOrbitValidationResult result = ValidateCurrentOrbitTargetId(mgr);
if (result == EOrbitValidationResult::OK) {
2018-12-08 05:30:43 +00:00
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
} else if (result == EOrbitValidationResult::BrokenLookAngle) {
2018-12-08 05:30:43 +00:00
OrbitPoint(EPlayerOrbitType::Far, mgr);
} else if (result == EOrbitValidationResult::ExtremeHorizonAngle) {
2018-12-08 05:30:43 +00:00
SetOrbitRequest(EPlayerOrbitRequest::BadVerticalAngle, mgr);
} else {
2018-12-08 05:30:43 +00:00
ActivateOrbitSource(mgr);
}
2018-12-08 05:30:43 +00:00
}
UpdateOrbitSelection(input, mgr);
break;
case EPlayerOrbitState::OrbitPoint:
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitObject, input) || m_deferredOrbitObject) {
m_deferredOrbitObject = false;
SetOrbitTargetId(FindOrbitTargetId(mgr), mgr);
if (x310_orbitTargetId != kInvalidUniqueId) {
if (ValidateAimTargetId(x310_orbitTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
}
2018-12-08 05:30:43 +00:00
SetOrbitState(EPlayerOrbitState::OrbitObject, mgr);
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
} else {
switch (x308_orbitType) {
case EPlayerOrbitType::Far:
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitClose, input)) {
x308_orbitType = EPlayerOrbitType::Close;
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
break;
case EPlayerOrbitType::Close:
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitFar, input) &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::OrbitClose, input)) {
x308_orbitType = EPlayerOrbitType::Far;
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
break;
default:
break;
}
}
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
break;
case EPlayerOrbitState::OrbitCarcass:
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitObject, input) || m_deferredOrbitObject) {
m_deferredOrbitObject = false;
SetOrbitTargetId(FindOrbitTargetId(mgr), mgr);
if (x310_orbitTargetId != kInvalidUniqueId) {
if (ValidateAimTargetId(x310_orbitTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
}
2018-12-08 05:30:43 +00:00
SetOrbitState(EPlayerOrbitState::OrbitObject, mgr);
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
2017-02-18 02:19:50 +00:00
}
2018-12-08 05:30:43 +00:00
}
UpdateOrbitSelection(input, mgr);
break;
case EPlayerOrbitState::ForcedOrbitObject:
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
UpdateOrbitSelection(input, mgr);
break;
2017-02-18 02:19:50 +00:00
}
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::Grapple) {
x33c_orbitNextTargetId = FindOrbitTargetId(mgr);
if (x33c_orbitNextTargetId == x310_orbitTargetId) {
2018-12-08 05:30:43 +00:00
x33c_orbitNextTargetId = kInvalidUniqueId;
}
2018-12-08 05:30:43 +00:00
}
} else {
switch (x304_orbitState) {
case EPlayerOrbitState::NoOrbit:
break;
case EPlayerOrbitState::OrbitObject:
if (TCastToConstPtr<CScriptGrapplePoint>(mgr.GetObjectById(x310_orbitTargetId))) {
2018-12-08 05:30:43 +00:00
BreakGrapple(EPlayerOrbitRequest::Default, mgr);
} else {
2018-12-08 05:30:43 +00:00
SetOrbitRequest(EPlayerOrbitRequest::StopOrbit, mgr);
}
2018-12-08 05:30:43 +00:00
break;
case EPlayerOrbitState::Grapple:
if (!g_tweakPlayer->GetOrbitReleaseBreaksGrapple()) {
x33c_orbitNextTargetId = FindOrbitTargetId(mgr);
if (x33c_orbitNextTargetId == x310_orbitTargetId) {
2018-12-08 05:30:43 +00:00
x33c_orbitNextTargetId = kInvalidUniqueId;
}
2018-12-08 05:30:43 +00:00
} else {
BreakGrapple(EPlayerOrbitRequest::StopOrbit, mgr);
}
break;
case EPlayerOrbitState::ForcedOrbitObject:
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
UpdateOrbitSelection(input, mgr);
break;
default:
SetOrbitRequest(EPlayerOrbitRequest::StopOrbit, mgr);
break;
}
}
}
void CPlayer::ActivateOrbitSource(CStateManager& mgr) {
switch (x390_orbitSource) {
default:
OrbitCarcass(mgr);
break;
case 1:
SetOrbitRequest(EPlayerOrbitRequest::InvalidateTarget, mgr);
break;
case 2:
if (x394_orbitingEnemy) {
2018-12-08 05:30:43 +00:00
OrbitPoint(EPlayerOrbitType::Far, mgr);
} else {
2018-12-08 05:30:43 +00:00
OrbitCarcass(mgr);
}
2018-12-08 05:30:43 +00:00
break;
}
}
void CPlayer::UpdateOrbitSelection(const CFinalInput& input, CStateManager& mgr) {
x33c_orbitNextTargetId = FindOrbitTargetId(mgr);
const TCastToConstPtr<CScriptGrapplePoint> curPoint = mgr.GetObjectById(x310_orbitTargetId);
const TCastToConstPtr<CScriptGrapplePoint> nextPoint = mgr.GetObjectById(x33c_orbitNextTargetId);
2018-12-08 05:30:43 +00:00
if (curPoint || (x304_orbitState == EPlayerOrbitState::Grapple && !nextPoint)) {
x33c_orbitNextTargetId = kInvalidUniqueId;
return;
}
if (ControlMapper::GetPressInput(ControlMapper::ECommands::OrbitObject, input) &&
x33c_orbitNextTargetId != kInvalidUniqueId) {
SetOrbitTargetId(x33c_orbitNextTargetId, mgr);
if (ValidateAimTargetId(x310_orbitTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
ResetAimTargetPrediction(x310_orbitTargetId);
}
2018-12-08 05:30:43 +00:00
SetOrbitState(EPlayerOrbitState::OrbitObject, mgr);
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
}
void CPlayer::UpdateOrbitOrientation(CStateManager& mgr) {
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitPoint:
if (x3dc_inFreeLook) {
2018-12-08 05:30:43 +00:00
return;
}
2019-02-18 05:47:46 +00:00
[[fallthrough]];
2018-12-08 05:30:43 +00:00
case EPlayerOrbitState::OrbitObject:
case EPlayerOrbitState::OrbitCarcass:
case EPlayerOrbitState::ForcedOrbitObject: {
zeus::CVector3f playerToPoint = x314_orbitPoint - GetTranslation();
if (!x374_orbitLockEstablished) {
2018-12-08 05:30:43 +00:00
playerToPoint = mgr.GetCameraManager()->GetFirstPersonCamera()->GetTransform().basis[1];
}
2018-12-08 05:30:43 +00:00
playerToPoint.z() = 0.f;
if (playerToPoint.canBeNormalized()) {
zeus::CTransform xf = zeus::lookAt(zeus::skZero3f, playerToPoint);
2018-12-08 05:30:43 +00:00
xf.origin = GetTranslation();
SetTransform(xf);
}
break;
}
default:
break;
}
}
void CPlayer::UpdateOrbitTarget(CStateManager& mgr) {
if (!ValidateOrbitTargetIdAndPointer(x310_orbitTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
SetOrbitTargetId(kInvalidUniqueId, mgr);
}
if (!ValidateOrbitTargetIdAndPointer(x33c_orbitNextTargetId, mgr)) {
2018-12-08 05:30:43 +00:00
x33c_orbitNextTargetId = kInvalidUniqueId;
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f playerToPoint = x314_orbitPoint - GetTranslation();
playerToPoint.z() = 0.f;
const float playerToPointMag = playerToPoint.magnitude();
2018-12-08 05:30:43 +00:00
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitObject:
if (const auto* ent = static_cast<const CActor*>(mgr.GetObjectById(x310_orbitTargetId))) {
2018-12-08 05:30:43 +00:00
if (ent->GetDoTargetDistanceTest() &&
(playerToPointMag >= GetOrbitMaxLockDistance(mgr) || playerToPointMag < 0.5f)) {
if (playerToPointMag < 0.5f) {
2018-12-08 05:30:43 +00:00
SetOrbitRequest(EPlayerOrbitRequest::BadVerticalAngle, mgr);
} else {
2018-12-08 05:30:43 +00:00
ActivateOrbitSource(mgr);
}
2018-12-08 05:30:43 +00:00
}
}
UpdateOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
break;
case EPlayerOrbitState::OrbitPoint: {
if (g_tweakPlayer->GetOrbitFixedOffset() &&
std::fabs(x320_orbitVector.z()) > g_tweakPlayer->GetOrbitFixedOffsetZDiff()) {
UpdateOrbitFixedPosition();
return;
}
if (playerToPointMag < CalculateOrbitMinDistance(x308_orbitType)) {
2018-12-08 05:30:43 +00:00
UpdateOrbitPosition(CalculateOrbitMinDistance(x308_orbitType), mgr);
}
const float maxDist = g_tweakPlayer->GetOrbitMaxDistance(int(x308_orbitType));
if (playerToPointMag > maxDist) {
2018-12-08 05:30:43 +00:00
UpdateOrbitPosition(maxDist, mgr);
}
if (x3dd_lookButtonHeld) {
2018-12-08 05:30:43 +00:00
SetOrbitPosition(g_tweakPlayer->GetOrbitNormalDistance(int(x308_orbitType)), mgr);
}
const zeus::CVector3f eyeToPoint = x314_orbitPoint - GetEyePosition();
const float angleToPoint = std::asin(zeus::clamp(-1.f, std::fabs(eyeToPoint.z()) / eyeToPoint.magnitude(), 1.f));
2018-12-08 05:30:43 +00:00
if ((eyeToPoint.z() >= 0.f && angleToPoint >= g_tweakPlayer->GetOrbitUpperAngle()) ||
(eyeToPoint.z() < 0.f && angleToPoint >= g_tweakPlayer->GetOrbitLowerAngle())) {
2018-12-08 05:30:43 +00:00
SetOrbitRequest(EPlayerOrbitRequest::BadVerticalAngle, mgr);
}
2018-12-08 05:30:43 +00:00
break;
}
case EPlayerOrbitState::OrbitCarcass: {
if (x3dd_lookButtonHeld) {
2018-12-08 05:30:43 +00:00
SetOrbitPosition(x340_, mgr);
}
2018-12-08 05:30:43 +00:00
if (playerToPointMag < CalculateOrbitMinDistance(x308_orbitType)) {
UpdateOrbitPosition(CalculateOrbitMinDistance(x308_orbitType), mgr);
x340_ = CalculateOrbitMinDistance(x308_orbitType);
}
const float maxDist = g_tweakPlayer->GetOrbitMaxDistance(int(x308_orbitType));
2018-12-08 05:30:43 +00:00
if (playerToPointMag > maxDist) {
UpdateOrbitPosition(maxDist, mgr);
x340_ = g_tweakPlayer->GetOrbitMaxDistance(int(x308_orbitType));
}
break;
}
case EPlayerOrbitState::NoOrbit:
SetOrbitTargetId(kInvalidUniqueId, mgr);
break;
default:
break;
}
UpdateOrbitZPosition();
}
float CPlayer::GetOrbitMaxLockDistance(CStateManager& mgr) const {
return mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan
? g_tweakPlayer->GetScanMaxLockDistance()
: g_tweakPlayer->GetOrbitMaxLockDistance();
}
float CPlayer::GetOrbitMaxTargetDistance(CStateManager& mgr) const {
return mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan
? g_tweakPlayer->GetScanMaxTargetDistance()
: g_tweakPlayer->GetOrbitMaxTargetDistance();
}
CPlayer::EOrbitValidationResult CPlayer::ValidateOrbitTargetId(TUniqueId uid, CStateManager& mgr) const {
if (uid == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::InvalidTarget;
}
2018-12-08 05:30:43 +00:00
const TCastToConstPtr<CActor> act = mgr.GetObjectById(uid);
if (!act || !act->GetIsTargetable() || !act->GetActive()) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::InvalidTarget;
}
2018-12-08 05:30:43 +00:00
if (x740_staticTimer != 0.f) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::PlayerNotReadyToTarget;
}
2018-12-08 05:30:43 +00:00
const zeus::CVector3f eyePos = GetEyePosition();
const zeus::CVector3f eyeToOrbit = act->GetOrbitPosition(mgr) - eyePos;
2018-12-08 05:30:43 +00:00
zeus::CVector3f eyeToOrbitFlat = eyeToOrbit;
eyeToOrbitFlat.z() = 0.f;
if (eyeToOrbitFlat.canBeNormalized() && eyeToOrbitFlat.magnitude() > 1.f) {
2021-06-07 19:29:18 +00:00
const float angleFromHorizon =
std::asin(zeus::clamp(-1.f, std::fabs(eyeToOrbit.z()) / eyeToOrbit.magnitude(), 1.f));
2018-12-08 05:30:43 +00:00
if ((eyeToOrbit.z() >= 0.f && angleFromHorizon >= g_tweakPlayer->GetOrbitUpperAngle()) ||
(eyeToOrbit.z() < 0.f && angleFromHorizon >= g_tweakPlayer->GetOrbitLowerAngle())) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::ExtremeHorizonAngle;
}
2018-12-08 05:30:43 +00:00
} else {
return EOrbitValidationResult::ExtremeHorizonAngle;
}
const CPlayerState::EPlayerVisor visor = mgr.GetPlayerState()->GetCurrentVisor();
const u8 flags = act->GetTargetableVisorFlags();
if (visor == CPlayerState::EPlayerVisor::Combat && (flags & 1) == 0) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::PlayerNotReadyToTarget;
}
if (visor == CPlayerState::EPlayerVisor::Scan && (flags & 2) == 0) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::PlayerNotReadyToTarget;
}
if (visor == CPlayerState::EPlayerVisor::Thermal && (flags & 4) == 0) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::PlayerNotReadyToTarget;
}
if (visor == CPlayerState::EPlayerVisor::XRay && (flags & 8) == 0) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::PlayerNotReadyToTarget;
}
2018-12-08 05:30:43 +00:00
if (visor == CPlayerState::EPlayerVisor::Scan && act->GetAreaIdAlways() != GetAreaIdAlways()) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::TargetingThroughDoor;
}
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::OK;
}
CPlayer::EOrbitValidationResult CPlayer::ValidateCurrentOrbitTargetId(CStateManager& mgr) {
const TCastToConstPtr<CActor> act = mgr.GetObjectById(x310_orbitTargetId);
if (!act || !act->GetIsTargetable() || !act->GetActive()) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::InvalidTarget;
}
2018-12-08 05:30:43 +00:00
if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Orbit)) {
if (!act->GetMaterialList().HasMaterial(EMaterialTypes::Scannable)) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::NonTargetableTarget;
}
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::NonTargetableTarget;
}
2018-12-08 05:30:43 +00:00
}
const EOrbitValidationResult type = ValidateOrbitTargetId(x310_orbitTargetId, mgr);
if (type != EOrbitValidationResult::OK) {
2018-12-08 05:30:43 +00:00
return type;
}
2018-12-08 05:30:43 +00:00
if (mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan &&
act->GetAreaIdAlways() != GetAreaIdAlways()) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::TargetingThroughDoor;
}
2018-12-08 05:30:43 +00:00
const TCastToConstPtr<CScriptGrapplePoint> point = mgr.GetObjectById(x310_orbitTargetId);
2018-12-08 05:30:43 +00:00
if ((mgr.GetPlayerState()->GetCurrentVisor() == CPlayerState::EPlayerVisor::Scan &&
g_tweakPlayer->GetOrbitWhileScanning()) ||
point || act->GetAreaIdAlways() != GetAreaIdAlways()) {
const zeus::CVector3f eyePos = GetEyePosition();
2018-12-08 05:30:43 +00:00
TUniqueId bestId = kInvalidUniqueId;
const zeus::CVector3f eyeToOrbit = act->GetOrbitPosition(mgr) - eyePos;
2018-12-08 05:30:43 +00:00
if (eyeToOrbit.canBeNormalized()) {
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildNearList(nearList, eyePos, eyeToOrbit.normalized(), eyeToOrbit.magnitude(), OccluderFilter,
act.GetPtr());
for (auto it = nearList.begin(); it != nearList.end();) {
if (const CEntity* ent = mgr.GetObjectById(*it)) {
if (ent->GetAreaIdAlways() != mgr.GetNextAreaId()) {
const CGameArea* area = mgr.GetWorld()->GetAreaAlways(ent->GetAreaIdAlways());
CGameArea::EOcclusionState occState = CGameArea::EOcclusionState::Occluded;
if (area->IsPostConstructed()) {
2018-12-08 05:30:43 +00:00
occState = area->GetOcclusionState();
}
2018-12-08 05:30:43 +00:00
if (occState == CGameArea::EOcclusionState::Occluded) {
it = nearList.erase(it);
continue;
}
}
}
++it;
}
const CRayCastResult result = mgr.RayWorldIntersection(bestId, eyePos, eyeToOrbit.normalized(),
eyeToOrbit.magnitude(), LineOfSightFilter, nearList);
if (result.IsValid()) {
if (TCastToConstPtr<CScriptDoor>(mgr.ObjectById(bestId)) || point) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::TargetingThroughDoor;
}
}
2018-12-08 05:30:43 +00:00
}
zeus::CVector3f eyeToOrbitFlat = eyeToOrbit;
eyeToOrbitFlat.z() = 0.f;
if (eyeToOrbitFlat.canBeNormalized()) {
const float lookToOrbitAngle =
2018-12-08 05:30:43 +00:00
std::acos(zeus::clamp(-1.f, eyeToOrbitFlat.normalized().dot(GetTransform().basis[1]), 1.f));
if (x374_orbitLockEstablished) {
if (lookToOrbitAngle >= g_tweakPlayer->GetOrbitHorizAngle()) {
2018-12-08 05:30:43 +00:00
return EOrbitValidationResult::BrokenLookAngle;
}
2018-12-08 05:30:43 +00:00
} else {
if (lookToOrbitAngle <= M_PIF / 180.f) {
2018-12-08 05:30:43 +00:00
x374_orbitLockEstablished = true;
}
2018-12-08 05:30:43 +00:00
}
} else {
return EOrbitValidationResult::BrokenLookAngle;
}
}
return EOrbitValidationResult::OK;
}
bool CPlayer::ValidateOrbitTargetIdAndPointer(TUniqueId uid, CStateManager& mgr) const {
if (uid == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
return false;
}
return TCastToConstPtr<CActor>(mgr.GetObjectById(uid)).IsValid();
2018-12-08 05:30:43 +00:00
}
zeus::CVector3f CPlayer::GetBallPosition() const {
return GetTranslation() + zeus::CVector3f(0.f, 0.f, g_tweakPlayer->GetPlayerBallHalfExtent());
}
zeus::CVector3f CPlayer::GetEyePosition() const { return GetTranslation() + zeus::CVector3f(0.f, 0.f, GetEyeHeight()); }
float CPlayer::GetEyeHeight() const { return x9c8_eyeZBias + (x2d8_fpBounds.max.z() - g_tweakPlayer->GetEyeOffset()); }
float CPlayer::GetUnbiasedEyeHeight() const { return x2d8_fpBounds.max.z() - g_tweakPlayer->GetEyeOffset(); }
float CPlayer::GetStepUpHeight() const {
if (x258_movementState == EPlayerMovementState::Jump || x258_movementState == EPlayerMovementState::ApplyJump) {
2018-12-08 05:30:43 +00:00
return 0.3f;
}
2018-12-08 05:30:43 +00:00
return CPhysicsActor::GetStepUpHeight();
}
float CPlayer::GetStepDownHeight() const {
if (x258_movementState == EPlayerMovementState::Jump) {
2018-12-08 05:30:43 +00:00
return -1.f;
}
if (x258_movementState == EPlayerMovementState::ApplyJump) {
2018-12-08 05:30:43 +00:00
return 0.1f;
}
2018-12-08 05:30:43 +00:00
return CPhysicsActor::GetStepDownHeight();
}
void CPlayer::Teleport(const zeus::CTransform& xf, CStateManager& mgr, bool resetBallCam) {
CPhysicsActor::Stop();
zeus::CVector3f lookDir = xf.basis[1];
if (lookDir.canBeNormalized()) {
lookDir.normalize();
SetTransform(zeus::lookAt(zeus::skZero3f, lookDir));
2018-12-08 05:30:43 +00:00
SetTranslation(xf.origin);
x500_lookDir = lookDir;
x50c_moveDir = lookDir;
x530_gunDir = lookDir;
x524_lastPosForDirCalc = xf.origin;
x4f8_moveSpeed = 0.f;
x4fc_flatMoveSpeed = 0.f;
x53c_timeMoving = 0.f;
x4a4_moveSpeedAvg.Clear();
x540_controlDir = lookDir;
x54c_controlDirFlat = lookDir;
} else {
SetTranslation(xf.origin);
}
x9c5_31_stepCameraZBiasDirty = true;
x9c8_eyeZBias = 0.f;
x1f4_lastNonCollidingState = GetMotionState();
SetMoveState(EPlayerMovementState::OnGround, mgr);
zeus::CTransform eyeXf = x34_transform;
eyeXf.origin = GetEyePosition();
mgr.GetCameraManager()->GetFirstPersonCamera()->Reset(eyeXf, mgr);
if (resetBallCam) {
2018-12-08 05:30:43 +00:00
mgr.GetCameraManager()->GetBallCamera()->Reset(eyeXf, mgr);
}
2018-12-08 05:30:43 +00:00
ForceGunOrientation(x34_transform, mgr);
SetOrbitRequest(EPlayerOrbitRequest::Respawn, mgr);
}
void CPlayer::BombJump(const zeus::CVector3f& pos, CStateManager& mgr) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed &&
x768_morphball->GetBombJumpState() != CMorphBall::EBombJumpState::BombJumpDisabled) {
const zeus::CVector3f posToBall =
2018-12-08 05:30:43 +00:00
GetTranslation() + zeus::CVector3f(0.f, 0.f, g_tweakPlayer->GetPlayerBallHalfExtent()) - pos;
const float maxJump = g_tweakPlayer->GetBombJumpHeight();
2018-12-08 05:30:43 +00:00
if (posToBall.magSquared() < maxJump * maxJump &&
posToBall.dot(zeus::skUp) >= -g_tweakPlayer->GetPlayerBallHalfExtent()) {
2018-12-08 05:30:43 +00:00
float upVel =
std::sqrt(2.f * std::fabs(g_tweakPlayer->GetNormalGravAccel()) * g_tweakPlayer->GetBombJumpRadius());
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerBump, 0.3f, ERumblePriority::One);
x2a0_ = 0.01f;
switch (GetSurfaceRestraint()) {
case ESurfaceRestraints::Water:
upVel *= g_tweakPlayer->GetWaterBallJumpFactor();
2017-03-24 05:30:16 +00:00
break;
2018-12-08 05:30:43 +00:00
case ESurfaceRestraints::Lava:
upVel *= g_tweakPlayer->GetLavaBallJumpFactor();
2017-03-24 05:30:16 +00:00
break;
2019-01-20 06:43:11 +00:00
case ESurfaceRestraints::Phazon:
2018-12-08 05:30:43 +00:00
upVel *= g_tweakPlayer->GetPhazonBallJumpFactor();
2017-03-24 05:30:16 +00:00
break;
2018-12-08 05:30:43 +00:00
default:
2017-03-24 05:30:16 +00:00
break;
2018-12-08 05:30:43 +00:00
}
SetVelocityWR(zeus::CVector3f(0.f, 0.f, upVel));
x768_morphball->SetDamageTimer(0.1f);
x768_morphball->CancelBoosting();
if (x9d0_bombJumpCount > 0) {
if (x9d0_bombJumpCount > 2) {
x9d0_bombJumpCount = 0;
x9d4_bombJumpCheckDelayFrames = 0;
} else {
++x9d0_bombJumpCount;
}
} else {
const CBallCamera* ballCam = mgr.GetCameraManager()->GetBallCamera();
2018-12-08 05:30:43 +00:00
if (ballCam->GetTooCloseActorId() != kInvalidUniqueId && ballCam->GetTooCloseActorDistance() < 5.f) {
x9d0_bombJumpCount = 1;
x9d4_bombJumpCheckDelayFrames = 2;
}
}
2020-04-22 00:43:34 +00:00
CSfxHandle hnd = CSfxManager::AddEmitter(SFXsam_ball_jump, GetTranslation(), zeus::skZero3f, false, false, 0x7f,
kInvalidAreaId);
2018-12-08 05:30:43 +00:00
ApplySubmergedPitchBend(hnd);
}
}
}
zeus::CTransform CPlayer::CreateTransformFromMovementDirection() const {
zeus::CVector3f moveDir = x50c_moveDir;
if (moveDir.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
moveDir.normalize();
} else {
moveDir = zeus::skForward;
}
2018-12-08 05:30:43 +00:00
return {zeus::CVector3f(moveDir.y(), -moveDir.x(), 0.f), moveDir, zeus::skUp, GetTranslation()};
2018-12-08 05:30:43 +00:00
}
const CCollisionPrimitive* CPlayer::GetCollisionPrimitive() const {
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Morphed:
return GetCollidableSphere();
default:
return CPhysicsActor::GetCollisionPrimitive();
}
}
const CCollidableSphere* CPlayer::GetCollidableSphere() const { return &x768_morphball->GetCollidableSphere(); }
zeus::CTransform CPlayer::GetPrimitiveTransform() const { return CPhysicsActor::GetPrimitiveTransform(); }
void CPlayer::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CStateManager& mgr) {
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphed) {
return;
}
x768_morphball->CollidedWith(id, list, mgr);
2018-12-08 05:30:43 +00:00
}
float CPlayer::GetBallMaxVelocity() const {
return g_tweakBall->GetBallTranslationMaxSpeed(int(GetSurfaceRestraint()));
}
float CPlayer::GetActualBallMaxVelocity(float dt) const {
const ESurfaceRestraints surf = GetSurfaceRestraint();
const float friction = g_tweakBall->GetBallTranslationFriction(int(surf));
const float maxSpeed = g_tweakBall->GetBallTranslationMaxSpeed(int(surf));
const float acceleration = g_tweakBall->GetMaxBallTranslationAcceleration(int(surf));
2018-12-08 05:30:43 +00:00
return -(friction * xe8_mass * maxSpeed / (acceleration * dt) - maxSpeed - friction);
}
float CPlayer::GetActualFirstPersonMaxVelocity(float dt) const {
const ESurfaceRestraints surf = GetSurfaceRestraint();
const float friction = g_tweakPlayer->GetPlayerTranslationFriction(int(surf));
const float maxSpeed = g_tweakPlayer->GetPlayerTranslationMaxSpeed(int(surf));
const float acceleration = g_tweakPlayer->GetMaxTranslationalAcceleration(int(surf));
2018-12-08 05:30:43 +00:00
return -(friction * xe8_mass * maxSpeed / (acceleration * dt) - maxSpeed - friction);
}
void CPlayer::SetMoveState(EPlayerMovementState newState, CStateManager& mgr) {
switch (newState) {
case EPlayerMovementState::Jump:
if (x258_movementState == EPlayerMovementState::ApplyJump) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_b_jump_00, 1.f, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerBump, 0.2015f, ERumblePriority::One);
x288_startingJumpTimeout = g_tweakPlayer->GetAllowedDoubleJumpTime();
x290_minJumpTimeout = g_tweakPlayer->GetAllowedDoubleJumpTime() - g_tweakPlayer->GetMinDoubleJumpTime();
x28c_sjTimer = 0.f;
} else if (x258_movementState != EPlayerMovementState::Jump) {
CSfxHandle hnd = CSfxManager::SfxStart(SFXsam_firstjump, 1.f, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
x2a0_ = 0.01f;
x288_startingJumpTimeout = g_tweakPlayer->GetAllowedJumpTime();
x290_minJumpTimeout = g_tweakPlayer->GetAllowedJumpTime() - g_tweakPlayer->GetMinJumpTime();
if (mgr.GetPlayerState()->GetItemAmount(CPlayerState::EItemType::SpaceJumpBoots) != 0) {
2018-12-08 05:30:43 +00:00
x28c_sjTimer = g_tweakPlayer->GetMaxDoubleJumpWindow();
} else {
2018-12-08 05:30:43 +00:00
x28c_sjTimer = 0.f;
}
2018-12-08 05:30:43 +00:00
if (x294_jumpCameraTimer <= 0.f && x29c_fallCameraTimer <= 0.f && !x3dc_inFreeLook && !x3dd_lookButtonHeld) {
x294_jumpCameraTimer = 0.01f;
x2a4_cancelCameraPitch = false;
}
}
x258_movementState = EPlayerMovementState::Jump;
2019-01-20 06:43:11 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Air;
2018-12-08 05:30:43 +00:00
x2a8_timeSinceJump = 0.f;
break;
case EPlayerMovementState::Falling:
if (x258_movementState == EPlayerMovementState::OnGround) {
x288_startingJumpTimeout = g_tweakPlayer->GetAllowedLedgeTime();
x258_movementState = EPlayerMovementState::Falling;
x2a0_ = 0.01f;
if (g_tweakPlayer->GetFallingDoubleJump()) {
2018-12-08 05:30:43 +00:00
x28c_sjTimer = g_tweakPlayer->GetMaxDoubleJumpWindow();
} else {
2018-12-08 05:30:43 +00:00
x28c_sjTimer = 0.f;
}
2017-03-24 05:30:16 +00:00
}
2018-12-08 05:30:43 +00:00
break;
case EPlayerMovementState::FallingMorphed:
x258_movementState = EPlayerMovementState::FallingMorphed;
x2ac_surfaceRestraint = ESurfaceRestraints::Normal;
break;
case EPlayerMovementState::OnGround:
x300_fallingTime = 0.f;
x258_movementState = EPlayerMovementState::OnGround;
x288_startingJumpTimeout = 0.f;
x28c_sjTimer = 0.f;
x2ac_surfaceRestraint = ESurfaceRestraints::Normal;
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
2018-12-08 05:30:43 +00:00
AddMaterial(EMaterialTypes::GroundCollider);
}
2018-12-08 05:30:43 +00:00
x294_jumpCameraTimer = 0.f;
x29c_fallCameraTimer = 0.f;
x2a4_cancelCameraPitch = false;
x298_jumpPresses = 0;
break;
case EPlayerMovementState::ApplyJump:
x288_startingJumpTimeout = 0.f;
if (x258_movementState != EPlayerMovementState::ApplyJump) {
x258_movementState = EPlayerMovementState::ApplyJump;
if (x294_jumpCameraTimer <= x288_startingJumpTimeout && x29c_fallCameraTimer <= x288_startingJumpTimeout &&
!x3dc_inFreeLook && !x3dd_lookButtonHeld) {
x29c_fallCameraTimer = 0.01f;
x2a4_cancelCameraPitch = false;
}
2017-03-24 05:30:16 +00:00
}
2019-01-20 06:43:11 +00:00
x2ac_surfaceRestraint = ESurfaceRestraints::Air;
2018-12-08 05:30:43 +00:00
break;
}
2017-03-24 05:30:16 +00:00
}
2018-12-08 05:30:43 +00:00
float CPlayer::JumpInput(const CFinalInput& input, CStateManager& mgr) {
if (IsMorphBallTransitioning()) {
2018-12-08 05:30:43 +00:00
return GetGravity() * xe8_mass;
}
2018-12-08 05:30:43 +00:00
float jumpFactor = 1.f;
if (!mgr.GetPlayerState()->HasPowerUp(CPlayerState::EItemType::GravitySuit)) {
const ESurfaceRestraints restraints = GetSurfaceRestraint();
2018-12-08 05:30:43 +00:00
switch (restraints) {
case ESurfaceRestraints::Water:
jumpFactor = g_tweakPlayer->GetWaterJumpFactor();
break;
case ESurfaceRestraints::Lava:
jumpFactor = g_tweakPlayer->GetLavaJumpFactor();
break;
2019-01-20 06:43:11 +00:00
case ESurfaceRestraints::Phazon:
2018-12-08 05:30:43 +00:00
jumpFactor = g_tweakPlayer->GetPhazonJumpFactor();
break;
default:
break;
}
}
const float vJumpAccel = g_tweakPlayer->GetVerticalJumpAccel();
const float hJumpAccel = g_tweakPlayer->GetHorizontalJumpAccel();
2018-12-08 05:30:43 +00:00
float doubleJumpImpulse = g_tweakPlayer->GetDoubleJumpImpulse();
float vDoubleJumpAccel = g_tweakPlayer->GetVerticalDoubleJumpAccel();
float hDoubleJumpAccel = g_tweakPlayer->GetHorizontalDoubleJumpAccel();
if (x37c_sidewaysDashing) {
doubleJumpImpulse = g_tweakPlayer->GetSidewaysDoubleJumpImpulse();
vDoubleJumpAccel = g_tweakPlayer->GetSidewaysVerticalDoubleJumpAccel();
hDoubleJumpAccel = g_tweakPlayer->GetSidewaysHorizontalDoubleJumpAccel();
}
if (x828_distanceUnderWater >= 0.8f * GetEyeHeight()) {
2018-12-08 05:30:43 +00:00
doubleJumpImpulse *= jumpFactor;
}
2018-12-08 05:30:43 +00:00
if (x258_movementState == EPlayerMovementState::ApplyJump) {
if (g_tweakPlayer->GetMaxDoubleJumpWindow() - g_tweakPlayer->GetMinDoubleJumpWindow() >= x28c_sjTimer &&
0.f < x28c_sjTimer && ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input)) {
SetMoveState(EPlayerMovementState::Jump, mgr);
x384_dashTimer = 0.f;
x380_strafeInputAtDash = StrafeInput(input);
if (g_tweakPlayer->GetImpulseDoubleJump()) {
const zeus::CVector3f impulse(0.f, 0.f, (doubleJumpImpulse - x138_velocity.z()) * xe8_mass);
ApplyImpulseWR(impulse, zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
}
float forwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Forward, input);
const float backwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input);
if (forwards < backwards) {
2018-12-08 05:30:43 +00:00
forwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input);
}
2018-12-08 05:30:43 +00:00
return ((vDoubleJumpAccel - (vDoubleJumpAccel - hDoubleJumpAccel) * forwards) * xe8_mass) * jumpFactor;
}
return GetGravity() * xe8_mass;
}
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::JumpOrBoost, input) ||
(x258_movementState == EPlayerMovementState::Jump && x290_minJumpTimeout <= x288_startingJumpTimeout)) {
if (x258_movementState != EPlayerMovementState::Jump) {
if (ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input)) {
SetMoveState(EPlayerMovementState::Jump, mgr);
return (vJumpAccel * xe8_mass) * jumpFactor;
}
return 0.f;
2017-04-02 03:03:37 +00:00
}
2018-12-08 05:30:43 +00:00
float forwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Forward, input);
const float backwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input);
if (forwards < backwards) {
2018-12-08 05:30:43 +00:00
forwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input);
}
2018-12-08 05:30:43 +00:00
return ((vJumpAccel - (vJumpAccel - hJumpAccel) * forwards) * xe8_mass) * jumpFactor;
}
2017-04-02 03:03:37 +00:00
if (x258_movementState == EPlayerMovementState::Jump) {
2018-12-08 05:30:43 +00:00
SetMoveState(EPlayerMovementState::ApplyJump, mgr);
}
2017-06-19 07:00:50 +00:00
2018-12-08 05:30:43 +00:00
return 0.f;
2017-07-20 06:04:40 +00:00
}
2018-12-08 05:30:43 +00:00
float CPlayer::TurnInput(const CFinalInput& input) const {
if (x304_orbitState == EPlayerOrbitState::OrbitObject || x304_orbitState == EPlayerOrbitState::Grapple) {
2018-12-08 05:30:43 +00:00
return 0.f;
}
if (IsMorphBallTransitioning()) {
2018-12-08 05:30:43 +00:00
return 0.f;
}
2018-12-08 05:30:43 +00:00
float left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnLeft, input);
float right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::TurnRight, input);
2018-12-08 05:30:43 +00:00
if (g_tweakPlayer->GetFreeLookTurnsPlayer()) {
if (!g_tweakPlayer->GetHoldButtonsForFreeLook() || x3dd_lookButtonHeld) {
if (left < 0.01f && right < 0.01f) {
left = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookLeft, input);
right = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookRight, input);
}
}
} else {
if (!g_tweakPlayer->GetHoldButtonsForFreeLook() || x3dd_lookButtonHeld) {
if (left < 0.01f && right < 0.01f) {
const float f31 = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookLeft, input);
const float f1 = ControlMapper::GetAnalogInput(ControlMapper::ECommands::LookRight, input);
if (f31 > 0.01f || f1 > 0.01f) {
2018-12-08 05:30:43 +00:00
return 0.f;
}
2018-12-08 05:30:43 +00:00
}
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
right = left - right;
if (x32c_orbitModeTimer > 0.f) {
2018-12-08 05:30:43 +00:00
right *= (1.f - zeus::clamp(0.f, x32c_orbitModeTimer / g_tweakPlayer->GetOrbitModeTimer(), 1.f) * 0.5f);
}
2018-12-08 05:30:43 +00:00
return zeus::clamp(-1.f, right, 1.f);
}
2018-12-08 05:30:43 +00:00
float CPlayer::StrafeInput(const CFinalInput& input) const {
if (IsMorphBallTransitioning() || x304_orbitState == EPlayerOrbitState::NoOrbit) {
2018-12-08 05:30:43 +00:00
return 0.f;
}
2018-12-08 05:30:43 +00:00
return ControlMapper::GetAnalogInput(ControlMapper::ECommands::StrafeRight, input) -
ControlMapper::GetAnalogInput(ControlMapper::ECommands::StrafeLeft, input);
}
float CPlayer::ForwardInput(const CFinalInput& input, float turnInput) const {
float forwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Forward, input);
float backwards = ControlMapper::GetAnalogInput(ControlMapper::ECommands::Backward, input);
if (x2f8_morphBallState != EPlayerMorphBallState::Unmorphed || InGrappleJumpCooldown()) {
2018-12-08 05:30:43 +00:00
backwards = 0.f;
}
if (x2f8_morphBallState == EPlayerMorphBallState::Morphing && x584_ballTransitionAnim == 2) {
2018-12-08 05:30:43 +00:00
forwards = 0.f;
}
if (x2f8_morphBallState == EPlayerMorphBallState::Unmorphing && x584_ballTransitionAnim == 5) {
2018-12-08 05:30:43 +00:00
forwards = 0.f;
}
2018-12-08 05:30:43 +00:00
if (forwards >= 0.001f) {
forwards = zeus::clamp(-1.f, forwards / 0.8f, 1.f);
if (std::fabs(std::atan2(std::fabs(turnInput), forwards)) < M_PIF / 3.6f) {
const zeus::CVector3f x50(std::fabs(turnInput), forwards, 0.f);
if (x50.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
forwards = x50.magnitude();
}
2018-12-08 05:30:43 +00:00
}
}
if (backwards >= 0.001f) {
backwards = zeus::clamp(-1.f, backwards / 0.8f, 1.f);
if (std::fabs(std::atan2(std::fabs(turnInput), backwards)) < M_PIF / 3.6f) {
const zeus::CVector3f x5c(std::fabs(turnInput), backwards, 0.f);
if (x5c.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
backwards = x5c.magnitude();
}
2018-12-08 05:30:43 +00:00
}
}
if (!g_tweakPlayer->GetMoveDuringFreeLook()) {
zeus::CVector3f velFlat = x138_velocity;
velFlat.z() = 0.f;
if (x3dc_inFreeLook || x3dd_lookButtonHeld) {
if (x258_movementState == EPlayerMovementState::OnGround || std::fabs(velFlat.magnitude()) < 0.00001f) {
2018-12-08 05:30:43 +00:00
return 0.f;
}
}
2018-12-08 05:30:43 +00:00
}
2018-12-08 05:30:43 +00:00
return zeus::clamp(-1.f, forwards - backwards * g_tweakPlayer->GetBackwardsForceMultiplier(), 1.f);
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f CPlayer::CalculateLeftStickEdgePosition(float strafeInput, float forwardInput) const {
float f31 = -1.f;
float f30 = -0.555f;
float f29 = 0.555f;
2017-07-16 06:13:37 +00:00
2018-12-08 05:30:43 +00:00
if (strafeInput >= 0.f) {
f31 = -f31;
f30 = -f30;
}
2017-07-16 06:13:37 +00:00
if (forwardInput < 0.f) {
2018-12-08 05:30:43 +00:00
f29 = -0.555f;
}
2017-07-16 06:13:37 +00:00
const float f4 = zeus::clamp(-1.f, std::atan(std::fabs(forwardInput) / std::fabs(strafeInput)) / (M_PIF / 4.f), 1.f);
2018-12-08 05:30:43 +00:00
return zeus::CVector3f(f30 - f31, f29, 0.f) * f4 + zeus::CVector3f(f31, 0.f, 0.f);
}
2017-07-16 06:13:37 +00:00
2018-12-08 05:30:43 +00:00
bool CPlayer::SidewaysDashAllowed(float strafeInput, float forwardInput, const CFinalInput& input,
CStateManager& mgr) const {
if (x9c5_28_slidingOnWall || x9c5_29_hitWall || x304_orbitState != EPlayerOrbitState::OrbitObject) {
2018-12-08 05:30:43 +00:00
return false;
}
2017-07-16 06:13:37 +00:00
2018-12-08 05:30:43 +00:00
if (g_tweakPlayer->GetDashOnButtonRelease()) {
if (x304_orbitState != EPlayerOrbitState::NoOrbit && g_tweakPlayer->GetDashEnabled() &&
x288_startingJumpTimeout > 0.f &&
!ControlMapper::GetDigitalInput(ControlMapper::ECommands::JumpOrBoost, input) &&
x388_dashButtonHoldTime < g_tweakPlayer->GetDashButtonHoldCancelTime() &&
std::fabs(strafeInput) >= std::fabs(forwardInput) &&
std::fabs(strafeInput) > g_tweakPlayer->GetDashStrafeInputThreshold()) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
} else {
if (x304_orbitState != EPlayerOrbitState::NoOrbit && g_tweakPlayer->GetDashEnabled() &&
2020-04-22 00:43:34 +00:00
ControlMapper::GetPressInput(ControlMapper::ECommands::JumpOrBoost, input) && x288_startingJumpTimeout > 0.f &&
std::fabs(strafeInput) >= std::fabs(forwardInput) && std::fabs(strafeInput) > 0.01f) {
const float threshold = std::sqrt(strafeInput * strafeInput + forwardInput * forwardInput) /
CalculateLeftStickEdgePosition(strafeInput, forwardInput).magnitude();
if (threshold >= g_tweakPlayer->GetDashStrafeInputThreshold()) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
}
}
return false;
}
void CPlayer::FinishSidewaysDash() {
if (x37c_sidewaysDashing) {
2018-12-08 05:30:43 +00:00
x38c_doneSidewaysDashing = true;
}
2018-12-08 05:30:43 +00:00
x37c_sidewaysDashing = false;
x380_strafeInputAtDash = 0.f;
x384_dashTimer = 0.f;
}
void CPlayer::ComputeDash(const CFinalInput& input, float dt, CStateManager& mgr) {
const float strafeInput = StrafeInput(input);
const float forwardInput = ForwardInput(input, TurnInput(input));
2018-12-08 05:30:43 +00:00
zeus::CVector3f orbitPointFlattened(x314_orbitPoint.x(), x314_orbitPoint.y(), GetTranslation().z());
const zeus::CVector3f orbitToPlayer = GetTranslation() - orbitPointFlattened;
if (!orbitToPlayer.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
zeus::CVector3f useOrbitToPlayer = orbitToPlayer;
const ESurfaceRestraints restraints = GetSurfaceRestraint();
float strafeVel = dt * skStrafeDistances[size_t(restraints)];
if (ControlMapper::GetDigitalInput(ControlMapper::ECommands::JumpOrBoost, input)) {
2018-12-08 05:30:43 +00:00
x388_dashButtonHoldTime += dt;
}
2018-12-08 05:30:43 +00:00
if (!x37c_sidewaysDashing) {
if (SidewaysDashAllowed(strafeInput, forwardInput, input, mgr)) {
x37c_sidewaysDashing = true;
x380_strafeInputAtDash = strafeInput;
x38c_doneSidewaysDashing = true;
x384_dashTimer = 0.f;
zeus::CVector3f vel = x138_velocity;
if (vel.z() > 0.f) {
vel.z() *= 0.1f;
if (!x9c5_28_slidingOnWall) {
SetVelocityWR(vel);
x778_dashSfx = CSfxManager::SfxStart(SFXsam_dash, 1.f, 0.f, true, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(x778_dashSfx);
mgr.GetRumbleManager().Rumble(mgr, ERumbleFxId::PlayerBump, 0.24375f, ERumblePriority::One);
}
}
}
strafeVel *= strafeInput;
} else {
x384_dashTimer += dt;
if (x258_movementState == EPlayerMovementState::OnGround || x384_dashTimer >= x3a0_dashDuration ||
x9c5_28_slidingOnWall || x9c5_29_hitWall || x304_orbitState != EPlayerOrbitState::OrbitObject) {
FinishSidewaysDash();
strafeVel *= strafeInput;
CSfxManager::RemoveEmitter(x778_dashSfx);
} else {
if (x39c_noStrafeDashBlend) {
strafeVel = dt * skDashStrafeDistances[size_t(restraints)] * x398_dashSpeedMultiplier;
2018-12-08 05:30:43 +00:00
} else {
strafeVel = ((skDashStrafeDistances[size_t(restraints)] - skStrafeDistances[size_t(restraints)]) *
2018-12-08 05:30:43 +00:00
(1.f - zeus::clamp(-1.f, x384_dashTimer / x3a4_strafeDashBlendDuration, 1.f)) +
skStrafeDistances[size_t(restraints)]) *
2018-12-08 05:30:43 +00:00
x398_dashSpeedMultiplier * dt;
}
if (x380_strafeInputAtDash < 0.f) {
2018-12-08 05:30:43 +00:00
strafeVel = -strafeVel;
}
2018-12-08 05:30:43 +00:00
}
}
const float f3 = strafeVel / orbitToPlayer.magnitude();
const float f2 = dt * (x37c_sidewaysDashing ? M_PIF : (M_PIF * 2.f / 3.f));
2020-04-22 00:43:34 +00:00
useOrbitToPlayer = zeus::CQuaternion::fromAxisAngle(zeus::skUp, zeus::clamp(-f2, f3, f2)).transform(orbitToPlayer);
2018-12-08 05:30:43 +00:00
orbitPointFlattened += useOrbitToPlayer;
if (!ControlMapper::GetDigitalInput(ControlMapper::ECommands::JumpOrBoost, input)) {
2018-12-08 05:30:43 +00:00
x388_dashButtonHoldTime = 0.f;
}
strafeVel = skOrbitForwardDistances[size_t(restraints)] * forwardInput * dt;
2018-12-08 05:30:43 +00:00
orbitPointFlattened += -useOrbitToPlayer.normalized() * strafeVel;
const zeus::CVector2f velFlat(x138_velocity.x(), x138_velocity.y());
2018-12-08 05:30:43 +00:00
zeus::CVector3f newVelocity = (orbitPointFlattened - GetTranslation()) / dt;
const zeus::CVector3f velDelta(newVelocity.x() - x138_velocity.x(), newVelocity.y() - x138_velocity.y(), 0.f);
2018-12-08 05:30:43 +00:00
strafeVel = velDelta.magnitude();
if (strafeVel <= FLT_EPSILON) {
return;
}
const float accel = dt * GetAcceleration();
newVelocity = velDelta / strafeVel * accel * zeus::clamp(-1.f, strafeVel / accel, 1.f) + x138_velocity;
if (x9c5_28_slidingOnWall) {
return;
2018-12-08 05:30:43 +00:00
}
SetVelocityWR(newVelocity);
2018-12-08 05:30:43 +00:00
}
void CPlayer::ComputeMovement(const CFinalInput& input, CStateManager& mgr, float dt) {
ESurfaceRestraints restraints = GetSurfaceRestraint();
const float jumpInput = JumpInput(input, mgr);
2018-12-08 05:30:43 +00:00
float zRotateInput = TurnInput(input);
const float forwardInput = ForwardInput(input, zRotateInput);
2018-12-08 05:30:43 +00:00
SetVelocityWR(GetDampedClampedVelocityWR());
float turnSpeedMul = g_tweakPlayer->GetTurnSpeedMultiplier();
if (g_tweakPlayer->GetFreeLookTurnsPlayer()) {
if (!g_tweakPlayer->GetHoldButtonsForFreeLook() || x3dd_lookButtonHeld) {
2018-12-08 05:30:43 +00:00
turnSpeedMul = g_tweakPlayer->GetFreeLookTurnSpeedMultiplier();
}
}
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::NoOrbit ||
(x3dd_lookButtonHeld && x304_orbitState != EPlayerOrbitState::OrbitObject &&
x304_orbitState != EPlayerOrbitState::Grapple)) {
if (std::fabs(zRotateInput) < 0.00001f) {
const float frictionZAngVel =
2018-12-08 05:30:43 +00:00
g_tweakPlayer->GetPlayerRotationFriction(int(restraints)) * GetAngularVelocityOR().getVector().z();
SetAngularVelocityOR({0.f, 0.f, frictionZAngVel});
}
const float curZAngVel = GetAngularVelocityOR().getVector().z();
const float maxZAngVel = g_tweakPlayer->GetPlayerRotationMaxSpeed(int(restraints)) * turnSpeedMul;
if (curZAngVel > maxZAngVel) {
2018-12-08 05:30:43 +00:00
SetAngularVelocityOR({0.f, 0.f, maxZAngVel});
} else if (-curZAngVel > maxZAngVel) {
2018-12-08 05:30:43 +00:00
SetAngularVelocityOR({0.f, 0.f, -maxZAngVel});
}
2018-12-08 05:30:43 +00:00
}
float f26 = g_tweakPlayer->GetPlayerRotationMaxSpeed(int(restraints)) * zRotateInput * turnSpeedMul;
f26 -= GetAngularVelocityOR().getVector().z();
const float remainVel = zeus::clamp(
2018-12-08 05:30:43 +00:00
0.f, std::fabs(f26) / (turnSpeedMul * g_tweakPlayer->GetPlayerRotationMaxSpeed(int(restraints))), 1.f);
if (f26 < 0.f) {
2018-12-08 05:30:43 +00:00
zRotateInput = remainVel * -g_tweakPlayer->GetMaxRotationalAcceleration(int(restraints));
} else {
2018-12-08 05:30:43 +00:00
zRotateInput = remainVel * g_tweakPlayer->GetMaxRotationalAcceleration(int(restraints));
}
2018-12-08 05:30:43 +00:00
float forwardForce;
if (std::fabs(forwardInput) >= 0.00001f) {
const float maxSpeed = g_tweakPlayer->GetPlayerTranslationMaxSpeed(int(restraints));
const float calcSpeed = g_tweakPlayer->GetPlayerTranslationFriction(int(restraints)) * xe8_mass /
(dt * g_tweakPlayer->GetMaxTranslationalAcceleration(int(restraints))) * maxSpeed;
const float f28 = (forwardInput > 0.f ? 1.f : -1.f) * calcSpeed + (maxSpeed - calcSpeed) * forwardInput;
2018-12-08 05:30:43 +00:00
forwardForce = zeus::clamp(-1.f, (f28 - x34_transform.transposeRotate(x138_velocity).y()) / maxSpeed, 1.f) *
g_tweakPlayer->GetMaxTranslationalAcceleration(int(restraints));
} else {
forwardForce = 0.f;
}
if (x304_orbitState != EPlayerOrbitState::NoOrbit && x3dd_lookButtonHeld) {
2018-12-08 05:30:43 +00:00
forwardForce = 0.f;
}
2018-12-08 05:30:43 +00:00
if (x304_orbitState == EPlayerOrbitState::NoOrbit || x3dd_lookButtonHeld) {
ApplyForceOR({0.f, forwardForce, jumpInput}, zeus::CAxisAngle());
if (zRotateInput != 0.f) {
ApplyForceOR(zeus::skZero3f, zeus::CAxisAngle({0.f, 0.f, 1.f}, zRotateInput));
}
if (x37c_sidewaysDashing) {
2018-12-08 05:30:43 +00:00
x38c_doneSidewaysDashing = true;
}
2018-12-08 05:30:43 +00:00
x37c_sidewaysDashing = false;
x380_strafeInputAtDash = 0.f;
x384_dashTimer = 0.f;
} else {
switch (x304_orbitState) {
case EPlayerOrbitState::OrbitObject:
case EPlayerOrbitState::OrbitPoint:
case EPlayerOrbitState::OrbitCarcass:
case EPlayerOrbitState::ForcedOrbitObject:
if (!InGrappleJumpCooldown()) {
2018-12-08 05:30:43 +00:00
ComputeDash(input, dt, mgr);
}
2018-12-08 05:30:43 +00:00
break;
default:
break;
2017-07-16 06:13:37 +00:00
}
ApplyForceOR({0.f, 0.f, jumpInput}, zeus::CAxisAngle());
2018-12-08 05:30:43 +00:00
}
2017-07-16 06:13:37 +00:00
2018-12-08 05:30:43 +00:00
if (x3dc_inFreeLook || x3dd_lookButtonHeld) {
if (!x9c5_28_slidingOnWall && x258_movementState == EPlayerMovementState::OnGround) {
const zeus::CVector3f revVelFlat(-x138_velocity.x(), -x138_velocity.y(), 0.f);
const float revVelFlatMag = revVelFlat.magnitude();
2018-12-08 05:30:43 +00:00
if (revVelFlatMag > FLT_EPSILON) {
const float accel = 0.2f * dt * GetAcceleration();
const float damp = zeus::clamp(-1.f, revVelFlatMag / accel, 1.f);
2018-12-08 05:30:43 +00:00
SetVelocityWR(revVelFlat / revVelFlatMag * accel * damp + x138_velocity);
}
}
}
x9c5_29_hitWall = false;
if (x2d4_accelerationChangeTimer > 0.f) {
2018-12-08 05:30:43 +00:00
x2d0_curAcceleration = 0;
} else {
2018-12-08 05:30:43 +00:00
x2d0_curAcceleration += 1;
}
2018-12-08 05:30:43 +00:00
x2d4_accelerationChangeTimer -= dt;
x2d4_accelerationChangeTimer = std::max(0.f, x2d4_accelerationChangeTimer);
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
float CPlayer::GetWeight() const { return xe8_mass * -GetGravity(); }
zeus::CVector3f CPlayer::GetDampedClampedVelocityWR() const {
zeus::CVector3f localVel = x34_transform.transposeRotate(x138_velocity);
2019-01-20 06:43:11 +00:00
if ((x258_movementState != EPlayerMovementState::ApplyJump || GetSurfaceRestraint() != ESurfaceRestraints::Air) &&
2018-12-08 05:30:43 +00:00
x304_orbitState == EPlayerOrbitState::NoOrbit) {
const float friction = g_tweakPlayer->GetPlayerTranslationFriction(int(GetSurfaceRestraint()));
if (localVel.y() > 0.f) {
2018-12-08 05:30:43 +00:00
localVel.y() = std::max(0.f, localVel.y() - friction);
} else {
2018-12-08 05:30:43 +00:00
localVel.y() = std::min(0.f, localVel.y() + friction);
}
if (localVel.x() > 0.f) {
2018-12-08 05:30:43 +00:00
localVel.x() = std::max(0.f, localVel.x() - friction);
} else {
2018-12-08 05:30:43 +00:00
localVel.x() = std::min(0.f, localVel.x() + friction);
}
2018-12-08 05:30:43 +00:00
}
const float maxSpeed = g_tweakPlayer->GetPlayerTranslationMaxSpeed(int(GetSurfaceRestraint()));
2018-12-08 05:30:43 +00:00
localVel.y() = zeus::clamp(-maxSpeed, float(localVel.y()), maxSpeed);
if (x258_movementState == EPlayerMovementState::OnGround) {
2018-12-08 05:30:43 +00:00
localVel.z() = 0.f;
}
2018-12-08 05:30:43 +00:00
return x34_transform.rotate(localVel);
}
const CScriptWater* CPlayer::GetVisorRunoffEffect(const CStateManager& mgr) const {
if (xc4_fluidId == kInvalidUniqueId) {
2018-12-08 05:30:43 +00:00
return nullptr;
}
2018-12-08 05:30:43 +00:00
return TCastToConstPtr<CScriptWater>(mgr.GetObjectById(xc4_fluidId)).GetPtr();
}
void CPlayer::SetMorphBallState(EPlayerMorphBallState state, CStateManager& mgr) {
if (x2f8_morphBallState == EPlayerMorphBallState::Morphed && state != EPlayerMorphBallState::Morphed) {
2019-01-16 04:22:44 +00:00
x9c5_26_ = x9c4_31_inWaterMovement;
}
2018-12-08 05:30:43 +00:00
x2f8_morphBallState = state;
xf9_standardCollider = state == EPlayerMorphBallState::Morphed;
switch (x2f8_morphBallState) {
case EPlayerMorphBallState::Unmorphed:
if (x9c5_26_ && mgr.GetCameraManager()->GetFluidCounter() == 0) {
if (const auto* water = GetVisorRunoffEffect(mgr)) {
2018-12-08 05:30:43 +00:00
if (const auto& effect = water->GetUnmorphVisorRunoffEffect()) {
auto* sheets = new CHUDBillboardEffect(
2018-12-08 05:30:43 +00:00
*effect, {}, mgr.AllocateUniqueId(), true, "WaterSheets", CHUDBillboardEffect::GetNearClipDistance(mgr),
CHUDBillboardEffect::GetScaleForPOV(mgr), zeus::skWhite, zeus::skOne3f, zeus::skZero3f);
2018-12-08 05:30:43 +00:00
mgr.AddObject(sheets);
}
CSfxHandle hnd =
CSfxManager::SfxStart(water->GetUnmorphVisorRunoffSfx(), 1.f, 0.f, false, 0x7f, false, kInvalidAreaId);
ApplySubmergedPitchBend(hnd);
}
}
break;
case EPlayerMorphBallState::Morphed:
case EPlayerMorphBallState::Morphing:
x768_morphball->LoadMorphBallModel(mgr);
break;
default:
break;
}
}
bool CPlayer::CanLeaveMorphBallState(CStateManager& mgr, zeus::CVector3f& pos) const {
if (x768_morphball->IsProjectile() || !x590_leaveMorphballAllowed ||
(IsUnderBetaMetroidAttack(mgr) && x2f8_morphBallState == EPlayerMorphBallState::Morphed)) {
2018-12-08 05:30:43 +00:00
return false;
}
if (!x9c4_28_canLeaveMorphBall) {
2018-12-08 05:30:43 +00:00
return false;
}
constexpr CMaterialFilter filter = CMaterialFilter::MakeInclude({EMaterialTypes::Solid});
const zeus::CAABox aabb(x2d8_fpBounds.min - zeus::CVector3f(1.f) + GetTranslation(),
x2d8_fpBounds.max + zeus::CVector3f(1.f) + GetTranslation());
EntityList nearList;
2018-12-08 05:30:43 +00:00
mgr.BuildColliderList(nearList, *this, aabb);
const zeus::CAABox& baseAABB = GetBaseBoundingBox();
pos = zeus::skZero3f;
2018-12-08 05:30:43 +00:00
for (int i = 0; i < 8; ++i) {
const zeus::CAABox aabb2(baseAABB.min + pos + GetTranslation(), baseAABB.max + pos + GetTranslation());
const CCollidableAABox cAABB(aabb2, CMaterialList());
if (!CGameCollision::DetectCollisionBoolean(mgr, cAABB, zeus::CTransform(), filter, nearList)) {
2018-12-08 05:30:43 +00:00
return true;
}
2018-12-08 05:30:43 +00:00
pos.z() += 0.1f;
}
2018-12-08 05:30:43 +00:00
return false;
}
void CPlayer::SetHudDisable(float staticTimer, float outSpeed, float inSpeed) {
x740_staticTimer = staticTimer;
x744_staticOutSpeed = outSpeed;
x748_staticInSpeed = inSpeed;
if (x744_staticOutSpeed != 0.f) {
2018-12-08 05:30:43 +00:00
return;
}
if (x740_staticTimer == 0.f) {
2018-12-08 05:30:43 +00:00
x74c_visorStaticAlpha = 1.f;
} else {
2018-12-08 05:30:43 +00:00
x74c_visorStaticAlpha = 0.f;
}
2018-12-08 05:30:43 +00:00
}
void CPlayer::SetIntoBallReadyAnimation(CStateManager& mgr) {
constexpr CAnimPlaybackParms parms(2, -1, 1.f, true);
x64_modelData->GetAnimationData()->SetAnimation(parms, false);
x64_modelData->GetAnimationData()->EnableLooping(false);
2018-12-08 05:30:43 +00:00
x64_modelData->AdvanceAnimation(0.f, mgr, kInvalidAreaId, true);
x64_modelData->GetAnimationData()->EnableAnimation(false);
2018-12-08 05:30:43 +00:00
}
void CPlayer::LeaveMorphBallState(CStateManager& mgr) {
x730_transitionModels.clear();
AddMaterial(EMaterialTypes::GroundCollider, mgr);
x150_momentum = zeus::skZero3f;
2018-12-08 05:30:43 +00:00
SetMorphBallState(EPlayerMorphBallState::Unmorphed, mgr);
SetHudDisable(FLT_EPSILON, 0.f, 2.f);
SetHudDisable(FLT_EPSILON, 0.f, 2.f);
SetIntoBallReadyAnimation(mgr);
CPhysicsActor::Stop();
x3e4_freeLookYawAngle = 0.f;
x3e8_horizFreeLookAngleVel = 0.f;
x3ec_freeLookPitchAngle = 0.f;
x3f0_vertFreeLookAngleVel = 0.f;
x768_morphball->LeaveMorphBallState(mgr);
mgr.GetCameraManager()->SetPlayerCamera(mgr, mgr.GetCameraManager()->GetFirstPersonCamera()->GetUniqueId());
mgr.GetCameraManager()->GetBallCamera()->SetState(CBallCamera::EBallCameraState::Default, mgr);
SetCameraState(EPlayerCameraState::FirstPerson, mgr);
mgr.GetCameraManager()->GetFirstPersonCamera()->DeferBallTransitionProcessing();
mgr.GetCameraManager()->GetFirstPersonCamera()->Think(0.f, mgr);
ForceGunOrientation(x34_transform, mgr);
DrawGun(mgr);
}
bool CPlayer::CanEnterMorphBallState(CStateManager& mgr, float f1) const {
if (x3b8_grappleState != EGrappleState::None ||
(IsUnderBetaMetroidAttack(mgr) && x2f8_morphBallState == EPlayerMorphBallState::Unmorphed)) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
return x9c4_27_canEnterMorphBall;
}
void CPlayer::EnterMorphBallState(CStateManager& mgr) {
SetMorphBallState(EPlayerMorphBallState::Morphed, mgr);
RemoveMaterial(EMaterialTypes::GroundCollider, mgr);
x730_transitionModels.clear();
SetAngularVelocityOR(zeus::CAxisAngle(
zeus::CVector3f(x138_velocity.magnitude() / g_tweakPlayer->GetPlayerBallHalfExtent(), 0.f, 0.f)));
x768_morphball->EnterMorphBallState(mgr);
x768_morphball->TakeDamage(-1.f);
x768_morphball->SetDamageTimer(0.f);
mgr.GetPlayerState()->StartTransitionToVisor(CPlayerState::EPlayerVisor::Combat);
2018-12-08 05:30:43 +00:00
}
void CPlayer::ActivateMorphBallCamera(CStateManager& mgr) {
SetCameraState(EPlayerCameraState::Ball, mgr);
mgr.GetCameraManager()->GetBallCamera()->SetState(CBallCamera::EBallCameraState::Default, mgr);
}
void CPlayer::UpdateCinematicState(CStateManager& mgr) {
if (mgr.GetCameraManager()->IsInCinematicCamera()) {
if (x2f4_cameraState != EPlayerCameraState::Spawned) {
x2fc_spawnedMorphBallState = x2f8_morphBallState;
if (x2fc_spawnedMorphBallState == EPlayerMorphBallState::Unmorphing) {
2018-12-08 05:30:43 +00:00
x2fc_spawnedMorphBallState = EPlayerMorphBallState::Unmorphed;
}
if (x2fc_spawnedMorphBallState == EPlayerMorphBallState::Morphing) {
2018-12-08 05:30:43 +00:00
x2fc_spawnedMorphBallState = EPlayerMorphBallState::Morphed;
}
2018-12-08 05:30:43 +00:00
SetCameraState(EPlayerCameraState::Spawned, mgr);
}
} else {
if (x2f4_cameraState == EPlayerCameraState::Spawned) {
if (x2fc_spawnedMorphBallState == x2f8_morphBallState) {
switch (x2fc_spawnedMorphBallState) {
case EPlayerMorphBallState::Morphed:
SetCameraState(EPlayerCameraState::Ball, mgr);
break;
case EPlayerMorphBallState::Unmorphed:
SetCameraState(EPlayerCameraState::FirstPerson, mgr);
if (mgr.GetPlayerState()->GetCurrentVisor() != CPlayerState::EPlayerVisor::Scan) {
ForceGunOrientation(x34_transform, mgr);
DrawGun(mgr);
}
2019-02-18 05:47:46 +00:00
break;
2018-12-08 05:30:43 +00:00
default:
break;
}
} else {
2017-08-19 06:52:13 +00:00
CPhysicsActor::Stop();
2017-08-20 05:23:22 +00:00
SetOrbitRequest(EPlayerOrbitRequest::Respawn, mgr);
2018-12-08 05:30:43 +00:00
switch (x2fc_spawnedMorphBallState) {
case EPlayerMorphBallState::Unmorphed: {
zeus::CVector3f vec;
if (CanLeaveMorphBallState(mgr, vec)) {
SetTranslation(GetTranslation() + vec);
LeaveMorphBallState(mgr);
SetCameraState(EPlayerCameraState::FirstPerson, mgr);
ForceGunOrientation(x34_transform, mgr);
DrawGun(mgr);
}
break;
2017-08-19 06:52:13 +00:00
}
case EPlayerMorphBallState::Morphed:
2018-12-08 05:30:43 +00:00
EnterMorphBallState(mgr);
ActivateMorphBallCamera(mgr);
mgr.GetCameraManager()->SetupBallCamera(mgr);
mgr.GetCameraManager()->GetBallCamera()->Reset(CreateTransformFromMovementDirection(), mgr);
2019-02-18 05:47:46 +00:00
break;
2017-08-19 06:52:13 +00:00
default:
2018-12-08 05:30:43 +00:00
break;
}
}
}
}
}
void CPlayer::SetCameraState(EPlayerCameraState camState, CStateManager& stateMgr) {
if (x2f4_cameraState == camState) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
x2f4_cameraState = camState;
2018-12-08 05:30:43 +00:00
CCameraManager* camMgr = stateMgr.GetCameraManager();
switch (camState) {
case EPlayerCameraState::FirstPerson:
camMgr->SetCurrentCameraId(camMgr->GetFirstPersonCamera()->GetUniqueId(), stateMgr);
x768_morphball->SetBallLightActive(stateMgr, false);
break;
case EPlayerCameraState::Ball:
case EPlayerCameraState::Transitioning:
camMgr->SetCurrentCameraId(camMgr->GetBallCamera()->GetUniqueId(), stateMgr);
x768_morphball->SetBallLightActive(stateMgr, true);
break;
case EPlayerCameraState::Two:
break;
case EPlayerCameraState::Spawned: {
bool ballLight = false;
if (const TCastToConstPtr<CCinematicCamera> cineCam = camMgr->GetCurrentCamera(stateMgr)) {
2018-12-08 05:30:43 +00:00
ballLight = x2f8_morphBallState == EPlayerMorphBallState::Morphed && cineCam->GetFlags() & 0x40;
}
2018-12-08 05:30:43 +00:00
x768_morphball->SetBallLightActive(stateMgr, ballLight);
break;
}
}
}
bool CPlayer::IsEnergyLow(const CStateManager& mgr) const {
const float lowThreshold =
mgr.GetPlayerState()->GetItemCapacity(CPlayerState::EItemType::EnergyTanks) < 4 ? 30.f : 100.f;
2018-12-08 05:30:43 +00:00
return GetHealthInfo(mgr)->GetHP() < lowThreshold;
}
bool CPlayer::ObjectInScanningRange(TUniqueId id, const CStateManager& mgr) const {
const CEntity* ent = mgr.GetObjectById(id);
if (const TCastToConstPtr<CActor> act = ent) {
const zeus::CVector3f delta = act->GetTranslation() - GetTranslation();
if (delta.canBeNormalized()) {
2018-12-08 05:30:43 +00:00
return delta.magnitude() < g_tweakPlayer->GetScanningRange();
}
2018-12-08 05:30:43 +00:00
}
return false;
}
void CPlayer::SetPlayerHitWallDuringMove() {
x9c5_29_hitWall = true;
x2d0_curAcceleration = 1;
}
void CPlayer::Touch(CActor& actor, CStateManager& mgr) {
if (x2f8_morphBallState != EPlayerMorphBallState::Morphed) {
return;
}
x768_morphball->Touch(actor, mgr);
2018-12-08 05:30:43 +00:00
}
void CPlayer::CVisorSteam::SetSteam(float targetAlpha, float alphaInDur, float alphaOutDur, CAssetId txtr,
bool affectsThermal) {
2019-03-13 03:46:20 +00:00
if (!x1c_txtr.IsValid() || targetAlpha > x10_nextTargetAlpha) {
2018-12-08 05:30:43 +00:00
x10_nextTargetAlpha = targetAlpha;
x14_nextAlphaInDur = alphaInDur;
x18_nextAlphaOutDur = alphaOutDur;
x1c_txtr = txtr;
}
x28_affectsThermal = affectsThermal;
}
CAssetId CPlayer::CVisorSteam::GetTextureId() const { return xc_tex; }
void CPlayer::CVisorSteam::Update(float dt) {
2019-03-13 03:46:20 +00:00
if (!x1c_txtr.IsValid()) {
2018-12-08 05:30:43 +00:00
x0_curTargetAlpha = 0.f;
2019-03-13 03:46:20 +00:00
} else {
2018-12-08 05:30:43 +00:00
x0_curTargetAlpha = x10_nextTargetAlpha;
x4_curAlphaInDur = x14_nextAlphaInDur;
x8_curAlphaOutDur = x18_nextAlphaOutDur;
xc_tex = x1c_txtr;
}
x1c_txtr.Reset();
if (zeus::close_enough(x20_alpha, x0_curTargetAlpha) && zeus::close_enough(x20_alpha, 0.f)) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
if (x20_alpha > x0_curTargetAlpha) {
if (x24_delayTimer <= 0.f) {
x20_alpha -= dt / x8_curAlphaOutDur;
if (x20_alpha < x0_curTargetAlpha) {
2019-03-13 03:46:20 +00:00
x20_alpha = x0_curTargetAlpha;
}
2018-12-08 05:30:43 +00:00
} else {
2019-03-13 03:46:20 +00:00
x24_delayTimer -= dt;
if (x24_delayTimer < 0.f) {
2019-03-13 03:46:20 +00:00
x24_delayTimer = 0.f;
}
2018-12-08 05:30:43 +00:00
}
return;
}
const CToken tmpTex = g_SimplePool->GetObj({SBIG('TXTR'), xc_tex});
if (!tmpTex) {
2018-12-08 05:30:43 +00:00
return;
}
2018-12-08 05:30:43 +00:00
x20_alpha += dt / x4_curAlphaInDur;
if (x20_alpha > x0_curTargetAlpha) {
2018-12-08 05:30:43 +00:00
x20_alpha = x0_curTargetAlpha;
}
2018-12-08 05:30:43 +00:00
x24_delayTimer = 0.1f;
}
void CPlayer::CFailsafeTest::Reset() {
x0_stateSamples.clear();
x54_posSamples.clear();
x148_velSamples.clear();
x23c_inputSamples.clear();
}
void CPlayer::CFailsafeTest::AddSample(EInputState state, const zeus::CVector3f& pos, const zeus::CVector3f& vel,
const zeus::CVector2f& input) {
if (x0_stateSamples.size() >= 20) {
2018-12-08 05:30:43 +00:00
x0_stateSamples.resize(19);
}
2018-12-08 05:30:43 +00:00
x0_stateSamples.insert(x0_stateSamples.begin(), state);
if (x54_posSamples.size() >= 20) {
2018-12-08 05:30:43 +00:00
x54_posSamples.resize(19);
}
2018-12-08 05:30:43 +00:00
x54_posSamples.insert(x54_posSamples.begin(), pos);
if (x148_velSamples.size() >= 20) {
2018-12-08 05:30:43 +00:00
x148_velSamples.resize(19);
}
2018-12-08 05:30:43 +00:00
x148_velSamples.insert(x148_velSamples.begin(), vel);
if (x23c_inputSamples.size() >= 20) {
2018-12-08 05:30:43 +00:00
x23c_inputSamples.resize(19);
}
2018-12-08 05:30:43 +00:00
x23c_inputSamples.insert(x23c_inputSamples.begin(), input);
}
bool CPlayer::CFailsafeTest::Passes() const {
if (x0_stateSamples.size() != 20) {
2018-12-08 05:30:43 +00:00
return false;
}
2018-12-08 05:30:43 +00:00
float posMag = 0.f;
zeus::CAABox velAABB(x148_velSamples[0], x148_velSamples[0]);
zeus::CAABox posAABB(x54_posSamples[0], x54_posSamples[0]);
zeus::CVector3f inputVec(x23c_inputSamples[0].x(), x23c_inputSamples[0].y(), 0.f);
zeus::CAABox inputAABB(inputVec, inputVec);
float maxVelMag = x148_velSamples[0].magnitude();
float minVelMag = maxVelMag;
u32 notEqualStates = 0;
for (int i = 1; i < 20; ++i) {
const float mag = (x54_posSamples[i - 1] - x54_posSamples[i]).magSquared();
if (mag > FLT_EPSILON) {
2018-12-08 05:30:43 +00:00
posMag += std::sqrt(mag);
}
2018-12-08 05:30:43 +00:00
posAABB.accumulateBounds(x54_posSamples[i]);
velAABB.accumulateBounds(x148_velSamples[i]);
const float velMag = x148_velSamples[i].magnitude();
2018-12-08 05:30:43 +00:00
minVelMag = std::min(minVelMag, velMag);
maxVelMag = std::max(maxVelMag, velMag);
const zeus::CVector3f inputVec2(x23c_inputSamples[i].x(), x23c_inputSamples[i].y(), 0.f);
2018-12-08 05:30:43 +00:00
inputAABB.accumulateBounds(inputVec2);
if (x0_stateSamples[i] != x0_stateSamples[i - 1]) {
2018-12-08 05:30:43 +00:00
notEqualStates += 1;
}
2018-12-08 05:30:43 +00:00
}
bool test1 = true;
if (posMag >= 1.f / 30.f && posMag >= minVelMag / 30.f) {
2018-12-08 05:30:43 +00:00
test1 = false;
}
2018-12-08 05:30:43 +00:00
if (notEqualStates == 0 && x0_stateSamples[0] == EInputState::StartingJump) {
const float inputMag = (inputAABB.max - inputAABB.min).magnitude();
2018-12-08 05:30:43 +00:00
zeus::CAABox inputFrom0AABB(inputAABB);
inputFrom0AABB.accumulateBounds(zeus::skZero3f);
2018-12-08 05:30:43 +00:00
bool test2 = true;
if ((inputFrom0AABB.max - inputFrom0AABB.min).magnitude() >= 0.01f && inputMag <= 1.5f) {
2018-12-08 05:30:43 +00:00
test2 = false;
}
2018-12-08 05:30:43 +00:00
return test1 && test2;
}
return false;
}
void CPlayer::SetSpawnedMorphBallState(EPlayerMorphBallState state, CStateManager& mgr) {
x2fc_spawnedMorphBallState = state;
SetCameraState(EPlayerCameraState::Spawned, mgr);
if (x2fc_spawnedMorphBallState != x2f8_morphBallState) {
CPhysicsActor::Stop();
SetOrbitRequest(EPlayerOrbitRequest::Respawn, mgr);
switch (x2fc_spawnedMorphBallState) {
case EPlayerMorphBallState::Unmorphed: {
zeus::CVector3f pos;
if (CanLeaveMorphBallState(mgr, pos)) {
SetTranslation(GetTranslation() + pos);
LeaveMorphBallState(mgr);
ForceGunOrientation(x34_transform, mgr);
DrawGun(mgr);
}
break;
}
case EPlayerMorphBallState::Morphed:
EnterMorphBallState(mgr);
ActivateMorphBallCamera(mgr);
mgr.GetCameraManager()->SetupBallCamera(mgr);
mgr.GetCameraManager()->GetBallCamera()->Reset(CreateTransformFromMovementDirection(), mgr);
break;
default:
break;
2017-08-19 06:52:13 +00:00
}
2018-12-08 05:30:43 +00:00
}
2017-08-19 06:52:13 +00:00
}
2017-01-15 03:59:37 +00:00
void CPlayer::DecrementEnvironmentDamage() {
if (xa10_envDmgCounter == 0) {
2018-12-08 05:30:43 +00:00
return;
}
2017-01-15 03:59:37 +00:00
xa10_envDmgCounter--;
2017-01-15 03:59:37 +00:00
}
void CPlayer::IncrementEnvironmentDamage() {
if (xa10_envDmgCounter != 0) {
xa10_envDmgCounter++;
} else {
xa14_envDmgCameraShakeTimer = 0.f;
}
2017-01-15 03:59:37 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::CheckSubmerged() const {
if (xe6_24_fluidCounter == 0) {
2018-12-08 05:30:43 +00:00
return false;
}
2017-06-12 04:23:34 +00:00
2018-12-08 05:30:43 +00:00
return x828_distanceUnderWater >= (x2f8_morphBallState == EPlayerMorphBallState::Morphed
? 2.f * g_tweakPlayer->GetPlayerBallHalfExtent()
: 0.5f * GetEyeHeight());
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::UpdateSubmerged(CStateManager& mgr) {
x82c_inLava = false;
x828_distanceUnderWater = 0.f;
if (xe6_24_fluidCounter == 0) {
return;
}
if (const TCastToConstPtr<CScriptWater> water = mgr.ObjectById(xc4_fluidId)) {
x828_distanceUnderWater = -(zeus::skUp.dot(x34_transform.origin) - water->GetTriggerBoundsWR().max.z());
const EFluidType fluidType = water->GetFluidPlane().GetFluidType();
x82c_inLava = (fluidType == EFluidType::Lava || fluidType == EFluidType::ThickLava);
CheckSubmerged();
2018-12-08 05:30:43 +00:00
}
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::ApplySubmergedPitchBend(CSfxHandle& sfx) {
if (!CheckSubmerged()) {
return;
}
CSfxManager::PitchBend(sfx, -1.f);
2017-06-12 04:23:34 +00:00
}
2018-12-08 05:30:43 +00:00
void CPlayer::DetachActorFromPlayer() {
x26c_attachedActor = kInvalidUniqueId;
x270_attachedActorTime = 0.f;
xa28_attachedActorStruggle = 0.f;
x490_gun->SetActorAttached(false);
2017-08-19 06:52:13 +00:00
}
2018-12-08 05:30:43 +00:00
bool CPlayer::AttachActorToPlayer(TUniqueId id, bool disableGun) {
if (x26c_attachedActor != kInvalidUniqueId) {
return false;
2018-12-08 05:30:43 +00:00
}
2017-08-19 06:52:13 +00:00
if (disableGun) {
x490_gun->SetActorAttached(true);
}
x26c_attachedActor = id;
x270_attachedActorTime = 0.f;
xa28_attachedActorStruggle = 0.f;
x768_morphball->StopEffects();
return true;
2017-08-19 06:52:13 +00:00
}
2018-12-13 07:39:16 +00:00
float CPlayer::GetAverageSpeed() const {
if (const auto avg = x4a4_moveSpeedAvg.GetAverage()) {
2018-12-13 07:39:16 +00:00
return *avg;
}
2018-12-13 07:39:16 +00:00
return x4f8_moveSpeed;
}
2021-04-10 08:42:06 +00:00
} // namespace metaforce