aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Scripting/ScriptMgr.h
diff options
context:
space:
mode:
authortreeston <treeston.mmoc@gmail.com>2017-07-20 00:19:05 +0200
committertreeston <treeston.mmoc@gmail.com>2017-07-20 00:27:20 +0200
commitfb87ac8e8da3d215d4988b8c2fa25d7a98cf9ee0 (patch)
tree4fc717859b9b2d4327ca1295dc2761527d3e6d68 /src/server/game/Scripting/ScriptMgr.h
parentbce40818bc172d18bde0a0630066596a8c3748ef (diff)
Core/Scripts: Implement generic script loaders (and script registry macros) to greatly reduce code duplication (#19526) (cherry-picked from commit a9174d5).
Diffstat (limited to 'src/server/game/Scripting/ScriptMgr.h')
-rw-r--r--src/server/game/Scripting/ScriptMgr.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index 311a7faf911..dab3b42329c 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -1053,6 +1053,61 @@ 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)
+
#define sScriptMgr ScriptMgr::instance()
#endif