AI fixes and additional functionality

This commit is contained in:
ZOD 2016-07-09 14:27:41 -04:00
parent df7ffce665
commit 0fccbc995c
5 changed files with 121 additions and 32 deletions

View file

@ -235,6 +235,13 @@ void AIPlayer::setMoveTolerance( const F32 tolerance )
*/
void AIPlayer::setMoveDestination( const Point3F &location, bool slowdown )
{
//> ZOD: Game Mechanic Kit v1.2.13: aiBot hack to avoid stopping right after beginning of the move
MatrixF eye;
getEyeTransform(&eye);
Point3F pos = eye.getPosition();
mLastLocation = pos;
mLastLocation.z += mMoveTolerance * 2;
//< Game Mechanic Kit: End addition
mMoveDestination = location;
mMoveState = ModeMove;
mMoveSlowdown = slowdown;
@ -245,14 +252,14 @@ void AIPlayer::setMoveDestination( const Point3F &location, bool slowdown )
* Sets the object the bot is targeting
*
* @param targetObject The object to target
*/
void AIPlayer::setAimObject( GameBase *targetObject )
{
mAimObject = targetObject;
mTargetInLOS = false;
mAimOffset = Point3F(0.0f, 0.0f, 0.0f);
}
*/
/**
* Sets the object the bot is targeting and an offset to add to target location
*
@ -271,12 +278,11 @@ void AIPlayer::setAimObject(GameBase *targetObject, const Point3F& offset)
*
* @param location Point to aim at
*/
void AIPlayer::setAimLocation( const Point3F &location )
void AIPlayer::setAimLocation( const Point3F &location, Point3F offset )
{
mAimObject = 0;
mAimLocationSet = true;
mAimLocation = location;
mAimOffset = Point3F(0.0f, 0.0f, 0.0f);
mAimOffset = offset;
}
/**
@ -539,29 +545,44 @@ bool AIPlayer::getAIMove(Move *movePtr)
// Test for target location in sight if it's an object. The LOS is
// run from the eye position to the center of the object's bounding,
// which is not very accurate.
if (mAimObject) {
MatrixF eyeMat;
getEyeTransform(&eyeMat);
eyeMat.getColumn(3,&location);
Point3F targetLoc = mAimObject->getBoxCenter();
// This ray ignores non-static shapes. Cast Ray returns true
// if it hit something.
RayInfo dummy;
if (getContainer()->castRay( location, targetLoc,
StaticShapeObjectType | StaticObjectType |
TerrainObjectType, &dummy)) {
if (mTargetInLOS) {
throwCallback( "onTargetExitLOS" );
mTargetInLOS = false;
}
}
else
if (!mTargetInLOS) {
throwCallback( "onTargetEnterLOS" );
//< ZOD: Use new los function
if (mAimObject)
{
if (checkInLos(mAimObject, true, true))
{
throwCallback( "onTargetEnterLOS" );
if (!mTargetInLOS)
{
mTargetInLOS = true;
}
}
}
else
{
throwCallback( "onTargetExitLOS" );
if (!mTargetInLOS)
{
mTargetInLOS = false;
}
}
}
//> ZOD: End edit
//< ZOD: https://www.garagegames.com/community/resources/view/22501
Pose desiredPose = mPose;
//yorks select for Ai using mAiPose
if ( mSwimming )
desiredPose = SwimPose;
else if ( mAiPose == 1 && canCrouch() )
desiredPose = CrouchPose;
else if ( mAiPose == 2 && canProne() )
desiredPose = PronePose;
else if ( mAiPose == 3 && canSprint() )
desiredPose = SprintPose;
else if ( canStand() )
desiredPose = StandPose;
setPose( desiredPose );
//< ZOD: End addition
// Replicate the trigger state into the move so that
// triggers can be controlled from scripts.
@ -587,10 +608,24 @@ bool AIPlayer::getAIMove(Move *movePtr)
#endif // TORQUE_NAVIGATION_ENABLED
mLastLocation = location;
//< ZOD: Dusty Monk/Michael Bacon · 11/15/2007: http://www.garagegames.com/community/blogs/view/13856
movePtr->clamp(); //Clamp the move for network traffic..
//> Dusty Monk: End
return true;
}
//< ZOD: https://www.garagegames.com/community/resources/view/22501
void AIPlayer::setAiPose( F32 pose )
{
mAiPose = pose;
}
F32 AIPlayer::getAiPose()
{
return mAiPose;
}
//< ZOD: End addition
/**
* Utility function to throw callbacks. Callbacks always occure
* on the datablock class.
@ -1095,6 +1130,12 @@ DefineEngineMethod( AIPlayer, getMoveSpeed, F32, ( ),,
return object->getMoveSpeed();
}
DefineEngineMethod( AIPlayer, setMoveTolerance, void, ( F32 tolerance ),,
"@Sets the movetolerance\n")
{
object->setMoveTolerance(tolerance);
}
DefineEngineMethod( AIPlayer, setMoveDestination, void, ( Point3F goal, bool slowDown ), ( true ),
"@brief Tells the AI to move to the location provided\n\n"
@ -1122,7 +1163,7 @@ DefineEngineMethod( AIPlayer, getMoveDestination, Point3F, (),,
{
return object->getMoveDestination();
}
/*
DefineEngineMethod( AIPlayer, setAimLocation, void, ( Point3F target ),,
"@brief Tells the AIPlayer to aim at the location provided.\n\n"
@ -1132,6 +1173,19 @@ DefineEngineMethod( AIPlayer, setAimLocation, void, ( Point3F target ),,
{
object->setAimLocation(target);
}
*/
ConsoleMethod( AIPlayer, setAimLocation, void, 3, 4, "( Point3F target, [Point3F offset] )"
"Sets the bot's target object. Optionally set an offset from target location."
"@hide")
{
Point3F off( 0.0f, 0.0f, 0.0f );
Point3F target( 0.0f, 0.0f, 0.0f );
if (argc == 4)
dSscanf( argv[3], "%g %g %g", &off.x, &off.y, &off.z );
dSscanf( argv[2], "%g %g %g", &target.x, &target.y, &target.z );
object->setAimLocation(target, off);
}
DefineEngineMethod( AIPlayer, getAimLocation, Point3F, (),,
"@brief Returns the point the AIPlayer is aiming at.\n\n"
@ -1348,3 +1402,21 @@ DefineEngineMethod( AIPlayer, clearMoveTriggers, void, ( ),,
{
object->clearMoveTriggers();
}
//< ZOD: https://www.garagegames.com/community/resources/view/22501
DefineEngineMethod( AIPlayer, setAiPose, void, ( F32 pose ),,
"@brief Sets the AiPose for an AI object.nn"
"@param pose StandPose=0,CrouchPose=1,PronePose=2,SprintPose=3. "
"Uses the new AiPose variable from shapebase (as defined in "
"its PlayerData datablock)nn")
{
object->setAiPose(pose);
}
DefineEngineMethod( AIPlayer, getAiPose, F32, (),,
"@brief Get the object's current AiPose.nn"
"@return StandPose=0,CrouchPose=1,PronePose=2,SprintPose=3n")
{
return object->getAiPose();
}
//< ZOD: End addition

View file

@ -165,7 +165,8 @@ public:
void setAimObject( GameBase *targetObject );
void setAimObject(GameBase *targetObject, const Point3F& offset);
GameBase* getAimObject() const { return mAimObject; }
void setAimLocation( const Point3F &location );
//void setAimLocation( const Point3F &location );
void setAimLocation( const Point3F &location, Point3F offset ); //> ZOD: Edit for offset
Point3F getAimLocation() const { return mAimLocation; }
void clearAim();
bool checkInLos(GameBase* target = NULL, bool _useMuzzle = false, bool _checkEnabled = false);
@ -179,6 +180,10 @@ public:
void setMoveDestination( const Point3F &location, bool slowdown );
Point3F getMoveDestination() const { return mMoveDestination; }
void stopMove();
//< ZOD: https://www.garagegames.com/community/resources/view/22501
void setAiPose( const F32 pose );
F32 getAiPose();
//> ZOD: End addition
// Trigger sets/gets
void setMoveTrigger( U32 slot, const bool isSet = true );

View file

@ -3172,7 +3172,8 @@ void Player::updateMove(const Move* move)
// Update the PlayerPose
Pose desiredPose = mPose;
if (!mIsAiControlled) //< ZOD: https://www.garagegames.com/community/resources/view/22501
{
if ( mSwimming )
desiredPose = SwimPose;
else if ( runSurface && move->trigger[sCrouchTrigger] && canCrouch() )
@ -3183,6 +3184,7 @@ void Player::updateMove(const Move* move)
desiredPose = SprintPose;
else if ( canStand() )
desiredPose = StandPose;
}
setPose( desiredPose );
}
@ -6185,7 +6187,11 @@ U32 Player::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
if (stream->writeFlag(mask & MoveMask))
{
stream->writeFlag(mFalling);
//< ZOD: https://www.garagegames.com/community/resources/view/22501
stream->writeFlag(mSwimming);
stream->writeFlag(mJetting);
stream->writeInt(mPose, NumPoseBits);
//> ZOD: End addition
stream->writeInt(mState,NumStateBits);
if (stream->writeFlag(mState == RecoverState))
stream->writeInt(mRecoverTicks,PlayerData::RecoverDelayBits);
@ -6282,7 +6288,11 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
if (stream->readFlag()) {
mPredictionCount = sMaxPredictionTicks;
mFalling = stream->readFlag();
//< ZOD: https://www.garagegames.com/community/resources/view/22501
mSwimming = stream->readFlag();
mJetting = stream->readFlag();
mPose = (Pose)(stream->readInt(NumPoseBits));
//> ZOD: End addition
ActionState actionState = (ActionState)stream->readInt(NumStateBits);
if (stream->readFlag()) {
mRecoverTicks = stream->readInt(PlayerData::RecoverDelayBits);

View file

@ -916,6 +916,7 @@ ShapeBase::ShapeBase()
mFadeDelay( 0.0f ),
mCameraFov( 90.0f ),
mIsControlled( false ),
mAiPose( 0 ), //< ZOD: https://www.garagegames.com/community/resources/view/22501
mLastRenderFrame( 0 ),
mLastRenderDistance( 0.0f )
{

View file

@ -882,6 +882,7 @@ protected:
F32 mEnergy; ///< Current enery level.
F32 mRechargeRate; ///< Energy recharge rate (in units/tick).
S32 mTeamId; ///< ZOD: Team identification for shape name
F32 mAiPose; ///< ZOD: https://www.garagegames.com/community/resources/view/22501
F32 mMass; ///< Mass.
F32 mOneOverMass; ///< Inverse of mass.
/// @note This is used to optimize certain physics calculations.