aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Battlefield/Battlefield.h3
-rw-r--r--src/server/game/Battlefield/BattlefieldMgr.cpp64
-rw-r--r--src/server/game/Entities/Player/Player.cpp5
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp2
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp22
-rw-r--r--src/server/game/Scripting/ScriptMgr.h16
-rw-r--r--src/server/game/Spells/SpellMgr.cpp1
-rw-r--r--src/server/scripts/Battlefield/BattlefieldWG.cpp (renamed from src/server/game/Battlefield/Zones/BattlefieldWG.cpp)16
-rw-r--r--src/server/scripts/Battlefield/BattlefieldWG.h (renamed from src/server/game/Battlefield/Zones/BattlefieldWG.h)12
-rw-r--r--src/server/scripts/Battlefield/battlefield_script_loader.cpp23
-rw-r--r--src/server/scripts/Northrend/zone_wintergrasp.cpp6
11 files changed, 127 insertions, 43 deletions
diff --git a/src/server/game/Battlefield/Battlefield.h b/src/server/game/Battlefield/Battlefield.h
index b4bf17c1797..3acb1e8655e 100644
--- a/src/server/game/Battlefield/Battlefield.h
+++ b/src/server/game/Battlefield/Battlefield.h
@@ -25,7 +25,8 @@
enum BattlefieldTypes
{
- BATTLEFIELD_WG // Wintergrasp
+ BATTLEFIELD_WG = 1, // Wintergrasp
+ BATTLEFIELD_MAX
};
enum BattlefieldIDs
diff --git a/src/server/game/Battlefield/BattlefieldMgr.cpp b/src/server/game/Battlefield/BattlefieldMgr.cpp
index 3625548074a..c62f60c03c7 100644
--- a/src/server/game/Battlefield/BattlefieldMgr.cpp
+++ b/src/server/game/Battlefield/BattlefieldMgr.cpp
@@ -16,9 +16,11 @@
*/
#include "BattlefieldMgr.h"
-#include "BattlefieldWG.h"
+#include "DatabaseEnv.h"
+#include "ObjectMgr.h"
#include "Log.h"
#include "Player.h"
+#include "ScriptMgr.h"
BattlefieldMgr::BattlefieldMgr()
{
@@ -41,34 +43,44 @@ BattlefieldMgr* BattlefieldMgr::instance()
void BattlefieldMgr::InitBattlefield()
{
- Battlefield* wg = new BattlefieldWG();
- // respawn, init variables
- if (!wg->SetupBattlefield())
- {
- TC_LOG_INFO("bg.battlefield", "Battlefield: Wintergrasp init failed.");
- delete wg;
- }
- else
- {
- _battlefieldSet.push_back(wg);
- TC_LOG_INFO("bg.battlefield", "Battlefield: Wintergrasp successfully initiated.");
- }
+ uint32 oldMSTime = getMSTime();
- /*
- For Cataclysm: Tol Barad
- Battlefield* tb = new BattlefieldTB;
- // respawn, init variables
- if (!tb->SetupBattlefield())
- {
- TC_LOG_DEBUG("bg.battlefield", "Battlefield: Tol Barad init failed.");
- delete tb;
- }
- else
+ uint32 count = 0;
+
+ if (QueryResult result = WorldDatabase.Query("SELECT TypeId, ScriptName FROM battlefield_template"))
{
- _battlefieldSet.push_back(tb);
- TC_LOG_DEBUG("bg.battlefield", "Battlefield: Tol Barad successfully initiated.");
+ do
+ {
+ Field* fields = result->Fetch();
+
+ uint32 typeId = fields[0].GetUInt32();
+
+ if (typeId >= BATTLEFIELD_MAX)
+ {
+ TC_LOG_ERROR("sql.sql", "BattlefieldMgr::InitBattlefield: Invalid TypeId value %u in battlefield_template, skipped.", typeId);
+ continue;
+ }
+
+ uint32 scriptId = sObjectMgr->GetScriptId(fields[1].GetString());
+
+ Battlefield* bf = sScriptMgr->CreateBattlefield(scriptId);
+
+ if (!bf->SetupBattlefield())
+ {
+ TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u failed.", typeId);
+ delete bf;
+ }
+ else
+ {
+ _battlefieldSet.push_back(bf);
+ TC_LOG_INFO("bg.battlefield", "Setting up battlefield with TypeId %u succeeded.", typeId);
+ }
+
+ ++count;
+ } while (result->NextRow());
}
- */
+
+ TC_LOG_INFO("server.loading", ">> Loaded %u battlefields in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
void BattlefieldMgr::AddZone(uint32 zoneId, Battlefield* bf)
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 9bb1bf8976b..8e0e9525ce5 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -23,7 +23,6 @@
#include "Bag.h"
#include "Battlefield.h"
#include "BattlefieldMgr.h"
-#include "BattlefieldWG.h"
#include "Battleground.h"
#include "BattlegroundMgr.h"
#include "BattlegroundScore.h"
@@ -9414,11 +9413,11 @@ void Player::SendBattlefieldWorldStates() const
/// Send misc stuff that needs to be sent on every login, like the battle timers.
if (sWorld->getBoolConfig(CONFIG_WINTERGRASP_ENABLE))
{
- if (BattlefieldWG* wg = static_cast<BattlefieldWG*>(sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG)))
+ if (Battlefield* wg = sBattlefieldMgr->GetBattlefieldByBattleId(BATTLEFIELD_BATTLEID_WG))
{
SendUpdateWorldState(WS_BATTLEFIELD_WG_ACTIVE, wg->IsWarTime() ? 0 : 1);
uint32 timer = wg->IsWarTime() ? 0 : (wg->GetTimer() / 1000); // 0 - Time to next battle
- SendUpdateWorldState(ClockWorldState[1], uint32(GameTime::GetGameTime() + timer));
+ SendUpdateWorldState(WS_BATTLEFIELD_WG_TIME_NEXT_BATTLE, uint32(GameTime::GetGameTime() + timer));
}
}
}
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 5ad1751f0a2..153751d39d0 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -9601,6 +9601,8 @@ void ObjectMgr::LoadScriptNames()
QueryResult result = WorldDatabase.Query(
"SELECT DISTINCT(ScriptName) FROM achievement_criteria_data WHERE ScriptName <> '' AND type = 11 "
"UNION "
+ "SELECT DISTINCT(ScriptName) FROM battlefield_template WHERE ScriptName <> '' "
+ "UNION "
"SELECT DISTINCT(ScriptName) FROM battleground_template WHERE ScriptName <> '' "
"UNION "
"SELECT DISTINCT(ScriptName) FROM creature WHERE ScriptName <> '' "
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index e23cf372732..972f9cedbba 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -78,6 +78,10 @@ struct is_script_database_bound<AreaTriggerScript>
: std::true_type { };
template<>
+struct is_script_database_bound<BattlefieldScript>
+ : std::true_type { };
+
+template<>
struct is_script_database_bound<BattlegroundScript>
: std::true_type { };
@@ -595,6 +599,11 @@ class ScriptRegistrySwapHooks<GameObjectScript, Base>
GameObject, GameObjectScript, Base
> { };
+/// This hook is responsible for swapping BattlefieldScripts
+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>
@@ -1591,6 +1600,12 @@ bool ScriptMgr::OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger)
return tmpscript->OnTrigger(player, trigger);
}
+Battlefield* ScriptMgr::CreateBattlefield(uint32 scriptId)
+{
+ GET_SCRIPT_RET(BattlefieldScript, scriptId, tmpscript, nullptr);
+ return tmpscript->GetBattlefield();
+}
+
Battleground* ScriptMgr::CreateBattleground(BattlegroundTypeId /*typeId*/)
{
/// @todo Implement script-side battlegrounds.
@@ -2226,6 +2241,12 @@ bool OnlyOnceAreaTriggerScript::OnTrigger(Player* player, AreaTriggerEntry const
void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(InstanceScript* script, uint32 triggerId) { script->ResetAreaTriggerDone(triggerId); }
void OnlyOnceAreaTriggerScript::ResetAreaTriggerDone(Player const* player, AreaTriggerEntry const* trigger) { if (InstanceScript* instance = player->GetInstanceScript()) ResetAreaTriggerDone(instance, trigger->id); }
+BattlefieldScript::BattlefieldScript(char const* name)
+ : ScriptObject(name)
+{
+ ScriptRegistry<BattlefieldScript>::Instance()->AddScript(this);
+}
+
BattlegroundScript::BattlegroundScript(char const* name)
: ScriptObject(name)
{
@@ -2322,6 +2343,7 @@ template class TC_GAME_API ScriptRegistry<ItemScript>;
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>;
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index 8f5199b860c..f255a3b06a3 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -26,6 +26,7 @@ class AccountMgr;
class AuctionHouseObject;
class Aura;
class AuraScript;
+class Battlefield;
class Battleground;
class BattlegroundMap;
class Channel;
@@ -463,6 +464,17 @@ class TC_GAME_API OnlyOnceAreaTriggerScript : public AreaTriggerScript
void ResetAreaTriggerDone(Player const* /*player*/, AreaTriggerEntry const* /*trigger*/);
};
+class TC_GAME_API BattlefieldScript : public ScriptObject
+{
+ protected:
+
+ BattlefieldScript(char const* name);
+
+ public:
+
+ virtual Battlefield* GetBattlefield() const = 0;
+};
+
class TC_GAME_API BattlegroundScript : public ScriptObject
{
protected:
@@ -938,6 +950,10 @@ class TC_GAME_API ScriptMgr
bool OnAreaTrigger(Player* player, AreaTriggerEntry const* trigger);
+ public: /* BattlefieldScript */
+
+ Battlefield* CreateBattlefield(uint32 scriptId);
+
public: /* BattlegroundScript */
Battleground* CreateBattleground(BattlegroundTypeId typeId);
diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp
index 234c94b9913..65d9a0e7071 100644
--- a/src/server/game/Spells/SpellMgr.cpp
+++ b/src/server/game/Spells/SpellMgr.cpp
@@ -17,7 +17,6 @@
#include "SpellMgr.h"
#include "BattlefieldMgr.h"
-#include "BattlefieldWG.h"
#include "BattlegroundMgr.h"
#include "Chat.h"
#include "Containers.h"
diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/scripts/Battlefield/BattlefieldWG.cpp
index 22efb3242ba..00486e9e4a0 100644
--- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp
+++ b/src/server/scripts/Battlefield/BattlefieldWG.cpp
@@ -32,6 +32,7 @@
#include "Opcodes.h"
#include "Player.h"
#include "Random.h"
+#include "ScriptMgr.h"
#include "SpellAuras.h"
#include "TemporarySummon.h"
#include "World.h"
@@ -1851,3 +1852,18 @@ void WintergraspWorkshop::Save()
{
sWorld->setWorldState(_staticInfo->WorldStateId, _state);
}
+
+class Battlefield_wintergrasp : public BattlefieldScript
+{
+public:
+ Battlefield_wintergrasp() : BattlefieldScript("battlefield_wg") { }
+
+ Battlefield* GetBattlefield() const override
+ {
+ return new BattlefieldWG();
+ }
+};
+
+void AddSC_BF_wintergrasp() {
+ new Battlefield_wintergrasp();
+}
diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.h b/src/server/scripts/Battlefield/BattlefieldWG.h
index 499fb6466b0..3706d573591 100644
--- a/src/server/game/Battlefield/Zones/BattlefieldWG.h
+++ b/src/server/scripts/Battlefield/BattlefieldWG.h
@@ -41,12 +41,6 @@ struct WintergraspObjectPositionData;
typedef std::vector<BfWGGameObjectBuilding*> GameObjectBuildingVect;
typedef std::vector<WintergraspWorkshop*> WorkshopVect;
-// used in Player.cpp
-extern uint32 const ClockWorldState[];
-
-// used in zone_wintergrasp.cpp
-TC_GAME_API extern uint32 const WintergraspFaction[];
-
enum WintergraspSpells
{
// Wartime auras
@@ -215,7 +209,7 @@ class WintergraspCapturePoint : public BfCapturePoint
* WinterGrasp Battlefield *
* ######################### */
-class TC_GAME_API BattlefieldWG : public Battlefield
+class BattlefieldWG : public Battlefield
{
public:
~BattlefieldWG();
@@ -507,7 +501,7 @@ enum WintergraspGameObject
// ********************************************************************
// Structure for different buildings that can be destroyed during battle
-struct TC_GAME_API BfWGGameObjectBuilding
+struct BfWGGameObjectBuilding
{
private:
// WG object
@@ -560,7 +554,7 @@ public:
};
// Structure for the 6 workshop
-struct TC_GAME_API WintergraspWorkshop
+struct WintergraspWorkshop
{
private:
BattlefieldWG* _wg; // Pointer to wintergrasp
diff --git a/src/server/scripts/Battlefield/battlefield_script_loader.cpp b/src/server/scripts/Battlefield/battlefield_script_loader.cpp
new file mode 100644
index 00000000000..a16d3eeb0d7
--- /dev/null
+++ b/src/server/scripts/Battlefield/battlefield_script_loader.cpp
@@ -0,0 +1,23 @@
+/*
+ * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+void AddSC_BF_wintergrasp();
+
+void AddBattlefieldScripts()
+{
+ AddSC_BF_wintergrasp();
+}
diff --git a/src/server/scripts/Northrend/zone_wintergrasp.cpp b/src/server/scripts/Northrend/zone_wintergrasp.cpp
index 2ee290ff9b9..1175306cbf3 100644
--- a/src/server/scripts/Northrend/zone_wintergrasp.cpp
+++ b/src/server/scripts/Northrend/zone_wintergrasp.cpp
@@ -18,7 +18,7 @@
#include "ScriptMgr.h"
#include "Battlefield.h"
#include "BattlefieldMgr.h"
-#include "BattlefieldWG.h"
+#include "Battlefield/BattlefieldWG.h"
#include "DBCStores.h"
#include "GameObject.h"
#include "GameObjectAI.h"
@@ -360,8 +360,8 @@ class go_wg_vehicle_teleporter : public GameObjectScript
bool IsFriendly(Unit* passenger)
{
- return ((me->GetFaction() == WintergraspFaction[TEAM_HORDE] && passenger->GetFaction() == HORDE) ||
- (me->GetFaction() == WintergraspFaction[TEAM_ALLIANCE] && passenger->GetFaction() == ALLIANCE));
+ return ((me->GetFaction() == FACTION_HORDE_GENERIC_WG && passenger->GetFaction() == HORDE) ||
+ (me->GetFaction() == FACTION_ALLIANCE_GENERIC_WG && passenger->GetFaction() == ALLIANCE));
}
Creature* GetValidVehicle(Creature* cVeh)