diff options
Diffstat (limited to 'src/server/game/Scripting')
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.cpp | 65 | ||||
| -rw-r--r-- | src/server/game/Scripting/ScriptMgr.h | 30 |
2 files changed, 58 insertions, 37 deletions
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 76a51e0795f..e69b64a73fa 100644 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -90,7 +90,7 @@ struct is_script_database_bound<BattlefieldScript> : std::true_type { }; template<> -struct is_script_database_bound<BattlegroundScript> +struct is_script_database_bound<BattlegroundMapScript> : std::true_type { }; template<> @@ -754,11 +754,6 @@ template<typename Base> class ScriptRegistrySwapHooks<BattlefieldScript, Base> : public UnsupportedScriptRegistrySwapHooks<Base> { }; -/// This hook is responsible for swapping BattlegroundScript's -template<typename Base> -class ScriptRegistrySwapHooks<BattlegroundScript, Base> - : public UnsupportedScriptRegistrySwapHooks<Base> { }; - /// This hook is responsible for swapping OutdoorPvP's template<typename Base> class ScriptRegistrySwapHooks<OutdoorPvPScript, Base> @@ -826,6 +821,35 @@ private: bool swapped; }; +/// This hook is responsible for swapping BattlegroundMapScript's +template<typename Base> +class ScriptRegistrySwapHooks<BattlegroundMapScript, Base> + : public ScriptRegistrySwapHookBase +{ +public: + ScriptRegistrySwapHooks() : swapped(false) { } + + void BeforeReleaseContext(std::string const& context) final override + { + auto const bounds = static_cast<Base*>(this)->_ids_of_contexts.equal_range(context); + if (bounds.first != bounds.second) + swapped = true; + } + + void BeforeSwapContext(bool /*initialize*/) override + { + swapped = false; + } + + void BeforeUnload() final override + { + ASSERT(!swapped); + } + +private: + bool swapped; +}; + /// This hook is responsible for swapping SceneScript's template<typename Base> class ScriptRegistrySwapHooks<SceneScript, Base> @@ -1623,6 +1647,14 @@ InstanceScript* ScriptMgr::CreateInstanceData(InstanceMap* map) return tmpscript->GetInstanceScript(map); } +BattlegroundScript* ScriptMgr::CreateBattlegroundData(BattlegroundMap* map) +{ + ASSERT(map); + + GET_SCRIPT_RET(BattlegroundMapScript, map->GetScriptId(), tmpscript, NULL); + return tmpscript->GetBattlegroundScript(map); +} + bool ScriptMgr::OnQuestAccept(Player* player, Item* item, Quest const* quest) { ASSERT(player); @@ -1726,13 +1758,6 @@ Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId, Map* map) return tmpscript->GetBattlefield(map); } -Battleground* ScriptMgr::CreateBattleground(BattlegroundTypeId /*typeId*/) -{ - /// @todo Implement script-side battlegrounds. - ABORT(); - return nullptr; -} - OutdoorPvP* ScriptMgr::CreateOutdoorPvP(uint32 scriptId, Map* map) { GET_SCRIPT_RET(OutdoorPvPScript, scriptId, tmpscript, nullptr); @@ -2582,6 +2607,11 @@ BattlegroundMapScript::BattlegroundMapScript(char const* name, uint32 mapId) BattlegroundMapScript::~BattlegroundMapScript() = default; +BattlegroundScript* BattlegroundMapScript::GetBattlegroundScript(BattlegroundMap* /*map*/) const +{ + return nullptr; +} + ItemScript::ItemScript(char const* name) : ScriptObject(name) { @@ -2702,14 +2732,6 @@ BattlefieldScript::BattlefieldScript(char const* name) BattlefieldScript::~BattlefieldScript() = default; -BattlegroundScript::BattlegroundScript(char const* name) - : ScriptObject(name) -{ - ScriptRegistry<BattlegroundScript>::Instance()->AddScript(this); -} - -BattlegroundScript::~BattlegroundScript() = default; - OutdoorPvPScript::OutdoorPvPScript(char const* name) : ScriptObject(name) { @@ -3247,7 +3269,6 @@ template class TC_GAME_API ScriptRegistry<CreatureScript>; template class TC_GAME_API ScriptRegistry<GameObjectScript>; template class TC_GAME_API ScriptRegistry<AreaTriggerScript>; template class TC_GAME_API ScriptRegistry<BattlefieldScript>; -template class TC_GAME_API ScriptRegistry<BattlegroundScript>; template class TC_GAME_API ScriptRegistry<OutdoorPvPScript>; template class TC_GAME_API ScriptRegistry<CommandScript>; template class TC_GAME_API ScriptRegistry<WeatherScript>; diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index fe3fb48df79..31a5842a383 100644 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -35,6 +35,7 @@ class AuraScript; class Battlefield; class Battleground; class BattlegroundMap; +class BattlegroundScript; class Channel; class Conversation; class Creature; @@ -372,6 +373,9 @@ class TC_GAME_API BattlegroundMapScript : public ScriptObject, public MapScript< public: ~BattlegroundMapScript(); + + // Gets an BattlegroundScript object for this battleground. + virtual BattlegroundScript* GetBattlegroundScript(BattlegroundMap* map) const; }; class TC_GAME_API ItemScript : public ScriptObject @@ -501,20 +505,6 @@ class TC_GAME_API BattlefieldScript : public ScriptObject virtual Battlefield* GetBattlefield(Map* map) const = 0; }; -class TC_GAME_API BattlegroundScript : public ScriptObject -{ - protected: - - explicit BattlegroundScript(char const* name); - - public: - - ~BattlegroundScript(); - - // Should return a fully valid Battleground object for the type ID. - virtual Battleground* GetBattleground() const = 0; -}; - class TC_GAME_API OutdoorPvPScript : public ScriptObject { protected: @@ -1151,7 +1141,7 @@ class TC_GAME_API ScriptMgr public: /* BattlegroundScript */ - Battleground* CreateBattleground(BattlegroundTypeId typeId); + BattlegroundScript* CreateBattlegroundData(BattlegroundMap* map); public: /* OutdoorPvPScript */ @@ -1415,6 +1405,16 @@ class GenericAreaTriggerEntityScript : public AreaTriggerEntityScript }; #define RegisterAreaTriggerAI(ai_name) new GenericAreaTriggerEntityScript<ai_name>(#ai_name) +template<class Script> +class GenericBattlegroundMapScript : public BattlegroundMapScript +{ +public: + GenericBattlegroundMapScript(char const* name, uint32 mapId) : BattlegroundMapScript(name, mapId) { } + + BattlegroundScript* GetBattlegroundScript(BattlegroundMap* map) const override { return new Script(map); } +}; +#define RegisterBattlegroundMapScript(script_name, mapId) new GenericBattlegroundMapScript<script_name>(#script_name, mapId) + #define sScriptMgr ScriptMgr::instance() #endif |
