OpenTTD Source: src/game/game_config.cpp Source File

OpenTTD Source 12.2

game_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 "game.hpp"
13 #include "game_config.hpp"
14 #include "game_info.hpp"
15
16 #include "../safeguards.h"
17
18 /* static */ GameConfig *GameConfig::GetConfig(ScriptSettingSource source)
19 {
20 GameConfig **config;
21 if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
22 config = &_settings_newgame.game_config;
23 } else {
24 config = &_settings_game.game_config;
25 }
26 if (*config == nullptr) *config = new GameConfig();
27 return *config;
28 }
29
30 class GameInfo *GameConfig::GetInfo() const
31 {
32 return static_cast<class GameInfo *>(ScriptConfig::GetInfo());
33 }
34
35 ScriptInfo *GameConfig::FindInfo(const char *name, int version, bool force_exact_match)
36 {
37 return static_cast<ScriptInfo *>(Game::FindInfo(name, version, force_exact_match));
38 }
39
40 bool GameConfig::ResetInfo(bool force_exact_match)
41 {
42 this->info = (ScriptInfo *)Game::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
43 return this->info != nullptr;
44 }
game.hpp
Game::FindInfo
static class GameInfo * FindInfo(const char *name, int version, bool force_exact_match)
Wrapper function for GameScannerInfo::FindInfo.
Definition: game_core.cpp:248
game_info.hpp
GameSettings::game_config
class GameConfig * game_config
settings for gamescript
Definition: settings_type.h:582
ScriptInfo::version
int version
Version of the script.
Definition: script_info.hpp:161
ScriptConfig::SSS_DEFAULT
@ SSS_DEFAULT
Get the Script config from the current game mode.
Definition: script_config.hpp:103
ScriptConfig::GetInfo
class ScriptInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
Definition: script_config.cpp:68
GameConfig
Definition: game_config.hpp:15
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
ScriptConfig::version
int version
Version of the Script.
Definition: script_config.hpp:190
ScriptConfig::info
class ScriptInfo * info
ScriptInfo object for related to this Script version.
Definition: script_config.hpp:191
GameConfig::ResetInfo
bool ResetInfo(bool force_exact_match)
When ever the Game Scanner is reloaded, all infos become invalid.
Definition: game_config.cpp:40
GameConfig::GetConfig
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the config of a company.
Definition: game_config.cpp:18
ScriptConfig::SSS_FORCE_NEWGAME
@ SSS_FORCE_NEWGAME
Get the newgame Script config.
Definition: script_config.hpp:104
GameInfo
All static information from an Game like name, version, etc.
Definition: game_info.hpp:16
ScriptConfig::name
const char * name
Name of the Script.
Definition: script_config.hpp:189
GameConfig::FindInfo
ScriptInfo * FindInfo(const char *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: game_config.cpp:35
ScriptInfo::name
const char * name
Full name of the script.
Definition: script_info.hpp:156
ScriptInfo
All static information from an Script like name, version, etc.
Definition: script_info.hpp:30
game_config.hpp
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:54
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:102