Пример #1
0
//--------------------------------------------------------------
// Name:        Evaluate()
// Class:       GeneralCombatWithRangedWeapon
//
// Description: Evaluates the behavior
//
// Parameters:  Actor &self -- The actor executing this behavior
//
// Returns:     BehaviorReturnCode_t 
//--------------------------------------------------------------
BehaviorReturnCode_t GeneralCombatWithRangedWeapon::Evaluate( Actor &self )
{
	BehaviorReturnCode_t stateResult;
	str	currentPostureState = _self->postureController->getCurrentPostureName();	
	float distToEnemy = self.enemyManager->GetDistanceFromEnemy();

	think();
	switch ( _state )	
	{	
	//---------------------------------------------------------------------		
	case GC_WRW_CHANGE_POSTURE_TO_ADVANCE:
	//---------------------------------------------------------------------		
		stateResult = evaluateStateChangePostureToAdvance();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_ADVANCE );		
	break;

	//---------------------------------------------------------------------		
	case GC_WRW_CHANGE_POSTURE_TO_RETREAT:
	//---------------------------------------------------------------------		
		stateResult = evaluateStateChangePostureToRetreat();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_RETREAT );
	break;

	//---------------------------------------------------------------------		
	case GC_WRW_ADVANCE:
	//---------------------------------------------------------------------
		if ( !checkShouldApproach( distToEnemy ) )
			{
			transitionToState( GC_WRW_STAND );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateStateAdvance();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_STAND );						

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_ADVANCE_FIRING );

	break;

	//---------------------------------------------------------------------
	case GC_WRW_ADVANCE_FIRING:
	//---------------------------------------------------------------------
		if ( !checkShouldApproach( distToEnemy ) )
			{
			transitionToState( GC_WRW_STAND );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateStateAdvanceFiring();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_STAND );	

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_ADVANCE );
	break;

	//---------------------------------------------------------------------
	case GC_WRW_RETREAT:
	//---------------------------------------------------------------------
		if ( !checkShouldRetreat( distToEnemy ) )
			{
			transitionToState( GC_WRW_STAND );
			_self->movementSubsystem->setMovingBackwards( false );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateStateRetreat();
		if ( stateResult == BEHAVIOR_FAILED )
			{
			transitionToState( GC_WRW_STAND );
			_self->movementSubsystem->setMovingBackwards( false );
			}

		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_self->movementSubsystem->setMovingBackwards( false );
			transitionToState( GC_WRW_RETREAT_FIRING );			
			}

	break;

	//---------------------------------------------------------------------
	case GC_WRW_RETREAT_FIRING:
	//---------------------------------------------------------------------
		if ( !checkShouldRetreat( distToEnemy ) )
			{
			_self->movementSubsystem->setMovingBackwards( false );
			transitionToState( GC_WRW_STAND );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateStateRetreatFiring();
		if ( stateResult == BEHAVIOR_FAILED )
			{
			transitionToState( GC_WRW_STAND );
			_self->movementSubsystem->setMovingBackwards( false );
			}

		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_self->movementSubsystem->setMovingBackwards( false );
			transitionToState( GC_WRW_RETREAT );
			}
	break;

	//---------------------------------------------------------------------
	case GC_WRW_STRAFE:
	//---------------------------------------------------------------------
		stateResult = evaluateStateStrafe();

		//It's perfectly understandable that strafe might
		//fail, so instead of failing the behavior entirely
		//we'll just change states
		if ( stateResult != BEHAVIOR_EVALUATING )
			{
			if ( currentPostureState == "DUCK" )
				transitionToState( GC_WRW_DUCKED );

			if ( currentPostureState == "STAND" )
				transitionToState( GC_WRW_STAND );
			}		

	break;

	//---------------------------------------------------------------------
	case GC_WRW_CHANGE_POSTURE_DUCK:
	//---------------------------------------------------------------------
		stateResult = evaluateStateChangePostureDuck();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_DUCKED );
	break;

	//---------------------------------------------------------------------
	case GC_WRW_DUCKED:	
	//---------------------------------------------------------------------	

	//
	// First Check if we are within our _approachDist.  If 
	// not, then we need to close in on our enemy
	//
	if ( checkShouldApproach( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_TO_ADVANCE );
		return BEHAVIOR_EVALUATING;
		}

	//
	// Now Check if wer are within our _retreatDist.  If 
	// we are, then we need to retreat in on our enemy
	//
	if ( checkShouldRetreat( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_TO_RETREAT );
		return BEHAVIOR_EVALUATING;
		}

	//
	// Lets check if we need to strafe
	//
	if ( checkShouldStrafe( distToEnemy ) )
		{
		transitionToState( GC_WRW_STRAFE );
		return BEHAVIOR_EVALUATING;
		}
	

	//
	//Now let's check if we need to change posture
	//
	if ( checkShouldChangePosture( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_STAND );
		return BEHAVIOR_EVALUATING;
		}

	//
	//Well we don't have anything else to do, so let's evaluate our state
	//
	stateResult = evaluateRotate();

	if ( stateResult == BEHAVIOR_SUCCESS )
		{
		stateResult = evaluateStateStand();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_DUCKED_FIRING );

		}

	break;

	//---------------------------------------------------------------------
	case GC_WRW_DUCKED_FIRING:
	//---------------------------------------------------------------------
		stateResult = evaluateRotate();
		stateResult = evaluateStateDuckedFiring();

		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_DUCKED );
	break;

	//---------------------------------------------------------------------
	case GC_WRW_CHANGE_POSTURE_STAND:
	//---------------------------------------------------------------------
		stateResult = evaluateStateChangePostureStand();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_STAND );
	break;

	//---------------------------------------------------------------------
	case GC_WRW_STAND:
	//---------------------------------------------------------------------	

	//
	// First Check if we are within our _approachDist.  If 
	// not, then we need to close in on our enemy
	//
	if ( checkShouldApproach( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_TO_ADVANCE );
		return BEHAVIOR_EVALUATING;
		}

	//
	// Now Check if wer are within our _retreatDist.  If 
	// we are, then we need to retreat in on our enemy
	//
	if ( checkShouldRetreat( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_TO_RETREAT );
		return BEHAVIOR_EVALUATING;
		}

	//
	// Lets check if we need to strafe
	//
	if ( checkShouldStrafe( distToEnemy ) )
		{
		transitionToState( GC_WRW_STRAFE );
		return BEHAVIOR_EVALUATING;
		}
	

	//
	//Now let's check if we need to change posture
	//
	if ( checkShouldChangePosture( distToEnemy ) )
		{
		transitionToState( GC_WRW_CHANGE_POSTURE_DUCK );
		return BEHAVIOR_EVALUATING;
		}

	//
	//Well we don't have anything else to do, so let's evaluate our state
	//
	stateResult = evaluateRotate();

	if ( stateResult == BEHAVIOR_SUCCESS )
		{
		stateResult = evaluateStateStand();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_STAND_FIRING );

		}

	break;

	//---------------------------------------------------------------------
	case GC_WRW_STAND_FIRING:
	//---------------------------------------------------------------------
		stateResult = evaluateRotate();
		stateResult = evaluateStateStandFiring();

		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( GC_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( GC_WRW_STAND );
	break;
	}


	return BEHAVIOR_EVALUATING;   
}
Пример #2
0
//--------------------------------------------------------------
// Name:        Evaluate()
// Class:       CorridorCombatWithRangedWeapon
//
// Description: Evaluates the behavior
//
// Parameters:  Actor &self -- The actor executing this behavior
//
// Returns:     BehaviorReturnCode_t 
//--------------------------------------------------------------
BehaviorReturnCode_t CorridorCombatWithRangedWeapon::Evaluate( Actor & )
{
	BehaviorReturnCode_t stateResult;


	think();

	switch ( _state )
	{
	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_FINDNODE:
	//---------------------------------------------------------------------
		stateResult = evaluateStateFindNode();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_STAND );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_MOVETONODE );
	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_MOVETONODE:
	//---------------------------------------------------------------------
		stateResult = evaluateStateMoveToNode();
	
		if ( stateResult == BEHAVIOR_FAILED )
			{		
			_self->SetAnim( "idle" , NULL , legs );
			transitionToState( CORRIDORCOMBAT_WRW_STAND );			
			}

		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_self->SetAnim( "idle" , NULL , legs );
			stateResult = evaluateRotate();

			if ( stateResult == BEHAVIOR_SUCCESS )
				{
				if ( checkShouldDuck() )
					transitionToState( CORRIDORCOMBAT_WRW_CHANGEPOSTURE_DUCK );
				else
					transitionToState( CORRIDORCOMBAT_WRW_STAND );
				}
			
			}

	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_BACKPEDAL:
	//---------------------------------------------------------------------
		stateResult = evaluateStateBackPedal();

		if ( stateResult == BEHAVIOR_FAILED )
			{
			_self->movementSubsystem->setMovingBackwards( false );
			_self->SetAnim( "idle" , NULL , legs );
			_holdPositionTime = level.time + G_Random(2.0) + 2.0f;

			transitionToState( CORRIDORCOMBAT_WRW_STAND );			
			return BEHAVIOR_EVALUATING;
			}
		
		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_self->movementSubsystem->setMovingBackwards( false );
			_self->SetAnim( "idle" , NULL , legs );
			transitionToState( CORRIDORCOMBAT_WRW_FINDBETTERNODE );			
			}
	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_FINDBETTERNODE:
	//---------------------------------------------------------------------
		stateResult = evaluateStateFindBetterNode();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_STAND );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_MOVETOBETTERNODE );			

	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_MOVETOBETTERNODE:
	//---------------------------------------------------------------------
		stateResult = evaluateStateMoveToBetterNode();		

		if ( stateResult == BEHAVIOR_FAILED )
			{
			_self->SetAnim( "idle" , NULL , legs );
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );			
			}

		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_self->SetAnim( "idle" , NULL , legs );
			stateResult = evaluateRotate();

			if ( stateResult == BEHAVIOR_SUCCESS )
				{
				if ( checkShouldDuck() )
					transitionToState( CORRIDORCOMBAT_WRW_CHANGEPOSTURE_DUCK );
				else
					transitionToState( CORRIDORCOMBAT_WRW_STAND );
				}
			
			}
	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_CHANGEPOSTURE_DUCK:
	//---------------------------------------------------------------------
		stateResult = evaluateStateChangePostureDuck();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_DUCKED );

	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_CHANGEPOSTURE_STAND:
	//---------------------------------------------------------------------
		stateResult = evaluateStateChangePostureStand();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_STAND );

	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_DUCKED:
	//---------------------------------------------------------------------
		if ( checkShouldStand() )	//Make sure we don't need to stand back up
			{
			transitionToState( CORRIDORCOMBAT_WRW_CHANGEPOSTURE_STAND );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateRotate();
		stateResult = evaluateStateDucked();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_DUCKED_FIRING );
	break;

	//----------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_DUCKED_FIRING:
	//----------------------------------------------------------------------
		if ( checkShouldStand() )	//Make sure we don't need to stand back up
			{
			transitionToState( CORRIDORCOMBAT_WRW_CHANGEPOSTURE_STAND );
			_fireWeapon.End(*_self);
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateRotate();
		if ( stateResult != BEHAVIOR_SUCCESS )
			return BEHAVIOR_EVALUATING;


		stateResult = evaluateStateFireDucked();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_DUCKED );

	break;

	//----------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_STAND:
	//----------------------------------------------------------------------
		if ( checkShouldRetreat() )
			{
			transitionToState( CORRIDORCOMBAT_WRW_BACKPEDAL );
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateRotate();
		stateResult = evaluateStateStanding();
		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState( CORRIDORCOMBAT_WRW_STAND_FIRING );
	break;

	//----------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_STAND_FIRING:
	//----------------------------------------------------------------------
		if ( checkShouldRetreat() )
			{
			transitionToState( CORRIDORCOMBAT_WRW_BACKPEDAL );
			_fireWeapon.End(*_self);
			return BEHAVIOR_EVALUATING;
			}

		stateResult = evaluateRotate();
		if ( stateResult != BEHAVIOR_SUCCESS )
			return BEHAVIOR_EVALUATING;

		stateResult = evaluateStateFireStanding();
		if ( stateResult == BEHAVIOR_FAILED )
			{
			_fireWeapon.End(*_self);
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );
			}

		if ( stateResult == BEHAVIOR_SUCCESS )
			{
			_fireWeapon.End(*_self);
			transitionToState( CORRIDORCOMBAT_WRW_STAND );
			}

	break;

	//---------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_HOLD_POSITION:
	//---------------------------------------------------------------------
		stateResult = evaluateStateHoldPosition();

		if ( stateResult == BEHAVIOR_FAILED )
			transitionToState( CORRIDORCOMBAT_WRW_FAILED );

		if ( stateResult == BEHAVIOR_SUCCESS )
			transitionToState(CORRIDORCOMBAT_WRW_FINDBETTERNODE);
	break;

	//----------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_SUCCESS:
	//----------------------------------------------------------------------
		return BEHAVIOR_SUCCESS;

	break;


	//----------------------------------------------------------------------
	case CORRIDORCOMBAT_WRW_FAILED:
	//----------------------------------------------------------------------
		return BEHAVIOR_FAILED;

	break;
	}

	return BEHAVIOR_EVALUATING;   

}