(svn r25788) -Feature: [Script] Game Scripts can now charge fees and give money to companies

This commit is contained in:
zuu
2013-09-21 13:07:42 +00:00
parent 01dea4ec37
commit ab69c6c2a0
9 changed files with 114 additions and 9 deletions

View File

@@ -12,6 +12,7 @@
#include "stdafx.h"
#include "command_func.h"
#include "economy_func.h"
#include "cmd_helper.h"
#include "window_func.h"
#include "textbuf_gui.h"
#include "network/network.h"
@@ -204,6 +205,38 @@ CommandCost CmdMoneyCheat(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
return CommandCost(EXPENSES_OTHER, -(int32)p1);
}
/**
* Change the bank bank balance of a company by inserting or removing money without affecting the loan.
* @param tile unused
* @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. */
Backup<CompanyByte> cur_company(_current_company, company, FILE_LINE);
SubtractMoneyFromCompany(CommandCost(expenses_type, -delta));
cur_company.Restore();
}
/* This command doesn't cost anyting for deity. */
CommandCost zero_cost(expenses_type, 0);
return zero_cost;
}
/**
* Transfer funds (money) from one company to another.
* To prevent abuse in multiplayer games you can only send money to other