diff --git a/src/openrct2/Date.cpp b/src/openrct2/Date.cpp index 2f9e87c616..8ea9fea9f7 100644 --- a/src/openrct2/Date.cpp +++ b/src/openrct2/Date.cpp @@ -157,5 +157,16 @@ void DateUpdateRealTimeOfDay() Date& GetDate() { - return OpenRCT2::GetContext()->GetGameState()->GetDate(); + return GetGameState().Date; +} + +/** + * + * rct2: 0x006C4494 + */ +void ResetDate() +{ + auto& gameState = GetGameState(); + gameState.Date = OpenRCT2::Date(); + gCurrentRealTimeTicks = 0; } diff --git a/src/openrct2/Date.h b/src/openrct2/Date.h index 85cc1017ca..e3447e80c4 100644 --- a/src/openrct2/Date.h +++ b/src/openrct2/Date.h @@ -86,6 +86,8 @@ struct RealWorldTime }; OpenRCT2::Date& GetDate(); +void ResetDate(); + extern RealWorldTime gRealTimeOfDay; int32_t DateGetMonth(int32_t months); diff --git a/src/openrct2/GameState.cpp b/src/openrct2/GameState.cpp index d6a11d58ed..72eb352a8b 100644 --- a/src/openrct2/GameState.cpp +++ b/src/openrct2/GameState.cpp @@ -317,15 +317,15 @@ void GameState::UpdateLogic() } } + 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. - auto day = _date.GetDay(); + auto day = gameState.Date.GetDay(); #endif - _date.Update(); + gameState.Date.Update(); - auto& gameState = GetGameState(); ScenarioUpdate(gameState); ClimateUpdate(); MapUpdateTiles(); @@ -340,7 +340,7 @@ void GameState::UpdateLogic() if (!(gScreenFlags & SCREEN_FLAGS_EDITOR)) { - _park->Update(_date); + _park->Update(gameState.Date); } ResearchUpdate(); @@ -374,7 +374,7 @@ void GameState::UpdateLogic() auto& hookEngine = GetContext()->GetScriptEngine().GetHookEngine(); hookEngine.Call(HOOK_TYPE::INTERVAL_TICK, true); - if (day != _date.GetDay()) + if (day != gameState.Date.GetDay()) { hookEngine.Call(HOOK_TYPE::INTERVAL_DAY, true); } @@ -394,17 +394,3 @@ void GameState::CreateStateSnapshot() snapshots->LinkSnapshot(snapshot, GetGameState().CurrentTicks, ScenarioRandState().s0); } -void GameState::SetDate(Date newDate) -{ - _date = newDate; -} - -/** - * - * rct2: 0x006C4494 - */ -void GameState::ResetDate() -{ - _date = OpenRCT2::Date(); - gCurrentRealTimeTicks = 0; -} diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index 3a6538e627..a5a6180ddf 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -39,6 +39,7 @@ namespace OpenRCT2 struct GameState_t { uint32_t CurrentTicks{}; + ::OpenRCT2::Date Date; uint64_t ParkFlags; uint16_t ParkRating; money64 ParkEntranceFee; @@ -163,16 +164,11 @@ namespace OpenRCT2 { private: std::unique_ptr _park; - Date _date; public: GameState(); GameState(const GameState&) = delete; - Date& GetDate() - { - return _date; - } Park& GetPark() { return *_park; @@ -181,8 +177,6 @@ namespace OpenRCT2 void InitAll(const TileCoordsXY& mapSize); void Tick(); void UpdateLogic(); - void SetDate(Date newDate); - void ResetDate(); private: void CreateStateSnapshot(); diff --git a/src/openrct2/actions/ParkSetDateAction.cpp b/src/openrct2/actions/ParkSetDateAction.cpp index fdd0ab99ef..7f82953bbb 100644 --- a/src/openrct2/actions/ParkSetDateAction.cpp +++ b/src/openrct2/actions/ParkSetDateAction.cpp @@ -18,6 +18,8 @@ #include "../ui/WindowManager.h" #include "../windows/Intent.h" +using namespace OpenRCT2; + ParkSetDateAction::ParkSetDateAction(int32_t year, int32_t month, int32_t day) : _year(year) , _month(month) @@ -69,6 +71,7 @@ GameActions::Result ParkSetDateAction::Query() const GameActions::Result ParkSetDateAction::Execute() const { - OpenRCT2::GetContext()->GetGameState()->SetDate(OpenRCT2::Date::FromYMD(_year, _month, _day)); + auto& gameState = GetGameState(); + gameState.Date = OpenRCT2::Date::FromYMD(_year, _month, _day); return GameActions::Result(); } diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index fe205516e6..134c6b1009 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -488,8 +488,7 @@ namespace OpenRCT2 uint32_t monthsElapsed; cs.ReadWrite(monthTicks); cs.ReadWrite(monthsElapsed); - // TODO: Use the passed gameState instead of the global one. - GetContext()->GetGameState()->SetDate(Date(monthsElapsed, monthTicks)); + gameState.Date = Date(monthsElapsed, monthTicks); } else { diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index 69ebdcaff1..378a711eba 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -2145,7 +2145,7 @@ namespace RCT1 // Date and srand gameState.CurrentTicks = _s4.Ticks; ScenarioRandSeed(_s4.RandomA, _s4.RandomB); - GetContext()->GetGameState()->SetDate(Date(_s4.Month, _s4.Day)); + gameState.Date = Date(_s4.Month, _s4.Day); // Park rating gameState.ParkRating = _s4.ParkRating; diff --git a/src/openrct2/rct2/S6Importer.cpp b/src/openrct2/rct2/S6Importer.cpp index 94373ba570..3e12ee3b7d 100644 --- a/src/openrct2/rct2/S6Importer.cpp +++ b/src/openrct2/rct2/S6Importer.cpp @@ -251,7 +251,7 @@ namespace RCT2 gameState.ScenarioDetails = loadMaybeUTF8(_s6.ScenarioDescription); } - OpenRCT2::GetContext()->GetGameState()->SetDate(OpenRCT2::Date(_s6.ElapsedMonths, _s6.CurrentDay)); + gameState.Date = OpenRCT2::Date(_s6.ElapsedMonths, _s6.CurrentDay); gameState.CurrentTicks = _s6.GameTicks1; ScenarioRandSeed(_s6.ScenarioSrand0, _s6.ScenarioSrand1); diff --git a/src/openrct2/scenario/Scenario.cpp b/src/openrct2/scenario/Scenario.cpp index b46897c785..aaec8425df 100644 --- a/src/openrct2/scenario/Scenario.cpp +++ b/src/openrct2/scenario/Scenario.cpp @@ -149,7 +149,7 @@ void ScenarioReset(GameState_t& gameState) FinanceResetHistory(); AwardReset(); ResetAllRideBuildDates(); - GetContext()->GetGameState()->ResetDate(); + ResetDate(); Duck::RemoveAll(); ParkCalculateSize(); MapCountRemainingLandRights(); diff --git a/src/openrct2/scripting/bindings/world/ScDate.hpp b/src/openrct2/scripting/bindings/world/ScDate.hpp index 965faf4052..491272e411 100644 --- a/src/openrct2/scripting/bindings/world/ScDate.hpp +++ b/src/openrct2/scripting/bindings/world/ScDate.hpp @@ -46,7 +46,7 @@ namespace OpenRCT2::Scripting void monthsElapsed_set(int32_t value) { ThrowIfGameStateNotMutable(); - GetContext()->GetGameState()->SetDate(Date(value, GetDate().GetMonthTicks())); + GetGameState().Date = Date(value, GetDate().GetMonthTicks()); } uint32_t monthProgress_get() const @@ -58,7 +58,7 @@ namespace OpenRCT2::Scripting void monthProgress_set(int32_t value) { ThrowIfGameStateNotMutable(); - GetContext()->GetGameState()->SetDate(Date(GetDate().GetMonthsElapsed(), value)); + GetGameState().Date = Date(GetDate().GetMonthsElapsed(), value); } uint32_t yearsElapsed_get() const @@ -74,27 +74,17 @@ namespace OpenRCT2::Scripting int32_t day_get() const { - const auto& date = GetDate(); - return date.GetDay() + 1; + return GetGameState().Date.GetDay() + 1; } int32_t month_get() const { - const auto& date = GetDate(); - return date.GetMonth(); + return GetGameState().Date.GetMonth(); } int32_t year_get() const { - const auto& date = GetDate(); - return date.GetYear() + 1; - } - - private: - const Date& GetDate() const - { - auto gameState = GetContext()->GetGameState(); - return gameState->GetDate(); + return GetGameState().Date.GetYear() + 1; } }; } // namespace OpenRCT2::Scripting diff --git a/test/tests/MultiLaunch.cpp b/test/tests/MultiLaunch.cpp index 00f65b9e06..83451d6ab3 100644 --- a/test/tests/MultiLaunch.cpp +++ b/test/tests/MultiLaunch.cpp @@ -48,7 +48,7 @@ TEST(MultiLaunchTest, all) auto gs = context->GetGameState(); ASSERT_NE(gs, nullptr); - auto& date = gs->GetDate(); + auto& date = GetGameState().Date; // NOTE: This value is saved in the SV6 file, after the import this will be the current state. // In case the save file gets replaced this needs to be adjusted. ASSERT_EQ(date.GetMonthTicks(), 0x1e98);