Пример #1
0
bool IsDeadCharacter(  HOBJECT hObject )
{
	if( !hObject ) return true;

	if( !IsCharacter( hObject ) ) return false;

	CCharacter *pCharacter = (CCharacter*)g_pLTServer->HandleToObject( hObject );
	return ( pCharacter->GetDestructible()->IsDead() );
}
bool CAISensorEnemyDamagedSuicide::UpdateSensor()
{
	if( !super::UpdateSensor() )
	{
		return false;
	}

	// AI is not targeting anyone.

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

	// Bail if no target.

	HOBJECT hTarget = m_pAI->GetAIBlackBoard()->GetBBTargetObject();
	CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject( hTarget );
	if( !pChar )
	{
		return false;
	}

	// Bail if no destructible.

	CDestructible* pDestructible = pChar->GetDestructible();
	if( !pDestructible )
	{
		return false;
	}

	// Bail if we were not the last damager.

	if( pDestructible->GetLastDamager() != m_pAI->m_hObject )
	{
		return false;
	}

	// No new damage.

	if( pDestructible->GetLastDamageTime() <= 0.f )
	{
		return false;
	}

	// We damaged the target.
	// So kill myself.
	
	g_pCmdMgr->QueueMessage( m_pAI, m_pAI, "DESTROY" );

	return true;
}
Пример #3
0
void CAIWeaponMelee::Fire(CAI* pAI)
{
	if( !m_pWeapon )
	{
		AIASSERT( 0, pAI->GetHOBJECT(), "CAIWeaponMelee::Fire: No weapon!" );
		return;
	}

	if( m_eFiringState != kAIFiringState_Firing )
	{
		return;
	}

	// Fire!

	LTVector vTargetPos;
	bool bHit = GetShootPosition( pAI, m_Context, vTargetPos );
	if (DefaultFire(pAI, vTargetPos, m_pAIWeaponRecord->bAIAnimatesReload))
	{
		// Decrement burst count for this shot.
		m_nBurstShots--;
	}

	// Knock the player back, if the hit inflicted damage.

	if( bHit )
	{
		CPlayerObj* pPlayer = NULL;
		HOBJECT hTarget = pAI->GetAIBlackBoard()->GetBBTargetObject();
		if( IsPlayer( hTarget ) )
		{
			pPlayer = (CPlayerObj*)g_pLTServer->HandleToObject( hTarget );
		}

		if( pPlayer &&
			( m_pAIWeaponRecord->fPlayerPusherRadius > 0.f ) &&
			( m_pAIWeaponRecord->fPlayerPusherForce > 0.f ) &&
			( pPlayer->GetDestructible() ) &&
			( pPlayer->GetDestructible()->GetLastDamageTime() == g_pLTServer->GetTime() ) &&
			( pPlayer->GetDestructible()->GetLastDamager() == pAI->m_hObject ) )
		{
			if( ( pPlayer->GetDestructible()->GetLastArmorAbsorb() > 0.f ) ||
				( pPlayer->GetDestructible()->GetLastDamage() > 0.f ) )
			{
				pPlayer->PushCharacter( pAI->GetPosition(), m_pAIWeaponRecord->fPlayerPusherRadius, 0.f, 0.3f, m_pAIWeaponRecord->fPlayerPusherForce );
			}
		}

		// Only play if we've been targeting someone for at least 5 seconds.
		// This ensures we first play higher priority reaction sounds.

		if( IsCharacter( hTarget ) )
		{
			CCharacter* pChar = (CCharacter*)g_pLTServer->HandleToObject( hTarget );
			if( pChar &&
				( pChar->GetDestructible() ) &&
				( pChar->GetDestructible()->GetLastDamageTime() == g_pLTServer->GetTime() ) &&
				( pChar->GetDestructible()->GetLastDamager() == pAI->m_hObject ) &&
				( pAI->GetAIBlackBoard()->GetBBTargetChangeTime() < g_pLTServer->GetTime() - 5.f ) )
			{
				HOBJECT hAlly = g_pAICoordinator->FindAlly( pAI->m_hObject, hTarget );
				if( hAlly )
				{
					g_pAISoundMgr->RequestAISound( hAlly, kAIS_HitSeenMelee, kAISndCat_Event, hTarget, 0.5f );
				}
			}
		}
	}
}