From 70fc93da7b022f441b92d83fa2f4df48c2be2ae4 Mon Sep 17 00:00:00 2001 From: XTZGZoReX Date: Mon, 9 Aug 2010 19:53:21 +0200 Subject: * Get rid of virtual function calls completely, seeing as they weren't necessary. Thanks to Ge0rG and Derex for enlightening me about this..... * Also add map ID for EoE instance script (thanks Silinoron). --HG-- branch : trunk --- src/server/game/Scripting/ScriptMgr.cpp | 154 ++++++++++++-------------------- 1 file changed, 57 insertions(+), 97 deletions(-) (limited to 'src/server/game/Scripting/ScriptMgr.cpp') diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 3f16c503e20..0bffcd5a1fd 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -1066,187 +1066,147 @@ bool ScriptMgr::OnCriteriaCheck(AchievementCriteriaData const* data, Player* sou return tmpscript->OnCheck(source, target); } -void SpellHandlerScript::RegisterSelf() +SpellHandlerScript::SpellHandlerScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void AuraHandlerScript::RegisterSelf() +AuraHandlerScript::AuraHandlerScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void ServerScript::RegisterSelf() +ServerScript::ServerScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void WorldScript::RegisterSelf() +WorldScript::WorldScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void FormulaScript::RegisterSelf() +FormulaScript::FormulaScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void WorldMapScript::RegisterSelf() +WorldMapScript::WorldMapScript(const char* name, uint32 mapId) + : ScriptObject(name), MapScript(mapId) { + if (GetEntry() && !GetEntry()->IsContinent()) + sLog.outError("WorldMapScript for map %u is invalid.", mapId); + ScriptMgr::ScriptRegistry::AddScript(this); } -void InstanceMapScript::RegisterSelf() +InstanceMapScript::InstanceMapScript(const char* name, uint32 mapId) + : ScriptObject(name), MapScript(0) { + if (GetEntry() && !GetEntry()->IsDungeon()) + sLog.outError("InstanceMapScript for map %u is invalid.", mapId); + ScriptMgr::ScriptRegistry::AddScript(this); } -void BattlegroundMapScript::RegisterSelf() +BattlegroundMapScript::BattlegroundMapScript(const char* name, uint32 mapId) + : ScriptObject(name), MapScript(mapId) { - ScriptMgr::ScriptRegistry::AddScript(this); -} + if (GetEntry() && !GetEntry()->IsBattleground()) + sLog.outError("BattlegroundMapScript for map %u is invalid.", mapId); -void AreaTriggerScript::RegisterSelf() -{ - ScriptMgr::ScriptRegistry::AddScript(this); + ScriptMgr::ScriptRegistry::AddScript(this); } -void ItemScript::RegisterSelf() +ItemScript::ItemScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void CreatureScript::RegisterSelf() +CreatureScript::CreatureScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void GameObjectScript::RegisterSelf() +GameObjectScript::GameObjectScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void BattlegroundScript::RegisterSelf() +AreaTriggerScript::AreaTriggerScript(const char* name) + : ScriptObject(name) +{ + ScriptMgr::ScriptRegistry::AddScript(this); +} + +BattlegroundScript::BattlegroundScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void OutdoorPvPScript::RegisterSelf() +OutdoorPvPScript::OutdoorPvPScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void CommandScript::RegisterSelf() +CommandScript::CommandScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void WeatherScript::RegisterSelf() +WeatherScript::WeatherScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void AuctionHouseScript::RegisterSelf() +AuctionHouseScript::AuctionHouseScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void ConditionScript::RegisterSelf() +ConditionScript::ConditionScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void VehicleScript::RegisterSelf() +VehicleScript::VehicleScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void DynamicObjectScript::RegisterSelf() +DynamicObjectScript::DynamicObjectScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void TransportScript::RegisterSelf() +TransportScript::TransportScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -void AchievementCriteriaScript::RegisterSelf() +AchievementCriteriaScript::AchievementCriteriaScript(const char* name) + : ScriptObject(name) { ScriptMgr::ScriptRegistry::AddScript(this); } -template -void ScriptMgr::ScriptRegistry::AddScript(TScript* const script) -{ - ASSERT(script); - - // See if the script is using the same memory as another script. If this happens, it means that - // someone forgot to allocate new memory for a script. - for (ScriptMapIterator it = ScriptPointerList.begin(); it != ScriptPointerList.end(); ++it) - { - if (it->second == script) - { - sLog.outError("Script '%s' forgot to allocate memory, so this script and/or the script before that can't work.", - script->GetName().c_str()); - - return; - } - } - - if (script->IsDatabaseBound()) - { - // 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 = GetScriptId(script->GetName().c_str()); - 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(); - } - else - { - // If the script is already assigned -> delete it! - sLog.outError("Script '%s' already assigned with the same script name, so the script can't work.", - script->GetName().c_str()); - - delete script; - } - } - else - { - // The script uses a script name from database, but isn't assigned to anything. - if (script->GetName().find("example") == std::string::npos) - sLog.outErrorDb("Script named '%s' does not have a script name assigned in database.", - script->GetName().c_str()); - - delete script; - } - } - else - { - // We're dealing with a code-only script; just add it. - ScriptPointerList[_scriptIdCounter++] = script; - sScriptMgr.IncrementScriptCount(); - } -} - // Instantiate static members of ScriptMgr::ScriptRegistry. template std::map ScriptMgr::ScriptRegistry::ScriptPointerList; template uint32 ScriptMgr::ScriptRegistry::_scriptIdCounter; -- cgit v1.2.3