mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Simplify AI/GameConfig::GetConfig. (#13900)
Reorganise these methods to reduce nesting and remove a raw pointer to a unique_ptr.pull/13901/head
parent
325f7f9767
commit
ff08a22aa4
|
@ -21,18 +21,17 @@
|
||||||
{
|
{
|
||||||
assert(company < MAX_COMPANIES);
|
assert(company < MAX_COMPANIES);
|
||||||
|
|
||||||
std::unique_ptr<AIConfig> *config;
|
if (_game_mode == GM_MENU) source = SSS_FORCE_NEWGAME;
|
||||||
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
|
|
||||||
config = &_settings_newgame.script_config.ai[company];
|
if (source == SSS_DEFAULT) {
|
||||||
} else {
|
Company *c = Company::GetIfValid(company);
|
||||||
if (source != SSS_FORCE_GAME) {
|
if (c != nullptr && c->ai_config != nullptr) return c->ai_config.get();
|
||||||
Company *c = Company::GetIfValid(company);
|
|
||||||
if (c != nullptr && c->ai_config != nullptr) return c->ai_config.get();
|
|
||||||
}
|
|
||||||
config = &_settings_game.script_config.ai[company];
|
|
||||||
}
|
}
|
||||||
if (*config == nullptr) *config = std::make_unique<AIConfig>();
|
|
||||||
return config->get();
|
auto &config = (source == SSS_FORCE_NEWGAME) ? _settings_newgame.script_config.ai[company] : _settings_game.script_config.ai[company];
|
||||||
|
if (config == nullptr) config = std::make_unique<AIConfig>();
|
||||||
|
|
||||||
|
return config.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
class AIInfo *AIConfig::GetInfo() const
|
class AIInfo *AIConfig::GetInfo() const
|
||||||
|
|
|
@ -17,14 +17,12 @@
|
||||||
|
|
||||||
/* static */ GameConfig *GameConfig::GetConfig(ScriptSettingSource source)
|
/* static */ GameConfig *GameConfig::GetConfig(ScriptSettingSource source)
|
||||||
{
|
{
|
||||||
std::unique_ptr<GameConfig> *config;
|
if (_game_mode == GM_MENU) source = SSS_FORCE_NEWGAME;
|
||||||
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
|
|
||||||
config = &_settings_newgame.script_config.game;
|
auto &config = (source == SSS_FORCE_NEWGAME) ? _settings_newgame.script_config.game : _settings_game.script_config.game;
|
||||||
} else {
|
if (config == nullptr) config = std::make_unique<GameConfig>();
|
||||||
config = &_settings_game.script_config.game;
|
|
||||||
}
|
return config.get();
|
||||||
if (*config == nullptr) *config = std::make_unique<GameConfig>();
|
|
||||||
return config->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GameInfo *GameConfig::GetInfo() const
|
class GameInfo *GameConfig::GetInfo() const
|
||||||
|
|
Loading…
Reference in New Issue