| 1518 | } |
| 1519 | |
| 1520 | static bool ConReloadAI(std::span<std::string_view> argv) |
| 1521 | { |
| 1522 | if (argv.size() != 2) { |
| 1523 | IConsolePrint(CC_HELP, "Reload an AI. Usage: 'reload_ai <company-id>'."); |
| 1524 | IConsolePrint(CC_HELP, "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."); |
| 1525 | return true; |
| 1526 | } |
| 1527 | |
| 1528 | if (_game_mode != GM_NORMAL) { |
| 1529 | IConsolePrint(CC_ERROR, "AIs can only be managed in a game."); |
| 1530 | return true; |
| 1531 | } |
| 1532 | |
| 1533 | if (_networking && !_network_server) { |
| 1534 | IConsolePrint(CC_ERROR, "Only the server can reload an AI."); |
| 1535 | return true; |
| 1536 | } |
| 1537 | |
| 1538 | auto company_id = ParseCompanyID(argv[1]); |
| 1539 | if (!company_id.has_value()) { |
| 1540 | IConsolePrint(CC_ERROR, "The given company-id is not a valid number."); |
| 1541 | return true; |
| 1542 | } |
| 1543 | |
| 1544 | if (!Company::IsValidID(*company_id)) { |
| 1545 | IConsolePrint(CC_ERROR, "Unknown company. Company range is between 1 and {}.", MAX_COMPANIES); |
| 1546 | return true; |
| 1547 | } |
| 1548 | |
| 1549 | /* In singleplayer mode the player can be in an AI company, after cheating or loading network save with an AI in first slot. */ |
| 1550 | if (Company::IsHumanID(*company_id) || *company_id == _local_company) { |
| 1551 | IConsolePrint(CC_ERROR, "Company is not controlled by an AI."); |
| 1552 | return true; |
| 1553 | } |
| 1554 | |
| 1555 | /* First kill the company of the AI, then start a new one. This should start the current AI again */ |
| 1556 | Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, *company_id, CRR_MANUAL, INVALID_CLIENT_ID); |
| 1557 | Command<CMD_COMPANY_CTRL>::Post(CCA_NEW_AI, *company_id, CRR_NONE, INVALID_CLIENT_ID); |
| 1558 | IConsolePrint(CC_DEFAULT, "AI reloaded."); |
| 1559 | |
| 1560 | return true; |
| 1561 | } |
| 1562 | |
| 1563 | static bool ConStopAI(std::span<std::string_view> argv) |
| 1564 | { |
nothing calls this directly
no test coverage detected