From 5c596eae5dc48bd56679ad72b7e8d1f040fc0bd1 Mon Sep 17 00:00:00 2001 From: Rik Smeets <30838294+rik-smeets@users.noreply.github.com> Date: Mon, 22 Aug 2022 18:50:37 +0200 Subject: [PATCH 1/2] Extract maze cost calculation --- src/openrct2/actions/MazePlaceTrackAction.cpp | 9 +++------ src/openrct2/actions/MazeSetTrackAction.cpp | 9 +++------ src/openrct2/libopenrct2.vcxproj | 1 + src/openrct2/ride/gentle/Maze.cpp | 14 ++++++++++++++ src/openrct2/ride/gentle/Maze.h | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/openrct2/ride/gentle/Maze.h diff --git a/src/openrct2/actions/MazePlaceTrackAction.cpp b/src/openrct2/actions/MazePlaceTrackAction.cpp index 9c701a6bb9..826bdf1a17 100644 --- a/src/openrct2/actions/MazePlaceTrackAction.cpp +++ b/src/openrct2/actions/MazePlaceTrackAction.cpp @@ -11,6 +11,7 @@ #include "../management/Finance.h" #include "../ride/RideData.h" #include "../ride/TrackData.h" +#include "../ride/gentle/Maze.h" #include "../world/ConstructionClearance.h" using namespace OpenRCT2::TrackMetaData; @@ -119,9 +120,7 @@ GameActions::Result MazePlaceTrackAction::Query() const return res; } - const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); - money64 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16)); - res.Cost = canBuild.Cost + price; + res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); return res; } @@ -161,9 +160,7 @@ GameActions::Result MazePlaceTrackAction::Execute() const return canBuild; } - const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); - money64 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16)); - res.Cost = canBuild.Cost + price; + res.Cost = MazeCalculateCost(canBuild.Cost, *ride, _loc); auto startLoc = _loc.ToTileStart(); diff --git a/src/openrct2/actions/MazeSetTrackAction.cpp b/src/openrct2/actions/MazeSetTrackAction.cpp index d9b1f96a2f..5353e87ea8 100644 --- a/src/openrct2/actions/MazeSetTrackAction.cpp +++ b/src/openrct2/actions/MazeSetTrackAction.cpp @@ -18,6 +18,7 @@ #include "../ride/RideData.h" #include "../ride/Track.h" #include "../ride/TrackData.h" +#include "../ride/gentle/Maze.h" #include "../world/ConstructionClearance.h" #include "../world/Footpath.h" #include "../world/Park.h" @@ -138,9 +139,7 @@ GameActions::Result MazeSetTrackAction::Query() const return res; } - const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); - money64 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16)); - res.Cost = price; + res.Cost = MazeCalculateCost(constructResult.Cost, *ride, _loc); return res; } @@ -174,9 +173,7 @@ GameActions::Result MazeSetTrackAction::Execute() const auto tileElement = map_get_track_element_at_of_type_from_ride(_loc, TrackElemType::Maze, _rideIndex); if (tileElement == nullptr) { - const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); - money64 price = (((ride->GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16)); - res.Cost = price; + res.Cost = MazeCalculateCost(0, *ride, _loc); auto startLoc = _loc.ToTileStart(); diff --git a/src/openrct2/libopenrct2.vcxproj b/src/openrct2/libopenrct2.vcxproj index 99c2bacb38..bc0ed411c8 100644 --- a/src/openrct2/libopenrct2.vcxproj +++ b/src/openrct2/libopenrct2.vcxproj @@ -391,6 +391,7 @@ + diff --git a/src/openrct2/ride/gentle/Maze.cpp b/src/openrct2/ride/gentle/Maze.cpp index 228b0cc659..d9bbd86fe8 100644 --- a/src/openrct2/ride/gentle/Maze.cpp +++ b/src/openrct2/ride/gentle/Maze.cpp @@ -7,6 +7,8 @@ * OpenRCT2 is licensed under the GNU General Public License version 3. *****************************************************************************/ +#include "Maze.h" + #include "../../core/Numerics.hpp" #include "../../interface/Viewport.h" #include "../../paint/Paint.h" @@ -15,9 +17,13 @@ #include "../../sprites.h" #include "../../world/Map.h" #include "../Ride.h" +#include "../RideData.h" #include "../Track.h" +#include "../TrackData.h" #include "../TrackPaint.h" +using namespace OpenRCT2::TrackMetaData; + enum { SPR_MAZE_BASE_HEDGE = 21938, @@ -190,3 +196,11 @@ TRACK_PAINT_FUNCTION get_track_paint_function_maze(int32_t trackType) return maze_paint_setup; } + +money64 MazeCalculateCost(money32 constructionCost, const Ride& ride) +{ + const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); + money64 price = (ride.GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16; + + return constructionCost + price; +} diff --git a/src/openrct2/ride/gentle/Maze.h b/src/openrct2/ride/gentle/Maze.h new file mode 100644 index 0000000000..e6a882337f --- /dev/null +++ b/src/openrct2/ride/gentle/Maze.h @@ -0,0 +1,14 @@ +/***************************************************************************** + * Copyright (c) 2014-2022 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 "../RideData.h" + +money64 MazeCalculateCost(money32 constructionCost, const Ride& ride); From f7c769603b448ab7cc43669295a58934ab546a6e Mon Sep 17 00:00:00 2001 From: Rik Smeets <30838294+rik-smeets@users.noreply.github.com> Date: Mon, 22 Aug 2022 18:51:16 +0200 Subject: [PATCH 2/2] Close #9104: Calculate maze support costs --- distribution/changelog.txt | 1 + src/openrct2/network/NetworkBase.cpp | 2 +- src/openrct2/ride/gentle/Maze.cpp | 8 ++++++-- src/openrct2/ride/gentle/Maze.h | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 18d98f88c9..ae255580ed 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -10,6 +10,7 @@ - Improved: [#15358] Park and scenario names can now contain up to 128 characters. - Improved: [#16840] Add support for rectangular heightmaps. - Improved: [#17575] You can now search for Authors in Object Selection. +- Change: [#9104] Calculate maze support costs. - Change: [#17319] Giant screenshots are now cropped to the horizontal view-clipping selection. - Change: [#17499] Update error text when using vehicle incompatible with TD6 and add error when using incompatible track elements. - Change: [#17655] Lower default price for the Crooked House. diff --git a/src/openrct2/network/NetworkBase.cpp b/src/openrct2/network/NetworkBase.cpp index be3784cf4c..ffa0abcf1d 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 "7" +#define NETWORK_STREAM_VERSION "8" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static Peep* _pickup_peep = nullptr; diff --git a/src/openrct2/ride/gentle/Maze.cpp b/src/openrct2/ride/gentle/Maze.cpp index d9bbd86fe8..56ee63459c 100644 --- a/src/openrct2/ride/gentle/Maze.cpp +++ b/src/openrct2/ride/gentle/Maze.cpp @@ -197,10 +197,14 @@ TRACK_PAINT_FUNCTION get_track_paint_function_maze(int32_t trackType) return maze_paint_setup; } -money64 MazeCalculateCost(money32 constructionCost, const Ride& ride) +money64 MazeCalculateCost(money32 constructionCost, const Ride& ride, const CoordsXYZ& _loc) { const auto& ted = GetTrackElementDescriptor(TrackElemType::Maze); money64 price = (ride.GetRideTypeDescriptor().BuildCosts.TrackPrice * ted.PriceModifier) >> 16; - return constructionCost + price; + auto surfaceElement = map_get_surface_element_at(_loc); + auto heightDifference = (_loc.z - surfaceElement->GetBaseZ()) / COORDS_Z_PER_TINY_Z; + money64 supportCost = heightDifference * ride.GetRideTypeDescriptor().BuildCosts.SupportPrice; + + return constructionCost + price + supportCost; } diff --git a/src/openrct2/ride/gentle/Maze.h b/src/openrct2/ride/gentle/Maze.h index e6a882337f..8a13c58f42 100644 --- a/src/openrct2/ride/gentle/Maze.h +++ b/src/openrct2/ride/gentle/Maze.h @@ -11,4 +11,4 @@ #include "../RideData.h" -money64 MazeCalculateCost(money32 constructionCost, const Ride& ride); +money64 MazeCalculateCost(money32 constructionCost, const Ride& ride, const CoordsXYZ& _loc);