Skip to content

Commit

Permalink
[12206] Let GetMapEntranceTrigger and GetGoBackTrigger work in a bett…
Browse files Browse the repository at this point in the history
…er defined order

Actually as this is still no total order (and it is basicly impossible to define a reasonable total order for areatrigger_teleport) it is not well defined, but probably good enough for all cases
  • Loading branch information
Schmoozerd authored and Salja committed Sep 9, 2012
1 parent a0265a8 commit 09ddd68
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
37 changes: 29 additions & 8 deletions src/game/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5714,33 +5714,54 @@ AreaTrigger const* ObjectMgr::GetGoBackTrigger(uint32 map_id) const
if (!mapEntry || mapEntry->ghost_entrance_map < 0)
return NULL;

AreaTrigger const* compareTrigger = NULL;
for (AreaTriggerMap::const_iterator itr = mAreaTriggers.begin(); itr != mAreaTriggers.end(); ++itr)
{
if (itr->second.target_mapId == uint32(mapEntry->ghost_entrance_map))
{
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(itr->first);
if (atEntry && atEntry->mapid == map_id)
return &itr->second;
if (!compareTrigger || itr->second.IsLessOrEqualThan(compareTrigger))
{
if (itr->second.IsMinimal())
return &itr->second;

compareTrigger = &itr->second;
}
}
}
return NULL;
return compareTrigger;
}

/**
* Searches for the areatrigger which teleports players to the given map
*/
AreaTrigger const* ObjectMgr::GetMapEntranceTrigger(uint32 Map) const
{
AreaTrigger const* compareTrigger = NULL;
MapEntry const* mEntry = sMapStore.LookupEntry(Map);

for (AreaTriggerMap::const_iterator itr = mAreaTriggers.begin(); itr != mAreaTriggers.end(); ++itr)
{
if (itr->second.target_mapId == Map)
{
AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(itr->first);
if (atEntry)
return &itr->second;
if (mEntry->Instanceable())
{
// Remark that IsLessOrEqualThan is no total order, and a->IsLeQ(b) != !b->IsLeQ(a)
if (!compareTrigger || compareTrigger->IsLessOrEqualThan(&itr->second))
compareTrigger = &itr->second;
}
else
{
if (!compareTrigger || itr->second.IsLessOrEqualThan(compareTrigger))
{
if (itr->second.IsMinimal())
return &itr->second;

compareTrigger = &itr->second;
}
}
}
}
return NULL;
return compareTrigger;
}

void ObjectMgr::PackGroupIds()
Expand Down
11 changes: 11 additions & 0 deletions src/game/ObjectMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ struct AreaTrigger
float target_Y;
float target_Z;
float target_Orientation;

// Operators
bool IsMinimal() const { return requiredLevel == 0 && requiredItem == 0 && requiredItem2 == 0 && heroicKey == 0 &&
heroicKey2 == 0 && requiredQuest == 0 && requiredQuestHeroic == 0; }

bool IsLessOrEqualThan(AreaTrigger const* l) const // Expected to have same map
{
MANGOS_ASSERT(target_mapId == l->target_mapId);
return requiredLevel <= l->requiredLevel && requiredItem <= l->requiredItem && requiredItem2 <= l->requiredItem2
&& heroicKey <= l->heroicKey&& heroicKey2 <= l->heroicKey2 && requiredQuest <= l->requiredQuest && requiredQuestHeroic <= l->requiredQuestHeroic;
}
};

typedef std::map < uint32/*player guid*/, uint32/*instance*/ > CellCorpseSet;
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 "12205"
#define REVISION_NR "12206"
#endif // __REVISION_NR_H__

0 comments on commit 09ddd68

Please sign in to comment.