2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD 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, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file misc_cmd.cpp Some misc functions that are better fitted in other files, but never got moved there... */
|
2007-03-03 04:04:22 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
|
|
|
#include "economy_func.h"
|
2013-09-21 13:07:42 +00:00
|
|
|
#include "cmd_helper.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_func.h"
|
|
|
|
#include "textbuf_gui.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2009-11-12 20:33:30 +00:00
|
|
|
#include "network/network_func.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "company_gui.h"
|
2010-01-05 17:11:56 +00:00
|
|
|
#include "company_base.h"
|
2021-01-22 09:28:26 +00:00
|
|
|
#include "tile_map.h"
|
|
|
|
#include "texteff.hpp"
|
2010-05-31 20:22:57 +00:00
|
|
|
#include "core/backup_type.hpp"
|
2020-04-14 19:11:38 +00:00
|
|
|
#include "cheat_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2020-12-27 22:38:45 +00:00
|
|
|
/* Make sure we can discard lower 2 bits of 64bit amount when passing it to Cmd[In|De]creaseLoan() */
|
|
|
|
static_assert((LOAN_INTERVAL & 3) == 0);
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Increase the loan of your company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2020-12-27 22:38:45 +00:00
|
|
|
* @param p1 higher half of amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
|
|
|
|
* @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
|
|
|
|
* (bit 0-1) - when 0: loans LOAN_INTERVAL
|
|
|
|
* when 1: loans the maximum loan permitting money (press CTRL),
|
|
|
|
* when 2: loans the amount specified in p1 and p2
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-11 00:00:27 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_current_company);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->current_loan >= _economy.max_loan) {
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, _economy.max_loan);
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_MAXIMUM_PERMITTED_LOAN);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:44:47 +00:00
|
|
|
Money loan;
|
2020-12-27 22:38:45 +00:00
|
|
|
switch (p2 & 3) {
|
2007-06-14 15:24:34 +00:00
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
|
case 0: // Take some extra loan
|
2009-01-12 17:11:45 +00:00
|
|
|
loan = LOAN_INTERVAL;
|
2007-06-14 15:24:34 +00:00
|
|
|
break;
|
|
|
|
case 1: // Take a loan as big as possible
|
2008-09-30 20:39:50 +00:00
|
|
|
loan = _economy.max_loan - c->current_loan;
|
2007-06-14 15:24:34 +00:00
|
|
|
break;
|
2009-01-12 17:11:45 +00:00
|
|
|
case 2: // Take the given amount of loan
|
2020-12-27 22:38:45 +00:00
|
|
|
loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC);
|
|
|
|
if (loan < LOAN_INTERVAL || c->current_loan + loan > _economy.max_loan || loan % LOAN_INTERVAL != 0) return CMD_ERROR;
|
2009-01-12 17:11:45 +00:00
|
|
|
break;
|
2007-06-14 15:24:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2023-01-15 10:08:08 +00:00
|
|
|
/* In case adding the loan triggers the overflow protection of Money,
|
|
|
|
* we would essentially be losing money as taking and repaying the loan
|
|
|
|
* immediately would not get us back to the same bank balance anymore. */
|
|
|
|
if (c->money > Money::max() - loan) return CMD_ERROR;
|
2007-06-19 00:05:26 +00:00
|
|
|
|
2007-06-14 15:24:34 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-09-30 20:39:50 +00:00
|
|
|
c->money += loan;
|
|
|
|
c->current_loan += loan;
|
|
|
|
InvalidateCompanyWindows(c);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 16:55:48 +00:00
|
|
|
return CommandCost(EXPENSES_OTHER);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Decrease the loan of your company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2020-12-27 22:38:45 +00:00
|
|
|
* @param p1 higher half of amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when (p2 & 3) == 2.
|
|
|
|
* @param p2 (bit 2-31) - lower half of amount (lower 2 bits assumed to be 0)
|
|
|
|
* (bit 0-1) - when 0: pays back LOAN_INTERVAL
|
|
|
|
* when 1: pays back the maximum loan permitting money (press CTRL),
|
|
|
|
* when 2: pays back the amount specified in p1 and p2
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-11 00:00:27 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_current_company);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-04-21 23:40:56 +00:00
|
|
|
if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED);
|
2005-05-11 00:00:27 +00:00
|
|
|
|
2007-06-19 00:05:26 +00:00
|
|
|
Money loan;
|
2020-12-27 22:38:45 +00:00
|
|
|
switch (p2 & 3) {
|
2007-06-14 15:24:34 +00:00
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
|
case 0: // Pay back one step
|
2021-01-08 10:16:18 +00:00
|
|
|
loan = std::min(c->current_loan, (Money)LOAN_INTERVAL);
|
2007-06-14 15:24:34 +00:00
|
|
|
break;
|
|
|
|
case 1: // Pay back as much as possible
|
2021-01-08 10:16:18 +00:00
|
|
|
loan = std::max(std::min(c->current_loan, c->money), (Money)LOAN_INTERVAL);
|
2007-06-14 15:24:34 +00:00
|
|
|
loan -= loan % LOAN_INTERVAL;
|
|
|
|
break;
|
2009-01-12 17:11:45 +00:00
|
|
|
case 2: // Repay the given amount of loan
|
2020-12-27 22:38:45 +00:00
|
|
|
loan = ((uint64)p1 << 32) | (p2 & 0xFFFFFFFC);
|
|
|
|
if (loan % LOAN_INTERVAL != 0 || loan < LOAN_INTERVAL || loan > c->current_loan) return CMD_ERROR; // Invalid amount to loan
|
2009-01-12 17:11:45 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->money < loan) {
|
2007-06-21 17:25:17 +00:00
|
|
|
SetDParam(0, loan);
|
2009-04-21 23:40:56 +00:00
|
|
|
return_cmd_error(STR_ERROR_CURRENCY_REQUIRED);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
2008-09-30 20:39:50 +00:00
|
|
|
c->money -= loan;
|
|
|
|
c->current_loan -= loan;
|
|
|
|
InvalidateCompanyWindows(c);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:50:07 +00:00
|
|
|
/**
|
|
|
|
* In case of an unsafe unpause, we want the
|
|
|
|
* user to confirm that it might crash.
|
|
|
|
* @param w unused
|
2021-05-09 17:02:17 +00:00
|
|
|
* @param confirmed whether the user confirmed their action
|
2007-12-04 22:50:07 +00:00
|
|
|
*/
|
|
|
|
static void AskUnsafeUnpauseCallback(Window *w, bool confirmed)
|
|
|
|
{
|
2011-07-02 17:40:39 +00:00
|
|
|
if (confirmed) {
|
|
|
|
DoCommandP(0, PM_PAUSED_ERROR, 0, CMD_PAUSE);
|
|
|
|
}
|
2007-12-04 22:50:07 +00:00
|
|
|
}
|
|
|
|
|
2009-11-12 20:33:30 +00:00
|
|
|
/**
|
|
|
|
* Pause/Unpause the game (server-only).
|
|
|
|
* Set or unset a bit in the pause mode. If pause mode is zero the game is
|
|
|
|
* unpaused. A bitset is used instead of a boolean value/counter to have
|
|
|
|
* more control over the game when saving/loading, etc.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2009-05-06 15:06:57 +00:00
|
|
|
* @param p1 the pause mode to change
|
|
|
|
* @param p2 1 pauses, 0 unpauses this mode
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 00:11:37 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-05-06 15:06:57 +00:00
|
|
|
switch (p1) {
|
|
|
|
case PM_PAUSED_SAVELOAD:
|
|
|
|
case PM_PAUSED_ERROR:
|
|
|
|
case PM_PAUSED_NORMAL:
|
2011-12-19 20:58:59 +00:00
|
|
|
case PM_PAUSED_GAME_SCRIPT:
|
2015-09-03 17:36:30 +00:00
|
|
|
case PM_PAUSED_LINK_GRAPH:
|
2009-05-06 15:06:57 +00:00
|
|
|
break;
|
2007-12-04 22:50:07 +00:00
|
|
|
|
2009-11-12 17:44:49 +00:00
|
|
|
case PM_PAUSED_JOIN:
|
2009-11-12 17:46:04 +00:00
|
|
|
case PM_PAUSED_ACTIVE_CLIENTS:
|
2009-11-12 17:44:49 +00:00
|
|
|
if (!_networking) return CMD_ERROR;
|
|
|
|
break;
|
|
|
|
|
2009-05-06 15:06:57 +00:00
|
|
|
default: return CMD_ERROR;
|
|
|
|
}
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
if (p1 == PM_PAUSED_NORMAL && _pause_mode & PM_PAUSED_ERROR) {
|
|
|
|
ShowQuery(
|
|
|
|
STR_NEWGRF_UNPAUSE_WARNING_TITLE,
|
|
|
|
STR_NEWGRF_UNPAUSE_WARNING,
|
2019-04-10 21:07:06 +00:00
|
|
|
nullptr,
|
2009-05-06 15:06:57 +00:00
|
|
|
AskUnsafeUnpauseCallback
|
|
|
|
);
|
|
|
|
} else {
|
2009-11-12 20:33:30 +00:00
|
|
|
PauseMode prev_mode = _pause_mode;
|
|
|
|
|
2020-06-05 16:11:09 +00:00
|
|
|
if ((p2 & 1) == 0) {
|
2019-04-22 12:14:46 +00:00
|
|
|
_pause_mode = static_cast<PauseMode>(_pause_mode & (byte)~p1);
|
2020-06-05 16:11:09 +00:00
|
|
|
_pause_countdown = (p2 >> 1);
|
2009-05-06 15:06:57 +00:00
|
|
|
} else {
|
2019-04-22 12:14:46 +00:00
|
|
|
_pause_mode = static_cast<PauseMode>(_pause_mode | (byte)p1);
|
2009-05-06 15:06:57 +00:00
|
|
|
}
|
2009-11-12 20:33:30 +00:00
|
|
|
|
|
|
|
NetworkHandlePauseChange(prev_mode, (PauseMode)p1);
|
2007-12-04 22:50:07 +00:00
|
|
|
}
|
|
|
|
|
2009-09-13 19:15:59 +00:00
|
|
|
SetWindowDirty(WC_STATUS_BAR, 0);
|
|
|
|
SetWindowDirty(WC_MAIN_TOOLBAR, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Change the financial flow of your company.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2013-09-21 10:06:23 +00:00
|
|
|
* @param p1 the amount of money to receive (if positive), or spend (if negative)
|
2005-05-12 23:46:01 +00:00
|
|
|
* @param p2 unused
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 23:46:01 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2020-04-14 21:04:41 +00:00
|
|
|
if (_networking && !_settings_game.difficulty.money_cheat_in_multiplayer) return CMD_ERROR;
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
_cheats.money.been_used = true;
|
|
|
|
SetWindowDirty(WC_CHEATS, 0);
|
|
|
|
}
|
|
|
|
return CommandCost(EXPENSES_OTHER, -(int32)p1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the financial flow of your company (admin).
|
|
|
|
* @param tile unused
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 the amount of money to receive (if positive), or spend (if negative)
|
|
|
|
* @param p2 unused
|
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
*/
|
|
|
|
CommandCost CmdMoneyCheatAdmin(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
{
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
_cheats.money.been_used = true;
|
|
|
|
SetWindowDirty(WC_CHEATS, 0);
|
|
|
|
}
|
2008-03-22 10:50:50 +00:00
|
|
|
return CommandCost(EXPENSES_OTHER, -(int32)p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 19:11:38 +00:00
|
|
|
/**
|
|
|
|
* Change the value of a cheat setting.
|
|
|
|
* @param tile unused
|
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 the cheat number
|
|
|
|
* @param p2 the cheat value
|
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
|
|
|
*/
|
|
|
|
CommandCost CmdCheatSetting(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
{
|
|
|
|
Cheat *cht = nullptr;
|
|
|
|
switch ((CheatNumbers) p1) {
|
|
|
|
case CHT_EXTRA_DYNAMITE:
|
|
|
|
cht = &_cheats.magic_bulldozer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHT_CROSSINGTUNNELS:
|
|
|
|
cht = &_cheats.crossing_tunnels;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHT_NO_JETCRASH:
|
|
|
|
cht = &_cheats.no_jetcrash;
|
|
|
|
break;
|
|
|
|
|
2020-04-18 09:52:08 +00:00
|
|
|
case CHT_INFLATION_INCOME:
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
_extra_cheats.inflation_income.been_used = true;
|
|
|
|
_economy.inflation_payment = Clamp<uint64>(p2, 1 << 16, MAX_INFLATION);
|
|
|
|
if (_economy.inflation_payment > _economy.inflation_prices) {
|
|
|
|
_economy.inflation_prices = _economy.inflation_payment;
|
|
|
|
_extra_cheats.inflation_cost.been_used = true;
|
|
|
|
}
|
|
|
|
RecomputePrices();
|
|
|
|
SetWindowDirty(WC_CHEATS, 0);
|
|
|
|
}
|
|
|
|
return CommandCost();
|
|
|
|
|
|
|
|
case CHT_INFLATION_COST:
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
_extra_cheats.inflation_cost.been_used = true;
|
|
|
|
_economy.inflation_prices = Clamp<uint64>(p2, 1 << 16, MAX_INFLATION);
|
|
|
|
if (_economy.inflation_payment > _economy.inflation_prices) {
|
|
|
|
_economy.inflation_payment = _economy.inflation_prices;
|
|
|
|
_extra_cheats.inflation_income.been_used = true;
|
|
|
|
}
|
|
|
|
RecomputePrices();
|
|
|
|
SetWindowDirty(WC_CHEATS, 0);
|
|
|
|
}
|
|
|
|
return CommandCost();
|
|
|
|
|
2021-04-11 02:51:30 +00:00
|
|
|
case CHT_STATION_RATING:
|
|
|
|
cht = &_extra_cheats.station_rating;
|
|
|
|
break;
|
|
|
|
|
2021-05-05 00:17:54 +00:00
|
|
|
case CHT_TOWN_RATING:
|
|
|
|
cht = &_extra_cheats.town_rating;
|
|
|
|
break;
|
|
|
|
|
2020-04-14 19:11:38 +00:00
|
|
|
default:
|
|
|
|
return CMD_ERROR;
|
|
|
|
}
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
cht->value = p2;
|
|
|
|
cht->been_used = true;
|
|
|
|
SetWindowDirty(WC_CHEATS, 0);
|
2021-04-11 02:51:30 +00:00
|
|
|
|
|
|
|
if (p1 == CHT_STATION_RATING) {
|
|
|
|
extern void UpdateAllStationRatings();
|
|
|
|
UpdateAllStationRatings();
|
|
|
|
}
|
2021-05-05 00:17:54 +00:00
|
|
|
if (p1 == CHT_TOWN_RATING) {
|
|
|
|
extern void UpdateAllTownRatings();
|
|
|
|
UpdateAllTownRatings();
|
|
|
|
}
|
2020-04-14 19:11:38 +00:00
|
|
|
}
|
|
|
|
return CommandCost();
|
|
|
|
}
|
|
|
|
|
2013-09-21 13:07:42 +00:00
|
|
|
/**
|
|
|
|
* Change the bank bank balance of a company by inserting or removing money without affecting the loan.
|
2021-01-22 09:28:26 +00:00
|
|
|
* @param tile tile to show text effect on (if not 0)
|
2013-09-21 13:07:42 +00:00
|
|
|
* @param flags operation to perform
|
|
|
|
* @param p1 the amount of money to receive (if positive), or spend (if negative)
|
|
|
|
* @param p2 (bit 0-7) - the company ID.
|
|
|
|
* (bit 8-15) - the expenses type which should register the cost/income @see ExpensesType.
|
|
|
|
* @param text unused
|
|
|
|
* @return zero cost or an error
|
|
|
|
*/
|
|
|
|
CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
|
{
|
|
|
|
int32 delta = (int32)p1;
|
|
|
|
CompanyID company = (CompanyID) GB(p2, 0, 8);
|
|
|
|
ExpensesType expenses_type = Extract<ExpensesType, 8, 8>(p2);
|
|
|
|
|
|
|
|
if (!Company::IsValidID(company)) return CMD_ERROR;
|
|
|
|
if (expenses_type >= EXPENSES_END) return CMD_ERROR;
|
|
|
|
if (_current_company != OWNER_DEITY) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
/* Change company bank balance of company. */
|
2019-04-22 08:10:04 +00:00
|
|
|
Backup<CompanyID> cur_company(_current_company, company, FILE_LINE);
|
2013-09-21 13:07:42 +00:00
|
|
|
SubtractMoneyFromCompany(CommandCost(expenses_type, -delta));
|
|
|
|
cur_company.Restore();
|
2021-01-22 09:28:26 +00:00
|
|
|
|
|
|
|
if (tile != 0) {
|
|
|
|
ShowCostOrIncomeAnimation(TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE, GetTilePixelZ(tile), -delta);
|
|
|
|
}
|
2013-09-21 13:07:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-29 20:27:32 +00:00
|
|
|
/* This command doesn't cost anything for deity. */
|
2013-09-21 13:07:42 +00:00
|
|
|
CommandCost zero_cost(expenses_type, 0);
|
|
|
|
return zero_cost;
|
|
|
|
}
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Transfer funds (money) from one company to another.
|
2006-08-28 18:53:03 +00:00
|
|
|
* To prevent abuse in multiplayer games you can only send money to other
|
2013-01-08 22:46:42 +00:00
|
|
|
* companies if you have paid off your loan (either explicitly, or implicitly
|
2005-05-13 17:09:05 +00:00
|
|
|
* given the fact that you have more money than loan).
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-13 17:09:05 +00:00
|
|
|
* @param p1 the amount of money to transfer; max 20.000.000
|
2008-09-30 20:39:50 +00:00
|
|
|
* @param p2 the company to transfer the money to
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2005-05-12 23:46:01 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
2008-05-29 15:13:28 +00:00
|
|
|
if (!_settings_game.economy.give_money) return CMD_ERROR;
|
2007-09-30 17:38:42 +00:00
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
const Company *c = Company::Get(_current_company);
|
2021-02-01 17:07:34 +00:00
|
|
|
CommandCost amount(EXPENSES_OTHER, std::min((Money)p1, (Money)20000000LL));
|
2010-06-05 11:51:34 +00:00
|
|
|
CompanyID dest_company = (CompanyID)p2;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2005-05-13 17:09:05 +00:00
|
|
|
/* You can only transfer funds that is in excess of your loan */
|
2010-04-20 18:02:08 +00:00
|
|
|
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() < 0) return CMD_ERROR;
|
2017-07-03 20:42:14 +00:00
|
|
|
if (!Company::IsValidID(dest_company)) return CMD_ERROR;
|
2004-12-28 09:24:02 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Add money to company */
|
2019-04-22 08:10:04 +00:00
|
|
|
Backup<CompanyID> cur_company(_current_company, dest_company, FILE_LINE);
|
2008-09-30 20:39:50 +00:00
|
|
|
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
2010-05-31 20:22:57 +00:00
|
|
|
cur_company.Restore();
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Subtract money from local-company */
|
2005-05-13 17:09:05 +00:00
|
|
|
return amount;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|