From 53a77b02b5def55c6fb7e7e36256de5034a0319c Mon Sep 17 00:00:00 2001 From: Harry Hopkinson Date: Fri, 22 Mar 2024 20:23:33 +0000 Subject: [PATCH 1/3] Save following entity into save file --- distribution/changelog.txt | 1 + src/openrct2/Game.cpp | 6 ++++++ src/openrct2/GameState.h | 1 + src/openrct2/interface/Window.cpp | 2 ++ src/openrct2/park/ParkFile.cpp | 8 +++++++- src/openrct2/park/ParkFile.h | 2 +- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 4d8471264d92..f26493ec5115 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -103,6 +103,7 @@ 0.4.11 (2024-05-05) ------------------------------------------------------------------------ - Feature: [#11512] Coloured usernames by group on multiplayer servers. +- Feature: [#21656] Save the currently following entity into the save file. - Feature: [#21734] Park admittance price can now be set via text input. - Feature: [#21957] [Plugin] Expose whether the game is paused to the plugin API. - Improved: [#21728] “Fix all rides” cheat now also works if a mechanic is already fixing the ride. diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 5ef61ffbb1be..4eebe4f4ebd3 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -363,6 +363,12 @@ void GameLoadInit() auto& gameState = GetGameState(); windowManager->SetMainView(gameState.SavedView, gameState.SavedViewZoom, gameState.SavedViewRotation); + if (gameState.CurrentlyFollowingEntity != EntityId::GetNull()) + { + auto* mainWindow = WindowGetMain(); + WindowFollowSprite(*mainWindow, gameState.CurrentlyFollowingEntity); + } + if (NetworkGetMode() != NETWORK_MODE_CLIENT) { GameActions::ClearQueue(); diff --git a/src/openrct2/GameState.h b/src/openrct2/GameState.h index bcf3db304e67..2145397481c3 100644 --- a/src/openrct2/GameState.h +++ b/src/openrct2/GameState.h @@ -127,6 +127,7 @@ namespace OpenRCT2 ScreenCoordsXY SavedView; uint8_t SavedViewRotation; ZoomLevel SavedViewZoom; + EntityId CurrentlyFollowingEntity{ EntityId::GetNull() }; ObjectEntryIndex LastEntranceStyle; diff --git a/src/openrct2/interface/Window.cpp b/src/openrct2/interface/Window.cpp index dcd3dc2b21b0..53cc3b84c816 100644 --- a/src/openrct2/interface/Window.cpp +++ b/src/openrct2/interface/Window.cpp @@ -1412,6 +1412,7 @@ void WindowFollowSprite(WindowBase& w, EntityId spriteIndex) if (spriteIndex.ToUnderlying() < MAX_ENTITIES || spriteIndex.IsNull()) { w.viewport_smart_follow_sprite = spriteIndex; + GetGameState().CurrentlyFollowingEntity = spriteIndex; } } @@ -1419,6 +1420,7 @@ void WindowUnfollowSprite(WindowBase& w) { w.viewport_smart_follow_sprite = EntityId::GetNull(); w.viewport_target_sprite = EntityId::GetNull(); + GetGameState().CurrentlyFollowingEntity = EntityId::GetNull(); } Viewport* WindowGetViewport(WindowBase* w) diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index 8edbc2d9bbfe..d8377459981f 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -600,7 +600,7 @@ namespace OpenRCT2 void ReadWriteInterfaceChunk(GameState_t& gameState, OrcaStream& os) { - os.ReadWriteChunk(ParkFileChunkType::INTERFACE, [&gameState](OrcaStream::ChunkStream& cs) { + os.ReadWriteChunk(ParkFileChunkType::INTERFACE, [&gameState, &os](OrcaStream::ChunkStream& cs) { cs.ReadWrite(gameState.SavedView.x); cs.ReadWrite(gameState.SavedView.y); if (cs.GetMode() == OrcaStream::Mode::READING) @@ -613,6 +613,12 @@ namespace OpenRCT2 cs.Write(static_cast(gameState.SavedViewZoom)); } cs.ReadWrite(gameState.SavedViewRotation); + + if (os.GetHeader().TargetVersion >= PARK_FILE_CURRENT_VERSION) + cs.ReadWrite(gameState.CurrentlyFollowingEntity); + else + gameState.CurrentlyFollowingEntity = EntityId::GetNull(); + cs.ReadWrite(gameState.LastEntranceStyle); cs.ReadWrite(gameState.EditorStep); }); diff --git a/src/openrct2/park/ParkFile.h b/src/openrct2/park/ParkFile.h index da6bf79e7cda..271c6de496f8 100644 --- a/src/openrct2/park/ParkFile.h +++ b/src/openrct2/park/ParkFile.h @@ -14,7 +14,7 @@ namespace OpenRCT2 constexpr uint32_t PARK_FILE_CURRENT_VERSION = 34; // The minimum version that is forwards compatible with the current version. - constexpr uint32_t PARK_FILE_MIN_VERSION = 33; + constexpr uint32_t PARK_FILE_MIN_VERSION = 34; // The minimum version that is backwards compatible with the current version. // If this is increased beyond 0, uncomment the checks in ParkFile.cpp and Context.cpp! From a040c7c6d18b76b782f5eb15c2da264c76af6d71 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson Date: Sun, 19 May 2024 15:50:50 +0100 Subject: [PATCH 2/3] Add changelog entry --- distribution/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index f26493ec5115..83203573e8b6 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -45,6 +45,7 @@ ------------------------------------------------------------------------ - Feature: [#622] Add option to align the top toolbar buttons horizontally centred (off by default). - Feature: [#20263] Ability to increase the size of the map in the (0, 0) direction. +- Feature: [#21656] Save the currently following entity into the save file. - Feature: [#21714] [Plugin] Costume assignment is now tailored to each staff type. - Feature: [#21853] Enlarged UI mode. - Feature: [#21893, #22065] On launch, the game now indicates what system is being initialised. @@ -103,7 +104,6 @@ 0.4.11 (2024-05-05) ------------------------------------------------------------------------ - Feature: [#11512] Coloured usernames by group on multiplayer servers. -- Feature: [#21656] Save the currently following entity into the save file. - Feature: [#21734] Park admittance price can now be set via text input. - Feature: [#21957] [Plugin] Expose whether the game is paused to the plugin API. - Improved: [#21728] “Fix all rides” cheat now also works if a mechanic is already fixing the ride. From bff8697dc138520e913284c8364f68f767b8e341 Mon Sep 17 00:00:00 2001 From: Harry Hopkinson Date: Sat, 3 Aug 2024 14:34:01 +0100 Subject: [PATCH 3/3] Change ParkFileVersion for explicit number. --- src/openrct2/park/ParkFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/park/ParkFile.cpp b/src/openrct2/park/ParkFile.cpp index d8377459981f..927590788be1 100644 --- a/src/openrct2/park/ParkFile.cpp +++ b/src/openrct2/park/ParkFile.cpp @@ -614,7 +614,7 @@ namespace OpenRCT2 } cs.ReadWrite(gameState.SavedViewRotation); - if (os.GetHeader().TargetVersion >= PARK_FILE_CURRENT_VERSION) + if (os.GetHeader().TargetVersion >= 34) cs.ReadWrite(gameState.CurrentlyFollowingEntity); else gameState.CurrentlyFollowingEntity = EntityId::GetNull();