[11384] Use SPLINEFLAG_FLYING for flying creatures, SPLINEFLAG_UNKNOWN7 is never used. Simplify Map::CreatureCellRelocation code

This commit is contained in:
SilverIce 2011-04-20 02:55:30 +03:00
parent e4c5aceba4
commit 75e1e7c3a3
7 changed files with 37 additions and 87 deletions

View file

@ -697,40 +697,27 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
}
}
void
Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang)
void Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang)
{
MANGOS_ASSERT(CheckGridIntegrity(creature,false));
Cell old_cell = creature->GetCurrentCell();
Cell new_cell(MaNGOS::ComputeCellPair(x, y));
CellPair new_val = MaNGOS::ComputeCellPair(x, y);
Cell new_cell(new_val);
if (old_cell.DiffCell(new_cell) || old_cell.DiffGrid(new_cell))
{
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) added to moving list from grid[%u,%u]cell[%u,%u] to grid[%u,%u]cell[%u,%u].", creature->GetGUIDLow(), creature->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());
// do move or do move to respawn or remove creature if previous all fail
if (CreatureCellRelocation(creature,new_cell))
{
// update pos
creature->Relocate(x, y, z, ang);
creature->OnRelocated();
}
// if creature can't be move in new cell/grid (not loaded) move it to repawn cell/grid
// creature coordinates will be updated and notifiers send
else if (!CreatureRespawnRelocation(creature))
{
// ... or unload (if respawn grid also not loaded)
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
}
}
else
// do move or do move to respawn or remove creature if previous all fail
if (CreatureCellRelocation(creature,new_cell))
{
// update pos
creature->Relocate(x, y, z, ang);
creature->OnRelocated();
}
// if creature can't be move in new cell/grid (not loaded) move it to repawn cell/grid
// creature coordinates will be updated and notifiers send
else if (!CreatureRespawnRelocation(creature))
{
// ... or unload (if respawn grid also not loaded)
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",creature->GetGUIDLow(),creature->GetEntry());
}
MANGOS_ASSERT(CheckGridIntegrity(creature,true));
}
@ -738,63 +725,26 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
{
Cell const& old_cell = c->GetCurrentCell();
if(!old_cell.DiffGrid(new_cell) ) // in same grid
if (old_cell.DiffGrid(new_cell))
{
// if in same cell then none do
if(old_cell.DiffCell(new_cell))
if (!c->isActiveObject() && !loaded(new_cell.gridPair()))
{
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "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());
RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell);
NGridType* new_grid = getNGrid(new_cell.GridX(), new_cell.GridY());
AddToGrid(c,new_grid,new_cell);
c->GetViewPoint().Event_GridChanged( &(*new_grid)(new_cell.CellX(),new_cell.CellY()) );
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) attempt move from grid[%u,%u]cell[%u,%u] to unloaded 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());
return false;
}
else
{
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "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());
}
return true;
}
// in diff. grids but active creature
if(c->isActiveObject())
{
EnsureGridLoadedAtEnter(new_cell);
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "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());
RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell);
NGridType* new_grid = getNGrid(new_cell.GridX(), new_cell.GridY());
AddToGrid(c,new_grid,new_cell);
c->GetViewPoint().Event_GridChanged( &(*new_grid)(new_cell.CellX(),new_cell.CellY()) );
return true;
}
// in diff. loaded grid normal creature
if(loaded(GridPair(new_cell.GridX(), new_cell.GridY())))
if (old_cell != new_cell)
{
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "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());
RemoveFromGrid(c,getNGrid(old_cell.GridX(), old_cell.GridY()),old_cell);
{
EnsureGridCreated(GridPair(new_cell.GridX(), new_cell.GridY()));
NGridType* new_grid = getNGrid(new_cell.GridX(), new_cell.GridY());
AddToGrid(c,new_grid,new_cell);
c->GetViewPoint().Event_GridChanged( &(*new_grid)(new_cell.CellX(),new_cell.CellY()) );
}
return true;
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "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());
NGridType* oldGrid = getNGrid(old_cell.GridX(), old_cell.GridY());
NGridType* newGrid = getNGrid(new_cell.GridX(), new_cell.GridY());
RemoveFromGrid(c, oldGrid, old_cell);
AddToGrid(c, newGrid, new_cell);
c->GetViewPoint().Event_GridChanged(&(*newGrid)(new_cell.CellX(),new_cell.CellY()));
}
// fail to move: normal creature attempt move to unloaded grid
DEBUG_FILTER_LOG(LOG_FILTER_CREATURE_MOVES, "Creature (GUID: %u Entry: %u) attempt move from grid[%u,%u]cell[%u,%u] to unloaded 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());
return false;
return true;
}
bool Map::CreatureRespawnRelocation(Creature *c)