Skip to content

Commit

Permalink
Feature #21426: Save followed entity.
Browse files Browse the repository at this point in the history
Feature #21426: Save followed entity.

Bump PARK_FILE_CURRENT_VERSION.
  • Loading branch information
Harry-Hopkinson committed Mar 22, 2024
1 parent a972d23 commit 7a7d775
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/openrct2/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,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();
Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/GameState.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Date.h"
#include "Editor.h"
#include "Limits.h"
#include "entity/EntityRegistry.h"
#include "interface/ZoomLevel.h"
#include "management/Award.h"
#include "management/Finance.h"
Expand Down Expand Up @@ -133,6 +134,7 @@ namespace OpenRCT2
ScreenCoordsXY SavedView;
uint8_t SavedViewRotation;
ZoomLevel SavedViewZoom;
EntityId CurrentlyFollowingEntity{ EntityId::GetNull() };

ObjectEntryIndex LastEntranceStyle;

Expand Down
2 changes: 2 additions & 0 deletions src/openrct2/interface/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1822,13 +1822,15 @@ void WindowFollowSprite(WindowBase& w, EntityId spriteIndex)
if (spriteIndex.ToUnderlying() < MAX_ENTITIES || spriteIndex.IsNull())
{
w.viewport_smart_follow_sprite = spriteIndex;
GetGameState().CurrentlyFollowingEntity = spriteIndex;
}
}

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)
Expand Down
8 changes: 7 additions & 1 deletion src/openrct2/park/ParkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,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)
Expand All @@ -617,6 +617,12 @@ namespace OpenRCT2
cs.Write(static_cast<int8_t>(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);
});
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/park/ParkFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OpenRCT2
struct GameState_t;

// Current version that is saved.
constexpr uint32_t PARK_FILE_CURRENT_VERSION = 33;
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;
Expand Down

0 comments on commit 7a7d775

Please sign in to comment.