From a4dbb5c58270959884c17d720185da06464fa256 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Wed, 2 May 2018 08:50:36 +0100 Subject: Prefer static_cast to reinterpret_cast (#4223) * Change reinterpret_cast -> static_cast wherever possible * Remove more unnecessary `const_cast`s. reinterpret_casts should be avoided for the same reason as c-style casts - they don't do any type-checking. reinterpret_cast was mainly being used for down-casting in inheritance hierarchies but static_cast works just as well while also making sure that there is actually an inheritance relationship there. --- src/Entities/Player.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Entities/Player.cpp') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index a58d45fb0..c674f4620 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -968,7 +968,7 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker != nullptr) && (a_TDI.Attacker->IsPlayer())) { - cPlayer * Attacker = reinterpret_cast(a_TDI.Attacker); + cPlayer * Attacker = static_cast(a_TDI.Attacker); if ((m_Team != nullptr) && (m_Team == Attacker->m_Team)) { @@ -1098,7 +1098,7 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) } else if (a_TDI.Attacker->IsPlayer()) { - cPlayer * Killer = reinterpret_cast(a_TDI.Attacker); + cPlayer * Killer = static_cast(a_TDI.Attacker); AString DeathMessage = Printf("%s was killed by %s", GetName().c_str(), Killer->GetName().c_str()); PluginManager->CallHookKilled(*this, a_TDI, DeathMessage); if (DeathMessage != AString("")) @@ -1139,7 +1139,7 @@ void cPlayer::Killed(cEntity * a_Victim) } else if (a_Victim->IsMob()) { - if (reinterpret_cast(a_Victim)->GetMobFamily() == cMonster::mfHostile) + if (static_cast(a_Victim)->GetMobFamily() == cMonster::mfHostile) { AwardAchievement(achKillMonster); } @@ -2529,7 +2529,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIs case cEntity::etBoat: m_Stats.AddValue(statDistBoat, Value); break; case cEntity::etMonster: { - cMonster * Monster = reinterpret_cast(m_AttachedTo); + cMonster * Monster = static_cast(m_AttachedTo); switch (Monster->GetMobType()) { case mtPig: m_Stats.AddValue(statDistPig, Value); break; -- cgit v1.2.3