[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,19 +697,12 @@ Map::PlayerRelocation(Player *player, float x, float y, float z, float orientati
} }
} }
void void Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang)
Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang)
{ {
MANGOS_ASSERT(CheckGridIntegrity(creature,false)); MANGOS_ASSERT(CheckGridIntegrity(creature,false));
Cell old_cell = creature->GetCurrentCell(); 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 // do move or do move to respawn or remove creature if previous all fail
if (CreatureCellRelocation(creature,new_cell)) if (CreatureCellRelocation(creature,new_cell))
@ -725,12 +718,6 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
// ... or unload (if respawn grid also not loaded) // ... 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()); 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
{
creature->Relocate(x, y, z, ang);
creature->OnRelocated();
}
MANGOS_ASSERT(CheckGridIntegrity(creature,true)); MANGOS_ASSERT(CheckGridIntegrity(creature,true));
} }
@ -738,64 +725,27 @@ Map::CreatureRelocation(Creature *creature, float x, float y, float z, float ang
bool Map::CreatureCellRelocation(Creature *c, Cell new_cell) bool Map::CreatureCellRelocation(Creature *c, Cell new_cell)
{ {
Cell const& old_cell = c->GetCurrentCell(); 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 (!c->isActiveObject() && !loaded(new_cell.gridPair()))
if(old_cell.DiffCell(new_cell))
{ {
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()) );
}
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())))
{
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;
}
// 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()); 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 false;
} }
EnsureGridLoadedAtEnter(new_cell);
}
if (old_cell != new_cell)
{
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()));
}
return true;
}
bool Map::CreatureRespawnRelocation(Creature *c) bool Map::CreatureRespawnRelocation(Creature *c)
{ {

View file

@ -37,7 +37,7 @@ void PointMovementGenerator<T>::Initialize(T &unit)
i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z); i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z);
if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->CanFly()) if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->CanFly())
((Creature&)unit).AddSplineFlag(SPLINEFLAG_UNKNOWN7); ((Creature&)unit).AddSplineFlag(SPLINEFLAG_FLYING);
} }
template<class T> template<class T>

View file

@ -100,7 +100,7 @@ RandomMovementGenerator<Creature>::_setRandomLocation(Creature &creature)
if (is_air_ok) if (is_air_ok)
{ {
i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime()); i_nextMoveTime.Reset(i_destinationHolder.GetTotalTravelTime());
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
} }
//else if (is_water_ok) // Swimming mode to be done with more than this check //else if (is_water_ok) // Swimming mode to be done with more than this check
else else
@ -117,7 +117,7 @@ void RandomMovementGenerator<Creature>::Initialize(Creature &creature)
return; return;
if (creature.CanFly()) if (creature.CanFly())
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
else else
creature.AddSplineFlag(SPLINEFLAG_WALKMODE); creature.AddSplineFlag(SPLINEFLAG_WALKMODE);
@ -171,7 +171,7 @@ bool RandomMovementGenerator<Creature>::Update(Creature &creature, const uint32
if (i_nextMoveTime.Passed()) if (i_nextMoveTime.Passed())
{ {
if (creature.CanFly()) if (creature.CanFly())
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
else else
creature.AddSplineFlag(SPLINEFLAG_WALKMODE); creature.AddSplineFlag(SPLINEFLAG_WALKMODE);

View file

@ -80,7 +80,7 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
D::_addUnitStateMove(owner); D::_addUnitStateMove(owner);
if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->CanFly()) if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->CanFly())
((Creature&)owner).AddSplineFlag(SPLINEFLAG_UNKNOWN7); ((Creature&)owner).AddSplineFlag(SPLINEFLAG_FLYING);
} }
template<> template<>
@ -147,7 +147,7 @@ bool TargetedMovementGeneratorMedium<T,D>::Update(T &owner, const uint32 & time_
{ {
D::_addUnitStateMove(owner); D::_addUnitStateMove(owner);
if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->CanFly()) if (owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->CanFly())
((Creature&)owner).AddSplineFlag(SPLINEFLAG_UNKNOWN7); ((Creature&)owner).AddSplineFlag(SPLINEFLAG_FLYING);
i_destinationHolder.StartTravel(traveller); i_destinationHolder.StartTravel(traveller);
return true; return true;
@ -211,7 +211,7 @@ void ChaseMovementGenerator<Creature>::Initialize(Creature &owner)
owner.RemoveSplineFlag(SPLINEFLAG_WALKMODE); owner.RemoveSplineFlag(SPLINEFLAG_WALKMODE);
if (((Creature*)&owner)->CanFly()) if (((Creature*)&owner)->CanFly())
owner.AddSplineFlag(SPLINEFLAG_UNKNOWN7); owner.AddSplineFlag(SPLINEFLAG_FLYING);
_setTargetLocation(owner); _setTargetLocation(owner);
} }
@ -282,7 +282,7 @@ void FollowMovementGenerator<Creature>::Initialize(Creature &owner)
_updateSpeed(owner); _updateSpeed(owner);
if (((Creature*)&owner)->CanFly()) if (((Creature*)&owner)->CanFly())
owner.AddSplineFlag(SPLINEFLAG_UNKNOWN7); owner.AddSplineFlag(SPLINEFLAG_FLYING);
_setTargetLocation(owner); _setTargetLocation(owner);
} }

View file

@ -75,7 +75,7 @@ inline float Traveller<Creature>::Speed()
{ {
if(i_traveller.HasSplineFlag(SPLINEFLAG_WALKMODE)) if(i_traveller.HasSplineFlag(SPLINEFLAG_WALKMODE))
return i_traveller.GetSpeed(MOVE_WALK); return i_traveller.GetSpeed(MOVE_WALK);
else if(i_traveller.HasSplineFlag(SPLINEFLAG_UNKNOWN7)) else if(i_traveller.HasSplineFlag(SPLINEFLAG_FLYING))
return i_traveller.GetSpeed(MOVE_FLIGHT); return i_traveller.GetSpeed(MOVE_FLIGHT);
else else
return i_traveller.GetSpeed(MOVE_RUN); return i_traveller.GetSpeed(MOVE_RUN);

View file

@ -79,7 +79,7 @@ void WaypointMovementGenerator<Creature>::LoadPath(Creature &creature)
CreatureTraveller traveller(creature); CreatureTraveller traveller(creature);
if (creature.CanFly()) if (creature.CanFly())
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
const WaypointNode &node = i_path->at(i_currentNode); const WaypointNode &node = i_path->at(i_currentNode);
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z); i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z);
@ -156,7 +156,7 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
creature.addUnitState(UNIT_STAT_ROAMING_MOVE); creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
if (creature.CanFly()) if (creature.CanFly())
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
// Now we re-set destination to same node and start travel // Now we re-set destination to same node and start travel
const WaypointNode &node = i_path->at(i_currentNode); const WaypointNode &node = i_path->at(i_currentNode);
@ -254,7 +254,7 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
creature.addUnitState(UNIT_STAT_ROAMING_MOVE); creature.addUnitState(UNIT_STAT_ROAMING_MOVE);
if (creature.CanFly()) if (creature.CanFly())
creature.AddSplineFlag(SPLINEFLAG_UNKNOWN7); creature.AddSplineFlag(SPLINEFLAG_FLYING);
if (WaypointBehavior *behavior = i_path->at(i_currentNode).behavior) if (WaypointBehavior *behavior = i_path->at(i_currentNode).behavior)
{ {

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11382" #define REVISION_NR "11384"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__