aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/base/world_database.sql29
-rw-r--r--sql/updates/9135_world_battleground_template.sql1
-rw-r--r--src/server/game/BattleGrounds/BattleGroundMgr.cpp44
-rw-r--r--src/server/game/BattleGrounds/BattleGroundMgr.h6
4 files changed, 52 insertions, 28 deletions
diff --git a/sql/base/world_database.sql b/sql/base/world_database.sql
index f0c2607a3d2..106851769ee 100644
--- a/sql/base/world_database.sql
+++ b/sql/base/world_database.sql
@@ -241,6 +241,7 @@ CREATE TABLE `battleground_template` (
`AllianceStartO` float NOT NULL,
`HordeStartLoc` mediumint(8) unsigned NOT NULL,
`HordeStartO` float NOT NULL,
+ `Weight` tinyint(2) unsigned NOT NULL DEFAULT 1,
`Comment` char(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -252,20 +253,20 @@ CREATE TABLE `battleground_template` (
LOCK TABLES `battleground_template` WRITE;
/*!40000 ALTER TABLE `battleground_template` DISABLE KEYS */;
-INSERT INTO `battleground_template` (`id`,`MinPlayersPerTeam`,`MaxPlayersPerTeam`,`MinLvl`,`MaxLvl`,`AllianceStartLoc`,`AllianceStartO`,`HordeStartLoc`,`HordeStartO`) VALUES
-(1,20,40,51,80,611,2.72532,610,2.27452),
-(2,5,10,10,80,769,3.14159,770,3.14159),
-(3,8,15,20,80,890,3.40156,889,0.263892),
-(4,0,2,10,80,929,0,936,3.14159),
-(5,0,2,10,80,939,0,940,3.14159),
-(6,0,2,10,80,0,0,0,0),
-(7,8,15,61,80,1103,3.40156,1104,0.263892),
-(8,0,2,10,80,1258,0,1259,3.14159),
-(9,7,15,71,80,1367,0,1368,0),
-(10,5,5,10,80,1362,0,1363,0),
-(11,5,5,10,80,1364,0,1365,0),
-(30,20,40,71,80,1485,0,1486,0),
-(32,10,10,0,80,0,0,0,0);
+INSERT INTO `battleground_template` (`id`,`MinPlayersPerTeam`,`MaxPlayersPerTeam`,`MinLvl`,`MaxLvl`,`AllianceStartLoc`,`AllianceStartO`,`HordeStartLoc`,`HordeStartO`, `Weight`) VALUES
+(1,20,40,51,80,611,2.72532,610,2.27452,1),
+(2,5,10,10,80,769,3.14159,770,3.14159,1),
+(3,8,15,20,80,890,3.40156,889,0.263892,1),
+(4,0,2,10,80,929,0,936,3.14159,1),
+(5,0,2,10,80,939,0,940,3.14159,1),
+(6,0,2,10,80,0,0,0,0,1),
+(7,8,15,61,80,1103,3.40156,1104,0.263892,1),
+(8,0,2,10,80,1258,0,1259,3.14159,1),
+(9,7,15,71,80,1367,0,1368,0,1),
+(10,5,5,10,80,1362,0,1363,0,1),
+(11,5,5,10,80,1364,0,1365,0,1),
+(30,20,40,71,80,1485,0,1486,0,1),
+(32,10,10,0,80,0,0,0,0,1);
/*!40000 ALTER TABLE `battleground_template` ENABLE KEYS */;
UNLOCK TABLES;
diff --git a/sql/updates/9135_world_battleground_template.sql b/sql/updates/9135_world_battleground_template.sql
new file mode 100644
index 00000000000..cf66584e12b
--- /dev/null
+++ b/sql/updates/9135_world_battleground_template.sql
@@ -0,0 +1 @@
+ALTER TABLE `battleground_template` ADD `Weight` tinyint(2) UNSIGNED NOT NULL DEFAULT 1 AFTER `HordeStartO`;
diff --git a/src/server/game/BattleGrounds/BattleGroundMgr.cpp b/src/server/game/BattleGrounds/BattleGroundMgr.cpp
index 8cf15984c1e..745b9829573 100644
--- a/src/server/game/BattleGrounds/BattleGroundMgr.cpp
+++ b/src/server/game/BattleGrounds/BattleGroundMgr.cpp
@@ -1551,7 +1551,7 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
{
// get the template BG
BattleGround *bg_template = GetBattleGroundTemplate(bgTypeId);
- BattleGroundTypeIdList *enabledBGsOrArenas = NULL;
+ BattleGroundSelectionWeightMap *selectionWeights = NULL;
if (!bg_template)
{
@@ -1561,19 +1561,39 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
bool isRandom = false;
if (bg_template->isArena())
- enabledBGsOrArenas = &m_EnabledArenas;
+ selectionWeights = &m_ArenaSelectionWeights;
else if (bgTypeId == BATTLEGROUND_RB)
{
- enabledBGsOrArenas = &m_EnabledBGs;
+ selectionWeights = &m_BGSelectionWeights;
isRandom = true;
}
- if (enabledBGsOrArenas)
+ if (selectionWeights)
{
- if (!enabledBGsOrArenas->size())
+ if (!selectionWeights->size())
return NULL;
- uint8 size = enabledBGsOrArenas->size() - 1;
- bgTypeId = enabledBGsOrArenas->at(urand(0,size));
+ uint32 Weight = 0;
+ uint32 selectedWeight = 0;
+ bgTypeId = BATTLEGROUND_TYPE_NONE;
+ // Get sum of all weights
+ for (BattleGroundSelectionWeightMap::const_iterator it = selectionWeights->begin(); it != selectionWeights->end(); ++it)
+ Weight += it->second;
+ if (!Weight)
+ return NULL;
+ // Select a random value
+ selectedWeight = urand(0, Weight);
+
+ // Select the correct bg (if we have in DB A(10), B(20), C(10), D(15) --> [0---A---9|10---B---29|30---C---39|40---D---54])
+ Weight = 0;
+ for (BattleGroundSelectionWeightMap::const_iterator it = selectionWeights->begin(); it != selectionWeights->end(); ++it)
+ {
+ Weight += it->second;
+ if (selectedWeight < Weight)
+ {
+ bgTypeId = it->first;
+ break;
+ }
+ }
bg_template = GetBattleGroundTemplate(bgTypeId);
if (!bg_template)
{
@@ -1701,14 +1721,15 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
float AStartLoc[4];
float HStartLoc[4];
uint32 MaxPlayersPerTeam, MinPlayersPerTeam, MinLvl, MaxLvl, start1, start2;
+ uint8 selectionWeight;
BattlemasterListEntry const *bl;
WorldSafeLocsEntry const *start;
bool IsArena;
uint32 count = 0;
- // 0 1 2 3 4 5 6 7 8
- QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO FROM battleground_template");
+ // 0 1 2 3 4 5 6 7 8 9
+ QueryResult_AutoPtr result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,AllianceStartO,HordeStartLoc,HordeStartO,Weight FROM battleground_template");
if (!result)
{
@@ -1806,6 +1827,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
continue;
}
+ selectionWeight = fields[9].GetUInt8();
//sLog.outDetail("Creating battleground %s, %u-%u", bl->name[sWorld.GetDBClang()], MinLvl, MaxLvl);
if (!CreateBattleGround(bgTypeID, IsArena, MinPlayersPerTeam, MaxPlayersPerTeam, MinLvl, MaxLvl, bl->name[sWorld.GetDefaultDbcLocale()], bl->mapid[0], AStartLoc[0], AStartLoc[1], AStartLoc[2], AStartLoc[3], HStartLoc[0], HStartLoc[1], HStartLoc[2], HStartLoc[3]))
continue;
@@ -1813,10 +1835,10 @@ void BattleGroundMgr::CreateInitialBattleGrounds()
if (IsArena)
{
if (bgTypeID != BATTLEGROUND_AA)
- m_EnabledArenas.push_back(bgTypeID);
+ m_ArenaSelectionWeights[bgTypeID] = selectionWeight;
}
else if (bgTypeID != BATTLEGROUND_RB)
- m_EnabledBGs.push_back(bgTypeID);
+ m_BGSelectionWeights[bgTypeID] = selectionWeight;
++count;
} while (result->NextRow());
diff --git a/src/server/game/BattleGrounds/BattleGroundMgr.h b/src/server/game/BattleGrounds/BattleGroundMgr.h
index 40dfc39b5e5..13067040f03 100644
--- a/src/server/game/BattleGrounds/BattleGroundMgr.h
+++ b/src/server/game/BattleGrounds/BattleGroundMgr.h
@@ -260,11 +260,11 @@ class BattleGroundMgr
private:
BattleMastersMap mBattleMastersMap;
- typedef std::vector<BattleGroundTypeId> BattleGroundTypeIdList;
+ typedef std::map<BattleGroundTypeId, uint8> BattleGroundSelectionWeightMap; // TypeId and its selectionWeight
/* Battlegrounds */
BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID];
- BattleGroundTypeIdList m_EnabledArenas;
- BattleGroundTypeIdList m_EnabledBGs;
+ BattleGroundSelectionWeightMap m_ArenaSelectionWeights;
+ BattleGroundSelectionWeightMap m_BGSelectionWeights;
std::vector<uint64> m_QueueUpdateScheduler;
std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_BRACKETS]; //the instanceids just visible for the client
uint32 m_NextRatingDiscardUpdate;