|
@@ -26,50 +26,50 @@
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @param p1 unused
|
|
|
* @param p2 face bitmasked
|
|
|
*/
|
|
|
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
CompanyManagerFace cmf = (CompanyManagerFace)p2;
|
|
|
|
|
|
if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
GetCompany(_current_company)->face = cmf;
|
|
|
Company::Get(_current_company)->face = cmf;
|
|
|
MarkWholeScreenDirty();
|
|
|
}
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
/** Change the company's company-colour
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @param p1 bitstuffed:
|
|
|
* p1 bits 0-7 scheme to set
|
|
|
* p1 bits 8-9 set in use state or first/second colour
|
|
|
* @param p2 new colour for vehicles, property, etc.
|
|
|
*/
|
|
|
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
if (p2 >= 16) return CMD_ERROR; // max 16 colours
|
|
|
|
|
|
Colours colour = (Colours)p2;
|
|
|
|
|
|
LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
|
|
|
byte state = GB(p1, 8, 2);
|
|
|
|
|
|
if (scheme >= LS_END || state >= 3) return CMD_ERROR;
|
|
|
|
|
|
Company *c = GetCompany(_current_company);
|
|
|
Company *c = Company::Get(_current_company);
|
|
|
|
|
|
/* Ensure no two companies have the same primary colour */
|
|
|
if (scheme == LS_DEFAULT && state == 0) {
|
|
|
const Company *cc;
|
|
|
FOR_ALL_COMPANIES(cc) {
|
|
|
if (cc != c && cc->colour == colour) return CMD_ERROR;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
switch (state) {
|
|
|
case 0:
|
|
@@ -129,25 +129,25 @@ CommandCost CmdSetCompanyColour(TileInde
|
|
|
}
|
|
|
|
|
|
/** Increase the loan of your company.
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @param p1 amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
|
|
* @param p2 when 0: loans LOAN_INTERVAL
|
|
|
* when 1: loans the maximum loan permitting money (press CTRL),
|
|
|
* when 2: loans the amount specified in p1
|
|
|
*/
|
|
|
CommandCost CmdIncreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
Company *c = GetCompany(_current_company);
|
|
|
Company *c = Company::Get(_current_company);
|
|
|
|
|
|
if (c->current_loan >= _economy.max_loan) {
|
|
|
SetDParam(0, _economy.max_loan);
|
|
|
return_cmd_error(STR_ERROR_MAXIMUM_PERMITTED_LOAN);
|
|
|
}
|
|
|
|
|
|
Money loan;
|
|
|
switch (p2) {
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
case 0: // Take some extra loan
|
|
|
loan = LOAN_INTERVAL;
|
|
|
break;
|
|
@@ -173,25 +173,25 @@ CommandCost CmdIncreaseLoan(TileIndex ti
|
|
|
}
|
|
|
|
|
|
/** Decrease the loan of your company.
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @param p1 amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
|
|
* @param p2 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
|
|
|
*/
|
|
|
CommandCost CmdDecreaseLoan(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
Company *c = GetCompany(_current_company);
|
|
|
Company *c = Company::Get(_current_company);
|
|
|
|
|
|
if (c->current_loan == 0) return_cmd_error(STR_ERROR_LOAN_ALREADY_REPAYED);
|
|
|
|
|
|
Money loan;
|
|
|
switch (p2) {
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
case 0: // Pay back one step
|
|
|
loan = min(c->current_loan, (Money)LOAN_INTERVAL);
|
|
|
break;
|
|
|
case 1: // Pay back as much as possible
|
|
|
loan = max(min(c->current_loan, c->money), (Money)LOAN_INTERVAL);
|
|
|
loan -= loan % LOAN_INTERVAL;
|
|
@@ -233,25 +233,25 @@ static bool IsUniqueCompanyName(const ch
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
CommandCost CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
bool reset = StrEmpty(text);
|
|
|
|
|
|
if (!reset) {
|
|
|
if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
|
|
|
if (!IsUniqueCompanyName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Company *c = GetCompany(_current_company);
|
|
|
Company *c = Company::Get(_current_company);
|
|
|
free(c->name);
|
|
|
c->name = reset ? NULL : strdup(text);
|
|
|
MarkWholeScreenDirty();
|
|
|
}
|
|
|
|
|
|
return CommandCost();
|
|
|
}
|
|
|
|
|
|
static bool IsUniquePresidentName(const char *name)
|
|
|
{
|
|
|
const Company *c;
|
|
|
|
|
@@ -269,25 +269,25 @@ static bool IsUniquePresidentName(const
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
CommandCost CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
bool reset = StrEmpty(text);
|
|
|
|
|
|
if (!reset) {
|
|
|
if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
|
|
|
if (!IsUniquePresidentName(text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
|
|
}
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
Company *c = GetCompany(_current_company);
|
|
|
Company *c = Company::Get(_current_company);
|
|
|
free(c->president_name);
|
|
|
|
|
|
if (reset) {
|
|
|
c->president_name = NULL;
|
|
|
} else {
|
|
|
c->president_name = strdup(text);
|
|
|
|
|
|
if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
|
|
|
char buf[80];
|
|
|
|
|
|
snprintf(buf, lengthof(buf), "%s Transport", text);
|
|
|
DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf);
|
|
@@ -373,25 +373,25 @@ CommandCost CmdMoneyCheat(TileIndex tile
|
|
|
* To prevent abuse in multiplayer games you can only send money to other
|
|
|
* companies if you have paid off your loan (either explicitely, or implicitely
|
|
|
* given the fact that you have more money than loan).
|
|
|
* @param tile unused
|
|
|
* @param flags operation to perform
|
|
|
* @param p1 the amount of money to transfer; max 20.000.000
|
|
|
* @param p2 the company to transfer the money to
|
|
|
*/
|
|
|
CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
|
|
{
|
|
|
if (!_settings_game.economy.give_money) return CMD_ERROR;
|
|
|
|
|
|
const Company *c = GetCompany(_current_company);
|
|
|
const Company *c = Company::Get(_current_company);
|
|
|
CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
|
|
|
|
|
|
/* You can only transfer funds that is in excess of your loan */
|
|
|
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
|
|
|
if (!_networking || !IsValidCompanyID((CompanyID)p2)) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
/* Add money to company */
|
|
|
CompanyID old_company = _current_company;
|
|
|
_current_company = (CompanyID)p2;
|
|
|
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
|
|
_current_company = old_company;
|