Index: /trunk/src/game/GridNotifiers.h
===================================================================
--- /trunk/src/game/GridNotifiers.h (revision 233)
+++ /trunk/src/game/GridNotifiers.h (revision 266)
@@ -699,17 +699,39 @@
     // Creature checks
 
-    class InAttackDistanceFromAnyHostileCreatureCheck
-    {
-        public:
-            explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {}
-            bool operator()(Creature* u)
-            {
-                if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit)))
-                    return true;
-
-                return false;
-            }
-        private:
-            Unit* const i_funit;
+    class NearestHostileUnitInAttackDistanceCheck
+    {
+        public:
+            explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature) 
+            {
+                m_range = (dist == 0 ? 9999 : dist);
+                m_force = (dist == 0 ? false : true);
+            }
+            bool operator()(Unit* u)
+            {
+                if(!u->isAlive() || !m_creature->IsHostileTo(u))
+                    return false;
+
+                float dist;
+                if(m_force) dist = m_range;
+                else
+                {
+                    dist = m_creature->GetAttackDistance(u);
+                    if(dist > m_range) dist = m_range;
+                }
+                if(!m_creature->IsWithinDistInMap(u, dist))
+                    return false;
+
+                if(!m_creature->canSeeOrDetect(u, true, false))
+                    return false;
+
+                m_range = m_creature->GetDistance(u);
+                return true;
+            }
+            float GetLastRange() const { return m_range; }
+        private:
+            Creature* const m_creature;
+            float m_range;
+            bool m_force;
+            NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&);
     };
 
Index: /trunk/src/game/Unit.h
===================================================================
--- /trunk/src/game/Unit.h (revision 257)
+++ /trunk/src/game/Unit.h (revision 266)
@@ -763,5 +763,5 @@
         void CombatStop(bool cast = false);
         void CombatStopWithPets(bool cast = false);
-        Unit* SelectNearbyTarget() const;
+        Unit* SelectNearbyTarget(float dist = ATTACK_DISTANCE) const;
 
         void addUnitState(uint32 f) { m_state |= f; }
Index: /trunk/src/game/Creature.cpp
===================================================================
--- /trunk/src/game/Creature.cpp (revision 265)
+++ /trunk/src/game/Creature.cpp (revision 266)
@@ -1823,4 +1823,27 @@
 }
 
+Unit* Creature::SelectNearestTarget(float dist) const
+{
+    /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY()));
+    Cell cell(p);
+    cell.data.Part.reserved = ALL_DISTRICT;
+    cell.SetNoCreate();
+
+    Unit *target;
+
+    {
+        Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist);
+        Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck> searcher(target, u_check);
+
+        TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
+        TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher);
+
+        CellLock<GridReadGuard> cell_lock(cell, p);
+        cell_lock->Visit(cell_lock, world_unit_searcher, GetMap());
+        cell_lock->Visit(cell_lock, grid_unit_searcher, GetMap());
+    }*/
+    return NULL;
+}
+
 void Creature::CallAssistence()
 {
Index: /trunk/src/game/Map.cpp
===================================================================
--- /trunk/src/game/Map.cpp (revision 260)
+++ /trunk/src/game/Map.cpp (revision 266)
@@ -597,5 +597,7 @@
 void Map::Update(const uint32 &t_diff)
 {
-    resetMarkedCells();
+    // TODO: need have an active object list for every map
+
+    /*resetMarkedCells();
 
     Trinity::ObjectUpdater updater(t_diff);
@@ -643,6 +645,5 @@
             }
         }
-    }
-
+    }*/
 
     // Don't unload grids if it's battleground, since we may have manually added GOs,creatures, those doesn't load from DB at grid re-load !
Index: /trunk/src/game/Creature.h
===================================================================
--- /trunk/src/game/Creature.h (revision 265)
+++ /trunk/src/game/Creature.h (revision 266)
@@ -560,4 +560,5 @@
         float GetAttackDistance(Unit const* pl) const;
 
+        Unit* SelectNearestTarget(float dist = 0) const;
         void CallAssistence();
         void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; }
Index: /trunk/src/game/Unit.cpp
===================================================================
--- /trunk/src/game/Unit.cpp (revision 265)
+++ /trunk/src/game/Unit.cpp (revision 266)
@@ -10425,5 +10425,5 @@
 }
 
-Unit* Unit::SelectNearbyTarget() const
+Unit* Unit::SelectNearbyTarget(float dist) const
 {
     CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY()));
@@ -10435,5 +10435,5 @@
 
     {
-        Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE);
+        Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, dist);
         Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(targets, u_check);
 
Index: /trunk/src/game/ObjectAccessor.cpp
===================================================================
--- /trunk/src/game/ObjectAccessor.cpp (revision 257)
+++ /trunk/src/game/ObjectAccessor.cpp (revision 266)
@@ -504,4 +504,6 @@
 
     {
+        //Player update now in MapManager -> UpdatePlayers
+        /*
         // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects.
         HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
@@ -512,6 +514,7 @@
                 iter->second->Update(diff);
             }
-        }
-
+        }*/
+
+        // TODO: move this to Map::Update
         // clone the active object list, because update might remove from it
         std::set<WorldObject *> activeobjects(i_activeobjects);
@@ -573,4 +576,26 @@
         }
     }
+
+    UpdateDataMapType update_players;
+    {
+        Guard guard(i_updateGuard);
+        while(!i_objects.empty())
+        {
+            Object* obj = *i_objects.begin();
+            i_objects.erase(i_objects.begin());
+            if (!obj)
+                continue;
+            _buildUpdateObject(obj, update_players);
+            obj->ClearUpdateMask(false);
+        }
+    }
+
+    WorldPacket packet;                                     // here we allocate a std::vector with a size of 0x10000
+    for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
+    {
+        iter->second.BuildPacket(&packet);
+        iter->first->GetSession()->SendPacket(&packet);
+        packet.clear();                                     // clean the string
+    }
 }
 
