Skip to content

Commit

Permalink
[c12983] CreatureLinking: Add const correctness
Browse files Browse the repository at this point in the history
(based on commit [12790] - ef81f08)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>
  • Loading branch information
Schmoozerd authored and xfurry committed Nov 23, 2014
1 parent 3885332 commit 63b5da1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
22 changes: 11 additions & 11 deletions src/game/CreatureLinkingMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ enum EventMask
};

// This functions checks if the NPC has linked NPCs for dynamic action
bool CreatureLinkingMgr::IsLinkedEventTrigger(Creature* pCreature)
bool CreatureLinkingMgr::IsLinkedEventTrigger(Creature* pCreature) const
{
// Entry case
if (m_eventTriggers.find(pCreature->GetEntry()) != m_eventTriggers.end())
Expand All @@ -286,22 +286,22 @@ bool CreatureLinkingMgr::IsLinkedEventTrigger(Creature* pCreature)

// This function check if the NPC is a master to other NPCs
// return true only for masters stored by entry - this prevents adding them to master-holder maps
bool CreatureLinkingMgr::IsLinkedMaster(Creature* pCreature)
bool CreatureLinkingMgr::IsLinkedMaster(Creature* pCreature) const
{
return m_eventTriggers.find(pCreature->GetEntry()) != m_eventTriggers.end();
}

// This function checks if the spawning of this NPC is dependend on other NPCs
bool CreatureLinkingMgr::IsSpawnedByLinkedMob(Creature* pCreature)
bool CreatureLinkingMgr::IsSpawnedByLinkedMob(Creature* pCreature) const
{
CreatureLinkingInfo const* pInfo = CreatureLinkingMgr::GetLinkedTriggerInformation(pCreature);
CreatureLinkingInfo const* pInfo = GetLinkedTriggerInformation(pCreature);

return pInfo && pInfo->linkingFlag & (FLAG_CANT_SPAWN_IF_BOSS_DEAD | FLAG_CANT_SPAWN_IF_BOSS_ALIVE) && (pInfo->masterDBGuid || pInfo->searchRange);
}

// This gives the information of a linked NPC (describes action when its ActionTrigger triggers)
// Depends of the map
CreatureLinkingInfo const* CreatureLinkingMgr::GetLinkedTriggerInformation(Creature* pCreature)
CreatureLinkingInfo const* CreatureLinkingMgr::GetLinkedTriggerInformation(Creature* pCreature) const
{
// guid case
CreatureLinkingMapBounds bounds = m_creatureLinkingGuidMap.equal_range(pCreature->GetGUIDLow());
Expand Down Expand Up @@ -386,7 +386,7 @@ void CreatureLinkingHolder::AddMasterToHolder(Creature* pCreature)

// Check, if already stored
BossGuidMapBounds bounds = m_masterGuid.equal_range(pCreature->GetEntry());
for (BossGuidMap::iterator itr = bounds.first; itr != bounds.second; ++itr)
for (BossGuidMap::const_iterator itr = bounds.first; itr != bounds.second; ++itr)
if (itr->second == pCreature->GetObjectGuid())
return; // Already added

Expand Down Expand Up @@ -438,7 +438,7 @@ void CreatureLinkingHolder::DoCreatureLinkingEvent(CreatureLinkingEvent eventTyp
if (pInfo->mapId != INVALID_MAP_ID) // entry case
{
BossGuidMapBounds finds = m_masterGuid.equal_range(pInfo->masterId);
for (BossGuidMap::iterator itr = finds.first; itr != finds.second; ++itr)
for (BossGuidMap::const_iterator itr = finds.first; itr != finds.second; ++itr)
{
pMaster = pSource->GetMap()->GetCreature(itr->second);
if (pMaster && IsSlaveInRangeOfBoss(pSource, pMaster, pInfo->searchRange))
Expand Down Expand Up @@ -591,7 +591,7 @@ void CreatureLinkingHolder::SetFollowing(Creature* pWho, Creature* pWhom)
}

// Function to check if a slave belongs to a boss by range-issue
bool CreatureLinkingHolder::IsSlaveInRangeOfBoss(Creature* pSlave, Creature* pBoss, uint16 searchRange)
bool CreatureLinkingHolder::IsSlaveInRangeOfBoss(Creature* pSlave, Creature* pBoss, uint16 searchRange) const
{
if (!searchRange)
return true;
Expand All @@ -609,7 +609,7 @@ bool CreatureLinkingHolder::IsSlaveInRangeOfBoss(Creature* pSlave, Creature* pBo
}

// Function to check if a passive spawning condition is met
bool CreatureLinkingHolder::CanSpawn(Creature* pCreature)
bool CreatureLinkingHolder::CanSpawn(Creature* pCreature) const
{
CreatureLinkingInfo const* pInfo = sCreatureLinkingMgr.GetLinkedTriggerInformation(pCreature);
if (!pInfo)
Expand All @@ -630,7 +630,7 @@ bool CreatureLinkingHolder::CanSpawn(Creature* pCreature)

// Search for nearby master
BossGuidMapBounds finds = m_masterGuid.equal_range(pInfo->masterId);
for (BossGuidMap::iterator itr = finds.first; itr != finds.second; ++itr)
for (BossGuidMap::const_iterator itr = finds.first; itr != finds.second; ++itr)
{
Creature* pMaster = pCreature->GetMap()->GetCreature(itr->second);
if (pMaster && IsSlaveInRangeOfBoss(pCreature, pMaster, pInfo->searchRange))
Expand Down Expand Up @@ -658,7 +658,7 @@ bool CreatureLinkingHolder::TryFollowMaster(Creature* pCreature)
if (pInfo->mapId != INVALID_MAP_ID) // entry case
{
BossGuidMapBounds finds = m_masterGuid.equal_range(pInfo->masterId);
for (BossGuidMap::iterator itr = finds.first; itr != finds.second; ++itr)
for (BossGuidMap::const_iterator itr = finds.first; itr != finds.second; ++itr)
{
pMaster = pCreature->GetMap()->GetCreature(itr->second);
if (pMaster && IsSlaveInRangeOfBoss(pCreature, pMaster, pInfo->searchRange))
Expand Down
16 changes: 8 additions & 8 deletions src/game/CreatureLinkingMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,17 @@ class CreatureLinkingMgr

public: // Accessors
// This functions checks if the NPC triggers actions for other NPCs
bool IsLinkedEventTrigger(Creature* pCreature);
bool IsLinkedEventTrigger(Creature* pCreature) const;

// This function checks if the NPC is a master NPC.
bool IsLinkedMaster(Creature* pCreature);
bool IsLinkedMaster(Creature* pCreature) const;

// This function checks if the spawning of this NPC is dependend on other NPCs
bool IsSpawnedByLinkedMob(Creature* pCreature);
bool IsSpawnedByLinkedMob(Creature* pCreature) const;

// This gives the information of a linked NPC (describes action when its ActionTrigger triggers)
// Depends of the map
CreatureLinkingInfo const* GetLinkedTriggerInformation(Creature* pCreature);
CreatureLinkingInfo const* GetLinkedTriggerInformation(Creature* pCreature) const;

private:
typedef std::multimap < uint32 /*slaveEntry*/, CreatureLinkingInfo > CreatureLinkingMap;
Expand All @@ -131,7 +131,7 @@ class CreatureLinkingMgr
UNORDERED_SET<uint32> m_eventGuidTriggers; // master by guid

// Check-routine
bool IsLinkingEntryValid(uint32 slaveEntry, CreatureLinkingInfo* pInfo, bool byEntry);
static bool IsLinkingEntryValid(uint32 slaveEntry, CreatureLinkingInfo* pInfo, bool byEntry);
};

/**
Expand All @@ -156,7 +156,7 @@ class CreatureLinkingHolder
void DoCreatureLinkingEvent(CreatureLinkingEvent eventType, Creature* pSource, Unit* pEnemy = NULL);

// Function to check if a passive spawning condition is met
bool CanSpawn(Creature* pCreature);
bool CanSpawn(Creature* pCreature) const;

// This function lets a slave refollow his master
bool TryFollowMaster(Creature* pCreature);
Expand All @@ -179,7 +179,7 @@ class CreatureLinkingHolder
typedef std::multimap < uint32 /*masterEntryOrGuid*/, InfoAndGuids > HolderMap;
typedef std::pair<HolderMap::iterator, HolderMap::iterator> HolderMapBounds;
typedef std::multimap < uint32 /*Entry*/, ObjectGuid > BossGuidMap;
typedef std::pair<BossGuidMap::iterator, BossGuidMap::iterator> BossGuidMapBounds;
typedef std::pair<BossGuidMap::const_iterator, BossGuidMap::const_iterator> BossGuidMapBounds;

// Helper function, to process a slave list
void ProcessSlaveGuidList(CreatureLinkingEvent eventType, Creature* pSource, uint32 flag, uint16 searchRange, GuidList& slaveGuidList, Unit* pEnemy);
Expand All @@ -188,7 +188,7 @@ class CreatureLinkingHolder
// Helper function to set following
void SetFollowing(Creature* pWho, Creature* pWhom);
// Helper function to return if a slave is in range of a boss
bool IsSlaveInRangeOfBoss(Creature* pSlave, Creature* pBoss, uint16 searchRange);
bool IsSlaveInRangeOfBoss(Creature* pSlave, Creature* pBoss, uint16 searchRange) const;

// Storage of Data (boss, flag, searchRange, GuidList) for action triggering
HolderMap m_holderMap;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12982"
#define REVISION_NR "12983"
#endif // __REVISION_NR_H__

0 comments on commit 63b5da1

Please sign in to comment.