[10909] Code style cleanups in scripting related functions

This commit is contained in:
zergtmn 2010-12-23 18:59:43 +05:00
parent a84d67a389
commit a1e0111638
5 changed files with 89 additions and 82 deletions

View file

@ -4555,28 +4555,28 @@ void ObjectMgr::LoadQuestLocales()
void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
{
if(sWorld.IsScriptScheduled()) // function don't must be called in time scripts use.
if (sWorld.IsScriptScheduled()) // function don't must be called in time scripts use.
return;
sLog.outString( "%s :", tablename);
sLog.outString("%s :", tablename);
scripts.clear(); // need for reload support
QueryResult *result = WorldDatabase.PQuery( "SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o FROM %s", tablename );
QueryResult *result = WorldDatabase.PQuery("SELECT id, delay, command, datalong, datalong2, datalong3, datalong4, data_flags, dataint, dataint2, dataint3, dataint4, x, y, z, o FROM %s", tablename);
uint32 count = 0;
if( !result )
if (!result)
{
barGoLink bar( 1 );
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString( ">> Loaded %u script definitions", count );
sLog.outString(">> Loaded %u script definitions", count);
return;
}
barGoLink bar( (int)result->GetRowCount() );
barGoLink bar((int)result->GetRowCount());
do
{
@ -4641,7 +4641,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
}
}
// if(!GetMangosStringLocale(tmp.dataint)) will checked after db_script_string loading
// if (!GetMangosStringLocale(tmp.dataint)) will be checked after db_script_string loading
break;
}
case SCRIPT_COMMAND_EMOTE:
@ -4735,11 +4735,11 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
continue;
}
if (info->type==GAMEOBJECT_TYPE_FISHINGNODE ||
info->type==GAMEOBJECT_TYPE_FISHINGHOLE ||
info->type==GAMEOBJECT_TYPE_DOOR ||
info->type==GAMEOBJECT_TYPE_BUTTON ||
info->type==GAMEOBJECT_TYPE_TRAP)
if (info->type == GAMEOBJECT_TYPE_FISHINGNODE ||
info->type == GAMEOBJECT_TYPE_FISHINGHOLE ||
info->type == GAMEOBJECT_TYPE_DOOR ||
info->type == GAMEOBJECT_TYPE_BUTTON ||
info->type == GAMEOBJECT_TYPE_TRAP)
{
sLog.outErrorDb("Table `%s` have gameobject type (%u) unsupported by command SCRIPT_COMMAND_RESPAWN_GAMEOBJECT for script id %u", tablename, info->id, tmp.id);
continue;
@ -4778,7 +4778,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
continue;
}
if (info->type!=GAMEOBJECT_TYPE_DOOR)
if (info->type != GAMEOBJECT_TYPE_DOOR)
{
sLog.outErrorDb("Table `%s` has gameobject type (%u) non supported by command %s for script id %u", tablename, info->id, (tmp.command == SCRIPT_COMMAND_OPEN_DOOR ? "SCRIPT_COMMAND_OPEN_DOOR" : "SCRIPT_COMMAND_CLOSE_DOOR"), tmp.id);
continue;
@ -4992,50 +4992,50 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename)
ScriptMap emptyMap;
scripts[tmp.id] = emptyMap;
}
scripts[tmp.id].insert(std::pair<uint32, ScriptInfo>(tmp.delay, tmp));
scripts[tmp.id].insert(ScriptMap::value_type(tmp.delay, tmp));
++count;
} while( result->NextRow() );
} while(result->NextRow());
delete result;
sLog.outString();
sLog.outString( ">> Loaded %u script definitions", count );
sLog.outString(">> Loaded %u script definitions", count);
}
void ObjectMgr::LoadGameObjectScripts()
{
LoadScripts(sGameObjectScripts, "gameobject_scripts");
LoadScripts(sGameObjectScripts, "gameobject_scripts");
// check ids
for(ScriptMapMap::const_iterator itr = sGameObjectScripts.begin(); itr != sGameObjectScripts.end(); ++itr)
{
if(!GetGOData(itr->first))
sLog.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id",itr->first);
if (!GetGOData(itr->first))
sLog.outErrorDb("Table `gameobject_scripts` has not existing gameobject (GUID: %u) as script id", itr->first);
}
}
void ObjectMgr::LoadQuestEndScripts()
{
LoadScripts(sQuestEndScripts, "quest_end_scripts");
LoadScripts(sQuestEndScripts, "quest_end_scripts");
// check ids
for(ScriptMapMap::const_iterator itr = sQuestEndScripts.begin(); itr != sQuestEndScripts.end(); ++itr)
{
if(!GetQuestTemplate(itr->first))
sLog.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id",itr->first);
if (!GetQuestTemplate(itr->first))
sLog.outErrorDb("Table `quest_end_scripts` has not existing quest (Id: %u) as script id", itr->first);
}
}
void ObjectMgr::LoadQuestStartScripts()
{
LoadScripts(sQuestStartScripts,"quest_start_scripts");
LoadScripts(sQuestStartScripts, "quest_start_scripts");
// check ids
for(ScriptMapMap::const_iterator itr = sQuestStartScripts.begin(); itr != sQuestStartScripts.end(); ++itr)
{
if(!GetQuestTemplate(itr->first))
sLog.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id",itr->first);
if (!GetQuestTemplate(itr->first))
sLog.outErrorDb("Table `quest_start_scripts` has not existing quest (Id: %u) as script id", itr->first);
}
}
@ -5048,9 +5048,9 @@ void ObjectMgr::LoadSpellScripts()
{
SpellEntry const* spellInfo = sSpellStore.LookupEntry(itr->first);
if(!spellInfo)
if (!spellInfo)
{
sLog.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id",itr->first);
sLog.outErrorDb("Table `spell_scripts` has not existing spell (Id: %u) as script id", itr->first);
continue;
}
@ -5070,7 +5070,7 @@ void ObjectMgr::LoadSpellScripts()
}
if (!found)
sLog.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect",itr->first,SPELL_EFFECT_SCRIPT_EFFECT);
sLog.outErrorDb("Table `spell_scripts` has unsupported spell (Id: %u) without SPELL_EFFECT_SCRIPT_EFFECT (%u) spell effect", itr->first, SPELL_EFFECT_SCRIPT_EFFECT);
}
}
@ -5082,19 +5082,19 @@ void ObjectMgr::LoadEventScripts()
// Load all possible script entries from gameobjects
for(uint32 i = 1; i < sGOStorage.MaxEntry; ++i)
if (GameObjectInfo const * goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i))
if (GameObjectInfo const* goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i))
if (uint32 eventId = goInfo->GetEventScriptId())
evt_scripts.insert(eventId);
// Load all possible script entries from spells
for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
{
SpellEntry const * spell = sSpellStore.LookupEntry(i);
SpellEntry const* spell = sSpellStore.LookupEntry(i);
if (spell)
{
for(int j = 0; j < MAX_EFFECT_INDEX; ++j)
{
if( spell->Effect[j] == SPELL_EFFECT_SEND_EVENT )
if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT)
{
if (spell->EffectMiscValue[j])
evt_scripts.insert(spell->EffectMiscValue[j]);
@ -5670,22 +5670,22 @@ void ObjectMgr::LoadTavernAreaTriggers()
void ObjectMgr::LoadAreaTriggerScripts()
{
mAreaTriggerScripts.clear(); // need for reload case
m_AreaTriggerScripts.clear(); // need for reload case
QueryResult *result = WorldDatabase.Query("SELECT entry, ScriptName FROM scripted_areatrigger");
uint32 count = 0;
if (!result)
{
barGoLink bar( 1 );
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString( ">> Loaded %u scripted areatrigger", count );
sLog.outString(">> Loaded %u scripted areatrigger", count);
return;
}
barGoLink bar( (int)result->GetRowCount() );
barGoLink bar((int)result->GetRowCount());
do
{
@ -5694,62 +5694,61 @@ void ObjectMgr::LoadAreaTriggerScripts()
Field *fields = result->Fetch();
uint32 Trigger_ID = fields[0].GetUInt32();
uint32 triggerId = fields[0].GetUInt32();
const char *scriptName = fields[1].GetString();
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(Trigger_ID);
if (!atEntry)
if (!sAreaTriggerStore.LookupEntry(triggerId))
{
sLog.outErrorDb("Table `scripted_areatrigger` has area trigger (ID:%u) not listed in `AreaTrigger.dbc`.", Trigger_ID);
sLog.outErrorDb("Table `scripted_areatrigger` has area trigger (ID: %u) not listed in `AreaTrigger.dbc`.", triggerId);
continue;
}
mAreaTriggerScripts[Trigger_ID] = GetScriptId(scriptName);
} while( result->NextRow() );
m_AreaTriggerScripts[triggerId] = GetScriptId(scriptName);
} while(result->NextRow());
delete result;
sLog.outString();
sLog.outString( ">> Loaded %u areatrigger scripts", count );
sLog.outString(">> Loaded %u areatrigger scripts", count);
}
void ObjectMgr::LoadEventIdScripts()
{
mEventIdScripts.clear(); // need for reload case
m_EventIdScripts.clear(); // need for reload case
QueryResult *result = WorldDatabase.Query("SELECT id, ScriptName FROM scripted_event_id");
uint32 count = 0;
if (!result)
{
barGoLink bar( 1 );
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString( ">> Loaded %u scripted event id", count );
sLog.outString(">> Loaded %u scripted event id", count);
return;
}
barGoLink bar( (int)result->GetRowCount() );
barGoLink bar((int)result->GetRowCount());
// TODO: remove duplicate code below, same way to collect event id's used in LoadEventScripts()
std::set<uint32> evt_scripts;
// Load all possible event entries from gameobjects
for(uint32 i = 1; i < sGOStorage.MaxEntry; ++i)
if (GameObjectInfo const * goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i))
if (GameObjectInfo const* goInfo = sGOStorage.LookupEntry<GameObjectInfo>(i))
if (uint32 eventId = goInfo->GetEventScriptId())
evt_scripts.insert(eventId);
// Load all possible event entries from spells
for(uint32 i = 1; i < sSpellStore.GetNumRows(); ++i)
{
SpellEntry const * spell = sSpellStore.LookupEntry(i);
SpellEntry const* spell = sSpellStore.LookupEntry(i);
if (spell)
{
for(int j = 0; j < MAX_EFFECT_INDEX; ++j)
{
if( spell->Effect[j] == SPELL_EFFECT_SEND_EVENT )
if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT)
{
if (spell->EffectMiscValue[j])
evt_scripts.insert(spell->EffectMiscValue[j]);
@ -5788,13 +5787,13 @@ void ObjectMgr::LoadEventIdScripts()
sLog.outErrorDb("Table `scripted_event_id` has id %u not referring to any gameobject_template type 10 data2 field, type 3 data6 field, type 13 data 2 field or any spell effect %u or path taxi node data",
eventId, SPELL_EFFECT_SEND_EVENT);
mEventIdScripts[eventId] = GetScriptId(scriptName);
} while( result->NextRow() );
m_EventIdScripts[eventId] = GetScriptId(scriptName);
} while(result->NextRow());
delete result;
sLog.outString();
sLog.outString( ">> Loaded %u scripted event id", count );
sLog.outString(">> Loaded %u scripted event id", count);
}
uint32 ObjectMgr::GetNearestTaxiNode( float x, float y, float z, uint32 mapid, Team team )
@ -8216,19 +8215,20 @@ bool ObjectMgr::CheckDeclinedNames( std::wstring mainpart, DeclinedName const& n
return true;
}
uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 trigger_id)
uint32 ObjectMgr::GetAreaTriggerScriptId(uint32 triggerId) const
{
AreaTriggerScriptMap::const_iterator i = mAreaTriggerScripts.find(trigger_id);
if(i!= mAreaTriggerScripts.end())
return i->second;
AreaTriggerScriptMap::const_iterator itr = m_AreaTriggerScripts.find(triggerId);
if (itr != m_AreaTriggerScripts.end())
return itr->second;
return 0;
}
uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId)
uint32 ObjectMgr::GetEventIdScriptId(uint32 eventId) const
{
EventIdScriptMap::const_iterator i = mEventIdScripts.find(eventId);
if (i!= mEventIdScripts.end())
return i->second;
EventIdScriptMap::const_iterator itr = m_EventIdScripts.find(eventId);
if (itr != m_EventIdScripts.end())
return itr->second;
return 0;
}
@ -9580,16 +9580,16 @@ void ObjectMgr::LoadScriptNames()
"UNION "
"SELECT DISTINCT(ScriptName) FROM instance_template WHERE ScriptName <> ''");
if( !result )
if (!result)
{
barGoLink bar( 1 );
barGoLink bar(1);
bar.step();
sLog.outString();
sLog.outErrorDb(">> Loaded empty set of Script Names!");
return;
}
barGoLink bar( (int)result->GetRowCount() );
barGoLink bar((int)result->GetRowCount());
uint32 count = 0;
do
@ -9605,14 +9605,19 @@ void ObjectMgr::LoadScriptNames()
sLog.outString( ">> Loaded %d Script Names", count );
}
uint32 ObjectMgr::GetScriptId(const char *name)
uint32 ObjectMgr::GetScriptId(const char *name) const
{
// use binary search to find the script name in the sorted vector
// assume "" is the first element
if(!name) return 0;
if (!name)
return 0;
ScriptNameMap::const_iterator itr =
std::lower_bound(m_scriptNames.begin(), m_scriptNames.end(), name);
if(itr == m_scriptNames.end() || *itr != name) return 0;
if (itr == m_scriptNames.end() || *itr != name)
return 0;
return uint32(itr - m_scriptNames.begin());
}
@ -9692,9 +9697,9 @@ void ObjectMgr::RemoveArenaTeam( uint32 Id )
}
// Functions for scripting access
uint32 GetAreaTriggerScriptId(uint32 trigger_id)
uint32 GetAreaTriggerScriptId(uint32 triggerId)
{
return sObjectMgr.GetAreaTriggerScriptId(trigger_id);
return sObjectMgr.GetAreaTriggerScriptId(triggerId);
}
uint32 GetEventIdScriptId(uint32 eventId)
@ -9720,7 +9725,7 @@ uint32 MANGOS_DLL_SPEC GetScriptId(const char *name)
return sObjectMgr.GetScriptId(name);
}
ObjectMgr::ScriptNameMap & GetScriptNames()
ObjectMgr::ScriptNameMap const& GetScriptNames()
{
return sObjectMgr.GetScriptNames();
}