当前位置: 首页>>代码示例>>C++>>正文


C++ CAI::HasTarget方法代码示例

本文整理汇总了C++中CAI::HasTarget方法的典型用法代码示例。如果您正苦于以下问题:C++ CAI::HasTarget方法的具体用法?C++ CAI::HasTarget怎么用?C++ CAI::HasTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CAI的用法示例。


在下文中一共展示了CAI::HasTarget方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ValidatePreconditions

bool CAITargetSelectCharacterSquad::ValidatePreconditions( CAI* pAI )
{
	// Sanity check.

	if( !pAI )
	{
		return false;
	}
	
	// AI is already targeting a character.

	if( pAI->HasTarget( kTarget_Character ) )
	{
		return false;
	}

	// AI is not in a squad.

	ENUM_AI_SQUAD_ID eSquad = g_pAICoordinator->GetSquadID( pAI->m_hObject );
	CAISquad* pSquad = g_pAICoordinator->FindSquad( eSquad );
	if( !pSquad )
	{
		return false;
	}

	// Find a squad member targeting a character.

	CAI* pMember = NULL;
	bool bTargetingCharacter = false;
	uint32 cMembers = pSquad->GetNumSquadMembers();
	LTObjRef* pMembers = pSquad->GetSquadMembers();
	if( pMembers )
	{
		for( uint32 iMember=0; iMember < cMembers; ++iMember )
		{
			pMember = (CAI*)g_pLTServer->HandleToObject( pMembers[iMember] );
			if( pMember && pMember->HasTarget( kTarget_Character ) )
			{
				bTargetingCharacter = true;
				break;
			}
		}
	}

	// Preconditions are met if the squad is targeting someone.

	return bTargetingCharacter;
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:48,代码来源:AITargetSelectCharacterSquad.cpp

示例2: Activate

void CAITargetSelectCharacterSquad::Activate( CAI* pAI )
{
	super::Activate( pAI );

	// Sanity check.

	if( !pAI )
	{
		return;
	}

	// Bail if AI is not in a squad.

	ENUM_AI_SQUAD_ID eSquad = g_pAICoordinator->GetSquadID( pAI->m_hObject );
	CAISquad* pSquad = g_pAICoordinator->FindSquad( eSquad );
	if( !pSquad )
	{
		return;
	}

	// Find a squad member targeting a character.

	CAI* pMember = NULL;
	bool bTargetingCharacter = false;
	uint32 cMembers = pSquad->GetNumSquadMembers();
	LTObjRef* pMembers = pSquad->GetSquadMembers();
	if( pMembers )
	{
		for( uint32 iMember=0; iMember < cMembers; ++iMember )
		{
			pMember = (CAI*)g_pLTServer->HandleToObject( pMembers[iMember] );
			if( pMember && pMember->HasTarget( kTarget_Character ) )
			{
				break;
			}
		}
	}

	// Bail if we failed to find a squad member.

	if( !pMember )
	{
		return;
	}

	// Bail if squad member is not targeting a character.

	if( !pMember->HasTarget( kTarget_Character ) )
	{
		return;
	}
	HOBJECT hTarget = pMember->GetAIBlackBoard()->GetBBTargetObject();

	// Bail if squad member has no memory of the character.

	CAIWMFact factQuery;
	factQuery.SetFactType( kFact_Character );
	factQuery.SetTargetObject( hTarget );
	CAIWMFact* pFact = pMember->GetAIWorkingMemory()->FindWMFact( factQuery );
	if( !pFact )
	{
		return;
	}

	// Create a memory for this character.

	CAIWMFact* pTargetFact;
	pTargetFact = pAI->GetAIWorkingMemory()->CreateWMFact( kFact_Character );
	pTargetFact->SetTargetObject( hTarget, 1.f );

	EnumAIStimulusID eStimulusID;
	EnumAIStimulusType eStimulusType;
	pFact->GetStimulus( &eStimulusType, &eStimulusID );
	pTargetFact->SetStimulus( eStimulusType, eStimulusID, 0.f );
	pTargetFact->SetPos( pFact->GetPos(), 1.f );
	pTargetFact->SetRadius( 0.f, 1.f );

	// Target the character.

	TargetCharacter( pAI, pTargetFact );
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:81,代码来源:AITargetSelectCharacterSquad.cpp

示例3: ActivateGoal

void CAIGoalDrawWeapon::ActivateGoal()
{
	super::ActivateGoal();

	// Bail if no holstered weapon, or already have a weapon armed.

	if( ( !m_pAI->HasHolsterString() ) ||
		( m_pAI->GetPrimaryWeapon() ) )
	{
		m_fCurImportance = 0.f;
		return;
	}

//	ASSERT(m_hStimulusSource != LTNULL);

	// Ignore senses other than see enemy.
	m_pAI->SetCurSenseFlags( kSense_SeeEnemy | kSense_SeeDangerousProjectile | kSense_SeeCatchableProjectile );

	m_pGoalMgr->LockGoal( this );

	// Set Draw state.

	m_pAI->SetState( kState_HumanDraw );

	if( m_pAI->GetAlarmLevel() >= m_pAI->GetBrain()->GetMajorAlarmThreshold() )
	{
		m_pAI->SetAwareness( kAware_Alert );
	}

	// If stimulated by an AI, target whatever he is targeting.

	if( IsAI( m_hStimulusSource ) )
	{
		CAI* pAI = (CAI*)g_pLTServer->HandleToObject( m_hStimulusSource );
		if( pAI )
		{
			if( pAI->HasTarget() )
			{
				m_pAI->Target( pAI->GetTarget()->GetObject() );
			}
		}
	}
	
	else if( IsCharacter( m_hStimulusSource ) )
	{
		// Only set a target to turn towards for specified senses.

		switch( m_eSenseType )
		{
			case kSense_SeeEnemy:
			case kSense_SeeEnemyLean:
			case kSense_HearEnemyWeaponFire:
			case kSense_HearEnemyFootstep:
				{
					// Only target hated characters.

					CCharacter *pChar = (CCharacter*)g_pLTServer->HandleToObject( m_hStimulusSource );
					if( pChar )
					{
						CharacterAlignment eAlignment = GetAlignment( pChar->GetRelationSet(), m_pAI->GetRelationData() );
						if( eAlignment == HATE )
						{
							m_pAI->Target( m_hStimulusSource );

							CAIHumanStateDraw* pStateDraw = (CAIHumanStateDraw*)m_pAI->GetState();
							pStateDraw->SetFaceTarget( LTTRUE );
						}
					}
				}
				break;
		}
	}
}
开发者ID:rickyharis39,项目名称:nolf2,代码行数:73,代码来源:AIGoalDrawWeapon.cpp

示例4: TargetDisturbance

void CAITargetSelectDisturbance::TargetDisturbance( CAI* pAI, CAIWMFact* pFact )
{
	// Sanity check.

	if( !( pAI && pFact ) )
	{
		return;
	}

	// Record the existence of a disturbance in the AI's world state.

	pAI->GetAIWorldState()->SetWSProp( kWSK_DisturbanceExists, pAI->m_hObject, kWST_bool, true );


	// Play a sound corresponding to the type of stimulus.

	EnumAIStimulusID eStimulusID;
	EnumAIStimulusType eStimulusType;
	pFact->GetStimulus( &eStimulusType, &eStimulusID );
	switch( eStimulusType )
	{
		case kStim_WeaponFireSound:
		case kStim_WeaponImpactSound:
		case kStim_WeaponReloadSound:
		case kStim_DisturbanceSound:
		case kStim_FootstepSound:
		case kStim_DeathSound:
		case kStim_PainSound:
			{
				HOBJECT hAlly = g_pAICoordinator->FindAlly( pAI->m_hObject, NULL );
				if( hAlly )
				{
					// "Check it out!"
					// "Roger!"

					g_pAISoundMgr->RequestAISound( pAI->m_hObject, kAIS_OrderInvestigate, kAISndCat_DisturbanceHeard, NULL, 1.f );
					g_pAISoundMgr->RequestAISoundSequence( hAlly, kAIS_Affirmative, pAI->m_hObject, kAIS_OrderInvestigate, kAIS_OrderInvestigate, kAISndCat_Event, NULL, 0.3f );
				}
				else {
					// "What was that?"

					g_pAISoundMgr->RequestAISound( pAI->m_hObject, kAIS_DisturbanceHeardAlarming, kAISndCat_DisturbanceHeard, NULL, 1.f );
				}
			}
			break;

		// "Flashlight!"

		case kStim_FlashlightBeamVisible:
			{
				g_pAISoundMgr->RequestAISound( pAI->m_hObject, kAIS_DisturbanceSeenFlashlight, kAISndCat_Event, NULL, 0.5f );

				HOBJECT hAlly = g_pAICoordinator->FindAlly( pAI->m_hObject, NULL );
				if( hAlly )
				{
					// "Check it out!"
					// "Roger!"

					g_pAISoundMgr->RequestAISoundSequence( hAlly, kAIS_OrderInvestigate, pAI->m_hObject, kAIS_DisturbanceSeenFlashlight, kAIS_DisturbanceSeenFlashlight, kAISndCat_DisturbanceHeard, NULL, 0.3f );
					g_pAISoundMgr->RequestAISoundSequence( pAI->m_hObject, kAIS_Affirmative, hAlly, kAIS_OrderInvestigate, kAIS_DisturbanceSeenFlashlight, kAISndCat_Event, NULL, 0.3f );
				}
			}
			break;
	}

	// Record new target on the BlackBoard.

	pAI->GetAIBlackBoard()->SetBBTargetType( kTarget_Disturbance );
	pAI->GetAIBlackBoard()->SetBBTargetStimulusType( eStimulusType );
	pAI->GetAIBlackBoard()->SetBBTargetStimulusID( eStimulusID );
	pAI->GetAIBlackBoard()->SetBBTargetChangeTime( g_pLTServer->GetTime() );
	pAI->GetAIBlackBoard()->SetBBTargetObject( pFact->GetTargetObject() );


	// Record initial disturbance position.
	// If the stimulus is dynamic, AITarget will track its movement.

	LTVector vTargetPos = pFact->GetPos();
	pAI->GetAIBlackBoard()->SetBBTargetPosition( vTargetPos );

	// If the disturbance is coming from an ally's weapon fire sound,
	// then treat the disturbance position as the position of whatever
	// the ally is firing at.

	if( IsAI( pFact->GetTargetObject() ) )
	{
		CAI* pOtherAI = (CAI*)g_pLTServer->HandleToObject( pFact->GetTargetObject() );
		if( pOtherAI && 
			pOtherAI->HasTarget( kTarget_Character ) &&
			( eStimulusType == kStim_WeaponFireSound ) &&
			( kCharStance_Like == g_pCharacterDB->GetStance( pAI->GetAlignment(), pOtherAI->GetAlignment() ) ) )
		{
			LTVector vTargetPos = pOtherAI->GetAIBlackBoard()->GetBBTargetPosition();
			pAI->GetAIBlackBoard()->SetBBTargetPosition( vTargetPos );
			pFact->SetPos( vTargetPos, 1.f );
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:98,代码来源:AITargetSelectDisturbance.cpp


注:本文中的CAI::HasTarget方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。