mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Merge pull request #8703 from ZehMatt/ga-cleanups
GameAction cleanup part 1
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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()) == false)
|
||||
{
|
||||
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 (result->Error == GA_ERROR::OK && finance_check_money_required(flags) && result->Cost != 0)
|
||||
{
|
||||
finance_payment(result->Cost, result->ExpenditureType);
|
||||
money_effect_create(result->Cost);
|
||||
|
||||
@@ -134,11 +134,7 @@ public:
|
||||
}
|
||||
}
|
||||
auto res = std::make_unique<GameActionResult>();
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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,37 @@ 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 > gCash)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pay an amount of money.
|
||||
* rct2: 0x069C674
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user