aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Scripting/ScriptMgr.h
diff options
context:
space:
mode:
authorSeyden <saiifii@live.de>2017-07-20 00:15:02 +0200
committerTreeston <treeston.mmoc@gmail.com>2017-07-20 00:15:02 +0200
commita9174d5eb75b4e0f28542c44b797fcacddc7ab64 (patch)
treeea5ff3b422d33373d9c28eb3a897635ddf2455a9 /src/server/game/Scripting/ScriptMgr.h
parenta6e46c1c2ef491cd4cce39be47445e9da194e84e (diff)
Core/Scripts: Implement generic script loaders (and script registry macros) to greatly reduce code duplication (#19526)
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.h')
-rw-r--r--src/server/game/Scripting/ScriptMgr.h68
1 files changed, 66 insertions, 2 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index 020df6d54ac..eea4d7cc39c 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -205,10 +205,10 @@ class TC_GAME_API SpellScriptLoader : public ScriptObject
public:
// Should return a fully valid SpellScript pointer.
- virtual SpellScript* GetSpellScript() const { return NULL; }
+ virtual SpellScript* GetSpellScript() const { return nullptr; }
// Should return a fully valid AuraScript pointer.
- virtual AuraScript* GetAuraScript() const { return NULL; }
+ virtual AuraScript* GetAuraScript() const { return nullptr; }
};
class TC_GAME_API ServerScript : public ScriptObject
@@ -1175,6 +1175,70 @@ class TC_GAME_API ScriptMgr
std::string _currentContext;
};
+template <class S>
+class GenericSpellScriptLoader : public SpellScriptLoader
+{
+ public:
+ GenericSpellScriptLoader(char const* name) : SpellScriptLoader(name) { }
+ SpellScript* GetSpellScript() const override { return new S(); }
+};
+#define RegisterSpellScript(spell_script) new GenericSpellScriptLoader<spell_script>(#spell_script)
+
+template <class A>
+class GenericAuraScriptLoader : public SpellScriptLoader
+{
+ public:
+ GenericAuraScriptLoader(char const* name) : SpellScriptLoader(name) { }
+ AuraScript* GetAuraScript() const override { return new A(); }
+};
+#define RegisterAuraScript(aura_script) new GenericAuraScriptLoader<aura_script>(#aura_script)
+
+template <class S, class A>
+class GenericSpellAndAuraScriptLoader : public SpellScriptLoader
+{
+ public:
+ GenericSpellAndAuraScriptLoader(char const* name) : SpellScriptLoader(name) { }
+ SpellScript* GetSpellScript() const override { return new S(); }
+ AuraScript* GetAuraScript() const override { return new A(); }
+};
+#define RegisterSpellAndAuraScriptPair(spell_script, aura_script) new GenericSpellAndAuraScriptLoader<spell_script, aura_script>(#spell_script)
+
+template <class AI>
+class GenericCreatureScript : public CreatureScript
+{
+ public:
+ GenericCreatureScript(char const* name) : CreatureScript(name) { }
+ CreatureAI* GetAI(Creature* me) const override { return new AI(me); }
+};
+#define RegisterCreatureAI(ai_name) new GenericCreatureScript<ai_name>(#ai_name)
+
+template <class AI, AI*(*AIFactory)(Creature*)>
+class FactoryCreatureScript : public CreatureScript
+{
+ public:
+ FactoryCreatureScript(char const* name) : CreatureScript(name) { }
+ CreatureAI* GetAI(Creature* me) const override { return AIFactory(me); }
+};
+#define RegisterCreatureAIWithFactory(ai_name, factory_fn) new FactoryCreatureScript<ai_name, &factory_fn>(#ai_name)
+
+template <class AI>
+class GenericGameObjectScript : public GameObjectScript
+{
+ public:
+ GenericGameObjectScript(char const* name) : GameObjectScript(name) { }
+ GameObjectAI* GetAI(GameObject* go) const override { return new AI(go); }
+};
+#define RegisterGameObjectAI(ai_name) new GenericGameObjectScript<ai_name>(#ai_name)
+
+template <class AI>
+class GenericAreaTriggerEntityScript : public AreaTriggerEntityScript
+{
+ public:
+ GenericAreaTriggerEntityScript(char const* name) : AreaTriggerEntityScript(name) { }
+ AreaTriggerAI* GetAI(AreaTrigger* at) const override { return new AI(at); }
+};
+#define RegisterAreaTriggerAI(ai_name) new GenericAreaTriggerEntityScript<ai_name>(#ai_name)
+
#define sScriptMgr ScriptMgr::instance()
#endif