Skip to content
Permalink
Browse files
Moved mMoveSpeed from AIPlayer to Player.
  • Loading branch information
crabmusket committed Oct 22, 2012
1 parent 974e337 commit d2a4c69677440ccaeff67083fb72300213d38d74
Showing with 41 additions and 42 deletions.
  1. +1 −37 Engine/source/T3D/aiPlayer.cpp
  2. +0 −3 Engine/source/T3D/aiPlayer.h
  3. +37 −2 Engine/source/T3D/player.cpp
  4. +3 −0 Engine/source/T3D/player.h
@@ -85,7 +85,6 @@ ConsoleDocClass( AIPlayer,
AIPlayer::AIPlayer()
{
mMoveDestination.set( 0.0f, 0.0f, 0.0f );
mMoveSpeed = 1.0f;
mMoveTolerance = 0.25f;
mMoveStuckTolerance = 0.01f;
mMoveStuckTestDelay = 30;
@@ -150,16 +149,6 @@ bool AIPlayer::onAdd()
return true;
}

/**
* Sets the speed at which this AI moves
*
* @param speed Speed to move, default player was 10
*/
void AIPlayer::setMoveSpeed( F32 speed )
{
mMoveSpeed = getMax(0.0f, getMin( 1.0f, speed ));
}

/**
* Stops movement for this AI
*/
@@ -375,7 +364,7 @@ bool AIPlayer::getAIMove(Move *movePtr)
// to try and stop on the spot...
if (mMoveSlowdown)
{
F32 speed = mMoveSpeed;
F32 speed = 1.0f;
F32 dist = mSqrt(xDiff*xDiff + yDiff*yDiff);
F32 maxDist = 5.0f;
if (dist < maxDist)
@@ -387,9 +376,6 @@ bool AIPlayer::getAIMove(Move *movePtr)
}
else
{
movePtr->x *= mMoveSpeed;
movePtr->y *= mMoveSpeed;

mMoveState = ModeMove;
}

@@ -482,28 +468,6 @@ DefineEngineMethod( AIPlayer, clearAim, void, ( ),,
object->clearAim();
}

DefineEngineMethod( AIPlayer, setMoveSpeed, void, ( F32 speed ),,
"@brief Sets the move speed for an AI object.\n\n"

"@param speed A speed multiplier between 0.0 and 1.0. "
"This is multiplied by the AIPlayer's base movement rates (as defined in "
"its PlayerData datablock)\n\n"

"@see getMoveDestination()\n")
{
object->setMoveSpeed(speed);
}

DefineEngineMethod( AIPlayer, getMoveSpeed, F32, ( ),,
"@brief Gets the move speed of an AI object.\n\n"

"@return A speed multiplier between 0.0 and 1.0.\n\n"

"@see setMoveSpeed()\n")
{
return object->getMoveSpeed();
}

DefineEngineMethod( AIPlayer, setMoveDestination, void, ( Point3F goal, bool slowDown ), ( true ),
"@brief Tells the AI to move to the location provided\n\n"

@@ -42,7 +42,6 @@ class AIPlayer : public Player {

private:
MoveState mMoveState;
F32 mMoveSpeed;
F32 mMoveTolerance; // Distance from destination before we stop
Point3F mMoveDestination; // Destination for movement
Point3F mLastLocation; // For stuck check
@@ -82,8 +81,6 @@ class AIPlayer : public Player {
void clearAim();

// Movement sets/gets
void setMoveSpeed( const F32 speed );
F32 getMoveSpeed() const { return mMoveSpeed; }
void setMoveTolerance( const F32 tolerance );
F32 getMoveTolerance() const { return mMoveTolerance; }
void setMoveDestination( const Point3F &location, bool slowdown );
@@ -1644,6 +1644,8 @@ Player::Player()
mShapeFPFlashThread[i] = 0;
mShapeFPSpinThread[i] = 0;
}

mMoveSpeed = 1.0f;
}

Player::~Player()
@@ -2217,6 +2219,17 @@ bool Player::getAIMove(Move* move)
return false;
}

void Player::setMoveSpeed(F32 speed)
{
mMoveSpeed = mClampF(speed, 0.0f, 1.0f);
setMaskBits(MoveMask);
}

F32 Player::getMoveSpeed() const
{
return mMoveSpeed;
}

void Player::setState(ActionState state, U32 recoverTicks)
{
if (state != mState) {
@@ -2626,6 +2639,8 @@ void Player::updateMove(const Move* move)
moveSpeed = 0.0f;
}

moveSpeed *= mMoveSpeed;

// Acceleration due to gravity
VectorF acc(0.0f, 0.0f, mGravity * mGravityMod * TickSec);

@@ -3125,12 +3140,12 @@ bool Player::checkDismountPosition(const MatrixF& oldMat, const MatrixF& mat)

bool Player::canJump()
{
return mAllowJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && !mJumpDelay && mEnergy >= mDataBlock->minJumpEnergy && mJumpSurfaceLastContact < JumpSkipContactsMax && !mSwimming && (mPose != SprintPose || mDataBlock->sprintCanJump);
return mAllowJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && !mJumpDelay && mEnergy >= mDataBlock->minJumpEnergy && mJumpSurfaceLastContact < JumpSkipContactsMax && !mSwimming && (mPose != SprintPose || mDataBlock->sprintCanJump) && mMoveSpeed > 0.0f;
}

bool Player::canJetJump()
{
return mAllowJetJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && mEnergy >= mDataBlock->jetMinJumpEnergy && mDataBlock->jetJumpForce != 0.0f;
return mAllowJetJumping && mState == MoveState && mDamageState == Enabled && !isMounted() && mEnergy >= mDataBlock->jetMinJumpEnergy && mDataBlock->jetJumpForce != 0.0f && mMoveSpeed > 0.0f;
}

bool Player::canSwim()
@@ -5836,6 +5851,8 @@ void Player::writePacketData(GameConnection *connection, BitStream *stream)
if (stream->writeFlag(mJumpDelay > 0))
stream->writeInt(mJumpDelay,PlayerData::JumpDelayBits);

stream->write(mMoveSpeed);

Point3F pos;
getTransform().getColumn(3,&pos);
if (stream->writeFlag(!isMounted())) {
@@ -5887,6 +5904,8 @@ void Player::readPacketData(GameConnection *connection, BitStream *stream)
else
mJumpDelay = 0;

stream->read(&mMoveSpeed);

Point3F pos,rot;
if (stream->readFlag()) {
// Only written if we are not mounted
@@ -5979,6 +5998,8 @@ U32 Player::packUpdate(NetConnection *con, U32 mask, BitStream *stream)
{
stream->writeFlag(mFalling);

stream->write(mMoveSpeed);

stream->writeInt(mState,NumStateBits);
if (stream->writeFlag(mState == RecoverState))
stream->writeInt(mRecoverTicks,PlayerData::RecoverDelayBits);
@@ -6073,6 +6094,8 @@ void Player::unpackUpdate(NetConnection *con, BitStream *stream)
mPredictionCount = sMaxPredictionTicks;
mFalling = stream->readFlag();

stream->read(&mMoveSpeed);

ActionState actionState = (ActionState)stream->readInt(NumStateBits);
if (stream->readFlag()) {
mRecoverTicks = stream->readInt(PlayerData::RecoverDelayBits);
@@ -6522,6 +6545,18 @@ DefineEngineMethod( Player, getNumDeathAnimations, S32, ( ),,
return count;
}

DefineEngineMethod(Player, setMoveSpeed, void, (F32 speed),,
"Sets movement speed.")
{
object->setMoveSpeed(speed);
}

DefineEngineMethod(Player, getMoveSpeed, F32, (),,
"Gets movement speed.")
{
return object->getMoveSpeed();
}

//----------------------------------------------------------------------------
void Player::consoleInit()
{
@@ -559,6 +559,7 @@ class Player: public ShapeBase
TSThread *mShapeFPFlashThread[ShapeBase::MaxMountedImages];
TSThread *mShapeFPSpinThread[ShapeBase::MaxMountedImages];

F32 mMoveSpeed;

public:

@@ -728,6 +729,8 @@ class Player: public ShapeBase
virtual void setMomentum(const Point3F &momentum);
virtual bool displaceObject(const Point3F& displaceVector);
virtual bool getAIMove(Move*);
virtual void setMoveSpeed(F32 speed);
virtual F32 getMoveSpeed() const;

bool checkDismountPosition(const MatrixF& oldPos, const MatrixF& newPos); ///< Is it safe to dismount here?

0 comments on commit d2a4c69

Please sign in to comment.