本文整理汇总了C++中PointPath类的典型用法代码示例。如果您正苦于以下问题:C++ PointPath类的具体用法?C++ PointPath怎么用?C++ PointPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PointPath类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: traveller
void PointMovementGenerator<T>::Initialize(T &unit)
{
unit.StopMoving();
Traveller<T> traveller(unit);
// OLD: knockback effect has UNIT_STAT_JUMPING set, so if here we disable sentmonstermove there will be creature position sync problem between client and server
// NEW: reactivated this check - UNIT_STAT_JUMPING is only used in MoveJump, which sends its own packet
//i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z, !m_usePathfinding);
if (m_usePathfinding)
{
PathInfo path(&unit, i_x, i_y, i_z);
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
if (unit.GetTypeId() != TYPEID_UNIT)
unit.SetUnitMovementFlags(SPLINEFLAG_WALKING);
unit.SendMonsterMoveByPath(pointPath, 1, pointPath.size(), traveltime);
PathNode p = pointPath[pointPath.size()-1];
i_destinationHolder.SetDestination(traveller, p.x, p.y, p.z, false);
}
else
i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z, /*true*/ !unit.HasUnitState(UNIT_STAT_JUMPING));
}
示例2: traveller
void PointMovementGenerator<T>::Initialize(T& unit)
{
if (!unit.IsStopped())
unit.StopMoving();
unit.addUnitState(UNIT_STAT_ROAMING | UNIT_STAT_ROAMING_MOVE);
Traveller<T> traveller(unit);
if (m_usePathfinding)
{
PathInfo path(&unit, i_x, i_y, i_z);
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
SplineFlags flags = (unit.GetTypeId() == TYPEID_UNIT) ? ((Creature*)&unit)->GetSplineFlags() : SPLINEFLAG_WALKMODE;
unit.SendMonsterMoveByPath(pointPath, 1, pointPath.size(), flags, traveltime);
PathNode p = pointPath[pointPath.size() - 1];
i_destinationHolder.SetDestination(traveller, p.x, p.y, p.z, false);
}
else
i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z, true);
if (unit.GetTypeId() == TYPEID_UNIT && ((Creature*)&unit)->CanFly())
((Creature&)unit).AddSplineFlag(SPLINEFLAG_FLYING);
}
示例3: traveller
void
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
{
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
return;
float x, y, z;
// at apply we can select more nice return points base at current movegen
if (owner.GetMotionMaster()->empty() || !owner.GetMotionMaster()->top()->GetResetPosition(owner,x,y,z))
owner.GetRespawnCoord(x, y, z);
CreatureTraveller traveller(owner);
i_destinationHolder.SetDestination(traveller, x, y, z, false);
PathInfo path(&owner, x, y, z);
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
modifyTravelTime(traveltime);
owner.SendMonsterMoveByPath(pointPath, 1, pointPath.size(), owner.GetSplineFlags(), traveltime);
owner.clearUnitState(UNIT_STAT_ALL_STATE);
}
示例4: traveller
void
HomeMovementGenerator<Creature>::_setTargetLocation(Creature & owner)
{
if (!&owner)
return;
if (owner.hasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED))
return;
float x, y, z;
owner.GetHomePosition(x, y, z, ori);
CreatureTraveller traveller(owner);
i_destinationHolder.SetDestination(traveller, x, y, z, false);
PathInfo path(&owner, x, y, z, true);
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
modifyTravelTime(traveltime);
owner.SendMonsterMoveByPath(pointPath, 1, pointPath.size(), traveltime);
owner.clearUnitState(UNIT_STAT_ALL_STATE);
}
示例5: makeSpline
bool NavigationMesh::makeSpline(PointPath& path) {
if( path.size() < 2 )
return false;
PointPath::iterator p0, p1, p2, p3;
p0 = p1 = path.begin();
++p1;
Ogre::Vector3 pextra = *p0 - ((*p1 - *p0).normalise() * 0.5);
path.push_front(pextra);
p0 = p1 = path.end();
--p1;
--p0;
--p0;
pextra = *p1 + ((*p1 - *p0).normalise() * 0.5);
path.push_back(pextra);
int dotsPerUnit = 2;
p0 = path.begin();
p1 = p0;
++p1;
p2 = p1;
++p2;
p3 = p2;
++p3;
while( p3 != path.end() ){
int n = (*p1 - *p2).length() * dotsPerUnit;
Ogre::Real step = 1.0/n;
Ogre::Real s = step;
for(int i = 1; i < n; ++i) {
path.insert(p2, CatmullRollSpline(*p0, *p1, *p2, *p3, s));
s += step;
}
p0 = p1;
p1 = p2;
++p2;
++p3;
}
path.pop_front();
path.pop_back();
return true;
}
示例6: sub_path
void WaypointMovementGenerator<Creature>::MoveToNextNode(CreatureTraveller &traveller)
{
Creature* owner = &(traveller.i_traveller);
const WaypointNode &node = i_path->at(i_currentNode);
i_destinationHolder.SetDestination(traveller, node.x, node.y, node.z, false);
PathInfo sub_path(owner, node.x, node.y, node.z);
PointPath myPath = sub_path.getFullPath();
float speed = traveller.Speed()*0.001f; // in ms
uint32 traveltime = uint32(myPath.GetTotalLength()/speed);
owner->SendMonsterMoveByPath(myPath, 1, myPath.size(), owner->GetSplineFlags(), traveltime);
i_nextMoveTime.Reset(traveltime);
}
示例7: buildPath
bool NavigationMesh::buildPath(PointPath& path,
const Ogre::Vector3& startPos,
const Ogre::Vector3& endPos,
Cell* startCell,
Cell* endCell) {
if (!startCell)
startCell = findCell(startPos);
if (!endCell)
endCell = findCell(endPos);
if (!startCell || !endCell) {
cout << "Celdas no pertenecen a la rejilla" << endl;
return false;
}
int startId = startCell->getId();
int endId = endCell->getId();
if (_graph[startId * _cellNumber + endId] == Ogre::Math::POS_INFINITY) {
cout << "No se ha encontrado camino" << endl;
return false;
}
CellPath cellPath;
recoverPath(startId, endId, cellPath);
path.clear();
for(CellPath::iterator i = cellPath.begin(); i != cellPath.end(); ++i)
path.push_back((*i)->getCenter());
path.push_front(startPos);
path.push_back(endPos);
makeSpline(path);
return true;
}
示例8: traveller
void PointMovementGenerator<T>::Initialize(T &unit)
{
unit.StopMoving();
Traveller<T> traveller(unit);
if (m_usePathfinding)
{
PathInfo path(&unit, i_x, i_y, i_z);
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
if (unit.GetTypeId() != TYPEID_UNIT)
unit.SetUnitMovementFlags(SPLINEFLAG_WALKMODE);
unit.SendMonsterMoveByPath(pointPath, 1, pointPath.size(), traveltime);
PathNode p = pointPath[pointPath.size()-1];
i_destinationHolder.SetDestination(traveller, p.x, p.y, p.z, false);
}
else
i_destinationHolder.SetDestination(traveller, i_x, i_y, i_z, true);
}
示例9: traveller
bool TargetedMovementGenerator<T>::_setTargetLocation(T &owner)
{
if (!i_target.isValid() || !i_target->IsInWorld())
return false;
if (owner.hasUnitState(UNIT_STAT_ROOT | UNIT_STAT_STUNNED | UNIT_STAT_DISTRACTED))
return false;
float x, y, z;
Traveller<T> traveller(owner);
if (i_destinationHolder.HasDestination() && !m_pathPointsSent)
{
if (i_destinationHolder.HasArrived())
{
// prevent redundant micro-movement
if (!i_offset)
{
if (i_target->IsWithinMeleeRange(&owner))
return false;
}
else if (!i_angle && !owner.hasUnitState(UNIT_STAT_FOLLOW))
{
if (i_target->IsWithinDistInMap(&owner, i_offset))
return false;
}
else
{
if (i_target->IsWithinDistInMap(&owner, i_offset + 1.0f))
return false;
}
}
else
{
bool stop = false;
if (!i_offset)
{
if (i_target->IsWithinMeleeRange(&owner, 0.0f))
stop = true;
}
else if (!i_angle && !owner.hasUnitState(UNIT_STAT_FOLLOW))
{
if (i_target->IsWithinDist(&owner, i_offset * 0.8f))
stop = true;
}
if (stop)
{
owner.GetPosition(x, y, z);
if (owner.GetTypeId() == TYPEID_UNIT && (owner.HasUnitMovementFlag(MOVEFLAG_CAN_FLY) || owner.IsInWater() || i_target->IsInWater()))
z = i_target->GetPositionZ();
if(m_usePathfinding)
{
bool newPathCalculated = true;
if (!i_path)
i_path = new PathInfo(&owner, x, y, z);
else
newPathCalculated = i_path->Update(x, y, z);
// nothing we can do here ...
if(i_path->getPathType() & PATHFIND_NOPATH)
return true;
PointPath pointPath = i_path->getFullPath();
if (i_destinationHolder.HasArrived() && m_pathPointsSent)
--m_pathPointsSent;
i_path->getNextPosition(x, y, z);
i_destinationHolder.SetDestination(traveller, x, y, z, false);
// send the path if:
// we have brand new path
// we have visited almost all of the previously sent points
// movespeed has changed
// the owner is stopped (caused by some movement effects)
if (newPathCalculated || m_pathPointsSent < 2 || i_recalculateTravel || owner.IsStopped())
{
// send 10 nodes, or send all nodes if there are less than 10 left
m_pathPointsSent = std::min<uint32>(10, pointPath.size() - 1);
uint32 endIndex = m_pathPointsSent + 1;
// dist to next node + world-unit length of the path
x -= owner.GetPositionX();
y -= owner.GetPositionY();
z -= owner.GetPositionZ();
float dist = sqrt(x*x + y*y + z*z) + pointPath.GetTotalLength(1, endIndex);
// calculate travel time, set spline, then send path
uint32 traveltime = uint32(dist / (traveller.Speed()*0.001f));
owner.SendMonsterMoveByPath(pointPath, 1, endIndex, traveltime);
return false;
}
}
else
{
i_destinationHolder.SetDestination(traveller, x, y, z);
//.........这里部分代码省略.........
示例10: traveller
bool ConfusedMovementGenerator<T>::Update(T &unit, const uint32 &diff)
{
if(!&unit)
return true;
// ignore in case other no reaction state
if (unit.hasUnitState(UNIT_STAT_CAN_NOT_REACT & ~UNIT_STAT_CONFUSED))
return true;
if (i_nextMoveTime.Passed())
{
// currently moving, update location
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
Traveller<T> traveller(unit);
if (i_destinationHolder.UpdateTraveller(traveller, diff, false))
{
if (!IsActive(unit)) // force stop processing (movement can move out active zone with cleanup movegens list)
return true; // not expire now, but already lost
if (i_destinationHolder.HasArrived())
{
// arrived, stop and wait a bit
unit.StopMoving();
i_nextMoveTime.Reset(urand(800, 1500));
}
}
}
else
{
// waiting for next move
i_nextMoveTime.Update(diff);
if(i_nextMoveTime.Passed())
{
// start moving
unit.addUnitState(UNIT_STAT_CONFUSED_MOVE);
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);
Traveller<T> traveller(unit);
PathInfo path(&unit, x, y, z);
if(!(path.getPathType() & PATHFIND_NORMAL))
{
i_nextMoveTime.Reset(urand(800, 1000));
return true;
}
PointPath pointPath = path.getFullPath();
float speed = traveller.Speed() * 0.001f; // in ms
uint32 traveltime = uint32(pointPath.GetTotalLength() / speed);
SplineFlags flags = (unit.GetTypeId() == TYPEID_UNIT) ? ((Creature*)&unit)->GetSplineFlags() : SPLINEFLAG_WALKMODE;
unit.SendMonsterMoveByPath(pointPath, 1, std::min<uint32>(pointPath.size(), 5), flags, traveltime);
PathNode p = pointPath[std::min<uint32>(pointPath.size()-1, 4)];
// we do not really need it with mmaps active
unit.UpdateAllowedPositionZ(p.x, p.y, p.z);
i_destinationHolder.SetDestination(traveller, p.x, p.y, p.z, false);
}
}
return true;
}
示例11: if
void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T &owner)
{
if (!i_target.isValid() || !i_target->IsInWorld())
return;
if (owner.hasUnitState(UNIT_STAT_NOT_MOVE))
return;
float x, y, z;
// prevent redundant micro-movement for pets, other followers.
if (i_offset && i_target->IsWithinDistInMap(&owner,2*i_offset))
{
if (i_destinationHolder.HasDestination())
return;
owner.GetPosition(x, y, z);
}
else if (!i_offset)
{
// to nearest contact position
i_target->GetContactPoint( &owner, x, y, z );
}
else
{
// to at i_offset distance from target and i_angle from target facing
i_target->GetClosePoint(x, y, z, owner.GetObjectBoundingRadius(), i_offset, i_angle, &owner);
}
/*
We MUST not check the distance difference and avoid setting the new location for smaller distances.
By that we risk having far too many GetContactPoint() calls freezing the whole system.
In TargetedMovementGenerator<T>::Update() we check the distance to the target and at
some range we calculate a new position. The calculation takes some processor cycles due to vmaps.
If the distance to the target it too large to ignore,
but the distance to the new contact point is short enough to be ignored,
we will calculate a new contact point each update loop, but will never move to it.
The system will freeze.
ralf
//We don't update Mob Movement, if the difference between New destination and last destination is < BothObjectSize
float bothObjectSize = i_target->GetObjectBoundingRadius() + owner.GetObjectBoundingRadius() + CONTACT_DISTANCE;
if( i_destinationHolder.HasDestination() && i_destinationHolder.GetDestinationDiff(x,y,z) < bothObjectSize )
return;
*/
//ACE_High_Res_Timer timer = ACE_High_Res_Timer();
//ACE_hrtime_t elapsed;
//timer.start();
bool forceDest = false;
// allow pets following their master to cheat while generating paths
if(owner.GetTypeId() == TYPEID_UNIT && ((Creature*)&owner)->IsPet()
&& owner.hasUnitState(UNIT_STAT_FOLLOW))
forceDest = true;
bool newPathCalculated = true;
if(!i_path)
i_path = new PathInfo(&owner, x, y, z, false, forceDest);
else
newPathCalculated = i_path->Update(x, y, z, false, forceDest);
//timer.stop();
//timer.elapsed_microseconds(elapsed);
//sLog.outDebug("Path found in %llu microseconds", elapsed);
// nothing we can do here ...
if(i_path->getPathType() & PATHFIND_NOPATH)
return;
PointPath pointPath = i_path->getFullPath();
if (i_destinationHolder.HasArrived() && m_pathPointsSent)
--m_pathPointsSent;
Traveller<T> traveller(owner);
i_path->getNextPosition(x, y, z);
i_destinationHolder.SetDestination(traveller, x, y, z, false);
// send the path if:
// we have brand new path
// we have visited almost all of the previously sent points
// movespeed has changed
// the owner is stopped (caused by some movement effects)
if (newPathCalculated || m_pathPointsSent < 2 || i_recalculateTravel || owner.IsStopped())
{
// send 10 nodes, or send all nodes if there are less than 10 left
m_pathPointsSent = std::min<uint32>(10, pointPath.size() - 1);
uint32 endIndex = m_pathPointsSent + 1;
// dist to next node + world-unit length of the path
x -= owner.GetPositionX();
y -= owner.GetPositionY();
z -= owner.GetPositionZ();
float dist = sqrt(x*x + y*y + z*z) + pointPath.GetTotalLength(1, endIndex);
// calculate travel time, set spline, then send path
uint32 traveltime = uint32(dist / (traveller.Speed()*0.001f));
SplineFlags flags = (owner.GetTypeId() == TYPEID_UNIT) ? ((Creature*)&owner)->GetSplineFlags() : SPLINEFLAG_WALKMODE;
owner.SendMonsterMoveByPath(pointPath, 1, endIndex, flags, traveltime);
//.........这里部分代码省略.........
示例12: switch
//.........这里部分代码省略.........
break;
}
}
break;
}
case TYPE_VALKIRIES:
{
switch(encounterStage)
{
case 1:
DoScriptText(SAY_STAGE_3_01, m_pInstance->GetCreature(NPC_TIRION));
cooldown = 12000;
break;
case 2:
SummonToCBoss(NPC_LIGHTBANE, NPC_DARKBANE);
for(uint8 i = 0; i < 4; ++i)
DoSpawnTocBoss(i/2 ? NPC_LIGHT_ESSENCE : NPC_DARK_ESSENCE, SpawnLoc[LOC_D_ESSENCE_1+i], 0);
cooldown = 2000;
break;
case 3:
{
if (!encounterCreature || !encounterCreature2)
break;
DoScriptText(SAY_STAGE_3_02, m_pInstance->GetCreature(NPC_TIRION));
uint32 travelTime[2];
for(uint8 second = 0; second < 2; ++second)
{
Creature* crt = second ? encounterCreature2 : encounterCreature;
((ScriptedAI*)crt->AI())->EnableAttack(false);
PointPath path;
path.resize(3);
path.set(0, crt->GetPosition());
path.set(1, second ? SpawnLoc[LOC_D_VALKYR_1] : SpawnLoc[LOC_L_VALKYR_1]);
path.set(2, second ? SpawnLoc[LOC_D_VALKYR_2] : SpawnLoc[LOC_L_VALKYR_2]);
//path.set(3, second ? SpawnLoc[LOC_D_VALKYR_3] : SpawnLoc[LOC_L_VALKYR_3]);
travelTime[second] = path.GetTotalLength()/(crt->GetSpeed(MOVE_RUN)*0.001f);
crt->GetMotionMaster()->Clear(false, true);
crt->ChargeMonsterMove(path, SPLINETYPE_FACINGANGLE, crt->GetSplineFlags(), travelTime[second], M_PI_F*1.5f);
}
cooldown = (travelTime[0] > travelTime[1] ? travelTime[0] : travelTime[1]) + 5000;
break;
}
case 4:
{
for(uint8 second = 0; second < 2; ++second)
{
Creature* crt = second ? encounterCreature2 : encounterCreature;
((ScriptedAI*)crt->AI())->EnableAttack(true);
crt->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
}
cooldown = REALLY_BIG_COOLDOWN;
break;
}
case 51: // outro
if (m_pInstance->GetInstanceSide() == INSTANCE_SIDE_ALI)
DoScriptText(SAY_STAGE_3_03a, m_pInstance->GetCreature(NPC_WRYNN));
else
DoScriptText(SAY_STAGE_3_03h, m_pInstance->GetCreature(NPC_GARROSH));
cooldown = 5000;
break;