Show
Ignore:
Timestamp:
11/22/08 00:35:41 (17 years ago)
Author:
yumileroy
Message:

Delete possessed AI only on creature delete.

Original author: gvcoman
Date: 2008-11-16 14:38:02-05:00

Files:
1 modified

Legend:

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

    r268 r272  
    143143{ 
    144144    Creature * ret = GetObjectInWorld(guid, (Creature*)NULL); 
    145     if(!ret) 
    146         return NULL; 
    147  
    148     if(ret->GetMapId() != u.GetMapId()) 
    149         return NULL; 
    150  
    151     if(ret->GetInstanceId() != u.GetInstanceId()) 
    152         return NULL; 
    153  
     145    if(ret && ret->GetMapId() != u.GetMapId()) ret = NULL; 
    154146    return ret; 
    155147} 
     
    257249 
    258250void 
     251ObjectAccessor::_update() 
     252{ 
     253    UpdateDataMapType update_players; 
     254    { 
     255        Guard guard(i_updateGuard); 
     256        while(!i_objects.empty()) 
     257        { 
     258            Object* obj = *i_objects.begin(); 
     259            i_objects.erase(i_objects.begin()); 
     260            if (!obj) 
     261                continue; 
     262            _buildUpdateObject(obj, update_players); 
     263            obj->ClearUpdateMask(false); 
     264        } 
     265    } 
     266 
     267    WorldPacket packet;                                     // here we allocate a std::vector with a size of 0x10000 
     268    for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter) 
     269    { 
     270        iter->second.BuildPacket(&packet); 
     271        iter->first->GetSession()->SendPacket(&packet); 
     272        packet.clear();                                     // clean the string 
     273    } 
     274} 
     275 
     276void 
    259277ObjectAccessor::UpdateObject(Object* obj, Player* exceptPlayer) 
    260278{ 
     
    344362    TypeContainerVisitor<WorldObjectChangeAccumulator, WorldTypeMapContainer > player_notifier(notifier); 
    345363    CellLock<GridReadGuard> cell_lock(cell, p); 
    346     cell_lock->Visit(cell_lock, player_notifier, *obj->GetMap()); 
     364    cell_lock->Visit(cell_lock, player_notifier, *MapManager::Instance().GetMap(obj->GetMapId(), obj)); 
    347365} 
    348366 
     
    488506 
    489507void 
     508ObjectAccessor::AddActiveObject( WorldObject * obj ) 
     509{ 
     510    i_activeobjects.insert(obj); 
     511} 
     512 
     513void 
     514ObjectAccessor::RemoveActiveObject( WorldObject * obj ) 
     515{ 
     516    i_activeobjects.erase(obj); 
     517} 
     518 
     519void 
    490520ObjectAccessor::Update(uint32 diff) 
    491521{ 
    492 /*    { 
    493         //Player update now in MapManager -> UpdatePlayers 
     522    { 
    494523        // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects. 
    495524        HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 
     
    502531        } 
    503532 
    504         // TODO: move this to Map::Update 
    505533        // clone the active object list, because update might remove from it 
    506534        std::set<WorldObject *> activeobjects(i_activeobjects); 
     
    561589            } 
    562590        } 
    563     }*/ 
    564  
    565     UpdateDataMapType update_players; 
    566     { 
    567         Guard guard(i_updateGuard); 
    568         while(!i_objects.empty()) 
    569         { 
    570             Object* obj = *i_objects.begin(); 
    571             i_objects.erase(i_objects.begin()); 
    572             if (!obj) 
    573                 continue; 
    574             _buildUpdateObject(obj, update_players); 
    575             obj->ClearUpdateMask(false); 
    576         } 
    577     } 
    578  
    579     WorldPacket packet;                                     // here we allocate a std::vector with a size of 0x10000 
    580     for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter) 
    581     { 
    582         iter->second.BuildPacket(&packet); 
    583         iter->first->GetSession()->SendPacket(&packet); 
    584         packet.clear();                                     // clean the string 
    585     } 
    586 } 
    587  
    588 void 
    589 ObjectAccessor::UpdatePlayers(uint32 diff) 
    590 { 
    591     HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer(); 
    592     for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter) 
    593         if(iter->second->IsInWorld()) 
    594             iter->second->Update(diff); 
     591    } 
     592 
     593    _update(); 
     594} 
     595 
     596bool 
     597ObjectAccessor::ActiveObjectsNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const 
     598{ 
     599    CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); 
     600    CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); 
     601    cell_min << 2; 
     602    cell_min -= 2; 
     603    cell_max >> 2; 
     604    cell_max += 2; 
     605 
     606    for(std::set<WorldObject*>::const_iterator itr = i_activeobjects.begin(); itr != i_activeobjects.end(); ++itr) 
     607    { 
     608        if( m_id != (*itr)->GetMapId() || i_id != (*itr)->GetInstanceId() ) 
     609            continue; 
     610 
     611        CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY()); 
     612        if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && 
     613            (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) 
     614            return true; 
     615    } 
     616 
     617    return false; 
    595618} 
    596619 
     
    655678    Cell cell(p); 
    656679 
    657     obj->GetMap()->UpdateObjectVisibility(obj,cell,p); 
     680    MapManager::Instance().GetMap(obj->GetMapId(), obj)->UpdateObjectVisibility(obj,cell,p); 
    658681} 
    659682 
     
    662685    CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); 
    663686    Cell cell(p); 
    664     Map* m = player->GetMap(); 
     687    Map* m = MapManager::Instance().GetMap(player->GetMapId(),player); 
    665688 
    666689    m->UpdatePlayerVisibility(player,cell,p);