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


C++ CAI类代码示例

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


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

示例1: LOAD_HOBJECT

void CAIWeaponAbstract::Load(ILTMessage_Read *pMsg)
{
	HOBJECT hOwner = NULL;
	HWEAPON hWeapon = NULL;

	LOAD_HOBJECT(hOwner);
	LOAD_HRECORD( hWeapon, g_pWeaponDB->GetWeaponsCategory() );
	LOAD_STDSTRING(m_szFireSocketName);
	LOAD_INT_CAST(m_eFiringState, ENUM_AIFiringState);
	LOAD_DWORD(m_iAnimRandomSeed);
	LOAD_TIME(m_fRandomSeedSelectionTime);
	LOAD_FLOAT(m_flWeaponContextInaccuracyScalar);
	LOAD_DWORD(m_hWeaponSocket);
	LOAD_bool(m_bCanDropWeapon);

	ASSERT(IsAI(hOwner));
	CAI* pAI = (CAI*)g_pLTServer->HandleToObject(hOwner);

	ASSERT(pAI->GetArsenal());
	if (pAI)
	{
		ASSERT(pAI->GetArsenal());
		if (CArsenal* pArsenal = pAI->GetArsenal())
		{
			m_pWeapon = pArsenal->GetWeapon(hWeapon);
		}
	}

	if( m_pWeapon )
	{
		m_pAIWeaponRecord = AIWeaponUtils::GetAIWeaponRecord( 
			m_pWeapon->GetWeaponRecord(), 
			pAI->GetAIBlackBoard()->GetBBAIWeaponOverrideSet() );
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:35,代码来源:AIWeaponAbstract.cpp

示例2: InitActivity

void CAIActivityAbstract::InitActivity()
{
	// Find squad members who could be potential participants of this activity.

	LTObjRef* pSquadMembers = m_pSquad->GetSquadMembers();
	int cSquadMembers = m_pSquad->GetNumSquadMembers();

	CAI* pCurAI;
	m_cPotentialParticipants = 0;
	for( int iMember=0; iMember < cSquadMembers; ++iMember )
	{
		pCurAI = (CAI*)g_pLTServer->HandleToObject( pSquadMembers[iMember] );
		if( !pCurAI )
		{
			continue;
		}

		// Add AI to list if he has this activity in his activity set.

		ENUM_AIActivitySet eActivitySet = pCurAI->GetAIBlackBoard()->GetBBAIActivitySet();
		if(	g_pAICoordinator->IsActivityInAIActivitySet( eActivitySet, GetActivityClassType() ) )
		{
			m_aPotentialParticipants[m_cPotentialParticipants] = pCurAI->m_hObject;
			++m_cPotentialParticipants;
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:27,代码来源:AIActivityAbstract.cpp

示例3: CalcActivityAABB

void CAIActivityAbstract::CalcActivityAABB( LTRect3f* pAABB )
{
	// Sanity check.

	if( !pAABB )
	{
		return;
	}

	CAI* pAI;
	uint32 iParticipant;
	bool bFirst = true;
	for( iParticipant=0; iParticipant < m_cPotentialParticipants; ++iParticipant )
	{
		pAI = (CAI*)g_pLTServer->HandleToObject( m_aPotentialParticipants[iParticipant] );
		if( !pAI )
		{
			continue;
		}

		if( bFirst )
		{
			pAABB->Init( pAI->GetPosition(), pAI->GetPosition() );
			bFirst = false;
			continue;
		}

		pAABB->Merge( pAI->GetPosition() );
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:30,代码来源:AIActivityAbstract.cpp

示例4: checkMoveKeys

bool CGenerator_AI::generate(SDL_Event& e)
{
	checkMoveKeys(e);

	if (e.button.type == SDL_MOUSEBUTTONDOWN && e.button.button == SDL_BUTTON_RIGHT &&
	        (m_pSpawnTimer->getTime() - m_prevTimeSpawn) > m_spawnTime_MS)
	{
		int w = 10;
		int h = 10;
		int x = e.button.x;
		int y = e.button.y;
		SCoords2<int> spawnCoords;
		spawnCoords.setCoords(x, y);

		SCoords2<int> topLeft, topRight, bottomLeft, bottomRight;
		topLeft.setCoords(x, y);
		topRight.setCoords(x + w, y);
		bottomRight.setCoords(x + w, y + h);
		bottomLeft.setCoords(x, y + h);

		if (m_pRoom_collision->size() == 0)
		{
			return false;
		}

		bool isWithinARoom = false;
		CRoom* pSpawnRoom = NULL;
		for (int i = 0; i < m_pRoom_collision->size(); ++i)
		{
			pSpawnRoom = m_pRoom_collision->at(i);

			// want to spawn AI within rooms
			if (pSpawnRoom->collision(&topLeft) == true &&
			        pSpawnRoom->collision(&topRight) == true &&
			        pSpawnRoom->collision(&bottomLeft) == true &&
			        pSpawnRoom->collision(&bottomRight) == true)
			{
				isWithinARoom = true;
				break;
			}
		}
		if (isWithinARoom == false)
		{
			return false;
		}

		CAI* pAI = new CAI(m_pWindow, m_pCollisionMap, m_pRoom_collision,
		                   spawnCoords, "Resource Files/AI/debug AI.png",
		                   w, h, 1, 1);
		pAI->setCurrentRoom(pSpawnRoom);

		m_aiVector.push_back(pAI);


		return true;
	}

	return false;
}
开发者ID:zZelman,项目名称:AI-wars,代码行数:59,代码来源:CGenerator_AI.cpp

示例5: AllPlayersTargeted

static bool AllPlayersTargeted( CAI* pIgnoreThisAI )
{
	CPlayerObj::PlayerObjList::const_iterator itEachPlayer = CPlayerObj::GetPlayerObjList().begin();
	CPlayerObj::PlayerObjList::const_iterator itEndPlayer = CPlayerObj::GetPlayerObjList().end();
	for ( ; itEachPlayer != itEndPlayer; ++itEachPlayer )
	{
		// Ignore this player if they are not valid or if they are not alive.

		CCharacter* pPlayer = *itEachPlayer;
		if ( NULL == pPlayer 
			|| IsDeadCharacter( pPlayer->GetHOBJECT() ) )
		{
			continue;
		}
		HOBJECT hPlayer = pPlayer->GetHOBJECT();

		// See if any AIs are targeting the player.

		bool bPlayerTargeted = false;
		CAI::AIList::const_iterator itEachAI = CAI::GetAIList().begin();
		CAI::AIList::const_iterator itEndAI = CAI::GetAIList().end();
		for (  ; itEachAI != itEndAI; ++itEachAI )
		{
			CAI* pCurrentAI = *itEachAI;
			if ( NULL == pCurrentAI )
			{
				continue;
			}

			if ( pCurrentAI == pIgnoreThisAI )
			{
				continue;
			}

			if ( pCurrentAI->GetAIBlackBoard()->GetBBTargetObject() != hPlayer )
			{
				continue;
			}

			bPlayerTargeted = true;
			break;
		}

		if ( false == bPlayerTargeted )
		{
			// Found an untargeted player.  Not all players are targeted.

			return false;
		}
	}

	// All players are targeted.

	return true;
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:55,代码来源:AITargetSelectTraitor.cpp

示例6: 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

示例7: if

void AI_Helicopter::InitAttachments()
{
	CAIVehicle::InitAttachments();

	for ( int iObject = 0 ; iObject < m_cObjects ; iObject++ )
	{
		BaseClass* pObject = m_apObjects[iObject];

		if (pObject)
		{
			if ( IsKindOf(pObject->m_hObject, "ControlledSearchLight") )
			{
				m_iObjectSearchLight = iObject;

				ControlledSearchLight* pSearchLight = ((ControlledSearchLight*)pObject);
				pSearchLight->SetController(m_hObject);

				HATTACHMENT hAttachment;
				if ( LT_OK == g_pLTServer->FindAttachment(m_hObject, pSearchLight->m_hObject, &hAttachment) )
				{
					LTransform transform;
					g_pLTServer->Common()->GetAttachmentTransform(hAttachment, transform, LTTRUE);
					g_pTransLT->Get(transform, m_vPosSearchlight, m_rRotSearchlight);
				}
			}
			else if ( IsKindOf(pObject->m_hObject, "CAI") )
			{
				Link(pObject->m_hObject);

				m_iObjectGunner = iObject;

				CAI* pGunner = ((CAI*)pObject);

				HATTACHMENT hAttachment;
				if ( LT_OK == g_pLTServer->FindAttachment(m_hObject, pGunner->m_hObject, &hAttachment) )
				{
					LTransform transform;
					g_pLTServer->Common()->GetAttachmentTransform(hAttachment, transform, LTTRUE);
					g_pTransLT->Get(transform, m_vPosGunner, m_rRotGunner);
				}

				char szMessage[128];
				sprintf(szMessage, "HELIATTACK HELI=%s", g_pLTServer->GetObjectName(m_hObject));
				SendTriggerMsgToObject(this, pGunner->GetObject(), LTFALSE, szMessage);
			}
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:48,代码来源:AIHelicopter.cpp

示例8: update

void CGenerator_AI::update()
{
	for (int i = 0; i < m_aiVector.size(); ++i)
	{
		CAI* pAI = m_aiVector.at(i);

		// delete a room if it is marked as needed to be deleted
		if (pAI->isToBeDeleted == true)
		{
			auto itr = m_aiVector.begin() + i;
			m_aiVector.erase(itr);
			continue;
		}

		pAI->setMove(isUpPressed, isDownPressed, isLeftPressed, isRightPressed);
		pAI->update();
	}
}
开发者ID:zZelman,项目名称:AI-wars,代码行数:18,代码来源:CGenerator_AI.cpp

示例9: CollectGarbage

void CAIMgr::CollectGarbage()
{
	// Central memory garbage collection.

	m_pAICentralMemory->CollectGarbage();

	// Individual AI working memory garbage collection.

	CAI::AIList::const_iterator it = CAI::GetAIList().begin();
	for (; it != CAI::GetAIList().end(); ++it)
	{
		CAI* pAI = *it;
		if (pAI)
		{
			pAI->GetAIWorkingMemory()->CollectGarbage();
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:18,代码来源:AIMgr.cpp

示例10: SelectDisturbanceSource

HOBJECT CAITargetSelectDisturbanceBeyondGuard::SelectDisturbanceSource( CAI* pAI, CAIWMFact* pFact )
{
	// Sanity check.

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

	// Disturbance is not from an AI.

	if( !IsAI( pFact->GetTargetObject() ) )
	{
		return pFact->GetTargetObject();
	}

	// AI is not an ally.

	CAI* pOther = (CAI*)g_pLTServer->HandleToObject( pFact->GetTargetObject() );
	EnumCharacterStance eStance = g_pCharacterDB->GetStance( pAI->GetAlignment(), pOther->GetAlignment() );
	if( eStance != kCharStance_Like )
	{
		return pFact->GetTargetObject();
	}

	// Ally is not targeting a character.

	if( pOther->GetAIBlackBoard()->GetBBTargetType() != kTarget_Character )
	{
		return pFact->GetTargetObject();
	}

	// Return the Ally's target object.

	return pOther->GetAIBlackBoard()->GetBBTargetObject();
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:36,代码来源:AITargetSelectDisturbanceBeyondGuard.cpp

示例11: if

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

	// Only set a new response index if the AI is witnessing a new stimulus,
	// rather than seeing an ally who is disturbed.

	if( ( m_eSenseType != kSense_SeeAllyDisturbance ) && 
		( m_eSenseType != kSense_HearAllyDisturbance ) )
	{
		m_pAI->SetLastStimulusTime( m_fStimulusTime );
	}

	// Copy an ally's stimulus time.

	else if( m_hStimulusSource && IsAI( m_hStimulusSource ) ) 
	{
		CAI* pAlly = (CAI*)( g_pLTServer->HandleToObject( m_hStimulusSource ) );
		if( pAlly )
		{
			m_pAI->SetLastStimulusTime( pAlly->GetLastStimulusTime() );
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:24,代码来源:AIGoalAbstractStimulated.cpp

示例12: main

int main()
{
	CAI aCAI;
	aCAI.StartTest();
	return 0;
}
开发者ID:hjlin89,项目名称:RemoteCodeManagementFacility,代码行数:6,代码来源:main.cpp

示例13: while

void CAIMgr::UpdateAISensors()
{
	CTList<CCharacter*>* plstChars = g_pCharacterMgr->GetCharacterList( CCharacterMgr::kList_AIs );
	CCharacter** pNext;
	CAI* pCurAI;

	// No AI exist.

	if( plstChars->GetLength() == 0 )
	{
		return;
	}

	// Find the next AI to update.
	// AI update round robin, so everyone gets the opportunity to
	// do a distributed update.

	pNext = plstChars->GetItem( TLIT_FIRST );
	while( m_hNextAI && ( (*pNext)->m_hObject != m_hNextAI ) )
	{
		pNext = plstChars->GetItem( TLIT_NEXT );
	}
	if( !pNext )
	{
		pNext = plstChars->GetItem( TLIT_FIRST );
	}

	HOBJECT hFirstToUpdate = (*pNext)->m_hObject;

	// Iterate over all existing AI.

	bool bWrapped = false;
	bool bUpdateDistributedSensors = true;
	while( true )
	{
		// Bail once we have updated everyone.

		if( bWrapped )
		{
			break;
		}

		// Look ahead at the next AI to update, and flag if we've wrapped.

		pCurAI = (CAI*)*pNext;
		pNext = plstChars->GetItem( TLIT_NEXT );
		if( !pNext )
		{
			pNext = plstChars->GetItem( TLIT_FIRST );
		}
		if( (*pNext)->m_hObject == hFirstToUpdate )
		{
			bWrapped = true;
		}

		// Do not update sensors of dead AI.

		if( pCurAI->GetDestructible()->IsDead() )
		{
			continue;
		}

		// Update all AI's sensors.
		// Stop updating distributed sensors once someone has performed
		// an expensive update.

		if( pCurAI->GetAISensorMgr()->UpdateSensors( bUpdateDistributedSensors ) )
		{
#if DISTRIBUTE_SENSORS
			m_hNextAI = (*pNext)->m_hObject;
			bUpdateDistributedSensors = false;
#endif
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:75,代码来源:AIMgr.cpp

示例14: Evaluate

bool AINodeValidatorLockedByOther::Evaluate( uint32 dwFilteredStatusFlags, CAI* pAI, EnumAINodeClusterID eNodeClusterID, HOBJECT hLockingAI, HOBJECT hDependency, bool* pbOutCoverBehindAlly ) const
{
	if( dwFilteredStatusFlags & kNodeStatus_LockedByOther )
	{
		if( pAI )
		{
			if( hLockingAI && ( hLockingAI != pAI->m_hObject ) )
			{
				return false;
			}

			// Node has a dependency.

			if( hDependency )
			{
				AINodeSmartObject* pNodeSmartObject = AINodeSmartObject::DynamicCast( hDependency );
				if( pNodeSmartObject )
				{
					AIDB_SmartObjectRecord* pRecord = pNodeSmartObject->GetSmartObject();
					if( pRecord )
					{
						// Destination dependency is locked by someone else.

						if( ( pRecord->eDependencyType == kDependency_Destination ) &&
							( pNodeSmartObject->IsNodeLocked() ) &&
							( pNodeSmartObject->GetLockingAI() != pAI->m_hObject ) )
						{
							return false;
						}

						// Occupation dependency is not occupied by someone else.

						if( pRecord->eDependencyType == kDependency_Occupied )
						{
							// AI is taking cover behind someone.

							if ( pbOutCoverBehindAlly )
								*pbOutCoverBehindAlly = true;

							// Node is unusable if dependency is disabled.

							if( pNodeSmartObject->IsNodeDisabled() )
							{
								return false;
							}

							// Node is unusable if locking AI does not exist.

							HOBJECT hLockingAI = pNodeSmartObject->GetLockingAI();
							CAI* pLockingAI = (CAI*)g_pLTServer->HandleToObject( hLockingAI );
							if( !pLockingAI )
							{
								return false;
							}

							// Node is not occupied if the locking AI is not at the node.

							SAIWORLDSTATE_PROP* pAtProp = pLockingAI->GetAIWorldState()->GetWSProp( kWSK_AtNode, pLockingAI->m_hObject );
							if( !( pAtProp && pAtProp->hWSValue == hDependency ) )
							{
								return false;
							}
						}
					}
				}
			}
			// Node has a cluster that is locked by someone else.

			if( eNodeClusterID != kNodeCluster_Invalid )
			{
				CAINodeCluster* pCluster = g_pAINodeMgr->GetNodeCluster( eNodeClusterID );
				if( pCluster &&
					pCluster->IsClusterLocked() &&
					( pCluster->GetLockingAI() != pAI->m_hObject ) )
				{
					return false;
				}
			}
		}
	}

	return true;
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:83,代码来源:AINodeValidators.cpp

示例15: IsPlayer

void CAIGoalCircleFlamePot::DeactivateGoal()
{
	super::DeactivateGoal();

	// If:
	// 1) The player is an enemy.
	// 2) There is another AI very close by
	// 3) That AI does not have a blitz task
	// ...this AI should blitz the player.  This is an anti-clumping measure.

	HOBJECT hTarget = m_pAI->GetAIBlackBoard()->GetBBTargetObject();

	bool bShouldBlitz = false;

	if ( m_pAI->HasTarget( kTarget_Character ) 
		&& IsPlayer( hTarget ) )
	{
		CAI::AIList::const_iterator itEachAI = CAI::GetAIList().begin();
		CAI::AIList::const_iterator itLastAI = CAI::GetAIList().end();
		for ( ; itEachAI != itLastAI; ++itEachAI )
		{
			CAI* pCurrentAI = *itEachAI;

			// Ignore NULL, self and dead AI.

			if ( NULL == pCurrentAI 
				|| pCurrentAI == m_pAI 
				|| IsDeadAI( pCurrentAI->GetHOBJECT() ) )
			{
				continue;
			}

			// Ignore AIs who are far away in 2D (false positives are okay).

			LTVector vDelta2D = ( pCurrentAI->GetPosition() - m_pAI->GetPosition() );
			vDelta2D.y = 0.0f;

			if ( vDelta2D.MagSqr() > g_flTooCloseToEnemySqr )
			{
				continue;
			}

			// Ignore AI who are already blitzing.

			CAIWMFact factQuery;
			factQuery.SetFactType( kFact_Task );
			factQuery.SetTaskType( kTask_BlitzCharacter );
			if ( pCurrentAI->GetAIWorkingMemory()->FindWMFact( factQuery ) )
			{
				continue;
			}

			// AI should blitz.

			bShouldBlitz = true;
			break;
		}
	}

	if ( bShouldBlitz || ( 0 == GetRandom( 0, 2 ) ) )
	{
		CAIWMFact factQuery;
		factQuery.SetFactType( kFact_Task );
		factQuery.SetTaskType( kTask_BlitzCharacter );
		CAIWMFact* pFact = m_pAI->GetAIWorkingMemory()->CreateWMFact( kFact_Task );
		if ( pFact )
		{
			pFact->SetTaskType( kTask_BlitzCharacter );
			pFact->SetTargetObject( hTarget );
			pFact->SetIndex( kContext_None );
			pFact->SetFactFlags( kFactFlag_Scripted, 1.f );
		}
	}
}
开发者ID:Arc0re,项目名称:lithtech,代码行数:74,代码来源:AIGoalCircleFlamePot.cpp


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