Skip to content

Commit

Permalink
Fix #21496: RCT1 scenery hidden after reloading (#22181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gymnasiast committed Jun 21, 2024
1 parent 1db7f66 commit f9a06ae
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Fix: [#13234] Vehicle weight sometimes wrong after using Remove All Guests cheat.
- Fix: [#13294] Map corners are cut off in some directions (original bug).
- Fix: [#14630] Non-ASCII thousands and decimal separators not processed correctly.
- Fix: [#21496] Some RCT1 scenery is hidden after saving and reloading.
- Fix: [#21974] No reason specified when attempting to place benches, lamps, or bins on path with no unconnected edges (original bug).
- Fix: [#21987] [Plugin] API cannot handle negative removal prices.
- Fix: [#22008] Uninverted Lay-down roller coaster uses the wrong support type.
Expand Down
69 changes: 47 additions & 22 deletions src/openrct2/world/Scenery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,26 @@ bool ObjectTypeCanBeRestricted(ObjectType objectType)
}
}

static std::vector<ScenerySelection> GetAllMiscScenery()
struct MiscScenery
{
std::vector<ScenerySelection> miscScenery;
std::vector<ScenerySelection> nonMiscScenery;
// Scenery that will end up on the ‘?’ tab
std::vector<ScenerySelection> miscScenery{};
// Scenery that has attached itself to an existing group, but is not referenced directly.
std::vector<ScenerySelection> additionalGroupScenery{};
};

static MiscScenery GetAllMiscScenery()
{
MiscScenery ret;
std::vector<ScenerySelection> referencedBySceneryGroups;
std::vector<ObjectEntryIndex> sceneryGroupIds;
for (ObjectEntryIndex i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
{
const auto* sgEntry = OpenRCT2::ObjectManager::GetObjectEntry<SceneryGroupEntry>(i);
if (sgEntry != nullptr)
{
nonMiscScenery.insert(nonMiscScenery.end(), sgEntry->SceneryEntries.begin(), sgEntry->SceneryEntries.end());
referencedBySceneryGroups.insert(
referencedBySceneryGroups.end(), sgEntry->SceneryEntries.begin(), sgEntry->SceneryEntries.end());
sceneryGroupIds.emplace_back(i);
}
}
Expand Down Expand Up @@ -487,50 +496,66 @@ static std::vector<ScenerySelection> GetAllMiscScenery()
break;
}

// An object may be link itself against a scenery group, in which case it should not be marked as miscellaneous.
const ScenerySelection sceneryItem = { sceneryType, i };
if (!IsSceneryEntryValid(sceneryItem))
continue;

const bool isReferencedBySceneryGroup = std::find(
std::begin(referencedBySceneryGroups),
std::end(referencedBySceneryGroups), sceneryItem)
!= std::end(referencedBySceneryGroups);
if (isReferencedBySceneryGroup)
continue;

// An object may link itself against a scenery group, in which case it should not be marked as miscellaneous.
bool isLinkedToKnownSceneryGroup = false;
if (linkedSceneryGroup != OBJECT_ENTRY_INDEX_NULL)
{
if (std::find(std::begin(sceneryGroupIds), std::end(sceneryGroupIds), linkedSceneryGroup)
!= std::end(sceneryGroupIds))
{
continue;
isLinkedToKnownSceneryGroup = true;
}
}

const ScenerySelection sceneryItem = { sceneryType, i };
if (IsSceneryEntryValid(sceneryItem))
{
if (std::find(std::begin(nonMiscScenery), std::end(nonMiscScenery), sceneryItem) == std::end(nonMiscScenery))
{
miscScenery.push_back(sceneryItem);
}
}
if (isLinkedToKnownSceneryGroup)
ret.additionalGroupScenery.push_back(sceneryItem);
else
ret.miscScenery.push_back(sceneryItem);
}
}
return miscScenery;
return ret;
}

void RestrictAllMiscScenery()
{
auto& gameState = GetGameState();
auto miscScenery = GetAllMiscScenery();
auto miscScenery = GetAllMiscScenery().miscScenery;
gameState.RestrictedScenery.insert(gameState.RestrictedScenery.begin(), miscScenery.begin(), miscScenery.end());
}

void MarkAllUnrestrictedSceneryAsInvented()
static void MarkAllUnrestrictedSceneryInVectorInvented(const std::vector<ScenerySelection>& vector)
{
auto& gameState = GetGameState();
auto miscScenery = GetAllMiscScenery();
for (const auto& sceneryItem : miscScenery)
auto& restrictedScenery = GetGameState().RestrictedScenery;

for (const auto& sceneryItem : vector)
{
if (std::find(gameState.RestrictedScenery.begin(), gameState.RestrictedScenery.end(), sceneryItem)
== gameState.RestrictedScenery.end())
const bool isNotRestricted = std::find(restrictedScenery.begin(), restrictedScenery.end(), sceneryItem)
== restrictedScenery.end();
if (isNotRestricted)
{
ScenerySetInvented(sceneryItem);
}
}
}

void MarkAllUnrestrictedSceneryAsInvented()
{
auto scenery = GetAllMiscScenery();
MarkAllUnrestrictedSceneryInVectorInvented(scenery.miscScenery);
MarkAllUnrestrictedSceneryInVectorInvented(scenery.additionalGroupScenery);
}

ObjectType GetObjectTypeFromSceneryType(uint8_t type)
{
switch (type)
Expand Down

0 comments on commit f9a06ae

Please sign in to comment.