From 795144662acb89ff7b36f43946533441c7bb37d3 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 19 Feb 2022 18:47:13 +0100 Subject: [PATCH] Fix #11752: Track pieces with fractional cost are too cheap to build (#16477) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes an inconsistency wuth RCT2 where track prices with a fractional part did not have their price rounded up when building, but did when refunding. This created an exploit where refunding such a track piece granted the player 0.50€ more than they spent on the piece. --- distribution/changelog.txt | 1 + src/openrct2/actions/MazePlaceTrackAction.cpp | 4 ++-- src/openrct2/actions/TrackPlaceAction.cpp | 8 ++++---- src/openrct2/network/NetworkBase.cpp | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 4c7c4a01b7..bd3d18761c 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -26,6 +26,7 @@ - Change: [#16077] When importing SV6 files, the RCT1 land types are only added when they were actually used. - Change: [#16424] Following an entity in the title sequence no longer toggles underground view when it's underground. - Change: [#16493] Boat Hire and Submarine Ride support costs now match their visual appearance. +- Fix: [#11752] Track pieces with fractional cost are too cheap to build. - Fix: [#13336] Can no longer place Bumble Bee track design (reverts #12707). - Fix: [#14155] Map Generator sometimes places non-tree objects as trees. - Fix: [#14674] Recent Messages only shows first few notifications. diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index 11e1bee7b4..cdf34aaad2 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -119,7 +119,7 @@ GameActions::Result MazePlaceTrackAction::Query() const const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); money32 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.Price) >> 16)); - res.Cost = canBuild.Cost + price / 2 * 10; + res.Cost = ((canBuild.Cost + price) / 2) * 10; return res; } @@ -161,7 +161,7 @@ GameActions::Result MazePlaceTrackAction::Execute() const const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); money32 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.Price) >> 16)); - res.Cost = canBuild.Cost + price / 2 * 10; + res.Cost = ((canBuild.Cost + price) / 2) * 10; auto startLoc = _loc.ToTileStart(); diff --git a/src/openrct2/actions/TrackPlaceAction.cpp b/src/openrct2/actions/TrackPlaceAction.cpp index cc859100f9..1e50240a95 100644 --- a/src/openrct2/actions/TrackPlaceAction.cpp +++ b/src/openrct2/actions/TrackPlaceAction.cpp @@ -393,14 +393,14 @@ GameActions::Result TrackPlaceAction::Query() const supportHeight = (10 * COORDS_Z_STEP); } - cost += ((supportHeight / (2 * COORDS_Z_STEP)) * ride->GetRideTypeDescriptor().BuildCosts.SupportPrice) * 5; + cost += ((supportHeight / (2 * COORDS_Z_STEP)) * ride->GetRideTypeDescriptor().BuildCosts.SupportPrice); } money32 price = ride->GetRideTypeDescriptor().BuildCosts.TrackPrice; price *= ted.Price; price >>= 16; - res.Cost = cost + ((price / 2) * 10); + res.Cost = ((cost + price) / 2) * 10; res.SetData(std::move(resultData)); return res; @@ -522,7 +522,7 @@ GameActions::Result TrackPlaceAction::Execute() const supportHeight = (10 * COORDS_Z_STEP); } - cost += ((supportHeight / (2 * COORDS_Z_STEP)) * ride->GetRideTypeDescriptor().BuildCosts.SupportPrice) * 5; + cost += (supportHeight / (2 * COORDS_Z_STEP)) * ride->GetRideTypeDescriptor().BuildCosts.SupportPrice; if (!(GetFlags() & GAME_COMMAND_FLAG_GHOST)) { @@ -697,7 +697,7 @@ GameActions::Result TrackPlaceAction::Execute() const price *= ted.Price; price >>= 16; - res.Cost = cost + ((price / 2) * 10); + res.Cost = ((cost + price) / 2) * 10; res.SetData(std::move(resultData)); return res; diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index 63ad89d4ec..51a9724ac1 100644 --- a/src/openrct2/network/NetworkBase.cpp +++ b/src/openrct2/network/NetworkBase.cpp @@ -42,7 +42,7 @@ // This string specifies which version of network stream current build uses. // It is used for making sure only compatible builds get connected, even within // single OpenRCT2 version. -#define NETWORK_STREAM_VERSION "17" +#define NETWORK_STREAM_VERSION "18" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr;