From fa67883cafb7d2dda98fafaa19d57d1b0957a268 Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Thu, 27 Sep 2018 22:51:56 +0200 Subject: [PATCH] Fix crash and address most line notes --- src/openrct2/actions/PlaceParkEntranceAction.hpp | 13 +++++++------ src/openrct2/world/Banner.cpp | 14 +++++++------- src/openrct2/world/Map.cpp | 4 ++-- src/openrct2/world/Map.h | 2 +- src/openrct2/world/TileInspector.cpp | 8 ++++---- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/openrct2/actions/PlaceParkEntranceAction.hpp b/src/openrct2/actions/PlaceParkEntranceAction.hpp index 7b1cfb10f3..b1bb6351d2 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.hpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.hpp @@ -183,18 +183,19 @@ public: rct_tile_element* newElement = tile_element_insert(entranceLoc.x / 32, entranceLoc.y / 32, zLow, 0xF); Guard::Assert(newElement != nullptr); - newElement->clearance_height = zHigh; + newElement->ClearAs(TILE_ELEMENT_TYPE_ENTRANCE); + auto entranceElement = newElement->AsEntrance(); + entranceElement->clearance_height = zHigh; if (flags & GAME_COMMAND_FLAG_GHOST) { newElement->flags |= TILE_ELEMENT_FLAG_GHOST; } - newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); - newElement->SetDirection(_direction); - newElement->AsEntrance()->SetSequenceIndex(index); - newElement->AsEntrance()->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); - newElement->AsEntrance()->SetPathType(gFootpathSelectedId); + entranceElement->SetDirection(_direction); + entranceElement->SetSequenceIndex(index); + entranceElement->SetEntranceType(ENTRANCE_TYPE_PARK_ENTRANCE); + entranceElement->SetPathType(gFootpathSelectedId); if (!(flags & GAME_COMMAND_FLAG_GHOST)) { diff --git a/src/openrct2/world/Banner.cpp b/src/openrct2/world/Banner.cpp index c088cd647e..71d88e49c8 100644 --- a/src/openrct2/world/Banner.cpp +++ b/src/openrct2/world/Banner.cpp @@ -80,13 +80,13 @@ static money32 BannerRemove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t di // Slight modification to the code so that it now checks height as well // This was causing a bug with banners on two paths stacked. - rct_tile_element* tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); + BannerElement* tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); if (tileElement == nullptr) { return MONEY32_UNDEFINED; } - rct_banner* banner = &gBanners[tileElement->AsBanner()->GetIndex()]; + rct_banner* banner = &gBanners[tileElement->GetIndex()]; rct_scenery_entry* bannerEntry = get_banner_entry(banner->type); money32 refund = 0; if (bannerEntry != nullptr) @@ -105,9 +105,9 @@ static money32 BannerRemove(int16_t x, int16_t y, uint8_t baseHeight, uint8_t di network_set_player_last_action_coord(network_get_player_index(game_command_playerid), coord); } - tile_element_remove_banner_entry(tileElement); + tile_element_remove_banner_entry((rct_tile_element*)tileElement); map_invalidate_tile_zoom1(x, y, z, z + 32); - tile_element_remove(tileElement); + tileElement->Remove(); } if (gParkFlags & PARK_FLAGS_NO_MONEY) @@ -217,8 +217,8 @@ static money32 BannerPlace( } uint8_t baseHeight = (pathBaseHeight + 1) * 2; - tileElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); - if (tileElement != nullptr) + BannerElement* bannerElement = map_get_banner_element_at(x / 32, y / 32, baseHeight, direction); + if (bannerElement != nullptr) { gGameCommandErrorText = STR_BANNER_SIGN_IN_THE_WAY; return MONEY32_UNDEFINED; @@ -247,7 +247,7 @@ static money32 BannerPlace( gBanners[*bannerIndex].colour = colour; gBanners[*bannerIndex].x = x / 32; gBanners[*bannerIndex].y = y / 32; - newTileElement->ClearAs(TILE_ELEMENT_TYPE_BANNER); + newTileElement->SetType(TILE_ELEMENT_TYPE_BANNER); newTileElement->clearance_height = newTileElement->base_height + 2; newTileElement->AsBanner()->SetPosition(direction); newTileElement->AsBanner()->ResetAllowedEdges(); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index bb8ac2797c..68d2e564ce 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -307,7 +307,7 @@ rct_tile_element* map_get_path_element_at(int32_t x, int32_t y, int32_t z) return nullptr; } -rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t position) +BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t position) { rct_tile_element* tileElement = map_get_first_element_at(x, y); @@ -324,7 +324,7 @@ rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uin if (tileElement->AsBanner()->GetPosition() != position) continue; - return tileElement; + return tileElement->AsBanner(); } while (!(tileElement++)->IsLastForTile()); return nullptr; diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index d882cdca26..cb55ae47e8 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -135,7 +135,7 @@ rct_tile_element* map_get_first_element_at(int32_t x, int32_t y); rct_tile_element* map_get_nth_element_at(int32_t x, int32_t y, int32_t n); void map_set_tile_elements(int32_t x, int32_t y, rct_tile_element* elements); int32_t map_height_from_slope(int32_t x, int32_t y, int32_t slope); -rct_tile_element* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); +BannerElement* map_get_banner_element_at(int32_t x, int32_t y, int32_t z, uint8_t direction); rct_tile_element* map_get_surface_element_at(int32_t x, int32_t y); rct_tile_element* map_get_surface_element_at(CoordsXY coords); rct_tile_element* map_get_path_element_at(int32_t x, int32_t y, int32_t z); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 099d59efee..891d3c2142 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -1029,16 +1029,16 @@ int32_t tile_inspector_scenery_set_quarter_collision( int32_t tile_inspector_banner_toggle_blocking_edge(int32_t x, int32_t y, int32_t elementIndex, int32_t edgeIndex, int32_t flags) { - BannerElement* const bannerElement = map_get_nth_element_at(x, y, elementIndex)->AsBanner(); + rct_tile_element* const bannerElement = map_get_nth_element_at(x, y, elementIndex); - if (bannerElement == nullptr) + if (bannerElement == nullptr || bannerElement->GetType() != TILE_ELEMENT_TYPE_BANNER) return MONEY32_UNDEFINED; if (flags & GAME_COMMAND_FLAG_APPLY) { - uint8_t edges = bannerElement->GetAllowedEdges(); + uint8_t edges = bannerElement->AsBanner()->GetAllowedEdges(); edges ^= (1 << edgeIndex); - bannerElement->SetAllowedEdges(edges); + bannerElement->AsBanner()->SetAllowedEdges(edges); if ((uint32_t)x == windowTileInspectorTileX && (uint32_t)y == windowTileInspectorTileY) {