diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 4718adad9c..2892551ae5 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -481,7 +481,8 @@ void game_fix_save_vars() if (surfaceElement == nullptr) { log_error("Null map element at x = %d and y = %d. Fixing...", x, y); - auto tileElement = tile_element_insert(TileCoordsXYZ{ x, y, 14 }.ToCoordsXYZ(), 0b0000); + auto tileElement = tile_element_insert( + TileCoordsXYZ{ x, y, 14 }.ToCoordsXYZ(), 0b0000, TileElementType::Surface); if (tileElement == nullptr) { log_error("Unable to fix: Map element limit reached."); diff --git a/src/openrct2/actions/BannerPlaceAction.cpp b/src/openrct2/actions/BannerPlaceAction.cpp index ffb68b5bd9..7dd6cc6d1f 100644 --- a/src/openrct2/actions/BannerPlaceAction.cpp +++ b/src/openrct2/actions/BannerPlaceAction.cpp @@ -141,7 +141,7 @@ GameActions::Result::Ptr BannerPlaceAction::Execute() const return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE); } - TileElement* newTileElement = tile_element_insert({ _loc, _loc.z + (2 * COORDS_Z_STEP) }, 0b0000); + TileElement* newTileElement = tile_element_insert({ _loc, _loc.z + (2 * COORDS_Z_STEP) }, 0b0000, TileElementType::Banner); assert(newTileElement != nullptr); banner->flags = 0; @@ -150,7 +150,6 @@ GameActions::Result::Ptr BannerPlaceAction::Execute() const banner->type = _bannerType; // Banner must be deleted after this point in an early return banner->colour = _primaryColour; banner->position = TileCoordsXY(_loc); - newTileElement->SetType(TILE_ELEMENT_TYPE_BANNER); BannerElement* bannerElement = newTileElement->AsBanner(); bannerElement->SetClearanceZ(_loc.z + PATH_CLEARANCE); bannerElement->SetPosition(_loc.direction); diff --git a/src/openrct2/actions/FootpathPlaceAction.cpp b/src/openrct2/actions/FootpathPlaceAction.cpp index 5c9f465b34..465996f491 100644 --- a/src/openrct2/actions/FootpathPlaceAction.cpp +++ b/src/openrct2/actions/FootpathPlaceAction.cpp @@ -340,9 +340,8 @@ GameActions::Result::Ptr FootpathPlaceAction::ElementInsertExecute(GameActions:: } else { - auto tileElement = tile_element_insert(_loc, 0b1111); + auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Path); assert(tileElement != nullptr); - tileElement->SetType(TILE_ELEMENT_TYPE_PATH); PathElement* pathElement = tileElement->AsPath(); pathElement->SetClearanceZ(zHigh); pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); diff --git a/src/openrct2/actions/FootpathPlaceFromTrackAction.cpp b/src/openrct2/actions/FootpathPlaceFromTrackAction.cpp index aee4964bdb..ec1232fbb8 100644 --- a/src/openrct2/actions/FootpathPlaceFromTrackAction.cpp +++ b/src/openrct2/actions/FootpathPlaceFromTrackAction.cpp @@ -230,9 +230,8 @@ GameActions::Result::Ptr FootpathPlaceFromTrackAction::ElementInsertExecute(Game } else { - auto tileElement = tile_element_insert(_loc, 0b1111); + auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Path); assert(tileElement != nullptr); - tileElement->SetType(TILE_ELEMENT_TYPE_PATH); PathElement* pathElement = tileElement->AsPath(); pathElement->SetClearanceZ(zHigh); pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.cpp b/src/openrct2/actions/LargeSceneryPlaceAction.cpp index 8172d3d825..c470bbcb11 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.cpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.cpp @@ -278,10 +278,9 @@ GameActions::Result::Ptr LargeSceneryPlaceAction::Execute() const } TileElement* newTileElement = tile_element_insert( - CoordsXYZ{ curTile.x, curTile.y, zLow }, quarterTile.GetBaseQuarterOccupied()); + CoordsXYZ{ curTile.x, curTile.y, zLow }, quarterTile.GetBaseQuarterOccupied(), TileElementType::LargeScenery); Guard::Assert(newTileElement != nullptr); map_animation_create(MAP_ANIMATION_TYPE_LARGE_SCENERY, { curTile, zLow }); - newTileElement->SetType(TILE_ELEMENT_TYPE_LARGE_SCENERY); newTileElement->SetClearanceZ(zHigh); auto newSceneryElement = newTileElement->AsLargeScenery(); diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index e0411563e6..1c6cc6579d 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -168,11 +168,10 @@ GameActions::Result::Ptr MazePlaceTrackAction::Execute() const auto startLoc = _loc.ToTileStart(); - auto tileElement = tile_element_insert(_loc, 0b1111); + auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Track); assert(tileElement != nullptr); tileElement->SetClearanceZ(clearanceHeight); - tileElement->SetType(TILE_ELEMENT_TYPE_TRACK); tileElement->AsTrack()->SetTrackType(TrackElemType::Maze); tileElement->AsTrack()->SetRideIndex(_rideIndex); diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index 9fe32e09ca..6bcda0fda5 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -1,4 +1,4 @@ -/***************************************************************************** +/***************************************************************************** * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md @@ -181,11 +181,10 @@ GameActions::Result::Ptr MazeSetTrackAction::Execute() const auto startLoc = _loc.ToTileStart(); - tileElement = tile_element_insert(_loc, 0b1111); + tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Track); assert(tileElement != nullptr); tileElement->SetClearanceZ(_loc.z + MAZE_CLEARANCE_HEIGHT); - tileElement->SetType(TILE_ELEMENT_TYPE_TRACK); tileElement->AsTrack()->SetTrackType(TrackElemType::Maze); tileElement->AsTrack()->SetRideIndex(_rideIndex); diff --git a/src/openrct2/actions/PlaceParkEntranceAction.cpp b/src/openrct2/actions/PlaceParkEntranceAction.cpp index 9472879212..2aca2392e4 100644 --- a/src/openrct2/actions/PlaceParkEntranceAction.cpp +++ b/src/openrct2/actions/PlaceParkEntranceAction.cpp @@ -138,9 +138,9 @@ GameActions::Result::Ptr PlaceParkEntranceAction::Execute() const } } - TileElement* newElement = tile_element_insert(CoordsXYZ{ entranceLoc, zLow }, 0b1111); + TileElement* newElement = tile_element_insert(CoordsXYZ{ entranceLoc, zLow }, 0b1111, TileElementType::Entrance); Guard::Assert(newElement != nullptr); - newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); + auto entranceElement = newElement->AsEntrance(); if (entranceElement == nullptr) { diff --git a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp index 8a85b86b05..88fc495299 100644 --- a/src/openrct2/actions/RideEntranceExitPlaceAction.cpp +++ b/src/openrct2/actions/RideEntranceExitPlaceAction.cpp @@ -176,9 +176,9 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::Execute() const res->Position = { _loc.ToTileCentre(), z }; res->Expenditure = ExpenditureType::RideConstruction; - TileElement* tileElement = tile_element_insert(CoordsXYZ{ _loc, z }, 0b1111); + TileElement* tileElement = tile_element_insert(CoordsXYZ{ _loc, z }, 0b1111, TileElementType::Entrance); assert(tileElement != nullptr); - tileElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE); + tileElement->SetDirection(_direction); tileElement->SetClearanceZ(clear_z); tileElement->AsEntrance()->SetEntranceType(_isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE); diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.cpp b/src/openrct2/actions/SmallSceneryPlaceAction.cpp index 9668cf5e88..c41f211c8b 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.cpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.cpp @@ -430,10 +430,11 @@ GameActions::Result::Ptr SmallSceneryPlaceAction::Execute() const res->Expenditure = ExpenditureType::Landscaping; res->Cost = (sceneryEntry->small_scenery.price * 10) + clearCost; - TileElement* newElement = tile_element_insert(CoordsXYZ{ _loc, zLow }, quarterTile.GetBaseQuarterOccupied()); + TileElement* newElement = tile_element_insert( + CoordsXYZ{ _loc, zLow }, quarterTile.GetBaseQuarterOccupied(), TileElementType::SmallScenery); assert(newElement != nullptr); res->tileElement = newElement; - newElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY); + newElement->SetDirection(_loc.direction); SmallSceneryElement* sceneryElement = newElement->AsSmallScenery(); sceneryElement->SetSceneryQuadrant(quadrant); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 0bbc903265..3b490073d9 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -592,10 +592,9 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const ride->overall_view = mapLoc; } - auto tileElement = tile_element_insert(mapLoc, quarterTile.GetBaseQuarterOccupied()); + auto tileElement = tile_element_insert(mapLoc, quarterTile.GetBaseQuarterOccupied(), TileElementType::Track); assert(tileElement != nullptr); tileElement->SetClearanceZ(clearanceZ); - tileElement->SetType(TILE_ELEMENT_TYPE_TRACK); tileElement->SetDirection(_origin.direction); if (_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED) { diff --git a/src/openrct2/actions/WallPlaceAction.cpp b/src/openrct2/actions/WallPlaceAction.cpp index 0d87c4c4f6..1baee9df41 100644 --- a/src/openrct2/actions/WallPlaceAction.cpp +++ b/src/openrct2/actions/WallPlaceAction.cpp @@ -397,7 +397,7 @@ GameActions::Result::Ptr WallPlaceAction::Execute() const } } - TileElement* tileElement = tile_element_insert(targetLoc, 0b0000); + TileElement* tileElement = tile_element_insert(targetLoc, 0b0000, TileElementType::Wall); assert(tileElement != nullptr); map_animation_create(MAP_ANIMATION_TYPE_WALL, targetLoc); diff --git a/src/openrct2/scripting/ScTile.hpp b/src/openrct2/scripting/ScTile.hpp index 7840664191..c811799595 100644 --- a/src/openrct2/scripting/ScTile.hpp +++ b/src/openrct2/scripting/ScTile.hpp @@ -835,13 +835,13 @@ namespace OpenRCT2::Scripting // Insert corrupt element at the end of the list for this tile // Note: Z = MAX_ELEMENT_HEIGHT to guarantee this - TileElement* insertedElement = tile_element_insert({ _coords, MAX_ELEMENT_HEIGHT }, 0); + TileElement* insertedElement = tile_element_insert( + { _coords, MAX_ELEMENT_HEIGHT }, 0, TileElementType::Corrupt); if (insertedElement == nullptr) { // TODO: Show error return; } - insertedElement->SetType(TILE_ELEMENT_TYPE_CORRUPT); // Since inserting a new element may move the tile elements in memory, we have to update the local pointer _element = map_get_first_element_at(_coords) + elementIndex; @@ -1661,7 +1661,7 @@ namespace OpenRCT2::Scripting auto numToInsert = numElements - currentNumElements; for (size_t i = 0; i < numToInsert; i++) { - tile_element_insert(pos, 0); + tile_element_insert(pos, 0, TileElementType::Corrupt); } // Copy data to element span @@ -1706,7 +1706,7 @@ namespace OpenRCT2::Scripting std::vector data(first, first + origNumElements); auto pos = TileCoordsXYZ(TileCoordsXY(_coords), 0).ToCoordsXYZ(); - auto newElement = tile_element_insert(pos, 0); + auto newElement = tile_element_insert(pos, 0, TileElementType::Corrupt); if (newElement == nullptr) { auto ctx = GetDukContext(); diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 8c6e99f95a..775dea76e1 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -1,4 +1,4 @@ -/***************************************************************************** +/***************************************************************************** * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md @@ -1108,7 +1108,7 @@ bool map_check_free_elements_and_reorganise(int32_t numElements) * * rct2: 0x0068B1F6 */ -TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants) +TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type) { const auto& tileLoc = TileCoordsXYZ(loc); TileElement *originalTileElement, *newTileElement, *insertedElement; @@ -1153,7 +1153,7 @@ TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants // Insert new map element insertedElement = newTileElement; - newTileElement->type = 0; + newTileElement->SetType(static_cast(type)); newTileElement->SetBaseZ(loc.z); newTileElement->Flags = 0; newTileElement->SetLastForTile(isLastForTile); diff --git a/src/openrct2/world/Map.h b/src/openrct2/world/Map.h index 038fceb1c8..0904114776 100644 --- a/src/openrct2/world/Map.h +++ b/src/openrct2/world/Map.h @@ -1,4 +1,4 @@ -/***************************************************************************** +/***************************************************************************** * Copyright (c) 2014-2020 OpenRCT2 developers * * For a complete list of all authors, please refer to contributors.md @@ -213,7 +213,7 @@ void map_invalidate_map_selection_tiles(); void map_invalidate_selection_rect(); void map_reorganise_elements(); bool map_check_free_elements_and_reorganise(int32_t num_elements); -TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants); +TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants, TileElementType type); namespace GameActions { diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index 24439c282c..8d0b1b60e2 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -240,10 +240,9 @@ static void mapgen_place_tree(int32_t type, const CoordsXY& loc) } int32_t surfaceZ = tile_element_height(loc.ToTileCentre()); - TileElement* tileElement = tile_element_insert({ loc, surfaceZ }, 0b1111); + TileElement* tileElement = tile_element_insert({ loc, surfaceZ }, 0b1111, TileElementType::SmallScenery); assert(tileElement != nullptr); tileElement->SetClearanceZ(surfaceZ + sceneryEntry->small_scenery.height); - tileElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY); tileElement->SetDirection(util_rand() & 3); SmallSceneryElement* sceneryElement = tileElement->AsSmallScenery(); sceneryElement->SetEntryIndex(type); diff --git a/src/openrct2/world/TileInspector.cpp b/src/openrct2/world/TileInspector.cpp index 21c00286ec..6f52d57dc6 100644 --- a/src/openrct2/world/TileInspector.cpp +++ b/src/openrct2/world/TileInspector.cpp @@ -88,13 +88,13 @@ GameActionResultPtr tile_inspector_insert_corrupt_at(const CoordsXY& loc, int16_ { // Create new corrupt element TileElement* corruptElement = tile_element_insert( - { loc, (-1 * COORDS_Z_STEP) }, 0b0000); // Ugly hack: -1 guarantees this to be placed first + { loc, (-1 * COORDS_Z_STEP) }, 0b0000, + TileElementType::Corrupt); // Ugly hack: -1 guarantees this to be placed first if (corruptElement == nullptr) { log_warning("Failed to insert corrupt element."); return std::make_unique(GameActions::Status::Unknown, STR_NONE); } - corruptElement->SetType(TILE_ELEMENT_TYPE_CORRUPT); // Set the base height to be the same as the selected element TileElement* const selectedElement = map_get_nth_element_at(loc, elementIndex + 1); @@ -382,7 +382,7 @@ GameActionResultPtr tile_inspector_paste_element_at(const CoordsXY& loc, TileEle // The occupiedQuadrants will be automatically set when the element is copied over, so it's not necessary to set them // correctly _here_. - TileElement* const pastedElement = tile_element_insert({ loc, element.GetBaseZ() }, 0b0000); + TileElement* const pastedElement = tile_element_insert({ loc, element.GetBaseZ() }, 0b0000, TileElementType::Corrupt); bool lastForTile = pastedElement->IsLastForTile(); *pastedElement = element;