mirror of https://github.com/OpenRCT2/OpenRCT2.git
Make the insertion of tile elements type explicit
This commit is contained in:
parent
6186766a05
commit
71174b8de7
|
@ -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.");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<TileElement> 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();
|
||||
|
|
|
@ -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<uint8_t>(type));
|
||||
newTileElement->SetBaseZ(loc.z);
|
||||
newTileElement->Flags = 0;
|
||||
newTileElement->SetLastForTile(isLastForTile);
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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::Result>(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;
|
||||
|
|
Loading…
Reference in New Issue