diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index 660a6e138f..d1cc955395 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -214,25 +214,30 @@ if (!_settings_game.ai_config[c]->ResetInfo(true)) { Debug(script, 0, "After a reload, the AI by the name '{}' was no longer found, and removed from the list.", _settings_game.ai_config[c]->GetName()); _settings_game.ai_config[c]->Change(std::nullopt); - if (Company::IsValidAiID(c)) { - /* The code belonging to an already running AI was deleted. We can only do - * one thing here to keep everything sane and that is kill the AI. After - * killing the offending AI we start a random other one in it's place, just - * like what would happen if the AI was missing during loading. */ - AI::Stop(c); - AI::StartNew(c); - } - } else if (Company::IsValidAiID(c)) { - /* Update the reference in the Company struct. */ - Company::Get(c)->ai_info = _settings_game.ai_config[c]->GetInfo(); } } + if (_settings_newgame.ai_config[c] != nullptr && _settings_newgame.ai_config[c]->HasScript()) { if (!_settings_newgame.ai_config[c]->ResetInfo(false)) { Debug(script, 0, "After a reload, the AI by the name '{}' was no longer found, and removed from the list.", _settings_newgame.ai_config[c]->GetName()); _settings_newgame.ai_config[c]->Change(std::nullopt); } } + + if (Company::IsValidAiID(c) && Company::Get(c)->ai_config != nullptr) { + AIConfig *config = Company::Get(c)->ai_config.get(); + if (!config->ResetInfo(true)) { + /* The code belonging to an already running AI was deleted. We can only do + * one thing here to keep everything sane and that is kill the AI. After + * killing the offending AI we start a random other one in it's place, just + * like what would happen if the AI was missing during loading. */ + AI::Stop(c); + AI::StartNew(c); + } else { + /* Update the reference in the Company struct. */ + Company::Get(c)->ai_info = config->GetInfo(); + } + } } }