aboutsummaryrefslogtreecommitdiff
path: root/src/game/Map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/Map.cpp')
-rw-r--r--src/game/Map.cpp84
1 files changed, 34 insertions, 50 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index 21371f28726..7045fe5be22 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -381,30 +381,26 @@ Map::EnsureGridCreated(const GridPair &p)
void
Map::EnsureGridLoadedAtEnter(const Cell &cell, Player *player)
{
- NGridType *grid;
+ EnsureGridLoaded(cell);
+ NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
+ assert( grid != NULL );
- if(EnsureGridLoaded(cell))
+ if (player)
{
- grid = getNGrid(cell.GridX(), cell.GridY());
-
- if (player)
- {
- player->SendDelayResponse(MAX_GRID_LOAD_TIME);
- DEBUG_LOG("Player %s enter cell[%u,%u] triggers of loading grid[%u,%u] on map %u", player->GetName(), cell.CellX(), cell.CellY(), cell.GridX(), cell.GridY(), GetId());
- }
- else
- {
- 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);
+ player->SendDelayResponse(MAX_GRID_LOAD_TIME);
+ DEBUG_LOG("Player %s enter cell[%u,%u] triggers of loading grid[%u,%u] on map %u", player->GetName(), cell.CellX(), cell.CellY(), cell.GridX(), cell.GridY(), GetId());
}
else
- grid = getNGrid(cell.GridX(), cell.GridY());
+ {
+ DEBUG_LOG("Active object nearby triggers of loading grid [%u,%u] on map %u", cell.GridX(), cell.GridY(), GetId());
+ }
- if (player)
- AddToGrid(player,grid,cell);
+ // refresh grid state & timer
+ if( grid->GetGridState() != GRID_STATE_ACTIVE )
+ {
+ ResetGridExpiry(*grid, 0.1f);
+ grid->SetGridState(GRID_STATE_ACTIVE);
+ }
}
bool Map::EnsureGridLoaded(const Cell &cell)
@@ -441,10 +437,22 @@ bool Map::Add(Player *player)
{
// Check if we are adding to correct map
assert (player->GetMap() == this);
- // update player state for other player and visa-versa
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.outError("Map::Add: 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 false;
+ }
+
+ player->GetMapRef().link(this, player);
+ player->SetMap(this);
+
Cell cell(p);
EnsureGridLoadedAtEnter(cell, player);
+ NGridType *grid = getNGrid(cell.GridX(), cell.GridY());
+ assert( grid != NULL );
+ AddToGrid(player, grid, cell);
+
player->ResetAllNotifies();
player->AddToWorld();
@@ -994,8 +1002,6 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
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);
@@ -1005,20 +1011,15 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
NGridType* oldGrid = getNGrid(old_cell.GridX(), old_cell.GridY());
RemoveFromGrid(player, oldGrid,old_cell);
- if (!old_cell.DiffGrid(new_cell))
- AddToGrid(player, oldGrid,new_cell);
- else
+
+ if( old_cell.DiffGrid(new_cell) )
EnsureGridLoadedAtEnter(new_cell, player);
+
+ NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY());
+ AddToGrid(player, newGrid,new_cell);
}
AddNotifier<Player>(player);
-
- NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY());
- if (!same_cell && newGrid->GetGridState()!= GRID_STATE_ACTIVE)
- {
- ResetGridExpiry(*newGrid, 0.1f);
- newGrid->SetGridState(GRID_STATE_ACTIVE);
- }
}
void
@@ -1048,24 +1049,7 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
}
if (creature->IsVehicle())
- {
- for (SeatMap::iterator itr = creature->GetVehicleKit()->m_Seats.begin(); itr != creature->GetVehicleKit()->m_Seats.end(); ++itr)
- if (Unit *passenger = itr->second.passenger)
- {
- if (passenger->GetTypeId() == TYPEID_PLAYER)
- PlayerRelocation((Player*)passenger,
- x + passenger->m_movementInfo.t_x,
- y + passenger->m_movementInfo.t_y,
- z + passenger->m_movementInfo.t_z,
- ang + passenger->m_movementInfo.t_o);
- else
- CreatureRelocation((Creature*)passenger,
- x + passenger->m_movementInfo.t_x,
- y + passenger->m_movementInfo.t_y,
- z + passenger->m_movementInfo.t_z,
- ang + passenger->m_movementInfo.t_o);
- }
- }
+ creature->GetVehicleKit()->RelocatePassengers(x,y,z,ang);
assert(CheckGridIntegrity(creature,true));
}