CElitePirate: Make use of TCastToConstPtr where applicable

Makes read-only semantics more obvious at a glance.
This commit is contained in:
Lioncash 2020-04-02 00:29:40 -04:00
parent 60000c163b
commit b3753c6a92
1 changed files with 18 additions and 18 deletions

View File

@ -161,16 +161,16 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
if (HealthInfo(mgr)->GetHP() <= 0.f) { if (HealthInfo(mgr)->GetHP() <= 0.f) {
break; break;
} }
TCastToPtr<CCollisionActor> actor = mgr.ObjectById(uid); const TCastToConstPtr<CCollisionActor> actor = mgr.ObjectById(uid);
if (!actor) { if (!actor) {
if (uid == x772_launcherId && x772_launcherId != kInvalidUniqueId) { if (uid == x772_launcherId && x772_launcherId != kInvalidUniqueId) {
SetShotAt(true, mgr); SetShotAt(true, mgr);
} }
break; break;
} }
const TUniqueId& touchedUid = actor->GetLastTouchedObject(); const TUniqueId touchedUid = actor->GetLastTouchedObject();
if (touchedUid != mgr.GetPlayer().GetUniqueId()) { if (touchedUid != mgr.GetPlayer().GetUniqueId()) {
if (TCastToPtr<CGameProjectile>(mgr.ObjectById(touchedUid))) { if (TCastToConstPtr<CGameProjectile>(mgr.ObjectById(touchedUid))) {
SetShotAt(true, mgr); SetShotAt(true, mgr);
} }
break; break;
@ -220,8 +220,8 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
break; break;
case EScriptObjectMessage::Damage: case EScriptObjectMessage::Damage:
shouldPass = false; shouldPass = false;
if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(uid)) { if (const TCastToConstPtr<CCollisionActor> actor = mgr.ObjectById(uid)) {
if (TCastToPtr<CGameProjectile> projectile = mgr.ObjectById(actor->GetLastTouchedObject())) { if (const TCastToConstPtr<CGameProjectile> projectile = mgr.ObjectById(actor->GetLastTouchedObject())) {
if (uid == x770_collisionHeadId) { if (uid == x770_collisionHeadId) {
x428_damageCooldownTimer = 0.33f; x428_damageCooldownTimer = 0.33f;
const auto& damageInfo = projectile->GetDamageInfo(); const auto& damageInfo = projectile->GetDamageInfo();
@ -242,7 +242,7 @@ void CElitePirate::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSta
break; break;
case EScriptObjectMessage::InvulnDamage: { case EScriptObjectMessage::InvulnDamage: {
SetShotAt(true, mgr); SetShotAt(true, mgr);
if (!TCastToPtr<CCollisionActor>(mgr.ObjectById(uid))) { if (!TCastToConstPtr<CCollisionActor>(mgr.ObjectById(uid))) {
ApplyDamageToHead(mgr, uid); ApplyDamageToHead(mgr, uid);
} }
break; break;
@ -283,7 +283,7 @@ zeus::CVector3f CElitePirate::GetOrbitPosition(const CStateManager& mgr) const {
} }
} }
if (HasWeakPointHead()) { if (HasWeakPointHead()) {
if (TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x770_collisionHeadId)) { if (const TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x770_collisionHeadId)) {
return actor->GetTranslation(); return actor->GetTranslation();
} }
} }
@ -294,7 +294,7 @@ zeus::CVector3f CElitePirate::GetAimPosition(const CStateManager& mgr, float) co
const std::shared_ptr<CPlayerState>& playerState = mgr.GetPlayerState(); const std::shared_ptr<CPlayerState>& playerState = mgr.GetPlayerState();
if (x5d4_collisionActorMgr->GetActive() && playerState->IsFiringComboBeam() && if (x5d4_collisionActorMgr->GetActive() && playerState->IsFiringComboBeam() &&
playerState->GetCurrentBeam() == CPlayerState::EBeamId::Wave) { playerState->GetCurrentBeam() == CPlayerState::EBeamId::Wave) {
if (TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x79c_)) { if (const TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x79c_)) {
return actor->GetTranslation(); return actor->GetTranslation();
} }
} }
@ -340,7 +340,7 @@ void CElitePirate::DoUserAnimEvent(CStateManager& mgr, const CInt32POINode& node
} }
case EUserEventType::BecomeShootThrough: case EUserEventType::BecomeShootThrough:
if (HasWeakPointHead()) { if (HasWeakPointHead()) {
u32 numCollisionActors = x730_collisionActorMgrHead->GetNumCollisionActors(); const u32 numCollisionActors = x730_collisionActorMgrHead->GetNumCollisionActors();
for (u32 i = 0; i < numCollisionActors; ++i) { for (u32 i = 0; i < numCollisionActors; ++i) {
const auto& description = x730_collisionActorMgrHead->GetCollisionDescFromIndex(i); const auto& description = x730_collisionActorMgrHead->GetCollisionDescFromIndex(i);
if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(description.GetCollisionActorId())) { if (TCastToPtr<CCollisionActor> 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::SetLaunchersActive(CStateManager& mgr, bool val) { SetLauncherActive(mgr, val, x772_launcherId); }
void CElitePirate::SetupPathFindSearch() { void CElitePirate::SetupPathFindSearch() {
float scale = 1.5f * GetModelData()->GetScale().y(); const float scale = 1.5f * GetModelData()->GetScale().y();
float fVar1 = IsElitePirate() ? 5.f : 1.f; const float fVar1 = IsElitePirate() ? 5.f : 1.f;
zeus::CAABox box{{-scale, -scale, 0.f}, {scale, scale, fVar1 * scale}}; const zeus::CAABox box{{-scale, -scale, 0.f}, {scale, scale, fVar1 * scale}};
SetBoundingBox(box); SetBoundingBox(box);
x738_collisionAabb.SetBox(box); x738_collisionAabb.SetBox(box);
x7d0_pathFindSearch.SetCharacterRadius(scale); x7d0_pathFindSearch.SetCharacterRadius(scale);
@ -928,7 +928,7 @@ void CElitePirate::ApplyDamageToHead(CStateManager& mgr, TUniqueId uid) {
if (!HasWeakPointHead()) { if (!HasWeakPointHead()) {
return; return;
} }
if (TCastToPtr<CWeapon> weapon = mgr.ObjectById(uid)) { if (const TCastToConstPtr<CWeapon> weapon = mgr.ObjectById(uid)) {
CDamageInfo damageInfo = weapon->GetDamageInfo(); CDamageInfo damageInfo = weapon->GetDamageInfo();
damageInfo.SetRadius(0.f); damageInfo.SetRadius(0.f);
mgr.ApplyDamage(uid, x770_collisionHeadId, weapon->GetOwnerId(), damageInfo, mgr.ApplyDamage(uid, x770_collisionHeadId, weapon->GetOwnerId(), damageInfo,
@ -998,7 +998,7 @@ void CElitePirate::AttractProjectiles(CStateManager& mgr) {
if (!IsAlive()) { if (!IsAlive()) {
return; return;
} }
TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x79c_); const TCastToConstPtr<CCollisionActor> actor = mgr.GetObjectById(x79c_);
if (!actor) { if (!actor) {
return; return;
} }
@ -1028,13 +1028,13 @@ void CElitePirate::AttractProjectiles(CStateManager& mgr) {
if (GetTransform().frontVector().dot(actorProjDist) < 0.f) { if (GetTransform().frontVector().dot(actorProjDist) < 0.f) {
const zeus::CVector3f projectileDir = projectilePos - projectile->GetPreviousPos(); const zeus::CVector3f projectileDir = projectilePos - projectile->GetPreviousPos();
if (projectileDir.canBeNormalized() && IsClosestEnergyAttractor(mgr, charNearList, projectilePos)) { 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 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 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 p1 = zeus::getBezierPoint(projectilePos, b, c, actorPos, 0.333f);
const zeus::CVector3f p2 = zeus::getBezierPoint(projectilePos, b, c, actorPos, 0.666f); 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 = const zeus::CVector3f p3 =
zeus::getBezierPoint(projectilePos, b, c, actorPos, projectileDir.magnitude() / magAdd); 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) { void CElitePirate::UpdateHealthInfo(CStateManager& mgr) {
float hp = HealthInfo(mgr)->GetHP(); const float hp = HealthInfo(mgr)->GetHP();
if (HasWeakPointHead()) { if (HasWeakPointHead()) {
if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(x770_collisionHeadId)) { if (TCastToPtr<CCollisionActor> actor = mgr.ObjectById(x770_collisionHeadId)) {
float headHp = actor->HealthInfo(mgr)->GetHP(); const float headHp = actor->HealthInfo(mgr)->GetHP();
HealthInfo(mgr)->SetHP(hp - (hp - headHp)); HealthInfo(mgr)->SetHP(hp - (hp - headHp));
*actor->HealthInfo(mgr) = *HealthInfo(mgr); // TODO does this work? *actor->HealthInfo(mgr) = *HealthInfo(mgr); // TODO does this work?
} }