diff --git a/src/openrct2-ui/ride/Construction.cpp b/src/openrct2-ui/ride/Construction.cpp index 7029aa0986..42b6817922 100644 --- a/src/openrct2-ui/ride/Construction.cpp +++ b/src/openrct2-ui/ride/Construction.cpp @@ -9,6 +9,7 @@ #include "Construction.h" +#include #include #include #include @@ -28,7 +29,8 @@ void RideConstructNew(RideSelection listItem) int32_t colour1 = RideGetRandomColourPresetIndex(listItem.Type); int32_t colour2 = RideGetUnusedPresetVehicleColour(rideEntryIndex); - auto gameAction = RideCreateAction(listItem.Type, listItem.EntryIndex, colour1, colour2, gLastEntranceStyle); + auto gameAction = RideCreateAction( + listItem.Type, listItem.EntryIndex, colour1, colour2, OpenRCT2::GetGameState().LastEntranceStyle); gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) diff --git a/src/openrct2-ui/windows/Ride.cpp b/src/openrct2-ui/windows/Ride.cpp index c7f909c855..5a20dcde4f 100644 --- a/src/openrct2-ui/windows/Ride.cpp +++ b/src/openrct2-ui/windows/Ride.cpp @@ -4322,7 +4322,7 @@ private: rideSetAppearanceAction.SetCallback([objIndex](const GameAction*, const GameActions::Result* res) { if (res->Error != GameActions::Status::Ok) return; - gLastEntranceStyle = objIndex; + GetGameState().LastEntranceStyle = objIndex; }); GameActions::Execute(&rideSetAppearanceAction); break; diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 5a793d0136..a54958c3a2 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -487,10 +487,10 @@ void FinishObjectSelection() SetEveryRideEntryInvented(); auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); - gLastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain"); - if (gLastEntranceStyle == OBJECT_ENTRY_INDEX_NULL) + gameState.LastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain"); + if (gameState.LastEntranceStyle == OBJECT_ENTRY_INDEX_NULL) { - gLastEntranceStyle = 0; + gameState.LastEntranceStyle = 0; } gameState.EditorStep = EditorStep::RollercoasterDesigner; diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 6b9310443d..539febfc85 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -125,6 +125,8 @@ namespace OpenRCT2 uint8_t SavedViewRotation; ZoomLevel SavedViewZoom; + ObjectEntryIndex LastEntranceStyle; + /** * Probability out of 65535, of gaining a new guest per game tick. * new guests per second = 40 * (probability / 65535) diff --git a/src/openrct2/actions/TrackDesignAction.cpp b/src/openrct2/actions/TrackDesignAction.cpp index 88bbc851d9..7f74c6006f 100644 --- a/src/openrct2/actions/TrackDesignAction.cpp +++ b/src/openrct2/actions/TrackDesignAction.cpp @@ -64,20 +64,21 @@ GameActions::Result TrackDesignAction::Query() const GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP); } + auto& gameState = GetGameState(); auto& objManager = GetContext()->GetObjectManager(); auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.vehicle_object); if (entryIndex == OBJECT_ENTRY_INDEX_NULL) { // Force a fallback if the entry is not invented yet a td6 of it is selected, // which can happen in select-by-track-type mode - if (!RideEntryIsInvented(entryIndex) && !GetGameState().Cheats.IgnoreResearchStatus) + if (!RideEntryIsInvented(entryIndex) && !gameState.Cheats.IgnoreResearchStatus) { entryIndex = OBJECT_ENTRY_INDEX_NULL; } } // Colours do not matter as will be overwritten - auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gLastEntranceStyle); + auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gameState.LastEntranceStyle); rideCreateAction.SetFlags(GetFlags()); auto r = GameActions::ExecuteNested(&rideCreateAction); if (r.Error != GameActions::Status::Ok) @@ -136,20 +137,21 @@ GameActions::Result TrackDesignAction::Execute() const res.Position.z = _loc.z; res.Expenditure = ExpenditureType::RideConstruction; + auto& gameState = GetGameState(); auto& objManager = GetContext()->GetObjectManager(); auto entryIndex = objManager.GetLoadedObjectEntryIndex(_td.vehicle_object); if (entryIndex != OBJECT_ENTRY_INDEX_NULL) { // Force a fallback if the entry is not invented yet a track design using it is selected. // This can happen on rides with multiple vehicles where some have been invented and some haven’t. - if (!RideEntryIsInvented(entryIndex) && !GetGameState().Cheats.IgnoreResearchStatus) + if (!RideEntryIsInvented(entryIndex) && !gameState.Cheats.IgnoreResearchStatus) { entryIndex = OBJECT_ENTRY_INDEX_NULL; } } // Colours do not matter as will be overwritten - auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gLastEntranceStyle); + auto rideCreateAction = RideCreateAction(_td.type, entryIndex, 0, 0, gameState.LastEntranceStyle); rideCreateAction.SetFlags(GetFlags()); auto r = GameActions::ExecuteNested(&rideCreateAction); if (r.Error != GameActions::Status::Ok) @@ -247,7 +249,7 @@ GameActions::Result TrackDesignAction::Execute() const ride->entrance_style = objManager.GetLoadedObjectEntryIndex(_td.StationObjectIdentifier); if (ride->entrance_style == OBJECT_ENTRY_INDEX_NULL) { - ride->entrance_style = gLastEntranceStyle; + ride->entrance_style = gameState.LastEntranceStyle; } for (int32_t i = 0; i < Limits::NumColourSchemes; i++) diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 524ec2153e..00ab7f958b 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -617,7 +617,7 @@ namespace OpenRCT2 cs.Write(static_cast(gameState.SavedViewZoom)); } cs.ReadWrite(gameState.SavedViewRotation); - cs.ReadWrite(gLastEntranceStyle); + cs.ReadWrite(gameState.LastEntranceStyle); cs.ReadWrite(gameState.EditorStep); }); } diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 1c795152ee..28f13df83a 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -407,7 +407,7 @@ namespace RCT2 | (static_cast(_s6.SamePriceThroughoutExtended) << 32); gameState.SuggestedGuestMaximum = _s6.SuggestedMaxGuests; gameState.ScenarioParkRatingWarningDays = _s6.ParkRatingWarningDays; - gLastEntranceStyle = _s6.LastEntranceStyle; + gameState.LastEntranceStyle = _s6.LastEntranceStyle; // rct1_water_colour // Pad01358842 ImportResearchList(gameState); diff --git a/src/openrct2/ride/Ride.h b/src/openrct2/ride/Ride.h index e25961e5e3..dc1795a7fa 100644 --- a/src/openrct2/ride/Ride.h +++ b/src/openrct2/ride/Ride.h @@ -1014,8 +1014,6 @@ std::string_view GetRideEntryName(ObjectEntryIndex index); extern const StringId ColourSchemeNames[4]; -extern ObjectEntryIndex gLastEntranceStyle; - int32_t RideGetCount(); void RideInitAll(); void ResetAllRideBuildDates(); diff --git a/src/openrct2/ride/RideConstruction.cpp b/src/openrct2/ride/RideConstruction.cpp index 024d1bee72..c133283391 100644 --- a/src/openrct2/ride/RideConstruction.cpp +++ b/src/openrct2/ride/RideConstruction.cpp @@ -79,8 +79,6 @@ uint8_t _currentSeatRotationAngle; CoordsXYZD _unkF440C5; -ObjectEntryIndex gLastEntranceStyle; - uint8_t gRideEntranceExitPlaceType; RideId gRideEntranceExitPlaceRideIndex; StationIndex gRideEntranceExitPlaceStationIndex; diff --git a/src/openrct2/ride/TrackDesign.cpp b/src/openrct2/ride/TrackDesign.cpp index df37b689a5..8e45f2c5b0 100644 --- a/src/openrct2/ride/TrackDesign.cpp +++ b/src/openrct2/ride/TrackDesign.cpp @@ -1873,7 +1873,7 @@ int32_t TrackDesignGetZPlacement(TrackDesign* td6, Ride& ride, const CoordsXYZD& static money64 TrackDesignCreateRide(int32_t type, int32_t subType, int32_t flags, RideId* outRideIndex) { // Don't set colours as will be set correctly later. - auto gameAction = RideCreateAction(type, subType, 0, 0, gLastEntranceStyle); + auto gameAction = RideCreateAction(type, subType, 0, 0, GetGameState().LastEntranceStyle); gameAction.SetFlags(flags); auto res = GameActions::ExecuteNested(&gameAction); @@ -1900,6 +1900,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon *outRide = nullptr; *flags = 0; + auto& gameState = GetGameState(); auto& objManager = GetContext()->GetObjectManager(); auto entry_index = objManager.GetLoadedObjectEntryIndex(td6->vehicle_object); @@ -1919,7 +1920,7 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon ride->entrance_style = objManager.GetLoadedObjectEntryIndex(td6->StationObjectIdentifier); if (ride->entrance_style == OBJECT_ENTRY_INDEX_NULL) { - ride->entrance_style = gLastEntranceStyle; + ride->entrance_style = gameState.LastEntranceStyle; } for (int32_t i = 0; i < OpenRCT2::Limits::NumColourSchemes; i++) @@ -1939,7 +1940,6 @@ static bool TrackDesignPlacePreview(TrackDesignState& tds, TrackDesign* td6, mon } } - auto& gameState = GetGameState(); _trackDesignDrawingPreview = true; uint8_t backup_rotation = _currentTrackPieceDirection; uint32_t backup_park_flags = gameState.ParkFlags; diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index f1424db3f0..b2d2db843c 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -156,11 +156,11 @@ void ScenarioReset(GameState_t& gameState) Staff::ResetStats(); auto& objManager = GetContext()->GetObjectManager(); - gLastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain"); - if (gLastEntranceStyle == OBJECT_ENTRY_INDEX_NULL) + gameState.LastEntranceStyle = objManager.GetLoadedObjectEntryIndex("rct2.station.plain"); + if (gameState.LastEntranceStyle == OBJECT_ENTRY_INDEX_NULL) { // Fall back to first entrance object - gLastEntranceStyle = 0; + gameState.LastEntranceStyle = 0; } gMarketingCampaigns.clear();