From e5ec74feaf103a9bbd52b7ddcf273a22f1667554 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Mon, 21 Sep 2020 22:42:25 +0200 Subject: [PATCH] Fix #12918: Cannot place "Blue Hurricane" (hypercoaster) (#12982) The track design was recognised as a Corkscrew RC, not as a Hypercoaster. Moved the conversion code from the track design repository to the TD6Importer (where it should have been, really). This also fixes the issue that Hypercoasters, Monster Trucks, Classic Mini Roller Coasters, Spinning Wild Mouses and Hyper-Twisters placed from a track design have the wrong ride type. --- distribution/changelog.txt | 1 + src/openrct2/rct2/T6Importer.cpp | 28 +++++++++++++++++++++ src/openrct2/ride/TrackDesignRepository.cpp | 23 +---------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index a5be4c1324..c9ec8063e2 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -24,6 +24,7 @@ - Fix: [#12881] Guests' favourite rides are not listed in the guest window. - Fix: [#12910] Plugin API: getRide sometimes returns null for valid ride IDs. - Fix: [#12912] Plugin: selectedCell of CustomListView is being ignored on creation. +- Fix: [#12918] Cannot place vanilla TD6 tracks of the Hypercoaster, Monster Trucks, Classic Mini Roller Coaster, Spinning Wild Mouse and Hyper-Twister types. - Fix: Incomplete loop collision box allowed overlapping track (original bug). - Improved: [#12806] Add Esperanto diacritics to the sprite font. - Improved: [#12837] Arabic text is now drawn and shaped correctly on Windows. diff --git a/src/openrct2/rct2/T6Importer.cpp b/src/openrct2/rct2/T6Importer.cpp index 324d6a28b8..5d6ac357f4 100644 --- a/src/openrct2/rct2/T6Importer.cpp +++ b/src/openrct2/rct2/T6Importer.cpp @@ -13,6 +13,8 @@ #include "../core/MemoryStream.h" #include "../core/Path.hpp" #include "../core/String.hpp" +#include "../object/ObjectRepository.h" +#include "../object/RideObject.h" #include "../rct12/SawyerChunkReader.h" #include "../rct12/SawyerEncoding.h" #include "../ride/Ride.h" @@ -20,6 +22,10 @@ #include "../ride/TrackDesign.h" #include "../ride/TrackDesignRepository.h" +#include + +static std::mutex _objectLookupMutex; + /** * Class to import RollerCoaster Tycoon 2 track designs (*.TD6). */ @@ -200,8 +206,30 @@ public: } td->name = _name; + + UpdateRideType(td); + return td; } + + void UpdateRideType(std::unique_ptr& td) + { + if (RCT2RideTypeNeedsConversion(td->type)) + { + std::scoped_lock lock(_objectLookupMutex); + auto* rawObject = object_repository_load_object(&td->vehicle_object); + if (rawObject != nullptr) + { + const auto* rideEntry = static_cast( + static_cast(rawObject)->GetLegacyData()); + if (rideEntry != nullptr) + { + td->type = RCT2RideTypeToOpenRCT2RideType(td->type, rideEntry); + } + object_delete(rawObject); + } + } + } }; std::unique_ptr TrackImporter::CreateTD6() diff --git a/src/openrct2/ride/TrackDesignRepository.cpp b/src/openrct2/ride/TrackDesignRepository.cpp index a3468adfe9..b1ddc12148 100644 --- a/src/openrct2/ride/TrackDesignRepository.cpp +++ b/src/openrct2/ride/TrackDesignRepository.cpp @@ -21,14 +21,12 @@ #include "../core/String.hpp" #include "../localisation/LocalisationService.h" #include "../object/ObjectRepository.h" -#include "../object/RideObject.h" #include "../ride/RideData.h" #include "../util/Util.h" #include "TrackDesign.h" #include #include -#include #include using namespace OpenRCT2; @@ -55,8 +53,6 @@ std::string GetNameFromTrackPath(const std::string& path) return name; } -static std::mutex _objectLookupMutex; - class TrackDesignFileIndex final : public FileIndex { private: @@ -82,27 +78,10 @@ public: auto td6 = track_design_open(path.c_str()); if (td6 != nullptr) { - ObjectEntryIndex rideType = td6->type; - if (RCT2RideTypeNeedsConversion(td6->type)) - { - std::scoped_lock lock(_objectLookupMutex); - auto* rawObject = object_repository_load_object(&td6->vehicle_object); - if (rawObject != nullptr) - { - const auto* rideEntry = static_cast( - static_cast(rawObject)->GetLegacyData()); - if (rideEntry != nullptr) - { - rideType = RCT2RideTypeToOpenRCT2RideType(td6->type, rideEntry); - } - object_delete(rawObject); - } - } - TrackRepositoryItem item; item.Name = GetNameFromTrackPath(path); item.Path = path; - item.RideType = rideType; + item.RideType = td6->type; item.ObjectEntry = std::string(td6->vehicle_object.name, 8); item.Flags = 0; if (IsTrackReadOnly(path))