From df0715284fda77a5c42b77c6cbf77e10b47bf490 Mon Sep 17 00:00:00 2001 From: SilverIce Date: Thu, 13 Oct 2011 20:08:25 +0300 Subject: [PATCH] [11819] move SetActiveObjectState to WorldObject level --- src/game/Creature.cpp | 20 -------------------- src/game/Creature.h | 2 -- src/game/Map.cpp | 4 +++- src/game/Object.cpp | 17 ++++++++++++++++- src/game/Object.h | 5 ++--- src/game/Player.cpp | 2 +- src/shared/revision_nr.h | 2 +- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 9e01f1cb1..1b2ec1c56 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -2403,26 +2403,6 @@ void Creature::ClearTemporaryFaction() setFaction(GetCreatureInfo()->faction_A); } -void Creature::SetActiveObjectState( bool on ) -{ - if(m_isActiveObject==on) - return; - - bool world = IsInWorld(); - - Map* map; - if(world) - { - map = GetMap(); - map->Remove(this,false); - } - - m_isActiveObject = on; - - if(world) - map->Add(this); -} - void Creature::SendAreaSpiritHealerQueryOpcode(Player *pl) { uint32 next_resurrect = 0; diff --git a/src/game/Creature.h b/src/game/Creature.h index b7b8aeb48..3520bb79b 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -682,8 +682,6 @@ class MANGOS_DLL_SPEC Creature : public Unit void SetDeadByDefault (bool death_state) { m_isDeadByDefault = death_state; } - void SetActiveObjectState(bool on); - void SetFactionTemporary(uint32 factionId, uint32 tempFactionFlags = TEMPFACTION_ALL); void ClearTemporaryFaction(); uint32 GetTemporaryFactionFlags() { return m_temporaryFactionFlags; } diff --git a/src/game/Map.cpp b/src/game/Map.cpp index bc86d42fb..2792d7bfa 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -1081,9 +1081,11 @@ bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const void Map::AddToActive( WorldObject* obj ) { m_activeNonPlayers.insert(obj); + Cell cell = Cell(MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY())); + EnsureGridLoaded(cell); // also not allow unloading spawn grid to prevent creating creature clone at load - if (obj->GetTypeId()==TYPEID_UNIT) + if (obj->GetTypeId() == TYPEID_UNIT) { Creature* c= (Creature*)obj; diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 77fde0648..66e8a2b0f 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1878,4 +1878,19 @@ bool WorldObject::PrintCoordinatesError(float x, float y, float z, char const* d { sLog.outError("%s with invalid %s coordinates: mapid = %uu, x = %f, y = %f, z = %f", GetGuidStr().c_str(), descr, GetMapId(), x, y, z); return false; // always false for continue assert fail -} \ No newline at end of file +} + +void WorldObject::SetActiveObjectState(bool active) +{ + if (m_isActiveObject == active || (isType(TYPEMASK_PLAYER) && !active)) // player shouldn't became inactive, never + return; + + if (IsInWorld()) + { + if (isActiveObject() && !active) + GetMap()->RemoveFromActive(this); + else if (!isActiveObject() && active) + GetMap()->AddToActive(this); + } + m_isActiveObject = active; +} diff --git a/src/game/Object.h b/src/game/Object.h index 000ebf8a9..68f68be8d 100644 --- a/src/game/Object.h +++ b/src/game/Object.h @@ -580,6 +580,7 @@ class MANGOS_DLL_SPEC WorldObject : public Object Creature* SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime, bool asActiveObject = false); bool isActiveObject() const { return m_isActiveObject || m_viewPoint.hasViewers(); } + void SetActiveObjectState(bool active); ViewPoint& GetViewPoint() { return m_viewPoint; } @@ -596,7 +597,6 @@ class MANGOS_DLL_SPEC WorldObject : public Object std::string m_name; - bool m_isActiveObject; private: Map * m_currMap; //current object's Map location @@ -605,10 +605,9 @@ class MANGOS_DLL_SPEC WorldObject : public Object uint32 m_phaseMask; // in area phase state Position m_position; - ViewPoint m_viewPoint; - WorldUpdateCounter m_updateTracker; + bool m_isActiveObject; }; #endif diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 7731dc944..efcdd75ba 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -387,7 +387,7 @@ Player::Player (WorldSession *session): Unit(), m_mover(this), m_camera(this), m m_valuesCount = PLAYER_END; - m_isActiveObject = true; // player is always active object + SetActiveObjectState(true); // player is always active object m_session = session; diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 060f508d6..30bd65673 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "11818" + #define REVISION_NR "11819" #endif // __REVISION_NR_H__