mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-18 04:23:20 +01:00
Constrain plugins to normal range when assigning ride prices (#22227)
* Constrain plugins to normal range when assigning ride prices * Introduce kRideMinPrice, kRideMaxPrice * Adjust RideSetPriceAction to fail in case of invalid price * Add changelog entry
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
- Change: [#22057] Reorder Time Twister’s scenarios and adjust their difficulty classification.
|
||||
- Change: [#22173] Patrol path selection is visible over existing patrol paths.
|
||||
- Change: [#22196] Make track navigation buttons holdable.
|
||||
- Change: [#22227] [Plugin] Ride prices are now constrained for plugins as well.
|
||||
- Fix: [#13234] Vehicle weight sometimes wrong after using Remove All Guests cheat.
|
||||
- Fix: [#13294] Map corners are cut off in some directions (original bug).
|
||||
- Fix: [#14630] Non-ASCII thousands and decimal separators not processed correctly.
|
||||
|
||||
@@ -6032,7 +6032,7 @@ static_assert(std::size(RatingNames) == 6);
|
||||
return;
|
||||
|
||||
auto price = ride->price[0];
|
||||
if (price < 20.00_GBP)
|
||||
if (price < kRideMaxPrice)
|
||||
price++;
|
||||
|
||||
IncomeSetPrimaryPrice(price);
|
||||
@@ -6048,7 +6048,7 @@ static_assert(std::size(RatingNames) == 6);
|
||||
return;
|
||||
|
||||
auto price = ride->price[0];
|
||||
if (price > 0.00_GBP)
|
||||
if (price > kRideMinPrice)
|
||||
price--;
|
||||
|
||||
IncomeSetPrimaryPrice(price);
|
||||
@@ -6085,7 +6085,7 @@ static_assert(std::size(RatingNames) == 6);
|
||||
{
|
||||
auto price = IncomeGetSecondaryPrice();
|
||||
|
||||
if (price < 20.00_GBP)
|
||||
if (price < kRideMaxPrice)
|
||||
price++;
|
||||
|
||||
IncomeSetSecondaryPrice(price);
|
||||
@@ -6206,7 +6206,7 @@ static_assert(std::size(RatingNames) == 6);
|
||||
return;
|
||||
}
|
||||
|
||||
price = std::clamp(price, 0.00_GBP, 20.00_GBP);
|
||||
price = std::clamp(price, kRideMinPrice, kRideMaxPrice);
|
||||
|
||||
if (widgetIndex == WIDX_PRIMARY_PRICE)
|
||||
{
|
||||
|
||||
@@ -49,8 +49,6 @@ void RideSetPriceAction::Serialise(DataSerialiser& stream)
|
||||
|
||||
GameActions::Result RideSetPriceAction::Query() const
|
||||
{
|
||||
GameActions::Result res = GameActions::Result();
|
||||
|
||||
auto ride = GetRide(_rideIndex);
|
||||
if (ride == nullptr)
|
||||
{
|
||||
@@ -66,7 +64,13 @@ GameActions::Result RideSetPriceAction::Query() const
|
||||
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_OBJECT_ENTRY_NOT_FOUND);
|
||||
}
|
||||
|
||||
return res;
|
||||
if (_price < kRideMinPrice || _price > kRideMaxPrice)
|
||||
{
|
||||
LOG_ERROR("Attempting to set an invalid price for rideIndex %u", _rideIndex.ToUnderlying());
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_EMPTY);
|
||||
}
|
||||
|
||||
return GameActions::Result();
|
||||
}
|
||||
|
||||
GameActions::Result RideSetPriceAction::Execute() const
|
||||
@@ -89,6 +93,12 @@ GameActions::Result RideSetPriceAction::Execute() const
|
||||
GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_ERR_RIDE_OBJECT_ENTRY_NOT_FOUND);
|
||||
}
|
||||
|
||||
if (_price < kRideMinPrice || _price > kRideMaxPrice)
|
||||
{
|
||||
LOG_ERROR("Attempting to set an invalid price for rideIndex %u", _rideIndex.ToUnderlying());
|
||||
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_INVALID_PARAMETER, STR_EMPTY);
|
||||
}
|
||||
|
||||
if (!ride->overall_view.IsNull())
|
||||
{
|
||||
auto location = ride->overall_view.ToTileCentre();
|
||||
|
||||
@@ -54,6 +54,9 @@ constexpr uint8_t kRideNumDropsMask = 0b00111111;
|
||||
constexpr uint8_t kRideMaxNumPoweredLiftsCount = 3;
|
||||
constexpr uint8_t kRideNumPoweredLiftsMask = 0b11000000;
|
||||
|
||||
constexpr money64 kRideMinPrice = 0.00_GBP;
|
||||
constexpr money64 kRideMaxPrice = 20.00_GBP;
|
||||
|
||||
struct RideStation
|
||||
{
|
||||
static constexpr uint8_t kNoTrain = std::numeric_limits<uint8_t>::max();
|
||||
|
||||
@@ -325,7 +325,7 @@ namespace OpenRCT2::Scripting
|
||||
auto numPrices = std::min(value.size(), ride->GetNumPrices());
|
||||
for (size_t i = 0; i < numPrices; i++)
|
||||
{
|
||||
ride->price[i] = static_cast<money64>(value[i]);
|
||||
ride->price[i] = std::clamp<money64>(value[i], kRideMinPrice, kRideMaxPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user