root/trunk/src/game/ObjectAccessor.cpp @ 257

Revision 257, 21.9 kB (checked in by yumileroy, 17 years ago)

*Merge from Mangos. Add MapReference?. Author: hunuza.
*Also re-commit the patches reverted in 255.

Original author: megamage
Date: 2008-11-18 19:40:06-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21#include "ObjectAccessor.h"
22#include "ObjectMgr.h"
23#include "Policies/SingletonImp.h"
24#include "Player.h"
25#include "Creature.h"
26#include "GameObject.h"
27#include "DynamicObject.h"
28#include "Corpse.h"
29#include "WorldSession.h"
30#include "WorldPacket.h"
31#include "Item.h"
32#include "Corpse.h"
33#include "GridNotifiers.h"
34#include "MapManager.h"
35#include "Map.h"
36#include "CellImpl.h"
37#include "GridNotifiersImpl.h"
38#include "Opcodes.h"
39#include "ObjectDefines.h"
40#include "MapInstanced.h"
41
42#include <cmath>
43
44#define CLASS_LOCK Trinity::ClassLevelLockable<ObjectAccessor, ZThread::FastMutex>
45INSTANTIATE_SINGLETON_2(ObjectAccessor, CLASS_LOCK);
46INSTANTIATE_CLASS_MUTEX(ObjectAccessor, ZThread::FastMutex);
47
48namespace Trinity
49{
50
51    struct TRINITY_DLL_DECL BuildUpdateForPlayer
52    {
53        Player &i_player;
54        UpdateDataMapType &i_updatePlayers;
55
56        BuildUpdateForPlayer(Player &player, UpdateDataMapType &data_map) : i_player(player), i_updatePlayers(data_map) {}
57
58        void Visit(PlayerMapType &m)
59        {
60            for(PlayerMapType::iterator iter=m.begin(); iter != m.end(); ++iter)
61            {
62                if( iter->getSource() == &i_player )
63                    continue;
64
65                UpdateDataMapType::iterator iter2 = i_updatePlayers.find(iter->getSource());
66                if( iter2 == i_updatePlayers.end() )
67                {
68                    std::pair<UpdateDataMapType::iterator, bool> p = i_updatePlayers.insert( ObjectAccessor::UpdateDataValueType(iter->getSource(), UpdateData()) );
69                    assert(p.second);
70                    iter2 = p.first;
71                }
72
73                i_player.BuildValuesUpdateBlockForPlayer(&iter2->second, iter2->first);
74            }
75        }
76
77        template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
78    };
79}
80
81ObjectAccessor::ObjectAccessor() {}
82ObjectAccessor::~ObjectAccessor() {}
83
84Creature*
85ObjectAccessor::GetNPCIfCanInteractWith(Player const &player, uint64 guid, uint32 npcflagmask)
86{
87    // unit checks
88    if (!guid)
89        return NULL;
90
91    // exist
92    Creature *unit = GetCreature(player, guid);
93    if (!unit)
94        return NULL;
95
96    // player check
97    if(!player.CanInteractWithNPCs(!unit->isSpiritService()))
98        return NULL;
99
100    // appropriate npc type
101    if(npcflagmask && !unit->HasFlag( UNIT_NPC_FLAGS, npcflagmask ))
102        return NULL;
103
104    // alive or spirit healer
105    if(!unit->isAlive() && (!unit->isSpiritService() || player.isAlive() ))
106        return NULL;
107
108    // not allow interaction under control
109    if(unit->GetCharmerOrOwnerGUID())
110        return NULL;
111
112    // not enemy
113    if( unit->IsHostileTo(&player))
114        return NULL;
115
116    // not unfriendly
117    FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction());
118    if(factionTemplate)
119    {
120        FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction);
121        if( faction->reputationListID >= 0 && player.GetReputationRank(faction) <= REP_UNFRIENDLY)
122            return NULL;
123    }
124
125    // not too far
126    if(!unit->IsWithinDistInMap(&player,INTERACTION_DISTANCE))
127        return NULL;
128
129    return unit;
130}
131
132Creature*
133ObjectAccessor::GetCreatureOrPet(WorldObject const &u, uint64 guid)
134{
135    if(Creature *unit = GetPet(guid))
136        return unit;
137
138    return GetCreature(u, guid);
139}
140
141Creature*
142ObjectAccessor::GetCreature(WorldObject const &u, uint64 guid)
143{
144    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
154    return ret;
155}
156
157Unit*
158ObjectAccessor::GetUnit(WorldObject const &u, uint64 guid)
159{
160    if(!guid)
161        return NULL;
162
163    if(IS_PLAYER_GUID(guid))
164        return FindPlayer(guid);
165
166    return GetCreatureOrPet(u, guid);
167}
168
169Corpse*
170ObjectAccessor::GetCorpse(WorldObject const &u, uint64 guid)
171{
172    Corpse * ret = GetObjectInWorld(guid, (Corpse*)NULL);
173    if(ret && ret->GetMapId() != u.GetMapId()) ret = NULL;
174    return ret;
175}
176
177Object* ObjectAccessor::GetObjectByTypeMask(Player const &p, uint64 guid, uint32 typemask)
178{
179    Object *obj = NULL;
180
181    if(typemask & TYPEMASK_PLAYER)
182    {
183        obj = FindPlayer(guid);
184        if(obj) return obj;
185    }
186
187    if(typemask & TYPEMASK_UNIT)
188    {
189        obj = GetCreatureOrPet(p,guid);
190        if(obj) return obj;
191    }
192
193    if(typemask & TYPEMASK_GAMEOBJECT)
194    {
195        obj = GetGameObject(p,guid);
196        if(obj) return obj;
197    }
198
199    if(typemask & TYPEMASK_DYNAMICOBJECT)
200    {
201        obj = GetDynamicObject(p,guid);
202        if(obj) return obj;
203    }
204
205    if(typemask & TYPEMASK_ITEM)
206    {
207        obj = p.GetItemByGuid( guid );
208        if(obj) return obj;
209    }
210
211    return NULL;
212}
213
214GameObject*
215ObjectAccessor::GetGameObject(WorldObject const &u, uint64 guid)
216{
217    GameObject * ret = GetObjectInWorld(guid, (GameObject*)NULL);
218    if(ret && ret->GetMapId() != u.GetMapId()) ret = NULL;
219    return ret;
220}
221
222DynamicObject*
223ObjectAccessor::GetDynamicObject(Unit const &u, uint64 guid)
224{
225    DynamicObject * ret = GetObjectInWorld(guid, (DynamicObject*)NULL);
226    if(ret && ret->GetMapId() != u.GetMapId()) ret = NULL;
227    return ret;
228}
229
230Player*
231ObjectAccessor::FindPlayer(uint64 guid)
232{
233    return GetObjectInWorld(guid, (Player*)NULL);
234}
235
236Player*
237ObjectAccessor::FindPlayerByName(const char *name)
238{
239    //TODO: Player Guard
240    HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
241    HashMapHolder<Player>::MapType::iterator iter = m.begin();
242    for(; iter != m.end(); ++iter)
243        if( ::strcmp(name, iter->second->GetName()) == 0 )
244            return iter->second;
245    return NULL;
246}
247
248void
249ObjectAccessor::SaveAllPlayers()
250{
251    Guard guard(*HashMapHolder<Player*>::GetLock());
252    HashMapHolder<Player>::MapType& m = HashMapHolder<Player>::GetContainer();
253    HashMapHolder<Player>::MapType::iterator itr = m.begin();
254    for(; itr != m.end(); ++itr)
255        itr->second->SaveToDB();
256}
257
258void
259ObjectAccessor::UpdateObject(Object* obj, Player* exceptPlayer)
260{
261    UpdateDataMapType update_players;
262    obj->BuildUpdate(update_players);
263
264    WorldPacket packet;
265    for(UpdateDataMapType::iterator iter = update_players.begin(); iter != update_players.end(); ++iter)
266    {
267        if(iter->first == exceptPlayer)
268            continue;
269
270        iter->second.BuildPacket(&packet);
271        iter->first->GetSession()->SendPacket(&packet);
272        packet.clear();
273    }
274}
275
276void
277ObjectAccessor::AddUpdateObject(Object *obj)
278{
279    Guard guard(i_updateGuard);
280    i_objects.insert(obj);
281}
282
283void
284ObjectAccessor::RemoveUpdateObject(Object *obj)
285{
286    Guard guard(i_updateGuard);
287    std::set<Object *>::iterator iter = i_objects.find(obj);
288    if( iter != i_objects.end() )
289        i_objects.erase( iter );
290}
291
292void
293ObjectAccessor::_buildUpdateObject(Object *obj, UpdateDataMapType &update_players)
294{
295    bool build_for_all = true;
296    Player *pl = NULL;
297    if( obj->isType(TYPEMASK_ITEM) )
298    {
299        Item *item = static_cast<Item *>(obj);
300        pl = item->GetOwner();
301        build_for_all = false;
302    }
303
304    if( pl != NULL )
305        _buildPacket(pl, obj, update_players);
306
307    // Capt: okey for all those fools who think its a real fix
308    //       THIS IS A TEMP FIX
309    if( build_for_all )
310    {
311        WorldObject * temp = dynamic_cast<WorldObject*>(obj);
312
313        //assert(dynamic_cast<WorldObject*>(obj)!=NULL);
314        if (temp)
315            _buildChangeObjectForPlayer(temp, update_players);
316        else
317            sLog.outDebug("ObjectAccessor: Ln 405 Temp bug fix");
318    }
319}
320
321void
322ObjectAccessor::_buildPacket(Player *pl, Object *obj, UpdateDataMapType &update_players)
323{
324    UpdateDataMapType::iterator iter = update_players.find(pl);
325
326    if( iter == update_players.end() )
327    {
328        std::pair<UpdateDataMapType::iterator, bool> p = update_players.insert( UpdateDataValueType(pl, UpdateData()) );
329        assert(p.second);
330        iter = p.first;
331    }
332
333    obj->BuildValuesUpdateBlockForPlayer(&iter->second, iter->first);
334}
335
336void
337ObjectAccessor::_buildChangeObjectForPlayer(WorldObject *obj, UpdateDataMapType &update_players)
338{
339    CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
340    Cell cell(p);
341    cell.data.Part.reserved = ALL_DISTRICT;
342    cell.SetNoCreate();
343    WorldObjectChangeAccumulator notifier(*obj, update_players);
344    TypeContainerVisitor<WorldObjectChangeAccumulator, WorldTypeMapContainer > player_notifier(notifier);
345    CellLock<GridReadGuard> cell_lock(cell, p);
346    cell_lock->Visit(cell_lock, player_notifier, *obj->GetMap());
347}
348
349Pet*
350ObjectAccessor::GetPet(uint64 guid)
351{
352    return GetObjectInWorld(guid, (Pet*)NULL);
353}
354
355Corpse*
356ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
357{
358    Guard guard(i_corpseGuard);
359
360    Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
361    if( iter == i_player2corpse.end() ) return NULL;
362
363    assert(iter->second->GetType() != CORPSE_BONES);
364
365    return iter->second;
366}
367
368void
369ObjectAccessor::RemoveCorpse(Corpse *corpse)
370{
371    assert(corpse && corpse->GetType() != CORPSE_BONES);
372
373    Guard guard(i_corpseGuard);
374    Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
375    if( iter == i_player2corpse.end() )
376        return;
377
378    // build mapid*cellid -> guid_set map
379    CellPair cell_pair = Trinity::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
380    uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
381
382    objmgr.DeleteCorpseCellData(corpse->GetMapId(),cell_id,corpse->GetOwnerGUID());
383    corpse->RemoveFromWorld();
384
385    i_player2corpse.erase(iter);
386}
387
388void
389ObjectAccessor::AddCorpse(Corpse *corpse)
390{
391    assert(corpse && corpse->GetType() != CORPSE_BONES);
392
393    Guard guard(i_corpseGuard);
394    assert(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
395    i_player2corpse[corpse->GetOwnerGUID()] = corpse;
396
397    // build mapid*cellid -> guid_set map
398    CellPair cell_pair = Trinity::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY());
399    uint32 cell_id = (cell_pair.y_coord*TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord;
400
401    objmgr.AddCorpseCellData(corpse->GetMapId(),cell_id,corpse->GetOwnerGUID(),corpse->GetInstanceId());
402}
403
404void
405ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair,GridType& grid,Map* map)
406{
407    Guard guard(i_corpseGuard);
408    for(Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
409        if(iter->second->GetGrid()==gridpair)
410    {
411        // verify, if the corpse in our instance (add only corpses which are)
412        if (map->Instanceable())
413        {
414            if (iter->second->GetInstanceId() == map->GetInstanceId())
415            {
416                grid.AddWorldObject(iter->second,iter->second->GetGUID());
417            }
418        }
419        else
420        {
421            grid.AddWorldObject(iter->second,iter->second->GetGUID());
422        }
423    }
424}
425
426Corpse*
427ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid)
428{
429    Corpse *corpse = GetCorpseForPlayerGUID(player_guid);
430    if(!corpse)
431    {
432        //in fact this function is called from several places
433        //even when player doesn't have a corpse, not an error
434        //sLog.outError("ERROR: Try remove corpse that not in map for GUID %ul", player_guid);
435        return NULL;
436    }
437
438    DEBUG_LOG("Deleting Corpse and spawning bones.\n");
439
440    // remove corpse from player_guid -> corpse map
441    RemoveCorpse(corpse);
442
443    // remove resurrectble corpse from grid object registry (loaded state checked into call)
444    // do not load the map if it's not loaded
445    Map *map = MapManager::Instance().FindMap(corpse->GetMapId(), corpse->GetInstanceId());
446    if(map) map->Remove(corpse,false);
447
448    // remove corpse from DB
449    corpse->DeleteFromDB();
450
451    Corpse *bones = NULL;
452    // create the bones only if the map and the grid is loaded at the corpse's location
453    if(map && !map->IsRemovalGrid(corpse->GetPositionX(), corpse->GetPositionY()))
454    {
455        // Create bones, don't change Corpse
456        bones = new Corpse;
457        bones->Create(corpse->GetGUIDLow());
458
459        for (int i = 3; i < CORPSE_END; i++)                    // don't overwrite guid and object type
460            bones->SetUInt32Value(i, corpse->GetUInt32Value(i));
461
462        bones->SetGrid(corpse->GetGrid());
463        // bones->m_time = m_time;                              // don't overwrite time
464        // bones->m_inWorld = m_inWorld;                        // don't overwrite world state
465        // bones->m_type = m_type;                              // don't overwrite type
466        bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation());
467        bones->SetMapId(corpse->GetMapId());
468        bones->SetInstanceId(corpse->GetInstanceId());
469
470        bones->SetUInt32Value(CORPSE_FIELD_FLAGS, CORPSE_FLAG_UNK2 | CORPSE_FLAG_BONES);
471        bones->SetUInt64Value(CORPSE_FIELD_OWNER, 0);
472
473        for (int i = 0; i < EQUIPMENT_SLOT_END; i++)
474        {
475            if(corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i))
476                bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0);
477        }
478
479        // add bones in grid store if grid loaded where corpse placed
480        map->Add(bones);
481    }
482
483    // all references to the corpse should be removed at this point
484    delete corpse;
485
486    return bones;
487}
488
489void
490ObjectAccessor::AddActiveObject( WorldObject * obj )
491{
492    i_activeobjects.insert(obj);
493}
494
495void
496ObjectAccessor::RemoveActiveObject( WorldObject * obj )
497{
498    i_activeobjects.erase(obj);
499}
500
501void
502ObjectAccessor::Update(uint32 diff)
503{
504
505    {
506        // player update might remove the player from grid, and that causes crashes. We HAVE to update players first, and then the active objects.
507        HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
508        for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter)
509        {
510            if(iter->second->IsInWorld())
511            {
512                iter->second->Update(diff);
513            }
514        }
515
516        // clone the active object list, because update might remove from it
517        std::set<WorldObject *> activeobjects(i_activeobjects);
518
519        std::set<WorldObject *>::iterator itr, next;
520        for(itr = activeobjects.begin(); itr != activeobjects.end(); itr = next)
521        {
522            next = itr;
523            ++next;
524            if((*itr)->IsInWorld())
525                (*itr)->GetMap()->resetMarkedCells();
526            else
527                activeobjects.erase(itr);
528        }
529
530        Map *map;
531
532        Trinity::ObjectUpdater updater(diff);
533        // for creature
534        TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer  > grid_object_update(updater);
535        // for pets
536        TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater);
537
538        for(itr = activeobjects.begin(); itr != activeobjects.end(); ++itr)
539        {
540            WorldObject *obj = (*itr);
541            map = obj->GetMap();
542
543            CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()));
544
545            // Check for correctness of standing_cell, it also avoids problems with update_cell
546            if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP)
547                continue;
548
549            // the overloaded operators handle range checking
550            // so ther's no need for range checking inside the loop
551            CellPair begin_cell(standing_cell), end_cell(standing_cell);
552            begin_cell << 1; begin_cell -= 1;               // upper left
553            end_cell >> 1; end_cell += 1;                   // lower right
554
555            for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; x++)
556            {
557                for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; y++)
558                {
559                    uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x;
560                    if( !map->isCellMarked(cell_id) )
561                    {
562                        CellPair cell_pair(x,y);
563                        map->markCell(cell_id);
564                        Cell cell(cell_pair);
565                        cell.data.Part.reserved = CENTER_DISTRICT;
566                        cell.SetNoCreate();
567                        CellLock<NullGuard> cell_lock(cell, cell_pair);
568                        cell_lock->Visit(cell_lock, grid_object_update,  *map);
569                        cell_lock->Visit(cell_lock, world_object_update, *map);
570                    }
571                }
572            }
573        }
574    }
575}
576
577void
578ObjectAccessor::UpdatePlayers(uint32 diff)
579{
580    HashMapHolder<Player>::MapType& playerMap = HashMapHolder<Player>::GetContainer();
581    for(HashMapHolder<Player>::MapType::iterator iter = playerMap.begin(); iter != playerMap.end(); ++iter)
582        if(iter->second->IsInWorld())
583            iter->second->Update(diff);
584}
585
586bool
587ObjectAccessor::ActiveObjectsNearGrid(uint32 x, uint32 y, uint32 m_id, uint32 i_id) const
588{
589    CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS);
590    CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS);
591    cell_min << 2;
592    cell_min -= 2;
593    cell_max >> 2;
594    cell_max += 2;
595
596    for(std::set<WorldObject*>::const_iterator itr = i_activeobjects.begin(); itr != i_activeobjects.end(); ++itr)
597    {
598        if( m_id != (*itr)->GetMapId() || i_id != (*itr)->GetInstanceId() )
599            continue;
600
601        CellPair p = Trinity::ComputeCellPair((*itr)->GetPositionX(), (*itr)->GetPositionY());
602        if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) &&
603            (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) )
604            return true;
605    }
606
607    return false;
608}
609
610void
611ObjectAccessor::WorldObjectChangeAccumulator::Visit(PlayerMapType &m)
612{
613    for(PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
614    {
615        BuildPacket(iter->getSource());
616        if (!iter->getSource()->GetSharedVisionList().empty())
617        {
618            SharedVisionList::const_iterator it = iter->getSource()->GetSharedVisionList().begin();
619            for ( ; it != iter->getSource()->GetSharedVisionList().end(); ++it)
620                BuildPacket(*it);
621        }
622    }
623}
624
625void
626ObjectAccessor::WorldObjectChangeAccumulator::Visit(CreatureMapType &m)
627{
628    for(CreatureMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
629    {
630        if (!iter->getSource()->GetSharedVisionList().empty())
631        {
632            SharedVisionList::const_iterator it = iter->getSource()->GetSharedVisionList().begin();
633            for ( ; it != iter->getSource()->GetSharedVisionList().end(); ++it)
634                BuildPacket(*it);
635        }
636    }
637}
638
639void
640ObjectAccessor::WorldObjectChangeAccumulator::Visit(DynamicObjectMapType &m)
641{
642    for(DynamicObjectMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
643    {
644        if (IS_PLAYER_GUID(iter->getSource()->GetCasterGUID()))
645        {
646            Player* caster = (Player*)iter->getSource()->GetCaster();
647            if (caster->GetUInt64Value(PLAYER_FARSIGHT) == iter->getSource()->GetGUID())
648                BuildPacket(caster);
649        }
650    }
651}
652
653void
654ObjectAccessor::WorldObjectChangeAccumulator::BuildPacket(Player* plr)
655{
656    // Only send update once to a player
657    if (plr_list.find(plr->GetGUID()) == plr_list.end() && plr->HaveAtClient(&i_object))
658    {
659        ObjectAccessor::_buildPacket(plr, &i_object, i_updateDatas);
660        plr_list.insert(plr->GetGUID());
661    }
662}
663
664void
665ObjectAccessor::UpdateObjectVisibility(WorldObject *obj)
666{
667    CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
668    Cell cell(p);
669
670    obj->GetMap()->UpdateObjectVisibility(obj,cell,p);
671}
672
673void ObjectAccessor::UpdateVisibilityForPlayer( Player* player )
674{
675    CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
676    Cell cell(p);
677    Map* m = player->GetMap();
678
679    m->UpdatePlayerVisibility(player,cell,p);
680    m->UpdateObjectsVisibilityFor(player,cell,p);
681}
682
683/// Define the static member of HashMapHolder
684
685template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap;
686template <class T> ZThread::FastMutex HashMapHolder<T>::i_lock;
687
688/// Global defintions for the hashmap storage
689
690template class HashMapHolder<Player>;
691template class HashMapHolder<Pet>;
692template class HashMapHolder<GameObject>;
693template class HashMapHolder<DynamicObject>;
694template class HashMapHolder<Creature>;
695template class HashMapHolder<Corpse>;
696
697template Player* ObjectAccessor::GetObjectInWorld<Player>(uint32 mapid, float x, float y, uint64 guid, Player* /*fake*/);
698template Pet* ObjectAccessor::GetObjectInWorld<Pet>(uint32 mapid, float x, float y, uint64 guid, Pet* /*fake*/);
699template Creature* ObjectAccessor::GetObjectInWorld<Creature>(uint32 mapid, float x, float y, uint64 guid, Creature* /*fake*/);
700template Corpse* ObjectAccessor::GetObjectInWorld<Corpse>(uint32 mapid, float x, float y, uint64 guid, Corpse* /*fake*/);
701template GameObject* ObjectAccessor::GetObjectInWorld<GameObject>(uint32 mapid, float x, float y, uint64 guid, GameObject* /*fake*/);
702template DynamicObject* ObjectAccessor::GetObjectInWorld<DynamicObject>(uint32 mapid, float x, float y, uint64 guid, DynamicObject* /*fake*/);
Note: See TracBrowser for help on using the browser.