Index: src/console_cmds.cpp =================================================================== --- src/console_cmds.cpp (revision 21200) +++ src/console_cmds.cpp (working copy) @@ -1072,6 +1072,50 @@ return true; } +DEF_CONSOLE_CMD(ConStartAllAIs) +{ + if (_game_mode != GM_NORMAL) { + IConsoleWarning("AIs can only be managed in a game."); + return true; + } + + if (Company::GetNumItems() == CompanyPool::MAX_SIZE) { + IConsoleWarning("Can't start a new AI (no more free slots)."); + return true; + } + + if (_networking && !_network_server) { + IConsoleWarning("Only the server can start a new AI."); + return true; + } + + if (_networking && !_settings_game.ai.ai_in_multiplayer) { + IConsoleWarning("AIs are not allowed in multiplayer by configuration."); + IConsoleWarning("Switch AI -> AI in multiplayer to True."); + return true; + } + + if (!AI::CanStartNew()) { + IConsoleWarning("Can't start a new AI."); + return true; + } + + int n = 0; + Company *c; + /* Find the next free slot */ + FOR_ALL_COMPANIES(c) { + if (c->index > n++) + { + /* Current compagny already exists, so we mustn't start it */ + continue; + } + /* Start a new AI company */ + DoCommandP(0, 1 | INVALID_COMPANY << 16, 0, CMD_COMPANY_CTRL); + } + + return true; +} + DEF_CONSOLE_CMD(ConReloadAI) { if (argc != 2) { @@ -1109,6 +1153,34 @@ return true; } +DEF_CONSOLE_CMD(ConReloadAllAIs) +{ + if (_game_mode != GM_NORMAL) { + IConsoleWarning("AIs can only be managed in a game."); + return true; + } + + if (_networking && !_network_server) { + IConsoleWarning("Only the server can reload an AI."); + return true; + } + + CompanyID company_id; + Company *c; + FOR_ALL_COMPANIES(c) { + company_id = c->index; + if (Company::IsValidID(company_id) && !Company::IsHumanID(company_id)) { + /* First kill the company of the AI, then start a new one. This should start the current AI again */ + DoCommandP(0, 2 | company_id << 16, 0, CMD_COMPANY_CTRL); + DoCommandP(0, 1 | company_id << 16, 0, CMD_COMPANY_CTRL); + } + } + + IConsolePrint(CC_DEFAULT, "All AIs reloaded."); + + return true; +} + DEF_CONSOLE_CMD(ConStopAI) { if (argc != 2) { @@ -1145,6 +1217,33 @@ return true; } +DEF_CONSOLE_CMD(ConStopAllAIs) +{ + if (_game_mode != GM_NORMAL) { + IConsoleWarning("AIs can only be managed in a game."); + return true; + } + + if (_networking && !_network_server) { + IConsoleWarning("Only the server can stop an AI."); + return true; + } + + CompanyID company_id; + Company *c; + FOR_ALL_COMPANIES(c) { + company_id = c->index; + if (Company::IsValidID(company_id) && !Company::IsHumanID(company_id)) { + /* Now kill the company of the AI. */ + DoCommandP(0, 2 | company_id << 16, 0, CMD_COMPANY_CTRL); + IConsolePrintF(CC_DEFAULT, "AI stopped, company %d deleted.", company_id); + } + + } + + return true; +} + DEF_CONSOLE_CMD(ConRescanAI) { if (argc == 0) { @@ -1778,11 +1877,14 @@ IConsoleAliasRegister("developer", "setting developer %+"); #ifdef ENABLE_AI - IConsoleCmdRegister("list_ai", ConListAI); - IConsoleCmdRegister("reload_ai", ConReloadAI); - IConsoleCmdRegister("rescan_ai", ConRescanAI); - IConsoleCmdRegister("start_ai", ConStartAI); - IConsoleCmdRegister("stop_ai", ConStopAI); + IConsoleCmdRegister("list_ai", ConListAI); + IConsoleCmdRegister("reload_ai", ConReloadAI); + IConsoleCmdRegister("reload_all_ais", ConReloadAllAIs); + IConsoleCmdRegister("rescan_ai", ConRescanAI); + IConsoleCmdRegister("start_ai", ConStartAI); + IConsoleCmdRegister("start_all_ais", ConStartAllAIs); + IConsoleCmdRegister("stop_ai", ConStopAI); + IConsoleCmdRegister("stop_all_ais", ConStopAllAIs); #endif /* ENABLE_AI */ /* networking functions */