Fix importing maps containing 255 height elements

This commit is contained in:
Ted John 2021-11-21 18:23:44 +00:00 committed by Gymnasiast
parent 915e6447f9
commit c4b4595708
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
2 changed files with 55 additions and 52 deletions

View File

@ -1542,13 +1542,8 @@ namespace RCT1
{
for (coords.x = 0; coords.x < MAXIMUM_MAP_SIZE_TECHNICAL; coords.x++)
{
if (coords.x >= RCT1_MAX_MAP_SIZE || coords.y >= RCT1_MAX_MAP_SIZE)
{
auto& dstElement = tileElements.emplace_back();
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
dstElement.SetLastForTile(true);
}
else
auto tileAdded = false;
if (coords.x < RCT1_MAX_MAP_SIZE && coords.y < RCT1_MAX_MAP_SIZE)
{
// This is the equivalent of map_get_first_element_at(x, y), but on S4 data.
RCT12TileElement* srcElement = tilePointerIndex.GetFirstElementAt(coords);
@ -1564,12 +1559,20 @@ namespace RCT1
auto numAddedElements = ImportTileElement(dstElement, srcElement);
tileElements.resize(originalSize + numAddedElements);
} while (!(srcElement++)->IsLastForTile());
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
{
tileElements.back().SetLastForTile(true);
}
if (!tileAdded)
{
// Add a default surface element, we always need at least one element per tile
auto& dstElement = tileElements.emplace_back();
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
dstElement.SetLastForTile(true);
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
{
tileElements.back().SetLastForTile(true);
}
}
}

View File

@ -1096,52 +1096,52 @@ public:
nextElementInvisible = false;
restOfTileInvisible = false;
if (coords.x >= RCT2_MAXIMUM_MAP_SIZE_TECHNICAL || coords.y >= RCT2_MAXIMUM_MAP_SIZE_TECHNICAL)
auto tileAdded = false;
if (coords.x < RCT2_MAXIMUM_MAP_SIZE_TECHNICAL && coords.y < RCT2_MAXIMUM_MAP_SIZE_TECHNICAL)
{
const auto* srcElement = tilePointerIndex.GetFirstElementAt(coords);
if (srcElement != nullptr)
{
do
{
if (srcElement->base_height == RCT12_MAX_ELEMENT_HEIGHT)
{
continue;
}
auto tileElementType = static_cast<RCT12TileElementType>(srcElement->GetType());
if (tileElementType == RCT12TileElementType::Corrupt)
{
// One property of corrupt elements was to hide tops of tower tracks, and to avoid the next
// element from being hidden, multiple consecutive corrupt elements were sometimes used. This
// would essentially toggle the flag, so we inverse nextElementInvisible here instead of always
// setting it to true.
nextElementInvisible = !nextElementInvisible;
continue;
}
if (tileElementType == RCT12TileElementType::EightCarsCorrupt14
|| tileElementType == RCT12TileElementType::EightCarsCorrupt15)
{
restOfTileInvisible = true;
continue;
}
auto& dstElement = tileElements.emplace_back();
ImportTileElement(&dstElement, srcElement, nextElementInvisible || restOfTileInvisible);
nextElementInvisible = false;
tileAdded = true;
} while (!(srcElement++)->IsLastForTile());
}
}
if (!tileAdded)
{
// Add a default surface element, we always need at least one element per tile
auto& dstElement = tileElements.emplace_back();
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
dstElement.SetLastForTile(true);
continue;
}
RCT12TileElement* srcElement = tilePointerIndex.GetFirstElementAt(coords);
// This might happen with damaged parks. Make sure there is *something* to avoid crashes.
if (srcElement == nullptr)
{
auto& dstElement = tileElements.emplace_back();
dstElement.ClearAs(TILE_ELEMENT_TYPE_SURFACE);
dstElement.SetLastForTile(true);
continue;
}
do
{
if (srcElement->base_height == RCT12_MAX_ELEMENT_HEIGHT)
{
continue;
}
auto tileElementType = static_cast<RCT12TileElementType>(srcElement->GetType());
if (tileElementType == RCT12TileElementType::Corrupt)
{
// One property of corrupt elements was to hide tops of tower tracks, and to avoid the next element from
// being hidden, multiple consecutive corrupt elements were sometimes used. This would essentially
// toggle the flag, so we inverse nextElementInvisible here instead of always setting it to true.
nextElementInvisible = !nextElementInvisible;
continue;
}
if (tileElementType == RCT12TileElementType::EightCarsCorrupt14
|| tileElementType == RCT12TileElementType::EightCarsCorrupt15)
{
restOfTileInvisible = true;
continue;
}
auto& dstElement = tileElements.emplace_back();
ImportTileElement(&dstElement, srcElement, nextElementInvisible || restOfTileInvisible);
nextElementInvisible = false;
} while (!(srcElement++)->IsLastForTile());
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
{