OpenTTD Source  14.0-beta1
ai_config.cpp
Go to the documentation of this file.
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  */
7 
10 #include "../stdafx.h"
11 #include "../settings_type.h"
12 #include "../string_func.h"
13 #include "ai.hpp"
14 #include "ai_config.hpp"
15 #include "ai_info.hpp"
16 
17 #include "../safeguards.h"
18 
20 {
21  assert(company < MAX_COMPANIES);
22 
23  AIConfig **config;
24  if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
25  config = &_settings_newgame.ai_config[company];
26  } else {
27  config = &_settings_game.ai_config[company];
28  }
29  if (*config == nullptr) *config = new AIConfig();
30  return *config;
31 }
32 
33 class AIInfo *AIConfig::GetInfo() const
34 {
35  return static_cast<class AIInfo *>(ScriptConfig::GetInfo());
36 }
37 
38 ScriptInfo *AIConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
39 {
40  return static_cast<ScriptInfo *>(AI::FindInfo(name, version, force_exact_match));
41 }
42 
43 bool AIConfig::ResetInfo(bool force_exact_match)
44 {
45  this->info = (ScriptInfo *)AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
46  return this->info != nullptr;
47 }
AIConfig
Definition: ai_config.hpp:16
GameSettings::ai_config
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
Definition: settings_type.h:623
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:152
ai.hpp
ai_info.hpp
ScriptConfig::SSS_DEFAULT
@ SSS_DEFAULT
Get the Script config from the current game mode.
Definition: script_config.hpp:97
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:56
AIConfig::GetConfig
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: ai_config.cpp:19
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
MAX_COMPANIES
@ MAX_COMPANIES
Maximum number of companies.
Definition: company_type.h:23
ScriptConfig::version
int version
Version of the Script.
Definition: script_config.hpp:187
AIConfig::FindInfo
ScriptInfo * FindInfo(const std::string &name, int version, bool force_exact_match) override
This function should call back to the Scanner in charge of this Config, to find the ScriptInfo belong...
Definition: ai_config.cpp:38
ScriptConfig::info
class ScriptInfo * info
ScriptInfo object for related to this Script version.
Definition: script_config.hpp:188
ScriptConfig::SSS_FORCE_NEWGAME
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:98
ScriptInfo::name
std::string name
Full name of the script.
Definition: script_info.hpp:147
ScriptConfig::name
std::string name
Name of the Script.
Definition: script_config.hpp:186
AIInfo
All static information from an AI like name, version, etc.
Definition: ai_info.hpp:16
AI::FindInfo
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition: ai_core.cpp:313
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:56
AIConfig::ResetInfo
bool ResetInfo(bool force_exact_match)
When ever the AI Scanner is reloaded, all infos become invalid.
Definition: ai_config.cpp:43
ai_config.hpp
ScriptConfig::ScriptSettingSource
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
Definition: script_config.hpp:96