mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: use std::string for script info/library finding
This commit is contained in:
parent
a30f7c83bd
commit
0fd9eb0faa
|
@ -120,9 +120,9 @@ public:
|
|||
/** Wrapper function for AIScanner::GetUniqueAIInfoList */
|
||||
static const ScriptInfoList *GetUniqueInfoList();
|
||||
/** Wrapper function for AIScanner::FindInfo */
|
||||
static class AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
static class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
/** Wrapper function for AIScanner::FindLibrary */
|
||||
static class AILibrary *FindLibrary(const char *library, int version);
|
||||
static class AILibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
/**
|
||||
* Rescans all searchpaths for available AIs. If a used AI is no longer
|
||||
|
|
|
@ -33,7 +33,7 @@ class AIInfo *AIConfig::GetInfo() const
|
|||
return static_cast<class AIInfo *>(ScriptConfig::GetInfo());
|
||||
}
|
||||
|
||||
ScriptInfo *AIConfig::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
ScriptInfo *AIConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return static_cast<ScriptInfo *>(AI::FindInfo(name, version, force_exact_match));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
bool ResetInfo(bool force_exact_match);
|
||||
|
||||
protected:
|
||||
ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) override;
|
||||
ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) override;
|
||||
};
|
||||
|
||||
#endif /* AI_CONFIG_HPP */
|
||||
|
|
|
@ -309,12 +309,12 @@
|
|||
return AI::scanner_info->GetUniqueInfoList();
|
||||
}
|
||||
|
||||
/* static */ AIInfo *AI::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
/* static */ AIInfo *AI::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return AI::scanner_info->FindInfo(name, version, force_exact_match);
|
||||
}
|
||||
|
||||
/* static */ AILibrary *AI::FindLibrary(const char *library, int version)
|
||||
/* static */ AILibrary *AI::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return AI::scanner_library->FindLibrary(library, version);
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ int AIInstance::GetSetting(const char *name)
|
|||
return AIConfig::GetConfig(_current_company)->GetSetting(name);
|
||||
}
|
||||
|
||||
ScriptInfo *AIInstance::FindLibrary(const char *library, int version)
|
||||
ScriptInfo *AIInstance::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return (ScriptInfo *)AI::FindLibrary(library, version);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
void Initialize(class AIInfo *info);
|
||||
|
||||
int GetSetting(const char *name) override;
|
||||
ScriptInfo *FindLibrary(const char *library, int version) override;
|
||||
ScriptInfo *FindLibrary(const std::string &library, int version) override;
|
||||
|
||||
private:
|
||||
void RegisterAPI() override;
|
||||
|
|
|
@ -92,10 +92,10 @@ AIInfo *AIScannerInfo::SelectRandomAI() const
|
|||
#undef GetAIInfo
|
||||
}
|
||||
|
||||
AIInfo *AIScannerInfo::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
AIInfo *AIScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
if (this->info_list.size() == 0) return nullptr;
|
||||
if (name == nullptr) return nullptr;
|
||||
if (name.empty()) return nullptr;
|
||||
|
||||
if (version == -1) {
|
||||
/* We want to load the latest version of this AI; so find it */
|
||||
|
@ -145,7 +145,7 @@ void AIScannerLibrary::RegisterAPI(class Squirrel *engine)
|
|||
AILibrary::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
AILibrary *AIScannerLibrary::FindLibrary(const char *library, int version)
|
||||
AILibrary *AIScannerLibrary::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
* @param force_exact_match Only match name+version, never latest.
|
||||
* @return nullptr if no match found, otherwise the AI that matched.
|
||||
*/
|
||||
class AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
class AIInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
|
||||
/**
|
||||
* Set the Dummy AI.
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
* @param version The version the library should have.
|
||||
* @return The library if found, nullptr otherwise.
|
||||
*/
|
||||
class AILibrary *FindLibrary(const char *library, int version);
|
||||
class AILibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
protected:
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
|
|
|
@ -91,9 +91,9 @@ public:
|
|||
/** Wrapper function for GameScanner::GetUniqueInfoList */
|
||||
static const ScriptInfoList *GetUniqueInfoList();
|
||||
/** Wrapper function for GameScannerInfo::FindInfo */
|
||||
static class GameInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
static class GameInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
/** Wrapper function for GameScanner::FindLibrary */
|
||||
static class GameLibrary *FindLibrary(const char *library, int version);
|
||||
static class GameLibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
/**
|
||||
* Get the current active instance.
|
||||
|
|
|
@ -32,7 +32,7 @@ class GameInfo *GameConfig::GetInfo() const
|
|||
return static_cast<class GameInfo *>(ScriptConfig::GetInfo());
|
||||
}
|
||||
|
||||
ScriptInfo *GameConfig::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
ScriptInfo *GameConfig::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return static_cast<ScriptInfo *>(Game::FindInfo(name, version, force_exact_match));
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
bool ResetInfo(bool force_exact_match);
|
||||
|
||||
protected:
|
||||
ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) override;
|
||||
ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) override;
|
||||
};
|
||||
|
||||
#endif /* GAME_CONFIG_HPP */
|
||||
|
|
|
@ -239,12 +239,12 @@
|
|||
return Game::scanner_info->GetUniqueInfoList();
|
||||
}
|
||||
|
||||
/* static */ GameInfo *Game::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
/* static */ GameInfo *Game::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
return Game::scanner_info->FindInfo(name, version, force_exact_match);
|
||||
}
|
||||
|
||||
/* static */ GameLibrary *Game::FindLibrary(const char *library, int version)
|
||||
/* static */ GameLibrary *Game::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return Game::scanner_library->FindLibrary(library, version);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ int GameInstance::GetSetting(const char *name)
|
|||
return GameConfig::GetConfig()->GetSetting(name);
|
||||
}
|
||||
|
||||
ScriptInfo *GameInstance::FindLibrary(const char *library, int version)
|
||||
ScriptInfo *GameInstance::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
return (ScriptInfo *)Game::FindLibrary(library, version);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
void Initialize(class GameInfo *info);
|
||||
|
||||
int GetSetting(const char *name) override;
|
||||
ScriptInfo *FindLibrary(const char *library, int version) override;
|
||||
ScriptInfo *FindLibrary(const std::string &library, int version) override;
|
||||
|
||||
private:
|
||||
void RegisterAPI() override;
|
||||
|
|
|
@ -33,10 +33,10 @@ void GameScannerInfo::RegisterAPI(class Squirrel *engine)
|
|||
GameInfo::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
GameInfo *GameScannerInfo::FindInfo(const char *name, int version, bool force_exact_match)
|
||||
GameInfo *GameScannerInfo::FindInfo(const std::string &name, int version, bool force_exact_match)
|
||||
{
|
||||
if (this->info_list.size() == 0) return nullptr;
|
||||
if (name == nullptr) return nullptr;
|
||||
if (name.empty()) return nullptr;
|
||||
|
||||
if (version == -1) {
|
||||
/* We want to load the latest version of this Game script; so find it */
|
||||
|
@ -86,7 +86,7 @@ void GameScannerLibrary::RegisterAPI(class Squirrel *engine)
|
|||
GameLibrary::RegisterAPI(engine);
|
||||
}
|
||||
|
||||
GameLibrary *GameScannerLibrary::FindLibrary(const char *library, int version)
|
||||
GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int version)
|
||||
{
|
||||
/* Internally we store libraries as 'library.version' */
|
||||
std::string library_name = fmt::format("{}.{}", library, version);
|
||||
|
|
|
@ -23,7 +23,7 @@ public:
|
|||
* @param force_exact_match Only match name+version, never latest.
|
||||
* @return nullptr if no match found, otherwise the game script that matched.
|
||||
*/
|
||||
class GameInfo *FindInfo(const char *name, int version, bool force_exact_match);
|
||||
class GameInfo *FindInfo(const std::string &name, int version, bool force_exact_match);
|
||||
|
||||
protected:
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
* @param version The version the library should have.
|
||||
* @return The library if found, nullptr otherwise.
|
||||
*/
|
||||
class GameLibrary *FindLibrary(const char *library, int version);
|
||||
class GameLibrary *FindLibrary(const std::string &library, int version);
|
||||
|
||||
protected:
|
||||
std::string GetScriptName(ScriptInfo *info) override;
|
||||
|
|
|
@ -19,8 +19,7 @@
|
|||
|
||||
void ScriptConfig::Change(const char *name, int version, bool force_exact_match, bool is_random)
|
||||
{
|
||||
free(this->name);
|
||||
this->name = (name == nullptr) ? nullptr : stredup(name);
|
||||
this->name = (name == nullptr) ? "" : name;
|
||||
this->info = (name == nullptr) ? nullptr : this->FindInfo(this->name, version, force_exact_match);
|
||||
this->version = (info == nullptr) ? -1 : info->GetVersion();
|
||||
this->is_random = is_random;
|
||||
|
@ -44,7 +43,7 @@ void ScriptConfig::Change(const char *name, int version, bool force_exact_match,
|
|||
|
||||
ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
||||
{
|
||||
this->name = (config->name == nullptr) ? nullptr : stredup(config->name);
|
||||
this->name = config->name;
|
||||
this->info = config->info;
|
||||
this->version = config->version;
|
||||
this->is_random = config->is_random;
|
||||
|
@ -60,7 +59,6 @@ ScriptConfig::ScriptConfig(const ScriptConfig *config)
|
|||
|
||||
ScriptConfig::~ScriptConfig()
|
||||
{
|
||||
free(this->name);
|
||||
this->ResetSettings();
|
||||
this->to_load_data.reset();
|
||||
}
|
||||
|
@ -156,7 +154,7 @@ bool ScriptConfig::IsRandom() const
|
|||
return this->is_random;
|
||||
}
|
||||
|
||||
const char *ScriptConfig::GetName() const
|
||||
const std::string &ScriptConfig::GetName() const
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,6 @@ protected:
|
|||
|
||||
public:
|
||||
ScriptConfig() :
|
||||
name(nullptr),
|
||||
version(-1),
|
||||
info(nullptr),
|
||||
is_random(false),
|
||||
|
@ -159,7 +158,7 @@ public:
|
|||
/**
|
||||
* Get the name of the Script.
|
||||
*/
|
||||
const char *GetName() const;
|
||||
const std::string &GetName() const;
|
||||
|
||||
/**
|
||||
* Get the version of the Script.
|
||||
|
@ -190,7 +189,7 @@ public:
|
|||
ScriptInstance::ScriptData *GetToLoadData();
|
||||
|
||||
protected:
|
||||
const char *name; ///< Name of the Script
|
||||
std::string name; ///< Name of the Script
|
||||
int version; ///< Version of the Script
|
||||
class ScriptInfo *info; ///< ScriptInfo object for related to this Script version
|
||||
SettingValueList settings; ///< List with all setting=>value pairs that are configure for this Script
|
||||
|
@ -207,7 +206,7 @@ protected:
|
|||
* This function should call back to the Scanner in charge of this Config,
|
||||
* to find the ScriptInfo belonging to a name+version.
|
||||
*/
|
||||
virtual ScriptInfo *FindInfo(const char *name, int version, bool force_exact_match) = 0;
|
||||
virtual ScriptInfo *FindInfo(const std::string &name, int version, bool force_exact_match) = 0;
|
||||
};
|
||||
|
||||
#endif /* SCRIPT_CONFIG_HPP */
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
* @param version The version the library should have.
|
||||
* @return The library if found, nullptr otherwise.
|
||||
*/
|
||||
virtual class ScriptInfo *FindLibrary(const char *library, int version) = 0;
|
||||
virtual class ScriptInfo *FindLibrary(const std::string &library, int version) = 0;
|
||||
|
||||
/**
|
||||
* A script in multiplayer waits for the server to handle its DoCommand.
|
||||
|
|
|
@ -1080,7 +1080,7 @@ static void AISaveConfig(IniFile &ini, const char *grpname)
|
|||
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
AIConfig *config = AIConfig::GetConfig(c, AIConfig::SSS_FORCE_NEWGAME);
|
||||
const char *name;
|
||||
std::string name;
|
||||
std::string value = config->SettingsToString();
|
||||
|
||||
if (config->HasScript()) {
|
||||
|
@ -1102,7 +1102,7 @@ static void GameSaveConfig(IniFile &ini, const char *grpname)
|
|||
group->Clear();
|
||||
|
||||
GameConfig *config = GameConfig::GetConfig(AIConfig::SSS_FORCE_NEWGAME);
|
||||
const char *name;
|
||||
std::string name;
|
||||
std::string value = config->SettingsToString();
|
||||
|
||||
if (config->HasScript()) {
|
||||
|
|
Loading…
Reference in New Issue