Make the insertion of tile elements type explicit

This commit is contained in:
Matt 2021-02-04 17:46:21 +02:00
parent 6186766a05
commit 71174b8de7
No known key found for this signature in database
GPG Key ID: 6D4C24A61C93E208
17 changed files with 31 additions and 37 deletions

View File

@ -481,7 +481,8 @@ void game_fix_save_vars()
if (surfaceElement == nullptr) if (surfaceElement == nullptr)
{ {
log_error("Null map element at x = %d and y = %d. Fixing...", x, y); 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) if (tileElement == nullptr)
{ {
log_error("Unable to fix: Map element limit reached."); log_error("Unable to fix: Map element limit reached.");

View File

@ -141,7 +141,7 @@ GameActions::Result::Ptr BannerPlaceAction::Execute() const
return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE); 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); assert(newTileElement != nullptr);
banner->flags = 0; 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->type = _bannerType; // Banner must be deleted after this point in an early return
banner->colour = _primaryColour; banner->colour = _primaryColour;
banner->position = TileCoordsXY(_loc); banner->position = TileCoordsXY(_loc);
newTileElement->SetType(TILE_ELEMENT_TYPE_BANNER);
BannerElement* bannerElement = newTileElement->AsBanner(); BannerElement* bannerElement = newTileElement->AsBanner();
bannerElement->SetClearanceZ(_loc.z + PATH_CLEARANCE); bannerElement->SetClearanceZ(_loc.z + PATH_CLEARANCE);
bannerElement->SetPosition(_loc.direction); bannerElement->SetPosition(_loc.direction);

View File

@ -340,9 +340,8 @@ GameActions::Result::Ptr FootpathPlaceAction::ElementInsertExecute(GameActions::
} }
else else
{ {
auto tileElement = tile_element_insert(_loc, 0b1111); auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Path);
assert(tileElement != nullptr); assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_PATH);
PathElement* pathElement = tileElement->AsPath(); PathElement* pathElement = tileElement->AsPath();
pathElement->SetClearanceZ(zHigh); pathElement->SetClearanceZ(zHigh);
pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE);

View File

@ -230,9 +230,8 @@ GameActions::Result::Ptr FootpathPlaceFromTrackAction::ElementInsertExecute(Game
} }
else else
{ {
auto tileElement = tile_element_insert(_loc, 0b1111); auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Path);
assert(tileElement != nullptr); assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_PATH);
PathElement* pathElement = tileElement->AsPath(); PathElement* pathElement = tileElement->AsPath();
pathElement->SetClearanceZ(zHigh); pathElement->SetClearanceZ(zHigh);
pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE); pathElement->SetSurfaceEntryIndex(_type & ~FOOTPATH_ELEMENT_INSERT_QUEUE);

View File

@ -278,10 +278,9 @@ GameActions::Result::Ptr LargeSceneryPlaceAction::Execute() const
} }
TileElement* newTileElement = tile_element_insert( 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); Guard::Assert(newTileElement != nullptr);
map_animation_create(MAP_ANIMATION_TYPE_LARGE_SCENERY, { curTile, zLow }); map_animation_create(MAP_ANIMATION_TYPE_LARGE_SCENERY, { curTile, zLow });
newTileElement->SetType(TILE_ELEMENT_TYPE_LARGE_SCENERY);
newTileElement->SetClearanceZ(zHigh); newTileElement->SetClearanceZ(zHigh);
auto newSceneryElement = newTileElement->AsLargeScenery(); auto newSceneryElement = newTileElement->AsLargeScenery();

View File

@ -168,11 +168,10 @@ GameActions::Result::Ptr MazePlaceTrackAction::Execute() const
auto startLoc = _loc.ToTileStart(); auto startLoc = _loc.ToTileStart();
auto tileElement = tile_element_insert(_loc, 0b1111); auto tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Track);
assert(tileElement != nullptr); assert(tileElement != nullptr);
tileElement->SetClearanceZ(clearanceHeight); tileElement->SetClearanceZ(clearanceHeight);
tileElement->SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement->AsTrack()->SetTrackType(TrackElemType::Maze); tileElement->AsTrack()->SetTrackType(TrackElemType::Maze);
tileElement->AsTrack()->SetRideIndex(_rideIndex); tileElement->AsTrack()->SetRideIndex(_rideIndex);

View File

@ -1,4 +1,4 @@
/***************************************************************************** /*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers * Copyright (c) 2014-2020 OpenRCT2 developers
* *
* For a complete list of all authors, please refer to contributors.md * 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(); auto startLoc = _loc.ToTileStart();
tileElement = tile_element_insert(_loc, 0b1111); tileElement = tile_element_insert(_loc, 0b1111, TileElementType::Track);
assert(tileElement != nullptr); assert(tileElement != nullptr);
tileElement->SetClearanceZ(_loc.z + MAZE_CLEARANCE_HEIGHT); tileElement->SetClearanceZ(_loc.z + MAZE_CLEARANCE_HEIGHT);
tileElement->SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement->AsTrack()->SetTrackType(TrackElemType::Maze); tileElement->AsTrack()->SetTrackType(TrackElemType::Maze);
tileElement->AsTrack()->SetRideIndex(_rideIndex); tileElement->AsTrack()->SetRideIndex(_rideIndex);

View File

@ -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); Guard::Assert(newElement != nullptr);
newElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE);
auto entranceElement = newElement->AsEntrance(); auto entranceElement = newElement->AsEntrance();
if (entranceElement == nullptr) if (entranceElement == nullptr)
{ {

View File

@ -176,9 +176,9 @@ GameActions::Result::Ptr RideEntranceExitPlaceAction::Execute() const
res->Position = { _loc.ToTileCentre(), z }; res->Position = { _loc.ToTileCentre(), z };
res->Expenditure = ExpenditureType::RideConstruction; 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); assert(tileElement != nullptr);
tileElement->SetType(TILE_ELEMENT_TYPE_ENTRANCE);
tileElement->SetDirection(_direction); tileElement->SetDirection(_direction);
tileElement->SetClearanceZ(clear_z); tileElement->SetClearanceZ(clear_z);
tileElement->AsEntrance()->SetEntranceType(_isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE); tileElement->AsEntrance()->SetEntranceType(_isExit ? ENTRANCE_TYPE_RIDE_EXIT : ENTRANCE_TYPE_RIDE_ENTRANCE);

View File

@ -430,10 +430,11 @@ GameActions::Result::Ptr SmallSceneryPlaceAction::Execute() const
res->Expenditure = ExpenditureType::Landscaping; res->Expenditure = ExpenditureType::Landscaping;
res->Cost = (sceneryEntry->small_scenery.price * 10) + clearCost; 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); assert(newElement != nullptr);
res->tileElement = newElement; res->tileElement = newElement;
newElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY);
newElement->SetDirection(_loc.direction); newElement->SetDirection(_loc.direction);
SmallSceneryElement* sceneryElement = newElement->AsSmallScenery(); SmallSceneryElement* sceneryElement = newElement->AsSmallScenery();
sceneryElement->SetSceneryQuadrant(quadrant); sceneryElement->SetSceneryQuadrant(quadrant);

View File

@ -592,10 +592,9 @@ GameActions::Result::Ptr TrackPlaceAction::Execute() const
ride->overall_view = mapLoc; 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); assert(tileElement != nullptr);
tileElement->SetClearanceZ(clearanceZ); tileElement->SetClearanceZ(clearanceZ);
tileElement->SetType(TILE_ELEMENT_TYPE_TRACK);
tileElement->SetDirection(_origin.direction); tileElement->SetDirection(_origin.direction);
if (_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED) if (_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED)
{ {

View File

@ -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); assert(tileElement != nullptr);
map_animation_create(MAP_ANIMATION_TYPE_WALL, targetLoc); map_animation_create(MAP_ANIMATION_TYPE_WALL, targetLoc);

View File

@ -835,13 +835,13 @@ namespace OpenRCT2::Scripting
// Insert corrupt element at the end of the list for this tile // Insert corrupt element at the end of the list for this tile
// Note: Z = MAX_ELEMENT_HEIGHT to guarantee this // 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) if (insertedElement == nullptr)
{ {
// TODO: Show error // TODO: Show error
return; 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 // 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; _element = map_get_first_element_at(_coords) + elementIndex;
@ -1661,7 +1661,7 @@ namespace OpenRCT2::Scripting
auto numToInsert = numElements - currentNumElements; auto numToInsert = numElements - currentNumElements;
for (size_t i = 0; i < numToInsert; i++) 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 // Copy data to element span
@ -1706,7 +1706,7 @@ namespace OpenRCT2::Scripting
std::vector<TileElement> data(first, first + origNumElements); std::vector<TileElement> data(first, first + origNumElements);
auto pos = TileCoordsXYZ(TileCoordsXY(_coords), 0).ToCoordsXYZ(); 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) if (newElement == nullptr)
{ {
auto ctx = GetDukContext(); auto ctx = GetDukContext();

View File

@ -1,4 +1,4 @@
/***************************************************************************** /*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers * Copyright (c) 2014-2020 OpenRCT2 developers
* *
* For a complete list of all authors, please refer to contributors.md * 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 * 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); const auto& tileLoc = TileCoordsXYZ(loc);
TileElement *originalTileElement, *newTileElement, *insertedElement; TileElement *originalTileElement, *newTileElement, *insertedElement;
@ -1153,7 +1153,7 @@ TileElement* tile_element_insert(const CoordsXYZ& loc, int32_t occupiedQuadrants
// Insert new map element // Insert new map element
insertedElement = newTileElement; insertedElement = newTileElement;
newTileElement->type = 0; newTileElement->SetType(static_cast<uint8_t>(type));
newTileElement->SetBaseZ(loc.z); newTileElement->SetBaseZ(loc.z);
newTileElement->Flags = 0; newTileElement->Flags = 0;
newTileElement->SetLastForTile(isLastForTile); newTileElement->SetLastForTile(isLastForTile);

View File

@ -1,4 +1,4 @@
/***************************************************************************** /*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers * Copyright (c) 2014-2020 OpenRCT2 developers
* *
* For a complete list of all authors, please refer to contributors.md * 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_invalidate_selection_rect();
void map_reorganise_elements(); void map_reorganise_elements();
bool map_check_free_elements_and_reorganise(int32_t num_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 namespace GameActions
{ {

View File

@ -240,10 +240,9 @@ static void mapgen_place_tree(int32_t type, const CoordsXY& loc)
} }
int32_t surfaceZ = tile_element_height(loc.ToTileCentre()); 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); assert(tileElement != nullptr);
tileElement->SetClearanceZ(surfaceZ + sceneryEntry->small_scenery.height); tileElement->SetClearanceZ(surfaceZ + sceneryEntry->small_scenery.height);
tileElement->SetType(TILE_ELEMENT_TYPE_SMALL_SCENERY);
tileElement->SetDirection(util_rand() & 3); tileElement->SetDirection(util_rand() & 3);
SmallSceneryElement* sceneryElement = tileElement->AsSmallScenery(); SmallSceneryElement* sceneryElement = tileElement->AsSmallScenery();
sceneryElement->SetEntryIndex(type); sceneryElement->SetEntryIndex(type);

View File

@ -88,13 +88,13 @@ GameActionResultPtr tile_inspector_insert_corrupt_at(const CoordsXY& loc, int16_
{ {
// Create new corrupt element // Create new corrupt element
TileElement* corruptElement = tile_element_insert( 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) if (corruptElement == nullptr)
{ {
log_warning("Failed to insert corrupt element."); log_warning("Failed to insert corrupt element.");
return std::make_unique<GameActions::Result>(GameActions::Status::Unknown, STR_NONE); return std::make_unique<GameActions::Result>(GameActions::Status::Unknown, STR_NONE);
} }
corruptElement->SetType(TILE_ELEMENT_TYPE_CORRUPT);
// Set the base height to be the same as the selected element // Set the base height to be the same as the selected element
TileElement* const selectedElement = map_get_nth_element_at(loc, elementIndex + 1); 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 // The occupiedQuadrants will be automatically set when the element is copied over, so it's not necessary to set them
// correctly _here_. // 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(); bool lastForTile = pastedElement->IsLastForTile();
*pastedElement = element; *pastedElement = element;