Changeset 266 for trunk

Show
Ignore:
Timestamp:
11/21/08 08:48:50 (17 years ago)
Author:
yumileroy
Message:

*Fix the bug that updatepacket is not sent to players.
*TODO: move creature::update to map::update. This requires that move activeobjectlist to map.

Original author: megamage
Date: 2008-11-20 20:28:17-06:00

Location:
trunk/src/game
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Creature.cpp

    r265 r266  
    18231823} 
    18241824 
     1825Unit* Creature::SelectNearestTarget(float dist) const 
     1826{ 
     1827    /*CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
     1828    Cell cell(p); 
     1829    cell.data.Part.reserved = ALL_DISTRICT; 
     1830    cell.SetNoCreate(); 
     1831 
     1832    Unit *target; 
     1833 
     1834    { 
     1835        Trinity::NearestHostileUnitInAttackDistanceCheck u_check(this, dist); 
     1836        Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck> searcher(target, u_check); 
     1837 
     1838        TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, WorldTypeMapContainer > world_unit_searcher(searcher); 
     1839        TypeContainerVisitor<Trinity::UnitLastSearcher<Trinity::NearestHostileUnitInAttackDistanceCheck>, GridTypeMapContainer >  grid_unit_searcher(searcher); 
     1840 
     1841        CellLock<GridReadGuard> cell_lock(cell, p); 
     1842        cell_lock->Visit(cell_lock, world_unit_searcher, GetMap()); 
     1843        cell_lock->Visit(cell_lock, grid_unit_searcher, GetMap()); 
     1844    }*/ 
     1845    return NULL; 
     1846} 
     1847 
    18251848void Creature::CallAssistence() 
    18261849{ 
  • trunk/src/game/Creature.h

    r265 r266  
    560560        float GetAttackDistance(Unit const* pl) const; 
    561561 
     562        Unit* SelectNearestTarget(float dist = 0) const; 
    562563        void CallAssistence(); 
    563564        void SetNoCallAssistence(bool val) { m_AlreadyCallAssistence = val; } 
  • trunk/src/game/GridNotifiers.h

    r233 r266  
    699699    // Creature checks 
    700700 
    701     class InAttackDistanceFromAnyHostileCreatureCheck 
    702     { 
    703         public: 
    704             explicit InAttackDistanceFromAnyHostileCreatureCheck(Unit* funit) : i_funit(funit) {} 
    705             bool operator()(Creature* u) 
    706             { 
    707                 if(u->isAlive() && u->IsHostileTo(i_funit) && i_funit->IsWithinDistInMap(u, u->GetAttackDistance(i_funit))) 
    708                     return true; 
    709  
    710                 return false; 
    711             } 
    712         private: 
    713             Unit* const i_funit; 
     701    class NearestHostileUnitInAttackDistanceCheck 
     702    { 
     703        public: 
     704            explicit NearestHostileUnitInAttackDistanceCheck(Creature* creature, float dist = 0) : m_creature(creature)  
     705            { 
     706                m_range = (dist == 0 ? 9999 : dist); 
     707                m_force = (dist == 0 ? false : true); 
     708            } 
     709            bool operator()(Unit* u) 
     710            { 
     711                if(!u->isAlive() || !m_creature->IsHostileTo(u)) 
     712                    return false; 
     713 
     714                float dist; 
     715                if(m_force) dist = m_range; 
     716                else 
     717                { 
     718                    dist = m_creature->GetAttackDistance(u); 
     719                    if(dist > m_range) dist = m_range; 
     720                } 
     721                if(!m_creature->IsWithinDistInMap(u, dist)) 
     722                    return false; 
     723 
     724                if(!m_creature->canSeeOrDetect(u, true, false)) 
     725                    return false; 
     726 
     727                m_range = m_creature->GetDistance(u); 
     728                return true; 
     729            } 
     730            float GetLastRange() const { return m_range; } 
     731        private: 
     732            Creature* const m_creature; 
     733            float m_range; 
     734            bool m_force; 
     735            NearestHostileUnitInAttackDistanceCheck(NearestHostileUnitInAttackDistanceCheck const&); 
    714736    }; 
    715737 
  • trunk/src/game/Map.cpp

    r260 r266  
    597597void Map::Update(const uint32 &t_diff) 
    598598{ 
    599     resetMarkedCells(); 
     599    // TODO: need have an active object list for every map 
     600 
     601    /*resetMarkedCells(); 
    600602 
    601603    Trinity::ObjectUpdater updater(t_diff); 
     
    643645            } 
    644646        } 
    645     } 
    646  
     647    }*/ 
    647648 
    648649    // 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 ! 
  • trunk/src/game/ObjectAccessor.cpp

    r257 r266  
    504504 
    505505    { 
     506        //Player update now in MapManager -> UpdatePlayers 
     507        /* 
    506508        // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. 
    507509        HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 
     
    512514                iter->second->Update(diff); 
    513515            } 
    514         } 
    515  
     516        }*/ 
     517 
     518        // TODO: move this to Map::Update 
    516519        // clone the active object list, because update might remove from it 
    517520        std::set<WorldObject *> activeobjects(i_activeobjects); 
     
    573576        } 
    574577    } 
     578 
     579    UpdateDataMapType update_players; 
     580    { 
     581        Guard guard(i_updateGuard); 
     582        while(!i_objects.empty()) 
     583        { 
     584            Object* obj = *i_objects.begin(); 
     585            i_objects.erase(i_objects.begin()); 
     586            if (!obj) 
     587                continue; 
     588            _buildUpdateObject(obj, update_players); 
     589            obj->ClearUpdateMask(false); 
     590        } 
     591    } 
     592 
     593    WorldPacket packet;                                     // here we allocate a std::vector with a size of 0x10000 
     594    for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter) 
     595    { 
     596        iter->second.BuildPacket(&packet); 
     597        iter->first->GetSession()->SendPacket(&packet); 
     598        packet.clear();                                     // clean the string 
     599    } 
    575600} 
    576601 
  • trunk/src/game/Unit.cpp

    r265 r266  
    1042510425} 
    1042610426 
    10427 Unit* Unit::SelectNearbyTarget() const 
     10427Unit* Unit::SelectNearbyTarget(float dist) const 
    1042810428{ 
    1042910429    CellPair p(Trinity::ComputeCellPair(GetPositionX(), GetPositionY())); 
     
    1043510435 
    1043610436    { 
    10437         Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, ATTACK_DISTANCE); 
     10437        Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(this, this, dist); 
    1043810438        Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(targets, u_check); 
    1043910439 
  • trunk/src/game/Unit.h

    r257 r266  
    763763        void CombatStop(bool cast = false); 
    764764        void CombatStopWithPets(bool cast = false); 
    765         Unit* SelectNearbyTarget() const; 
     765        Unit* SelectNearbyTarget(float dist = ATTACK_DISTANCE) const; 
    766766 
    767767        void addUnitState(uint32 f) { m_state |= f; }