diff options
| author | QAston <none@none> | 2010-10-08 21:33:44 +0200 |
|---|---|---|
| committer | QAston <none@none> | 2010-10-08 21:33:44 +0200 |
| commit | 1760e42e2caa99d3de0038d1b52f64a1daeb665a (patch) | |
| tree | 9d95c4a73c675b3fb59724a1b0a908e5c9c3a490 /src/server/game | |
| parent | e5e53498cede475ae0d80623e89c4a3cbec39b62 (diff) | |
Core/ScriptSystem: Add compile time type check of function assigned to hooks - prevents incorrect function calls. Since this rev you have to put PrepareSpellScript(<yourscriptclassnamehere>) at the beginning of every spell script. Yes, i know it's unhandy, but unfortunately C++ preprocessor is very limited, so you have to do that extra work each time you write a script:(.
--HG--
branch : trunk
Diffstat (limited to 'src/server/game')
| -rwxr-xr-x | src/server/game/Spells/Spell.cpp | 6 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellMgr.h | 2 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.cpp | 10 | ||||
| -rwxr-xr-x | src/server/game/Spells/SpellScript.h | 43 |
4 files changed, 46 insertions, 15 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index b7c8049e1e4..6e4ead80a2e 100755 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -7242,7 +7242,7 @@ void Spell::CallScriptBeforeHitHandlers() std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->BeforeHit.end(), hookItr = (*scritr)->BeforeHit.begin(); for(; hookItr != hookItrEnd ; ++hookItr) { - ((*scritr)->*(*hookItr))(); + (*hookItr).Call(*scritr); } (*scritr)->_FinishScriptCall(); } @@ -7256,7 +7256,7 @@ void Spell::CallScriptOnHitHandlers() std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->OnHit.end(), hookItr = (*scritr)->OnHit.begin(); for(; hookItr != hookItrEnd ; ++hookItr) { - ((*scritr)->*(*hookItr))(); + (*hookItr).Call(*scritr); } (*scritr)->_FinishScriptCall(); } @@ -7270,7 +7270,7 @@ void Spell::CallScriptAfterHitHandlers() std::list<SpellScript::HitHandler>::iterator hookItrEnd = (*scritr)->AfterHit.end(), hookItr = (*scritr)->AfterHit.begin(); for(; hookItr != hookItrEnd ; ++hookItr) { - ((*scritr)->*(*hookItr))(); + (*hookItr).Call(*scritr); } (*scritr)->_FinishScriptCall(); } diff --git a/src/server/game/Spells/SpellMgr.h b/src/server/game/Spells/SpellMgr.h index 628c89af20a..2d394d9860b 100755 --- a/src/server/game/Spells/SpellMgr.h +++ b/src/server/game/Spells/SpellMgr.h @@ -559,7 +559,7 @@ enum ProcFlags PROC_FLAG_TAKEN_MELEE_AUTO_ATTACK = 0x00000008, // 03 Taken melee auto attack PROC_FLAG_DONE_SPELL_MELEE_DMG_CLASS = 0x00000010, // 04 Done attack by Spell that has dmg class melee - PROC_FLAG_TAKEN_SPELL_MELEE_DMG_CLASS = 0x00000020, // 05 Taken damage by Spell that has dmg class melee + PROC_FLAG_TAKEN_SPELL_MELEE_DMG_CLASS = 0x00000020, // 05 Taken attack by Spell that has dmg class melee PROC_FLAG_DONE_RANGED_AUTO_ATTACK = 0x00000040, // 06 Done ranged auto attack PROC_FLAG_TAKEN_RANGED_AUTO_ATTACK = 0x00000080, // 07 Taken ranged auto attack diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp index 355da664f42..ee2c7836f62 100755 --- a/src/server/game/Spells/SpellScript.cpp +++ b/src/server/game/Spells/SpellScript.cpp @@ -167,6 +167,16 @@ void SpellScript::EffectHandler::Call(SpellScript * spellScript, SpellEffIndex e (spellScript->*pEffectHandlerScript)(effIndex); } +SpellScript::HitHandler::HitHandler(SpellHitFnType _pHitHandlerScript) +{ + pHitHandlerScript = _pHitHandlerScript; +} + +void SpellScript::HitHandler::Call(SpellScript * spellScript) +{ + (spellScript->*pHitHandlerScript)(); +} + bool SpellScript::_Validate(SpellEntry const * entry) { for (std::list<EffectHandler>::iterator itr = OnEffect.begin(); itr != OnEffect.end(); ++itr) diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h index e4c9fd42fd3..7600b24a8d6 100755 --- a/src/server/game/Spells/SpellScript.h +++ b/src/server/game/Spells/SpellScript.h @@ -131,8 +131,11 @@ class SpellScript : public _SpellScript // internal use classes & functions // DO NOT OVERRIDE THESE IN SCRIPTS public: - typedef void(SpellScript::*SpellEffectFnType)(SpellEffIndex); - typedef void(SpellScript::*SpellHitFnType)(); + #define SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \ + typedef void(CLASSNAME::*SpellEffectFnType)(SpellEffIndex); \ + typedef void(CLASSNAME::*SpellHitFnType)(); \ + + SPELLSCRIPT_FUNCTION_TYPE_DEFINES(SpellScript) class EffectHandler : public _SpellScript::EffectNameCheck, public _SpellScript::EffectHook { @@ -144,7 +147,21 @@ class SpellScript : public _SpellScript private: SpellEffectFnType pEffectHandlerScript; }; - typedef SpellHitFnType HitHandler; + + class HitHandler + { + public: + HitHandler(SpellHitFnType _pHitHandlerScript); + void Call(SpellScript * spellScript); + private: + SpellHitFnType pHitHandlerScript; + }; + + #define SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) \ + class EffectHandlerFunction : public SpellScript::EffectHandler { public: EffectHandlerFunction(SpellEffectFnType _pEffectHandlerScript,uint8 _effIndex, uint16 _effName) : SpellScript::EffectHandler((SpellScript::SpellEffectFnType)_pEffectHandlerScript, _effIndex, _effName) {} }; \ + class HitHandlerFunction : public SpellScript::HitHandler { public: HitHandlerFunction(SpellHitFnType _pHitHandlerScript) : SpellScript::HitHandler((SpellScript::SpellHitFnType)_pHitHandlerScript) {} }; \ + + #define PrepareSpellScript(CLASSNAME) SPELLSCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) SPELLSCRIPT_FUNCTION_CAST_DEFINES(CLASSNAME) public: bool _Validate(SpellEntry const * entry); bool _Load(Spell * spell); @@ -167,7 +184,7 @@ class SpellScript : public _SpellScript // example: OnEffect += SpellEffectFn(class::function, EffectIndexSpecifier, EffectNameSpecifier); // where function is void function(SpellEffIndex effIndex) HookList<EffectHandler> OnEffect; - #define SpellEffectFn(F, I, N) EffectHandler((SpellEffectFnType)&F, I, N) + #define SpellEffectFn(F, I, N) EffectHandlerFunction(&F, I, N) // example: BeforeHit += SpellHitFn(class::function); HookList<HitHandler> BeforeHit; @@ -176,7 +193,7 @@ class SpellScript : public _SpellScript // example: AfterHit += SpellHitFn(class::function); HookList<HitHandler> AfterHit; // where function is: void function() - #define SpellHitFn(F) (SpellHitFnType)&F + #define SpellHitFn(F) HitHandlerFunction(&F) // hooks are executed in following order, at specified event of spell: // 1. BeforeHit - executed just before spell hits a target @@ -276,12 +293,16 @@ class AuraScript : public _SpellScript // internal use classes & functions // DO NOT OVERRIDE THESE IN SCRIPTS public: - typedef void(AuraScript::*AuraEffectApplicationModeFnType)(AuraEffect const *, AuraApplication const *, AuraEffectHandleModes mode); - typedef void(AuraScript::*AuraEffectPeriodicFnType)(AuraEffect const *, AuraApplication const *); - typedef void(AuraScript::*AuraEffectUpdatePeriodicFnType)(AuraEffect *); - typedef void(AuraScript::*AuraEffectCalcAmountFnType)(AuraEffect const *, int32 &, bool &); - typedef void(AuraScript::*AuraEffectCalcPeriodicFnType)(AuraEffect const *, bool &, int32 &); - typedef void(AuraScript::*AuraEffectCalcSpellModFnType)(AuraEffect const *, SpellModifier *&); + + #define AURASCRIPT_FUNCTION_TYPE_DEFINES(CLASSNAME) \ + typedef void(CLASSNAME::*AuraEffectApplicationModeFnType)(AuraEffect const *, AuraApplication const *, AuraEffectHandleModes mode); \ + typedef void(CLASSNAME::*AuraEffectPeriodicFnType)(AuraEffect const *, AuraApplication const *); \ + typedef void(CLASSNAME::*AuraEffectUpdatePeriodicFnType)(AuraEffect *); \ + typedef void(CLASSNAME::*AuraEffectCalcAmountFnType)(AuraEffect const *, int32 &, bool &); \ + typedef void(CLASSNAME::*AuraEffectCalcPeriodicFnType)(AuraEffect const *, bool &, int32 &); \ + typedef void(CLASSNAME::*AuraEffectCalcSpellModFnType)(AuraEffect const *, SpellModifier *&); \ + + AURASCRIPT_FUNCTION_TYPE_DEFINES(AuraScript) class EffectBase : public _SpellScript::EffectAuraNameCheck, public _SpellScript::EffectHook { |
