OpenTTD Source 20260218-master-g2123fca5ea
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
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 if (source == SSS_DEFAULT && _game_mode == GM_MENU) source = SSS_FORCE_NEWGAME;
21
22 auto &config = (source == SSS_FORCE_NEWGAME) ? _settings_newgame.script_config.game : _settings_game.script_config.game;
23 if (config == nullptr) config = std::make_unique<GameConfig>();
24
25 return config.get();
26}
27
29{
30 return static_cast<class GameInfo *>(ScriptConfig::GetInfo());
31}
32
33ScriptInfo *GameConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
34{
35 return static_cast<ScriptInfo *>(Game::FindInfo(name, version, force_exact_match));
36}
37
38bool GameConfig::ResetInfo(bool force_exact_match)
39{
40 this->info = (ScriptInfo *)Game::FindInfo(this->name, force_exact_match ? this->version : -1, force_exact_match);
41 return this->info != nullptr;
42}
ScriptInfo * FindInfo(const std::string &name, int version, bool force_exact_match) override
Finds the appropriate ScriptInfo for a given script name and version.
bool ResetInfo(bool force_exact_match)
When ever the Game Scanner is reloaded, all infos become invalid.
static GameConfig * GetConfig(ScriptSettingSource source=SSS_DEFAULT)
Get the script configuration.
class GameInfo * GetInfo() const
Get the ScriptInfo linked to this ScriptConfig.
All static information from an Game like name, version, etc.
Definition game_info.hpp:16
static class GameInfo * FindInfo(const std::string &name, int version, bool force_exact_match)
Finds the appropriate ScriptInfo for a given script name and version.
ScriptSettingSource
Where to get the config from, either default (depends on current game mode) or force either newgame o...
@ 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.
Base functions for all Games.
GameConfig stores the configuration settings of every Game.
GameInfo keeps track of all information of an Game, like Author, Description, ...
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
Types related to global configuration settings.
Definition of base types and functions in a cross-platform compatible way.