コード例 #1
0
ファイル: agent.cpp プロジェクト: yxrkt/DigiPen
// get vacuum's next move
Action Agent::GetAction( Percept p )
{
  // on home node
  if ( p.home )
  {
    if ( first )
    {
      x = 0;
      y = 0;
      
      room[x][y].type = OPEN;
      room[x][y].dist = 0;
      room[x][y].hits = 1;
      first = false;
      return FORWARD;
    }
    
    if ( retreating ) return SHUTOFF;
  }
  
  // if returning home...
  if ( retreating )
  {
    // orient if not facing right direction
    return OrientAndMoveTo( GetRetreatOrient() );
  }  
  
  // otherwise...
  
  if ( p.bump )
  {
    room[x + GetFaceX()][y + GetFaceY()].type = WALL;
    
    return FindBestNode();
  }
  
  else
  {
    if ( turned || sucked ) return FindBestNode();
    
    // last action was a move; update position and node
    room[x += GetFaceX()][y += GetFaceY()].type = OPEN;
    room[x][y].hits++;
    UpdateDist( x, y );
    
    // clean this potentially new node if dirty
    if ( p.dirt )
    {
      sucked = true;
      score += 20;
      ticker = 0;
      if ( score >= RETREAT_SCORE ) retreating = true;
      return SUCK;
    }
    
    return FindBestNode();
  }
}
コード例 #2
0
ファイル: AIGoalFlee.cpp プロジェクト: Arc0re/lithtech
bool CAIGoalFlee::IsGoalInProgress()
{
	// Initionally skip super::IsGoalInProgress().
	// Allow AI to flee to invalid nodes when necessary.

	if( !CAIGoalUseSmartObject::IsGoalInProgress() )
	{
		return false;
	}

	// Do not check node validity until AI has finished transitioning.

	if( m_pAI->GetAnimationContext()->IsTransitioning() )
	{
		return true;
	}

	if( m_pAI->HasTarget( kTarget_All ) )
	{
		// Node's status is OK from threat.

		uint32 dwNodeStatus = kNodeStatus_Disabled | 
							  kNodeStatus_LockedByOther | 
							  kNodeStatus_ThreatInsideRadius;

		// Leave a damaged node only if there is some other node to goto.

		SAIWORLDSTATE_PROP* pProp = m_pAI->GetAIWorldState()->GetWSProp( kWSK_AtNode, m_pAI->m_hObject );
		if( pProp && 
		   ( pProp->hWSValue == m_hNode ) &&
		   FindBestNode( kNode_Ambush ) )
		{
			dwNodeStatus |= kNodeStatus_Damaged;
		}

		AINodeSmartObject* pNode = (AINodeSmartObject*)g_pLTServer->HandleToObject( m_hNode );
		if( pNode && pNode->IsNodeValid( m_pAI, m_pAI->GetPosition(), m_pAI->GetAIBlackBoard()->GetBBTargetObject(), kThreatPos_TargetPos, dwNodeStatus ) )
		{
			return true;
		}
	}

	// Goal is no longer in progress.

	return false;
}
コード例 #3
0
void CAIGoalUseSmartObject::CalculateGoalRelevance()
{
	// Goal is in progress.

	if( IsGoalInProgress() )
	{
		m_fGoalRelevance = m_pGoalRecord->fIntrinsicRelevance;
		return;
	}

	// Goal is relevant if we know of available nodes.

	m_hNodeBest = FindBestNode( m_pGoalRecord->eNodeType );
	if( m_hNodeBest )
	{
		m_fGoalRelevance = m_pGoalRecord->fIntrinsicRelevance;
		return;
	}

	m_fGoalRelevance = 0.f;
}