mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
Make S4Importer::CorrectRCT1ParkValue independent of global game state (#25178)
This commit is contained in:
@@ -93,13 +93,15 @@ static constexpr ObjectEntryIndex ObjectEntryIndexIgnore = 254;
|
||||
|
||||
namespace OpenRCT2::RCT1
|
||||
{
|
||||
constexpr uint8_t kDefaultParkValueConversionFactor = 100;
|
||||
|
||||
class S4Importer final : public IParkImporter
|
||||
{
|
||||
private:
|
||||
std::string _s4Path;
|
||||
S4 _s4 = {};
|
||||
uint8_t _gameVersion = 0;
|
||||
uint8_t _parkValueConversionFactor = 0;
|
||||
uint8_t _parkValueConversionFactor = kDefaultParkValueConversionFactor;
|
||||
bool _isScenario = false;
|
||||
|
||||
// Lists of dynamic object entries
|
||||
@@ -288,6 +290,17 @@ namespace OpenRCT2::RCT1
|
||||
return {};
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t calculateParkValueConversionFactor(const Park::ParkData& park, const GameState_t& gameState)
|
||||
{
|
||||
if (_s4.ParkValue == 0)
|
||||
return kDefaultParkValueConversionFactor;
|
||||
|
||||
// Use the ratio between the old and new park value to calculate the ratio to
|
||||
// use for the park value history and the goal.
|
||||
return (Park::CalculateParkValue(park, gameState) * 10) / _s4.ParkValue;
|
||||
}
|
||||
|
||||
money64 CorrectRCT1ParkValue(money32 oldParkValue)
|
||||
{
|
||||
if (oldParkValue == kMoney32Undefined)
|
||||
@@ -295,26 +308,11 @@ namespace OpenRCT2::RCT1
|
||||
return kMoney64Undefined;
|
||||
}
|
||||
|
||||
if (_parkValueConversionFactor == 0)
|
||||
{
|
||||
if (_s4.ParkValue != 0)
|
||||
{
|
||||
// Use the ratio between the old and new park value to calcute the ratio to
|
||||
// use for the park value history and the goal.
|
||||
// TODO: split up this function so this can pass the actual park/gamestate as needed
|
||||
_parkValueConversionFactor = (Park::CalculateParkValue() * 10) / _s4.ParkValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// In new games, the park value isn't set.
|
||||
_parkValueConversionFactor = 100;
|
||||
}
|
||||
}
|
||||
assert(_parkValueConversionFactor != 0);
|
||||
|
||||
return (oldParkValue * _parkValueConversionFactor) / 10;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<S4> ReadAndDecodeS4(IStream* stream, bool isScenario)
|
||||
{
|
||||
auto s4 = std::make_unique<S4>();
|
||||
@@ -345,7 +343,7 @@ namespace OpenRCT2::RCT1
|
||||
void Initialise(GameState_t& gameState)
|
||||
{
|
||||
// Avoid reusing the value used for last import
|
||||
_parkValueConversionFactor = 0;
|
||||
_parkValueConversionFactor = kDefaultParkValueConversionFactor;
|
||||
|
||||
uint16_t mapSize = _s4.MapSize == 0 ? Limits::kMaxMapSize : _s4.MapSize;
|
||||
|
||||
@@ -1514,6 +1512,9 @@ namespace OpenRCT2::RCT1
|
||||
park.value = CorrectRCT1ParkValue(_s4.ParkValue);
|
||||
park.currentProfit = ToMoney64(_s4.Profit);
|
||||
|
||||
// With park value known, we can recalculate the conversion factor
|
||||
_parkValueConversionFactor = calculateParkValueConversionFactor(park, gameState);
|
||||
|
||||
for (size_t i = 0; i < Limits::kFinanceGraphSize; i++)
|
||||
{
|
||||
park.cashHistory[i] = ToMoney64(_s4.CashHistory[i]);
|
||||
|
||||
@@ -509,13 +509,6 @@ namespace OpenRCT2::Park
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO: refactor S4Importer so this hack is no longer needed
|
||||
money64 CalculateParkValue()
|
||||
{
|
||||
auto& gameState = getGameState();
|
||||
return CalculateParkValue(gameState.park, gameState);
|
||||
}
|
||||
|
||||
money64 CalculateCompanyValue(const ParkData& park)
|
||||
{
|
||||
auto result = park.value - park.bankLoan;
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace OpenRCT2::Park
|
||||
uint32_t CalculateParkSize(ParkData& park);
|
||||
int32_t CalculateParkRating(const ParkData& park, const GameState_t& gameState);
|
||||
money64 CalculateParkValue(const ParkData& park, const GameState_t& gameState);
|
||||
money64 CalculateParkValue();
|
||||
money64 CalculateCompanyValue(const ParkData& park);
|
||||
|
||||
Guest* GenerateGuest();
|
||||
|
||||
Reference in New Issue
Block a user