@@ -1273,25 +1273,25 @@ struct AIDebugWindow : public Window {
if (IsInsideMM(widget, WID_AID_COMPANY_BUTTON_START, WID_AID_COMPANY_BUTTON_END + 1)) {
ChangeToAI((CompanyID)(widget - WID_AID_COMPANY_BUTTON_START));
}
switch (widget) {
case WID_AID_SCRIPT_GAME:
ChangeToAI(OWNER_DEITY);
break;
case WID_AID_RELOAD_TOGGLE:
if (ai_debug_company == OWNER_DEITY) break;
/* First kill the company of the AI, then start a new one. This should start the current AI again */
DoCommandP(0, CCA_DELETE | ai_debug_company << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_DELETE | ai_debug_company << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_NEW_AI | ai_debug_company << 16, 0, CMD_COMPANY_CTRL);
case WID_AID_SETTINGS:
ShowAISettingsWindow(ai_debug_company);
case WID_AID_BREAK_STR_ON_OFF_BTN:
this->break_check_enabled = !this->break_check_enabled;
this->InvalidateData(-1);
@@ -798,28 +798,27 @@ void CompanyAdminUpdate(const Company *c
*/
void CompanyAdminRemove(CompanyID company_id, CompanyRemoveReason reason)
{
if (_network_server) NetworkAdminCompanyRemove(company_id, (AdminCompanyRemoveReason)reason);
/**
* Control the companies: add, delete, etc.
* @param tile unused
* @param flags operation to perform
* @param p1 various functionality
* - bits 0..15: CompanyCtrlAction
* - bits 16..24: CompanyID
* @param p2 various depending on CompanyCtrlAction
* - bits 0..31: ClientID (with CCA_NEW)
* - bits 0..1: CompanyRemoveReason (with CCA_DELETE)
* - bits 16..23: CompanyID
* - bits 24..31: CompanyRemoveReason (with CCA_DELETE)
* @param p2 ClientID
* @param text unused
* @return the cost of this operation or an error
CommandCost CmdCompanyCtrl(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
InvalidateWindowData(WC_COMPANY_LEAGUE, 0, 0);
CompanyID company_id = (CompanyID)GB(p1, 16, 8);
switch ((CompanyCtrlAction)GB(p1, 0, 16)) {
case CCA_NEW: { // Create a new company
/* This command is only executed in a multiplayer game */
if (!_networking) return CMD_ERROR;
@@ -871,25 +870,25 @@ CommandCost CmdCompanyCtrl(TileIndex til
case CCA_NEW_AI: { // Make a new AI company
if (!(flags & DC_EXEC)) return CommandCost();
if (company_id != INVALID_COMPANY && (company_id >= MAX_COMPANIES || Company::IsValidID(company_id))) return CMD_ERROR;
Company *c = DoStartupNewCompany(true, company_id);
if (c != NULL) NetworkServerNewCompany(c, NULL);
case CCA_DELETE: { // Delete a company
CompanyRemoveReason reason = (CompanyRemoveReason)GB(p2, 0, 2);
CompanyRemoveReason reason = (CompanyRemoveReason)GB(p1, 24, 8);
if (reason >= CRR_END) return CMD_ERROR;
Company *c = Company::GetIfValid(company_id);
if (c == NULL) return CMD_ERROR;
/* Delete any open window of the company */
DeleteCompanyWindows(c->index);
CompanyNewsInformation *cni = MallocT<CompanyNewsInformation>(1);
cni->FillData(c);
@@ -816,25 +816,25 @@ DEF_CONSOLE_CMD(ConResetCompany)
if (NetworkCompanyHasClients(index)) {
IConsoleError("Cannot remove company: a client is connected to that company.");
return false;
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (ci->client_playas == index) {
IConsoleError("Cannot remove company: the server is connected to that company.");
return true;
/* It is safe to remove this company */
DoCommandP(0, CCA_DELETE | index << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_DELETE | index << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "Company deleted.");
DEF_CONSOLE_CMD(ConNetworkClients)
if (argc == 0) {
IConsoleHelp("Get a list of connected clients including their ID, name, company-id, and IP. Usage: 'clients'");
@@ -1191,25 +1191,25 @@ DEF_CONSOLE_CMD(ConReloadAI)
CompanyID company_id = (CompanyID)(atoi(argv[1]) - 1);
if (!Company::IsValidID(company_id)) {
IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
if (Company::IsHumanID(company_id)) {
IConsoleWarning("Company is not controlled by an AI.");
DoCommandP(0, CCA_DELETE | company_id << 16, CRR_MANUAL, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0,CMD_COMPANY_CTRL);
DoCommandP(0, CCA_NEW_AI | company_id << 16, 0, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI reloaded.");
DEF_CONSOLE_CMD(ConStopAI)
if (argc != 2) {
IConsoleHelp("Stop an AI. Usage: 'stop_ai <company-id>'");
IConsoleHelp("Stop the AI with the given company id. For company-id's, see the list of companies from the dropdown menu. Company 1 is 1, etc.");
@@ -1228,25 +1228,25 @@ DEF_CONSOLE_CMD(ConStopAI)
if (Company::IsHumanID(company_id) || company_id == _local_company) {
/* Now kill the company of the AI. */
DoCommandP(0, CCA_DELETE | company_id << 16 | CRR_MANUAL << 24, 0, CMD_COMPANY_CTRL);
IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
DEF_CONSOLE_CMD(ConRescanAI)
IConsoleHelp("Rescan the AI dir for scripts. Usage: 'rescan_ai'");
@@ -631,25 +631,25 @@ static void CompanyCheckBankrupt(Company
/* Actually remove the company, but not when we're a network client.
* In case of network clients we will be getting a command from the
* server. It is done in this way as we are called from the
* StateGameLoop which can't change the current company, and thus
* updating the local company triggers an assert later on. In the
* case of a network game the command will be processed at a time
* that changing the current company is okay. In case of single
* player we are sure (the above check) that we are not the local
* company and thus we won't be moved. */
if (!_networking || _network_server) DoCommandP(0, CCA_DELETE | (c->index << 16), CRR_BANKRUPT, CMD_COMPANY_CTRL);
if (!_networking || _network_server) DoCommandP(0, CCA_DELETE | (c->index << 16) | (CRR_BANKRUPT << 24), 0, CMD_COMPANY_CTRL);
* Update the finances of all companies.
* Pay for the stations, update the history graph, update ratings and company values, and deal with bankruptcy.
static void CompaniesGenStatistics()
/* Check for bankruptcy each month */
@@ -1664,39 +1664,39 @@ static void NetworkAutoCleanCompanies()
/* Go through all the companies */
FOR_ALL_COMPANIES(c) {
/* Skip the non-active once */
if (c->is_ai) continue;
if (!clients_in_company[c->index]) {
/* The company is empty for one month more */
_network_company_states[c->index].months_empty++;
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
if (_settings_client.network.autoclean_unprotected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_unprotected && StrEmpty(_network_company_states[c->index].password)) {
/* Shut the company down */
DoCommandP(0, CCA_DELETE | c->index << 16, CRR_AUTOCLEAN, CMD_COMPANY_CTRL);
DoCommandP(0, CCA_DELETE | c->index << 16 | CRR_AUTOCLEAN << 24, 0, CMD_COMPANY_CTRL);
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no password", c->index + 1);
/* Is the company empty for autoclean_protected-months, and there is a protection? */
if (_settings_client.network.autoclean_protected != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_protected && !StrEmpty(_network_company_states[c->index].password)) {
/* Unprotect the company */
_network_company_states[c->index].password[0] = '\0';
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", c->index + 1);
_network_company_states[c->index].months_empty = 0;
NetworkServerUpdateCompanyPassworded(c->index, false);
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d with no vehicles", c->index + 1);
} else {
/* It is not empty, reset the date */
* Check whether a name is unique, and otherwise try to make it unique.
* @param new_name The name to check/modify.
Status change: