本文整理汇总了C++中CAI_BaseNPC::IRelationPriority方法的典型用法代码示例。如果您正苦于以下问题:C++ CAI_BaseNPC::IRelationPriority方法的具体用法?C++ CAI_BaseNPC::IRelationPriority怎么用?C++ CAI_BaseNPC::IRelationPriority使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CAI_BaseNPC
的用法示例。
在下文中一共展示了CAI_BaseNPC::IRelationPriority方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BestEnemy
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBaseEntity *CAI_FuncTankBehavior::BestEnemy( void )
{
// Only use this BestEnemy call when we are on the manned gun.
if ( !m_hFuncTank ||!IsMounted() )
return BaseClass::BestEnemy();
CBaseEntity *pBestEnemy = NULL;
int iBestDistSq = MAX_COORD_RANGE * MAX_COORD_RANGE; // so first visible entity will become the closest.
int iBestPriority = -1000;
bool bBestUnreachable = false; // Forces initial check
bool bBestSeen = false;
bool bUnreachable = false;
int iDistSq;
AIEnemiesIter_t iter;
// Get the current npc for checking from.
CAI_BaseNPC *pNPC = GetOuter();
if ( !pNPC )
return NULL;
for( AI_EnemyInfo_t *pEMemory = GetEnemies()->GetFirst( &iter ); pEMemory != NULL; pEMemory = GetEnemies()->GetNext( &iter ) )
{
CBaseEntity *pEnemy = pEMemory->hEnemy;
if ( !pEnemy || !pEnemy->IsAlive() )
continue;
// UNDONE: Move relationship checks into IsValidEnemy?
if ( ( pEnemy->GetFlags() & FL_NOTARGET ) ||
( pNPC->IRelationType( pEnemy ) != D_HT && pNPC->IRelationType( pEnemy ) != D_FR ) ||
!IsValidEnemy( pEnemy ) )
continue;
if ( pEMemory->timeLastSeen < pNPC->GetAcceptableTimeSeenEnemy() )
continue;
if ( pEMemory->timeValidEnemy > gpGlobals->curtime )
continue;
// Skip enemies that have eluded me to prevent infinite loops
if ( GetEnemies()->HasEludedMe( pEnemy ) )
continue;
// Establish the reachability of this enemy
bUnreachable = pNPC->IsUnreachable( pEnemy );
// Check view cone of the view tank here.
bUnreachable = !m_hFuncTank->IsEntityInViewCone( pEnemy );
if ( !bUnreachable )
{
// It's in the viewcone. Now make sure we have LOS to it.
bUnreachable = !m_hFuncTank->HasLOSTo( pEnemy );
}
// If best is reachable and current is unreachable, skip the unreachable enemy regardless of priority
if ( !bBestUnreachable && bUnreachable )
continue;
// If best is unreachable and current is reachable, always pick the current regardless of priority
if ( bBestUnreachable && !bUnreachable )
{
bBestSeen = ( pNPC->GetSenses()->DidSeeEntity( pEnemy ) || pNPC->FVisible( pEnemy ) ); // @TODO (toml 04-02-03): Need to optimize CanSeeEntity() so multiple calls in frame do not recalculate, rather cache
iBestPriority = pNPC->IRelationPriority( pEnemy );
iBestDistSq = static_cast<int>((pEnemy->GetAbsOrigin() - GetAbsOrigin() ).LengthSqr());
pBestEnemy = pEnemy;
bBestUnreachable = bUnreachable;
}
// If both are unreachable or both are reachable, chose enemy based on priority and distance
else if ( pNPC->IRelationPriority( pEnemy ) > iBestPriority )
{
// this entity is disliked MORE than the entity that we
// currently think is the best visible enemy. No need to do
// a distance check, just get mad at this one for now.
iBestPriority = pNPC->IRelationPriority ( pEnemy );
iBestDistSq = static_cast<int>(( pEnemy->GetAbsOrigin() - GetAbsOrigin() ).LengthSqr());
pBestEnemy = pEnemy;
bBestUnreachable = bUnreachable;
}
else if ( pNPC->IRelationPriority( pEnemy ) == iBestPriority )
{
// this entity is disliked just as much as the entity that
// we currently think is the best visible enemy, so we only
// get mad at it if it is closer.
iDistSq = static_cast<int>(( pEnemy->GetAbsOrigin() - GetAbsOrigin() ).LengthSqr());
bool bCloser = ( iDistSq < iBestDistSq ) ;
if ( bCloser || !bBestSeen )
{
// @TODO (toml 04-02-03): Need to optimize FVisible() so multiple calls in frame do not recalculate, rather cache
bool fSeen = ( pNPC->GetSenses()->DidSeeEntity( pEnemy ) || pNPC->FVisible( pEnemy ) );
if ( ( bCloser && ( fSeen || !bBestSeen ) ) || ( !bCloser && !bBestSeen && fSeen ) )
{
bBestSeen = fSeen;
iBestDistSq = iDistSq;
iBestPriority = pNPC->IRelationPriority( pEnemy );
pBestEnemy = pEnemy;
//.........这里部分代码省略.........
示例2: HandleAnimEvent
void CNPC_Zombine::HandleAnimEvent( animevent_t *pEvent )
{
if ( pEvent->event == AE_ZOMBINE_PULLPIN )
{
Vector vecStart;
QAngle angles;
GetAttachment( "grenade_attachment", vecStart, angles );
CBaseGrenade *pGrenade = Fraggrenade_Create( vecStart, vec3_angle, vec3_origin, AngularImpulse( 0, 0, 0 ), this, 3.5f, true );
if ( pGrenade )
{
// Move physobject to shadow
IPhysicsObject *pPhysicsObject = pGrenade->VPhysicsGetObject();
if ( pPhysicsObject )
{
pGrenade->VPhysicsDestroyObject();
int iAttachment = LookupAttachment( "grenade_attachment");
pGrenade->SetMoveType( MOVETYPE_NONE );
pGrenade->SetSolid( SOLID_NONE );
pGrenade->SetCollisionGroup( COLLISION_GROUP_DEBRIS );
pGrenade->SetAbsOrigin( vecStart );
pGrenade->SetAbsAngles( angles );
pGrenade->SetParent( this, iAttachment );
pGrenade->SetDamage( 200.0f );
m_hGrenade = pGrenade;
EmitSound( "Zombine.ReadyGrenade" );
// Tell player allies nearby to regard me!
CAI_BaseNPC **ppAIs = g_AI_Manager.AccessAIs();
CAI_BaseNPC *pNPC;
for ( int i = 0; i < g_AI_Manager.NumAIs(); i++ )
{
pNPC = ppAIs[i];
if( pNPC->Classify() == CLASS_PLAYER_ALLY || pNPC->Classify() == CLASS_PLAYER_ALLY_VITAL && pNPC->FVisible(this) )
{
int priority;
Disposition_t disposition;
priority = pNPC->IRelationPriority(this);
disposition = pNPC->IRelationType(this);
pNPC->AddEntityRelationship( this, disposition, priority + 1 );
}
}
}
m_iGrenadeCount--;
}
return;
}
if ( pEvent->event == AE_NPC_ATTACK_BROADCAST )
{
if ( HasGrenade() )
return;
}
BaseClass::HandleAnimEvent( pEvent );
}