From bf66375bc73c2b9dd7c2d26d7af25b111734c622 Mon Sep 17 00:00:00 2001 From: megamage Date: Wed, 25 Feb 2009 20:52:20 -0600 Subject: *Update active object code. By VladimirMangos. --HG-- branch : trunk --- src/game/DynamicObject.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/game/DynamicObject.cpp') diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp index 12a9cd67500..de8d0eb2c6d 100644 --- a/src/game/DynamicObject.cpp +++ b/src/game/DynamicObject.cpp @@ -57,7 +57,7 @@ void DynamicObject::RemoveFromWorld() { // Make sure the object is back to grid container for removal as farsight targets // are switched to world container on creation and they are also set to active - if (isActive()) + if (isActiveObject()) { GetMap()->SwitchGridContainers(this, false); setActive(false); -- cgit v1.2.3 From ee6418d92a4cccbf63941016e7339ce557144287 Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 26 Feb 2009 16:29:55 -0600 Subject: *Update active object code. --HG-- branch : trunk --- src/game/Creature.cpp | 2 +- src/game/DynamicObject.cpp | 12 +----------- src/game/Map.cpp | 32 +++++++++++++++++++++++++------- src/game/Object.cpp | 19 +++++++++++++++++++ src/game/Object.h | 1 + src/game/Pet.cpp | 2 +- src/game/SpellEffects.cpp | 7 ++----- src/game/Unit.cpp | 18 ++++++------------ 8 files changed, 56 insertions(+), 37 deletions(-) (limited to 'src/game/DynamicObject.cpp') diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index e2a9fab0998..23ae8229251 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1662,7 +1662,7 @@ void Creature::setDeathState(DeathState s) { SetUInt64Value (UNIT_FIELD_TARGET,0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState) SetUInt32Value(UNIT_NPC_FLAGS, 0); - if(!isPet()) + //if(!isPet()) setActive(false); if(!isPet() && GetCreatureInfo()->SkinLootId) diff --git a/src/game/DynamicObject.cpp b/src/game/DynamicObject.cpp index de8d0eb2c6d..0ae3656fc9d 100644 --- a/src/game/DynamicObject.cpp +++ b/src/game/DynamicObject.cpp @@ -53,17 +53,7 @@ void DynamicObject::AddToWorld() void DynamicObject::RemoveFromWorld() { ///- Remove the dynamicObject from the accessor - if(IsInWorld()) - { - // Make sure the object is back to grid container for removal as farsight targets - // are switched to world container on creation and they are also set to active - if (isActiveObject()) - { - GetMap()->SwitchGridContainers(this, false); - setActive(false); - } - ObjectAccessor::Instance().RemoveObject(this); - } + if(IsInWorld()) ObjectAccessor::Instance().RemoveObject(this); WorldObject::RemoveFromWorld(); } diff --git a/src/game/Map.cpp b/src/game/Map.cpp index d40c341fd47..6bbefa8b0a0 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -269,6 +269,15 @@ void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell) obj->SetCurrentCell(cell); } +template<> +void Map::AddToGrid(DynamicObject* obj, NGridType *grid, Cell const& cell) +{ + if(obj->isActiveObject()) // only farsight + (*grid)(cell.CellX(), cell.CellY()).AddWorldObject(obj, obj->GetGUID()); + else + (*grid)(cell.CellX(), cell.CellY()).AddGridObject(obj, obj->GetGUID()); +} + template void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell) { @@ -311,6 +320,15 @@ void Map::RemoveFromGrid(Creature* obj, NGridType *grid, Cell const& cell) } } +template<> +void Map::RemoveFromGrid(DynamicObject* obj, NGridType *grid, Cell const& cell) +{ + if(obj->isActiveObject()) // only farsight + (*grid)(cell.CellX(), cell.CellY()).RemoveWorldObject(obj, obj->GetGUID()); + else + (*grid)(cell.CellX(), cell.CellY()).RemoveGridObject(obj, obj->GetGUID()); +} + template void Map::SwitchGridContainers(T* obj, bool apply) { @@ -321,18 +339,18 @@ void Map::SwitchGridContainers(T* obj, bool apply) if(apply) { - assert(!grid.GetWorldObject(obj->GetGUID(), obj)); + if(!grid.RemoveGridObject(obj, obj->GetGUID()) + || !grid.AddWorldObject(obj, obj->GetGUID())) { - grid.RemoveGridObject(obj, obj->GetGUID()); - grid.AddWorldObject(obj, obj->GetGUID()); + assert(false); } } else { - assert(!grid.GetGridObject(obj->GetGUID(), obj)); + if(!grid.RemoveWorldObject(obj, obj->GetGUID()) + || !grid.AddGridObject(obj, obj->GetGUID())) { - grid.RemoveWorldObject(obj, obj->GetGUID()); - grid.AddGridObject(obj, obj->GetGUID()); + assert(false); } } } @@ -428,7 +446,7 @@ void Map::LoadGrid(float x, float y) { CellPair pair = Trinity::ComputeCellPair(x, y); Cell cell(pair); - EnsureGridLoaded(cell, NULL); + EnsureGridLoaded(cell); } bool Map::Add(Player *player) diff --git a/src/game/Object.cpp b/src/game/Object.cpp index f35b392991e..1e0834ecf1f 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1070,11 +1070,30 @@ WorldObject::WorldObject() m_isActive = false; } +void WorldObject::SetWorldObject(bool on) +{ + if(!IsInWorld()) + return; + + if(GetTypeId() == TYPEID_UNIT) + { + if(!((Creature*)this)->isPet()) + GetMap()->SwitchGridContainers((Creature*)this, on); + } + /*else if(GetTypeId() == TYPEID_DYNAMICOBJECT) + { + GetMap()->SwitchGridContainers((DynamicObject*)this, on); + }*/ +} + void WorldObject::setActive( bool on ) { if(m_isActive==on) return; + if(GetTypeId() == TYPEID_PLAYER) + return; + bool world = IsInWorld(); Map* map; diff --git a/src/game/Object.h b/src/game/Object.h index ab3e49721b3..c6d5f73f3ed 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -486,6 +486,7 @@ class TRINITY_DLL_SPEC WorldObject : public Object Creature* SummonTrigger(float x, float y, float z, float ang, uint32 dur, CreatureAI* (*GetAI)(Creature*) = NULL); bool isActiveObject() const { return m_isActive; } void setActive(bool isActiveObject); + void SetWorldObject(bool apply); template void VisitNearbyObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitAll(GetPositionX(), GetPositionY(), radius, notifier); } template void VisitNearbyGridObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitGrid(GetPositionX(), GetPositionY(), radius, notifier); } template void VisitNearbyWorldObject(const float &radius, NOTIFIER ¬ifier) const { GetMap()->VisitWorld(GetPositionX(), GetPositionY(), radius, notifier); } diff --git a/src/game/Pet.cpp b/src/game/Pet.cpp index a8e662108e8..00452fc0d95 100644 --- a/src/game/Pet.cpp +++ b/src/game/Pet.cpp @@ -96,7 +96,7 @@ Pet::Pet(PetType type) : Creature() m_CreatureCategoryCooldowns.clear(); m_autospells.clear(); m_declinedname = NULL; - m_isActive = true; + //m_isActive = true; } Pet::~Pet() diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 846ab8ddf13..c9e0d1e0647 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3497,11 +3497,8 @@ void Spell::EffectAddFarsight(uint32 i) dynObj->SetUInt32Value(DYNAMICOBJECT_BYTES, 0x80000002); m_caster->AddDynObject(dynObj); - Map* map = dynObj->GetMap(); - map->LoadGrid(dynObj->GetPositionX(), dynObj->GetPositionY()); // In case the spell is casted into a different grid by player - map->Add(dynObj); - dynObj->setActive(true); // Keep the grid updated even if there are no players in it - map->SwitchGridContainers(dynObj, true); // Needed for forwarding player packets + dynObj->setActive(true); //must before add to map to be put in world container + dynObj->GetMap()->Add(dynObj); //grid will also be loaded // Need to update visibility of object for client to accept farsight guid ((Player*)m_caster)->UpdateVisibilityOf(dynObj); diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 8f5462cea81..6f63d8c9825 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -8502,25 +8502,19 @@ void Unit::SetCharm(Unit* pet) void Unit::AddPlayerToVision(Player* plr) { - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT - && !((Creature*)this)->isPet()) - { - setActive(true); - GetMap()->SwitchGridContainers((Creature*)this, true); - } + setActive(true); + if(m_sharedVision.empty()) + SetWorldObject(true); m_sharedVision.push_back(plr); plr->SetFarsightTarget(this); } void Unit::RemovePlayerFromVision(Player* plr) { + setActive(false); m_sharedVision.remove(plr); - if (m_sharedVision.empty() && GetTypeId() == TYPEID_UNIT - && !((Creature*)this)->isPet()) - { - GetMap()->SwitchGridContainers((Creature*)this, false); - setActive(false); - } + if(m_sharedVision.empty()) + SetWorldObject(false); plr->ClearFarsight(); } -- cgit v1.2.3