// user fired laser ----------------------------------------------------------- // INLINE void User_FireLaser() { if ( ( FireRepeat > 0 ) || ( FireDisable > 0 ) ) { return; } // create laser OBJ_ShootLaser( MyShip ); if ( ( FireRepeat += MyShip->FireRepeatDelay ) <= 0 ) { FireRepeat = 1; } if ( ( FireDisable += MyShip->FireDisableDelay ) <= 0 ) { FireDisable = 1; } }
// set the currently used goal position --------------------------------------- // void BOT_AI::_GoalCheck_AgentMode_Attack() { //FIXME: push current goal onto goal stack BOT_Goal* pGoal = m_State.GetCurGoal(); ASSERT( pGoal != NULL ); //FIXME: here we should also evaluate whether we pick another target // select a target, if none, or no ship selected as target GenObject* pTargetObject = pGoal->GetTargetObject(); Vector3* pGoalPos = pGoal->GetGoalPosition(); if( ( pTargetObject == NULL ) || ( OBJECT_TYPE_SHIP( pTargetObject) == FALSE ) ){ // let the character select a target pTargetObject = m_Character.SelectAttackTarget( m_pShip ); // no target if ( pTargetObject == NULL ) { //FIXME: transition function m_nAgentMode = AGENTMODE_IDLE; pGoal->SetTargetObject(NULL); #ifdef BOT_LOGFILES BOT_MsgOut( "switching from ATTACK to IDLE" ); #endif // BOT_LOGFILES return; } // set the target object pGoal->SetTargetObject( pTargetObject ); // set the goal position to where the target is FetchTVector( pTargetObject->ObjPosition, pGoalPos ); #ifdef BOT_LOGFILES BOT_MsgOut( "found new ATTACK target %d", pTargetObject->HostObjNumber ); #endif // BOT_LOGFILES } Vector3 TargetPos; FetchTVector( pTargetObject->ObjPosition, &TargetPos ); // get vector to target Vector3 vec2Target; VECSUB( &vec2Target, &TargetPos, &m_AgentPos ); float len = VctLenX( &vec2Target ); #ifdef BOT_LOGFILES BOT_MsgOut( "BOT: distance to target: %f", len ); #endif #define MIN_DISTANCE_TO_TARGET 100.0f if ( len < 500.0F) { if ( FireRepeat > 0 ) { FireRepeat -= CurScreenRefFrames; } if ( ( FireRepeat > 0 ) || ( FireDisable > 0 ) ) { //do nothing! } else { // create laser OBJ_ShootLaser( m_pShip ); if ( ( FireRepeat += MyShip->FireRepeatDelay ) <= 0 ) { FireRepeat = 1; } if ( ( FireDisable += MyShip->FireDisableDelay ) <= 0 ) { FireDisable = 1; } } } if ( len < MIN_DISTANCE_TO_TARGET ) { // if nearby goal, we stay where we are memcpy( pGoalPos, &m_AgentPos, sizeof( Vector3 ) ); } else { // set the goal position to the position of the target ASSERT( pTargetObject != NULL ); FetchTVector( pTargetObject->ObjPosition, pGoalPos ); } #ifdef BOT_LOGFILES BOT_MsgOut( "ATTACK goal is at %f %f %f", pGoalPos->X, pGoalPos->Y, pGoalPos->Z ); #endif // BOT_LOGFILES }