aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp154
-rw-r--r--src/server/game/Scripting/ScriptMgr.h313
-rw-r--r--src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp2
3 files changed, 151 insertions, 318 deletions
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<SpellHandlerScript>::AddScript(this);
}
-void AuraHandlerScript::RegisterSelf()
+AuraHandlerScript::AuraHandlerScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<AuraHandlerScript>::AddScript(this);
}
-void ServerScript::RegisterSelf()
+ServerScript::ServerScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<ServerScript>::AddScript(this);
}
-void WorldScript::RegisterSelf()
+WorldScript::WorldScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<WorldScript>::AddScript(this);
}
-void FormulaScript::RegisterSelf()
+FormulaScript::FormulaScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<FormulaScript>::AddScript(this);
}
-void WorldMapScript::RegisterSelf()
+WorldMapScript::WorldMapScript(const char* name, uint32 mapId)
+ : ScriptObject(name), MapScript<Map>(mapId)
{
+ if (GetEntry() && !GetEntry()->IsContinent())
+ sLog.outError("WorldMapScript for map %u is invalid.", mapId);
+
ScriptMgr::ScriptRegistry<WorldMapScript>::AddScript(this);
}
-void InstanceMapScript::RegisterSelf()
+InstanceMapScript::InstanceMapScript(const char* name, uint32 mapId)
+ : ScriptObject(name), MapScript<InstanceMap>(0)
{
+ if (GetEntry() && !GetEntry()->IsDungeon())
+ sLog.outError("InstanceMapScript for map %u is invalid.", mapId);
+
ScriptMgr::ScriptRegistry<InstanceMapScript>::AddScript(this);
}
-void BattlegroundMapScript::RegisterSelf()
+BattlegroundMapScript::BattlegroundMapScript(const char* name, uint32 mapId)
+ : ScriptObject(name), MapScript<BattlegroundMap>(mapId)
{
- ScriptMgr::ScriptRegistry<BattlegroundMapScript>::AddScript(this);
-}
+ if (GetEntry() && !GetEntry()->IsBattleground())
+ sLog.outError("BattlegroundMapScript for map %u is invalid.", mapId);
-void AreaTriggerScript::RegisterSelf()
-{
- ScriptMgr::ScriptRegistry<AreaTriggerScript>::AddScript(this);
+ ScriptMgr::ScriptRegistry<BattlegroundMapScript>::AddScript(this);
}
-void ItemScript::RegisterSelf()
+ItemScript::ItemScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<ItemScript>::AddScript(this);
}
-void CreatureScript::RegisterSelf()
+CreatureScript::CreatureScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<CreatureScript>::AddScript(this);
}
-void GameObjectScript::RegisterSelf()
+GameObjectScript::GameObjectScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<GameObjectScript>::AddScript(this);
}
-void BattlegroundScript::RegisterSelf()
+AreaTriggerScript::AreaTriggerScript(const char* name)
+ : ScriptObject(name)
+{
+ ScriptMgr::ScriptRegistry<AreaTriggerScript>::AddScript(this);
+}
+
+BattlegroundScript::BattlegroundScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<BattlegroundScript>::AddScript(this);
}
-void OutdoorPvPScript::RegisterSelf()
+OutdoorPvPScript::OutdoorPvPScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<OutdoorPvPScript>::AddScript(this);
}
-void CommandScript::RegisterSelf()
+CommandScript::CommandScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<CommandScript>::AddScript(this);
}
-void WeatherScript::RegisterSelf()
+WeatherScript::WeatherScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<WeatherScript>::AddScript(this);
}
-void AuctionHouseScript::RegisterSelf()
+AuctionHouseScript::AuctionHouseScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<AuctionHouseScript>::AddScript(this);
}
-void ConditionScript::RegisterSelf()
+ConditionScript::ConditionScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<ConditionScript>::AddScript(this);
}
-void VehicleScript::RegisterSelf()
+VehicleScript::VehicleScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<VehicleScript>::AddScript(this);
}
-void DynamicObjectScript::RegisterSelf()
+DynamicObjectScript::DynamicObjectScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<DynamicObjectScript>::AddScript(this);
}
-void TransportScript::RegisterSelf()
+TransportScript::TransportScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<TransportScript>::AddScript(this);
}
-void AchievementCriteriaScript::RegisterSelf()
+AchievementCriteriaScript::AchievementCriteriaScript(const char* name)
+ : ScriptObject(name)
{
ScriptMgr::ScriptRegistry<AchievementCriteriaScript>::AddScript(this);
}
-template<class TScript>
-void ScriptMgr::ScriptRegistry<TScript>::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<class TScript> std::map<uint32, TScript*> ScriptMgr::ScriptRegistry<TScript>::ScriptPointerList;
template<class TScript> uint32 ScriptMgr::ScriptRegistry<TScript>::_scriptIdCounter;
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index c226e783d38..c98a1574d9d 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -91,7 +91,7 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit *pTarget = NULL);
MyScriptType(const char* name, uint32 someId)
: ScriptObject(name), _someId(someId)
{
- RegisterSelf();
+ ScriptMgr::ScriptRegistry<MyScriptType>::AddScript(this);
}
public:
@@ -107,14 +107,6 @@ void DoScriptText(int32 textEntry, WorldObject* pSource, Unit *pTarget = NULL);
virtual void OnAnotherEvent(uint32 someArg) = 0;
}
- RegisterSelf() should be defined in ScriptMgr.cpp, and simply registers the script
- with ScriptRegistry:
-
- void MyScriptType::RegisterSelf()
- {
- ScriptMgr::ScriptRegistry<MyScriptType>::AddScript(this);
- }
-
Next, you need to add a specialization for ScriptRegistry. Put this in the bottom of
ScriptMgr.cpp:
@@ -168,9 +160,6 @@ class ScriptObject
protected:
- // Call this to register the script with ScriptMgr.
- virtual void RegisterSelf() = 0;
-
ScriptObject(const char* name)
: _name(std::string(name))
{
@@ -204,17 +193,9 @@ template<class TObject> class UpdatableScript
class SpellHandlerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- SpellHandlerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ SpellHandlerScript(const char* name);
public:
@@ -226,17 +207,9 @@ class SpellHandlerScript : public ScriptObject
class AuraHandlerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AuraHandlerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AuraHandlerScript(const char* name);
public:
@@ -248,17 +221,9 @@ class AuraHandlerScript : public ScriptObject
class ServerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ServerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ServerScript(const char* name);
public:
@@ -290,17 +255,9 @@ class ServerScript : public ScriptObject
class WorldScript : public ScriptObject, public UpdatableScript<void>
{
- private:
-
- void RegisterSelf();
-
protected:
- WorldScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ WorldScript(const char* name);
public:
@@ -331,17 +288,9 @@ class WorldScript : public ScriptObject, public UpdatableScript<void>
class FormulaScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- FormulaScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ FormulaScript(const char* name);
public:
@@ -412,38 +361,16 @@ template<class TMap> class MapScript : public UpdatableScript<TMap>
class WorldMapScript : public ScriptObject, public MapScript<Map>
{
- private:
-
- void RegisterSelf();
-
protected:
- WorldMapScript(const char* name, uint32 mapId)
- : ScriptObject(name), MapScript<Map>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsContinent())
- sLog.outError("WorldMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
+ WorldMapScript(const char* name, uint32 mapId);
};
class InstanceMapScript : public ScriptObject, public MapScript<InstanceMap>
{
- private:
-
- void RegisterSelf();
-
protected:
- InstanceMapScript(const char* name, uint32 mapId = 0)
- : ScriptObject(name), MapScript<InstanceMap>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsDungeon())
- sLog.outError("InstanceMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
+ InstanceMapScript(const char* name, uint32 mapId);
public:
@@ -457,31 +384,14 @@ class BattlegroundMapScript : public ScriptObject, public MapScript<Battleground
{
protected:
- BattlegroundMapScript(const char* name, uint32 mapId)
- : ScriptObject(name), MapScript<BattlegroundMap>(mapId)
- {
- if (GetEntry() && !GetEntry()->IsBattleground())
- sLog.outError("BattlegroundMapScript for map %u is invalid.", mapId);
- else
- RegisterSelf();
- }
-
- void RegisterSelf();
+ BattlegroundMapScript(const char* name, uint32 mapId);
};
class ItemScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ItemScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ItemScript(const char* name);
public:
@@ -502,17 +412,9 @@ class ItemScript : public ScriptObject
class CreatureScript : public ScriptObject, public UpdatableScript<Creature>
{
- private:
-
- void RegisterSelf();
-
protected:
- CreatureScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ CreatureScript(const char* name);
public:
@@ -551,17 +453,9 @@ class CreatureScript : public ScriptObject, public UpdatableScript<Creature>
class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
{
- private:
-
- void RegisterSelf();
-
protected:
- GameObjectScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ GameObjectScript(const char* name);
public:
@@ -594,17 +488,9 @@ class GameObjectScript : public ScriptObject, public UpdatableScript<GameObject>
class AreaTriggerScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AreaTriggerScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AreaTriggerScript(const char* name);
public:
@@ -616,17 +502,9 @@ class AreaTriggerScript : public ScriptObject
class BattlegroundScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- BattlegroundScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ BattlegroundScript(const char* name);
public:
@@ -638,17 +516,9 @@ class BattlegroundScript : public ScriptObject
class OutdoorPvPScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- OutdoorPvPScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ OutdoorPvPScript(const char* name);
public:
@@ -660,17 +530,9 @@ class OutdoorPvPScript : public ScriptObject
class CommandScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- CommandScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ CommandScript(const char* name);
public:
@@ -680,17 +542,9 @@ class CommandScript : public ScriptObject
class WeatherScript : public ScriptObject, public UpdatableScript<Weather>
{
- private:
-
- void RegisterSelf();
-
protected:
- WeatherScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ WeatherScript(const char* name);
public:
@@ -702,17 +556,9 @@ class WeatherScript : public ScriptObject, public UpdatableScript<Weather>
class AuctionHouseScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AuctionHouseScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AuctionHouseScript(const char* name);
public:
@@ -731,17 +577,9 @@ class AuctionHouseScript : public ScriptObject
class ConditionScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- ConditionScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ ConditionScript(const char* name);
public:
@@ -753,17 +591,9 @@ class ConditionScript : public ScriptObject
class VehicleScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- VehicleScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ VehicleScript(const char* name);
public:
@@ -791,32 +621,16 @@ class VehicleScript : public ScriptObject
class DynamicObjectScript : public ScriptObject, public UpdatableScript<DynamicObject>
{
- private:
-
- void RegisterSelf();
-
protected:
- DynamicObjectScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ DynamicObjectScript(const char* name);
};
class TransportScript : public ScriptObject, public UpdatableScript<Transport>
{
- private:
-
- void RegisterSelf();
-
protected:
- TransportScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ TransportScript(const char* name);
public:
@@ -837,17 +651,9 @@ class TransportScript : public ScriptObject, public UpdatableScript<Transport>
class AchievementCriteriaScript : public ScriptObject
{
- private:
-
- void RegisterSelf();
-
protected:
- AchievementCriteriaScript(const char* name)
- : ScriptObject(name)
- {
- RegisterSelf();
- }
+ AchievementCriteriaScript(const char* name);
public:
@@ -1047,6 +853,76 @@ class ScriptMgr
// after server startup.
static ScriptMap ScriptPointerList;
+ static void 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' has same memory pointer as '%s'.",
+ script->GetName().c_str(), it->second->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();
+ }
+ }
+
// Gets a script by its ID (assigned by ObjectMgr).
static TScript* GetScriptById(uint32 id)
{
@@ -1056,9 +932,6 @@ class ScriptMgr
return NULL;
}
-
- // Attempts to add a new script to the list.
- static void AddScript(TScript* const script);
};
};
diff --git a/src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp b/src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp
index e64c40cc550..83a9f497c39 100644
--- a/src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp
+++ b/src/server/scripts/Northrend/Nexus/EyeOfEternity/instance_eye_of_eternity.cpp
@@ -21,7 +21,7 @@
class instance_eye_of_eternity : public InstanceMapScript
{
public:
- instance_eye_of_eternity() : InstanceMapScript("instance_eye_of_eternity") { }
+ instance_eye_of_eternity() : InstanceMapScript("instance_eye_of_eternity", 616) { }
InstanceScript* GetInstanceData_InstanceMapScript(Map* pMap)
{