mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 15:44:36 +00:00
Improved style of AIPlayer modifications.
This commit is contained in:
parent
199d98d096
commit
d315b1fa5a
2 changed files with 28 additions and 38 deletions
|
|
@ -104,7 +104,7 @@ AIPlayer::AIPlayer()
|
||||||
mJump = None;
|
mJump = None;
|
||||||
mNavSize = Regular;
|
mNavSize = Regular;
|
||||||
mLinkTypes = LinkData(AllFlags);
|
mLinkTypes = LinkData(AllFlags);
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
#endif
|
||||||
|
|
||||||
mIsAiControlled = true;
|
mIsAiControlled = true;
|
||||||
}
|
}
|
||||||
|
|
@ -145,20 +145,20 @@ void AIPlayer::initPersistFields()
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
addGroup("Pathfinding");
|
addGroup("Pathfinding");
|
||||||
|
|
||||||
addField("allowWalk", TypeBool, Offset(mLinkTypes.walk, AIPlayer),
|
addField("allowWalk", TypeBool, Offset(mLinkTypes.walk, AIPlayer),
|
||||||
"Allow the character to walk on dry land.");
|
"Allow the character to walk on dry land.");
|
||||||
addField("allowJump", TypeBool, Offset(mLinkTypes.jump, AIPlayer),
|
addField("allowJump", TypeBool, Offset(mLinkTypes.jump, AIPlayer),
|
||||||
"Allow the character to use jump links.");
|
"Allow the character to use jump links.");
|
||||||
addField("allowDrop", TypeBool, Offset(mLinkTypes.drop, AIPlayer),
|
addField("allowDrop", TypeBool, Offset(mLinkTypes.drop, AIPlayer),
|
||||||
"Allow the character to use drop links.");
|
"Allow the character to use drop links.");
|
||||||
addField("allowSwim", TypeBool, Offset(mLinkTypes.swim, AIPlayer),
|
addField("allowSwim", TypeBool, Offset(mLinkTypes.swim, AIPlayer),
|
||||||
"Allow the character tomove in water.");
|
"Allow the character tomove in water.");
|
||||||
addField("allowLedge", TypeBool, Offset(mLinkTypes.ledge, AIPlayer),
|
addField("allowLedge", TypeBool, Offset(mLinkTypes.ledge, AIPlayer),
|
||||||
"Allow the character to jump ledges.");
|
"Allow the character to jump ledges.");
|
||||||
addField("allowClimb", TypeBool, Offset(mLinkTypes.climb, AIPlayer),
|
addField("allowClimb", TypeBool, Offset(mLinkTypes.climb, AIPlayer),
|
||||||
"Allow the character to use climb links.");
|
"Allow the character to use climb links.");
|
||||||
addField("allowTeleport", TypeBool, Offset(mLinkTypes.teleport, AIPlayer),
|
addField("allowTeleport", TypeBool, Offset(mLinkTypes.teleport, AIPlayer),
|
||||||
"Allow the character to use teleporters.");
|
"Allow the character to use teleporters.");
|
||||||
|
|
||||||
endGroup("Pathfinding");
|
endGroup("Pathfinding");
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
#endif // TORQUE_NAVIGATION_ENABLED
|
||||||
|
|
@ -179,15 +179,15 @@ bool AIPlayer::onAdd()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
void AIPlayer::onRemove()
|
void AIPlayer::onRemove()
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
clearPath();
|
clearPath();
|
||||||
clearCover();
|
clearCover();
|
||||||
clearFollow();
|
clearFollow();
|
||||||
|
#endif
|
||||||
Parent::onRemove();
|
Parent::onRemove();
|
||||||
}
|
}
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the speed at which this AI moves
|
* Sets the speed at which this AI moves
|
||||||
|
|
@ -209,7 +209,7 @@ void AIPlayer::stopMove()
|
||||||
clearPath();
|
clearPath();
|
||||||
clearCover();
|
clearCover();
|
||||||
clearFollow();
|
clearFollow();
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -408,11 +408,7 @@ bool AIPlayer::getAIMove(Move *movePtr)
|
||||||
if (mFabs(xDiff) < mMoveTolerance && mFabs(yDiff) < mMoveTolerance)
|
if (mFabs(xDiff) < mMoveTolerance && mFabs(yDiff) < mMoveTolerance)
|
||||||
{
|
{
|
||||||
mMoveState = ModeStop;
|
mMoveState = ModeStop;
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
onReachDestination();
|
onReachDestination();
|
||||||
#else
|
|
||||||
throwCallback("onReachDestination");
|
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -481,11 +477,7 @@ bool AIPlayer::getAIMove(Move *movePtr)
|
||||||
if ( mMoveState != ModeSlowing || locationDelta == 0 )
|
if ( mMoveState != ModeSlowing || locationDelta == 0 )
|
||||||
{
|
{
|
||||||
mMoveState = ModeStuck;
|
mMoveState = ModeStuck;
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
onStuck();
|
onStuck();
|
||||||
#else
|
|
||||||
throwCallback("onMoveStuck");
|
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -558,7 +550,6 @@ void AIPlayer::throwCallback( const char *name )
|
||||||
Con::executef(getDataBlock(), name, getIdString());
|
Con::executef(getDataBlock(), name, getIdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
/**
|
/**
|
||||||
* Called when we get within mMoveTolerance of our destination set using
|
* Called when we get within mMoveTolerance of our destination set using
|
||||||
* setMoveDestination(). Only fires the script callback if we are at the end
|
* setMoveDestination(). Only fires the script callback if we are at the end
|
||||||
|
|
@ -566,6 +557,7 @@ void AIPlayer::throwCallback( const char *name )
|
||||||
*/
|
*/
|
||||||
void AIPlayer::onReachDestination()
|
void AIPlayer::onReachDestination()
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
if(!mPathData.path.isNull())
|
if(!mPathData.path.isNull())
|
||||||
{
|
{
|
||||||
if(mPathData.index == mPathData.path->size() - 1)
|
if(mPathData.index == mPathData.path->size() - 1)
|
||||||
|
|
@ -589,6 +581,7 @@ void AIPlayer::onReachDestination()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
throwCallback("onReachDestination");
|
throwCallback("onReachDestination");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -598,12 +591,15 @@ void AIPlayer::onReachDestination()
|
||||||
*/
|
*/
|
||||||
void AIPlayer::onStuck()
|
void AIPlayer::onStuck()
|
||||||
{
|
{
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
if(!mPathData.path.isNull())
|
if(!mPathData.path.isNull())
|
||||||
repath();
|
repath();
|
||||||
else
|
else
|
||||||
|
#endif
|
||||||
throwCallback("onMoveStuck");
|
throwCallback("onMoveStuck");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
// Pathfinding
|
// Pathfinding
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -67,11 +67,6 @@ private:
|
||||||
void throwCallback( const char *name );
|
void throwCallback( const char *name );
|
||||||
|
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
#ifdef TORQUE_NAVIGATION_ENABLED
|
||||||
public:
|
|
||||||
/// Get cover we are moving to.
|
|
||||||
CoverPoint *getCover() { return mCoverData.cover; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
/// Should we jump?
|
/// Should we jump?
|
||||||
enum JumpStates {
|
enum JumpStates {
|
||||||
None, ///< No, don't jump.
|
None, ///< No, don't jump.
|
||||||
|
|
@ -109,9 +104,7 @@ private:
|
||||||
/// Pointer to a cover point.
|
/// Pointer to a cover point.
|
||||||
SimObjectPtr<CoverPoint> cover;
|
SimObjectPtr<CoverPoint> cover;
|
||||||
/// Default constructor.
|
/// Default constructor.
|
||||||
CoverData() : cover(NULL)
|
CoverData() : cover(NULL) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Current cover we're trying to get to.
|
/// Current cover we're trying to get to.
|
||||||
|
|
@ -144,11 +137,11 @@ private:
|
||||||
|
|
||||||
/// 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);
|
||||||
|
#endif // TORQUE_NAVIGATION_ENABLED
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onReachDestination();
|
virtual void onReachDestination();
|
||||||
virtual void onStuck();
|
virtual void onStuck();
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DECLARE_CONOBJECT( AIPlayer );
|
DECLARE_CONOBJECT( AIPlayer );
|
||||||
|
|
@ -159,9 +152,7 @@ public:
|
||||||
static void initPersistFields();
|
static void initPersistFields();
|
||||||
|
|
||||||
bool onAdd();
|
bool onAdd();
|
||||||
#ifdef TORQUE_NAVIGATION_ENABLED
|
|
||||||
void onRemove();
|
void onRemove();
|
||||||
#endif // TORQUE_NAVIGATION_ENABLED
|
|
||||||
|
|
||||||
virtual bool getAIMove( Move *move );
|
virtual bool getAIMove( Move *move );
|
||||||
|
|
||||||
|
|
@ -210,6 +201,9 @@ public:
|
||||||
void updateNavMesh();
|
void updateNavMesh();
|
||||||
NavMesh *getNavMesh() const { return mNavMesh; }
|
NavMesh *getNavMesh() const { return mNavMesh; }
|
||||||
|
|
||||||
|
/// Get cover we are moving to.
|
||||||
|
CoverPoint *getCover() { return mCoverData.cover; }
|
||||||
|
|
||||||
/// Types of link we can use.
|
/// Types of link we can use.
|
||||||
LinkData mLinkTypes;
|
LinkData mLinkTypes;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue