From 41c6c0bee390e12b5a399fbfc2b8b0548e05ee19 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 4 Feb 2021 17:59:06 +0200 Subject: [PATCH] Support casting back to TileElement --- src/openrct2/world/TileElement.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/openrct2/world/TileElement.h b/src/openrct2/world/TileElement.h index 905674ac42..d9d6c7186a 100644 --- a/src/openrct2/world/TileElement.h +++ b/src/openrct2/world/TileElement.h @@ -56,6 +56,7 @@ enum class TileElementType : uint8_t Corrupt = (8 << 2), }; +struct TileElement; struct SurfaceElement; struct PathElement; struct TrackElement; @@ -102,11 +103,19 @@ struct TileElementBase template const TType* as() const { - return static_cast(GetType()) == TType::ElementType ? reinterpret_cast(this) : nullptr; + if constexpr (std::is_same_v) + return reinterpret_cast(this); + else + return static_cast(GetType()) == TType::ElementType ? reinterpret_cast(this) + : nullptr; } + template TType* as() { - return static_cast(GetType()) == TType::ElementType ? reinterpret_cast(this) : nullptr; + if constexpr (std::is_same_v) + return reinterpret_cast(this); + else + return static_cast(GetType()) == TType::ElementType ? reinterpret_cast(this) : nullptr; } const SurfaceElement* AsSurface() const