Core/Quests: Some cleanup in quest relation accessing
--HG-- branch : trunk
This commit is contained in:
@@ -1315,8 +1315,8 @@ void Creature::LoadEquipment(uint32 equip_entry, bool force)
|
||||
|
||||
bool Creature::hasQuest(uint32 quest_id) const
|
||||
{
|
||||
QuestRelations const& qr = sObjectMgr.mCreatureQuestRelations;
|
||||
for (QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
|
||||
QuestRelationBounds qr = sObjectMgr.GetCreatureQuestRelationBounds(GetEntry());
|
||||
for (QuestRelations::const_iterator itr = qr.first; itr != qr.second; ++itr)
|
||||
{
|
||||
if (itr->second == quest_id)
|
||||
return true;
|
||||
@@ -1326,8 +1326,8 @@ bool Creature::hasQuest(uint32 quest_id) const
|
||||
|
||||
bool Creature::hasInvolvedQuest(uint32 quest_id) const
|
||||
{
|
||||
QuestRelations const& qr = sObjectMgr.mCreatureQuestInvolvedRelations;
|
||||
for (QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
|
||||
QuestRelationBounds qir = sObjectMgr.GetCreatureQuestInvolvedRelationBounds(GetEntry());
|
||||
for (QuestRelations::const_iterator itr = qir.first; itr != qir.second; ++itr)
|
||||
{
|
||||
if (itr->second == quest_id)
|
||||
return true;
|
||||
|
||||
@@ -742,8 +742,8 @@ GameObject* GameObject::GetGameObject(WorldObject& object, uint64 guid)
|
||||
/*********************************************************/
|
||||
bool GameObject::hasQuest(uint32 quest_id) const
|
||||
{
|
||||
QuestRelations const& qr = sObjectMgr.mGOQuestRelations;
|
||||
for (QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
|
||||
QuestRelationBounds qr = sObjectMgr.GetGOQuestRelationBounds(GetEntry());
|
||||
for (QuestRelations::const_iterator itr = qr.first; itr != qr.second; ++itr)
|
||||
{
|
||||
if (itr->second == quest_id)
|
||||
return true;
|
||||
@@ -753,8 +753,8 @@ bool GameObject::hasQuest(uint32 quest_id) const
|
||||
|
||||
bool GameObject::hasInvolvedQuest(uint32 quest_id) const
|
||||
{
|
||||
QuestRelations const& qr = sObjectMgr.mGOQuestInvolvedRelations;
|
||||
for (QuestRelations::const_iterator itr = qr.lower_bound(GetEntry()); itr != qr.upper_bound(GetEntry()); ++itr)
|
||||
QuestRelationBounds qir = sObjectMgr.GetGOQuestInvolvedRelationBounds(GetEntry());
|
||||
for (QuestRelations::const_iterator itr = qir.first; itr != qir.second; ++itr)
|
||||
{
|
||||
if (itr->second == quest_id)
|
||||
return true;
|
||||
|
||||
@@ -13800,17 +13800,15 @@ uint32 Player::GetDefaultGossipMenuForSource(WorldObject *pSource)
|
||||
|
||||
void Player::PrepareQuestMenu(uint64 guid)
|
||||
{
|
||||
Object *pObject;
|
||||
QuestRelations* pObjectQR;
|
||||
QuestRelations* pObjectQIR;
|
||||
QuestRelationBounds pObjectQR;
|
||||
QuestRelationBounds pObjectQIR;
|
||||
|
||||
// pets also can have quests
|
||||
Creature *pCreature = ObjectAccessor::GetCreatureOrPetOrVehicle(*this, guid);
|
||||
if (pCreature)
|
||||
{
|
||||
pObject = (Object*)pCreature;
|
||||
pObjectQR = &sObjectMgr.mCreatureQuestRelations;
|
||||
pObjectQIR = &sObjectMgr.mCreatureQuestInvolvedRelations;
|
||||
pObjectQR = sObjectMgr.GetCreatureQuestRelationBounds(pCreature->GetEntry());
|
||||
pObjectQIR = sObjectMgr.GetCreatureQuestInvolvedRelationBounds(pCreature->GetEntry());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -13821,9 +13819,8 @@ void Player::PrepareQuestMenu(uint64 guid)
|
||||
GameObject *pGameObject = _map->GetGameObject(guid);
|
||||
if (pGameObject)
|
||||
{
|
||||
pObject = (Object*)pGameObject;
|
||||
pObjectQR = &sObjectMgr.mGOQuestRelations;
|
||||
pObjectQIR = &sObjectMgr.mGOQuestInvolvedRelations;
|
||||
pObjectQR = sObjectMgr.GetGOQuestRelationBounds(pGameObject->GetEntry());
|
||||
pObjectQIR = sObjectMgr.GetGOQuestInvolvedRelationBounds(pGameObject->GetEntry());
|
||||
}
|
||||
else
|
||||
return;
|
||||
@@ -13832,7 +13829,7 @@ void Player::PrepareQuestMenu(uint64 guid)
|
||||
QuestMenu &qm = PlayerTalkClass->GetQuestMenu();
|
||||
qm.ClearMenu();
|
||||
|
||||
for (QuestRelations::const_iterator i = pObjectQIR->lower_bound(pObject->GetEntry()); i != pObjectQIR->upper_bound(pObject->GetEntry()); ++i)
|
||||
for (QuestRelations::const_iterator i = pObjectQIR.first; i != pObjectQIR.second; ++i)
|
||||
{
|
||||
uint32 quest_id = i->second;
|
||||
QuestStatus status = GetQuestStatus(quest_id);
|
||||
@@ -13844,7 +13841,7 @@ void Player::PrepareQuestMenu(uint64 guid)
|
||||
// qm.AddMenuItem(quest_id, 2);
|
||||
}
|
||||
|
||||
for (QuestRelations::const_iterator i = pObjectQR->lower_bound(pObject->GetEntry()); i != pObjectQR->upper_bound(pObject->GetEntry()); ++i)
|
||||
for (QuestRelations::const_iterator i = pObjectQR.first; i != pObjectQR.second; ++i)
|
||||
{
|
||||
uint32 quest_id = i->second;
|
||||
Quest const* pQuest = sObjectMgr.GetQuestTemplate(quest_id);
|
||||
@@ -13964,17 +13961,11 @@ bool Player::IsActiveQuest(uint32 quest_id) const
|
||||
|
||||
Quest const * Player::GetNextQuest(uint64 guid, Quest const *pQuest)
|
||||
{
|
||||
Object *pObject;
|
||||
QuestRelations* pObjectQR;
|
||||
QuestRelations* pObjectQIR;
|
||||
QuestRelationBounds pObjectQR;
|
||||
|
||||
Creature *pCreature = ObjectAccessor::GetCreatureOrPetOrVehicle(*this,guid);
|
||||
if (pCreature)
|
||||
{
|
||||
pObject = (Object*)pCreature;
|
||||
pObjectQR = &sObjectMgr.mCreatureQuestRelations;
|
||||
pObjectQIR = &sObjectMgr.mCreatureQuestInvolvedRelations;
|
||||
}
|
||||
pObjectQR = sObjectMgr.GetCreatureQuestRelationBounds(pCreature->GetEntry());
|
||||
else
|
||||
{
|
||||
//we should obtain map pointer from GetMap() in 99% of cases. Special case
|
||||
@@ -13983,17 +13974,13 @@ Quest const * Player::GetNextQuest(uint64 guid, Quest const *pQuest)
|
||||
ASSERT(_map);
|
||||
GameObject *pGameObject = _map->GetGameObject(guid);
|
||||
if (pGameObject)
|
||||
{
|
||||
pObject = (Object*)pGameObject;
|
||||
pObjectQR = &sObjectMgr.mGOQuestRelations;
|
||||
pObjectQIR = &sObjectMgr.mGOQuestInvolvedRelations;
|
||||
}
|
||||
pObjectQR = sObjectMgr.GetGOQuestRelationBounds(pGameObject->GetEntry());
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32 nextQuestID = pQuest->GetNextQuestInChain();
|
||||
for (QuestRelations::const_iterator itr = pObjectQR->lower_bound(pObject->GetEntry()); itr != pObjectQR->upper_bound(pObject->GetEntry()); ++itr)
|
||||
for (QuestRelations::const_iterator itr = pObjectQR.first; itr != pObjectQR.second; ++itr)
|
||||
{
|
||||
if (itr->second == nextQuestID)
|
||||
return sObjectMgr.GetQuestTemplate(nextQuestID);
|
||||
|
||||
@@ -1534,23 +1534,23 @@ void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate)
|
||||
QuestRelList::iterator itr;
|
||||
for (itr = mGameEventCreatureQuests[event_id].begin(); itr != mGameEventCreatureQuests[event_id].end(); ++itr)
|
||||
{
|
||||
QuestRelations &CreatureQuestMap = sObjectMgr.mCreatureQuestRelations;
|
||||
QuestRelations* CreatureQuestMap = sObjectMgr.GetCreatureQuestRelationMap();
|
||||
if (activate) // Add the pair(id,quest) to the multimap
|
||||
CreatureQuestMap.insert(QuestRelations::value_type(itr->first, itr->second));
|
||||
CreatureQuestMap->insert(QuestRelations::value_type(itr->first, itr->second));
|
||||
else
|
||||
{
|
||||
if (!hasCreatureQuestActiveEventExcept(itr->second,event_id))
|
||||
{
|
||||
// Remove the pair(id,quest) from the multimap
|
||||
QuestRelations::iterator qitr = CreatureQuestMap.find(itr->first);
|
||||
if (qitr == CreatureQuestMap.end())
|
||||
QuestRelations::iterator qitr = CreatureQuestMap->find(itr->first);
|
||||
if (qitr == CreatureQuestMap->end())
|
||||
continue;
|
||||
QuestRelations::iterator lastElement = CreatureQuestMap.upper_bound(itr->first);
|
||||
QuestRelations::iterator lastElement = CreatureQuestMap->upper_bound(itr->first);
|
||||
for (; qitr != lastElement; ++qitr)
|
||||
{
|
||||
if (qitr->second == itr->second)
|
||||
{
|
||||
CreatureQuestMap.erase(qitr); // iterator is now no more valid
|
||||
CreatureQuestMap->erase(qitr); // iterator is now no more valid
|
||||
break; // but we can exit loop since the element is found
|
||||
}
|
||||
}
|
||||
@@ -1559,23 +1559,23 @@ void GameEventMgr::UpdateEventQuests(uint16 event_id, bool activate)
|
||||
}
|
||||
for (itr = mGameEventGameObjectQuests[event_id].begin(); itr != mGameEventGameObjectQuests[event_id].end(); ++itr)
|
||||
{
|
||||
QuestRelations &GameObjectQuestMap = sObjectMgr.mGOQuestRelations;
|
||||
QuestRelations* GameObjectQuestMap = sObjectMgr.GetGOQuestRelationMap();
|
||||
if (activate) // Add the pair(id,quest) to the multimap
|
||||
GameObjectQuestMap.insert(QuestRelations::value_type(itr->first, itr->second));
|
||||
GameObjectQuestMap->insert(QuestRelations::value_type(itr->first, itr->second));
|
||||
else
|
||||
{
|
||||
if (!hasGameObjectQuestActiveEventExcept(itr->second,event_id))
|
||||
{
|
||||
// Remove the pair(id,quest) from the multimap
|
||||
QuestRelations::iterator qitr = GameObjectQuestMap.find(itr->first);
|
||||
if (qitr == GameObjectQuestMap.end())
|
||||
QuestRelations::iterator qitr = GameObjectQuestMap->find(itr->first);
|
||||
if (qitr == GameObjectQuestMap->end())
|
||||
continue;
|
||||
QuestRelations::iterator lastElement = GameObjectQuestMap.upper_bound(itr->first);
|
||||
QuestRelations::iterator lastElement = GameObjectQuestMap->upper_bound(itr->first);
|
||||
for (; qitr != lastElement; ++qitr)
|
||||
{
|
||||
if (qitr->second == itr->second)
|
||||
{
|
||||
GameObjectQuestMap.erase(qitr); // iterator is now no more valid
|
||||
GameObjectQuestMap->erase(qitr); // iterator is now no more valid
|
||||
break; // but we can exit loop since the element is found
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +192,7 @@ typedef UNORDERED_MAP<uint32,GossipMenuItemsLocale> GossipMenuItemsLocaleMap;
|
||||
typedef UNORDERED_MAP<uint32,PointOfInterestLocale> PointOfInterestLocaleMap;
|
||||
|
||||
typedef std::multimap<uint32,uint32> QuestRelations;
|
||||
typedef std::pair<QuestRelations::const_iterator, QuestRelations::const_iterator> QuestRelationBounds;
|
||||
typedef std::multimap<uint32,ItemRequiredTarget> ItemRequiredTargetMap;
|
||||
typedef std::pair<ItemRequiredTargetMap::const_iterator, ItemRequiredTargetMap::const_iterator> ItemRequiredTargetMapBounds;
|
||||
|
||||
@@ -612,10 +613,35 @@ class ObjectMgr
|
||||
void LoadCreatureQuestRelations();
|
||||
void LoadCreatureInvolvedRelations();
|
||||
|
||||
QuestRelations mGOQuestRelations;
|
||||
QuestRelations mGOQuestInvolvedRelations;
|
||||
QuestRelations mCreatureQuestRelations;
|
||||
QuestRelations mCreatureQuestInvolvedRelations;
|
||||
QuestRelations* GetGOQuestRelationMap()
|
||||
{
|
||||
return &mGOQuestRelations;
|
||||
}
|
||||
|
||||
QuestRelationBounds GetGOQuestRelationBounds(uint32 go_entry)
|
||||
{
|
||||
return mGOQuestRelations.equal_range(go_entry);
|
||||
}
|
||||
|
||||
QuestRelationBounds GetGOQuestInvolvedRelationBounds(uint32 go_entry)
|
||||
{
|
||||
return mGOQuestInvolvedRelations.equal_range(go_entry);
|
||||
}
|
||||
|
||||
QuestRelations* GetCreatureQuestRelationMap()
|
||||
{
|
||||
return &mCreatureQuestRelations;
|
||||
}
|
||||
|
||||
QuestRelationBounds GetCreatureQuestRelationBounds(uint32 creature_entry)
|
||||
{
|
||||
return mCreatureQuestRelations.equal_range(creature_entry);
|
||||
}
|
||||
|
||||
QuestRelationBounds GetCreatureQuestInvolvedRelationBounds(uint32 creature_entry)
|
||||
{
|
||||
return mCreatureQuestInvolvedRelations.equal_range(creature_entry);
|
||||
}
|
||||
|
||||
void LoadGameObjectScripts();
|
||||
void LoadQuestEndScripts();
|
||||
@@ -1026,6 +1052,11 @@ class ObjectMgr
|
||||
|
||||
QuestPOIMap mQuestPOIMap;
|
||||
|
||||
QuestRelations mGOQuestRelations;
|
||||
QuestRelations mGOQuestInvolvedRelations;
|
||||
QuestRelations mCreatureQuestRelations;
|
||||
QuestRelations mCreatureQuestInvolvedRelations;
|
||||
|
||||
//character reserved names
|
||||
typedef std::set<std::wstring> ReservedNamesMap;
|
||||
ReservedNamesMap m_ReservedNames;
|
||||
|
||||
@@ -572,21 +572,21 @@ uint32 WorldSession::getDialogStatus(Player *pPlayer, Object* questgiver, uint32
|
||||
{
|
||||
uint32 result = defstatus;
|
||||
|
||||
QuestRelations const* qir;
|
||||
QuestRelations const* qr;
|
||||
QuestRelationBounds qr;
|
||||
QuestRelationBounds qir;
|
||||
|
||||
switch(questgiver->GetTypeId())
|
||||
{
|
||||
case TYPEID_GAMEOBJECT:
|
||||
{
|
||||
qir = &sObjectMgr.mGOQuestInvolvedRelations;
|
||||
qr = &sObjectMgr.mGOQuestRelations;
|
||||
qr = sObjectMgr.GetGOQuestRelationBounds(questgiver->GetEntry());
|
||||
qir = sObjectMgr.GetGOQuestInvolvedRelationBounds(questgiver->GetEntry());
|
||||
break;
|
||||
}
|
||||
case TYPEID_UNIT:
|
||||
{
|
||||
qir = &sObjectMgr.mCreatureQuestInvolvedRelations;
|
||||
qr = &sObjectMgr.mCreatureQuestRelations;
|
||||
qr = sObjectMgr.GetCreatureQuestRelationBounds(questgiver->GetEntry());
|
||||
qir = sObjectMgr.GetCreatureQuestInvolvedRelationBounds(questgiver->GetEntry());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -595,7 +595,7 @@ uint32 WorldSession::getDialogStatus(Player *pPlayer, Object* questgiver, uint32
|
||||
return DIALOG_STATUS_NONE;
|
||||
}
|
||||
|
||||
for (QuestRelations::const_iterator i = qir->lower_bound(questgiver->GetEntry()); i != qir->upper_bound(questgiver->GetEntry()); ++i)
|
||||
for (QuestRelations::const_iterator i = qir.first; i != qir.second; ++i)
|
||||
{
|
||||
uint32 result2 = 0;
|
||||
uint32 quest_id = i->second;
|
||||
@@ -618,7 +618,7 @@ uint32 WorldSession::getDialogStatus(Player *pPlayer, Object* questgiver, uint32
|
||||
result = result2;
|
||||
}
|
||||
|
||||
for (QuestRelations::const_iterator i = qr->lower_bound(questgiver->GetEntry()); i != qr->upper_bound(questgiver->GetEntry()); ++i)
|
||||
for (QuestRelations::const_iterator i = qr.first; i != qr.second; ++i)
|
||||
{
|
||||
uint32 result2 = 0;
|
||||
uint32 quest_id = i->second;
|
||||
|
||||
Reference in New Issue
Block a user