aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsilver1ce <none@none>2010-01-16 11:43:47 +0200
committersilver1ce <none@none>2010-01-16 11:43:47 +0200
commit2c03836a7c82803059b1b477d568d47ca2849179 (patch)
tree22eb3a8be45e1a453498765949c54e8db70a5a71 /src
parentf7ed03458acc345554a2700eaa1810a6351f4263 (diff)
some changes into grid relocations, cleanup
player with incorrect coordinates wouldn't be added into map, fixed problem that sometimes grid not marked as active even with players inside --HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Map.cpp84
-rw-r--r--src/game/Vehicle.cpp24
-rw-r--r--src/game/Vehicle.h1
3 files changed, 59 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));
}
diff --git a/src/game/Vehicle.cpp b/src/game/Vehicle.cpp
index a4a09389552..d7ad2d31baa 100644
--- a/src/game/Vehicle.cpp
+++ b/src/game/Vehicle.cpp
@@ -376,6 +376,30 @@ void Vehicle::RemovePassenger(Unit *unit)
//CastSpell(this, 45472, true); // Parachute
}
+void Vehicle::RelocatePassengers(float x, float y, float z, float ang)
+{
+ Map *map = me->GetMap();
+ assert(map != NULL);
+
+ // not sure that absolute position calculation is correct, it must depend on vehicle orientation and pitch angle
+ for (SeatMap::const_iterator itr = m_Seats.begin(); itr != m_Seats.end(); ++itr)
+ if (Unit *passenger = itr->second.passenger)
+ {
+ if (passenger->GetTypeId() == TYPEID_PLAYER)
+ map->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
+ map->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);
+ }
+}
+
void Vehicle::Dismiss()
{
sLog.outDebug("Vehicle::Dismiss %u", me->GetEntry());
diff --git a/src/game/Vehicle.h b/src/game/Vehicle.h
index 620f194a15b..79270d269be 100644
--- a/src/game/Vehicle.h
+++ b/src/game/Vehicle.h
@@ -60,6 +60,7 @@ class TRINITY_DLL_SPEC Vehicle
int8 GetNextEmptySeat(int8 seatId, bool next) const;
bool AddPassenger(Unit *passenger, int8 seatId = -1);
void RemovePassenger(Unit *passenger);
+ void RelocatePassengers(float x, float y, float z, float ang);
void RemoveAllPassengers();
void Dismiss();