(svn r13582) [NoAI] -Add: added 'stop_ai', which stops a company controlled by an AI (Yexo)
--- a/src/console_cmds.cpp Thu Jun 19 11:55:14 2008 +0000
+++ b/src/console_cmds.cpp Thu Jun 19 16:26:56 2008 +0000
@@ -867,7 +867,7 @@
DEF_CONSOLE_CMD(ConStartAI)
{
if (argc == 0) {
- IConsoleHelp("Start a new AI. Usage: 'startai [<AI>]'");
+ IConsoleHelp("Start a new AI. Usage: 'start_ai [<AI>]'");
IConsoleHelp("Start a new AI. If <AI> is given, it starts that specific AI (if found).");
return true;
}
@@ -903,6 +903,37 @@
return true;
}
+DEF_CONSOLE_CMD(ConStopAI)
+{
+ if (argc == 0) {
+ 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. Player 1 is 1, etc.");
+ return true;
+ }
+
+ if (_networking && !_network_server) {
+ IConsoleWarning("Only the server can stop an AI.");
+ return true;
+ }
+
+ PlayerID player_id = (PlayerID)(atoi(argv[1]) - 1);
+ if (!IsValidPlayer(player_id) || !GetPlayer(player_id)->is_active) {
+ IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_PLAYERS);
+ return true;
+ }
+
+ if (IsHumanPlayer(player_id)) {
+ IConsoleWarning("Company is not controlled by an AI.");
+ return true;
+ }
+
+ /* Now kill the company of the AI. */
+ DoCommandP(0, 2, player_id, NULL, CMD_PLAYER_CTRL);
+ IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
+
+ return true;
+}
+
DEF_CONSOLE_CMD(ConRescanAI)
{
if (argc == 0) {
@@ -1445,6 +1476,7 @@
IConsoleCmdRegister("save", ConSave);
IConsoleCmdRegister("saveconfig", ConSaveConfig);
IConsoleCmdRegister("start_ai", ConStartAI);
+ IConsoleCmdRegister("stop_ai", ConStopAI);
IConsoleCmdRegister("ls", ConListFiles);
IConsoleCmdRegister("cd", ConChangeDirectory);
IConsoleCmdRegister("pwd", ConPrintWorkingDirectory);