1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-04 13:42:55 +01:00

Implement game action for park set loan

This commit is contained in:
Ted John
2018-03-14 19:43:01 +00:00
committed by Michał Janiszewski
parent 9c568105f2
commit 16a7e21ffa
8 changed files with 104 additions and 68 deletions

View File

@@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include <openrct2/actions/ParkSetLoanAction.hpp>
#include <openrct2/config/Config.h>
#include <openrct2/core/Math.hpp>
#include <openrct2-ui/windows/Window.h>
@@ -594,19 +595,21 @@ static void window_finances_summary_mouseup(rct_window *w, rct_widgetindex widge
*/
static void window_finances_summary_mousedown(rct_window *w, rct_widgetindex widgetIndex, rct_widget* widget)
{
money32 newLoan;
switch (widgetIndex) {
switch (widgetIndex)
{
case WIDX_LOAN_INCREASE:
newLoan = gBankLoan + MONEY(1000, 00);
gGameCommandErrorTitle = STR_CANT_BORROW_ANY_MORE_MONEY;
finance_set_loan(newLoan);
break;
{
auto newLoan = gBankLoan + MONEY(1000, 00);
auto gameAction = ParkSetLoanAction(newLoan);
GameActions::Execute(&gameAction);
break;
}
case WIDX_LOAN_DECREASE:
if (gBankLoan > 0) {
newLoan = gBankLoan - MONEY(1000, 00);
gGameCommandErrorTitle = STR_CANT_PAY_BACK_LOAN;
finance_set_loan(newLoan);
if (gBankLoan > 0)
{
auto newLoan = gBankLoan - MONEY(1000, 00);
auto gameAction = ParkSetLoanAction(newLoan);
GameActions::Execute(&gameAction);
}
break;
}

View File

@@ -14,6 +14,7 @@
*****************************************************************************/
#pragma endregion
#include "actions/ParkSetLoanAction.hpp"
#include "Cheats.h"
#include "config/Config.h"
#include "localisation/Localisation.h"
@@ -259,9 +260,8 @@ static void cheat_clear_loan()
cheat_add_money(gBankLoan);
// Then pay the loan
money32 newLoan;
newLoan = MONEY(0, 00);
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, newLoan, GAME_COMMAND_SET_CURRENT_LOAN, 0, 0);
auto gameAction = ParkSetLoanAction(MONEY(0, 00));
GameActions::Execute(&gameAction);
}
static void cheat_generate_guests(sint32 count)

View File

@@ -1733,7 +1733,7 @@ GAME_COMMAND_POINTER * new_game_command_table[GAME_COMMAND_COUNT] = {
game_command_remove_wall,
game_command_place_large_scenery,
game_command_remove_large_scenery,
game_command_set_current_loan,
nullptr,
game_command_set_research_funding,
game_command_place_track_design,
game_command_start_campaign,

View File

@@ -72,7 +72,7 @@ enum GAME_COMMAND
GAME_COMMAND_REMOVE_WALL,
GAME_COMMAND_PLACE_LARGE_SCENERY,
GAME_COMMAND_REMOVE_LARGE_SCENERY,
GAME_COMMAND_SET_CURRENT_LOAN,
GAME_COMMAND_SET_CURRENT_LOAN, // GA
GAME_COMMAND_SET_RESEARCH_FUNDING,
GAME_COMMAND_PLACE_TRACK_DESIGN,
GAME_COMMAND_START_MARKETING_CAMPAIGN,

View File

@@ -16,6 +16,7 @@
#include "GameAction.h"
#include "GuestSetNameAction.hpp"
#include "ParkSetLoanAction.hpp"
#include "PlaceParkEntranceAction.hpp"
#include "SetParkEntranceFeeAction.hpp"
#include "StaffSetNameAction.hpp"
@@ -31,6 +32,7 @@ namespace GameActions
void Register()
{
Register<SetParkEntranceFeeAction>();
Register<ParkSetLoanAction>();
Register<PlaceParkEntranceAction>();
Register<RideCreateAction>();
Register<RideSetStatusAction>();

View File

@@ -0,0 +1,83 @@
#pragma region Copyright (c) 2014-2018 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include "../Context.h"
#include "../core/MemoryStream.h"
#include "../localisation/StringIds.h"
#include "../management/Finance.h"
#include "../ui/UiContext.h"
#include "../ui/WindowManager.h"
#include "../windows/Intent.h"
#include "GameAction.h"
using namespace OpenRCT2;
struct ParkSetLoanAction : public GameActionBase<GAME_COMMAND_SET_CURRENT_LOAN, GameActionResult>
{
private:
money32 _value;
public:
ParkSetLoanAction() {}
ParkSetLoanAction(money32 value)
: _value(value)
{
}
uint16 GetActionFlags() const override
{
return GameAction::GetActionFlags() | GA_FLAGS::ALLOW_WHILE_PAUSED;
}
void Serialise(DataSerialiser& stream) override
{
GameAction::Serialise(stream);
stream << _value;
}
GameActionResult::Ptr Query() const override
{
auto currentLoan = gBankLoan;
auto loanDifference = currentLoan - _value;
if (_value > currentLoan)
{
if (_value > gMaxBankLoan)
{
return std::make_unique<GameActionResult>(GA_ERROR::DISALLOWED, STR_CANT_BORROW_ANY_MORE_MONEY, STR_BANK_REFUSES_TO_INCREASE_LOAN);
}
}
else
{
if (loanDifference > gCash)
{
return std::make_unique<GameActionResult>(GA_ERROR::INSUFFICIENT_FUNDS, STR_CANT_PAY_BACK_LOAN, STR_NOT_ENOUGH_CASH_AVAILABLE);
}
}
return std::make_unique<GameActionResult>();
}
GameActionResult::Ptr Execute() const override
{
gCash -= (gBankLoan - _value);
gBankLoan = _value;
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
windowManager->BroadcastIntent(Intent(INTENT_ACTION_UPDATE_CASH));
return std::make_unique<GameActionResult>();
}
};

View File

@@ -284,11 +284,6 @@ void finance_update_daily_profit()
window_invalidate_by_class(WC_FINANCES);
}
void finance_set_loan(money32 loan)
{
game_do_command(0, GAME_COMMAND_FLAG_APPLY, 0, loan, GAME_COMMAND_SET_CURRENT_LOAN, 0, 0);
}
money32 finance_get_initial_cash()
{
return gInitialCash;
@@ -309,51 +304,6 @@ money32 finance_get_current_cash()
return gCash;
}
/**
*
* rct2: 0x0069DFB3
*/
void game_command_set_current_loan(sint32 * eax, sint32 * ebx, sint32 * ecx, sint32 * edx, sint32 * esi, sint32 * edi, sint32 * ebp)
{
money32 loanDifference, currentLoan;
money32 newLoan = *edx;
currentLoan = gBankLoan;
loanDifference = currentLoan - newLoan;
gCommandExpenditureType = RCT_EXPENDITURE_TYPE_INTEREST;
if (newLoan > currentLoan)
{
if (newLoan > gMaxBankLoan)
{
gGameCommandErrorText = STR_BANK_REFUSES_TO_INCREASE_LOAN;
*ebx = MONEY32_UNDEFINED;
return;
}
}
else
{
if (loanDifference > gCash)
{
gGameCommandErrorText = STR_NOT_ENOUGH_CASH_AVAILABLE;
*ebx = MONEY32_UNDEFINED;
return;
}
}
if (*ebx & GAME_COMMAND_FLAG_APPLY)
{
gCash -= loanDifference;
gBankLoan = newLoan;
gInitialCash = gCash;
auto intent = Intent(INTENT_ACTION_UPDATE_CASH);
context_broadcast_intent(&intent);
}
*ebx = 0;
}
/**
* Shift the expenditure table history one month to the left
* If the table is full, accumulate the sum of the oldest month first

View File

@@ -80,11 +80,9 @@ void finance_update_daily_profit();
void finance_shift_expenditure_table();
void finance_reset_cash_to_initial();
void finance_set_loan(money32 loan);
money32 finance_get_initial_cash();
money32 finance_get_current_loan();
money32 finance_get_maximum_loan();
money32 finance_get_current_cash();
void game_command_set_current_loan(sint32* eax, sint32* ebx, sint32* ecx, sint32* edx, sint32* esi, sint32* edi, sint32* ebp);
money32 finance_get_last_month_shop_profit();