2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
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"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
|
|
|
#include "economy_func.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"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_manager_face.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
|
|
|
#include "company_gui.h"
|
2009-03-04 23:32:23 +00:00
|
|
|
#include "vehicle_base.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/** Change the company manager's face.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-18 18:00:33 +00:00
|
|
|
* @param flags operation to perform
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 face bitmasked
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdSetCompanyManagerFace(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
CompanyManagerFace cmf = (CompanyManagerFace)p2;
|
2007-03-02 01:17:11 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsValidCompanyManagerFace(cmf)) return CMD_ERROR;
|
2007-03-02 01:17:11 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2009-05-16 23:34:14 +00:00
|
|
|
Company::Get(_current_company)->face = cmf;
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/** Change the company's company-colour
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perform
|
2006-09-15 12:27:00 +00:00
|
|
|
* @param p1 bitstuffed:
|
|
|
|
* p1 bits 0-7 scheme to set
|
|
|
|
* p1 bits 8-9 set in use state or first/second colour
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p2 new colour for vehicles, property, etc.
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text unused
|
|
|
|
* @return the cost of this operation or an error
|
2004-08-09 17:04:08 +00:00
|
|
|
*/
|
2009-02-09 21:20:05 +00:00
|
|
|
CommandCost CmdSetCompanyColour(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-04 17:27:38 +00:00
|
|
|
if (p2 >= 16) return CMD_ERROR; // max 16 colours
|
|
|
|
|
2009-02-09 01:06:23 +00:00
|
|
|
Colours colour = (Colours)p2;
|
2008-04-04 17:27:38 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
LiveryScheme scheme = (LiveryScheme)GB(p1, 0, 8);
|
2006-09-15 12:27:00 +00:00
|
|
|
byte state = GB(p1, 8, 2);
|
2005-05-30 15:50:20 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
if (scheme >= LS_END || state >= 3) return CMD_ERROR;
|
|
|
|
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_current_company);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-15 12:27:00 +00:00
|
|
|
/* Ensure no two companies have the same primary colour */
|
|
|
|
if (scheme == LS_DEFAULT && state == 0) {
|
2008-09-30 20:39:50 +00:00
|
|
|
const Company *cc;
|
|
|
|
FOR_ALL_COMPANIES(cc) {
|
|
|
|
if (cc != c && cc->colour == colour) return CMD_ERROR;
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2006-09-15 12:27:00 +00:00
|
|
|
switch (state) {
|
|
|
|
case 0:
|
2008-09-30 20:39:50 +00:00
|
|
|
c->livery[scheme].colour1 = colour;
|
2006-09-15 12:27:00 +00:00
|
|
|
|
|
|
|
/* If setting the first colour of the default scheme, adjust the
|
2008-09-30 20:39:50 +00:00
|
|
|
* original and cached company colours too. */
|
2006-09-15 12:27:00 +00:00
|
|
|
if (scheme == LS_DEFAULT) {
|
2008-09-30 20:39:50 +00:00
|
|
|
_company_colours[_current_company] = colour;
|
|
|
|
c->colour = colour;
|
2006-09-15 12:27:00 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2008-09-30 20:39:50 +00:00
|
|
|
c->livery[scheme].colour2 = colour;
|
2006-09-15 12:27:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2008-09-30 20:39:50 +00:00
|
|
|
c->livery[scheme].in_use = colour != 0;
|
2006-09-15 12:27:00 +00:00
|
|
|
|
|
|
|
/* Now handle setting the default scheme's in_use flag.
|
|
|
|
* This is different to the other schemes, as it signifies if any
|
|
|
|
* scheme is active at all. If this flag is not set, then no
|
|
|
|
* processing of vehicle types occurs at all, and only the default
|
|
|
|
* colours will be used. */
|
|
|
|
|
|
|
|
/* If enabling a scheme, set the default scheme to be in use too */
|
|
|
|
if (colour != 0) {
|
2008-09-30 20:39:50 +00:00
|
|
|
c->livery[LS_DEFAULT].in_use = true;
|
2006-09-15 12:27:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Else loop through all schemes to see if any are left enabled.
|
|
|
|
* If not, disable the default scheme too. */
|
2008-09-30 20:39:50 +00:00
|
|
|
c->livery[LS_DEFAULT].in_use = false;
|
2006-09-15 12:27:00 +00:00
|
|
|
for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->livery[scheme].in_use) {
|
|
|
|
c->livery[LS_DEFAULT].in_use = true;
|
2006-09-15 12:27:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-02-09 02:57:15 +00:00
|
|
|
ResetVehicleColourMap();
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
2009-03-04 23:32:23 +00:00
|
|
|
|
|
|
|
/* Company colour data is indirectly cached. */
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2009-05-31 12:03:14 +00:00
|
|
|
if (v->owner == _current_company) v->InvalidateNewGRFCache();
|
2009-03-04 23:32:23 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +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
|
2009-01-12 17:11:45 +00:00
|
|
|
* @param p1 amount to increase the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
2007-06-14 15:24:34 +00:00
|
|
|
* @param p2 when 0: loans LOAN_INTERVAL
|
|
|
|
* when 1: loans the maximum loan permitting money (press CTRL),
|
2009-01-12 17:11:45 +00:00
|
|
|
* when 2: loans the amount specified in p1
|
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;
|
2007-06-14 15:24:34 +00:00
|
|
|
switch (p2) {
|
|
|
|
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
|
|
|
|
if ((((int32)p1 < LOAN_INTERVAL) || c->current_loan + (int32)p1 > _economy.max_loan || (p1 % LOAN_INTERVAL) != 0)) return CMD_ERROR;
|
|
|
|
loan = p1;
|
|
|
|
break;
|
2007-06-14 15:24:34 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-19 00:05:26 +00:00
|
|
|
/* Overflow protection */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->money + c->current_loan + loan < c->money) 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
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +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
|
2009-01-12 17:11:45 +00:00
|
|
|
* @param p1 amount to decrease the loan with, multitude of LOAN_INTERVAL. Only used when p2 == 2.
|
2007-06-14 15:24:34 +00:00
|
|
|
* @param p2 when 0: pays back LOAN_INTERVAL
|
|
|
|
* when 1: pays back the maximum loan permitting money (press CTRL),
|
2009-01-12 17:11:45 +00:00
|
|
|
* when 2: pays back the amount specified in p1
|
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;
|
2007-06-14 15:24:34 +00:00
|
|
|
switch (p2) {
|
|
|
|
default: return CMD_ERROR; // Invalid method
|
|
|
|
case 0: // Pay back one step
|
2009-01-12 17:11:45 +00:00
|
|
|
loan = min(c->current_loan, (Money)LOAN_INTERVAL);
|
2007-06-14 15:24:34 +00:00
|
|
|
break;
|
|
|
|
case 1: // Pay back as much as possible
|
2008-09-30 20:39:50 +00:00
|
|
|
loan = max(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
|
|
|
|
if ((p1 % LOAN_INTERVAL != 0) || ((int32)p1 < LOAN_INTERVAL)) return CMD_ERROR; // Invalid amount to loan
|
|
|
|
loan = p1;
|
|
|
|
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-06-27 20:53:25 +00:00
|
|
|
static bool IsUniqueCompanyName(const char *name)
|
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
const Company *c;
|
2007-06-27 20:53:25 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
2009-01-10 15:54:07 +00:00
|
|
|
if (c->name != NULL && strcmp(c->name, name) == 0) return false;
|
2007-06-27 20:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the 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
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text the new name or an empty string when resetting to the default
|
|
|
|
* @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 CmdRenameCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-12-28 14:37:19 +00:00
|
|
|
bool reset = StrEmpty(text);
|
2007-06-27 20:53:25 +00:00
|
|
|
|
2008-09-15 19:02:50 +00:00
|
|
|
if (!reset) {
|
2008-12-28 14:37:19 +00:00
|
|
|
if (strlen(text) >= MAX_LENGTH_COMPANY_NAME_BYTES) return CMD_ERROR;
|
2009-08-05 17:59:21 +00:00
|
|
|
if (!IsUniqueCompanyName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
2008-09-15 19:02:50 +00:00
|
|
|
}
|
2005-05-17 20:58:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_current_company);
|
2008-09-30 20:39:50 +00:00
|
|
|
free(c->name);
|
2008-12-28 14:37:19 +00:00
|
|
|
c->name = reset ? NULL : strdup(text);
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
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-06-27 20:53:25 +00:00
|
|
|
static bool IsUniquePresidentName(const char *name)
|
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
const Company *c;
|
2007-06-27 20:53:25 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
2009-01-10 15:54:07 +00:00
|
|
|
if (c->president_name != NULL && strcmp(c->president_name, name) == 0) return false;
|
2007-06-27 20:53:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Change the name of the president.
|
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-11 00:00:27 +00:00
|
|
|
* @param p1 unused
|
|
|
|
* @param p2 unused
|
2009-09-18 14:23:58 +00:00
|
|
|
* @param text the new name or an empty string when resetting to the default
|
|
|
|
* @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 CmdRenamePresident(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-12-28 14:37:19 +00:00
|
|
|
bool reset = StrEmpty(text);
|
2007-06-27 20:53:25 +00:00
|
|
|
|
2008-09-15 19:02:50 +00:00
|
|
|
if (!reset) {
|
2008-12-28 14:37:19 +00:00
|
|
|
if (strlen(text) >= MAX_LENGTH_PRESIDENT_NAME_BYTES) return CMD_ERROR;
|
2009-08-05 17:59:21 +00:00
|
|
|
if (!IsUniquePresidentName(text)) return_cmd_error(STR_ERROR_NAME_MUST_BE_UNIQUE);
|
2008-09-15 19:02:50 +00:00
|
|
|
}
|
2005-05-17 20:58:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2009-05-16 23:34:14 +00:00
|
|
|
Company *c = Company::Get(_current_company);
|
2008-09-30 20:39:50 +00:00
|
|
|
free(c->president_name);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-15 19:02:50 +00:00
|
|
|
if (reset) {
|
2008-09-30 20:39:50 +00:00
|
|
|
c->president_name = NULL;
|
2008-09-15 19:02:50 +00:00
|
|
|
} else {
|
2008-12-28 14:37:19 +00:00
|
|
|
c->president_name = strdup(text);
|
2005-05-15 18:50:55 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->name_1 == STR_SV_UNNAMED && c->name == NULL) {
|
2008-09-15 19:02:50 +00:00
|
|
|
char buf[80];
|
|
|
|
|
2008-12-28 14:37:19 +00:00
|
|
|
snprintf(buf, lengthof(buf), "%s Transport", text);
|
|
|
|
DoCommand(0, 0, 0, DC_EXEC, CMD_RENAME_COMPANY, buf);
|
2008-09-15 19:02:50 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2008-09-15 19:02:50 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
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
|
|
|
|
* @param confirmed whether the user confirms his/her action
|
|
|
|
*/
|
|
|
|
static void AskUnsafeUnpauseCallback(Window *w, bool confirmed)
|
|
|
|
{
|
2009-05-06 15:06:57 +00:00
|
|
|
DoCommandP(0, PM_PAUSED_ERROR, confirmed ? 0 : 1, 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:
|
|
|
|
break;
|
2007-12-04 22:50:07 +00:00
|
|
|
|
2009-11-12 17:44:49 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
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-11-12 20:33:30 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2009-11-12 17:44:49 +00:00
|
|
|
|
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,
|
|
|
|
NULL,
|
|
|
|
AskUnsafeUnpauseCallback
|
|
|
|
);
|
|
|
|
} else {
|
2009-11-12 20:33:30 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
PauseMode prev_mode = _pause_mode;
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2009-05-06 15:06:57 +00:00
|
|
|
if (p2 == 0) {
|
|
|
|
_pause_mode = _pause_mode & ~p1;
|
|
|
|
} else {
|
|
|
|
_pause_mode = _pause_mode | p1;
|
|
|
|
}
|
2009-11-12 20:33:30 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
NetworkHandlePauseChange(prev_mode, (PauseMode)p1);
|
|
|
|
#endif /* ENABLE_NETWORK */
|
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
|
|
|
}
|
|
|
|
|
2005-05-12 23:46:01 +00:00
|
|
|
/** Change the financial flow of your company.
|
|
|
|
* This is normally only enabled in offline mode, but if there is a debug
|
|
|
|
* build, you can cheat (to test).
|
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-12 23:46:01 +00:00
|
|
|
* @param p1 the amount of money to receive (if negative), or spend (if positive)
|
|
|
|
* @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
|
|
|
{
|
2005-05-12 23:46:01 +00:00
|
|
|
#ifndef _DEBUG
|
|
|
|
if (_networking) return CMD_ERROR;
|
|
|
|
#endif
|
2008-03-22 10:50:50 +00:00
|
|
|
return CommandCost(EXPENSES_OTHER, -(int32)p1);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +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
|
2008-09-30 20:39:50 +00:00
|
|
|
* companies if you have paid off your loan (either explicitely, or implicitely
|
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);
|
2008-01-09 16:55:48 +00:00
|
|
|
CommandCost amount(EXPENSES_OTHER, min((Money)p1, (Money)20000000LL));
|
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 */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (c->money - c->current_loan < amount.GetCost() || amount.GetCost() <= 0) return CMD_ERROR;
|
2009-05-17 01:00:56 +00:00
|
|
|
if (!_networking || !Company::IsValidID((CompanyID)p2)) 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 */
|
|
|
|
CompanyID old_company = _current_company;
|
|
|
|
_current_company = (CompanyID)p2;
|
|
|
|
SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost()));
|
|
|
|
_current_company = old_company;
|
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
|
|
|
}
|