diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Creature.cpp | 23 | ||||
-rw-r--r-- | src/game/Creature.h | 1 | ||||
-rw-r--r-- | src/game/GridNotifiers.h | 36 | ||||
-rw-r--r-- | src/game/Map.cpp | 7 | ||||
-rw-r--r-- | src/game/ObjectAccessor.cpp | 27 | ||||
-rw-r--r-- | src/game/Unit.cpp | 4 | ||||
-rw-r--r-- | src/game/Unit.h | 2 |
7 files changed, 86 insertions, 14 deletions
diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 68b8ab1feae..33d1fd2ea02 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1822,6 +1822,29 @@ void Creature::DoFleeToGetAssistance(float radius) // Optional parameter } } +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() { if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed()) diff --git a/src/game/Creature.h b/src/game/Creature.h index 3713465fa79..eb5b2d711f0 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -559,6 +559,7 @@ class TRINITY_DLL_SPEC Creature : public Unit bool IsWithinSightDist(Unit const* u) const; float GetAttackDistance(Unit const* pl) const; + Unit* SelectNearestTarget(float dist = 0) const; void CallAssistence(); void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } void DoFleeToGetAssistance(float radius = 50); diff --git a/src/game/GridNotifiers.h b/src/game/GridNotifiers.h index 972c209964c..57abea4d5a2 100644 --- a/src/game/GridNotifiers.h +++ b/src/game/GridNotifiers.h @@ -698,19 +698,41 @@ namespace Trinity // Creature checks - class InAttackDistanceFromAnyHostileCreatureCheck + class NearestHostileUnitInAttackDistanceCheck { public: - explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} - bool operator()(Creature* u) + explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature) { - if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) - return true; + 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; - 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: - Unit* const i_funit; + Creature* const m_creature; + float m_range; + bool m_force; + NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&); }; class NearestAssistCreatureInCreatureRangeCheck diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 3804560b662..39006c932c6 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -596,7 +596,9 @@ bool Map::loaded(const GridPair &p) const void Map::Update(const uint32 &t_diff) { - resetMarkedCells(); + // TODO: need have an active object list for every map + + /*resetMarkedCells(); Trinity::ObjectUpdater updater(t_diff); // for creature @@ -642,8 +644,7 @@ void Map::Update(const uint32 &t_diff) } } } - } - + }*/ // 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 ! // This isn't really bother us, since as soon as we have instanced BG-s, the whole map unloads as the BG gets ended diff --git a/src/game/ObjectAccessor.cpp b/src/game/ObjectAccessor.cpp index 8a7e8fbfa2c..8d9f3f63fc2 100644 --- a/src/game/ObjectAccessor.cpp +++ b/src/game/ObjectAccessor.cpp @@ -503,6 +503,8 @@ ObjectAccessor::Update(uint32 diff) { { + //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(); for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) @@ -511,8 +513,9 @@ ObjectAccessor::Update(uint32 diff) { 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); @@ -572,6 +575,28 @@ ObjectAccessor::Update(uint32 diff) } } } + + 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 + } } void diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index c0868ce24f1..9a78c50857f 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -10424,7 +10424,7 @@ void Unit::UpdateReactives( uint32 p_time ) } } -Unit* Unit::SelectNearbyTarget() const +Unit* Unit::SelectNearbyTarget(float dist) const { CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); Cell cell(p); @@ -10434,7 +10434,7 @@ Unit* Unit::SelectNearbyTarget() const std::list<Unit *> targets; { - Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); + Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, dist); Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(targets, u_check); TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); diff --git a/src/game/Unit.h b/src/game/Unit.h index 4a5dc7e4bb9..cd5770cccd6 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -762,7 +762,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject Unit* getVictim() const { return m_attacking; } 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; } bool hasUnitState(const uint32 f) const { return (m_state & f); } |