From c1ac7c0700177817195152e112543b3bce11db7a Mon Sep 17 00:00:00 2001 From: Harry Hopkinson <63599884+Harry-Hopkinson@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:42:37 +0100 Subject: [PATCH] Cleanup gameState usage --- src/openrct2-ui/ride/Construction.cpp | 2 +- .../windows/EditorBottomToolbar.cpp | 2 +- .../windows/EditorObjectiveOptions.cpp | 2 +- src/openrct2-ui/windows/Finances.cpp | 2 +- src/openrct2-ui/windows/GameBottomToolbar.cpp | 4 +- src/openrct2-ui/windows/Guest.cpp | 2 +- src/openrct2-ui/windows/LoadSave.cpp | 2 +- src/openrct2-ui/windows/Park.cpp | 8 +-- src/openrct2-ui/windows/RideConstruction.cpp | 2 +- src/openrct2/Editor.cpp | 2 +- src/openrct2/EditorObjectSelectionSession.cpp | 2 +- src/openrct2/GameState.cpp | 7 ++- src/openrct2/ReplayManager.cpp | 4 +- src/openrct2/actions/CheatSetAction.cpp | 57 ++++++++++--------- src/openrct2/actions/ClearAction.cpp | 2 +- .../actions/FootpathAdditionPlaceAction.cpp | 3 +- .../actions/FootpathAdditionRemoveAction.cpp | 3 +- src/openrct2/actions/LandLowerAction.cpp | 2 +- src/openrct2/actions/LandRaiseAction.cpp | 2 +- src/openrct2/actions/LandSetHeightAction.cpp | 8 +-- .../actions/LargeSceneryPlaceAction.cpp | 6 +- .../actions/LargeScenerySetColourAction.cpp | 2 +- src/openrct2/actions/MapChangeSizeAction.cpp | 2 +- src/openrct2/actions/MazePlaceTrackAction.cpp | 5 +- src/openrct2/actions/MazeSetTrackAction.cpp | 5 +- src/openrct2/actions/ParkSetNameAction.cpp | 2 +- src/openrct2/actions/RideCreateAction.cpp | 5 +- src/openrct2/actions/RideSetSettingAction.cpp | 5 +- src/openrct2/actions/RideSetVehicleAction.cpp | 5 +- .../actions/SmallSceneryPlaceAction.cpp | 12 ++-- .../actions/SurfaceSetStyleAction.cpp | 8 ++- src/openrct2/actions/TrackPlaceAction.cpp | 22 +++---- src/openrct2/actions/WaterRaiseAction.cpp | 4 +- src/openrct2/actions/WaterSetHeightAction.cpp | 7 ++- src/openrct2/drawing/LightFX.cpp | 2 +- src/openrct2/entity/Guest.cpp | 4 +- src/openrct2/entity/Litter.cpp | 5 +- src/openrct2/entity/Peep.cpp | 4 +- src/openrct2/management/Award.cpp | 5 +- src/openrct2/management/Finance.cpp | 2 +- src/openrct2/network/DiscordService.cpp | 2 +- .../paint/tile_element/Paint.Entrance.cpp | 7 ++- src/openrct2/ride/Ride.cpp | 5 +- src/openrct2/scenario/Scenario.cpp | 4 +- .../scripting/bindings/entity/ScGuest.cpp | 5 +- .../scripting/bindings/world/ScClimate.hpp | 6 +- src/openrct2/world/Footpath.cpp | 8 +-- src/openrct2/world/Map.cpp | 15 ++--- src/openrct2/world/MapGen.cpp | 4 +- src/openrct2/world/Scenery.cpp | 12 ++-- 50 files changed, 159 insertions(+), 139 deletions(-) diff --git a/src/openrct2-ui/ride/Construction.cpp b/src/openrct2-ui/ride/Construction.cpp index 0248d0233a..a5c23e94e9 100644 --- a/src/openrct2-ui/ride/Construction.cpp +++ b/src/openrct2-ui/ride/Construction.cpp @@ -34,7 +34,7 @@ namespace OpenRCT2 int32_t colour2 = RideGetUnusedPresetVehicleColour(rideEntryIndex); auto gameAction = RideCreateAction( - listItem.Type, listItem.EntryIndex, colour1, colour2, OpenRCT2::GetGameState().LastEntranceStyle); + listItem.Type, listItem.EntryIndex, colour1, colour2, GetGameState().LastEntranceStyle); gameAction.SetCallback([](const GameAction* ga, const GameActions::Result* result) { if (result->Error != GameActions::Status::Ok) diff --git a/src/openrct2-ui/windows/EditorBottomToolbar.cpp b/src/openrct2-ui/windows/EditorBottomToolbar.cpp index 8bdacf984f..c90d03143c 100644 --- a/src/openrct2-ui/windows/EditorBottomToolbar.cpp +++ b/src/openrct2-ui/windows/EditorBottomToolbar.cpp @@ -140,7 +140,7 @@ static Widget _editorBottomToolbarWidgets[] = { if (widgetIndex == WIDX_PREVIOUS_STEP_BUTTON) { if ((gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) - || (GetNumFreeEntities() == MAX_ENTITIES && !(GetGameState().Park.Flags & PARK_FLAGS_SPRITES_INITIALISED))) + || (GetNumFreeEntities() == MAX_ENTITIES && !(gameState.Park.Flags & PARK_FLAGS_SPRITES_INITIALISED))) { ((this)->*(_previousButtonMouseUp[EnumValue(gameState.EditorStep)]))(); } diff --git a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp index 130d496683..85bf62c82d 100644 --- a/src/openrct2-ui/windows/EditorObjectiveOptions.cpp +++ b/src/openrct2-ui/windows/EditorObjectiveOptions.cpp @@ -971,7 +971,7 @@ static uint64_t window_editor_objective_options_page_hold_down_widgets[] = { widthToSet = widgets[WIDX_PARK_NAME].left - 16; { - auto parkName = OpenRCT2::GetGameState().Park.Name.c_str(); + auto parkName = GetGameState().Park.Name.c_str(); ft = Formatter(); ft.Add(STR_STRING); diff --git a/src/openrct2-ui/windows/Finances.cpp b/src/openrct2-ui/windows/Finances.cpp index 6145b59900..3d933c8b56 100644 --- a/src/openrct2-ui/windows/Finances.cpp +++ b/src/openrct2-ui/windows/Finances.cpp @@ -744,7 +744,7 @@ static Widget _windowFinancesResearchWidgets[] = break; default: { - auto parkName = OpenRCT2::GetGameState().Park.Name.c_str(); + auto parkName = GetGameState().Park.Name.c_str(); ft.Add(STR_STRING); ft.Add(parkName); } diff --git a/src/openrct2-ui/windows/GameBottomToolbar.cpp b/src/openrct2-ui/windows/GameBottomToolbar.cpp index 8305d0d2ff..20b7fe1ef2 100644 --- a/src/openrct2-ui/windows/GameBottomToolbar.cpp +++ b/src/openrct2-ui/windows/GameBottomToolbar.cpp @@ -206,7 +206,7 @@ static Widget window_game_bottom_toolbar_widgets[] = screenCoords = { windowPos.x + window_game_bottom_toolbar_widgets[WIDX_RIGHT_OUTSET].left + 15, static_cast(screenCoords.y + line_height + 1) }; - int32_t temperature = OpenRCT2::GetGameState().ClimateCurrent.Temperature; + int32_t temperature = GetGameState().ClimateCurrent.Temperature; StringId format = STR_CELSIUS_VALUE; if (Config::Get().general.TemperatureFormat == TemperatureUnit::Fahrenheit) { @@ -219,7 +219,7 @@ static Widget window_game_bottom_toolbar_widgets[] = screenCoords.x += 30; // Current weather - auto currentWeatherSpriteId = ClimateGetWeatherSpriteId(OpenRCT2::GetGameState().ClimateCurrent); + auto currentWeatherSpriteId = ClimateGetWeatherSpriteId(GetGameState().ClimateCurrent); GfxDrawSprite(dpi, ImageId(currentWeatherSpriteId), screenCoords); // Next weather diff --git a/src/openrct2-ui/windows/Guest.cpp b/src/openrct2-ui/windows/Guest.cpp index 1165df7941..29ea03b5b1 100644 --- a/src/openrct2-ui/windows/Guest.cpp +++ b/src/openrct2-ui/windows/Guest.cpp @@ -1609,7 +1609,7 @@ static_assert(_guestWindowPageWidgets.size() == WINDOW_GUEST_PAGE_COUNT); std::pair InventoryFormatItem(Guest& guest, ShopItem item) const { - auto parkName = OpenRCT2::GetGameState().Park.Name.c_str(); + auto parkName = GetGameState().Park.Name.c_str(); // Default arguments auto ft = Formatter(); diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 6934fa0017..f3f01e455d 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -461,7 +461,7 @@ static Widget window_loadsave_widgets[] = } else { - auto buffer = OpenRCT2::GetGameState().Park.Name; + auto buffer = GetGameState().Park.Name; if (buffer.empty()) { buffer = LanguageGetString(STR_UNNAMED_PARK); diff --git a/src/openrct2-ui/windows/Park.cpp b/src/openrct2-ui/windows/Park.cpp index 17b230793a..6b4e117db9 100644 --- a/src/openrct2-ui/windows/Park.cpp +++ b/src/openrct2-ui/windows/Park.cpp @@ -417,7 +417,7 @@ static constexpr WindowParkAward _parkAwards[] = { void PrepareWindowTitleText() { - auto parkName = OpenRCT2::GetGameState().Park.Name.c_str(); + auto parkName = GetGameState().Park.Name.c_str(); auto ft = Formatter::Common(); ft.Add(STR_STRING); @@ -437,7 +437,7 @@ static constexpr WindowParkAward _parkAwards[] = { break; case WIDX_RENAME: { - auto& park = OpenRCT2::GetGameState().Park; + auto& park = GetGameState().Park; WindowTextInputRawOpen( this, WIDX_RENAME, STR_PARK_NAME, STR_ENTER_PARK_NAME, {}, park.Name.c_str(), kUserStringMaxLength); break; @@ -526,7 +526,7 @@ static constexpr WindowParkAward _parkAwards[] = { // Set open / close park button state { - auto parkName = OpenRCT2::GetGameState().Park.Name.c_str(); + auto parkName = GetGameState().Park.Name.c_str(); auto ft = Formatter::Common(); ft.Add(STR_STRING); @@ -1173,7 +1173,7 @@ static constexpr WindowParkAward _parkAwards[] = { auto screenCoords = windowPos + ScreenCoordsXY{ widgets[WIDX_PAGE_BACKGROUND].left + 4, widgets[WIDX_PAGE_BACKGROUND].top + 4 }; - auto& currentAwards = OpenRCT2::GetGameState().CurrentAwards; + auto& currentAwards = GetGameState().CurrentAwards; for (const auto& award : currentAwards) { diff --git a/src/openrct2-ui/windows/RideConstruction.cpp b/src/openrct2-ui/windows/RideConstruction.cpp index 2f6bfcb1d9..72b57618a0 100644 --- a/src/openrct2-ui/windows/RideConstruction.cpp +++ b/src/openrct2-ui/windows/RideConstruction.cpp @@ -2636,7 +2636,7 @@ static Widget _rideConstructionWidgets[] = { return; } - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); auto preserveMapSize = gameState.MapSize; gameState.MapSize = { kMaximumMapSizeTechnical, kMaximumMapSizeTechnical }; diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 8ac38b09bf..1c8c6a6071 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -298,7 +298,7 @@ namespace OpenRCT2::Editor gameState.GuestInitialCash = std::clamp(gameState.GuestInitialCash, 10.00_GBP, MAX_ENTRANCE_FEE); - gameState.InitialCash = std::min(GetGameState().InitialCash, 100000); + gameState.InitialCash = std::min(gameState.InitialCash, 100000); FinanceResetCashToInitial(); gameState.BankLoan = std::clamp(gameState.BankLoan, 0.00_GBP, 5000000.00_GBP); diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index 7fc1592b5e..1c9be53784 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -483,7 +483,7 @@ void ResetSelectedObjectCountAndSize() void FinishObjectSelection() { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); if (gScreenFlags & SCREEN_FLAGS_TRACK_DESIGNER) { SetEveryRideTypeInvented(); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index 6e3def1cd2..8a4acc11d5 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -80,7 +80,7 @@ namespace OpenRCT2 gInMapInitCode = false; - GetGameState().NextGuestNumber = 1; + gameState.NextGuestNumber = 1; ContextInit(); @@ -264,6 +264,8 @@ namespace OpenRCT2 NetworkUpdate(); + auto& gameState = GetGameState(); + if (NetworkGetMode() == NETWORK_MODE_SERVER) { if (NetworkGamestateSnapshotsEnabled()) @@ -277,7 +279,7 @@ namespace OpenRCT2 else if (NetworkGetMode() == NETWORK_MODE_CLIENT) { // Don't run past the server, this condition can happen during map changes. - if (NetworkGetServerTick() == GetGameState().CurrentTicks) + if (NetworkGetServerTick() == gameState.CurrentTicks) { gInUpdateCode = false; return; @@ -299,7 +301,6 @@ namespace OpenRCT2 } } - auto& gameState = GetGameState(); #ifdef ENABLE_SCRIPTING // Stash the current day number before updating the date so that we // know if the day number changes on this tick. diff --git a/src/openrct2/ReplayManager.cpp b/src/openrct2/ReplayManager.cpp index 25064e8d3b..97b6c685de 100644 --- a/src/openrct2/ReplayManager.cpp +++ b/src/openrct2/ReplayManager.cpp @@ -238,7 +238,8 @@ namespace OpenRCT2 if (_mode != ReplayMode::NONE && _mode != ReplayMode::NORMALISATION) return false; - const auto currentTicks = GetGameState().CurrentTicks; + auto& gameState = GetGameState(); + const auto currentTicks = gameState.CurrentTicks; auto replayData = std::make_unique(); replayData->magic = kReplayMagic; @@ -257,7 +258,6 @@ namespace OpenRCT2 auto& objManager = context->GetObjectManager(); auto objects = objManager.GetPackableObjects(); - auto& gameState = GetGameState(); auto exporter = std::make_unique(); exporter->ExportObjectsList = objects; exporter->Export(gameState, replayData->parkData); diff --git a/src/openrct2/actions/CheatSetAction.cpp b/src/openrct2/actions/CheatSetAction.cpp index dcb4f0c0e2..48713bb26e 100644 --- a/src/openrct2/actions/CheatSetAction.cpp +++ b/src/openrct2/actions/CheatSetAction.cpp @@ -105,53 +105,53 @@ GameActions::Result CheatSetAction::Execute() const switch (static_cast(_cheatType.id)) { case CheatType::SandboxMode: - GetGameState().Cheats.SandboxMode = _param1 != 0; + gameState.Cheats.SandboxMode = _param1 != 0; WindowInvalidateByClass(WindowClass::Map); WindowInvalidateByClass(WindowClass::Footpath); break; case CheatType::DisableClearanceChecks: - GetGameState().Cheats.DisableClearanceChecks = _param1 != 0; + gameState.Cheats.DisableClearanceChecks = _param1 != 0; // Required to update the clearance checks overlay on the Cheats button. WindowInvalidateByClass(WindowClass::TopToolbar); break; case CheatType::DisableSupportLimits: - GetGameState().Cheats.DisableSupportLimits = _param1 != 0; + gameState.Cheats.DisableSupportLimits = _param1 != 0; break; case CheatType::ShowAllOperatingModes: - GetGameState().Cheats.ShowAllOperatingModes = _param1 != 0; + gameState.Cheats.ShowAllOperatingModes = _param1 != 0; break; case CheatType::ShowVehiclesFromOtherTrackTypes: - GetGameState().Cheats.ShowVehiclesFromOtherTrackTypes = _param1 != 0; + gameState.Cheats.ShowVehiclesFromOtherTrackTypes = _param1 != 0; break; case CheatType::FastLiftHill: - GetGameState().Cheats.UnlockOperatingLimits = _param1 != 0; + gameState.Cheats.UnlockOperatingLimits = _param1 != 0; break; case CheatType::DisableBrakesFailure: - GetGameState().Cheats.DisableBrakesFailure = _param1 != 0; + gameState.Cheats.DisableBrakesFailure = _param1 != 0; break; case CheatType::DisableAllBreakdowns: - GetGameState().Cheats.DisableAllBreakdowns = _param1 != 0; + gameState.Cheats.DisableAllBreakdowns = _param1 != 0; break; case CheatType::DisableTrainLengthLimit: - GetGameState().Cheats.DisableTrainLengthLimit = _param1 != 0; + gameState.Cheats.DisableTrainLengthLimit = _param1 != 0; break; case CheatType::EnableChainLiftOnAllTrack: - GetGameState().Cheats.EnableChainLiftOnAllTrack = _param1 != 0; + gameState.Cheats.EnableChainLiftOnAllTrack = _param1 != 0; break; case CheatType::BuildInPauseMode: - GetGameState().Cheats.BuildInPauseMode = _param1 != 0; + gameState.Cheats.BuildInPauseMode = _param1 != 0; break; case CheatType::IgnoreRideIntensity: - GetGameState().Cheats.IgnoreRideIntensity = _param1 != 0; + gameState.Cheats.IgnoreRideIntensity = _param1 != 0; break; case CheatType::IgnorePrice: - GetGameState().Cheats.IgnorePrice = _param1 != 0; + gameState.Cheats.IgnorePrice = _param1 != 0; break; case CheatType::DisableVandalism: - GetGameState().Cheats.DisableVandalism = _param1 != 0; + gameState.Cheats.DisableVandalism = _param1 != 0; break; case CheatType::DisableLittering: - GetGameState().Cheats.DisableLittering = _param1 != 0; + gameState.Cheats.DisableLittering = _param1 != 0; break; case CheatType::NoMoney: SetScenarioNoMoney(_param1 != 0); @@ -190,7 +190,7 @@ GameActions::Result CheatSetAction::Execute() const RemoveLitter(); break; case CheatType::DisablePlantAging: - GetGameState().Cheats.DisablePlantAging = _param1 != 0; + gameState.Cheats.DisablePlantAging = _param1 != 0; break; case CheatType::SetStaffSpeed: SetStaffSpeed(_param1); @@ -199,7 +199,7 @@ GameActions::Result CheatSetAction::Execute() const RenewRides(); break; case CheatType::MakeDestructible: - GetGameState().Cheats.MakeAllDestructible = _param1 != 0; + gameState.Cheats.MakeAllDestructible = _param1 != 0; WindowInvalidateByClass(WindowClass::Ride); break; case CheatType::FixRides: @@ -219,13 +219,13 @@ GameActions::Result CheatSetAction::Execute() const ClimateForceWeather(WeatherType{ static_cast(_param1) }); break; case CheatType::FreezeWeather: - GetGameState().Cheats.FreezeWeather = _param1 != 0; + gameState.Cheats.FreezeWeather = _param1 != 0; break; case CheatType::NeverEndingMarketing: - GetGameState().Cheats.NeverendingMarketing = _param1 != 0; + gameState.Cheats.NeverendingMarketing = _param1 != 0; break; case CheatType::OpenClosePark: - ParkSetOpen(!GetGameState().Park.IsOpen()); + ParkSetOpen(!gameState.Park.IsOpen()); break; case CheatType::HaveFun: gameState.ScenarioObjective.Type = OBJECTIVE_HAVE_FUN; @@ -234,20 +234,20 @@ GameActions::Result CheatSetAction::Execute() const Park::SetForcedRating(_param1); break; case CheatType::AllowArbitraryRideTypeChanges: - GetGameState().Cheats.AllowArbitraryRideTypeChanges = _param1 != 0; + gameState.Cheats.AllowArbitraryRideTypeChanges = _param1 != 0; WindowInvalidateByClass(WindowClass::Ride); break; case CheatType::OwnAllLand: OwnAllLand(); break; case CheatType::DisableRideValueAging: - GetGameState().Cheats.DisableRideValueAging = _param1 != 0; + gameState.Cheats.DisableRideValueAging = _param1 != 0; break; case CheatType::IgnoreResearchStatus: - GetGameState().Cheats.IgnoreResearchStatus = _param1 != 0; + gameState.Cheats.IgnoreResearchStatus = _param1 != 0; break; case CheatType::EnableAllDrawableTrackPieces: - GetGameState().Cheats.EnableAllDrawableTrackPieces = _param1 != 0; + gameState.Cheats.EnableAllDrawableTrackPieces = _param1 != 0; break; case CheatType::CreateDucks: CreateDucks(_param1); @@ -256,13 +256,13 @@ GameActions::Result CheatSetAction::Execute() const Duck::RemoveAll(); break; case CheatType::AllowTrackPlaceInvalidHeights: - GetGameState().Cheats.AllowTrackPlaceInvalidHeights = _param1 != 0; + gameState.Cheats.AllowTrackPlaceInvalidHeights = _param1 != 0; break; case CheatType::AllowRegularPathAsQueue: - GetGameState().Cheats.AllowRegularPathAsQueue = _param1 != 0; + gameState.Cheats.AllowRegularPathAsQueue = _param1 != 0; break; case CheatType::AllowSpecialColourSchemes: - GetGameState().Cheats.AllowSpecialColourSchemes = static_cast(_param1); + gameState.Cheats.AllowSpecialColourSchemes = static_cast(_param1); break; case CheatType::RemoveParkFences: RemoveParkFences(); @@ -603,7 +603,8 @@ void CheatSetAction::SetMoney(money64 amount) const void CheatSetAction::AddMoney(money64 amount) const { - GetGameState().Cash = AddClamp(GetGameState().Cash, amount); + auto& gameState = GetGameState(); + gameState.Cash = AddClamp(gameState.Cash, amount); WindowInvalidateByClass(WindowClass::Finances); WindowInvalidateByClass(WindowClass::BottomToolbar); diff --git a/src/openrct2/actions/ClearAction.cpp b/src/openrct2/actions/ClearAction.cpp index 23eb22e688..b084c1e57d 100644 --- a/src/openrct2/actions/ClearAction.cpp +++ b/src/openrct2/actions/ClearAction.cpp @@ -217,7 +217,7 @@ money64 ClearAction::ClearSceneryFromTile(const CoordsXY& tilePos, bool executin void ClearAction::ResetClearLargeSceneryFlag() { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); // TODO: Improve efficiency of this for (int32_t y = 0; y < gameState.MapSize.y; y++) { diff --git a/src/openrct2/actions/FootpathAdditionPlaceAction.cpp b/src/openrct2/actions/FootpathAdditionPlaceAction.cpp index ff8f176b0d..c3ba64ac4c 100644 --- a/src/openrct2/actions/FootpathAdditionPlaceAction.cpp +++ b/src/openrct2/actions/FootpathAdditionPlaceAction.cpp @@ -61,8 +61,7 @@ GameActions::Result FootpathAdditionPlaceAction::Query() const return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_POSITION_THIS_HERE, STR_OFF_EDGE_OF_MAP); } - if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode) - && !MapIsLocationOwned(_loc)) + if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode) && !MapIsLocationOwned(_loc)) { return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); } diff --git a/src/openrct2/actions/FootpathAdditionRemoveAction.cpp b/src/openrct2/actions/FootpathAdditionRemoveAction.cpp index 7cefb89925..1d6d3bba05 100644 --- a/src/openrct2/actions/FootpathAdditionRemoveAction.cpp +++ b/src/openrct2/actions/FootpathAdditionRemoveAction.cpp @@ -53,8 +53,7 @@ GameActions::Result FootpathAdditionRemoveAction::Query() const return GameActions::Result(GameActions::Status::InvalidParameters, STR_CANT_REMOVE_THIS, STR_OFF_EDGE_OF_MAP); } - if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode) - && !MapIsLocationOwned(_loc)) + if (!((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode) && !MapIsLocationOwned(_loc)) { return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_REMOVE_THIS, STR_LAND_NOT_OWNED_BY_PARK); } diff --git a/src/openrct2/actions/LandLowerAction.cpp b/src/openrct2/actions/LandLowerAction.cpp index 56a28e20bf..94e68219ea 100644 --- a/src/openrct2/actions/LandLowerAction.cpp +++ b/src/openrct2/actions/LandLowerAction.cpp @@ -96,7 +96,7 @@ GameActions::Result LandLowerAction::QueryExecute(bool isExecuting) const if (surfaceElement == nullptr) continue; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) { if (!MapIsLocationInPark(CoordsXY{ x, y })) { diff --git a/src/openrct2/actions/LandRaiseAction.cpp b/src/openrct2/actions/LandRaiseAction.cpp index 429db39de0..b32cd57612 100644 --- a/src/openrct2/actions/LandRaiseAction.cpp +++ b/src/openrct2/actions/LandRaiseAction.cpp @@ -97,7 +97,7 @@ GameActions::Result LandRaiseAction::QueryExecute(bool isExecuting) const if (surfaceElement == nullptr) continue; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) { if (!MapIsLocationInPark(CoordsXY{ x, y })) { diff --git a/src/openrct2/actions/LandSetHeightAction.cpp b/src/openrct2/actions/LandSetHeightAction.cpp index 44800f0dc9..a2f6fd8b23 100644 --- a/src/openrct2/actions/LandSetHeightAction.cpp +++ b/src/openrct2/actions/LandSetHeightAction.cpp @@ -67,7 +67,7 @@ GameActions::Result LandSetHeightAction::Query() const return GameActions::Result(GameActions::Status::Disallowed, STR_NONE, errorMessage); } - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode) { if (!MapIsLocationInPark(_coords)) { @@ -76,7 +76,7 @@ GameActions::Result LandSetHeightAction::Query() const } money64 sceneryRemovalCost = 0; - if (!GetGameState().Cheats.DisableClearanceChecks) + if (!gameState.Cheats.DisableClearanceChecks) { if (gameState.Park.Flags & PARK_FLAGS_FORBID_TREE_REMOVAL) { @@ -93,7 +93,7 @@ GameActions::Result LandSetHeightAction::Query() const } // Check for ride support limits - if (!GetGameState().Cheats.DisableSupportLimits) + if (!gameState.Cheats.DisableSupportLimits) { errorMessage = CheckRideSupports(); if (errorMessage != STR_NONE) @@ -124,7 +124,7 @@ GameActions::Result LandSetHeightAction::Query() const return res; } - if (!GetGameState().Cheats.DisableClearanceChecks) + if (!gameState.Cheats.DisableClearanceChecks) { uint8_t zCorner = _height; if (_style & kTileSlopeRaisedCornersMask) diff --git a/src/openrct2/actions/LargeSceneryPlaceAction.cpp b/src/openrct2/actions/LargeSceneryPlaceAction.cpp index b7a244fa1f..e4958df2ea 100644 --- a/src/openrct2/actions/LargeSceneryPlaceAction.cpp +++ b/src/openrct2/actions/LargeSceneryPlaceAction.cpp @@ -70,6 +70,8 @@ GameActions::Result LargeSceneryPlaceAction::Query() const auto resultData = LargeSceneryPlaceActionResult{}; + auto& gameState = GetGameState(); + money64 supportsCost = 0; if (_primaryColour >= COLOUR_COUNT) @@ -147,7 +149,7 @@ GameActions::Result LargeSceneryPlaceAction::Query() const const auto clearanceData = canBuild.GetData(); int32_t tempSceneryGroundFlags = clearanceData.GroundFlags & (ELEMENT_IS_ABOVE_GROUND | ELEMENT_IS_UNDERGROUND); - if (!GetGameState().Cheats.DisableClearanceChecks) + if (!gameState.Cheats.DisableClearanceChecks) { if ((clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER) || (clearanceData.GroundFlags & ELEMENT_IS_UNDERGROUND)) { @@ -170,7 +172,7 @@ GameActions::Result LargeSceneryPlaceAction::Query() const } if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !MapIsLocationOwned({ curTile, zLow }) - && !GetGameState().Cheats.SandboxMode) + && !gameState.Cheats.SandboxMode) { return GameActions::Result( GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); diff --git a/src/openrct2/actions/LargeScenerySetColourAction.cpp b/src/openrct2/actions/LargeScenerySetColourAction.cpp index a76a41efce..36ab12a774 100644 --- a/src/openrct2/actions/LargeScenerySetColourAction.cpp +++ b/src/openrct2/actions/LargeScenerySetColourAction.cpp @@ -129,7 +129,7 @@ GameActions::Result LargeScenerySetColourAction::QueryExecute(bool isExecuting) auto rotatedTileCoords = CoordsXYZ{ CoordsXY{ tile->x_offset, tile->y_offset }.Rotate(_loc.direction), tile->z_offset }; auto currentTile = CoordsXYZ{ baseTile.x, baseTile.y, baseTile.z } + rotatedTileCoords; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) { if (!MapIsLocationOwned(currentTile)) { diff --git a/src/openrct2/actions/MapChangeSizeAction.cpp b/src/openrct2/actions/MapChangeSizeAction.cpp index 30b4b9398e..de08e2a421 100644 --- a/src/openrct2/actions/MapChangeSizeAction.cpp +++ b/src/openrct2/actions/MapChangeSizeAction.cpp @@ -59,7 +59,7 @@ GameActions::Result MapChangeSizeAction::Query() const GameActions::Result MapChangeSizeAction::Execute() const { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); // Expand map while (_targetSize.x > gameState.MapSize.x) { diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index 07ecb99c77..d76a737535 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -60,7 +60,8 @@ GameActions::Result MazePlaceTrackAction::Query() const res.ErrorMessage = STR_OFF_EDGE_OF_MAP; return res; } - if (!MapIsLocationOwned(_loc) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + auto& gameState = GetGameState(); + if (!MapIsLocationOwned(_loc) && !gameState.Cheats.SandboxMode) { res.Error = GameActions::Status::NotOwned; res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; @@ -85,7 +86,7 @@ GameActions::Result MazePlaceTrackAction::Query() const auto clearanceHeight = _loc.z + MAZE_CLEARANCE_HEIGHT; auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); - if (heightDifference >= 0 && !OpenRCT2::GetGameState().Cheats.DisableSupportLimits) + if (heightDifference >= 0 && !gameState.Cheats.DisableSupportLimits) { heightDifference /= kCoordsZPerTinyZ; diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index dbb89ea3da..b2a2c7043f 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -97,7 +97,8 @@ GameActions::Result MazeSetTrackAction::Query() const res.ErrorMessage = STR_OFF_EDGE_OF_MAP; return res; } - if (!MapIsLocationOwned(_loc) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + auto& gameState = GetGameState(); + if (!MapIsLocationOwned(_loc) && !gameState.Cheats.SandboxMode) { res.Error = GameActions::Status::NotOwned; res.ErrorMessage = STR_LAND_NOT_OWNED_BY_PARK; @@ -122,7 +123,7 @@ GameActions::Result MazeSetTrackAction::Query() const auto clearanceHeight = _loc.z + 32; auto heightDifference = baseHeight - surfaceElement->GetBaseZ(); - if (heightDifference >= 0 && !OpenRCT2::GetGameState().Cheats.DisableSupportLimits) + if (heightDifference >= 0 && !gameState.Cheats.DisableSupportLimits) { heightDifference /= kCoordsZPerTinyZ; diff --git a/src/openrct2/actions/ParkSetNameAction.cpp b/src/openrct2/actions/ParkSetNameAction.cpp index 8ec0fb6b85..a1e2acfe94 100644 --- a/src/openrct2/actions/ParkSetNameAction.cpp +++ b/src/openrct2/actions/ParkSetNameAction.cpp @@ -57,7 +57,7 @@ GameActions::Result ParkSetNameAction::Query() const GameActions::Result ParkSetNameAction::Execute() const { // Do a no-op if new name is the same as the current name is the same - auto& park = OpenRCT2::GetGameState().Park; + auto& park = GetGameState().Park; if (_name != park.Name) { park.Name = _name; diff --git a/src/openrct2/actions/RideCreateAction.cpp b/src/openrct2/actions/RideCreateAction.cpp index 2d451828b3..04435ae9c8 100644 --- a/src/openrct2/actions/RideCreateAction.cpp +++ b/src/openrct2/actions/RideCreateAction.cpp @@ -161,7 +161,9 @@ GameActions::Result RideCreateAction::Execute() const ride->status = RideStatus::Closed; ride->NumTrains = 1; - if (GetGameState().Cheats.DisableTrainLengthLimit) + + auto& gameState = GetGameState(); + if (gameState.Cheats.DisableTrainLengthLimit) { // Reduce amount of proposed trains to prevent 32 trains from always spawning when limits are disabled if (rideEntry->cars_per_flat_ride == NoFlatRideCars) @@ -205,7 +207,6 @@ GameActions::Result RideCreateAction::Execute() const ride->ratings.setNull(); - auto& gameState = GetGameState(); if (!(gameState.Park.Flags & PARK_FLAGS_NO_MONEY)) { for (auto i = 0; i < RCT2::ObjectLimits::MaxShopItemsPerRideEntry; i++) diff --git a/src/openrct2/actions/RideSetSettingAction.cpp b/src/openrct2/actions/RideSetSettingAction.cpp index db9dd6531f..245c1c23e6 100644 --- a/src/openrct2/actions/RideSetSettingAction.cpp +++ b/src/openrct2/actions/RideSetSettingAction.cpp @@ -262,8 +262,9 @@ bool RideSetSettingAction::RideIsModeValid(const Ride& ride) const bool RideSetSettingAction::RideIsValidLiftHillSpeed(const Ride& ride) const { - int32_t minSpeed = GetGameState().Cheats.UnlockOperatingLimits ? 0 : ride.GetRideTypeDescriptor().LiftData.minimum_speed; - int32_t maxSpeed = GetGameState().Cheats.UnlockOperatingLimits ? 255 : ride.GetRideTypeDescriptor().LiftData.maximum_speed; + auto& gameState = GetGameState(); + int32_t minSpeed = gameState.Cheats.UnlockOperatingLimits ? 0 : ride.GetRideTypeDescriptor().LiftData.minimum_speed; + int32_t maxSpeed = gameState.Cheats.UnlockOperatingLimits ? 255 : ride.GetRideTypeDescriptor().LiftData.maximum_speed; return _value >= minSpeed && _value <= maxSpeed; } diff --git a/src/openrct2/actions/RideSetVehicleAction.cpp b/src/openrct2/actions/RideSetVehicleAction.cpp index af72334fc6..b24dce20c6 100644 --- a/src/openrct2/actions/RideSetVehicleAction.cpp +++ b/src/openrct2/actions/RideSetVehicleAction.cpp @@ -226,10 +226,11 @@ bool RideSetVehicleAction::RideIsVehicleTypeValid(const Ride& ride) const { bool selectionShouldBeExpanded; int32_t rideTypeIterator, rideTypeIteratorMax; + auto& gameState = GetGameState(); { const auto& rtd = ride.GetRideTypeDescriptor(); - if (GetGameState().Cheats.ShowVehiclesFromOtherTrackTypes + if (gameState.Cheats.ShowVehiclesFromOtherTrackTypes && !( ride.GetRideTypeDescriptor().HasFlag(RtdFlag::isFlatRide) || rtd.HasFlag(RtdFlag::isMaze) || ride.type == RIDE_TYPE_MINI_GOLF)) @@ -264,7 +265,7 @@ bool RideSetVehicleAction::RideIsVehicleTypeValid(const Ride& ride) const { if (rideEntryIndex == _value) { - if (!RideEntryIsInvented(rideEntryIndex) && !GetGameState().Cheats.IgnoreResearchStatus) + if (!RideEntryIsInvented(rideEntryIndex) && !gameState.Cheats.IgnoreResearchStatus) { return false; } diff --git a/src/openrct2/actions/SmallSceneryPlaceAction.cpp b/src/openrct2/actions/SmallSceneryPlaceAction.cpp index a1658fc490..eef9547df4 100644 --- a/src/openrct2/actions/SmallSceneryPlaceAction.cpp +++ b/src/openrct2/actions/SmallSceneryPlaceAction.cpp @@ -168,7 +168,8 @@ GameActions::Result SmallSceneryPlaceAction::Query() const targetHeight = surfaceHeight; } - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode + auto& gameState = GetGameState(); + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode && !MapIsLocationOwned({ _loc.x, _loc.y, targetHeight })) { return GameActions::Result(GameActions::Status::NotOwned, STR_CANT_POSITION_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); @@ -176,7 +177,7 @@ GameActions::Result SmallSceneryPlaceAction::Query() const auto* surfaceElement = MapGetSurfaceElementAt(_loc); - if (surfaceElement != nullptr && !GetGameState().Cheats.DisableClearanceChecks && surfaceElement->GetWaterHeight() > 0) + if (surfaceElement != nullptr && !gameState.Cheats.DisableClearanceChecks && surfaceElement->GetWaterHeight() > 0) { int32_t water_height = surfaceElement->GetWaterHeight() - 1; if (water_height > targetHeight) @@ -186,7 +187,7 @@ GameActions::Result SmallSceneryPlaceAction::Query() const } } - if (!GetGameState().Cheats.DisableClearanceChecks && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE))) + if (!gameState.Cheats.DisableClearanceChecks && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE))) { if (isOnWater) { @@ -204,14 +205,13 @@ GameActions::Result SmallSceneryPlaceAction::Query() const } } - if (!GetGameState().Cheats.DisableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE)) + if (!gameState.Cheats.DisableClearanceChecks && (sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_REQUIRE_FLAT_SURFACE)) && !supportsRequired && !isOnWater && surfaceElement != nullptr && (surfaceElement->GetSlope() != kTileSlopeFlat)) { return GameActions::Result(GameActions::Status::Disallowed, STR_CANT_POSITION_THIS_HERE, STR_LEVEL_LAND_REQUIRED); } - if (!GetGameState().Cheats.DisableSupportLimits && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE)) - && supportsRequired) + if (!gameState.Cheats.DisableSupportLimits && !(sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_STACKABLE)) && supportsRequired) { if (!isOnWater) { diff --git a/src/openrct2/actions/SurfaceSetStyleAction.cpp b/src/openrct2/actions/SurfaceSetStyleAction.cpp index a4f92cfa78..64e617c3bd 100644 --- a/src/openrct2/actions/SurfaceSetStyleAction.cpp +++ b/src/openrct2/actions/SurfaceSetStyleAction.cpp @@ -85,9 +85,11 @@ GameActions::Result SurfaceSetStyleAction::Query() const res.Position.y = yMid; res.Position.z = heightMid; + auto& gameState = GetGameState(); + // Do nothing if not in editor, sandbox mode or landscaping is forbidden - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode - && (GetGameState().Park.Flags & PARK_FLAGS_FORBID_LANDSCAPE_CHANGES)) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode + && (gameState.Park.Flags & PARK_FLAGS_FORBID_LANDSCAPE_CHANGES)) { return GameActions::Result( GameActions::Status::Disallowed, STR_CANT_CHANGE_LAND_TYPE, STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY); @@ -103,7 +105,7 @@ GameActions::Result SurfaceSetStyleAction::Query() const if (!LocationValid(coords)) continue; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode) { if (!MapIsLocationInPark(coords)) continue; diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index 500dc38f09..7a5bf2f22b 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -93,7 +93,8 @@ GameActions::Result TrackPlaceAction::Query() const GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_ERR_VALUE_OUT_OF_RANGE); } - if (_rideType != ride->type && !GetGameState().Cheats.AllowArbitraryRideTypeChanges) + auto& gameState = GetGameState(); + if (_rideType != ride->type && !gameState.Cheats.AllowArbitraryRideTypeChanges) { return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_NONE); @@ -131,7 +132,7 @@ GameActions::Result TrackPlaceAction::Query() const if (!(GetActionFlags() & GameActions::Flags::AllowWhilePaused)) { - if (GameIsPaused() && !GetGameState().Cheats.BuildInPauseMode) + if (GameIsPaused() && !gameState.Cheats.BuildInPauseMode) { return GameActions::Result( GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, @@ -161,7 +162,7 @@ GameActions::Result TrackPlaceAction::Query() const } // Backwards steep lift hills are allowed, even on roller coasters that do not support forwards steep lift hills. if ((_trackPlaceFlags & CONSTRUCTION_LIFT_HILL_SELECTED) && !rtd.SupportsTrackGroup(TrackGroup::liftHillSteep) - && !GetGameState().Cheats.EnableChainLiftOnAllTrack) + && !gameState.Cheats.EnableChainLiftOnAllTrack) { const auto& ted = GetTrackElementDescriptor(_trackType); if (ted.flags & TRACK_ELEM_FLAG_IS_STEEP_UP) @@ -187,7 +188,7 @@ GameActions::Result TrackPlaceAction::Query() const return GameActions::Result( GameActions::Status::InvalidParameters, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_OFF_EDGE_OF_MAP); } - if (!MapIsLocationOwned(tileCoords) && !GetGameState().Cheats.SandboxMode) + if (!MapIsLocationOwned(tileCoords) && !gameState.Cheats.SandboxMode) { return GameActions::Result( GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, STR_LAND_NOT_OWNED_BY_PARK); @@ -203,7 +204,7 @@ GameActions::Result TrackPlaceAction::Query() const STR_TILE_ELEMENT_LIMIT_REACHED); } - if (!GetGameState().Cheats.AllowTrackPlaceInvalidHeights) + if (!gameState.Cheats.AllowTrackPlaceInvalidHeights) { if (ted.flags & TRACK_ELEM_FLAG_STARTS_AT_HALF_HEIGHT) { @@ -306,7 +307,7 @@ GameActions::Result TrackPlaceAction::Query() const } } - if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER && !GetGameState().Cheats.DisableClearanceChecks) + if (clearanceData.GroundFlags & ELEMENT_IS_UNDERWATER && !gameState.Cheats.DisableClearanceChecks) { return GameActions::Result( GameActions::Status::Disallowed, STR_RIDE_CONSTRUCTION_CANT_CONSTRUCT_THIS_HERE, @@ -372,7 +373,7 @@ GameActions::Result TrackPlaceAction::Query() const STR_ERR_SURFACE_ELEMENT_NOT_FOUND); } - if (!GetGameState().Cheats.DisableSupportLimits) + if (!gameState.Cheats.DisableSupportLimits) { int32_t ride_height = clearanceZ - surfaceElement->GetBaseZ(); if (ride_height >= 0) @@ -497,7 +498,8 @@ GameActions::Result TrackPlaceAction::Execute() const } } - if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !GetGameState().Cheats.DisableClearanceChecks) + auto& gameState = GetGameState(); + if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !gameState.Cheats.DisableClearanceChecks) { FootpathRemoveLitter(mapLoc); if (rtd.HasFlag(RtdFlag::noWallsAroundTrack)) @@ -629,7 +631,7 @@ GameActions::Result TrackPlaceAction::Execute() const uint32_t availableDirections = entranceDirections & 0x0F; if (availableDirections != 0) { - if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !GetGameState().Cheats.DisableClearanceChecks) + if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST) && !gameState.Cheats.DisableClearanceChecks) { for (int32_t chosenDirection = UtilBitScanForward(availableDirections); chosenDirection != -1; chosenDirection = UtilBitScanForward(availableDirections)) @@ -671,7 +673,7 @@ GameActions::Result TrackPlaceAction::Execute() const } } - if (!GetGameState().Cheats.DisableClearanceChecks || !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) + if (!gameState.Cheats.DisableClearanceChecks || !(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { FootpathConnectEdges(mapLoc, tileElement, GetFlags()); } diff --git a/src/openrct2/actions/WaterRaiseAction.cpp b/src/openrct2/actions/WaterRaiseAction.cpp index 33084aa463..3bd26c4217 100644 --- a/src/openrct2/actions/WaterRaiseAction.cpp +++ b/src/openrct2/actions/WaterRaiseAction.cpp @@ -79,7 +79,7 @@ GameActions::Result WaterRaiseAction::QueryExecute(bool isExecuting) const if (surfaceElement == nullptr) continue; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) { if (!MapIsLocationInPark(CoordsXY{ x, y })) { @@ -151,7 +151,7 @@ uint16_t WaterRaiseAction::GetHighestHeight(const MapRange& validRange) const { for (int32_t x = validRange.GetLeft(); x <= validRange.GetRight(); x += kCoordsXYStep) { - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !OpenRCT2::GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) { if (!MapIsLocationInPark(CoordsXY{ x, y })) { diff --git a/src/openrct2/actions/WaterSetHeightAction.cpp b/src/openrct2/actions/WaterSetHeightAction.cpp index 8e2e5f9e5e..b5922c6912 100644 --- a/src/openrct2/actions/WaterSetHeightAction.cpp +++ b/src/openrct2/actions/WaterSetHeightAction.cpp @@ -49,8 +49,9 @@ GameActions::Result WaterSetHeightAction::Query() const res.Expenditure = ExpenditureType::Landscaping; res.Position = { _coords, _height * kCoordsZStep }; - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode - && GetGameState().Park.Flags & PARK_FLAGS_FORBID_LANDSCAPE_CHANGES) + auto& gameState = GetGameState(); + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode + && gameState.Park.Flags & PARK_FLAGS_FORBID_LANDSCAPE_CHANGES) { return GameActions::Result(GameActions::Status::Disallowed, STR_NONE, STR_FORBIDDEN_BY_THE_LOCAL_AUTHORITY); } @@ -66,7 +67,7 @@ GameActions::Result WaterSetHeightAction::Query() const return GameActions::Result(GameActions::Status::NotOwned, STR_NONE, STR_LAND_NOT_OWNED_BY_PARK); } - if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !GetGameState().Cheats.SandboxMode) + if (!(gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) && !gameState.Cheats.SandboxMode) { if (!MapIsLocationInPark(_coords)) { diff --git a/src/openrct2/drawing/LightFX.cpp b/src/openrct2/drawing/LightFX.cpp index b55c7d3255..7143cb1827 100644 --- a/src/openrct2/drawing/LightFX.cpp +++ b/src/openrct2/drawing/LightFX.cpp @@ -838,7 +838,7 @@ void LightFxAddShopLights(const CoordsXY& mapPosition, const uint8_t direction, void LightFXApplyPaletteFilter(uint8_t i, uint8_t* r, uint8_t* g, uint8_t* b) { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); float night = static_cast(pow(gDayNightCycle, 1.5)); diff --git a/src/openrct2/entity/Guest.cpp b/src/openrct2/entity/Guest.cpp index 73ce6f9362..9a2a58cc24 100644 --- a/src/openrct2/entity/Guest.cpp +++ b/src/openrct2/entity/Guest.cpp @@ -1550,7 +1550,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) if (!hasVoucher) { - if (price != 0 && !(GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY)) + if (price != 0 && !(gameState.Park.Flags & PARK_FLAGS_NO_MONEY)) { if (CashInPocket == 0) { @@ -1597,7 +1597,7 @@ bool Guest::DecideAndBuyItem(Ride& ride, const ShopItem shopItem, money64 price) itemValue -= price; itemValue = std::max(0.80_GBP, itemValue); - if (!(GetGameState().Park.Flags & PARK_FLAGS_NO_MONEY)) + if (!(gameState.Park.Flags & PARK_FLAGS_NO_MONEY)) { if (itemValue >= static_cast(ScenarioRand() & 0x07)) { diff --git a/src/openrct2/entity/Litter.cpp b/src/openrct2/entity/Litter.cpp index 2f1dc3e85d..e544a7ec8c 100644 --- a/src/openrct2/entity/Litter.cpp +++ b/src/openrct2/entity/Litter.cpp @@ -49,7 +49,8 @@ static bool IsLocationLitterable(const CoordsXYZ& mapPos) */ void Litter::Create(const CoordsXYZD& litterPos, Type type) { - if (GetGameState().Cheats.DisableLittering) + auto& gameState = GetGameState(); + if (gameState.Cheats.DisableLittering) return; auto offsetLitterPos = litterPos @@ -89,7 +90,7 @@ void Litter::Create(const CoordsXYZD& litterPos, Type type) litter->SpriteData.HeightMax = 3; litter->SubType = type; litter->MoveTo(offsetLitterPos); - litter->creationTick = GetGameState().CurrentTicks; + litter->creationTick = gameState.CurrentTicks; } /** diff --git a/src/openrct2/entity/Peep.cpp b/src/openrct2/entity/Peep.cpp index 9c66191db6..e821de8423 100644 --- a/src/openrct2/entity/Peep.cpp +++ b/src/openrct2/entity/Peep.cpp @@ -200,7 +200,7 @@ void PeepUpdateAll() if (gScreenFlags & SCREEN_FLAGS_EDITOR) return; - const auto currentTicks = OpenRCT2::GetGameState().CurrentTicks; + const auto currentTicks = GetGameState().CurrentTicks; constexpr auto kTicks128Mask = 128u - 1u; const auto currentTicksMasked = currentTicks & kTicks128Mask; @@ -898,7 +898,7 @@ void Peep::SetState(PeepState new_state) */ void Peep::UpdatePicked() { - if (OpenRCT2::GetGameState().CurrentTicks & 0x1F) + if (GetGameState().CurrentTicks & 0x1F) return; SubState++; auto* guest = As(); diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index f8e91059be..4220040320 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -603,7 +603,8 @@ void AwardUpdateAll() { PROFILED_FUNCTION(); - auto& currentAwards = GetGameState().CurrentAwards; + auto& gameState = GetGameState(); + auto& currentAwards = gameState.CurrentAwards; // Decrease award times for (auto& award : currentAwards) { @@ -619,7 +620,7 @@ void AwardUpdateAll() } // Only add new awards if park is open - if (GetGameState().Park.Flags & PARK_FLAGS_PARK_OPEN) + if (gameState.Park.Flags & PARK_FLAGS_PARK_OPEN) { // Set active award types as flags int32_t activeAwardTypes = 0; diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 887e23342a..c4abf1a5e3 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -324,7 +324,7 @@ void FinanceShiftExpenditureTable() std::cbegin(gameState.ExpenditureTable[kExpenditureTableMonthCount - 1]), std::cend(gameState.ExpenditureTable[kExpenditureTableMonthCount - 1]), money64{}); - GetGameState().HistoricalProfit += sum; + gameState.HistoricalProfit += sum; } // Shift the table diff --git a/src/openrct2/network/DiscordService.cpp b/src/openrct2/network/DiscordService.cpp index b3a7375a71..9599712e50 100644 --- a/src/openrct2/network/DiscordService.cpp +++ b/src/openrct2/network/DiscordService.cpp @@ -66,7 +66,7 @@ DiscordService::~DiscordService() static std::string GetParkName() { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); return gameState.Park.Name; } diff --git a/src/openrct2/paint/tile_element/Paint.Entrance.cpp b/src/openrct2/paint/tile_element/Paint.Entrance.cpp index d5df5efd69..a5c4e5690a 100644 --- a/src/openrct2/paint/tile_element/Paint.Entrance.cpp +++ b/src/openrct2/paint/tile_element/Paint.Entrance.cpp @@ -221,9 +221,10 @@ static void PaintParkEntranceScrollingText( return; auto ft = Formatter(); - if (GetGameState().Park.Flags & PARK_FLAGS_PARK_OPEN) + auto& gameState = GetGameState(); + if (gameState.Park.Flags & PARK_FLAGS_PARK_OPEN) { - const auto& park = OpenRCT2::GetGameState().Park; + const auto& park = gameState.Park; auto name = park.Name.c_str(); ft.Add(STR_STRING); ft.Add(name); @@ -245,7 +246,7 @@ static void PaintParkEntranceScrollingText( } auto stringWidth = GfxGetStringWidth(text, FontStyle::Tiny); - auto scroll = stringWidth > 0 ? (GetGameState().CurrentTicks / 2) % stringWidth : 0; + auto scroll = stringWidth > 0 ? (gameState.CurrentTicks / 2) % stringWidth : 0; auto imageIndex = ScrollingTextSetup( session, STR_BANNER_TEXT_FORMAT, ft, scroll, scrollingMode + direction / 2, COLOUR_BLACK); auto textHeight = height + entrance.GetTextHeight(); diff --git a/src/openrct2/ride/Ride.cpp b/src/openrct2/ride/Ride.cpp index 1d0f629d96..320f7e8936 100644 --- a/src/openrct2/ride/Ride.cpp +++ b/src/openrct2/ride/Ride.cpp @@ -1396,7 +1396,8 @@ static int32_t GetAgePenalty(const Ride& ride) */ static void RideBreakdownUpdate(Ride& ride) { - const auto currentTicks = GetGameState().CurrentTicks; + auto& gameState = GetGameState(); + const auto currentTicks = gameState.CurrentTicks; if (currentTicks & 255) return; @@ -1450,7 +1451,7 @@ static void RideBreakdownUpdate(Ride& ride) // continues. if ((ride.reliability == 0 || static_cast(ScenarioRand() & 0x2FFFFF) <= 1u + kRideInitialReliability - ride.reliability) - && !GetGameState().Cheats.DisableAllBreakdowns) + && !gameState.Cheats.DisableAllBreakdowns) { int32_t breakdownReason = RideGetNewBreakdownProblem(ride); if (breakdownReason != -1) diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index c612470228..a74e0578a6 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -208,7 +208,7 @@ void ScenarioSuccess(GameState_t& gameState) if (ScenarioRepositoryTryRecordHighscore(gScenarioFileName.c_str(), companyValue, nullptr)) { // Allow name entry - GetGameState().Park.Flags |= PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT; + gameState.Park.Flags |= PARK_FLAGS_SCENARIO_COMPLETE_NAME_INPUT; gameState.ScenarioCompanyValueRecord = companyValue; } ScenarioEnd(); @@ -600,7 +600,7 @@ ResultWithMessage ScenarioPrepareForSave(GameState_t& gameState) } if (gameState.ScenarioObjective.Type == OBJECTIVE_GUESTS_AND_RATING) - GetGameState().Park.Flags |= PARK_FLAGS_PARK_OPEN; + gameState.Park.Flags |= PARK_FLAGS_PARK_OPEN; ScenarioReset(gameState); diff --git a/src/openrct2/scripting/bindings/entity/ScGuest.cpp b/src/openrct2/scripting/bindings/entity/ScGuest.cpp index ac86f9d32b..c144ff394a 100644 --- a/src/openrct2/scripting/bindings/entity/ScGuest.cpp +++ b/src/openrct2/scripting/bindings/entity/ScGuest.cpp @@ -539,8 +539,9 @@ namespace OpenRCT2::Scripting auto peep = GetGuest(); if (peep != nullptr) { - if (value.type() == DukValue::Type::NUMBER && value.as_uint() < GetGameState().Rides.size() - && GetGameState().Rides[value.as_uint()].type != RIDE_TYPE_NULL) + auto& gameState = GetGameState(); + if (value.type() == DukValue::Type::NUMBER && value.as_uint() < gameState.Rides.size() + && gameState.Rides[value.as_uint()].type != RIDE_TYPE_NULL) { peep->FavouriteRide = RideId::FromUnderlying(value.as_uint()); } diff --git a/src/openrct2/scripting/bindings/world/ScClimate.hpp b/src/openrct2/scripting/bindings/world/ScClimate.hpp index 4fc3ab8c05..7940aa4626 100644 --- a/src/openrct2/scripting/bindings/world/ScClimate.hpp +++ b/src/openrct2/scripting/bindings/world/ScClimate.hpp @@ -101,20 +101,20 @@ namespace OpenRCT2::Scripting std::string type_get() const { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); return ClimateTypeToString(gameState.Climate); } std::shared_ptr current_get() const { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); std::string weatherType = WeatherTypeToString(gameState.ClimateCurrent.Weather); return std::make_shared(weatherType, gameState.ClimateCurrent.Temperature); } std::shared_ptr future_get() const { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); std::string weatherType = WeatherTypeToString(gameState.ClimateNext.Weather); return std::make_shared(weatherType, gameState.ClimateNext.Temperature); } diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 030e32a20d..0a712e6bd0 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -652,7 +652,7 @@ static void Loc6A6D7E( FootpathNeighbourList* neighbourList) { auto targetPos = CoordsXY{ initialTileElementPos } + CoordsDirectionDelta[direction]; - if (((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode) && MapIsEdge(targetPos)) + if (((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode) && MapIsEdge(targetPos)) { if (query) { @@ -2180,7 +2180,7 @@ void FootpathRemoveEdgesAt(const CoordsXY& footpathPos, TileElement* tileElement static ObjectEntryIndex FootpathGetDefaultSurface(bool queue) { - bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode); + bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode); for (ObjectEntryIndex i = 0; i < kMaxFootpathSurfaceObjects; i++) { auto pathEntry = GetPathSurfaceEntry(i); @@ -2204,7 +2204,7 @@ static bool FootpathIsSurfaceEntryOkay(ObjectEntryIndex index, bool queue) auto pathEntry = GetPathSurfaceEntry(index); if (pathEntry != nullptr) { - bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode); + bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode); if (!showEditorPaths && (pathEntry->Flags & FOOTPATH_ENTRY_FLAG_SHOW_ONLY_IN_SCENARIO_EDITOR)) { return false; @@ -2232,7 +2232,7 @@ static ObjectEntryIndex FootpathGetDefaultRailings() static bool FootpathIsLegacyPathEntryOkay(ObjectEntryIndex index) { - bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || OpenRCT2::GetGameState().Cheats.SandboxMode); + bool showEditorPaths = ((gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR) || GetGameState().Cheats.SandboxMode); auto& objManager = OpenRCT2::GetContext()->GetObjectManager(); auto footpathObj = static_cast(objManager.GetLoadedObject(ObjectType::Paths, index)); if (footpathObj != nullptr) diff --git a/src/openrct2/world/Map.cpp b/src/openrct2/world/Map.cpp index 7d46c276fd..78cda3cd4e 100644 --- a/src/openrct2/world/Map.cpp +++ b/src/openrct2/world/Map.cpp @@ -113,7 +113,7 @@ void StashMap() auto& gameState = GetGameState(); _tileIndexStash = std::move(_tileIndex); _tileElementsStash = std::move(gameState.TileElements); - _mapSizeStash = GetGameState().MapSize; + _mapSizeStash = gameState.MapSize; _tileElementsInUseStash = _tileElementsInUse; } @@ -122,18 +122,18 @@ void UnstashMap() auto& gameState = GetGameState(); _tileIndex = std::move(_tileIndexStash); gameState.TileElements = std::move(_tileElementsStash); - GetGameState().MapSize = _mapSizeStash; + gameState.MapSize = _mapSizeStash; _tileElementsInUse = _tileElementsInUseStash; } CoordsXY GetMapSizeUnits() { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); return { (gameState.MapSize.x - 1) * kCoordsXYStep, (gameState.MapSize.y - 1) * kCoordsXYStep }; } CoordsXY GetMapSizeMinus2() { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); return { (gameState.MapSize.x * kCoordsXYStep) + (8 * kCoordsXYStep - 2), (gameState.MapSize.y * kCoordsXYStep) + (8 * kCoordsXYStep - 2) }; } @@ -1351,8 +1351,9 @@ void MapRemoveOutOfRangeElements() // NOTE: This is only a workaround for non-networked games. // Map resize has to become its own Game Action to properly solve this issue. // - bool buildState = GetGameState().Cheats.BuildInPauseMode; - GetGameState().Cheats.BuildInPauseMode = true; + auto& gameState = GetGameState(); + bool buildState = gameState.Cheats.BuildInPauseMode; + gameState.Cheats.BuildInPauseMode = true; for (int32_t y = MAXIMUM_MAP_SIZE_BIG - kCoordsXYStep; y >= 0; y -= kCoordsXYStep) { @@ -1373,7 +1374,7 @@ void MapRemoveOutOfRangeElements() } // Reset cheat state - GetGameState().Cheats.BuildInPauseMode = buildState; + gameState.Cheats.BuildInPauseMode = buildState; } static void MapExtendBoundarySurfaceExtendTile(const SurfaceElement& sourceTile, SurfaceElement& destTile) diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index f783371e9f..42e5c3a2dd 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -337,7 +337,7 @@ static void MapGenPlaceTrees() // Place trees CoordsXY pos; float treeToLandRatio = (10 + (UtilRand() % 30)) / 100.0f; - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); for (int32_t y = 1; y < gameState.MapSize.y - 1; y++) { for (int32_t x = 1; x < gameState.MapSize.x - 1; x++) @@ -418,7 +418,7 @@ static void MapGenPlaceTrees() */ static void MapGenSetWaterLevel(int32_t waterLevel) { - auto& gameState = OpenRCT2::GetGameState(); + auto& gameState = GetGameState(); for (int32_t y = 1; y < gameState.MapSize.y - 1; y++) { for (int32_t x = 1; x < gameState.MapSize.x - 1; x++) diff --git a/src/openrct2/world/Scenery.cpp b/src/openrct2/world/Scenery.cpp index f9e5c02c5f..6d97773c45 100644 --- a/src/openrct2/world/Scenery.cpp +++ b/src/openrct2/world/Scenery.cpp @@ -176,13 +176,14 @@ void SmallSceneryElement::UpdateAge(const CoordsXY& sceneryPos) return; } - if (OpenRCT2::GetGameState().Cheats.DisablePlantAging && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED)) + auto& gameState = GetGameState(); + if (gameState.Cheats.DisablePlantAging && sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED)) { return; } - if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED) - || WeatherIsDry(OpenRCT2::GetGameState().ClimateCurrent.Weather) || GetAge() < 5) + if (!sceneryEntry->HasFlag(SMALL_SCENERY_FLAG_CAN_BE_WATERED) || WeatherIsDry(gameState.ClimateCurrent.Weather) + || GetAge() < 5) { IncreaseAge(sceneryPos); return; @@ -311,7 +312,8 @@ bool IsSceneryAvailableToBuild(const ScenerySelection& item) return true; } - if (!OpenRCT2::GetGameState().Cheats.IgnoreResearchStatus) + auto& gameState = GetGameState(); + if (!gameState.Cheats.IgnoreResearchStatus) { if (!SceneryIsInvented(item)) { @@ -319,7 +321,7 @@ bool IsSceneryAvailableToBuild(const ScenerySelection& item) } } - if (!OpenRCT2::GetGameState().Cheats.SandboxMode && !(gScreenFlags & SCREEN_FLAGS_EDITOR)) + if (!gameState.Cheats.SandboxMode && !(gScreenFlags & SCREEN_FLAGS_EDITOR)) { if (IsSceneryItemRestricted(item)) {