Changeset - r10750:3efcb08f2f72
[Not reviewed]
master
0 1 0
truebrain - 16 years ago 2009-01-14 15:39:05
truebrain@openttd.org
(svn r15083) -Add [NoAI]: added a console command to reload an AI (requested by Zuu)
1 file changed with 38 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -908,12 +908,49 @@ DEF_CONSOLE_CMD(ConStartAI)
 
	/* Start a new AI company */
 
	DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 

	
 
	return true;
 
}
 

	
 
DEF_CONSOLE_CMD(ConReloadAI)
 
{
 
	if (argc != 2) {
 
		IConsoleHelp("Reload an AI. Usage: 'reload_ai <company-id>'");
 
		IConsoleHelp("Reload 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.");
 
		return true;
 
	}
 

	
 
	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 = (CompanyID)(atoi(argv[1]) - 1);
 
	if (!IsValidCompanyID(company_id)) {
 
		IConsolePrintF(CC_DEFAULT, "Unknown company. Company range is between 1 and %d.", MAX_COMPANIES);
 
		return true;
 
	}
 

	
 
	if (IsHumanCompany(company_id)) {
 
		IConsoleWarning("Company is not controlled by an AI.");
 
		return true;
 
	}
 

	
 
	/* First kill the company of the AI, then start a new one. This should start the current AI again */
 
	DoCommandP(0, 2, company_id, CMD_COMPANY_CTRL);
 
	DoCommandP(0, 1, 0, CMD_COMPANY_CTRL);
 
	IConsolePrint(CC_DEFAULT, "AI reloaded.");
 

	
 
	return true;
 
}
 

	
 
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.");
 
		return true;
 
@@ -1476,12 +1513,13 @@ void IConsoleStdLibRegister()
 
	IConsoleCmdRegister("list_aliases", ConListAliases);
 
	IConsoleCmdRegister("newgame",      ConNewGame);
 
	IConsoleCmdRegister("restart",      ConRestart);
 
	IConsoleCmdRegister("getseed",      ConGetSeed);
 
	IConsoleCmdRegister("getdate",      ConGetDate);
 
	IConsoleCmdRegister("quit",         ConExit);
 
	IConsoleCmdRegister("reload_ai",    ConReloadAI);
 
	IConsoleCmdRegister("rescan_ai",    ConRescanAI);
 
	IConsoleCmdRegister("resetengines", ConResetEngines);
 
	IConsoleCmdRegister("return",       ConReturn);
 
	IConsoleCmdRegister("screenshot",   ConScreenShot);
 
	IConsoleCmdRegister("script",       ConScript);
 
	IConsoleCmdRegister("scrollto",     ConScrollToTile);
0 comments (0 inline, 0 general)