Core/Phases: Preliminary work with correctly implementing the phase system in 4.3.4

Put here for peer review.
This commit is contained in:
Subv
2014-06-01 22:27:29 -05:00
parent 6bc62d730e
commit 48ec2df81f
40 changed files with 436 additions and 863 deletions

View File

@@ -1493,7 +1493,7 @@ bool WorldObject::IsWithinDist(WorldObject const* obj, float dist2compare, bool
bool WorldObject::IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D /*= true*/) const
{
return obj && IsInMap(obj) && InSamePhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
return obj && IsInMap(obj) && IsInPhase(obj) && _IsWithinDist(obj, dist2compare, is3D);
}
bool WorldObject::IsWithinLOS(float ox, float oy, float oz) const
@@ -1932,7 +1932,7 @@ bool WorldObject::CanSeeOrDetect(WorldObject const* obj, bool ignoreStealth, boo
bool WorldObject::CanNeverSee(WorldObject const* obj) const
{
return GetMap() != obj->GetMap() || !InSamePhase(obj);
return GetMap() != obj->GetMap() || !IsInPhase(obj);
}
bool WorldObject::CanDetect(WorldObject const* obj, bool ignoreStealth) const
@@ -2330,8 +2330,12 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
}
uint32 phase = PHASEMASK_NORMAL;
std::set<uint32> phases;
if (summoner)
{
phase = summoner->GetPhaseMask();
phases = summoner->GetPhases();
}
TempSummon* summon = NULL;
switch (mask)
@@ -2359,6 +2363,10 @@ TempSummon* Map::SummonCreature(uint32 entry, Position const& pos, SummonPropert
return NULL;
}
// Set the summon to the summoner's phase
for (auto phaseId : phases)
summon->SetInPhase(phaseId, false, true);
summon->SetUInt32Value(UNIT_CREATED_BY_SPELL, spellId);
summon->SetHomePosition(pos);
@@ -2453,6 +2461,9 @@ GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float
return NULL;
}
for (auto phase : GetPhases())
go->SetInPhase(phase, false, true);
go->SetRespawnTime(respawnTime);
if (GetTypeId() == TYPEID_PLAYER || GetTypeId() == TYPEID_UNIT) //not sure how to handle this
ToUnit()->AddGameObject(go);
@@ -2835,9 +2846,39 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update)
UpdateObjectVisibility();
}
void WorldObject::SetInPhase(uint32 id, bool update, bool apply)
{
if (apply)
_phases.insert(id);
else
_phases.erase(id);
if (update && IsInWorld())
UpdateObjectVisibility();
}
bool WorldObject::IsInPhase(WorldObject const* obj) const
{
// PhaseId 169 is the default fallback phase
if (_phases.empty() && obj->GetPhases().empty())
return true;
if (_phases.empty() && obj->IsInPhase(169))
return true;
if (obj->GetPhases().empty() && IsInPhase(169))
return true;
for (auto phase : _phases)
if (obj->IsInPhase(phase))
return true;
return false;
}
bool WorldObject::InSamePhase(WorldObject const* obj) const
{
return InSamePhase(obj->GetPhaseMask());
return IsInPhase(obj);
// return InSamePhase(obj->GetPhaseMask());
}
void WorldObject::PlayDistanceSound(uint32 sound_id, Player* target /*= NULL*/)