diff options
Diffstat (limited to 'src/game/Map.cpp')
-rw-r--r-- | src/game/Map.cpp | 518 |
1 files changed, 0 insertions, 518 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 2f8c4d0e152..ca139c13d2d 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -17,7 +17,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include "MapManager.h" #include "Player.h" #include "Vehicle.h" @@ -38,17 +37,13 @@ #include "MapRefManager.h" #include "Vehicle.h" #include "WaypointManager.h" - #include "MapInstanced.h" #include "InstanceSaveMgr.h" #include "VMapFactory.h" - #define DEFAULT_GRID_EXPIRY 300 #define MAX_GRID_LOAD_TIME 50 #define MAX_CREATURE_ATTACK_RADIUS (45.0f * sWorld.getRate(RATE_CREATURE_AGGRO)) - GridState* si_GridStates[MAX_GRID_STATE]; - struct ScriptAction { uint64 sourceGUID; @@ -56,11 +51,9 @@ struct ScriptAction uint64 ownerGUID; // owner of source if source is item ScriptInfo const* script; // pointer to static script data }; - Map::~Map() { UnloadAll(); - while(!i_worldObjects.empty()) { WorldObject *obj = *i_worldObjects.begin(); @@ -69,26 +62,21 @@ Map::~Map() obj->RemoveFromWorld(); obj->ResetMap(); } - if(!m_scriptSchedule.empty()) sWorld.DecreaseScheduledScriptCount(m_scriptSchedule.size()); } - bool Map::ExistMap(uint32 mapid,int gx,int gy) { int len = sWorld.GetDataPath().length()+strlen("maps/%03u%02u%02u.map")+1; char* tmp = new char[len]; snprintf(tmp, len, (char *)(sWorld.GetDataPath()+"maps/%03u%02u%02u.map").c_str(),mapid,gx,gy); - FILE *pf=fopen(tmp,"rb"); - if(!pf) { sLog.outError("Check existing of map file '%s': not exist!",tmp); delete[] tmp; return false; } - map_fileheader header; fread(&header, sizeof(header), 1, pf); if (header.mapMagic != uint32(MAP_MAGIC) || @@ -99,12 +87,10 @@ bool Map::ExistMap(uint32 mapid,int gx,int gy) fclose(pf); //close file before return return false; } - delete [] tmp; fclose(pf); return true; } - bool Map::ExistVMap(uint32 mapid,int gx,int gy) { if(VMAP::IVMapManager* vmgr = VMAP::VMapFactory::createOrGetVMapManager()) @@ -121,10 +107,8 @@ bool Map::ExistVMap(uint32 mapid,int gx,int gy) } } } - return true; } - void Map::LoadVMap(int gx,int gy) { // x and y are swapped !! @@ -142,26 +126,21 @@ void Map::LoadVMap(int gx,int gy) break; } } - void Map::LoadMap(int gx,int gy, bool reload) { if( i_InstanceId != 0 ) { if(GridMaps[gx][gy]) return; - // load grid map for base map if (!m_parentMap->GridMaps[gx][gy]) m_parentMap->EnsureGridCreated(GridPair(63-gx,63-gy)); - ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridPair(gx,gy)); GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy]; return; } - if(GridMaps[gx][gy] && !reload) return; - //map already load, delete it before reloading (Is it necessary? Do we really need the ability the reload maps during runtime?) if(GridMaps[gx][gy]) { @@ -169,7 +148,6 @@ void Map::LoadMap(int gx,int gy, bool reload) delete (GridMaps[gx][gy]); GridMaps[gx][gy]=NULL; } - // map file name char *tmp=NULL; int len = sWorld.GetDataPath().length()+strlen("maps/%03u%02u%02u.map")+1; @@ -184,14 +162,12 @@ void Map::LoadMap(int gx,int gy, bool reload) } delete [] tmp; } - void Map::LoadMapAndVMap(int gx,int gy) { LoadMap(gx,gy); if(i_InstanceId == 0) LoadVMap(gx, gy); // Only load the data for the base map } - void Map::InitStateMachine() { si_GridStates[GRID_STATE_INVALID] = new InvalidState; @@ -199,7 +175,6 @@ void Map::InitStateMachine() si_GridStates[GRID_STATE_IDLE] = new IdleState; si_GridStates[GRID_STATE_REMOVAL] = new RemovalState; } - void Map::DeleteStateMachine() { delete si_GridStates[GRID_STATE_INVALID]; @@ -207,7 +182,6 @@ void Map::DeleteStateMachine() delete si_GridStates[GRID_STATE_IDLE]; delete si_GridStates[GRID_STATE_REMOVAL]; } - Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent) : i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), i_InstanceId(InstanceId), m_unloadTimer(0), m_activeNonPlayersIter(m_activeNonPlayers.end()), @@ -216,7 +190,6 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _par , i_notifyLock(false), i_scriptLock(false) { m_notifyTimer.SetInterval(IN_MILISECONDS/2); - for(unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx) { for(unsigned int j=0; j < MAX_NUMBER_OF_GRIDS; ++j) @@ -226,17 +199,14 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _par setNGrid(NULL, idx, j); } } - //lets initialize visibility distance for map Map::InitVisibilityDistance(); } - void Map::InitVisibilityDistance() { //init visibility for continents m_VisibleDistance = sWorld.GetMaxVisibleDistanceOnContinents(); } - // Template specialization of utility methods template<class T> void Map::AddToGrid(T* obj, NGridType *grid, Cell const& cell) @@ -246,7 +216,6 @@ void Map::AddToGrid(T* obj, NGridType *grid, Cell const& cell) else (*grid)(cell.CellX(), cell.CellY()).template AddGridObject<T>(obj, obj->GetGUID()); } - template<> void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell) { @@ -254,10 +223,8 @@ void Map::AddToGrid(Creature* obj, NGridType *grid, Cell const& cell) (*grid)(cell.CellX(), cell.CellY()).AddWorldObject(obj, obj->GetGUID()); else (*grid)(cell.CellX(), cell.CellY()).AddGridObject(obj, obj->GetGUID()); - obj->SetCurrentCell(cell); } - template<class T> void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell) { @@ -266,7 +233,6 @@ void Map::RemoveFromGrid(T* obj, NGridType *grid, Cell const& cell) else (*grid)(cell.CellX(), cell.CellY()).template RemoveGridObject<T>(obj, obj->GetGUID()); } - template<class T> void Map::SwitchGridContainers(T* obj, bool on) { @@ -276,17 +242,13 @@ void Map::SwitchGridContainers(T* obj, bool on) sLog.outError("Map::SwitchGridContainers: Object " I64FMT " have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) return; - DEBUG_LOG("Switch object " I64FMT " from grid[%u,%u] %u", obj->GetGUID(), cell.data.Part.grid_x, cell.data.Part.grid_y, on); NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY()); assert( ngrid != NULL ); - GridType &grid = (*ngrid)(cell.CellX(), cell.CellY()); - if(on) { grid.RemoveGridObject<T>(obj, obj->GetGUID()); @@ -309,29 +271,24 @@ void Map::SwitchGridContainers(T* obj, bool on) } obj->m_isWorldObject = on; } - template void Map::SwitchGridContainers(Creature *, bool); //template void Map::SwitchGridContainers(DynamicObject *, bool); - template<class T> void Map::DeleteFromWorld(T* obj) { // Note: In case resurrectable corpse and pet its removed from global lists in own destructor delete obj; } - template<> void Map::DeleteFromWorld(Player* pl) { ObjectAccessor::Instance().RemoveObject(pl); delete pl; } - template<class T> void Map::AddNotifier(T*) { } - template<> void Map::AddNotifier(Player* obj) { @@ -339,7 +296,6 @@ void Map::AddNotifier(Player* obj) //obj->m_IsInNotifyList = false; AddUnitToNotify(obj); } - template<> void Map::AddNotifier(Creature* obj) { @@ -347,7 +303,6 @@ void Map::AddNotifier(Creature* obj) //obj->m_IsInNotifyList = false; AddUnitToNotify(obj); } - void Map::EnsureGridCreated(const GridPair &p) { @@ -357,34 +312,26 @@ Map::EnsureGridCreated(const GridPair &p) if(!getNGrid(p.x_coord, p.y_coord)) { sLog.outDebug("Creating grid[%u,%u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); - setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld.getConfig(CONFIG_GRID_UNLOAD)), p.x_coord, p.y_coord); - // build a linkage between this map and NGridType buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); - getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); - //z coord int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord; int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord; - if(!GridMaps[gx][gy]) LoadMapAndVMap(gx,gy); } } } - void Map::EnsureGridLoadedAtEnter(const Cell &cell, Player *player) { NGridType *grid; - if(EnsureGridLoaded(cell)) { grid = getNGrid(cell.GridX(), cell.GridY()); - if (player) { player->SendDelayResponse(MAX_GRID_LOAD_TIME); @@ -394,47 +341,37 @@ Map::EnsureGridLoadedAtEnter(const Cell &cell, Player *player) { DEBUG_LOG("Active object nearby triggers of loading grid [%u,%u] on map %u", cell.GridX(), cell.GridY(), GetId()); } - ResetGridExpiry(*getNGrid(cell.GridX(), cell.GridY()), 0.1f); grid->SetGridState(GRID_STATE_ACTIVE); } else grid = getNGrid(cell.GridX(), cell.GridY()); - if (player) AddToGrid(player,grid,cell); } - bool Map::EnsureGridLoaded(const Cell &cell) { EnsureGridCreated(GridPair(cell.GridX(), cell.GridY())); NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); - assert(grid != NULL); if( !isGridObjectDataLoaded(cell.GridX(), cell.GridY()) ) { sLog.outDebug("Loading grid[%u,%u] for map %u instance %u", cell.GridX(), cell.GridY(), GetId(), i_InstanceId); - ObjectGridLoader loader(*grid, this, cell); loader.LoadN(); - // Add resurrectable corpses to world object list in grid ObjectAccessor::Instance().AddCorpsesToGrid(GridPair(cell.GridX(),cell.GridY()),(*grid)(cell.CellX(), cell.CellY()), this); - setGridObjectDataLoaded(true,cell.GridX(), cell.GridY()); return true; } - return false; } - void Map::LoadGrid(float x, float y) { CellPair pair = Trinity::ComputeCellPair(x, y); Cell cell(pair); EnsureGridLoaded(cell); } - bool Map::Add(Player *player) { // Check if we are adding to correct map @@ -444,16 +381,12 @@ bool Map::Add(Player *player) Cell cell(p); EnsureGridLoadedAtEnter(cell, player); player->AddToWorld(); - SendInitSelf(player); SendInitTransports(player); - player->m_clientGUIDs.clear(); //AddNotifier(player); - return true; } - template<class T> void Map::Add(T *obj) @@ -464,7 +397,6 @@ Map::Add(T *obj) sLog.outError("Map::Add: Object " UI64FMTD " have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); if(obj->IsInWorld()) // need some clean up later { @@ -472,72 +404,56 @@ Map::Add(T *obj) AddNotifier(obj); return; } - if(obj->isActiveObject()) EnsureGridLoadedAtEnter(cell); else EnsureGridCreated(GridPair(cell.GridX(), cell.GridY())); - NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); assert( grid != NULL ); - AddToGrid(obj,grid,cell); //obj->SetMap(this); obj->AddToWorld(); - if(obj->isActiveObject()) AddToActive(obj); - DEBUG_LOG("Object %u enters grid[%u,%u]", GUID_LOPART(obj->GetGUID()), cell.GridX(), cell.GridY()); - //something, such as vehicle, needs to be update immediately //also, trigger needs to cast spell, if not update, cannot see visual //if(obj->GetTypeId() != TYPEID_UNIT) UpdateObjectVisibility(obj,cell,p); AddNotifier(obj); } - /* void Map::MessageBroadcast(Player *player, WorldPacket *msg, bool to_self) { CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) { sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) return; - MaNGOS::MessageDeliverer post_man(*player, msg, to_self); TypeContainerVisitor<MaNGOS::MessageDeliverer, WorldTypeMapContainer > message(post_man); CellLock<ReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, message, *this, *player, GetVisibilityDistance()); } - void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg) { CellPair p = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) { sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) return; - //TODO: currently on continents when Visibility.Distance.InFlight > Visibility.Distance.Continents //we have alot of blinking mobs because monster move packet send is broken... MaNGOS::ObjectMessageDeliverer post_man(*obj,msg); @@ -545,77 +461,60 @@ void Map::MessageBroadcast(WorldObject *obj, WorldPacket *msg) CellLock<ReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, message, *this, *obj, GetVisibilityDistance()); } - void Map::MessageDistBroadcast(Player *player, WorldPacket *msg, float dist, bool to_self, bool own_team_only) { CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); - if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) { sLog.outError("Map::MessageBroadcast: Player (GUID: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", player->GetGUIDLow(), player->GetPositionX(), player->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) return; - MaNGOS::MessageDistDeliverer post_man(*player, msg, dist, to_self, own_team_only); TypeContainerVisitor<MaNGOS::MessageDistDeliverer , WorldTypeMapContainer > message(post_man); CellLock<ReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, message, *this, *player, dist); } - void Map::MessageDistBroadcast(WorldObject *obj, WorldPacket *msg, float dist) { CellPair p = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); - if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) { sLog.outError("Map::MessageBroadcast: Object (GUID: %u TypeId: %u) have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); return; } - Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); - if( !loaded(GridPair(cell.data.Part.grid_x, cell.data.Part.grid_y)) ) return; - MaNGOS::ObjectMessageDistDeliverer post_man(*obj, msg, dist); TypeContainerVisitor<MaNGOS::ObjectMessageDistDeliverer, WorldTypeMapContainer > message(post_man); CellLock<ReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, message, *this, *obj, dist); } */ - bool Map::loaded(const GridPair &p) const { return ( getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord) ); } - void Map::RelocationNotify() { i_notifyLock = true; - //Notify for(std::vector<Unit*>::iterator iter = i_unitsToNotify.begin(); iter != i_unitsToNotify.end(); ++iter) { Unit *unit = *iter; if(!unit) continue; - unit->m_NotifyListPos = -1; - if(unit->m_Notified) continue; - unit->m_Notified = true; - float dist = abs(unit->GetPositionX() - unit->oldX) + abs(unit->GetPositionY() - unit->oldY); if(dist > 10.0f) { @@ -623,7 +522,6 @@ void Map::RelocationNotify() VisitWorld(unit->oldX, unit->oldY, GetVisibilityDistance(), notifier); dist = 0; } - if(unit->GetTypeId() == TYPEID_PLAYER) { Trinity::PlayerRelocationNotifier notifier(*((Player*)unit)); @@ -643,23 +541,19 @@ void Map::RelocationNotify() if(*iter) (*iter)->m_Notified = false; i_unitsToNotify.clear(); - i_notifyLock = false; - if(!i_unitsToNotifyBacklog.empty()) { i_unitsToNotify.insert(i_unitsToNotify.end(), i_unitsToNotifyBacklog.begin(), i_unitsToNotifyBacklog.end()); i_unitsToNotifyBacklog.clear(); } } - void Map::AddUnitToNotify(Unit* u) { if(u->m_NotifyListPos < 0 && u->IsInWorld()) { u->oldX = u->GetPositionX(); u->oldY = u->GetPositionY(); - if(i_notifyLock) { u->m_NotifyListPos = i_unitsToNotifyBacklog.size(); @@ -672,7 +566,6 @@ void Map::AddUnitToNotify(Unit* u) } } } - void Map::RemoveUnitFromNotify(Unit *unit) { int32 slot = unit->m_NotifyListPos; @@ -690,10 +583,8 @@ void Map::RemoveUnitFromNotify(Unit *unit) assert(slot < i_unitsToNotify.size()); i_unitsToNotify[slot] = NULL; } - unit->m_NotifyListPos = -1; } - void Map::Update(const uint32 &t_diff) { /// update players at tick @@ -703,45 +594,36 @@ void Map::Update(const uint32 &t_diff) if(plr && plr->IsInWorld()) plr->Update(t_diff); } - m_notifyTimer.Update(t_diff); if(m_notifyTimer.Passed()) { m_notifyTimer.Reset(); RelocationNotify(); } - /// update active cells around players and active objects resetMarkedCells(); - Trinity::ObjectUpdater updater(t_diff); // for creature TypeContainerVisitor<Trinity::ObjectUpdater, GridTypeMapContainer > grid_object_update(updater); // for pets TypeContainerVisitor<Trinity::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater); - // the player iterator is stored in the map object // to make sure calls to Map::Remove don't invalidate it for(m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); ++m_mapRefIter) { Player* plr = m_mapRefIter->getSource(); - if(!plr->IsInWorld()) continue; - CellPair standing_cell(Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY())); - // Check for correctness of standing_cell, it also avoids problems with update_cell if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) continue; - // the overloaded operators handle range checking // so ther's no need for range checking inside the loop CellPair begin_cell(standing_cell), end_cell(standing_cell); //lets update mobs/objects in ALL visible cells around player! CellArea area = Cell::CalculateCellArea(*plr, GetVisibilityDistance()); area.ResizeBorders(begin_cell, end_cell); - for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) { for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) @@ -762,11 +644,9 @@ void Map::Update(const uint32 &t_diff) } } } - if(plr->m_seer != plr && !plr->GetVehicle()) AddUnitToNotify(plr); } - // non-player active objects if(!m_activeNonPlayers.empty()) { @@ -774,26 +654,20 @@ void Map::Update(const uint32 &t_diff) { // skip not in world WorldObject* obj = *m_activeNonPlayersIter; - // step before processing, in this case if Map::Remove remove next object we correctly // step to next-next, and if we step to end() then newly added objects can wait next update. ++m_activeNonPlayersIter; - if(!obj->IsInWorld()) continue; - CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY())); - // Check for correctness of standing_cell, it also avoids problems with update_cell if (standing_cell.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || standing_cell.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) continue; - // the overloaded operators handle range checking // so ther's no need for range checking inside the loop CellPair begin_cell(standing_cell), end_cell(standing_cell); begin_cell << 1; begin_cell -= 1; // upper left end_cell >> 1; end_cell += 1; // lower right - for(uint32 x = begin_cell.x_coord; x <= end_cell.x_coord; ++x) { for(uint32 y = begin_cell.y_coord; y <= end_cell.y_coord; ++y) @@ -816,7 +690,6 @@ void Map::Update(const uint32 &t_diff) } } } - ///- Process necessary scripts if (!m_scriptSchedule.empty()) { @@ -824,15 +697,12 @@ void Map::Update(const uint32 &t_diff) ScriptsProcess(); i_scriptLock = false; } - MoveAllCreaturesInMoveList(); } - void Map::Remove(Player *player, bool remove) { player->RemoveFromWorld(); SendRemoveTransports(player); - CellPair p = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP) sLog.outCrash("Map::Remove: Player is in invalid cell!"); @@ -846,16 +716,13 @@ void Map::Remove(Player *player, bool remove) DEBUG_LOG("Remove player %s from grid[%u,%u]", player->GetName(), cell.GridX(), cell.GridY()); NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); assert(grid != NULL); - RemoveFromGrid(player,grid,cell); UpdateObjectVisibility(player,cell,p); } } - if( remove ) DeleteFromWorld(player); } - bool Map::RemoveBones(uint64 guid, float x, float y) { if (IsRemovalGrid(x, y)) @@ -868,7 +735,6 @@ bool Map::RemoveBones(uint64 guid, float x, float y) } return true; } - template<class T> void Map::Remove(T *obj, bool remove) @@ -876,7 +742,6 @@ Map::Remove(T *obj, bool remove) obj->RemoveFromWorld(); if(obj->isActiveObject()) RemoveFromActive(obj); - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); if(p.x_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP || p.y_coord >= TOTAL_NUMBER_OF_CELLS_PER_MAP ) sLog.outError("Map::Remove: Object " I64FMT " have invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUID(), obj->GetPositionX(), obj->GetPositionY(), p.x_coord, p.y_coord); @@ -888,14 +753,11 @@ Map::Remove(T *obj, bool remove) DEBUG_LOG("Remove object " I64FMT " from grid[%u,%u]", obj->GetGUID(), cell.data.Part.grid_x, cell.data.Part.grid_y); NGridType *grid = getNGrid(cell.GridX(), cell.GridY()); assert( grid != NULL ); - RemoveFromGrid(obj,grid,cell); UpdateObjectVisibility(obj,cell,p); } } - obj->ResetMap(); - if( remove ) { // if option set then object already saved at this moment @@ -904,30 +766,23 @@ Map::Remove(T *obj, bool remove) DeleteFromWorld(obj); } } - void Map::PlayerRelocation(Player *player, float x, float y, float z, float orientation) { assert(player); - CellPair old_val = Trinity::ComputeCellPair(player->GetPositionX(), player->GetPositionY()); CellPair new_val = Trinity::ComputeCellPair(x, y); - Cell old_cell(old_val); Cell new_cell(new_val); new_cell |= old_cell; bool same_cell = (new_cell == old_cell); - player->Relocate(x, y, z, orientation); - if( old_cell.DiffGrid(new_cell) || old_cell.DiffCell(new_cell) ) { DEBUG_LOG("Player %s relocation grid[%u,%u]cell[%u,%u]->grid[%u,%u]cell[%u,%u]", player->GetName(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); - // update player position for group at taxi flight if(player->GetGroup() && player->isInFlight()) player->SetGroupUpdateFlag(GROUP_UPDATE_FLAG_POSITION); - NGridType* oldGrid = getNGrid(old_cell.GridX(), old_cell.GridY()); RemoveFromGrid(player, oldGrid,old_cell); if( !old_cell.DiffGrid(new_cell) ) @@ -935,9 +790,7 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati else EnsureGridLoadedAtEnter(new_cell, player); } - AddUnitToNotify(player); - NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY()); if( !same_cell && newGrid->GetGridState()!= GRID_STATE_ACTIVE ) { @@ -945,17 +798,13 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati newGrid->SetGridState(GRID_STATE_ACTIVE); } } - void Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang) { assert(CheckGridIntegrity(creature,false)); - Cell old_cell = creature->GetCurrentCell(); - CellPair new_val = Trinity::ComputeCellPair(x, y); Cell new_cell(new_val); - // delay creature move for grid/cell to grid/cell moves if( old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell) ) { @@ -971,7 +820,6 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang creature->Relocate(x, y, z, ang); AddUnitToNotify(creature); } - if(creature->IsVehicle()) { for(SeatMap::iterator itr = creature->GetVehicleKit()->m_Seats.begin(); itr != creature->GetVehicleKit()->m_Seats.end(); ++itr) @@ -991,18 +839,14 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang ang + passenger->m_movementInfo.t_o); } } - assert(CheckGridIntegrity(creature,true)); } - void Map::AddCreatureToMoveList(Creature *c, float x, float y, float z, float ang) { if(!c) return; - i_creaturesToMove[c] = CreatureMover(x,y,z,ang); } - void Map::MoveAllCreaturesInMoveList() { while(!i_creaturesToMove.empty()) @@ -1012,11 +856,9 @@ void Map::MoveAllCreaturesInMoveList() Creature* c = iter->first; CreatureMover cm = iter->second; i_creaturesToMove.erase(iter); - // calculate cells CellPair new_val = Trinity::ComputeCellPair(cm.x, cm.y); Cell new_cell(new_val); - // do move or do move to respawn or remove creature if previous all fail if(CreatureCellRelocation(c,new_cell)) { @@ -1041,7 +883,6 @@ void Map::MoveAllCreaturesInMoveList() } } } - bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) { Cell const& old_cell = c->GetCurrentCell(); @@ -1054,7 +895,6 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0) sLog.outDebug("Creature (GUID: %u Entry: %u) moved in grid[%u,%u] from cell[%u,%u] to cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell); AddToGrid(c,getNGrid(new_cell.GridX(), new_cell.GridY()),new_cell); } @@ -1065,26 +905,20 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) sLog.outDebug("Creature (GUID: %u Entry: %u) move in same grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY()); #endif } - return true; } - // in diff. grids but active creature if(c->isActiveObject()) { EnsureGridLoadedAtEnter(new_cell); - #ifdef TRINITY_DEBUG if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0) sLog.outDebug("Active creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell); AddToGrid(c,getNGrid(new_cell.GridX(), new_cell.GridY()),new_cell); - return true; } - // in diff. loaded grid normal creature if(loaded(GridPair(new_cell.GridX(), new_cell.GridY()))) { @@ -1092,14 +926,11 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0) sLog.outDebug("Creature (GUID: %u Entry: %u) moved from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), old_cell.GridX(), old_cell.GridY(), old_cell.CellX(), old_cell.CellY(), new_cell.GridX(), new_cell.GridY(), new_cell.CellX(), new_cell.CellY()); #endif - RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell); EnsureGridCreated(GridPair(new_cell.GridX(), new_cell.GridY())); AddToGrid(c,getNGrid(new_cell.GridX(), new_cell.GridY()),new_cell); - return true; } - // fail to move: normal creature attempt move to unloaded grid #ifdef TRINITY_DEBUG if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0) @@ -1107,23 +938,18 @@ bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) #endif return false; } - bool Map::CreatureRespawnRelocation(Creature *c) { float resp_x, resp_y, resp_z, resp_o; c->GetRespawnCoord(resp_x, resp_y, resp_z, &resp_o); - CellPair resp_val = Trinity::ComputeCellPair(resp_x, resp_y); Cell resp_cell(resp_val); - c->CombatStop(); c->GetMotionMaster()->Clear(); - #ifdef TRINITY_DEBUG if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0) sLog.outDebug("Creature (GUID: %u Entry: %u) will moved from grid[%u,%u]cell[%u,%u] to respawn grid[%u,%u]cell[%u,%u].", c->GetGUIDLow(), c->GetEntry(), c->GetCurrentCell().GridX(), c->GetCurrentCell().GridY(), c->GetCurrentCell().CellX(), c->GetCurrentCell().CellY(), resp_cell.GridX(), resp_cell.GridY(), resp_cell.CellX(), resp_cell.CellY()); #endif - // teleport it to respawn point (like normal respawn if player see) if(CreatureCellRelocation(c,resp_cell)) { @@ -1136,48 +962,35 @@ bool Map::CreatureRespawnRelocation(Creature *c) else return false; } - bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll) { NGridType *grid = getNGrid(x, y); assert( grid != NULL); - { if(!unloadAll && ActiveObjectsNearGrid(x, y) ) return false; - sLog.outDebug("Unloading grid[%u,%u] for map %u", x,y, GetId()); - ObjectGridUnloader unloader(*grid); - if(!unloadAll) { // Finish creature moves, remove and delete all creatures with delayed remove before moving to respawn grids // Must know real mob position before move MoveAllCreaturesInMoveList(); - // move creatures to respawn grids if this is diff.grid or to remove list unloader.MoveToRespawnN(); - // Finish creature moves, remove and delete all creatures with delayed remove before unload MoveAllCreaturesInMoveList(); } - ObjectGridCleaner cleaner(*grid); cleaner.CleanN(); - RemoveAllObjectsInRemoveList(); - unloader.UnloadN(); - assert(i_objectsToRemove.empty()); - delete grid; setNGrid(NULL, x, y); } int gx = (MAX_NUMBER_OF_GRIDS - 1) - x; int gy = (MAX_NUMBER_OF_GRIDS - 1) - y; - // delete grid map, but don't delete if it is from parent map (and thus only reference) //+++if (GridMaps[gx][gy]) don't check for GridMaps[gx][gy], we might have to unload vmaps { @@ -1193,13 +1006,11 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool unloadAll) } else ((MapInstanced*)m_parentMap)->RemoveGridMapReference(GridPair(gx, gy)); - GridMaps[gx][gy] = NULL; } DEBUG_LOG("Unloading grid[%u,%u] for map %u finished", x,y, GetId()); return true; } - void Map::RemoveAllPlayers() { if(HavePlayers()) @@ -1216,12 +1027,10 @@ void Map::RemoveAllPlayers() } } } - void Map::UnloadAll() { // clear all delayed moves, useless anyway do this moves before map unload. i_creaturesToMove.clear(); - for (GridRefManager<NGridType>::iterator i = GridRefManager<NGridType>::begin(); i != GridRefManager<NGridType>::end(); ) { NGridType &grid(*i->getSource()); @@ -1229,7 +1038,6 @@ void Map::UnloadAll() UnloadGrid(grid.getX(), grid.getY(), true); // deletes the grid and removes it from the GridRefManager } } - //***************************** // Grid function //***************************** @@ -1254,17 +1062,14 @@ GridMap::GridMap() m_liquid_type = NULL; m_liquid_map = NULL; } - GridMap::~GridMap() { unloadData(); } - bool GridMap::loadData(char *filename) { // Unload old data if exist unloadData(); - map_fileheader header; // Not return error if file not found FILE *in = fopen(filename, "rb"); @@ -1302,7 +1107,6 @@ bool GridMap::loadData(char *filename) fclose(in); return false; } - void GridMap::unloadData() { if (m_area_map) delete[] m_area_map; @@ -1317,7 +1121,6 @@ void GridMap::unloadData() m_liquid_map = NULL; m_gridGetHeight = &GridMap::getHeightFromFlat; } - bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 size) { map_areaHeader header; @@ -1325,7 +1128,6 @@ bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 size) fread(&header, sizeof(header), 1, in); if (header.fourcc != uint32(MAP_AREA_MAGIC)) return false; - m_gridArea = header.gridArea; if (!(header.flags & MAP_AREA_NO_AREA)) { @@ -1334,7 +1136,6 @@ bool GridMap::loadAreaData(FILE *in, uint32 offset, uint32 size) } return true; } - bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 size) { map_heightHeader header; @@ -1342,7 +1143,6 @@ bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 size) fread(&header, sizeof(header), 1, in); if (header.fourcc != uint32(MAP_HEIGHT_MAGIC)) return false; - m_gridHeight = header.gridHeight; if (!(header.flags & MAP_HEIGHT_NO_HEIGHT)) { @@ -1377,7 +1177,6 @@ bool GridMap::loadHeihgtData(FILE *in, uint32 offset, uint32 size) m_gridGetHeight = &GridMap::getHeightFromFlat; return true; } - bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 size) { map_liquidHeader header; @@ -1385,14 +1184,12 @@ bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 size) fread(&header, sizeof(header), 1, in); if (header.fourcc != uint32(MAP_LIQUID_MAGIC)) return false; - m_liquidType = header.liquidType; m_liquid_offX = header.offsetX; m_liquid_offY = header.offsetY; m_liquid_width = header.width; m_liquid_height= header.height; m_liquidLevel = header.liquidLevel; - if (!(header.flags & MAP_LIQUID_NO_TYPE)) { m_liquid_type = new uint8 [16*16]; @@ -1405,39 +1202,32 @@ bool GridMap::loadLiquidData(FILE *in, uint32 offset, uint32 size) } return true; } - uint16 GridMap::getArea(float x, float y) { if (!m_area_map) return m_gridArea; - x = 16 * (32 - x/SIZE_OF_GRIDS); y = 16 * (32 - y/SIZE_OF_GRIDS); int lx = (int)x & 15; int ly = (int)y & 15; return m_area_map[lx*16 + ly]; } - float GridMap::getHeightFromFlat(float /*x*/, float /*y*/) const { return m_gridHeight; } - float GridMap::getHeightFromFloat(float x, float y) const { if (!m_V8 || !m_V9) return m_gridHeight; - x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS); y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS); - int x_int = (int)x; int y_int = (int)y; x -= x_int; y -= y_int; x_int&=(MAP_RESOLUTION - 1); y_int&=(MAP_RESOLUTION - 1); - // Height stored as: h5 - its v8 grid, h1-h4 - its v9 grid // +--------------> X // | h1-------h2 Coordinates is: @@ -1452,7 +1242,6 @@ float GridMap::getHeightFromFloat(float x, float y) const // 1 - detect triangle // 2 - solve linear equation from triangle points // Calculate coefficients for solve h = a*x + b*y + c - float a,b,c; // Select triangle: if (x+y < 1) @@ -1504,22 +1293,18 @@ float GridMap::getHeightFromFloat(float x, float y) const // Calculate height return a * x + b * y + c; } - float GridMap::getHeightFromUint8(float x, float y) const { if (!m_uint8_V8 || !m_uint8_V9) return m_gridHeight; - x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS); y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS); - int x_int = (int)x; int y_int = (int)y; x -= x_int; y -= y_int; x_int&=(MAP_RESOLUTION - 1); y_int&=(MAP_RESOLUTION - 1); - int32 a, b, c; uint8 *V9_h1_ptr = &m_uint8_V9[x_int*128 + x_int + y_int]; if (x+y < 1) @@ -1571,22 +1356,18 @@ float GridMap::getHeightFromUint8(float x, float y) const // Calculate height return (float)((a * x) + (b * y) + c)*m_gridIntHeightMultiplier + m_gridHeight; } - float GridMap::getHeightFromUint16(float x, float y) const { if (!m_uint16_V8 || !m_uint16_V9) return m_gridHeight; - x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS); y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS); - int x_int = (int)x; int y_int = (int)y; x -= x_int; y -= y_int; x_int&=(MAP_RESOLUTION - 1); y_int&=(MAP_RESOLUTION - 1); - int32 a, b, c; uint16 *V9_h1_ptr = &m_uint16_V9[x_int*128 + x_int + y_int]; if (x+y < 1) @@ -1638,61 +1419,48 @@ float GridMap::getHeightFromUint16(float x, float y) const // Calculate height return (float)((a * x) + (b * y) + c)*m_gridIntHeightMultiplier + m_gridHeight; } - float GridMap::getLiquidLevel(float x, float y) { if (!m_liquid_map) return m_liquidLevel; - x = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS); y = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS); - int cx_int = ((int)x & (MAP_RESOLUTION-1)) - m_liquid_offY; int cy_int = ((int)y & (MAP_RESOLUTION-1)) - m_liquid_offX; - if (cx_int < 0 || cx_int >=m_liquid_height) return INVALID_HEIGHT; if (cy_int < 0 || cy_int >=m_liquid_width ) return INVALID_HEIGHT; - return m_liquid_map[cx_int*m_liquid_width + cy_int]; } - uint8 GridMap::getTerrainType(float x, float y) { if (!m_liquid_type) return m_liquidType; - x = 16 * (32 - x/SIZE_OF_GRIDS); y = 16 * (32 - y/SIZE_OF_GRIDS); int lx = (int)x & 15; int ly = (int)y & 15; return m_liquid_type[lx*16 + ly]; } - // Get water state on map inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data) { // Check water type (if no water return) if (!m_liquid_type && !m_liquidType) return LIQUID_MAP_NO_WATER; - // Get cell float cx = MAP_RESOLUTION * (32 - x/SIZE_OF_GRIDS); float cy = MAP_RESOLUTION * (32 - y/SIZE_OF_GRIDS); - int x_int = (int)cx & (MAP_RESOLUTION-1); int y_int = (int)cy & (MAP_RESOLUTION-1); - // Check water type in cell uint8 type = m_liquid_type ? m_liquid_type[(x_int>>3)*16 + (y_int>>3)] : m_liquidType; if (type == 0) return LIQUID_MAP_NO_WATER; - // Check req liquid type mask if (ReqLiquidType && !(ReqLiquidType&type)) return LIQUID_MAP_NO_WATER; - // Check water level: // Check water height map int lx_int = x_int - m_liquid_offY; @@ -1701,16 +1469,13 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R return LIQUID_MAP_NO_WATER; if (ly_int < 0 || ly_int >=m_liquid_width ) return LIQUID_MAP_NO_WATER; - // Get water level float liquid_level = m_liquid_map ? m_liquid_map[lx_int*m_liquid_width + ly_int] : m_liquidLevel; // Get ground level (sub 0.2 for fix some errors) float ground_level = getHeight(x, y); - // Check water level and ground level if (liquid_level < ground_level || z < ground_level - 2) return LIQUID_MAP_NO_WATER; - // All ok in water -> store data if (data) { @@ -1718,10 +1483,8 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R data->level = liquid_level; data->depth_level = ground_level; } - // For speed check as int values int delta = int((liquid_level - z) * 10); - // Get position delta if (delta > 20) // Under water return LIQUID_MAP_UNDER_WATER; @@ -1732,19 +1495,15 @@ inline ZLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 R // Above water return LIQUID_MAP_ABOVE_WATER; } - inline GridMap *Map::GetGrid(float x, float y) { // half opt method int gx=(int)(32-x/SIZE_OF_GRIDS); //grid x int gy=(int)(32-y/SIZE_OF_GRIDS); //grid y - // ensure GridMap is loaded EnsureGridCreated(GridPair(63-gx,63-gy)); - return GridMaps[gx][gy]; } - float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const { // find raw .map surface under Z coordinates @@ -1752,7 +1511,6 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y)) { float _mapheight = gmap->getHeight(x,y); - // look from a bit higher pos to find the floor, ignore under surface case if(z + 2.0f > _mapheight) mapHeight = _mapheight; @@ -1761,7 +1519,6 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const } else mapHeight = VMAP_INVALID_HEIGHT_VALUE; - float vmapHeight; if(pUseVmaps) { @@ -1776,23 +1533,19 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const } else vmapHeight = VMAP_INVALID_HEIGHT_VALUE; - // mapHeight set for any above raw ground Z or <= INVALID_HEIGHT // vmapheight set for any under Z value or <= INVALID_HEIGHT - if( vmapHeight > INVALID_HEIGHT ) { if( mapHeight > INVALID_HEIGHT ) { // we have mapheight and vmapheight and must select more appropriate - // we are already under the surface or vmap height above map heigt // or if the distance of the vmap height is less the land height distance if( z < mapHeight || vmapHeight > mapHeight || fabs(mapHeight-z) > fabs(vmapHeight-z) ) return vmapHeight; else return mapHeight; // better use .map surface height - } else return vmapHeight; // we have only vmapHeight (if have) @@ -1807,7 +1560,6 @@ float Map::GetHeight(float x, float y, float z, bool pUseVmaps) const return VMAP_INVALID_HEIGHT_VALUE; // we not have any height } } - float Map::GetVmapHeight(float x, float y, float z, bool useMaps) const { float mapHeight; @@ -1827,7 +1579,6 @@ float Map::GetVmapHeight(float x, float y, float z, bool useMaps) const return INVALID_HEIGHT; return vmapHeight; } - uint16 Map::GetAreaFlag(float x, float y, float z) const { uint16 areaflag; @@ -1836,7 +1587,6 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const // this used while not all *.map files generated (instances) else areaflag = GetAreaFlagByMapId(GetId()); - //FIXME: some hacks for areas above or underground for ground area // required for area specific spells/etc, until map/vmap data // not provided correct areaflag with this hacks @@ -1865,14 +1615,12 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const break; } } - // The Violet Hold (Dalaran), fast check if (x < 5791.0f && y > 404.0f && y < 595.0f) { areaflag = 2540; break; } - // Dalaran areaflag = 2153; } @@ -1893,21 +1641,18 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const break; } } - // The Eventide (Dalaran), fast check against diagonal box with lower limit if (z > 635.0f && x+y < 6375.0f && x+y > 6295.0f && x-y < 5106.0f && x-y > 4972.0f) { areaflag = 2543; break; } - // The Violet Hold (Dalaran), fast check if (x < 5791.0f && y > 404.0f && y < 595.0f) { areaflag = 2540; break; } - // Dalaran areaflag = 2153; } @@ -1926,7 +1671,6 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const areaflag = 2748; break; } - // The Violet Citadel (Dalaran) if ((x-5803.0f)*(x-5803.0f)+(y-846.18f)*(y-846.18f) < 6690.0f) { @@ -1934,7 +1678,6 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const break; } } - // Dalaran areaflag = 2153; } @@ -1999,10 +1742,8 @@ uint16 Map::GetAreaFlag(float x, float y, float z) const } break; } - return areaflag; } - uint8 Map::GetTerrainType(float x, float y ) const { if(GridMap *gmap = const_cast<Map*>(this)->GetGrid(x, y)) @@ -2010,7 +1751,6 @@ uint8 Map::GetTerrainType(float x, float y ) const else return 0; } - ZLiquidStatus Map::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidType, LiquidData *data) const { if(GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y)) @@ -2018,7 +1758,6 @@ ZLiquidStatus Map::getLiquidStatus(float x, float y, float z, uint8 ReqLiquidTyp else return LIQUID_MAP_NO_WATER; } - float Map::GetWaterLevel(float x, float y ) const { if(GridMap* gmap = const_cast<Map*>(this)->GetGrid(x, y)) @@ -2026,35 +1765,28 @@ float Map::GetWaterLevel(float x, float y ) const else return 0; } - uint32 Map::GetAreaIdByAreaFlag(uint16 areaflag,uint32 map_id) { AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id); - if (entry) return entry->ID; else return 0; } - uint32 Map::GetZoneIdByAreaFlag(uint16 areaflag,uint32 map_id) { AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id); - if( entry ) return ( entry->zone != 0 ) ? entry->zone : entry->ID; else return 0; } - void Map::GetZoneAndAreaIdByAreaFlag(uint32& zoneid, uint32& areaid, uint16 areaflag,uint32 map_id) { AreaTableEntry const *entry = GetAreaEntryByAreaFlagAndMap(areaflag,map_id); - areaid = entry ? entry->ID : 0; zoneid = entry ? (( entry->zone != 0 ) ? entry->zone : entry->ID) : 0; } - bool Map::IsInWater(float x, float y, float pZ, float min_depth) const { // Check surface in x, y point for liquid @@ -2069,7 +1801,6 @@ bool Map::IsInWater(float x, float y, float pZ, float min_depth) const } return false; } - bool Map::IsUnderWater(float x, float y, float z) const { if (const_cast<Map*>(this)->GetGrid(x, y)) @@ -2079,11 +1810,9 @@ bool Map::IsUnderWater(float x, float y, float z) const } return false; } - bool Map::CheckGridIntegrity(Creature* c, bool moved) const { Cell const& cur_cell = c->GetCurrentCell(); - CellPair xy_val = Trinity::ComputeCellPair(c->GetPositionX(), c->GetPositionY()); Cell xy_cell(xy_val); if(xy_cell != cur_cell) @@ -2095,15 +1824,12 @@ bool Map::CheckGridIntegrity(Creature* c, bool moved) const xy_cell.GridX(), xy_cell.GridY(), xy_cell.CellX(), xy_cell.CellY()); return true; // not crash at error, just output error in debug mode } - return true; } - const char* Map::GetMapName() const { return i_mapEntry ? i_mapEntry->name[sWorld.GetDefaultDbcLocale()] : "UNNAMEDMAP\x0"; } - void Map::UpdateObjectVisibility( WorldObject* obj, Cell cell, CellPair cellpair) { cell.data.Part.reserved = ALL_DISTRICT; @@ -2113,23 +1839,18 @@ void Map::UpdateObjectVisibility( WorldObject* obj, Cell cell, CellPair cellpair CellLock<GridReadGuard> cell_lock(cell, cellpair); cell_lock->Visit(cell_lock, player_notifier, *this, *obj, GetVisibilityDistance()); } - /* void Map::UpdatePlayerVisibility( Player* player, Cell cell, CellPair cellpair ) { cell.data.Part.reserved = ALL_DISTRICT; - MaNGOS::PlayerNotifier pl_notifier(*player); TypeContainerVisitor<MaNGOS::PlayerNotifier, WorldTypeMapContainer > player_notifier(pl_notifier); - CellLock<ReadGuard> cell_lock(cell, cellpair); cell_lock->Visit(cell_lock, player_notifier, *this, *player, GetVisibilityDistance()); } - void Map::UpdateObjectsVisibilityFor( Player* player, Cell cell, CellPair cellpair ) { MaNGOS::VisibleNotifier notifier(*player); - cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); TypeContainerVisitor<MaNGOS::VisibleNotifier, WorldTypeMapContainer > world_notifier(notifier); @@ -2137,54 +1858,42 @@ void Map::UpdateObjectsVisibilityFor( Player* player, Cell cell, CellPair cellpa CellLock<GridReadGuard> cell_lock(cell, cellpair); cell_lock->Visit(cell_lock, world_notifier, *this, *player, GetVisibilityDistance()); cell_lock->Visit(cell_lock, grid_notifier, *this, *player, GetVisibilityDistance()); - // send data notifier.Notify(); } - void Map::PlayerRelocationNotify( Player* player, Cell cell, CellPair cellpair ) { CellLock<ReadGuard> cell_lock(cell, cellpair); MaNGOS::PlayerRelocationNotifier relocationNotifier(*player); cell.data.Part.reserved = ALL_DISTRICT; - TypeContainerVisitor<MaNGOS::PlayerRelocationNotifier, GridTypeMapContainer > p2grid_relocation(relocationNotifier); TypeContainerVisitor<MaNGOS::PlayerRelocationNotifier, WorldTypeMapContainer > p2world_relocation(relocationNotifier); - cell_lock->Visit(cell_lock, p2grid_relocation, *this, *player, MAX_CREATURE_ATTACK_RADIUS); cell_lock->Visit(cell_lock, p2world_relocation, *this, *player, MAX_CREATURE_ATTACK_RADIUS); } - void Map::CreatureRelocationNotify(Creature *creature, Cell cell, CellPair cellpair) { CellLock<ReadGuard> cell_lock(cell, cellpair); MaNGOS::CreatureRelocationNotifier relocationNotifier(*creature); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); // not trigger load unloaded grids at notifier call - TypeContainerVisitor<MaNGOS::CreatureRelocationNotifier, WorldTypeMapContainer > c2world_relocation(relocationNotifier); TypeContainerVisitor<MaNGOS::CreatureRelocationNotifier, GridTypeMapContainer > c2grid_relocation(relocationNotifier); - cell_lock->Visit(cell_lock, c2world_relocation, *this, *creature, MAX_CREATURE_ATTACK_RADIUS); cell_lock->Visit(cell_lock, c2grid_relocation, *this, *creature, MAX_CREATURE_ATTACK_RADIUS); } */ - void Map::SendInitSelf( Player * player ) { sLog.outDetail("Creating player data for himself %u", player->GetGUIDLow()); - UpdateData data; - // attach to player data current transport data if(Transport* transport = player->GetTransport()) { transport->BuildCreateUpdateBlockForPlayer(&data, player); } - // build data for self presence in world at own client (one time for map) player->BuildCreateUpdateBlockForPlayer(&data, player); - // build other passengers at transport also (they always visible and marked as visible and will not send at visibility update at add to map if(Transport* transport = player->GetTransport()) { @@ -2196,25 +1905,19 @@ void Map::SendInitSelf( Player * player ) } } } - WorldPacket packet; data.BuildPacket(&packet); player->GetSession()->SendPacket(&packet); } - void Map::SendInitTransports( Player * player ) { // Hack to send out transports MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; - // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) return; - UpdateData transData; - MapManager::TransportSet& tset = tmap[player->GetMapId()]; - for (MapManager::TransportSet::const_iterator i = tset.begin(); i != tset.end(); ++i) { // send data for current transport in other place @@ -2223,35 +1926,27 @@ void Map::SendInitTransports( Player * player ) (*i)->BuildCreateUpdateBlockForPlayer(&transData, player); } } - WorldPacket packet; transData.BuildPacket(&packet); player->GetSession()->SendPacket(&packet); } - void Map::SendRemoveTransports( Player * player ) { // Hack to send out transports MapManager::TransportMap& tmap = MapManager::Instance().m_TransportsByMap; - // no transports at map if (tmap.find(player->GetMapId()) == tmap.end()) return; - UpdateData transData; - MapManager::TransportSet& tset = tmap[player->GetMapId()]; - // except used transport for (MapManager::TransportSet::const_iterator i = tset.begin(); i != tset.end(); ++i) if((*i) != player->GetTransport() && (*i)->GetMapId()!=GetId()) (*i)->BuildOutOfRangeUpdateBlock(&transData); - WorldPacket packet; transData.BuildPacket(&packet); player->GetSession()->SendPacket(&packet); } - inline void Map::setNGrid(NGridType *grid, uint32 x, uint32 y) { if(x >= MAX_NUMBER_OF_GRIDS || y >= MAX_NUMBER_OF_GRIDS) @@ -2261,11 +1956,9 @@ inline void Map::setNGrid(NGridType *grid, uint32 x, uint32 y) } i_grids[x][y] = grid; } - void Map::DelayedUpdate(const uint32 t_diff) { RemoveAllObjectsInRemoveList(); - // 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 if (!IsBattleGroundOrArena()) @@ -2280,21 +1973,16 @@ void Map::DelayedUpdate(const uint32 t_diff) } } } - void Map::AddObjectToRemoveList(WorldObject *obj) { assert(obj->GetMapId()==GetId() && obj->GetInstanceId()==GetInstanceId()); - obj->CleanupsBeforeDelete(); // remove or simplify at least cross referenced links - i_objectsToRemove.insert(obj); //sLog.outDebug("Object (GUID: %u TypeId: %u ) added to removing list.",obj->GetGUIDLow(),obj->GetTypeId()); } - void Map::AddObjectToSwitchList(WorldObject *obj, bool on) { assert(obj->GetMapId()==GetId() && obj->GetInstanceId()==GetInstanceId()); - std::map<WorldObject*, bool>::iterator itr = i_objectsToSwitch.find(obj); if(itr == i_objectsToSwitch.end()) i_objectsToSwitch.insert(itr, std::make_pair(obj, on)); @@ -2303,7 +1991,6 @@ void Map::AddObjectToSwitchList(WorldObject *obj, bool on) else assert(false); } - void Map::RemoveAllObjectsInRemoveList() { while(!i_objectsToSwitch.empty()) @@ -2312,7 +1999,6 @@ void Map::RemoveAllObjectsInRemoveList() WorldObject *obj = itr->first; bool on = itr->second; i_objectsToSwitch.erase(itr); - switch(obj->GetTypeId()) { case TYPEID_UNIT: @@ -2321,13 +2007,11 @@ void Map::RemoveAllObjectsInRemoveList() break; } } - //sLog.outDebug("Object remover 1 check."); while(!i_objectsToRemove.empty()) { std::set<WorldObject*>::iterator itr = i_objectsToRemove.begin(); WorldObject* obj = *itr; - switch(obj->GetTypeId()) { case TYPEID_CORPSE: @@ -2355,12 +2039,10 @@ void Map::RemoveAllObjectsInRemoveList() sLog.outError("Non-grid object (TypeId: %u) in grid object removing list, ignored.",obj->GetTypeId()); break; } - i_objectsToRemove.erase(itr); } //sLog.outDebug("Object remover 2 check."); } - uint32 Map::GetPlayersCountExceptGMs() const { uint32 count = 0; @@ -2369,57 +2051,45 @@ uint32 Map::GetPlayersCountExceptGMs() const ++count; return count; } - void Map::SendToPlayers(WorldPacket const* data) const { for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) itr->getSource()->GetSession()->SendPacket(data); } - bool Map::ActiveObjectsNearGrid(uint32 x, uint32 y) const { ASSERT(x < MAX_NUMBER_OF_GRIDS); ASSERT(y < MAX_NUMBER_OF_GRIDS); - CellPair cell_min(x*MAX_NUMBER_OF_CELLS, y*MAX_NUMBER_OF_CELLS); CellPair cell_max(cell_min.x_coord + MAX_NUMBER_OF_CELLS, cell_min.y_coord+MAX_NUMBER_OF_CELLS); - //we must find visible range in cells so we unload only non-visible cells... float viewDist = GetVisibilityDistance(); int cell_range = (int)ceilf(viewDist / SIZE_OF_GRID_CELL) + 1; - cell_min << cell_range; cell_min -= cell_range; cell_max >> cell_range; cell_max += cell_range; - for(MapRefManager::const_iterator iter = m_mapRefManager.begin(); iter != m_mapRefManager.end(); ++iter) { Player* plr = iter->getSource(); - CellPair p = Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()); if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) return true; } - for(ActiveNonPlayers::const_iterator iter = m_activeNonPlayers.begin(); iter != m_activeNonPlayers.end(); ++iter) { WorldObject* obj = *iter; - CellPair p = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); if( (cell_min.x_coord <= p.x_coord && p.x_coord <= cell_max.x_coord) && (cell_min.y_coord <= p.y_coord && p.y_coord <= cell_max.y_coord) ) return true; } - return false; } - void Map::AddToActive( Creature* c ) { AddToActiveHelper(c); - // also not allow unloading spawn grid to prevent creating creature clone at load if(!c->isPet() && c->GetDBTableGUIDLow()) { @@ -2436,11 +2106,9 @@ void Map::AddToActive( Creature* c ) } } } - void Map::RemoveFromActive( Creature* c ) { RemoveFromActiveHelper(c); - // also allow unloading spawn grid if(!c->isPet() && c->GetDBTableGUIDLow()) { @@ -2457,19 +2125,15 @@ void Map::RemoveFromActive( Creature* c ) } } } - template void Map::Add(Corpse *); template void Map::Add(Creature *); template void Map::Add(GameObject *); template void Map::Add(DynamicObject *); - template void Map::Remove(Corpse *,bool); template void Map::Remove(Creature *,bool); template void Map::Remove(GameObject *, bool); template void Map::Remove(DynamicObject *, bool); - /* ******* Dungeon Instance Maps ******* */ - InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent) : Map(id, expiry, InstanceId, SpawnMode, _parent), m_resetAfterUnload(false), m_unloadWhenEmpty(false), @@ -2477,12 +2141,10 @@ InstanceMap::InstanceMap(uint32 id, time_t expiry, uint32 InstanceId, uint8 Spaw { //lets initialize visibility distance for dungeons InstanceMap::InitVisibilityDistance(); - // the timer is started by default, and stopped when the first player joins // this make sure it gets unloaded if for some reason no player joins m_unloadTimer = std::max(sWorld.getConfig(CONFIG_INSTANCE_UNLOAD_DELAY), (uint32)MIN_UNLOAD_DELAY); } - InstanceMap::~InstanceMap() { if(i_data) @@ -2491,13 +2153,11 @@ InstanceMap::~InstanceMap() i_data = NULL; } } - void InstanceMap::InitVisibilityDistance() { //init visibility distance for instances m_VisibleDistance = sWorld.GetMaxVisibleDistanceInInstances(); } - /* Do map specific checks to see if the player can enter */ @@ -2509,7 +2169,6 @@ bool InstanceMap::CanEnter(Player *player) assert(false); return false; } - // cannot enter if the instance is full (player cap), GMs don't count uint32 maxPlayers = GetMaxPlayers(); if (!player->isGameMaster() && GetPlayersCountExceptGMs() >= maxPlayers) @@ -2518,7 +2177,6 @@ bool InstanceMap::CanEnter(Player *player) player->SendTransferAborted(GetId(), TRANSFER_ABORT_MAX_PLAYERS); return false; } - // cannot enter while players in the instance are in combat Group *pGroup = player->GetGroup(); if(!player->isGameMaster() && pGroup && pGroup->InCombatToInstance(GetInstanceId()) && player->GetMapId() != GetId()) @@ -2526,10 +2184,8 @@ bool InstanceMap::CanEnter(Player *player) player->SendTransferAborted(GetId(), TRANSFER_ABORT_ZONE_IN_COMBAT); return false; } - return Map::CanEnter(player); } - /* Do map specific checks and add the player to the map if successful. */ @@ -2538,13 +2194,11 @@ bool InstanceMap::Add(Player *player) // TODO: Not sure about checking player level: already done in HandleAreaTriggerOpcode // GMs still can teleport player in instance. // Is it needed? - { Guard guard(*this); // Check moved to void WorldSession::HandleMoveWorldportAckOpcode() //if(!CanEnter(player)) //return false; - // Dungeon only code if(IsDungeon()) { @@ -2555,7 +2209,6 @@ bool InstanceMap::Add(Player *player) sLog.outDetail("InstanceMap::Add: creating instance save for map %d spawnmode %d with instance id %d", GetId(), GetSpawnMode(), GetInstanceId()); mapSave = sInstanceSaveManager.AddInstanceSave(GetId(), GetInstanceId(), GetSpawnMode(), 0, true); } - // check for existing instance binds InstancePlayerBind *playerBind = player->GetBoundInstance(GetId(), GetSpawnMode()); if(playerBind && playerBind->perm) @@ -2622,32 +2275,26 @@ bool InstanceMap::Add(Player *player) } } } - if(i_data) i_data->OnPlayerEnter(player); // for normal instances cancel the reset schedule when the // first player enters (no players yet) SetResetSchedule(false); - sLog.outDetail("MAP: Player '%s' entered the instance '%u' of map '%s'", player->GetName(), GetInstanceId(), GetMapName()); // initialize unload state m_unloadTimer = 0; m_resetAfterUnload = false; m_unloadWhenEmpty = false; } - // this will acquire the same mutex so it cannot be in the previous block Map::Add(player); return true; } - void InstanceMap::Update(const uint32& t_diff) { Map::Update(t_diff); - if(i_data) i_data->Update(t_diff); } - void InstanceMap::Remove(Player *player, bool remove) { sLog.outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName()); @@ -2658,24 +2305,19 @@ void InstanceMap::Remove(Player *player, bool remove) // for normal instances schedule the reset after all players have left SetResetSchedule(true); } - void InstanceMap::CreateInstanceData(bool load) { if(i_data != NULL) return; - InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(GetId()); if (mInstance) { i_script_id = mInstance->script_id; i_data = Script->CreateInstanceData(this); } - if(!i_data) return; - i_data->Initialize(); - if(load) { // TODO: make a global storage for this @@ -2693,7 +2335,6 @@ void InstanceMap::CreateInstanceData(bool load) } } } - /* Returns true if there are no players in the instance */ @@ -2701,7 +2342,6 @@ bool InstanceMap::Reset(uint8 method) { // note: since the map may not be loaded when the instance needs to be reset // the instance must be deleted from the DB by InstanceSaveManager - if(HavePlayers()) { if(method == INSTANCE_RESET_ALL) @@ -2718,7 +2358,6 @@ bool InstanceMap::Reset(uint8 method) for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) itr->getSource()->m_InstanceValid = false; } - // the unload timer is not started // instead the map will unload immediately after the players have left m_unloadWhenEmpty = true; @@ -2731,22 +2370,18 @@ bool InstanceMap::Reset(uint8 method) m_unloadTimer = MIN_UNLOAD_DELAY; m_resetAfterUnload = true; } - return m_mapRefManager.isEmpty(); } - void InstanceMap::PermBindAllPlayers(Player *player) { if(!IsDungeon()) return; - InstanceSave *save = sInstanceSaveManager.GetInstanceSave(GetInstanceId()); if(!save) { sLog.outError("Cannot bind players, no instance save available for map!"); return; } - Group *group = player->GetGroup(); // group members outside the instance group don't get bound for(MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) @@ -2762,29 +2397,23 @@ void InstanceMap::PermBindAllPlayers(Player *player) data << uint32(0); plr->GetSession()->SendPacket(&data); } - // if the leader is not in the instance the group will not get a perm bind if(group && group->GetLeaderGUID() == plr->GetGUID()) group->BindToInstance(save, true); } } - void InstanceMap::UnloadAll() { assert(!HavePlayers()); - if(m_resetAfterUnload == true) objmgr.DeleteRespawnTimeForInstance(GetInstanceId()); - Map::UnloadAll(); } - void InstanceMap::SendResetWarnings(uint32 timeLeft) const { for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) itr->getSource()->SendInstanceResetWarning(GetId(), itr->getSource()->GetDifficulty(), timeLeft); } - void InstanceMap::SetResetSchedule(bool on) { // only for normal instances @@ -2797,7 +2426,6 @@ void InstanceMap::SetResetSchedule(bool on) else sInstanceSaveManager.ScheduleReset(on, save->GetResetTime(), InstanceSaveManager::InstResetEvent(0, GetId(), GetInstanceId())); } } - uint32 InstanceMap::GetMaxPlayers() const { InstanceTemplate const* iTemplate = objmgr.GetInstanceTemplate(GetId()); @@ -2805,26 +2433,21 @@ uint32 InstanceMap::GetMaxPlayers() const return 0; return IsHeroic() ? iTemplate->maxPlayersHeroic : iTemplate->maxPlayers; } - /* ******* Battleground Instance Maps ******* */ - BattleGroundMap::BattleGroundMap(uint32 id, time_t expiry, uint32 InstanceId, Map* _parent) : Map(id, expiry, InstanceId, DIFFICULTY_NORMAL, _parent) { //lets initialize visibility distance for BG/Arenas BattleGroundMap::InitVisibilityDistance(); } - BattleGroundMap::~BattleGroundMap() { } - void BattleGroundMap::InitVisibilityDistance() { //init visibility distance for BG/Arenas m_VisibleDistance = sWorld.GetMaxVisibleDistanceInBGArenas(); } - bool BattleGroundMap::CanEnter(Player * player) { if(player->GetMapRef().getTarget() == this) @@ -2833,15 +2456,11 @@ bool BattleGroundMap::CanEnter(Player * player) assert(false); return false; } - if(player->GetBattleGroundId() != GetInstanceId()) return false; - // player number limit is checked in bgmgr, no need to do it here - return Map::CanEnter(player); } - bool BattleGroundMap::Add(Player * player) { { @@ -2854,18 +2473,15 @@ bool BattleGroundMap::Add(Player * player) } return Map::Add(player); } - void BattleGroundMap::Remove(Player *player, bool remove) { sLog.outDetail("MAP: Removing player '%s' from bg '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName()); Map::Remove(player, remove); } - void BattleGroundMap::SetUnload() { m_unloadTimer = MIN_UNLOAD_DELAY; } - void BattleGroundMap::RemoveAllPlayers() { if(HavePlayers()) @@ -2878,7 +2494,6 @@ void BattleGroundMap::RemoveAllPlayers() } } } - /// Put scripts in the execution queue void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, Object* target) { @@ -2886,12 +2501,10 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O ScriptMapMap::const_iterator s = scripts.find(id); if (s == scripts.end()) return; - // prepare static data uint64 sourceGUID = source ? source->GetGUID() : (uint64)0; //some script commands doesn't have source uint64 targetGUID = target ? target->GetGUID() : (uint64)0; uint64 ownerGUID = (source->GetTypeId()==TYPEID_ITEM) ? ((Item*)source)->GetOwnerGUID() : (uint64)0; - ///- Schedule script execution for all scripts in the script map ScriptMap const *s2 = &(s->second); bool immedScript = false; @@ -2901,12 +2514,10 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O sa.sourceGUID = sourceGUID; sa.targetGUID = targetGUID; sa.ownerGUID = ownerGUID; - sa.script = &iter->second; m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld.GetGameTime() + iter->first), sa)); if (iter->first == 0) immedScript = true; - sWorld.IncreaseScheduledScriptsCount(); } ///- If one of the effects should be immediate, launch the script execution @@ -2917,26 +2528,20 @@ void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, O i_scriptLock = false; } } - void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* source, Object* target) { // NOTE: script record _must_ exist until command executed - // prepare static data uint64 sourceGUID = source ? source->GetGUID() : (uint64)0; uint64 targetGUID = target ? target->GetGUID() : (uint64)0; uint64 ownerGUID = (source->GetTypeId()==TYPEID_ITEM) ? ((Item*)source)->GetOwnerGUID() : (uint64)0; - ScriptAction sa; sa.sourceGUID = sourceGUID; sa.targetGUID = targetGUID; sa.ownerGUID = ownerGUID; - sa.script = &script; m_scriptSchedule.insert(std::pair<time_t, ScriptAction>(time_t(sWorld.GetGameTime() + delay), sa)); - sWorld.IncreaseScheduledScriptsCount(); - ///- If effects should be immediate, launch the script execution if(delay == 0 && !i_scriptLock) { @@ -2945,22 +2550,18 @@ void Map::ScriptCommandStart(ScriptInfo const& script, uint32 delay, Object* sou i_scriptLock = false; } } - /// Process queued scripts void Map::ScriptsProcess() { if (m_scriptSchedule.empty()) return; - ///- Process overdue queued scripts std::multimap<time_t, ScriptAction>::iterator iter = m_scriptSchedule.begin(); // ok as multimap is a *sorted* associative container while (!m_scriptSchedule.empty() && (iter->first <= sWorld.GetGameTime())) { ScriptAction const& step = iter->second; - Object* source = NULL; - if(step.sourceGUID) { switch(GUID_HIPART(step.sourceGUID)) @@ -3006,11 +2607,8 @@ void Map::ScriptsProcess() break; } } - //if(source && !source->IsInWorld()) source = NULL; - Object* target = NULL; - if(step.targetGUID) { switch(GUID_HIPART(step.targetGUID)) @@ -3038,9 +2636,7 @@ void Map::ScriptsProcess() break; } } - //if(target && !target->IsInWorld()) target = NULL; - switch (step.script->command) { case SCRIPT_COMMAND_TALK: @@ -3050,7 +2646,6 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TALK call for NULL creature."); break; } - if(source->GetTypeId()!=TYPEID_UNIT) { sLog.outError("SCRIPT_COMMAND_TALK call for non-creature (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); @@ -3061,9 +2656,7 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TALK invalid chat type (%u), skipping.",step.script->datalong); break; } - uint64 unit_target = target ? target->GetGUID() : 0; - //datalong 0=normal say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text switch(step.script->datalong) { @@ -3092,20 +2685,17 @@ void Map::ScriptsProcess() } break; } - case SCRIPT_COMMAND_EMOTE: if(!source) { sLog.outError("SCRIPT_COMMAND_EMOTE call for NULL creature."); break; } - if(source->GetTypeId()!=TYPEID_UNIT) { sLog.outError("SCRIPT_COMMAND_EMOTE call for non-creature (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - ((Creature *)source)->HandleEmoteCommand(step.script->datalong); break; case SCRIPT_COMMAND_FIELD_SET: @@ -3120,7 +2710,6 @@ void Map::ScriptsProcess() step.script->datalong,source->GetValuesCount(),source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - source->SetUInt32Value(step.script->datalong, step.script->datalong2); break; case SCRIPT_COMMAND_MOVE_TO: @@ -3129,7 +2718,6 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_MOVE_TO call for NULL creature."); break; } - if(source->GetTypeId()!=TYPEID_UNIT) { sLog.outError("SCRIPT_COMMAND_MOVE_TO call for non-creature (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); @@ -3150,7 +2738,6 @@ void Map::ScriptsProcess() step.script->datalong,source->GetValuesCount(),source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - source->SetFlag(step.script->datalong, step.script->datalong2); break; case SCRIPT_COMMAND_FLAG_REMOVE: @@ -3165,10 +2752,8 @@ void Map::ScriptsProcess() step.script->datalong,source->GetValuesCount(),source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - source->RemoveFlag(step.script->datalong, step.script->datalong2); break; - case SCRIPT_COMMAND_TELEPORT_TO: { // accept player in any one from target/source arg @@ -3177,20 +2762,16 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TELEPORT_TO call for NULL object."); break; } - // must be only Player if((!target || target->GetTypeId() != TYPEID_PLAYER) && (!source || source->GetTypeId() != TYPEID_PLAYER)) { sLog.outError("SCRIPT_COMMAND_TELEPORT_TO call for non-player (TypeIdSource: %u)(TypeIdTarget: %u), skipping.", source ? source->GetTypeId() : 0, target ? target->GetTypeId() : 0); break; } - Player* pSource = target && target->GetTypeId() == TYPEID_PLAYER ? (Player*)target : (Player*)source; - pSource->TeleportTo(step.script->datalong, step.script->x, step.script->y, step.script->z, step.script->o); break; } - case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE: { if(!step.script->datalong) // creature not specified @@ -3198,36 +2779,29 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TEMP_SUMMON_CREATURE call for NULL creature."); break; } - if(!source) { sLog.outError("SCRIPT_COMMAND_TEMP_SUMMON_CREATURE call for NULL world object."); break; } - WorldObject* summoner = dynamic_cast<WorldObject*>(source); - if(!summoner) { sLog.outError("SCRIPT_COMMAND_TEMP_SUMMON_CREATURE call for non-WorldObject (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - float x = step.script->x; float y = step.script->y; float z = step.script->z; float o = step.script->o; - Creature* pCreature = summoner->SummonCreature(step.script->datalong, x, y, z, o,TEMPSUMMON_TIMED_OR_DEAD_DESPAWN,step.script->datalong2); if (!pCreature) { sLog.outError("SCRIPT_COMMAND_TEMP_SUMMON failed for creature (entry: %u).",step.script->datalong); break; } - break; } - case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT: { if(!step.script->datalong) // gameobject not specified @@ -3235,41 +2809,32 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_RESPAWN_GAMEOBJECT call for NULL gameobject."); break; } - if(!source) { sLog.outError("SCRIPT_COMMAND_RESPAWN_GAMEOBJECT call for NULL world object."); break; } - WorldObject* summoner = dynamic_cast<WorldObject*>(source); - if(!summoner) { sLog.outError("SCRIPT_COMMAND_RESPAWN_GAMEOBJECT call for non-WorldObject (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - GameObject *go = NULL; int32 time_to_despawn = step.script->datalong2<5 ? 5 : (int32)step.script->datalong2; - CellPair p(MaNGOS::ComputeCellPair(summoner->GetPositionX(), summoner->GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; - MaNGOS::GameObjectWithDbGUIDCheck go_check(*summoner,step.script->datalong); MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck> checker(summoner, go,go_check); - TypeContainerVisitor<MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > object_checker(checker); CellLock<GridReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, object_checker, *summoner->GetMap()); - if ( !go ) { sLog.outError("SCRIPT_COMMAND_RESPAWN_GAMEOBJECT failed for gameobject(guid: %u).", step.script->datalong); break; } - if( go->GetGoType()==GAMEOBJECT_TYPE_FISHINGNODE || go->GetGoType()==GAMEOBJECT_TYPE_DOOR || go->GetGoType()==GAMEOBJECT_TYPE_BUTTON || @@ -3278,13 +2843,10 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_RESPAWN_GAMEOBJECT can not be used with gameobject of type %u (guid: %u).", uint32(go->GetGoType()), step.script->datalong); break; } - if( go->isSpawned() ) break; //gameobject already spawned - go->SetLootState(GO_READY); go->SetRespawnTime(time_to_despawn); //despawn object in ? seconds - go->GetMap()->Add(go); break; } @@ -3295,35 +2857,27 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_OPEN_DOOR call for NULL door."); break; } - if(!source) { sLog.outError("SCRIPT_COMMAND_OPEN_DOOR call for NULL unit."); break; } - if(!source->isType(TYPEMASK_UNIT)) // must be any Unit (creature or player) { sLog.outError("SCRIPT_COMMAND_OPEN_DOOR call for non-unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - Unit* caster = (Unit*)source; - GameObject *door = NULL; int32 time_to_close = step.script->datalong2 < 15 ? 15 : (int32)step.script->datalong2; - CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; - MaNGOS::GameObjectWithDbGUIDCheck go_check(*caster,step.script->datalong); MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck> checker(caster,door,go_check); - TypeContainerVisitor<MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > object_checker(checker); CellLock<GridReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, object_checker, *caster->GetMap()); - if (!door) { sLog.outError("SCRIPT_COMMAND_OPEN_DOOR failed for gameobject(guid: %u).", step.script->datalong); @@ -3334,12 +2888,9 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_OPEN_DOOR failed for non-door(GoType: %u, Entry: %u, GUID: %u).", door->GetGoType(),door->GetEntry(),door->GetGUIDLow()); break; } - if (door->GetGoState() != GO_STATE_READY) break; //door already open - door->UseDoorOrButton(time_to_close); - if(target && target->isType(TYPEMASK_GAMEOBJECT) && ((GameObject*)target)->GetGoType()==GAMEOBJECT_TYPE_BUTTON) ((GameObject*)target)->UseDoorOrButton(time_to_close); break; @@ -3351,35 +2902,27 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_CLOSE_DOOR call for NULL door."); break; } - if(!source) { sLog.outError("SCRIPT_COMMAND_CLOSE_DOOR call for NULL unit."); break; } - if(!source->isType(TYPEMASK_UNIT)) // must be any Unit (creature or player) { sLog.outError("SCRIPT_COMMAND_CLOSE_DOOR call for non-unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - Unit* caster = (Unit*)source; - GameObject *door = NULL; int32 time_to_open = step.script->datalong2 < 15 ? 15 : (int32)step.script->datalong2; - CellPair p(MaNGOS::ComputeCellPair(caster->GetPositionX(), caster->GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; - MaNGOS::GameObjectWithDbGUIDCheck go_check(*caster,step.script->datalong); MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck> checker(caster,door,go_check); - TypeContainerVisitor<MaNGOS::GameObjectSearcher<MaNGOS::GameObjectWithDbGUIDCheck>, GridTypeMapContainer > object_checker(checker); CellLock<GridReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, object_checker, *caster->GetMap()); - if ( !door ) { sLog.outError("SCRIPT_COMMAND_CLOSE_DOOR failed for gameobject(guid: %u).", step.script->datalong); @@ -3390,15 +2933,11 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_CLOSE_DOOR failed for non-door(GoType: %u, Entry: %u, GUID: %u).", door->GetGoType(),door->GetEntry(),door->GetGUIDLow()); break; } - if( door->GetGoState() == GO_STATE_READY ) break; //door already closed - door->UseDoorOrButton(time_to_open); - if(target && target->isType(TYPEMASK_GAMEOBJECT) && ((GameObject*)target)->GetGoType()==GAMEOBJECT_TYPE_BUTTON) ((GameObject*)target)->UseDoorOrButton(time_to_open); - break; } case SCRIPT_COMMAND_QUEST_EXPLORED: @@ -3408,17 +2947,14 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_QUEST_EXPLORED call for NULL source."); break; } - if(!target) { sLog.outError("SCRIPT_COMMAND_QUEST_EXPLORED call for NULL target."); break; } - // when script called for item spell casting then target == (unit or GO) and source is player WorldObject* worldObject; Player* player; - if(target->GetTypeId()==TYPEID_PLAYER) { if(source->GetTypeId()!=TYPEID_UNIT && source->GetTypeId()!=TYPEID_GAMEOBJECT) @@ -3426,7 +2962,6 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_QUEST_EXPLORED call for non-creature and non-gameobject (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - worldObject = (WorldObject*)source; player = (Player*)target; } @@ -3437,27 +2972,22 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_QUEST_EXPLORED call for non-creature and non-gameobject (TypeId: %u, Entry: %u, GUID: %u), skipping.",target->GetTypeId(),target->GetEntry(),target->GetGUIDLow()); break; } - if(source->GetTypeId()!=TYPEID_PLAYER) { sLog.outError("SCRIPT_COMMAND_QUEST_EXPLORED call for non-player(TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - worldObject = (WorldObject*)target; player = (Player*)source; } - // quest id and flags checked at script loading if( (worldObject->GetTypeId()!=TYPEID_UNIT || ((Unit*)worldObject)->isAlive()) && (step.script->datalong2==0 || worldObject->IsWithinDistInMap(player,float(step.script->datalong2))) ) player->AreaExploredOrEventHappens(step.script->datalong); else player->FailQuest(step.script->datalong); - break; } - case SCRIPT_COMMAND_ACTIVATE_OBJECT: { if(!source) @@ -3465,53 +2995,42 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_ACTIVATE_OBJECT must have source caster."); break; } - if(!source->isType(TYPEMASK_UNIT)) { sLog.outError("SCRIPT_COMMAND_ACTIVATE_OBJECT source caster isn't unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - if(!target) { sLog.outError("SCRIPT_COMMAND_ACTIVATE_OBJECT call for NULL gameobject."); break; } - if(target->GetTypeId()!=TYPEID_GAMEOBJECT) { sLog.outError("SCRIPT_COMMAND_ACTIVATE_OBJECT call for non-gameobject (TypeId: %u, Entry: %u, GUID: %u), skipping.",target->GetTypeId(),target->GetEntry(),target->GetGUIDLow()); break; } - Unit* caster = (Unit*)source; - GameObject *go = (GameObject*)target; - go->Use(caster); break; } - case SCRIPT_COMMAND_REMOVE_AURA: { Object* cmdTarget = step.script->datalong2 ? source : target; - if(!cmdTarget) { sLog.outError("SCRIPT_COMMAND_REMOVE_AURA call for NULL %s.",step.script->datalong2 ? "source" : "target"); break; } - if(!cmdTarget->isType(TYPEMASK_UNIT)) { sLog.outError("SCRIPT_COMMAND_REMOVE_AURA %s isn't unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",step.script->datalong2 ? "source" : "target",cmdTarget->GetTypeId(),cmdTarget->GetEntry(),cmdTarget->GetGUIDLow()); break; } - ((Unit*)cmdTarget)->RemoveAurasDueToSpell(step.script->datalong); break; } - case SCRIPT_COMMAND_CAST_SPELL: { if(!source) @@ -3519,39 +3038,29 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_CAST_SPELL must have source caster."); break; } - Object* cmdTarget = step.script->datalong2 & 0x01 ? source : target; - if(cmdTarget && !cmdTarget->isType(TYPEMASK_UNIT)) { sLog.outError("SCRIPT_COMMAND_CAST_SPELL %s isn't unit (TypeId: %u, Entry: %u. GUID: %u), skipping.",step.script->datalong2 & 0x01 ? "source" : "target",cmdTarget->GetTypeId(),cmdTarget->GetEntry(),cmdTarget->GetGUIDLow()); break; } - Unit* spellTarget = (Unit*)cmdTarget; - Object* cmdSource = step.script->datalong2 & 0x02 ? target : source; - if(!cmdSource) { sLog.outError("SCRIPT_COMMAND_CAST_SPELL %u call for NULL %s.", step.script->datalong, step.script->datalong2 & 0x02 ? "target" : "source"); break; } - if(!cmdSource->isType(TYPEMASK_UNIT)) { sLog.outError("SCRIPT_COMMAND_CAST_SPELL %s isn't unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",step.script->datalong2 & 0x02 ? "target" : "source", cmdSource->GetTypeId(),cmdSource->GetEntry(),cmdSource->GetGUIDLow()); break; } - Unit* spellSource = (Unit*)cmdSource; - //TODO: when GO cast implemented, code below must be updated accordingly to also allow GO spell cast spellSource->CastSpell(spellTarget,step.script->datalong,false); - break; } - case SCRIPT_COMMAND_LOAD_PATH: { if(!source) @@ -3559,23 +3068,19 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_START_MOVE is tried to apply to NON-existing unit."); break; } - if(!source->isType(TYPEMASK_UNIT)) { sLog.outError("SCRIPT_COMMAND_START_MOVE source mover isn't unit (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - if(!WaypointMgr.GetPath(step.script->datalong)) { sLog.outError("SCRIPT_COMMAND_START_MOVE source mover has an invallid path, skipping.", step.script->datalong2); break; } - dynamic_cast<Unit*>(source)->GetMotionMaster()->MovePath(step.script->datalong, step.script->datalong2); break; } - case SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT: { if(!step.script->datalong || !step.script->datalong2) @@ -3585,17 +3090,14 @@ void Map::ScriptsProcess() } //our target Creature* target = NULL; - if(source) //using grid searcher { CellPair p(Trinity::ComputeCellPair(((Unit*)source)->GetPositionX(), ((Unit*)source)->GetPositionY())); Cell cell(p); cell.data.Part.reserved = ALL_DISTRICT; - //sLog.outDebug("Attempting to find Creature: Db GUID: %i", step.script->datalong); Trinity::CreatureWithDbGUIDCheck target_check(((Unit*)source), step.script->datalong); Trinity::CreatureSearcher<Trinity::CreatureWithDbGUIDCheck> checker(((Unit*)source), target, target_check); - TypeContainerVisitor<Trinity::CreatureSearcher <Trinity::CreatureWithDbGUIDCheck>, GridTypeMapContainer > unit_checker(checker); CellLock<GridReadGuard> cell_lock(cell, p); cell_lock->Visit(cell_lock, unit_checker, *(((Unit*)source)->GetMap())); @@ -3638,20 +3140,16 @@ void Map::ScriptsProcess() //if no scriptmap present... if(!datamap) break; - uint32 script_id = step.script->datalong2; //insert script into schedule but do not start it ScriptsStart(*datamap, script_id, target, NULL/*, false*/); break; } - case SCRIPT_COMMAND_KILL: { if(!source || ((Creature*)source)->isDead()) break; - ((Creature*)source)->DealDamage(((Creature*)source), ((Creature*)source)->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false); - switch(step.script->dataint) { case 0: break; //return false not remove corpse @@ -3659,7 +3157,6 @@ void Map::ScriptsProcess() } break; } - case SCRIPT_COMMAND_PLAY_SOUND: { if(!source) @@ -3667,14 +3164,12 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_PLAY_SOUND call for NULL creature."); break; } - WorldObject* pSource = dynamic_cast<WorldObject*>(source); if(!pSource) { sLog.outError("SCRIPT_COMMAND_PLAY_SOUND call for non-world object (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - // bitmask: 0/1=anyone/target, 0/2=with distance dependent Player* pTarget = NULL; if(step.script->datalong2 & 1) @@ -3684,16 +3179,13 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_PLAY_SOUND in targeted mode call for NULL target."); break; } - if(target->GetTypeId()!=TYPEID_PLAYER) { sLog.outError("SCRIPT_COMMAND_PLAY_SOUND in targeted mode call for non-player (TypeId: %u, Entry: %u, GUID: %u), skipping.",target->GetTypeId(),target->GetEntry(),target->GetGUIDLow()); break; } - pTarget = (Player*)target; } - // bitmask: 0/1=anyone/target, 0/2=with distance dependent if(step.script->datalong2 & 2) pSource->PlayDistanceSound(step.script->datalong,pTarget); @@ -3705,33 +3197,25 @@ void Map::ScriptsProcess() sLog.outError("Unknown script command %u called.",step.script->command); break; } - m_scriptSchedule.erase(iter); sWorld.DecreaseScheduledScriptCount(); - iter = m_scriptSchedule.begin(); } } - Creature* Map::GetCreature(uint64 guid) { Creature * ret = NULL; if(IS_CRE_OR_VEH_GUID(guid)) ret = ObjectAccessor::GetObjectInWorld(guid, (Creature*)NULL); - if(!ret) return NULL; - if(ret->GetMapId() != GetId()) return NULL; - if(ret->GetInstanceId() != GetInstanceId()) return NULL; - return ret; } - GameObject* Map::GetGameObject(uint64 guid) { @@ -3744,7 +3228,6 @@ Map::GetGameObject(uint64 guid) return NULL; return ret; } - DynamicObject* Map::GetDynamicObject(uint64 guid) { @@ -3757,7 +3240,6 @@ Map::GetDynamicObject(uint64 guid) return NULL; return ret; } - void Map::UpdateIteratorBack(Player *player) { if(m_mapRefIter == player->GetMapRef()) |