MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ConStopAI

Function ConStopAI

src/console_cmds.cpp:1563–1603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1561}
1562
1563static bool ConStopAI(std::span<std::string_view> argv)
1564{
1565 if (argv.size() != 2) {
1566 IConsolePrint(CC_HELP, "Stop an AI. Usage: 'stop_ai <company-id>'.");
1567 IConsolePrint(CC_HELP, "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.");
1568 return true;
1569 }
1570
1571 if (_game_mode != GM_NORMAL) {
1572 IConsolePrint(CC_ERROR, "AIs can only be managed in a game.");
1573 return true;
1574 }
1575
1576 if (_networking && !_network_server) {
1577 IConsolePrint(CC_ERROR, "Only the server can stop an AI.");
1578 return true;
1579 }
1580
1581 auto company_id = ParseCompanyID(argv[1]);
1582 if (!company_id.has_value()) {
1583 IConsolePrint(CC_ERROR, "The given company-id is not a valid number.");
1584 return true;
1585 }
1586
1587 if (!Company::IsValidID(*company_id)) {
1588 IConsolePrint(CC_ERROR, "Unknown company. Company range is between 1 and {}.", MAX_COMPANIES);
1589 return true;
1590 }
1591
1592 /* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */
1593 if (Company::IsHumanID(*company_id) || *company_id == _local_company) {
1594 IConsolePrint(CC_ERROR, "Company is not controlled by an AI.");
1595 return true;
1596 }
1597
1598 /* Now kill the company of the AI. */
1599 Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, *company_id, CRR_MANUAL, INVALID_CLIENT_ID);
1600 IConsolePrint(CC_DEFAULT, "AI stopped, company deleted.");
1601
1602 return true;
1603}
1604
1605static bool ConRescanAI(std::span<std::string_view> argv)
1606{

Callers

nothing calls this directly

Calls 3

ParseCompanyIDFunction · 0.85
IConsolePrintFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected