Skip to content

Commit

Permalink
Fix OpenRCT2#11752: Track pieces with fractional cost are too cheap t…
Browse files Browse the repository at this point in the history
…o build

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.
  • Loading branch information
CookiePLMonster committed Jan 26, 2022
1 parent 3752a5a commit e1bd13d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions distribution/changelog.txt
Expand Up @@ -22,6 +22,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: [#15571] Non-ASCII characters in scenario description get distorted while saving.
- Fix: [#15830] Objects with RCT1 images are very glitchy if OpenRCT2 is not linked to an RCT1 install.
Expand Down
4 changes: 2 additions & 2 deletions src/openrct2/actions/MazePlaceTrackAction.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/actions/TrackPlaceAction.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e1bd13d

Please sign in to comment.