mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[11912] Use mmaps for MovementGenerators
This commit is contained in:
parent
e738c27714
commit
2f0ed05566
15 changed files with 130 additions and 744 deletions
|
|
@ -22,68 +22,18 @@
|
|||
#include "Player.h"
|
||||
#include "movement/MoveSplineInit.h"
|
||||
#include "movement/MoveSpline.h"
|
||||
#include "PathFinder.h"
|
||||
|
||||
template<class T>
|
||||
void
|
||||
ConfusedMovementGenerator<T>::Initialize(T &unit)
|
||||
void ConfusedMovementGenerator<T>::Initialize(T &unit)
|
||||
{
|
||||
const float wander_distance=11;
|
||||
float x,y,z;
|
||||
x = unit.GetPositionX();
|
||||
y = unit.GetPositionY();
|
||||
z = unit.GetPositionZ();
|
||||
|
||||
TerrainInfo const* map = unit.GetTerrain();
|
||||
|
||||
i_nextMove = 1;
|
||||
|
||||
bool is_water_ok, is_land_ok;
|
||||
_InitSpecific(unit, is_water_ok, is_land_ok);
|
||||
|
||||
for(unsigned int idx=0; idx < MAX_CONF_WAYPOINTS+1; ++idx)
|
||||
{
|
||||
const float wanderX=wander_distance*rand_norm_f() - wander_distance/2;
|
||||
const float wanderY=wander_distance*rand_norm_f() - wander_distance/2;
|
||||
|
||||
i_waypoints[idx][0] = x + wanderX;
|
||||
i_waypoints[idx][1] = y + wanderY;
|
||||
|
||||
// prevent invalid coordinates generation
|
||||
MaNGOS::NormalizeMapCoord(i_waypoints[idx][0]);
|
||||
MaNGOS::NormalizeMapCoord(i_waypoints[idx][1]);
|
||||
|
||||
bool is_water = map->IsInWater(i_waypoints[idx][0],i_waypoints[idx][1],z);
|
||||
// if generated wrong path just ignore
|
||||
if ((is_water && !is_water_ok) || (!is_water && !is_land_ok))
|
||||
{
|
||||
i_waypoints[idx][0] = idx > 0 ? i_waypoints[idx-1][0] : x;
|
||||
i_waypoints[idx][1] = idx > 0 ? i_waypoints[idx-1][1] : y;
|
||||
}
|
||||
|
||||
unit.UpdateAllowedPositionZ(i_waypoints[idx][0],i_waypoints[idx][1],z);
|
||||
i_waypoints[idx][2] = z;
|
||||
}
|
||||
// set initial position
|
||||
unit.GetPosition(i_x, i_y, i_z);
|
||||
|
||||
unit.StopMoving();
|
||||
unit.addUnitState(UNIT_STAT_CONFUSED|UNIT_STAT_CONFUSED_MOVE);
|
||||
}
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfusedMovementGenerator<Creature>::_InitSpecific(Creature &creature, bool &is_water_ok, bool &is_land_ok)
|
||||
{
|
||||
is_water_ok = creature.CanSwim();
|
||||
is_land_ok = creature.CanWalk();
|
||||
}
|
||||
|
||||
template<>
|
||||
void
|
||||
ConfusedMovementGenerator<Player>::_InitSpecific(Player &, bool &is_water_ok, bool &is_land_ok)
|
||||
{
|
||||
is_water_ok = true;
|
||||
is_land_ok = true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void ConfusedMovementGenerator<T>::Interrupt(T &unit)
|
||||
{
|
||||
|
|
@ -94,7 +44,6 @@ void ConfusedMovementGenerator<T>::Interrupt(T &unit)
|
|||
template<class T>
|
||||
void ConfusedMovementGenerator<T>::Reset(T &unit)
|
||||
{
|
||||
i_nextMove = 1;
|
||||
i_nextMoveTime.Reset(0);
|
||||
unit.StopMoving();
|
||||
unit.addUnitState(UNIT_STAT_CONFUSED|UNIT_STAT_CONFUSED_MOVE);
|
||||
|
|
@ -113,10 +62,7 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
|
|||
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
|
||||
|
||||
if (unit.movespline->Finalized())
|
||||
{
|
||||
i_nextMove = urand(1,MAX_CONF_WAYPOINTS);
|
||||
i_nextMoveTime.Reset(urand(0, 1500-1)); // TODO: check the minimum reset time, should be probably higher
|
||||
}
|
||||
i_nextMoveTime.Reset(urand(800, 1500));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -127,16 +73,28 @@ bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
|
|||
// start moving
|
||||
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
|
||||
|
||||
MANGOS_ASSERT( i_nextMove <= MAX_CONF_WAYPOINTS );
|
||||
float x = i_waypoints[i_nextMove][0];
|
||||
float y = i_waypoints[i_nextMove][1];
|
||||
float z = i_waypoints[i_nextMove][2];
|
||||
float x = i_x + 10.0f*(rand_norm_f() - 0.5f);
|
||||
float y = i_y + 10.0f*(rand_norm_f() - 0.5f);
|
||||
float z = i_z;
|
||||
|
||||
unit.UpdateAllowedPositionZ(x, y, z);
|
||||
|
||||
PathFinder path(&unit);
|
||||
path.setPathLengthLimit(30.0f);
|
||||
path.calculate(x, y, z);
|
||||
if(path.getPathType() & PATHFIND_NOPATH)
|
||||
{
|
||||
i_nextMoveTime.Reset(urand(800, 1000));
|
||||
return true;
|
||||
}
|
||||
|
||||
Movement::MoveSplineInit init(unit);
|
||||
init.MoveTo(x, y, z);
|
||||
init.MovebyPath(path.getPath());
|
||||
init.SetWalk(true);
|
||||
init.Launch();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +102,7 @@ template<>
|
|||
void ConfusedMovementGenerator<Player>::Finalize(Player &unit)
|
||||
{
|
||||
unit.clearUnitState(UNIT_STAT_CONFUSED|UNIT_STAT_CONFUSED_MOVE);
|
||||
unit.StopMoving();
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue