1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-15 11:03:00 +01:00

Initial park save preview implementation

This commit is contained in:
Aaron van Geffen
2025-02-18 15:48:57 +01:00
parent 225d3bda2c
commit f4809291cb
8 changed files with 130 additions and 1 deletions

View File

@@ -23,6 +23,7 @@ namespace OpenRCT2
{
struct IStream;
struct GameState_t;
struct ParkPreview;
} // namespace OpenRCT2
struct ScenarioIndexEntry;
@@ -58,6 +59,7 @@ public:
virtual void Import(OpenRCT2::GameState_t& gameState) = 0;
virtual bool PopulateIndexEntry(ScenarioIndexEntry* dst) = 0;
virtual OpenRCT2::ParkPreview GetParkPreview() = 0;
};
namespace OpenRCT2::ParkImporter

View File

@@ -391,6 +391,7 @@
<ClInclude Include="ParkImporter.h" />
<ClInclude Include="park\Legacy.h" />
<ClInclude Include="park\ParkFile.h" />
<ClInclude Include="park\ParkPreview.h" />
<ClInclude Include="peep\Guest.h" />
<ClInclude Include="peep\GuestPathfinding.h" />
<ClInclude Include="peep\PeepAnimations.h" />
@@ -1014,6 +1015,7 @@
<ClCompile Include="ParkImporter.cpp" />
<ClCompile Include="park\Legacy.cpp" />
<ClCompile Include="park\ParkFile.cpp" />
<ClCompile Include="park\ParkPreview.cpp" />
<ClCompile Include="peep\GuestPathfinding.cpp" />
<ClCompile Include="peep\PeepAnimations.cpp" />
<ClCompile Include="peep\PeepThoughts.cpp" />

View File

@@ -59,6 +59,7 @@
#include "../world/tile_element/SmallSceneryElement.h"
#include "../world/tile_element/TrackElement.h"
#include "Legacy.h"
#include "ParkPreview.h"
#include <cassert>
#include <cstdint>
@@ -94,6 +95,7 @@ namespace OpenRCT2
constexpr uint32_t CHEATS = 0x36;
constexpr uint32_t RESTRICTED_OBJECTS = 0x37;
constexpr uint32_t PLUGIN_STORAGE = 0x38;
constexpr uint32_t PREVIEW = 0x39;
constexpr uint32_t PACKED_OBJECTS = 0x80;
// clang-format on
}; // namespace ParkFileChunkType
@@ -196,6 +198,7 @@ namespace OpenRCT2
ReadWriteCheatsChunk(gameState, os);
ReadWriteRestrictedObjectsChunk(gameState, os);
ReadWritePluginStorageChunk(gameState, os);
ReadWritePreviewChunk(gameState, os);
ReadWritePackedObjectsChunk(os);
}
@@ -235,6 +238,24 @@ namespace OpenRCT2
return entry;
}
ParkPreview ReadPreviewChunk()
{
ParkPreview preview{};
auto& os = *_os;
os.ReadWriteChunk(ParkFileChunkType::PREVIEW, [&preview](OrcaStream::ChunkStream& cs) {
cs.ReadWrite(preview.parkName);
cs.ReadWrite(preview.parkRating);
cs.ReadWrite(preview.year);
cs.ReadWrite(preview.month);
cs.ReadWrite(preview.day);
cs.ReadWrite(preview.parkUsesMoney);
cs.ReadWrite(preview.cash);
cs.ReadWrite(preview.numRides);
cs.ReadWrite(preview.numGuests);
});
return preview;
}
private:
static uint8_t GetMinCarsPerTrain(uint8_t value)
{
@@ -477,6 +498,23 @@ namespace OpenRCT2
});
}
void ReadWritePreviewChunk(GameState_t& gameState, OrcaStream& os)
{
os.ReadWriteChunk(ParkFileChunkType::PREVIEW, [&gameState](OrcaStream::ChunkStream& cs) {
auto preview = OpenRCT2::generatePreviewFromGameState(gameState);
cs.ReadWrite(preview.parkName);
cs.ReadWrite(preview.parkRating);
cs.ReadWrite(preview.year);
cs.ReadWrite(preview.month);
cs.ReadWrite(preview.day);
cs.ReadWrite(preview.parkUsesMoney);
cs.ReadWrite(preview.cash);
cs.ReadWrite(preview.numRides);
cs.ReadWrite(preview.numGuests);
});
}
void ReadWriteGeneralChunk(GameState_t& gameState, OrcaStream& os)
{
const auto version = os.GetHeader().TargetVersion;
@@ -2745,6 +2783,11 @@ public:
*dst = _parkFile->ReadScenarioChunk();
return true;
}
ParkPreview GetParkPreview() override
{
return _parkFile->ReadPreviewChunk();
}
};
std::unique_ptr<IParkImporter> ParkImporter::CreateParkFile(IObjectRepository& objectRepository)

View File

@@ -20,7 +20,7 @@ namespace OpenRCT2
struct GameState_t;
// Current version that is saved.
constexpr uint32_t kParkFileCurrentVersion = 51;
constexpr uint32_t kParkFileCurrentVersion = 52;
// The minimum version that is forwards compatible with the current version.
constexpr uint32_t kParkFileMinVersion = 51;
@@ -48,6 +48,7 @@ namespace OpenRCT2
constexpr uint16_t kExtendedStandUpRollerCoasterVersion = 48;
constexpr uint16_t kPeepAnimationObjectsVersion = 49;
constexpr uint16_t kDiagonalLongFlatToSteepAndDiveLoopVersion = 50;
constexpr uint16_t kEmbeddedParkPreviewChunk = 52;
} // namespace OpenRCT2
class ParkFileExporter

View File

@@ -0,0 +1,34 @@
/*****************************************************************************
* Copyright (c) 2014-2025 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#include "ParkPreview.h"
#include "../Context.h"
#include "../GameState.h"
#include "../ride/RideManager.hpp"
namespace OpenRCT2
{
ParkPreview generatePreviewFromGameState(const GameState_t& gameState)
{
ParkPreview preview{
.parkName = gameState.Park.Name,
.parkRating = gameState.Park.Rating,
.year = gameState.Date.GetYear(),
.month = gameState.Date.GetMonth(),
.day = gameState.Date.GetDay(),
.parkUsesMoney = !(gameState.Park.Flags & PARK_FLAGS_NO_MONEY),
.cash = gameState.Cash,
.numRides = static_cast<uint16_t>(RideManager().size()),
.numGuests = static_cast<uint16_t>(gameState.NumGuestsInPark),
};
return preview;
}
} // namespace OpenRCT2

View File

@@ -0,0 +1,35 @@
/*****************************************************************************
* Copyright (c) 2014-2025 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "../core/Money.hpp"
#include <cstdint>
#include <string>
namespace OpenRCT2
{
struct ParkPreview
{
std::string parkName{};
uint16_t parkRating{};
int32_t year{};
int32_t month{};
int32_t day{};
bool parkUsesMoney{ true };
money64 cash{};
uint16_t numRides{};
uint16_t numGuests{};
};
struct GameState_t;
ParkPreview generatePreviewFromGameState(const GameState_t& gameState);
} // namespace OpenRCT2

View File

@@ -52,6 +52,7 @@
#include "../object/PeepAnimationsObject.h"
#include "../object/ScenarioTextObject.h"
#include "../park/Legacy.h"
#include "../park/ParkPreview.h"
#include "../peep/RideUseSystem.h"
#include "../rct12/CSStringConverter.h"
#include "../rct12/EntryList.h"
@@ -289,6 +290,11 @@ namespace OpenRCT2::RCT1
return true;
}
ParkPreview GetParkPreview() override
{
return {};
}
money64 CorrectRCT1ParkValue(money32 oldParkValue)
{
if (oldParkValue == kMoney32Undefined)

View File

@@ -52,6 +52,7 @@
#include "../object/ScenarioTextObject.h"
#include "../object/WallSceneryEntry.h"
#include "../park/Legacy.h"
#include "../park/ParkPreview.h"
#include "../peep/RideUseSystem.h"
#include "../rct12/CSStringConverter.h"
#include "../rct12/EntryList.h"
@@ -314,6 +315,11 @@ namespace OpenRCT2::RCT2
return true;
}
ParkPreview GetParkPreview() override
{
return {};
}
void Import(GameState_t& gameState) override
{
Initialise(gameState);