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);
|
||||
|
||||
std::unique_ptr<AIConfig> *config;
|
||||
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
|
||||
config = &_settings_newgame.script_config.ai[company];
|
||||
} else {
|
||||
if (source != SSS_FORCE_GAME) {
|
||||
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 (_game_mode == GM_MENU) source = SSS_FORCE_NEWGAME;
|
||||
|
||||
if (source == SSS_DEFAULT) {
|
||||
Company *c = Company::GetIfValid(company);
|
||||
if (c != nullptr && c->ai_config != nullptr) return c->ai_config.get();
|
||||
}
|
||||
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
|
||||
|
|
|
@ -17,14 +17,12 @@
|
|||
|
||||
/* static */ GameConfig *GameConfig::GetConfig(ScriptSettingSource source)
|
||||
{
|
||||
std::unique_ptr<GameConfig> *config;
|
||||
if (source == SSS_FORCE_NEWGAME || (source == SSS_DEFAULT && _game_mode == GM_MENU)) {
|
||||
config = &_settings_newgame.script_config.game;
|
||||
} else {
|
||||
config = &_settings_game.script_config.game;
|
||||
}
|
||||
if (*config == nullptr) *config = std::make_unique<GameConfig>();
|
||||
return config->get();
|
||||
if (_game_mode == GM_MENU) source = SSS_FORCE_NEWGAME;
|
||||
|
||||
auto &config = (source == SSS_FORCE_NEWGAME) ? _settings_newgame.script_config.game : _settings_game.script_config.game;
|
||||
if (config == nullptr) config = std::make_unique<GameConfig>();
|
||||
|
||||
return config.get();
|
||||
}
|
||||
|
||||
class GameInfo *GameConfig::GetInfo() const
|
||||
|
|
Loading…
Reference in New Issue