Core/ScriptMgr: Fix "conditional expression is constant" warning.

* introduced in commit 12d1993994
This commit is contained in:
Naios
2015-11-04 21:16:39 +01:00
parent 2c23a686e3
commit 155a289f05

View File

@@ -125,64 +125,7 @@ class ScriptRegistry
}
}
if (is_script_database_bound<TScript>::value)
{
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
// through a script name (or similar).
uint32 id = sObjectMgr->GetScriptId(script->GetName());
if (id)
{
// Try to find an existing script.
bool existing = false;
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
{
// If the script names match...
if (it->second->GetName() == script->GetName())
{
// ... It exists.
existing = true;
break;
}
}
// If the script isn't assigned -> assign it!
if (!existing)
{
ScriptPointerList[id] = script;
sScriptMgr->IncrementScriptCount();
#ifdef SCRIPTS
UnusedScriptNamesContainer::iterator itr = std::lower_bound(UnusedScriptNames.begin(), UnusedScriptNames.end(), script->GetName());
if (itr != UnusedScriptNames.end() && *itr == script->GetName())
UnusedScriptNames.erase(itr);
#endif
}
else
{
// If the script is already assigned -> delete it!
TC_LOG_ERROR("scripts", "Script '%s' already assigned with the same script name, so the script can't work.",
script->GetName().c_str());
ABORT(); // Error that should be fixed ASAP.
}
}
else
{
// The script uses a script name from database, but isn't assigned to anything.
TC_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str());
// Avoid calling "delete script;" because we are currently in the script constructor
// In a valid scenario this will not happen because every script has a name assigned in the database
UnusedScripts.push_back(script);
return;
}
}
else
{
// We're dealing with a code-only script; just add it.
ScriptPointerList[_scriptIdCounter++] = script;
sScriptMgr->IncrementScriptCount();
}
AddScript(std::integral_constant<bool, is_script_database_bound<TScript>::value>{}, script);
}
// Gets a script by its ID (assigned by ObjectMgr).
@@ -197,6 +140,68 @@ class ScriptRegistry
private:
// Adds a database bound script
static void AddScript(std::true_type, TScript* const script)
{
// Get an ID for the script. An ID only exists if it's a script that is assigned in the database
// through a script name (or similar).
uint32 id = sObjectMgr->GetScriptId(script->GetName());
if (id)
{
// Try to find an existing script.
bool existing = false;
for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it)
{
// If the script names match...
if (it->second->GetName() == script->GetName())
{
// ... It exists.
existing = true;
break;
}
}
// If the script isn't assigned -> assign it!
if (!existing)
{
ScriptPointerList[id] = script;
sScriptMgr->IncrementScriptCount();
#ifdef SCRIPTS
UnusedScriptNamesContainer::iterator itr = std::lower_bound(UnusedScriptNames.begin(), UnusedScriptNames.end(), script->GetName());
if (itr != UnusedScriptNames.end() && *itr == script->GetName())
UnusedScriptNames.erase(itr);
#endif
}
else
{
// If the script is already assigned -> delete it!
TC_LOG_ERROR("scripts", "Script '%s' already assigned with the same script name, so the script can't work.",
script->GetName().c_str());
ABORT(); // Error that should be fixed ASAP.
}
}
else
{
// The script uses a script name from database, but isn't assigned to anything.
TC_LOG_ERROR("sql.sql", "Script named '%s' does not have a script name assigned in database.", script->GetName().c_str());
// Avoid calling "delete script;" because we are currently in the script constructor
// In a valid scenario this will not happen because every script has a name assigned in the database
UnusedScripts.push_back(script);
return;
}
}
// Adds a non database bound script
static void AddScript(std::false_type, TScript* const script)
{
// We're dealing with a code-only script; just add it.
ScriptPointerList[_scriptIdCounter++] = script;
sScriptMgr->IncrementScriptCount();
}
// Counter used for code-only scripts.
static uint32 _scriptIdCounter;
};