AIMotorMoveResult_t CAI_Motor::MoveGroundExecute( const AILocalMoveGoal_t &move, AIMoveTrace_t *pTraceResult ) { // -------------------------------------------- // turn in the direction of movement // -------------------------------------------- MoveFacing( move ); // -------------------------------------------- float flNewSpeed = GetIdealSpeed(); // -------------------------------------------- // calculate actual travel distance // -------------------------------------------- // assuming linear acceleration, how far will I travel? float flTotal = 0.5 * (GetCurSpeed() + flNewSpeed) * GetMoveInterval(); // can I move farther in this interval than I'm supposed to? if ( flTotal > move.maxDist ) { if ( !(move.flags & AILMG_CONSUME_INTERVAL) ) { // only use a portion of the time interval SetMoveInterval( GetMoveInterval() * (1 - move.maxDist / flTotal) ); } else SetMoveInterval( 0 ); flTotal = move.maxDist; } else { // use all the time SetMoveInterval( 0 ); } SetMoveVel( move.dir * flNewSpeed ); // -------------------------------------------- // walk the distance // -------------------------------------------- AIMotorMoveResult_t result = AIM_SUCCESS; if ( flTotal > 0.0 ) { Vector vecFrom = GetLocalOrigin(); Vector vecTo = vecFrom + move.dir * flTotal; result = MoveGroundStep( vecTo, move.pMoveTarget, -1, true, pTraceResult ); if ( result == AIM_FAILED ) MoveStop(); } else if ( !OnMoveStalled( move ) ) { result = AIM_FAILED; } return result; }
AIMotorMoveResult_t CAI_Motor::MoveGroundExecuteWalk( const AILocalMoveGoal_t &move, float speed, float dist, AIMoveTrace_t *pTraceResult ) { bool bReachingLocalGoal = ( dist > move.maxDist ); // can I move farther in this interval than I'm supposed to? if ( bReachingLocalGoal ) { if ( !(move.flags & AILMG_CONSUME_INTERVAL) ) { // only use a portion of the time interval SetMoveInterval( GetMoveInterval() * (1 - move.maxDist / dist) ); } else SetMoveInterval( 0 ); dist = move.maxDist; } else { // use all the time SetMoveInterval( 0 ); } SetMoveVel( move.dir * speed ); // -------------------------------------------- // walk the distance // -------------------------------------------- AIMotorMoveResult_t result = AIM_SUCCESS; if ( dist > 0.0 ) { Vector vecFrom = GetLocalOrigin(); Vector vecTo = vecFrom + move.dir * dist; if ( move.navType == NAV_CRAWL ) { char *pchHackBoolToInt = (char*)(&bReachingLocalGoal); *pchHackBoolToInt = 2; } result = MoveGroundStep( vecTo, move.pMoveTarget, -1, true, bReachingLocalGoal, pTraceResult ); if ( result == AIM_FAILED ) MoveStop(); } else if ( !OnMoveStalled( move ) ) { result = AIM_FAILED; } return result; }