Skip to content

Commit

Permalink
[WiP] Core/PvP: Extensive cleanup, bug-fixing and optimization of Bat…
Browse files Browse the repository at this point in the history
…tleground scripts:

- Standards: Moved all statics to cpps where they belong.
- Cleanups: NULL -> nullptr, moved #defines to constants/enums
- Added a helper struct for handling spawns easily. Rewrote spawns using it.
- Moved spawn containers to private scope of Battleground (idea taken from boss states array in InstanceScripts)
- Remove unused teamId parameter from Battleground::SpawnCreature
- Prevent Battleground::RelocateDeadPlayers creating new entries on map.
- Make AddObject return a GameObject pointer instead of a bool (just like its AddCreature sibling)
- Corrected and added proper GO rotation to spawns
- De-hardcode buff entries for Battlegrounds, each BG uses their own entries (blizzlike).
- Moved logs from incorrect logger "sql.sql" to "bg.battleground"

Additional Notes for some BGs:
- Warsong Gulch:
  * Fixed inverted worldstates of flags being sent to new players, wrong flag state was shown on UI

- Alterac Valley:
  * Fix Snowfall graveyard cap time as per Patch 2.3.0
  * Use proper gameobject entries for each node (blizzlike)
  * Removed magic numbers in favor of compile time consts (enum offsets etc)
  * More additional missing spawns (both creatures and gameobjects)

- Isle of Conquest:
  * Removed Transport pointers from class, instead store GUIDs and use HashMapHolder to access them
  * Fixed some wrong spawns which had Y coord set as X coord, Z as Y and Orientation as Z, fix a double spawn related to this
  * Additional cleanups of spawn code that checked if the spawn was correct only to then do a Get(spawntype) to manipulate it.
  * Incremented door close time to 30 seconds, as it is on sniff

- Strand of the Ancients:
  * Fixed sending timer to players that join with BG in progress
  * Corrected ships rotation as per sniff
  * Added missing seaforium bomb spawns
  * Implemented team switch logic to different spawn entries (like Titan Relic)
  * Implemented changing teleport locations depending on destroyed doors (Closes #12127)
  • Loading branch information
ariel- committed Aug 22, 2016
1 parent f183ed3 commit b72da70
Show file tree
Hide file tree
Showing 23 changed files with 4,455 additions and 3,629 deletions.
342 changes: 342 additions & 0 deletions sql/updates/world/3.3.5/2016_MM_DD_NN_world_335.sql

Large diffs are not rendered by default.

203 changes: 96 additions & 107 deletions src/server/game/Battlegrounds/Battleground.cpp

Large diffs are not rendered by default.

91 changes: 63 additions & 28 deletions src/server/game/Battlegrounds/Battleground.h
Expand Up @@ -28,6 +28,7 @@
#include "GameObject.h"
#include "EventMap.h"

class Battleground;
class Creature;
class GameObject;
class Group;
Expand Down Expand Up @@ -146,15 +147,6 @@ enum BattlegroundStartTimeIntervals
BG_START_DELAY_NONE = 0 // ms
};

enum BattlegroundBuffObjects
{
BG_OBJECTID_SPEEDBUFF_ENTRY = 179871,
BG_OBJECTID_REGENBUFF_ENTRY = 179904,
BG_OBJECTID_BERSERKERBUFF_ENTRY = 179905
};

const uint32 Buff_Entries[3] = { BG_OBJECTID_SPEEDBUFF_ENTRY, BG_OBJECTID_REGENBUFF_ENTRY, BG_OBJECTID_BERSERKERBUFF_ENTRY };

enum BattlegroundStatus
{
STATUS_NONE = 0, // first status, should mean bg is not instance
Expand All @@ -172,7 +164,7 @@ struct BattlegroundPlayer

struct BattlegroundObjectInfo
{
BattlegroundObjectInfo() : object(NULL), timer(0), spellid(0) { }
BattlegroundObjectInfo() : object(nullptr), timer(0), spellid(0) { }

GameObject *object;
int32 timer;
Expand Down Expand Up @@ -202,7 +194,6 @@ enum BattlegroundStartingEventsIds
BG_STARTING_EVENT_THIRD = 2,
BG_STARTING_EVENT_FOURTH = 3
};
#define BG_STARTING_EVENT_COUNT 4

enum BGHonorMode
{
Expand All @@ -211,8 +202,48 @@ enum BGHonorMode
BG_HONOR_MODE_NUM
};

#define BG_AWARD_ARENA_POINTS_MIN_LEVEL 71
#define ARENA_TIMELIMIT_POINTS_LOSS -16
enum BattlegroudMisc
{
BG_MAX_BUFFS = 3,

BG_STARTING_EVENT_COUNT = 4,

BG_AWARD_ARENA_POINTS_MIN_LEVEL = 71,

ARENA_TIMELIMIT_POINTS_LOSS = -16
};

// because hardcoding values is bad
struct BattlegroundBuffEntries
{
friend class Battleground;

BattlegroundBuffEntries(uint32 SpeedBuffEntry, uint32 RegenBuffEntry, uint32 BerserkBuffEntry)
{
_buffEntry[0] = SpeedBuffEntry;
_buffEntry[1] = RegenBuffEntry;
_buffEntry[2] = BerserkBuffEntry;
}

private:
uint32 _buffEntry[BG_MAX_BUFFS];
};

// data helpers
struct BattlegroundSpawnPoint
{
uint32 Entry;
Position Pos;
uint32 SpawnTime;
};

struct BattlegroundGOSpawnPoint
{
uint32 Entry;
Position Pos;
G3D::Quat Rot;
uint32 SpawnTime;
};

/*
This class is used to:
Expand Down Expand Up @@ -243,7 +274,7 @@ class TC_GAME_API Battleground
/* achievement req. */
virtual bool IsAllNodesControlledByTeam(uint32 /*team*/) const { return false; }
void StartTimedAchievement(AchievementCriteriaTimedTypes type, uint32 entry);
virtual bool CheckAchievementCriteriaMeet(uint32 /*criteriaId*/, Player const* /*player*/, Unit const* /*target*/ = NULL, uint32 /*miscvalue1*/ = 0);
virtual bool CheckAchievementCriteriaMeet(uint32 /*criteriaId*/, Player const* /*player*/, Unit const* /*target*/ = nullptr, uint32 /*miscvalue1*/ = 0);

/* Battleground */
// Get methods:
Expand Down Expand Up @@ -352,10 +383,10 @@ class TC_GAME_API Battleground
// Packet Transfer
// method that should fill worldpacket with actual world states (not yet implemented for all battlegrounds!)
virtual void FillInitialWorldStates(WorldPacket& /*data*/) { }
void SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player* sender = NULL, bool self = true);
void SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player* sender = nullptr, bool self = true);
void SendPacketToAll(WorldPacket* packet);

void SendChatMessage(Creature* source, uint8 textId, WorldObject* target = NULL);
void SendChatMessage(Creature* source, uint8 textId, WorldObject* target = nullptr);

template<class Do>
void BroadcastWorker(Do& _do);
Expand All @@ -372,7 +403,7 @@ class TC_GAME_API Battleground
void BlockMovement(Player* player);

void SendWarningToAll(uint32 entry, ...);
void SendMessageToAll(uint32 entry, ChatMsg type, Player const* source = NULL);
void SendMessageToAll(uint32 entry, ChatMsg type, Player const* source = nullptr);
void PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...);

// specialized version with 2 string id args
Expand Down Expand Up @@ -417,7 +448,7 @@ class TC_GAME_API Battleground
virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) { }
void EventPlayerLoggedIn(Player* player);
void EventPlayerLoggedOut(Player* player);
virtual void ProcessEvent(WorldObject* /*obj*/, uint32 /*eventId*/, WorldObject* /*invoker*/ = NULL) { }
virtual void ProcessEvent(WorldObject* /*obj*/, uint32 /*eventId*/, WorldObject* /*invoker*/ = nullptr) { }

// this function can be used by spell to interact with the BG map
virtual void DoAction(uint32 /*action*/, ObjectGuid /*var*/) { }
Expand All @@ -437,17 +468,11 @@ class TC_GAME_API Battleground
void HandleTriggerBuff(ObjectGuid go_guid);
void SetHoliday(bool is_holiday);

/// @todo make this protected:
GuidVector BgObjects;
GuidVector BgCreatures;
void SpawnBGObject(uint32 type, uint32 respawntime);
virtual bool AddObject(uint32 type, uint32 entry, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime = 0, GOState goState = GO_STATE_READY);
bool AddObject(uint32 type, uint32 entry, Position const& pos, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime = 0, GOState goState = GO_STATE_READY);
virtual Creature* AddCreature(uint32 entry, uint32 type, float x, float y, float z, float o, TeamId teamId = TEAM_NEUTRAL, uint32 respawntime = 0, Transport* transport = NULL);
Creature* AddCreature(uint32 entry, uint32 type, Position const& pos, TeamId teamId = TEAM_NEUTRAL, uint32 respawntime = 0, Transport* transport = NULL);
GameObject* AddObject(uint32 type, uint32 entry, Position const& pos, G3D::Quat const& rot, uint32 respawnTime = 0, GOState goState = GO_STATE_READY);
Creature* AddCreature(uint32 entry, uint32 type, Position const& pos, uint32 respawntime = 0, Transport* transport = nullptr);
bool DelCreature(uint32 type);
bool DelObject(uint32 type);
virtual bool AddSpiritGuide(uint32 type, float x, float y, float z, float o, TeamId teamId = TEAM_NEUTRAL);
bool AddSpiritGuide(uint32 type, Position const& pos, TeamId teamId = TEAM_NEUTRAL);
int32 GetObjectType(ObjectGuid guid);

Expand Down Expand Up @@ -480,6 +505,10 @@ class TC_GAME_API Battleground
uint8 GetUniqueBracketId() const;

protected:
void SetCreaturesNumber(size_t count);
void SetGameObjectsNumber(size_t count);
void SetChangeBuffs(bool change, std::vector<BattlegroundBuffEntries> const* buffEntries);

// this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground
void EndNow();
void PlayerAddedToBGCheckIfBGIsRunning(Player* player);
Expand Down Expand Up @@ -512,7 +541,6 @@ class TC_GAME_API Battleground
// this must be filled in constructors!
uint32 StartMessageIds[BG_STARTING_EVENT_COUNT];

bool m_BuffChange;
bool m_IsRandom;

BGHonorMode m_HonorMode;
Expand Down Expand Up @@ -543,6 +571,7 @@ class TC_GAME_API Battleground
bool m_PrematureCountDown;
uint32 m_PrematureCountDownTimer;
std::string m_Name;
bool m_BuffChange;

/* Pre- and post-update hooks */

Expand Down Expand Up @@ -574,10 +603,14 @@ class TC_GAME_API Battleground
*/
virtual void PostUpdateImpl(uint32 /* diff */) { }

// Player lists
// Player containers
GuidVector m_ResurrectQueue; // Player GUID
GuidDeque m_OfflineQueue; // Player GUID

// Spawn containers
GuidVector BgObjects;
GuidVector BgCreatures;

// Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction
// Invited counters will be changed only when removing already invited player from queue, removing player from battleground and inviting player to BG
// Invited players counters
Expand Down Expand Up @@ -609,5 +642,7 @@ class TC_GAME_API Battleground
Position StartPosition[BG_TEAMS_COUNT];
float m_StartMaxDist;
uint32 ScriptId;

std::vector<BattlegroundBuffEntries> const* m_BuffEntries;
};
#endif
32 changes: 16 additions & 16 deletions src/server/game/Battlegrounds/BattlegroundMgr.cpp
Expand Up @@ -116,7 +116,7 @@ void BattlegroundMgr::Update(uint32 diff)
}

// update events timer
for (int qtype = BATTLEGROUND_QUEUE_NONE; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
for (uint32 qtype = BATTLEGROUND_QUEUE_NONE; qtype < MAX_BATTLEGROUND_QUEUE_TYPES; ++qtype)
m_BattlegroundQueues[qtype].UpdateEvents(diff);

// update scheduled queues
Expand All @@ -125,7 +125,7 @@ void BattlegroundMgr::Update(uint32 diff)
std::vector<uint64> scheduled;
std::swap(scheduled, m_QueueUpdateScheduler);

for (uint8 i = 0; i < scheduled.size(); i++)
for (uint32 i = 0; i < scheduled.size(); ++i)
{
uint32 arenaMMRating = scheduled[i] >> 32;
uint8 arenaType = scheduled[i] >> 24 & 255;
Expand Down Expand Up @@ -160,7 +160,7 @@ void BattlegroundMgr::Update(uint32 diff)
{
if (m_AutoDistributionTimeChecker < diff)
{
if (time(NULL) > m_NextAutoDistributionTime)
if (time(nullptr) > m_NextAutoDistributionTime)
{
sArenaTeamMgr->DistributeArenaPoints();
m_NextAutoDistributionTime = m_NextAutoDistributionTime + BATTLEGROUND_ARENA_POINT_DISTRIBUTION_DAY * sWorld->getIntConfig(CONFIG_ARENA_AUTO_DISTRIBUTE_INTERVAL_DAYS);
Expand Down Expand Up @@ -265,28 +265,28 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
//SMSG_BATTLEFIELD_LIST we need to find the battleground with this clientinstance-id
Battleground* bg = GetBattlegroundTemplate(bgTypeId);
if (!bg)
return NULL;
return nullptr;

if (bg->isArena())
return GetBattleground(instanceId, bgTypeId);

BattlegroundDataContainer::const_iterator it = bgDataStore.find(bgTypeId);
if (it == bgDataStore.end())
return NULL;
return nullptr;

for (BattlegroundContainer::const_iterator itr = it->second.m_Battlegrounds.begin(); itr != it->second.m_Battlegrounds.end(); ++itr)
{
if (itr->second->GetClientInstanceID() == instanceId)
return itr->second;
}

return NULL;
return nullptr;
}

Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTypeId bgTypeId)
{
if (!instanceId)
return NULL;
return nullptr;

BattlegroundDataContainer::const_iterator begin, end;

Expand All @@ -299,7 +299,7 @@ Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTy
{
end = bgDataStore.find(bgTypeId);
if (end == bgDataStore.end())
return NULL;
return nullptr;
begin = end++;
}

Expand All @@ -311,18 +311,18 @@ Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTy
return itr->second;
}

return NULL;
return nullptr;
}

Battleground* BattlegroundMgr::GetBattlegroundTemplate(BattlegroundTypeId bgTypeId)
{
BattlegroundDataContainer::const_iterator itr = bgDataStore.find(bgTypeId);
if (itr == bgDataStore.end())
return NULL;
return nullptr;

BattlegroundContainer const& bgs = itr->second.m_Battlegrounds;
//map is sorted and we can be sure that lowest instance id has only BG template
return bgs.empty() ? NULL : bgs.begin()->second;
return bgs.empty() ? nullptr : bgs.begin()->second;
}

uint32 BattlegroundMgr::CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
Expand Down Expand Up @@ -361,10 +361,10 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId original
if (!bg_template)
{
TC_LOG_ERROR("bg.battleground", "Battleground: CreateNewBattleground - bg template not found for %u", bgTypeId);
return NULL;
return nullptr;
}

Battleground* bg = NULL;
Battleground* bg = nullptr;
// create a copy of the BG template
switch (bgTypeId)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ Battleground* BattlegroundMgr::CreateNewBattleground(BattlegroundTypeId original
case BATTLEGROUND_RB:
case BATTLEGROUND_AA:
default:
return NULL;
return nullptr;
}

bool isRandom = bgTypeId != originalBgTypeId && !bg->isArena();
Expand Down Expand Up @@ -541,7 +541,7 @@ void BattlegroundMgr::LoadBattlegroundTemplates()

BattlegroundTypeId bgTypeId = BattlegroundTypeId(fields[0].GetUInt32());

if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeId, NULL))
if (DisableMgr::IsDisabledFor(DISABLE_TYPE_BATTLEGROUND, bgTypeId, nullptr))
continue;

// can be overwrite by values from DB
Expand Down Expand Up @@ -624,7 +624,7 @@ void BattlegroundMgr::InitAutomaticArenaPointDistribution()
return;

time_t wstime = time_t(sWorld->getWorldState(WS_ARENA_DISTRIBUTION_TIME));
time_t curtime = time(NULL);
time_t curtime = time(nullptr);
TC_LOG_DEBUG("bg.battleground", "Initializing Automatic Arena Point Distribution");
if (wstime < curtime)
{
Expand Down

0 comments on commit b72da70

Please sign in to comment.