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,6 +1559,15 @@ namespace RCT1
auto numAddedElements = ImportTileElement(dstElement, srcElement);
tileElements.resize(originalSize + numAddedElements);
} 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);
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)
@ -1572,7 +1576,6 @@ namespace RCT1
}
}
}
}
SetTileElements(std::move(tileElements));
FixEntrancePositions();

View File

@ -1096,24 +1096,12 @@ 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)
{
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)
const auto* srcElement = tilePointerIndex.GetFirstElementAt(coords);
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)
@ -1124,9 +1112,10 @@ public:
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.
// 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;
}
@ -1140,7 +1129,18 @@ public:
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);
}
// Set last element flag in case the original last element was never added
if (tileElements.size() > 0)