Doc: update changelog
[openttd-github.git] / src / ai / ai_config.cpp
blobbdb986692e00674bf7b7271157a601485d99d9b7
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file ai_config.cpp Implementation of AIConfig. */
10 #include "../stdafx.h"
11 #include "../company_base.h"
12 #include "../settings_type.h"
13 #include "../string_func.h"
14 #include "ai.hpp"
15 #include "ai_config.hpp"
16 #include "ai_info.hpp"
18 #include "../safeguards.h"
20 /* static */ AIConfig *AIConfig::GetConfig(CompanyID company, ScriptSettingSource source)
22 assert(company < MAX_COMPANIES);
24 AIConfig **config;
25 if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
26 config = &_settings_newgame.ai_config[company];
27 } else {
28 if (source != SSS_FORCE_GAME) {
29 Company *c = Company::GetIfValid(company);
30 if (c != nullptr && c->ai_config != nullptr) return c->ai_config.get();
32 config = &_settings_game.ai_config[company];
34 if (*config == nullptr) *config = new AIConfig();
35 return *config;
38 class AIInfo *AIConfig::GetInfo() const
40 return static_cast<class AIInfo *>(ScriptConfig::GetInfo());
43 ScriptInfo *AIConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
45 return static_cast<ScriptInfo *>(AI::FindInfo(name, version, force_exact_match));
48 bool AIConfig::ResetInfo(bool force_exact_match)
50 this->info = (ScriptInfo *)AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
51 return this->info != nullptr;