Core/Misc: fixed creating battlefield/opvp capturepoints and prevented mem leak

This commit is contained in:
joschiwald
2015-01-30 23:53:41 +01:00
parent 74094dae63
commit beb1a06ea5
7 changed files with 62 additions and 59 deletions

View File

@@ -450,6 +450,25 @@ void Battlefield::SendUpdateWorldState(uint32 variable, uint32 value, bool hidde
BroadcastPacketToZone(worldstate.Write());
}
void Battlefield::AddCapturePoint(BfCapturePoint* cp)
{
Battlefield::BfCapturePointMap::iterator i = m_capturePoints.find(cp->GetCapturePointEntry());
if (i != m_capturePoints.end())
{
TC_LOG_ERROR("bg.battlefield", "Battlefield::AddCapturePoint: CapturePoint %s already exists!", cp->GetCapturePointEntry());
delete i->second;
}
m_capturePoints[cp->GetCapturePointEntry()] = cp;
}
BfCapturePoint* Battlefield::GetCapturePoint(uint32 entry) const
{
Battlefield::BfCapturePointMap::const_iterator itr = m_capturePoints.find(entry);
if (itr != m_capturePoints.end())
return itr->second;
return nullptr;
}
void Battlefield::RegisterZone(uint32 zoneId)
{
sBattlefieldMgr->AddZone(zoneId, this);
@@ -913,10 +932,11 @@ bool BfCapturePoint::SetCapturePointData(GameObject* capturePoint)
TC_LOG_DEBUG("bg.battlefield", "Creating capture point %u", capturePoint->GetEntry());
m_capturePointGUID = capturePoint->GetGUID();
m_capturePointEntry = capturePoint->GetEntry();
// check info existence
GameObjectTemplate const* goinfo = capturePoint->GetGOInfo();
if (goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
if (goinfo->type != GAMEOBJECT_TYPE_CONTROL_ZONE)
{
TC_LOG_ERROR("misc", "OutdoorPvP: GO %u is not capture point!", capturePoint->GetEntry());
return false;
@@ -927,7 +947,7 @@ bool BfCapturePoint::SetCapturePointData(GameObject* capturePoint)
m_maxSpeed = m_maxValue / (goinfo->controlZone.minTime ? goinfo->controlZone.minTime : 60);
m_neutralValuePct = goinfo->controlZone.neutralPercent;
m_minValue = m_maxValue * goinfo->controlZone.neutralPercent / 100;
m_capturePointEntry = capturePoint->GetEntry();
if (m_team == TEAM_ALLIANCE)
{
m_value = m_maxValue;

View File

@@ -402,15 +402,8 @@ class Battlefield : public ZoneScript
void BroadcastPacketToWar(WorldPacket const* data) const;
// CapturePoint system
void AddCapturePoint(BfCapturePoint* cp) { m_capturePoints[cp->GetCapturePointEntry()] = cp; }
BfCapturePoint* GetCapturePoint(uint32 lowguid) const
{
Battlefield::BfCapturePointMap::const_iterator itr = m_capturePoints.find(lowguid);
if (itr != m_capturePoints.end())
return itr->second;
return NULL;
}
void AddCapturePoint(BfCapturePoint* cp);
BfCapturePoint* GetCapturePoint(uint32 entry) const;
void RegisterZone(uint32 zoneid);
bool HasPlayer(Player* player) const;

View File

@@ -776,11 +776,11 @@ union GameObjectValue
{
uint32 MaxOpens;
} FishingHole;
//29 GAMEOBJECT_TYPE_CAPTURE_POINT
//29 GAMEOBJECT_TYPE_CONTROL_ZONE
struct
{
OPvPCapturePoint *OPvPObj;
} CapturePoint;
} ControlZone;
//33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING
struct
{

View File

@@ -156,11 +156,11 @@ bool normalizePlayerName(std::string& name)
}
// Extracts player and realm names delimited by -
ExtendedPlayerName ExtractExtendedPlayerName(std::string& name)
ExtendedPlayerName ExtractExtendedPlayerName(std::string const& name)
{
size_t pos = name.find('-');
if (pos != std::string::npos)
return ExtendedPlayerName(name.substr(0, pos), name.substr(pos+1));
return ExtendedPlayerName(name.substr(0, pos), name.substr(pos + 1));
else
return ExtendedPlayerName(name, "");
}
@@ -1869,7 +1869,7 @@ ObjectGuid::LowType ObjectMgr::AddGOData(uint32 entry, uint32 mapId, float x, fl
data.spawnMask = 1;
data.go_state = GO_STATE_READY;
data.phaseMask = PHASEMASK_NORMAL;
data.artKit = goinfo->type == GAMEOBJECT_TYPE_CAPTURE_POINT ? 21 : 0;
data.artKit = goinfo->type == GAMEOBJECT_TYPE_CONTROL_ZONE ? 21 : 0;
data.dbData = false;
AddGameobjectToGrid(guid, &data);

View File

@@ -636,12 +636,12 @@ bool normalizePlayerName(std::string& name);
struct ExtendedPlayerName
{
ExtendedPlayerName(std::string const& name, std::string const& realm) : Name(name), Realm(realm) {}
ExtendedPlayerName(std::string const& name, std::string const& realm) : Name(name), Realm(realm) { }
std::string Name;
std::string Realm;
};
ExtendedPlayerName ExtractExtendedPlayerName(std::string& name);
ExtendedPlayerName ExtractExtendedPlayerName(std::string const& name);
struct LanguageDesc
{

View File

@@ -141,7 +141,7 @@ bool OPvPCapturePoint::SetCapturePointData(uint32 entry, uint32 map, float x, fl
// check info existence
GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(entry);
if (!goinfo || goinfo->type != GAMEOBJECT_TYPE_CAPTURE_POINT)
if (!goinfo || goinfo->type != GAMEOBJECT_TYPE_CONTROL_ZONE)
{
TC_LOG_ERROR("outdoorpvp", "OutdoorPvP: GO %u is not capture point!", entry);
return false;
@@ -548,21 +548,6 @@ bool OutdoorPvP::HandleDropFlag(Player* player, uint32 id)
return false;
}
bool OPvPCapturePoint::HandleGossipOption(Player* /*player*/, ObjectGuid /*guid*/, uint32 /*id*/)
{
return false;
}
bool OPvPCapturePoint::CanTalkTo(Player* /*player*/, Creature* /*c*/, GossipMenuItems const& /*gso*/)
{
return false;
}
bool OPvPCapturePoint::HandleDropFlag(Player* /*player*/, uint32 /*id*/)
{
return false;
}
int32 OPvPCapturePoint::HandleOpenGo(Player* /*player*/, ObjectGuid guid)
{
std::map<ObjectGuid, uint32>::iterator itr = m_ObjectTypes.find(guid);
@@ -573,18 +558,32 @@ int32 OPvPCapturePoint::HandleOpenGo(Player* /*player*/, ObjectGuid guid)
return -1;
}
bool OutdoorPvP::HandleAreaTrigger(Player* /*player*/, uint32 /*trigger*/)
{
return false;
}
void OutdoorPvP::BroadcastPacket(WorldPacket &data) const
void OutdoorPvP::BroadcastPacket(WorldPacket const* data) const
{
// This is faster than sWorld->SendZoneMessage
for (uint32 team = 0; team < 2; ++team)
for (GuidSet::const_iterator itr = m_players[team].begin(); itr != m_players[team].end(); ++itr)
if (Player* const player = ObjectAccessor::FindPlayer(*itr))
player->GetSession()->SendPacket(&data);
player->SendDirectMessage(data);
}
void OutdoorPvP::AddCapturePoint(OPvPCapturePoint* cp)
{
OPvPCapturePointMap::iterator i = m_capturePoints.find(cp->m_capturePointGUID);
if (i != m_capturePoints.end())
{
TC_LOG_ERROR("outdoorpvp", "OutdoorPvP::AddCapturePoint: CapturePoint %s already exists!", cp->m_capturePointGUID);
delete i->second;
}
m_capturePoints[cp->m_capturePointGUID] = cp;
}
OPvPCapturePoint* OutdoorPvP::GetCapturePoint(ObjectGuid guid) const
{
OutdoorPvP::OPvPCapturePointMap::const_iterator itr = m_capturePoints.find(guid);
if (itr != m_capturePoints.end())
return itr->second;
return nullptr;
}
void OutdoorPvP::RegisterZone(uint32 zoneId)
@@ -622,7 +621,7 @@ void OutdoorPvP::TeamApplyBuff(TeamId team, uint32 spellId, uint32 spellId2)
void OutdoorPvP::OnGameObjectCreate(GameObject* go)
{
if (go->GetGoType() != GAMEOBJECT_TYPE_CAPTURE_POINT)
if (go->GetGoType() != GAMEOBJECT_TYPE_CONTROL_ZONE)
return;
if (OPvPCapturePoint *cp = GetCapturePoint(go->GetGUID()))
@@ -631,7 +630,7 @@ void OutdoorPvP::OnGameObjectCreate(GameObject* go)
void OutdoorPvP::OnGameObjectRemove(GameObject* go)
{
if (go->GetGoType() != GAMEOBJECT_TYPE_CAPTURE_POINT)
if (go->GetGoType() != GAMEOBJECT_TYPE_CONTROL_ZONE)
return;
if (OPvPCapturePoint *cp = GetCapturePoint(go->GetGUID()))

View File

@@ -119,11 +119,11 @@ class OPvPCapturePoint
virtual void SendChangePhase();
virtual bool HandleGossipOption(Player* player, ObjectGuid guid, uint32 gossipid);
virtual bool HandleGossipOption(Player* /*player*/, ObjectGuid /*guid*/, uint32 /*gossipId*/) { return false; }
virtual bool CanTalkTo(Player* player, Creature* c, GossipMenuItems const& gso);
virtual bool CanTalkTo(Player* /*player*/, Creature* /*creature*/, GossipMenuItems const& /*gso*/) { return false; }
virtual bool HandleDropFlag(Player* player, uint32 spellId);
virtual bool HandleDropFlag(Player* /*player*/, uint32 /*spellId*/) { return false; }
virtual void DeleteSpawns();
@@ -204,7 +204,7 @@ class OutdoorPvP : public ZoneScript
virtual void FillInitialWorldStates(WorldPacket & /*data*/) { }
// called when a player triggers an areatrigger
virtual bool HandleAreaTrigger(Player* player, uint32 trigger);
virtual bool HandleAreaTrigger(Player* /*player*/, uint32 /*trigger*/) { return false; }
// called on custom spell
virtual bool HandleCustomSpell(Player* player, uint32 spellId, GameObject* go);
@@ -274,25 +274,16 @@ class OutdoorPvP : public ZoneScript
// world state stuff
virtual void SendRemoveWorldStates(Player* /*player*/) { }
void BroadcastPacket(WorldPacket & data) const;
void BroadcastPacket(WorldPacket const* data) const;
virtual void HandlePlayerEnterZone(Player* player, uint32 zone);
virtual void HandlePlayerLeaveZone(Player* player, uint32 zone);
virtual void HandlePlayerResurrects(Player* player, uint32 zone);
void AddCapturePoint(OPvPCapturePoint* cp)
{
m_capturePoints[cp->m_capturePointGUID] = cp;
}
void AddCapturePoint(OPvPCapturePoint* cp);
OPvPCapturePoint * GetCapturePoint(ObjectGuid guid) const
{
OutdoorPvP::OPvPCapturePointMap::const_iterator itr = m_capturePoints.find(guid);
if (itr != m_capturePoints.end())
return itr->second;
return NULL;
}
OPvPCapturePoint * GetCapturePoint(ObjectGuid guid) const;
void RegisterZone(uint32 zoneid);