*Fix the bug that updatepacket is not sent to players.

*TODO: move creature::update to map::update. This requires that move activeobjectlist to map.

--HG--
branch : trunk
This commit is contained in:
megamage
2008-11-20 20:28:17 -06:00
parent 2c95ee4b31
commit 5528b7c512
7 changed files with 87 additions and 15 deletions
+23
View File
@@ -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() void Creature::CallAssistence()
{ {
if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed()) if( !m_AlreadyCallAssistence && getVictim() && !isPet() && !isCharmed())
+1
View File
@@ -559,6 +559,7 @@ class TRINITY_DLL_SPEC Creature : public Unit
bool IsWithinSightDist(Unit const* u) const; bool IsWithinSightDist(Unit const* u) const;
float GetAttackDistance(Unit const* pl) const; float GetAttackDistance(Unit const* pl) const;
Unit* SelectNearestTarget(float dist = 0) const;
void CallAssistence(); void CallAssistence();
void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; }
void DoFleeToGetAssistance(float radius = 50); void DoFleeToGetAssistance(float radius = 50);
+30 -8
View File
@@ -698,19 +698,41 @@ namespace Trinity
// Creature checks // Creature checks
class InAttackDistanceFromAnyHostileCreatureCheck class NearestHostileUnitInAttackDistanceCheck
{ {
public: public:
explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature)
bool operator()(Creature* u)
{ {
if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) m_range = (dist == 0 ? 9999 : dist);
return true; m_force = (dist == 0 ? false : true);
return false;
} }
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: private:
Unit* const i_funit; Creature* const m_creature;
float m_range;
bool m_force;
NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&);
}; };
class NearestAssistCreatureInCreatureRangeCheck class NearestAssistCreatureInCreatureRangeCheck
+4 -3
View File
@@ -596,7 +596,9 @@ bool Map::loaded(const GridPair &p) const
void Map::Update(const uint32 &t_diff) void Map::Update(const uint32 &t_diff)
{ {
resetMarkedCells(); // TODO: need have an active object list for every map
/*resetMarkedCells();
Trinity::ObjectUpdater updater(t_diff); Trinity::ObjectUpdater updater(t_diff);
// for creature // 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 ! // 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 // This isn't really bother us, since as soon as we have instanced BG-s, the whole map unloads as the BG gets ended
+26 -1
View File
@@ -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. // 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(); HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter)
@@ -511,8 +513,9 @@ ObjectAccessor::Update(uint32 diff)
{ {
iter->second->Update(diff); iter->second->Update(diff);
} }
} }*/
// TODO: move this to Map::Update
// clone the active object list, because update might remove from it // clone the active object list, because update might remove from it
std::set<WorldObject *> activeobjects(i_activeobjects); 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 void
+2 -2
View File
@@ -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())); CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY()));
Cell cell(p); Cell cell(p);
@@ -10434,7 +10434,7 @@ Unit* Unit::SelectNearbyTarget() const
std::list<Unit *> targets; 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); Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(targets, u_check);
TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); TypeContainerVisitor<Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck>, WorldTypeMapContainer > world_unit_searcher(searcher);
+1 -1
View File
@@ -762,7 +762,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
Unit* getVictim() const { return m_attacking; } Unit* getVictim() const { return m_attacking; }
void CombatStop(bool cast = false); void CombatStop(bool cast = false);
void CombatStopWithPets(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; } void addUnitState(uint32 f) { m_state |= f; }
bool hasUnitState(const uint32 f) const { return (m_state & f); } bool hasUnitState(const uint32 f) const { return (m_state & f); }