From b3753c6a92abf0154b400358f91ade6d6d74a38f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 2 Apr 2020 00:29:40 -0400 Subject: [PATCH] CElitePirate: Make use of TCastToConstPtr where applicable Makes read-only semantics more obvious at a glance. --- Runtime/MP1/World/CElitePirate.cpp | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Runtime/MP1/World/CElitePirate.cpp b/Runtime/MP1/World/CElitePirate.cpp index d92e4e3a8..22ef8533f 100644 --- a/Runtime/MP1/World/CElitePirate.cpp +++ b/Runtime/MP1/World/CElitePirate.cpp @@ -161,16 +161,16 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta if (HealthInfo(mgr)->GetHP() <= 0.f) { break; } - TCastToPtr actor = mgr.ObjectById(uid); + const TCastToConstPtr actor = mgr.ObjectById(uid); if (!actor) { if (uid == x772_launcherId && x772_launcherId != kInvalidUniqueId) { SetShotAt(true, mgr); } break; } - const TUniqueId& touchedUid = actor->GetLastTouchedObject(); + const TUniqueId touchedUid = actor->GetLastTouchedObject(); if (touchedUid != mgr.GetPlayer().GetUniqueId()) { - if (TCastToPtr(mgr.ObjectById(touchedUid))) { + if (TCastToConstPtr(mgr.ObjectById(touchedUid))) { SetShotAt(true, mgr); } break; @@ -220,8 +220,8 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta break; case EScriptObjectMessage::Damage: shouldPass = false; - if (TCastToPtr actor = mgr.ObjectById(uid)) { - if (TCastToPtr projectile = mgr.ObjectById(actor->GetLastTouchedObject())) { + if (const TCastToConstPtr actor = mgr.ObjectById(uid)) { + if (const TCastToConstPtr projectile = mgr.ObjectById(actor->GetLastTouchedObject())) { if (uid == x770_collisionHeadId) { x428_damageCooldownTimer = 0.33f; const auto& damageInfo = projectile->GetDamageInfo(); @@ -242,7 +242,7 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta break; case EScriptObjectMessage::InvulnDamage: { SetShotAt(true, mgr); - if (!TCastToPtr(mgr.ObjectById(uid))) { + if (!TCastToConstPtr(mgr.ObjectById(uid))) { ApplyDamageToHead(mgr, uid); } break; @@ -283,7 +283,7 @@ zeus::CVector3f CElitePirate::GetOrbitPosition(const CStateManager& mgr) const { } } if (HasWeakPointHead()) { - if (TCastToConstPtr actor = mgr.GetObjectById(x770_collisionHeadId)) { + if (const TCastToConstPtr actor = mgr.GetObjectById(x770_collisionHeadId)) { return actor->GetTranslation(); } } @@ -294,7 +294,7 @@ zeus::CVector3f CElitePirate::GetAimPosition(const CStateManager& mgr, float) co const std::shared_ptr& playerState = mgr.GetPlayerState(); if (x5d4_collisionActorMgr->GetActive() && playerState->IsFiringComboBeam() && playerState->GetCurrentBeam() == CPlayerState::EBeamId::Wave) { - if (TCastToConstPtr actor = mgr.GetObjectById(x79c_)) { + if (const TCastToConstPtr actor = mgr.GetObjectById(x79c_)) { return actor->GetTranslation(); } } @@ -340,7 +340,7 @@ void CElitePirate::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node } case EUserEventType::BecomeShootThrough: if (HasWeakPointHead()) { - u32 numCollisionActors = x730_collisionActorMgrHead->GetNumCollisionActors(); + const u32 numCollisionActors = x730_collisionActorMgrHead->GetNumCollisionActors(); for (u32 i = 0; i < numCollisionActors; ++i) { const auto& description = x730_collisionActorMgrHead->GetCollisionDescFromIndex(i); if (TCastToPtr actor = mgr.ObjectById(description.GetCollisionActorId())) { @@ -779,9 +779,9 @@ void CElitePirate::SetupHealthInfo(CStateManager& mgr) { void CElitePirate::SetLaunchersActive(CStateManager& mgr, bool val) { SetLauncherActive(mgr, val, x772_launcherId); } void CElitePirate::SetupPathFindSearch() { - float scale = 1.5f * GetModelData()->GetScale().y(); - float fVar1 = IsElitePirate() ? 5.f : 1.f; - zeus::CAABox box{{-scale, -scale, 0.f}, {scale, scale, fVar1 * scale}}; + const float scale = 1.5f * GetModelData()->GetScale().y(); + const float fVar1 = IsElitePirate() ? 5.f : 1.f; + const zeus::CAABox box{{-scale, -scale, 0.f}, {scale, scale, fVar1 * scale}}; SetBoundingBox(box); x738_collisionAabb.SetBox(box); x7d0_pathFindSearch.SetCharacterRadius(scale); @@ -928,7 +928,7 @@ void CElitePirate::ApplyDamageToHead(CStateManager& mgr, TUniqueId uid) { if (!HasWeakPointHead()) { return; } - if (TCastToPtr weapon = mgr.ObjectById(uid)) { + if (const TCastToConstPtr weapon = mgr.ObjectById(uid)) { CDamageInfo damageInfo = weapon->GetDamageInfo(); damageInfo.SetRadius(0.f); mgr.ApplyDamage(uid, x770_collisionHeadId, weapon->GetOwnerId(), damageInfo, @@ -998,7 +998,7 @@ void CElitePirate::AttractProjectiles(CStateManager& mgr) { if (!IsAlive()) { return; } - TCastToConstPtr actor = mgr.GetObjectById(x79c_); + const TCastToConstPtr actor = mgr.GetObjectById(x79c_); if (!actor) { return; } @@ -1028,13 +1028,13 @@ void CElitePirate::AttractProjectiles(CStateManager& mgr) { if (GetTransform().frontVector().dot(actorProjDist) < 0.f) { const zeus::CVector3f projectileDir = projectilePos - projectile->GetPreviousPos(); if (projectileDir.canBeNormalized() && IsClosestEnergyAttractor(mgr, charNearList, projectilePos)) { - float actorProjMag = actorProjDist.magnitude(); + const float actorProjMag = actorProjDist.magnitude(); const zeus::CVector3f b = projectilePos + ((0.5f * actorProjMag) * projectileDir.normalized()); const zeus::CVector3f c = actorPos + zeus::CVector3f{0.f, 0.f, 0.4f * 0.4f * actorProjMag}; const zeus::CVector3f p1 = zeus::getBezierPoint(projectilePos, b, c, actorPos, 0.333f); const zeus::CVector3f p2 = zeus::getBezierPoint(projectilePos, b, c, actorPos, 0.666f); - float magAdd = (p2 - p1).magnitude() + (p1 - projectilePos).magnitude() + (actorPos - p2).magnitude(); + const float magAdd = (p2 - p1).magnitude() + (p1 - projectilePos).magnitude() + (actorPos - p2).magnitude(); const zeus::CVector3f p3 = zeus::getBezierPoint(projectilePos, b, c, actorPos, projectileDir.magnitude() / magAdd); @@ -1118,10 +1118,10 @@ void CElitePirate::UpdateActorTransform(CStateManager& mgr, TUniqueId& uid, std: } void CElitePirate::UpdateHealthInfo(CStateManager& mgr) { - float hp = HealthInfo(mgr)->GetHP(); + const float hp = HealthInfo(mgr)->GetHP(); if (HasWeakPointHead()) { if (TCastToPtr actor = mgr.ObjectById(x770_collisionHeadId)) { - float headHp = actor->HealthInfo(mgr)->GetHP(); + const float headHp = actor->HealthInfo(mgr)->GetHP(); HealthInfo(mgr)->SetHP(hp - (hp - headHp)); *actor->HealthInfo(mgr) = *HealthInfo(mgr); // TODO does this work? }