From 914bf3a0c6bbaf25d8f18a9ac92b780bf039ee16 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Feb 2019 23:10:34 +0100 Subject: [PATCH 1/4] Add finance_check_money_required and finance_check_affordability helper functions. --- src/openrct2/management/Finance.cpp | 34 +++++++++++++++++++++++++++++ src/openrct2/management/Finance.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index 7c64905411..c68dc85938 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -11,6 +11,7 @@ #include "../Context.h" #include "../Game.h" +#include "../OpenRCT2.h" #include "../interface/Window.h" #include "../localisation/Date.h" #include "../localisation/Localisation.h" @@ -64,6 +65,39 @@ money32 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][RCT_EXPENDITURE_TYPE_CO uint8_t gCommandExpenditureType; +/** + * Checks the condition if the game is required to use money. + * @param flags game command flags. + */ +bool finance_check_money_required(uint32_t flags) +{ + if (gParkFlags & PARK_FLAGS_NO_MONEY) + return false; + if (gScreenFlags & SCREEN_FLAGS_EDITOR) + return false; + if (flags & GAME_COMMAND_FLAG_5) + return false; + if (flags & GAME_COMMAND_FLAG_GHOST) + return false; + return true; +} + +/** + * Checks if enough money is available. + * @param cost. + * @param flags game command flags. + */ +bool finance_check_affordability(money32 cost, uint32_t flags) +{ + if (finance_check_money_required(flags) == false) + return true; + if (cost <= 0) + return true; + if (cost <= gCash) + return true; + return false; +} + /** * Pay an amount of money. * rct2: 0x069C674 diff --git a/src/openrct2/management/Finance.h b/src/openrct2/management/Finance.h index ef131b5f26..2a7191b3d7 100644 --- a/src/openrct2/management/Finance.h +++ b/src/openrct2/management/Finance.h @@ -63,6 +63,8 @@ extern money32 gExpenditureTable[EXPENDITURE_TABLE_MONTH_COUNT][RCT_EXPENDITURE_ extern uint8_t gCommandExpenditureType; +bool finance_check_money_required(uint32_t flags); +bool finance_check_affordability(money32 cost, uint32_t flags); void finance_payment(money32 amount, rct_expenditure_type type); void finance_pay_wages(); void finance_pay_research(); From 21e4c52853e1f3ed484b8e2c1f1789f3606ae593 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Feb 2019 23:11:12 +0100 Subject: [PATCH 2/4] Use finance_check_affordability instead of CheckActionAffordability --- src/openrct2/actions/GameAction.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index 69bb3445cf..54d6c2e04c 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -126,17 +126,6 @@ namespace GameActions return false; } - static bool CheckActionAffordability(const GameActionResult* result) - { - if (gParkFlags & PARK_FLAGS_NO_MONEY) - return true; - if (result->Cost <= 0) - return true; - if (result->Cost <= gCash) - return true; - return false; - } - static GameActionResult::Ptr QueryInternal(const GameAction* action, bool topLevel) { Guard::ArgumentNotNull(action); @@ -165,7 +154,7 @@ namespace GameActions if (result->Error == GA_ERROR::OK) { - if (!CheckActionAffordability(result.get())) + if (finance_check_affordability(result->Cost, action->GetFlags())) { result->Error = GA_ERROR::INSUFFICIENT_FUNDS; result->ErrorMessage = STR_NOT_ENOUGH_CASH_REQUIRES; @@ -309,8 +298,7 @@ namespace GameActions gCommandPosition.z = result->Position.z; // Update money balance - if (!(gParkFlags & PARK_FLAGS_NO_MONEY) && !(flags & GAME_COMMAND_FLAG_GHOST) && !(flags & GAME_COMMAND_FLAG_5) - && result->Cost != 0) + if (finance_check_money_required(flags) && result->Cost != 0) { finance_payment(result->Cost, result->ExpenditureType); money_effect_create(result->Cost); From a6c6d6ddc32c42ed53acf96c674eafb8718b69b0 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Feb 2019 23:24:40 +0100 Subject: [PATCH 3/4] Update checks for when money is required. --- src/openrct2/Game.cpp | 15 +++++++-------- src/openrct2/actions/FootpathRemoveAction.hpp | 10 ---------- src/openrct2/actions/GameAction.cpp | 4 ++-- src/openrct2/actions/LandSetHeightAction.hpp | 6 +----- src/openrct2/management/Finance.cpp | 8 +++----- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index c8011dc63d..5ea9f38e75 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -332,17 +332,16 @@ void update_palette_effects() * * @param cost (ebp) */ -static int32_t game_check_affordability(int32_t cost) +static int32_t game_check_affordability(int32_t cost, uint32_t flags) { - if (cost <= 0) - return cost; + // Only checked for game commands. if (gUnk141F568 & 0xF0) return cost; - if (cost <= gCash) + + if (finance_check_affordability(cost, flags)) return cost; set_format_arg(0, uint32_t, cost); - gGameCommandErrorText = STR_NOT_ENOUGH_CASH_REQUIRES; return MONEY32_UNDEFINED; } @@ -447,7 +446,7 @@ int32_t game_do_command_p( // Check funds int32_t insufficientFunds = 0; if (gGameCommandNestLevel == 1 && !(flags & GAME_COMMAND_FLAG_2) && !(flags & GAME_COMMAND_FLAG_5) && cost != 0) - insufficientFunds = game_check_affordability(cost); + insufficientFunds = game_check_affordability(cost, flags); if (insufficientFunds != MONEY32_UNDEFINED) { @@ -531,8 +530,8 @@ int32_t game_do_command_p( if (gGameCommandNestLevel != 0) return cost; - // - if (!(flags & 0x20)) + // Check if money is required. + if (finance_check_money_required(flags)) { // Update money balance finance_payment(cost, gCommandExpenditureType); diff --git a/src/openrct2/actions/FootpathRemoveAction.hpp b/src/openrct2/actions/FootpathRemoveAction.hpp index 8e7335bf53..94dfef978c 100644 --- a/src/openrct2/actions/FootpathRemoveAction.hpp +++ b/src/openrct2/actions/FootpathRemoveAction.hpp @@ -138,16 +138,6 @@ private: money32 GetRefundPrice(TileElement * footpathElement) const { money32 cost = -MONEY(10, 00); - - bool isNotOwnedByPark = (GetFlags() & GAME_COMMAND_FLAG_5); - bool moneyDisabled = (gParkFlags & PARK_FLAGS_NO_MONEY); - bool isGhost = (footpathElement == nullptr) || (footpathElement->IsGhost()); - - if (isNotOwnedByPark || moneyDisabled || isGhost) - { - cost = 0; - } - return cost; } }; diff --git a/src/openrct2/actions/GameAction.cpp b/src/openrct2/actions/GameAction.cpp index 54d6c2e04c..b8b78af009 100644 --- a/src/openrct2/actions/GameAction.cpp +++ b/src/openrct2/actions/GameAction.cpp @@ -154,7 +154,7 @@ namespace GameActions if (result->Error == GA_ERROR::OK) { - if (finance_check_affordability(result->Cost, action->GetFlags())) + if (finance_check_affordability(result->Cost, action->GetFlags()) == false) { result->Error = GA_ERROR::INSUFFICIENT_FUNDS; result->ErrorMessage = STR_NOT_ENOUGH_CASH_REQUIRES; @@ -298,7 +298,7 @@ namespace GameActions gCommandPosition.z = result->Position.z; // Update money balance - if (finance_check_money_required(flags) && result->Cost != 0) + if (result->Error == GA_ERROR::OK && finance_check_money_required(flags) && result->Cost != 0) { finance_payment(result->Cost, result->ExpenditureType); money_effect_create(result->Cost); diff --git a/src/openrct2/actions/LandSetHeightAction.hpp b/src/openrct2/actions/LandSetHeightAction.hpp index 52d9900947..5161d4f588 100644 --- a/src/openrct2/actions/LandSetHeightAction.hpp +++ b/src/openrct2/actions/LandSetHeightAction.hpp @@ -134,11 +134,7 @@ public: } } auto res = std::make_unique(); - res->Cost = 0; - if (!(gScreenFlags & SCREEN_FLAGS_EDITOR) && !(gParkFlags & PARK_FLAGS_NO_MONEY)) - { - res->Cost = sceneryRemovalCost + GetSurfaceHeightChangeCost(surfaceElement); - } + res->Cost = sceneryRemovalCost + GetSurfaceHeightChangeCost(surfaceElement); res->ExpenditureType = RCT_EXPENDITURE_TYPE_LANDSCAPING; return res; } diff --git a/src/openrct2/management/Finance.cpp b/src/openrct2/management/Finance.cpp index c68dc85938..d2c8421a24 100644 --- a/src/openrct2/management/Finance.cpp +++ b/src/openrct2/management/Finance.cpp @@ -91,11 +91,9 @@ bool finance_check_affordability(money32 cost, uint32_t flags) { if (finance_check_money_required(flags) == false) return true; - if (cost <= 0) - return true; - if (cost <= gCash) - return true; - return false; + if (cost > gCash) + return false; + return true; } /** From d7ff3854a9c4247d468fcd25d432dd99ab6cfc0f Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 18 Feb 2019 17:20:18 +0100 Subject: [PATCH 4/4] Bump up network version. --- src/openrct2/network/Network.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index 67642ca015..1614c866f4 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -30,7 +30,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 "38" +#define NETWORK_STREAM_VERSION "39" #define NETWORK_STREAM_ID OPENRCT2_VERSION "-" NETWORK_STREAM_VERSION static rct_peep* _pickup_peep = nullptr;