OpenTTD Source 20241224-master-gee860a5c8e
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 "../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"
17
18#include "../safeguards.h"
19
21{
22 assert(company < MAX_COMPANIES);
23
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();
31 }
32 config = &_settings_game.ai_config[company];
33 }
34 if (*config == nullptr) *config = new AIConfig();
35 return *config;
36}
37
38class AIInfo *AIConfig::GetInfo() const
39{
40 return static_cast<class AIInfo *>(ScriptConfig::GetInfo());
41}
42
43ScriptInfo *AIConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
44{
45 return static_cast<ScriptInfo *>(AI::FindInfo(name, version, force_exact_match));
46}
47
48bool AIConfig::ResetInfo(bool force_exact_match)
49{
50 this->info = (ScriptInfo *)AI::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
51 return this->info != nullptr;
52}
Base functions for all AIs.
AIConfig stores the configuration settings of every AI.
AIInfo keeps track of all information of an AI, like Author, Description, ...
static AIConfig * GetConfig(CompanyID company, ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition ai_config.cpp:20
bool ResetInfo(bool force_exact_match)
When ever the AI Scanner is reloaded, all infos become invalid.
Definition ai_config.cpp:48
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:43
All static information from an AI like name, version, etc.
Definition ai_info.hpp:16
static class AIInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Wrapper function for AIScanner::FindInfo.
Definition ai_core.cpp:316
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
@ SSS_FORCE_GAME
Get the Script config from the current game.
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
@ SSS_DEFAULT
Get the Script config from the current game mode.
int version
Version of the Script.
class ScriptInfo * info
ScriptInfo object for related to this Script version.
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
std::string name
Name of the Script.
All static information from an Script like name, version, etc.
int version
Version of the script.
std::string name
Full name of the script.
Owner
Enum for all companies/owners.
@ MAX_COMPANIES
Maximum number of companies.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:58
class AIConfig * ai_config[MAX_COMPANIES]
settings per company
static Titem * GetIfValid(size_t index)
Returns Titem with given index.