mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 00:54:54 +00:00
TORQUE_NAVIGATION_ENABLED filtering
This commit is contained in:
parent
618ddbc9ba
commit
f278150185
4 changed files with 249 additions and 202 deletions
|
|
@ -110,8 +110,6 @@ void AIController::setAim(SimObjectPtr<SceneObject> objIn, F32 rad, Point3F offs
|
||||||
mAimTarget->mAimOffset = offset;
|
mAimTarget->mAimOffset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
|
|
||||||
bool AIController::getAIMove(Move* movePtr)
|
bool AIController::getAIMove(Move* movePtr)
|
||||||
{
|
{
|
||||||
*movePtr = NullMove;
|
*movePtr = NullMove;
|
||||||
|
|
@ -145,9 +143,9 @@ bool AIController::getAIMove(Move* movePtr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
if (sbo->getDamageState() == ShapeBase::Enabled && getGoal())
|
if (sbo->getDamageState() == ShapeBase::Enabled && getGoal())
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
if (mMovement.mMoveState != ModeStop)
|
if (mMovement.mMoveState != ModeStop)
|
||||||
getNav()->updateNavMesh();
|
getNav()->updateNavMesh();
|
||||||
|
|
||||||
|
|
@ -202,8 +200,39 @@ bool AIController::getAIMove(Move* movePtr)
|
||||||
else getGoal()->mInFiringRange = false;
|
else getGoal()->mInFiringRange = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
#else
|
||||||
|
if (getGoal()->getDist() > mControllerData->mMoveTolerance)
|
||||||
|
{
|
||||||
|
if (getGoal()->mPosSet)
|
||||||
|
getNav()->setPathDestination(getGoal()->getPosition(true));
|
||||||
|
|
||||||
|
getGoal()->mInRange = false;
|
||||||
|
}
|
||||||
|
if (getGoal()->getDist() < mControllerData->mMoveTolerance)
|
||||||
|
{
|
||||||
|
mMovement.mMoveState = ModeStop;
|
||||||
|
|
||||||
|
if (!getGoal()->mInRange)
|
||||||
|
{
|
||||||
|
getGoal()->mInRange = true;
|
||||||
|
throwCallback("onTargetInRange");
|
||||||
|
}
|
||||||
|
else getGoal()->mInRange = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (getGoal()->getDist() < mControllerData->mAttackRadius)
|
||||||
|
{
|
||||||
|
if (!getGoal()->mInFiringRange)
|
||||||
|
{
|
||||||
|
getGoal()->mInFiringRange = true;
|
||||||
|
throwCallback("onTargetInFiringRange");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else getGoal()->mInFiringRange = false;
|
||||||
|
}
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
#endif // TORQUE_NAVIGATION_ENABLED
|
||||||
|
}
|
||||||
// Orient towards the aim point, aim object, or towards
|
// Orient towards the aim point, aim object, or towards
|
||||||
// our destination.
|
// our destination.
|
||||||
if (getAim() || mMovement.mMoveState != ModeStop)
|
if (getAim() || mMovement.mMoveState != ModeStop)
|
||||||
|
|
@ -486,19 +515,20 @@ void AIControllerData::resolveStuck(AIController* obj)
|
||||||
AIControllerData::AIControllerData()
|
AIControllerData::AIControllerData()
|
||||||
{
|
{
|
||||||
mMoveTolerance = 0.25f;
|
mMoveTolerance = 0.25f;
|
||||||
mFollowTolerance = 1.0f;
|
|
||||||
mAttackRadius = 2.0f;
|
mAttackRadius = 2.0f;
|
||||||
mMoveStuckTolerance = 0.01f;
|
mMoveStuckTolerance = 0.01f;
|
||||||
mMoveStuckTestDelay = 30;
|
mMoveStuckTestDelay = 30;
|
||||||
mLinkTypes = LinkData(AllFlags);
|
|
||||||
mNavSize = AINavigation::Regular;
|
|
||||||
mHeightTolerance = 0.001f;
|
mHeightTolerance = 0.001f;
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
mFollowTolerance = 1.0f;
|
||||||
|
mLinkTypes = LinkData(AllFlags);
|
||||||
|
mNavSize = AINavigation::Regular;
|
||||||
mFlocking.mChance = 90;
|
mFlocking.mChance = 90;
|
||||||
mFlocking.mMin = 1.0f;
|
mFlocking.mMin = 1.0f;
|
||||||
mFlocking.mMax = 3.0f;
|
mFlocking.mMax = 3.0f;
|
||||||
mFlocking.mSideStep = 0.01f;
|
mFlocking.mSideStep = 0.01f;
|
||||||
|
#endif
|
||||||
resolveYawPtr.bind(this, &AIControllerData::resolveYaw);
|
resolveYawPtr.bind(this, &AIControllerData::resolveYaw);
|
||||||
resolvePitchPtr.bind(this, &AIControllerData::resolvePitch);
|
resolvePitchPtr.bind(this, &AIControllerData::resolvePitch);
|
||||||
resolveRollPtr.bind(this, &AIControllerData::resolveRoll);
|
resolveRollPtr.bind(this, &AIControllerData::resolveRoll);
|
||||||
|
|
@ -510,18 +540,20 @@ AIControllerData::AIControllerData()
|
||||||
AIControllerData::AIControllerData(const AIControllerData& other, bool temp_clone) : SimDataBlock(other, temp_clone)
|
AIControllerData::AIControllerData(const AIControllerData& other, bool temp_clone) : SimDataBlock(other, temp_clone)
|
||||||
{
|
{
|
||||||
mMoveTolerance = other.mMoveTolerance;
|
mMoveTolerance = other.mMoveTolerance;
|
||||||
mFollowTolerance = other.mFollowTolerance;
|
|
||||||
mAttackRadius = other.mAttackRadius;
|
mAttackRadius = other.mAttackRadius;
|
||||||
mMoveStuckTolerance = other.mMoveStuckTolerance;
|
mMoveStuckTolerance = other.mMoveStuckTolerance;
|
||||||
mMoveStuckTestDelay = other.mMoveStuckTestDelay;
|
mMoveStuckTestDelay = other.mMoveStuckTestDelay;
|
||||||
mLinkTypes = other.mLinkTypes;
|
|
||||||
mNavSize = other.mNavSize;
|
|
||||||
mHeightTolerance = other.mHeightTolerance;
|
mHeightTolerance = other.mHeightTolerance;
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
mFollowTolerance = other.mFollowTolerance;
|
||||||
|
mLinkTypes = other.mLinkTypes;
|
||||||
|
mNavSize = other.mNavSize;
|
||||||
mFlocking.mChance = other.mFlocking.mChance;
|
mFlocking.mChance = other.mFlocking.mChance;
|
||||||
mFlocking.mMin = other.mFlocking.mMin;
|
mFlocking.mMin = other.mFlocking.mMin;
|
||||||
mFlocking.mMax = other.mFlocking.mMax;
|
mFlocking.mMax = other.mFlocking.mMax;
|
||||||
mFlocking.mSideStep = other.mFlocking.mSideStep;
|
mFlocking.mSideStep = other.mFlocking.mSideStep;
|
||||||
|
#endif
|
||||||
|
|
||||||
resolveYawPtr.bind(this, &AIControllerData::resolveYaw);
|
resolveYawPtr.bind(this, &AIControllerData::resolveYaw);
|
||||||
resolvePitchPtr.bind(this, &AIControllerData::resolvePitch);
|
resolvePitchPtr.bind(this, &AIControllerData::resolvePitch);
|
||||||
|
|
@ -543,12 +575,8 @@ void AIControllerData::initPersistFields()
|
||||||
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
||||||
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
||||||
|
|
||||||
addFieldV("followTolerance", TypeRangedF32, Offset(mFollowTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("AttackRadius", TypeRangedF32, Offset(mAttackRadius, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
"@brief Distance from destination before stopping.\n\n"
|
"@brief Distance considered in firing range for callback purposes.");
|
||||||
"When the AIController controlled object is moving to a given destination it will move to within "
|
|
||||||
"this distance of the destination and then stop. By providing this tolerance "
|
|
||||||
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
|
||||||
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
|
||||||
|
|
||||||
addFieldV("moveStuckTolerance", TypeRangedF32, Offset(mMoveStuckTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("moveStuckTolerance", TypeRangedF32, Offset(mMoveStuckTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
"@brief Distance tolerance on stuck check.\n\n"
|
"@brief Distance tolerance on stuck check.\n\n"
|
||||||
|
|
@ -569,10 +597,16 @@ void AIControllerData::initPersistFields()
|
||||||
"before the AIController controlled object starts to check if it is stuck. This delay allows the AIController controlled object "
|
"before the AIController controlled object starts to check if it is stuck. This delay allows the AIController controlled object "
|
||||||
"to accelerate to full speed without its initial slow start being considered as stuck.\n"
|
"to accelerate to full speed without its initial slow start being considered as stuck.\n"
|
||||||
"@note Set to zero to have the stuck test start immediately.\n");
|
"@note Set to zero to have the stuck test start immediately.\n");
|
||||||
|
endGroup("AI");
|
||||||
|
|
||||||
addFieldV("AttackRadius", TypeRangedF32, Offset(mAttackRadius, AIControllerData), &CommonValidators::PositiveFloat,
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
"@brief Distance considered in firing range for callback purposes.");
|
addGroup("Pathfinding");
|
||||||
|
addFieldV("followTolerance", TypeRangedF32, Offset(mFollowTolerance, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
|
"@brief Distance from destination before stopping.\n\n"
|
||||||
|
"When the AIController controlled object is moving to a given destination it will move to within "
|
||||||
|
"this distance of the destination and then stop. By providing this tolerance "
|
||||||
|
"it helps the AIController controlled object from never reaching its destination due to minor obstacles, "
|
||||||
|
"rounding errors on its position calculation, etc. By default it is set to 0.25.\n");
|
||||||
addFieldV("FlockChance", TypeRangedS32, Offset(mFlocking.mChance, AIControllerData), &CommonValidators::S32Percent,
|
addFieldV("FlockChance", TypeRangedS32, Offset(mFlocking.mChance, AIControllerData), &CommonValidators::S32Percent,
|
||||||
"@brief chance of flocking.");
|
"@brief chance of flocking.");
|
||||||
addFieldV("FlockMin", TypeRangedF32, Offset(mFlocking.mMin, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("FlockMin", TypeRangedF32, Offset(mFlocking.mMin, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
|
|
@ -581,10 +615,6 @@ void AIControllerData::initPersistFields()
|
||||||
"@brief max flocking clustering distance.");
|
"@brief max flocking clustering distance.");
|
||||||
addFieldV("FlockSideStep", TypeRangedF32, Offset(mFlocking.mSideStep, AIControllerData), &CommonValidators::PositiveFloat,
|
addFieldV("FlockSideStep", TypeRangedF32, Offset(mFlocking.mSideStep, AIControllerData), &CommonValidators::PositiveFloat,
|
||||||
"@brief Distance from destination before we stop moving out of the way.");
|
"@brief Distance from destination before we stop moving out of the way.");
|
||||||
endGroup("AI");
|
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
addGroup("Pathfinding");
|
|
||||||
|
|
||||||
addField("allowWalk", TypeBool, Offset(mLinkTypes.walk, AIControllerData),
|
addField("allowWalk", TypeBool, Offset(mLinkTypes.walk, AIControllerData),
|
||||||
"Allow the character to walk on dry land.");
|
"Allow the character to walk on dry land.");
|
||||||
|
|
@ -611,19 +641,21 @@ void AIControllerData::packData(BitStream* stream)
|
||||||
{
|
{
|
||||||
Parent::packData(stream);
|
Parent::packData(stream);
|
||||||
stream->write(mMoveTolerance);
|
stream->write(mMoveTolerance);
|
||||||
stream->write(mFollowTolerance);
|
|
||||||
stream->write(mAttackRadius);
|
stream->write(mAttackRadius);
|
||||||
stream->write(mMoveStuckTolerance);
|
stream->write(mMoveStuckTolerance);
|
||||||
stream->write(mMoveStuckTestDelay);
|
stream->write(mMoveStuckTestDelay);
|
||||||
|
stream->write(mHeightTolerance);
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
stream->write(mFollowTolerance);
|
||||||
//enums
|
//enums
|
||||||
stream->write(mLinkTypes.getFlags());
|
stream->write(mLinkTypes.getFlags());
|
||||||
stream->write((U32)mNavSize);
|
stream->write((U32)mNavSize);
|
||||||
// end enums
|
// end enums
|
||||||
stream->write(mHeightTolerance);
|
|
||||||
stream->write(mFlocking.mChance);
|
stream->write(mFlocking.mChance);
|
||||||
stream->write(mFlocking.mMin);
|
stream->write(mFlocking.mMin);
|
||||||
stream->write(mFlocking.mMax);
|
stream->write(mFlocking.mMax);
|
||||||
stream->write(mFlocking.mSideStep);
|
stream->write(mFlocking.mSideStep);
|
||||||
|
#endif // TORQUE_NAVIGATION_ENABLED
|
||||||
};
|
};
|
||||||
|
|
||||||
void AIControllerData::unpackData(BitStream* stream)
|
void AIControllerData::unpackData(BitStream* stream)
|
||||||
|
|
@ -631,10 +663,13 @@ void AIControllerData::unpackData(BitStream* stream)
|
||||||
Parent::unpackData(stream);
|
Parent::unpackData(stream);
|
||||||
|
|
||||||
stream->read(&mMoveTolerance);
|
stream->read(&mMoveTolerance);
|
||||||
stream->read(&mFollowTolerance);
|
|
||||||
stream->read(&mAttackRadius);
|
stream->read(&mAttackRadius);
|
||||||
stream->read(&mMoveStuckTolerance);
|
stream->read(&mMoveStuckTolerance);
|
||||||
stream->read(&mMoveStuckTestDelay);
|
stream->read(&mMoveStuckTestDelay);
|
||||||
|
stream->read(&mHeightTolerance);
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
stream->read(&mFollowTolerance);
|
||||||
//enums
|
//enums
|
||||||
U16 linkFlags;
|
U16 linkFlags;
|
||||||
stream->read(&linkFlags);
|
stream->read(&linkFlags);
|
||||||
|
|
@ -643,11 +678,11 @@ void AIControllerData::unpackData(BitStream* stream)
|
||||||
stream->read(&navSize);
|
stream->read(&navSize);
|
||||||
mNavSize = (AINavigation::NavSize)(navSize);
|
mNavSize = (AINavigation::NavSize)(navSize);
|
||||||
// end enums
|
// end enums
|
||||||
stream->read(&mHeightTolerance);
|
|
||||||
stream->read(&(mFlocking.mChance));
|
stream->read(&(mFlocking.mChance));
|
||||||
stream->read(&(mFlocking.mMin));
|
stream->read(&(mFlocking.mMin));
|
||||||
stream->read(&(mFlocking.mMax));
|
stream->read(&(mFlocking.mMax));
|
||||||
stream->read(&(mFlocking.mSideStep));
|
stream->read(&(mFlocking.mSideStep));
|
||||||
|
#endif // TORQUE_NAVIGATION_ENABLED
|
||||||
};
|
};
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -875,4 +910,3 @@ void AIFlyingVehicleControllerData::resolveSpeed(AIController* obj, Point3F loca
|
||||||
movePtr->x = 0;
|
movePtr->x = 0;
|
||||||
movePtr->y = obj->mMovement.mMoveSpeed;
|
movePtr->y = obj->mMovement.mMoveSpeed;
|
||||||
}
|
}
|
||||||
#endif //_AICONTROLLER_H_
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
#ifndef _AICONTROLLER_H_
|
#ifndef _AICONTROLLER_H_
|
||||||
#define _AICONTROLLER_H_
|
#define _AICONTROLLER_H_
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
#include "navigation/coverPoint.h"
|
#include "navigation/coverPoint.h"
|
||||||
#include "AIInfo.h"
|
#include "AIInfo.h"
|
||||||
#include "AIGoal.h"
|
#include "AIGoal.h"
|
||||||
|
|
@ -154,11 +153,12 @@ public:
|
||||||
DECLARE_CONOBJECT(AIControllerData);
|
DECLARE_CONOBJECT(AIControllerData);
|
||||||
|
|
||||||
F32 mMoveTolerance; // Distance from destination point before we stop
|
F32 mMoveTolerance; // Distance from destination point before we stop
|
||||||
F32 mFollowTolerance; // Distance from destination object before we stop
|
|
||||||
F32 mAttackRadius; // Distance to trigger weaponry calcs
|
F32 mAttackRadius; // Distance to trigger weaponry calcs
|
||||||
F32 mMoveStuckTolerance; // Distance tolerance on stuck check
|
|
||||||
S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck
|
S32 mMoveStuckTestDelay; // The number of ticks to wait before checking if the AI is stuck
|
||||||
|
F32 mMoveStuckTolerance; // Distance tolerance on stuck check
|
||||||
F32 mHeightTolerance; // how high above the navmesh are we before we stop trying to repath
|
F32 mHeightTolerance; // how high above the navmesh are we before we stop trying to repath
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
F32 mFollowTolerance; // Distance from destination object before we stop
|
||||||
struct Flocking {
|
struct Flocking {
|
||||||
U32 mChance; // chance of flocking
|
U32 mChance; // chance of flocking
|
||||||
F32 mMin; // min flocking separation distance
|
F32 mMin; // min flocking separation distance
|
||||||
|
|
@ -169,6 +169,7 @@ public:
|
||||||
/// Types of link we can use.
|
/// Types of link we can use.
|
||||||
LinkData mLinkTypes;
|
LinkData mLinkTypes;
|
||||||
AINavigation::NavSize mNavSize;
|
AINavigation::NavSize mNavSize;
|
||||||
|
#endif
|
||||||
Delegate<void(AIController* obj, Point3F location, Move* movePtr)> resolveYawPtr;
|
Delegate<void(AIController* obj, Point3F location, Move* movePtr)> resolveYawPtr;
|
||||||
void resolveYaw(AIController* obj, Point3F location, Move* movePtr);
|
void resolveYaw(AIController* obj, Point3F location, Move* movePtr);
|
||||||
|
|
||||||
|
|
@ -243,5 +244,4 @@ public:
|
||||||
|
|
||||||
DECLARE_CONOBJECT(AIFlyingVehicleControllerData);
|
DECLARE_CONOBJECT(AIFlyingVehicleControllerData);
|
||||||
};
|
};
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
#endif //_AICONTROLLER_H_
|
#endif //_AICONTROLLER_H_
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,10 @@ static U32 sAILoSMask = TerrainObjectType | StaticShapeObjectType | StaticObject
|
||||||
AINavigation::AINavigation(AIController* controller)
|
AINavigation::AINavigation(AIController* controller)
|
||||||
{
|
{
|
||||||
mControllerRef = controller;
|
mControllerRef = controller;
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
mJump = None;
|
mJump = None;
|
||||||
mNavSize = Regular;
|
mNavSize = Regular;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
AINavigation::~AINavigation()
|
AINavigation::~AINavigation()
|
||||||
|
|
@ -40,6 +42,175 @@ AINavigation::~AINavigation()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AINavigation::setMoveDestination(const Point3F& location, bool slowdown)
|
||||||
|
{
|
||||||
|
mMoveDestination = location;
|
||||||
|
getCtrl()->mMovement.mMoveState = AIController::ModeMove;
|
||||||
|
getCtrl()->mMovement.mMoveSlowdown = slowdown;
|
||||||
|
getCtrl()->mMovement.mMoveStuckTestCountdown = getCtrl()->mControllerData->mMoveStuckTestDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AINavigation::setPathDestination(const Point3F& pos, bool replace)
|
||||||
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
if (replace)
|
||||||
|
getCtrl()->setGoal(pos, getCtrl()->mControllerData->mMoveTolerance);
|
||||||
|
|
||||||
|
if (!mNavMesh)
|
||||||
|
updateNavMesh();
|
||||||
|
|
||||||
|
// If we can't find a mesh, just move regularly.
|
||||||
|
if (!mNavMesh)
|
||||||
|
{
|
||||||
|
//setMoveDestination(pos);
|
||||||
|
getCtrl()->throwCallback("onPathFailed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new path.
|
||||||
|
NavPath* path = new NavPath();
|
||||||
|
|
||||||
|
path->mMesh = mNavMesh;
|
||||||
|
path->mFrom = getCtrl()->getAIInfo()->getPosition(true);
|
||||||
|
path->mTo = getCtrl()->getGoal()->getPosition(true);
|
||||||
|
path->mFromSet = path->mToSet = true;
|
||||||
|
path->mAlwaysRender = true;
|
||||||
|
path->mLinkTypes = getCtrl()->mControllerData->mLinkTypes;
|
||||||
|
path->mXray = true;
|
||||||
|
// Paths plan automatically upon being registered.
|
||||||
|
if (!path->registerObject())
|
||||||
|
{
|
||||||
|
delete path;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (path->success())
|
||||||
|
{
|
||||||
|
// Clear any current path we might have.
|
||||||
|
clearPath();
|
||||||
|
getCtrl()->clearCover();
|
||||||
|
// Store new path.
|
||||||
|
mPathData.path = path;
|
||||||
|
mPathData.owned = true;
|
||||||
|
// Skip node 0, which we are currently standing on.
|
||||||
|
moveToNode(1);
|
||||||
|
getCtrl()->throwCallback("onPathSuccess");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Just move normally if we can't path.
|
||||||
|
//setMoveDestination(pos, true);
|
||||||
|
//return;
|
||||||
|
getCtrl()->throwCallback("onPathFailed");
|
||||||
|
path->deleteObject();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
setMoveDestination(pos, false);
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
Point3F AINavigation::getPathDestination() const
|
||||||
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
if (!mPathData.path.isNull())
|
||||||
|
return mPathData.path->mTo;
|
||||||
|
return Point3F(0, 0, 0);
|
||||||
|
#else
|
||||||
|
return getMoveDestination();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void AINavigation::onReachDestination()
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
|
if (!getPath().isNull())
|
||||||
|
{
|
||||||
|
if (mPathData.index == getPath()->size() - 1)
|
||||||
|
{
|
||||||
|
// Handle looping paths.
|
||||||
|
if (getPath()->mIsLooping)
|
||||||
|
moveToNode(0);
|
||||||
|
// Otherwise end path.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
clearPath();
|
||||||
|
getCtrl()->throwCallback("onReachDestination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
moveToNode(mPathData.index + 1);
|
||||||
|
// Throw callback every time if we're on a looping path.
|
||||||
|
//if(mPathData.path->mIsLooping)
|
||||||
|
//throwCallback("onReachDestination");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
getCtrl()->throwCallback("onReachDestination");
|
||||||
|
getCtrl()->mMovement.mMoveState = AIController::ModeStop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(AIController, setMoveDestination, void, (Point3F goal, bool slowDown), (true),
|
||||||
|
"@brief Tells the AI to move to the location provided\n\n"
|
||||||
|
|
||||||
|
"@param goal Coordinates in world space representing location to move to.\n"
|
||||||
|
"@param slowDown A boolean value. If set to true, the bot will slow down "
|
||||||
|
"when it gets within 5-meters of its move destination. If false, the bot "
|
||||||
|
"will stop abruptly when it reaches the move destination. By default, this is true.\n\n"
|
||||||
|
|
||||||
|
"@note Upon reaching a move destination, the bot will clear its move destination and "
|
||||||
|
"calls to getMoveDestination will return \"0 0 0\"."
|
||||||
|
|
||||||
|
"@see getMoveDestination()\n")
|
||||||
|
{
|
||||||
|
object->getNav()->setMoveDestination(goal, slowDown);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DefineEngineMethod(AIController, getMoveDestination, Point3F, (), ,
|
||||||
|
"@brief Get the AIPlayer's current destination.\n\n"
|
||||||
|
|
||||||
|
"@return Returns a point containing the \"x y z\" position "
|
||||||
|
"of the AIPlayer's current move destination. If no move destination "
|
||||||
|
"has yet been set, this returns \"0 0 0\"."
|
||||||
|
|
||||||
|
"@see setMoveDestination()\n")
|
||||||
|
{
|
||||||
|
return object->getNav()->getMoveDestination();
|
||||||
|
}
|
||||||
|
|
||||||
|
DefineEngineMethod(AIController, setPathDestination, bool, (Point3F goal), ,
|
||||||
|
"@brief Tells the AI to find a path to the location provided\n\n"
|
||||||
|
|
||||||
|
"@param goal Coordinates in world space representing location to move to.\n"
|
||||||
|
"@return True if a path was found.\n\n"
|
||||||
|
|
||||||
|
"@see getPathDestination()\n"
|
||||||
|
"@see setMoveDestination()\n")
|
||||||
|
{
|
||||||
|
return object->getNav()->setPathDestination(goal, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
DefineEngineMethod(AIController, getPathDestination, Point3F, (), ,
|
||||||
|
"@brief Get the AIPlayer's current pathfinding destination.\n\n"
|
||||||
|
|
||||||
|
"@return Returns a point containing the \"x y z\" position "
|
||||||
|
"of the AIPlayer's current path destination. If no path destination "
|
||||||
|
"has yet been set, this returns \"0 0 0\"."
|
||||||
|
|
||||||
|
"@see setPathDestination()\n")
|
||||||
|
{
|
||||||
|
return object->getNav()->getPathDestination();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
NavMesh* AINavigation::findNavMesh() const
|
NavMesh* AINavigation::findNavMesh() const
|
||||||
{
|
{
|
||||||
GameBase* gbo = dynamic_cast<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());
|
GameBase* gbo = dynamic_cast<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());
|
||||||
|
|
@ -144,113 +315,6 @@ void AINavigation::repath()
|
||||||
moveToNode(1);
|
moveToNode(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Point3F AINavigation::getPathDestination() const
|
|
||||||
{
|
|
||||||
if (!mPathData.path.isNull())
|
|
||||||
return mPathData.path->mTo;
|
|
||||||
return Point3F(0, 0, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::setMoveDestination(const Point3F& location, bool slowdown)
|
|
||||||
{
|
|
||||||
mMoveDestination = location;
|
|
||||||
getCtrl()->mMovement.mMoveState = AIController::ModeMove;
|
|
||||||
getCtrl()->mMovement.mMoveSlowdown = slowdown;
|
|
||||||
getCtrl()->mMovement.mMoveStuckTestCountdown = getCtrl()->mControllerData->mMoveStuckTestDelay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::onReachDestination()
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
if (!getPath().isNull())
|
|
||||||
{
|
|
||||||
if (mPathData.index == getPath()->size() - 1)
|
|
||||||
{
|
|
||||||
// Handle looping paths.
|
|
||||||
if (getPath()->mIsLooping)
|
|
||||||
moveToNode(0);
|
|
||||||
// Otherwise end path.
|
|
||||||
else
|
|
||||||
{
|
|
||||||
clearPath();
|
|
||||||
getCtrl()->throwCallback("onReachDestination");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
moveToNode(mPathData.index + 1);
|
|
||||||
// Throw callback every time if we're on a looping path.
|
|
||||||
//if(mPathData.path->mIsLooping)
|
|
||||||
//throwCallback("onReachDestination");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
getCtrl()->throwCallback("onReachDestination");
|
|
||||||
getCtrl()->mMovement.mMoveState = AIController::ModeStop;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AINavigation::setPathDestination(const Point3F& pos, bool replace)
|
|
||||||
{
|
|
||||||
if (replace)
|
|
||||||
getCtrl()->setGoal(pos, getCtrl()->mControllerData->mMoveTolerance);
|
|
||||||
|
|
||||||
if (!mNavMesh)
|
|
||||||
updateNavMesh();
|
|
||||||
|
|
||||||
// If we can't find a mesh, just move regularly.
|
|
||||||
if (!mNavMesh)
|
|
||||||
{
|
|
||||||
//setMoveDestination(pos);
|
|
||||||
getCtrl()->throwCallback("onPathFailed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new path.
|
|
||||||
NavPath* path = new NavPath();
|
|
||||||
|
|
||||||
path->mMesh = mNavMesh;
|
|
||||||
path->mFrom = getCtrl()->getAIInfo()->getPosition(true);
|
|
||||||
path->mTo = getCtrl()->getGoal()->getPosition(true);
|
|
||||||
path->mFromSet = path->mToSet = true;
|
|
||||||
path->mAlwaysRender = true;
|
|
||||||
path->mLinkTypes = getCtrl()->mControllerData->mLinkTypes;
|
|
||||||
path->mXray = true;
|
|
||||||
// Paths plan automatically upon being registered.
|
|
||||||
if (!path->registerObject())
|
|
||||||
{
|
|
||||||
delete path;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path->success())
|
|
||||||
{
|
|
||||||
// Clear any current path we might have.
|
|
||||||
clearPath();
|
|
||||||
getCtrl()->clearCover();
|
|
||||||
// Store new path.
|
|
||||||
mPathData.path = path;
|
|
||||||
mPathData.owned = true;
|
|
||||||
// Skip node 0, which we are currently standing on.
|
|
||||||
moveToNode(1);
|
|
||||||
getCtrl()->throwCallback("onPathSuccess");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Just move normally if we can't path.
|
|
||||||
//setMoveDestination(pos, true);
|
|
||||||
//return;
|
|
||||||
getCtrl()->throwCallback("onPathFailed");
|
|
||||||
path->deleteObject();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AINavigation::followObject()
|
void AINavigation::followObject()
|
||||||
{
|
{
|
||||||
if (getCtrl()->getGoal()->getDist() < getCtrl()->mControllerData->mMoveTolerance)
|
if (getCtrl()->getGoal()->getDist() < getCtrl()->mControllerData->mMoveTolerance)
|
||||||
|
|
@ -422,59 +486,6 @@ bool AINavigation::flock()
|
||||||
return flocking;
|
return flocking;
|
||||||
}
|
}
|
||||||
|
|
||||||
DefineEngineMethod(AIController, setMoveDestination, void, (Point3F goal, bool slowDown), (true),
|
|
||||||
"@brief Tells the AI to move to the location provided\n\n"
|
|
||||||
|
|
||||||
"@param goal Coordinates in world space representing location to move to.\n"
|
|
||||||
"@param slowDown A boolean value. If set to true, the bot will slow down "
|
|
||||||
"when it gets within 5-meters of its move destination. If false, the bot "
|
|
||||||
"will stop abruptly when it reaches the move destination. By default, this is true.\n\n"
|
|
||||||
|
|
||||||
"@note Upon reaching a move destination, the bot will clear its move destination and "
|
|
||||||
"calls to getMoveDestination will return \"0 0 0\"."
|
|
||||||
|
|
||||||
"@see getMoveDestination()\n")
|
|
||||||
{
|
|
||||||
object->getNav()->setMoveDestination(goal, slowDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DefineEngineMethod(AIController, getMoveDestination, Point3F, (), ,
|
|
||||||
"@brief Get the AIPlayer's current destination.\n\n"
|
|
||||||
|
|
||||||
"@return Returns a point containing the \"x y z\" position "
|
|
||||||
"of the AIPlayer's current move destination. If no move destination "
|
|
||||||
"has yet been set, this returns \"0 0 0\"."
|
|
||||||
|
|
||||||
"@see setMoveDestination()\n")
|
|
||||||
{
|
|
||||||
return object->getNav()->getMoveDestination();
|
|
||||||
}
|
|
||||||
|
|
||||||
DefineEngineMethod(AIController, setPathDestination, bool, (Point3F goal), ,
|
|
||||||
"@brief Tells the AI to find a path to the location provided\n\n"
|
|
||||||
|
|
||||||
"@param goal Coordinates in world space representing location to move to.\n"
|
|
||||||
"@return True if a path was found.\n\n"
|
|
||||||
|
|
||||||
"@see getPathDestination()\n"
|
|
||||||
"@see setMoveDestination()\n")
|
|
||||||
{
|
|
||||||
return object->getNav()->setPathDestination(goal,true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
DefineEngineMethod(AIController, getPathDestination, Point3F, (), ,
|
|
||||||
"@brief Get the AIPlayer's current pathfinding destination.\n\n"
|
|
||||||
|
|
||||||
"@return Returns a point containing the \"x y z\" position "
|
|
||||||
"of the AIPlayer's current path destination. If no path destination "
|
|
||||||
"has yet been set, this returns \"0 0 0\"."
|
|
||||||
|
|
||||||
"@see setPathDestination()\n")
|
|
||||||
{
|
|
||||||
return object->getNav()->getPathDestination();
|
|
||||||
}
|
|
||||||
|
|
||||||
DefineEngineMethod(AIController, followNavPath, void, (SimObjectId obj), ,
|
DefineEngineMethod(AIController, followNavPath, void, (SimObjectId obj), ,
|
||||||
"@brief Tell the AIPlayer to follow a path.\n\n"
|
"@brief Tell the AIPlayer to follow a path.\n\n"
|
||||||
|
|
@ -555,3 +566,4 @@ DefineEngineMethod(AIController, getNavSize, const char*, (), ,
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,15 @@ struct AINavigation
|
||||||
AINavigation() = delete;
|
AINavigation() = delete;
|
||||||
AINavigation(AIController* controller);
|
AINavigation(AIController* controller);
|
||||||
~AINavigation();
|
~AINavigation();
|
||||||
|
Point3F mMoveDestination;
|
||||||
|
void setMoveDestination(const Point3F& location, bool slowdown);
|
||||||
|
Point3F getMoveDestination() const { return mMoveDestination; };
|
||||||
|
bool setPathDestination(const Point3F& pos, bool replace = false);
|
||||||
|
Point3F getPathDestination() const;
|
||||||
|
|
||||||
|
void onReachDestination();
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
/// Stores information about a path.
|
/// Stores information about a path.
|
||||||
struct PathData {
|
struct PathData {
|
||||||
/// Pointer to path object.
|
/// Pointer to path object.
|
||||||
|
|
@ -67,12 +76,6 @@ struct AINavigation
|
||||||
void setNavSize(NavSize size) { mNavSize = size; updateNavMesh(); }
|
void setNavSize(NavSize size) { mNavSize = size; updateNavMesh(); }
|
||||||
NavSize getNavSize() const { return mNavSize; }
|
NavSize getNavSize() const { return mNavSize; }
|
||||||
|
|
||||||
Point3F mMoveDestination;
|
|
||||||
void setMoveDestination(const Point3F& location, bool slowdown);
|
|
||||||
Point3F getMoveDestination() { return mMoveDestination; };
|
|
||||||
|
|
||||||
void onReachDestination();
|
|
||||||
|
|
||||||
/// NavMesh we pathfind on.
|
/// NavMesh we pathfind on.
|
||||||
SimObjectPtr<NavMesh> mNavMesh;
|
SimObjectPtr<NavMesh> mNavMesh;
|
||||||
NavMesh* findNavMesh() const;
|
NavMesh* findNavMesh() const;
|
||||||
|
|
@ -83,8 +86,6 @@ struct AINavigation
|
||||||
|
|
||||||
/// Clear out the current path.
|
/// Clear out the current path.
|
||||||
void clearPath();
|
void clearPath();
|
||||||
bool setPathDestination(const Point3F& pos, bool replace = false);
|
|
||||||
Point3F getPathDestination() const;
|
|
||||||
void repath();
|
void repath();
|
||||||
|
|
||||||
/// Get the current path we're following.
|
/// Get the current path we're following.
|
||||||
|
|
@ -96,8 +97,8 @@ struct AINavigation
|
||||||
void clearFollow();
|
void clearFollow();
|
||||||
/// Move to the specified node in the current path.
|
/// Move to the specified node in the current path.
|
||||||
void moveToNode(S32 node);
|
void moveToNode(S32 node);
|
||||||
|
|
||||||
bool flock();
|
bool flock();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue