//------------------------------------------------------------------------------
// Purpose :
// Input   :
// Output  :
//------------------------------------------------------------------------------
void CNPC_MissileDefense::RunAI( void )
{
	// If my enemy is dead clear the memory and reset m_hEnemy
	if (GetEnemy() != NULL && 
		!GetEnemy()->IsAlive())
	{
		ClearEnemyMemory();
		SetEnemy( NULL );
	}

	if (GetEnemy() == NULL )
	{
		GetSenses()->Look( 4092 );
		SetEnemy( BestEnemy( ) );

		if (GetEnemy() != NULL)
		{
			m_iAmmoLoaded = MD_FULLAMMO;
			m_flReloadedTime = gpGlobals->curtime;
		}
	}

	if( m_iAmmoLoaded < 1 && gpGlobals->curtime > m_flReloadedTime )
	{
		m_iAmmoLoaded = MD_FULLAMMO;
	}

	AimGun();
	FireCannons();
	SetNextThink( gpGlobals->curtime + 0.05 );
}
예제 #2
0
void PlayMenu::AddCharacterToGameSession()
{
	char *player[3] = { "PlayerWizard.xml", "PlayerWarrior.xml", "PlayerAssassin.xml" };
	char *hpBars[3] = { "HpBarWizard.xml", "HpBarWarrior.xml", "HpBarAssassin.xml" };
	char *playersNames[3] = { "wizard", "warrior", "assassin" };

	auto player1 = Object::CreateFromFile(player[indexL]);
	auto player2 = Object::CreateFromFile(player[indexR]);

	player1->SetPos(Vector2f(384, 450));
	player2->SetPos(Vector2f(896, 450));

	player1->GetComponent<PlayerMovement>()->SetControls(0);
	player2->GetComponent<PlayerMovement>()->SetControls(1);

	auto player1CharComp = player1->GetComponent<CharacterComponent>();
	auto player2CharComp = player2->GetComponent<CharacterComponent>();

	player1CharComp->SetEnemy(player2.get());
	player2CharComp->SetEnemy(player1.get());

	player1CharComp->SetControls(0);
	player2CharComp->SetControls(1);

	auto hpBar1 = Object::CreateFromFile(hpBars[indexL]);
	auto hpBar2 = Object::CreateFromFile(hpBars[indexR]);

	hpBar1->SetName("LeftHpBar");
	hpBar2->SetName("RightHpBar");

	hpBar1->SetPos(Vector2f(0, 0));
	hpBar2->SetPos(Vector2f(g_app->APP_RESOLUTION_WIDTH - 200, 0));

	hpBar1->GetComponent<PlayerHpBar>()->SetPlayer(player1.get());
	hpBar2->GetComponent<PlayerHpBar>()->SetPlayer(player2.get());

	auto spellBar1 = Object::Create();
	auto spellBar2 = Object::Create();

	spellBar1->SetPos(Vector2f(0.f, 685.f));
	spellBar2->SetPos(Vector2f(1175.f, 685.f));

	auto spellBar1Comp = spellBar1->AddComponent<SpellFeedbackComponent>();
	auto spellBar2Comp = spellBar2->AddComponent<SpellFeedbackComponent>();

	spellBar1Comp->SetCharacter(playersNames[indexL]);
	spellBar2Comp->SetCharacter(playersNames[indexR]);

	spellBar1Comp->SetCharacter(player1CharComp->GetCharacter());
	spellBar2Comp->SetCharacter(player2CharComp->GetCharacter());

	auto mainGameObject = g_menuHandler->GetMenuObject(MAIN_GAME);

	mainGameObject->AddChild(std::move(player1));
	mainGameObject->AddChild(std::move(player2));
	mainGameObject->AddChild(std::move(hpBar1));
	mainGameObject->AddChild(std::move(hpBar2));
	mainGameObject->AddChild(std::move(spellBar1));
	mainGameObject->AddChild(std::move(spellBar2));
}
예제 #3
0
//-----------------------------------------------------------------------------
// Purpose: Watch for a target to wander into our view
//-----------------------------------------------------------------------------
void CNPC_CeilingTurret::AutoSearchThink( void )
{
	//Allow descended classes a chance to do something before the think function
	if ( PreThink( TURRET_AUTO_SEARCHING ) )
		return;

	//Spread out our thinking
	SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.2f, 0.4f ) );

	//If the enemy is dead, find a new one
	if ( ( GetEnemy() != NULL ) && ( GetEnemy()->IsAlive() == false ) )
	{
		SetEnemy( NULL );
	}

	//Acquire Target
	if ( GetEnemy() == NULL )
	{
		GetSenses()->Look( CEILING_TURRET_RANGE );
		SetEnemy( BestEnemy() );
	}

	//Deploy if we've got an active target
	if ( GetEnemy() != NULL )
	{
		SetThink( &CNPC_CeilingTurret::Deploy );
		EmitSound( "NPC_CeilingTurret.Alert" );
	}
}
void CJaS_GeneratorSparks::Think()
{
    BaseClass::Think();

    if ( !RandomInt( 0, 10 ) )
    {
        CBaseEntity *pNearestMarine = gEntList.FindEntityByClassnameNearest( "asw_marine", m_vecStartPos, 384 );
        CBaseEntity *pNearestDrone = gEntList.FindEntityByClassnameNearest( "asw_drone", m_vecStartPos, 384 );
        CBaseEntity *pNearestBuzzer = gEntList.FindEntityByClassnameNearest( "asw_buzzer", m_vecStartPos, 384 );

        CBaseEntity *pNearest = pNearestMarine ? pNearestMarine : ( pNearestDrone ? pNearestDrone : pNearestBuzzer );
        if ( !pNearest )
        {
            SetEnemy( NULL );
            return;
        }

        if ( pNearestDrone && pNearest->GetDistanceToEntity( this ) > pNearestDrone->GetDistanceToEntity( this ) )
        {
            pNearest = pNearestDrone;
        }
        if ( pNearestBuzzer && pNearest->GetDistanceToEntity( this ) > pNearestBuzzer->GetDistanceToEntity( this ) )
        {
            pNearest = pNearestBuzzer;
        }

        SetEnemy( pNearest );
    }
}
예제 #5
0
// 
// This think function will deploy the turret when something comes into range. This is for
// automatically activated turrets.
//
void CBaseTurret::AutoSearchThink(void)
{
	// ensure rethink
	StudioFrameAdvance( );
	SetNextThink( gpGlobals->curtime + random->RandomFloat( 0.2, 0.3 ) );

	// If we have a target and we're still healthy

	if (GetEnemy() != NULL)
	{
		if (!GetEnemy()->IsAlive() )
			SetEnemy( NULL );// Dead enemy forces a search for new one
	}

	// Acquire Target

	if (GetEnemy() == NULL)
	{
		GetSenses()->Look( TURRET_RANGE );
		SetEnemy( BestEnemy() );
	}

	if (GetEnemy() != NULL)
	{
		SetThink(Deploy);
		EmitSound( "NPC_Turret.Alert" );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  :
// Output : 
//-----------------------------------------------------------------------------
bool CBaseHelicopter::ChooseEnemy( void )
{
	// See if there's a new enemy.
	CBaseEntity *pNewEnemy;

	pNewEnemy = BestEnemy();

	if ( pNewEnemy != GetEnemy() )
	{
		if ( pNewEnemy != NULL )
		{
			// New enemy! Clear the timers and set conditions.
			SetEnemy( pNewEnemy );
			m_flLastSeen = m_flPrevSeen = gpGlobals->curtime;
		}
		else
		{
			SetEnemy( NULL );
			SetState( NPC_STATE_ALERT );
		}
		return true;
	}
	else
	{
		ClearCondition( COND_NEW_ENEMY );
		return false;
	}
}
예제 #7
0
void AFournoidAIController::FindClosestEnemy(){
	APawn* MyBot = GetPawn();
	if (MyBot == NULL)
	{
		return;
	}
	
	const FVector MyLoc = MyBot->GetActorLocation();
	float BestDistSq = MAX_FLT;
	AFournoidCharacter* BestPawn = NULL;
	
	for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; ++It)
	{
		AFournoidCharacter* TestPawn = Cast<AFournoidCharacter>(*It);
		if (TestPawn && TestPawn->IsAlive() && TestPawn->GetController()->IsA(APlayerController::StaticClass()))
		{
			const float DistSq = (TestPawn->GetActorLocation() - MyLoc).SizeSquared();
			if (DistSq < BestDistSq &&  sqrt(DistSq) < 2500.f )
			{
				BestDistSq = DistSq;
				BestPawn = TestPawn;
			}
		}
	}
	
	if (BestPawn)
	{
		SetEnemy(BestPawn);
	}else {
		SetEnemy(NULL);
	}
}
예제 #8
0
파일: stage.cpp 프로젝트: ponyuzu/-
/******************************************************************************
* 関数名:Stage1
* 
* 引数  :
* 戻り値:
* 説明  :
******************************************************************************/
void Stage1( void )
{

	//field///////////////////////////////////////////////////////////////////////
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 0 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 400 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 900 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 1300 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 1700 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f , 2200 ) );
	SetField( D3DXVECTOR3( 0.0f , 0.0f ,  2800 ) );
	SetField(D3DXVECTOR3( 0.0f , 0.0f ,  3500 ));


	//Box/////////////////////////////////////////////////////////////////////////
	SetBox( D3DXVECTOR3( 50.0f ,20 , 0.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( -50.0f , 20 , 100.0f ) , BOX_SPRING );

	SetBox( D3DXVECTOR3( - 50.0f ,20 , 900.0f ) , BOX_NOMAL );

	SetBox( D3DXVECTOR3( 50.0f ,20 , 1340.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 50.0f ,20 , 1380.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 10.0f ,20 , 1380.0f ) , BOX_NOMAL );

	SetBox( D3DXVECTOR3( 50.0f ,20 , 2800.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 10.0f ,20 , 2800.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 50.0f ,20 , 2840.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 10.0f ,20 , 2840.0f ) , BOX_NOMAL );
	SetBox( D3DXVECTOR3( 30.0f ,60 , 2820.0f ) , BOX_NOMAL );


	//Obstacl/////////////////////////////////////////////////////////////////////
	SetObstacl( D3DXVECTOR3( 0.0f ,20 , 50.0f ) , OBSTACL_NOMAL );

	SetObstacl( D3DXVECTOR3( -50.0f , 20 , 2500.0f ) , OBSTACL_NOMAL );

	SetObstacl( D3DXVECTOR3( 0.0f , -20 , 3100.0f ) , OBSTACL_NOMAL );
	SetObstacl( D3DXVECTOR3( 0.0f , -20 , 3200.0f ) , OBSTACL_NOMAL );
	SetObstacl( D3DXVECTOR3( 0.0f , -20 , 3300.0f ) , OBSTACL_NOMAL );

	//Enemy///////////////////////////////////////////////////////////////////////
	SetEnemy( D3DXVECTOR3( 150.0f , 0.0f ,  1200.0f ) );
	SetEnemy( D3DXVECTOR3( 150.0f , 0.0f ,  1500.0f ) );
	SetEnemy( D3DXVECTOR3( 0.0f , 0.0f ,  1700.0f ) );


	//Acorn///////////////////////////////////////////////////////////////////////
	SetAcorn( D3DXVECTOR3( 0.0f ,0, - 80.0f ) );


	//goal/////////////////////////////////////////////////////////////////////
	SetGoal( D3DXVECTOR3( 0.0f , 50.0f , 3500 ) );
}
//-----------------------------------------------------------------------------
// Purpose: The turret doesn't run base AI properly, which is a bad decision.
//			As a result, it has to manually find enemies.
//-----------------------------------------------------------------------------
void CNPC_Portal_FloorTurret::HackFindEnemy( void )
{
	// We have to refresh our memories before finding enemies, so
	// dead enemies are cleared out before new ones are added.
	GetEnemies()->RefreshMemories();

	GetSenses()->Look( PORTAL_FLOOR_TURRET_RANGE );
	SetEnemy( BestEnemy() );

	if ( GetEnemy() == NULL )
	{
		// Look through the list of sensed objects for possible targets
		AISightIter_t iter;
		CBaseEntity *pObject;
		CBaseEntity	*pNearest = NULL;
		float flClosestDistSqr = PORTAL_FLOOR_TURRET_RANGE * PORTAL_FLOOR_TURRET_RANGE;

		for ( pObject = GetSenses()->GetFirstSeenEntity( &iter, SEEN_MISC ); pObject; pObject = GetSenses()->GetNextSeenEntity( &iter ) )
		{
			Vector vVelocity;
			pObject->GetVelocity( &vVelocity );

			// Ignore objects going too slowly
			if ( vVelocity.LengthSqr() < m_fMovingTargetThreashold )
				continue;

			float flDistSqr = pObject->WorldSpaceCenter().DistToSqr( GetAbsOrigin() );
			if ( flDistSqr < flClosestDistSqr )
			{
				flClosestDistSqr = flDistSqr;
				pNearest = pObject;
			}
		}

		if ( pNearest )
		{
			SetEnemy( pNearest );
			m_fMovingTargetThreashold += gpGlobals->curtime * 15.0f;
			if ( m_fMovingTargetThreashold > 800.0f )
			{
				m_fMovingTargetThreashold = 800.0f;
			}
		}
	}
	else
	{
		m_fMovingTargetThreashold = 20.0f;
	}
}
예제 #10
0
//
// This search function will sit with the turret deployed and look for a new target. 
// After a set amount of time, the barrel will spin down. After m_flMaxWait, the turret will
// retact.
//
void CBaseTurret::SearchThink(void)
{
	// ensure rethink
	SetActivity( (Activity)ACT_TURRET_OPEN_IDLE );

	StudioFrameAdvance( );
	SetNextThink( gpGlobals->curtime + 0.1f );

	Ping( );

	// If we have a target and we're still healthy
	if (GetEnemy() != NULL)
	{
		if (!GetEnemy()->IsAlive() )
			SetEnemy( NULL );// Dead enemy forces a search for new one
	}

	// Acquire Target
	if (GetEnemy() == NULL)
	{
		GetSenses()->Look(TURRET_RANGE);
		SetEnemy( BestEnemy() );
	}

	// If we've found a target, spin up the barrel and start to attack
	if (GetEnemy() != NULL)
	{
		m_flLastSight = 0;
		SetThink(ActiveThink);
	}
	else
	{
		// Are we out of time, do we need to retract?
 		if (gpGlobals->curtime > m_flLastSight)
		{
			//Before we retrace, make sure that we are spun down.
			m_flLastSight = 0;
			SetThink(Retire);
		}
		
		// generic hunt for new victims
		m_vecGoalAngles.y = (m_vecGoalAngles.y + 0.1 * m_iBaseTurnRate);
		if (m_vecGoalAngles.y >= 360)
			m_vecGoalAngles.y -= 360;

		MoveTurret();
	}
}
예제 #11
0
파일: npc_ai.cpp 프로젝트: CCNHsK-Dev/SyPB
void NPC::SetMoveTarget(edict_t *entity)
{
	if (FNullEnt(entity) || !IsAlive(entity))
	{
		m_moveTargetEntity = null;
		m_task &= ~TASK_MOVETOTARGET;
		m_enemyUpdateTime = -1.0f;
		return;
	}

	if (!FNullEnt (m_enemy) || m_moveTargetEntity != entity)
	{
		LoadEntityWaypointPoint(entity);
		LoadEntityWaypointPoint(GetEntity(), entity);
		m_currentWaypointIndex = -1;

		// Pro P.45 - Move Target improve
		FindWaypoint();
	}
	
	SetEnemy(null);

	m_moveTargetEntity = entity;
	m_task |= TASK_MOVETOTARGET;
	m_enemyUpdateTime = gpGlobals->time + 0.3f;
}
예제 #12
0
//-----------------------------------------------------------------------------
// Purpose: Input handler for toggling the turret on/off.
//-----------------------------------------------------------------------------
void CBaseTurret::InputToggle( inputdata_t &inputdata )
{
	//if ( !ShouldToggle( useType, m_iOn ) )
	//	return;

	if (m_iOn)
	{
		SetEnemy( NULL );
		SetNextThink( gpGlobals->curtime + 0.1f );
		m_iAutoStart = FALSE;// switching off a turret disables autostart
		//!!!! this should spin down first!!BUGBUG
		SetThink(Retire);
	}
	else 
	{
		SetNextThink( gpGlobals->curtime + 0.1f ); // turn on delay

		// if the turret is flagged as an autoactivate turret, re-enable its ability open self.
		if ( m_spawnflags & SF_NPC_TURRET_AUTOACTIVATE )
		{
			m_iAutoStart = TRUE;
		}
		
		SetThink(Deploy);
	}
}
예제 #13
0
/**
 Function called to search for an enemy
 
 - parameter void:
 - returns: void
 */
void AEnemyController::SearchForEnemy()
{
    APawn* MyEnemy = GetPawn();
    if (MyEnemy == NULL)
        return;
    
    const FVector MyLoc = MyEnemy->GetActorLocation();
    float BestDistSq = MAX_FLT;
    ATankCharacter* BestPawn = NULL;
    
    for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++)
    {
        ATankCharacter* TestPawn = Cast<ATankCharacter>(*It);
        if (TestPawn)
        {
            const float DistSq = FVector::Dist(TestPawn->GetActorLocation(), MyLoc);
            bool canSee = LineOfSightTo(TestPawn);
            
            //choose the closest option to the AI that can be seen
            if (DistSq < BestDistSq && canSee)
            {
                BestDistSq = DistSq;
                BestPawn = TestPawn;
            }
        }
    }
    
    if (BestPawn)
    {
        GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Green, BestPawn->GetName());
        SetEnemy(BestPawn);
        
    }
}
예제 #14
0
void CNPC_BaseTurret::TurretUse( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{
	if ( !ShouldToggle( useType, m_iOn ) )
		return;

	if (m_iOn)
	{
		SetEnemy( NULL );
		SetNextThink( gpGlobals->curtime + 0.1 );
		m_iAutoStart = FALSE;// switching off a turret disables autostart
		//!!!! this should spin down first!!BUGBUG
		SetThink(&CNPC_BaseTurret::Retire);
	}
	else 
	{
		SetNextThink( gpGlobals->curtime + 0.1 ); // turn on delay

		// if the turret is flagged as an autoactivate turret, re-enable it's ability open self.
		if ( m_spawnflags & SF_MONSTER_TURRET_AUTOACTIVATE )
		{
			m_iAutoStart = TRUE;
		}
		
		SetThink(&CNPC_BaseTurret::Deploy);
	}
}
//---------------------------------------------------------
//---------------------------------------------------------
void CNPC_Combine_Cannon::PrescheduleThink( void )
{
	BaseClass::PrescheduleThink();
	
	// NOTE: We'll deal with this on the client
	// Think faster if the beam is on, this gives the beam higher resolution.
	if( m_pBeam )
	{
		SetNextThink( gpGlobals->curtime + 0.03 );
	}
	else
	{
		SetNextThink( gpGlobals->curtime + 0.1f );
	}

	// If the enemy has just stepped into view, or we've acquired a new enemy,
	// Record the last time we've seen the enemy as right now.
	//
	// If the enemy has been out of sight for a full second, mark him eluded.
	if( GetEnemy() != NULL )
	{
		if( gpGlobals->curtime - GetEnemies()->LastTimeSeen( GetEnemy() ) > 30 )
		{
			// Stop pestering enemies after 30 seconds of frustration.
			GetEnemies()->ClearMemory( GetEnemy() );
			SetEnemy(NULL);
		}
	}
}
void CNPC_SO_BaseZombie::ForceMove( const Vector &targetPos, const Vector &traceDir, bool bRun ) 
{
	// Make sure our zombie gets the message (sometimes it is stubborn)
	// This bit should force our zombie to listen to us
	SetEnemy( NULL );
	SetSchedule( SCHED_ZOMBIE_AMBUSH_MODE );

	Vector chasePosition = targetPos;

	Vector vUpBit = chasePosition;
	vUpBit.z += 1;

	trace_t tr;
	AI_TraceHull( chasePosition, vUpBit, GetHullMins(), GetHullMaxs(), MASK_NPCSOLID, this, COLLISION_GROUP_NONE, &tr );

	m_vecLastPosition = chasePosition;

	if ( m_hCine != NULL )
		ExitScriptedSequence();

	SetCondition( COND_RECEIVED_ORDERS );

	if ( bRun )
		SetSchedule( SCHED_FORCED_GO_RUN );
	else
		SetSchedule( SCHED_FORCED_GO );

	m_flMoveWaitFinished = gpGlobals->curtime;
}
예제 #17
0
void CASW_Parasite::GatherEnemyConditions( CBaseEntity *pEnemy )
{
	// Do the base class
	BaseClass::GatherEnemyConditions( pEnemy );

	// If we're not already too far away, check again
	//TODO: Check to make sure we don't already have a condition set that removes the need for this
	if ( HasCondition( COND_ENEMY_UNREACHABLE ) == false )
	{
		Vector	predPosition;
		UTIL_PredictedPosition( GetEnemy(), 1.0f, &predPosition );

		Vector	predDir = ( predPosition - GetAbsOrigin() );
		float	predLength = VectorNormalize( predDir );

		// See if we'll be outside our effective target range
		if ( predLength > 2000 ) // m_flEludeDistance
		{
			Vector	predVelDir = ( predPosition - GetEnemy()->GetAbsOrigin() );
			float	predSpeed  = VectorNormalize( predVelDir );

			// See if the enemy is moving mostly away from us
			if ( ( predSpeed > 512.0f ) && ( DotProduct( predVelDir, predDir ) > 0.0f ) )
			{
				// Mark the enemy as eluded and burrow away
				ClearEnemyMemory();
				SetEnemy( NULL );
				SetIdealState( NPC_STATE_ALERT );
				SetCondition( COND_ENEMY_UNREACHABLE );
			}
		}
	}
}
예제 #18
0
bool AMyAIController::FindClosestEnemy()
{
	AMyChar* mySelf = Cast<AMyChar>(GetPawn());
	if (!mySelf)
		return false;

	const FVector myLoc = mySelf->GetActorLocation();
	float BestDistSq = MAX_FLT;
	AMyChar * bestTarget = nullptr;

	for (FConstPawnIterator iter = GetWorld()->GetPawnIterator(); iter; ++iter)
	{
		AMyChar* tmpTarget = Cast<AMyChar>(*iter);
		if (tmpTarget != mySelf)
		{
			if (tmpTarget)
			{
				const float DistSq = (tmpTarget->GetActorLocation() - myLoc).SizeSquared();
				if (DistSq < BestDistSq)
				{
					BestDistSq = DistSq;
					bestTarget = tmpTarget;
					FString str = FString::Printf(TEXT("--- find enemy dist:%f"), BestDistSq);
					GEngine->AddOnScreenDebugMessage(0, 2.0f, FColor::Red, str);
				}
			}
		}
	}

	if (bestTarget)
	{
		return SetEnemy(bestTarget);
	}
	return false;
}
예제 #19
0
void hhCenturion::Event_Touch( idEntity *other, trace_t *trace ) {
	if ( (!enemy.GetEntity() || other->IsType( hhPlayer::Type )) && !other->fl.notarget && ( ReactionTo( other ) & ATTACK_ON_ACTIVATE ) ) {
		Activate( other );
		SetEnemy( static_cast<idActor *> ( other ) );
	}
	AI_PUSHED = true;
}
예제 #20
0
void CBaseJungle::InitEnemies(Sint32 sMin)
{
	//---------------------------------------------------------------------------
	//敵の初期化
	//---------------------------------------------------------------------------

	SetEnemy(sMin);

}
예제 #21
0
void CASW_Simple_Alien::FindNewEnemy()
{
	float dist;
	CBaseEntity *pNearest = UTIL_ASW_NearestMarine(GetAbsOrigin(), dist);
	if (CanSee(pNearest))
	{
		SetEnemy(pNearest);
	}
}
예제 #22
0
//-----------------------------------------------------------------------------
// Purpose: Retire the turret until enabled again
//-----------------------------------------------------------------------------
void CNPC_CeilingTurret::Disable( void )
{
	m_bEnabled = false;
	m_bAutoStart = false;

	SetEnemy( NULL );
	SetThink( &CNPC_CeilingTurret::Retire );
	SetNextThink( gpGlobals->curtime + 0.1f );
}
//------------------------------------------------------------------------------
// Updates the enemy
//------------------------------------------------------------------------------
void CBaseHelicopter::UpdateEnemy()
{
	if( HasCondition( COND_ENEMY_DEAD ) )
	{
		SetEnemy( NULL );
	}

	// Look for my best enemy. If I change enemies, 
	// be sure and change my prevseen/lastseen timers.
	if( m_lifeState == LIFE_ALIVE )
	{
		GetSenses()->Look( (int)EnemySearchDistance() );

		GetEnemies()->RefreshMemories();
		ChooseEnemy();

		if( HasEnemy() )
		{
			CBaseEntity *pEnemy = GetEnemy();
			GatherEnemyConditions( pEnemy );
			if ( FVisible( pEnemy ) )
			{
				if (m_flLastSeen < gpGlobals->curtime - 2)
				{
					m_flPrevSeen = gpGlobals->curtime;
				}

				m_flLastSeen = gpGlobals->curtime;
				m_vecTargetPosition = pEnemy->WorldSpaceCenter();
			}
		}
		else
		{
			// look at where we're going instead
			m_vecTargetPosition = GetDesiredPosition();
		}
	}
	else
	{
		// If we're dead or dying, forget our enemy and don't look for new ones(sjb)
		SetEnemy( NULL );
	}

}
예제 #24
0
void CNPC_BaseTurret::InputDeactivate( inputdata_t &inputdata )
{
	if( m_iOn && m_lifeState == LIFE_ALIVE )
	{
		SetEnemy( NULL );
		SetNextThink( gpGlobals->curtime + 0.1 );
		m_iAutoStart = FALSE;// switching off a turret disables autostart
		//!!!! this should spin down first!!BUGBUG
		SetThink(&CNPC_BaseTurret::Retire);
	}
}
//-----------------------------------------------------------------------------
// Purpose: Sparks and fizzes to show it's broken.
//-----------------------------------------------------------------------------
void CNPC_RocketTurret::DeathThink( void )
{
	Vector vForward;
	AngleVectors( m_vecCurrentAngles, &vForward, NULL, NULL );

	m_iLaserState = 0;
	SetEnemy( NULL );

	g_pEffects->Sparks( EyePosition(), 1, 1, &vForward );
	g_pEffects->Smoke( EyePosition(), 0, 6.0f, 20 );

	SetNextThink( gpGlobals->curtime + RandomFloat( 2.0f, 8.0f ) );
}
//-----------------------------------------------------------------------------
// Purpose: Retire the turret until enabled again
//-----------------------------------------------------------------------------
void CNPC_RocketTurret::Disable( void )
{
	if ( !m_bEnabled )
		return;

	UpdateSkin( ROCKET_SKIN_IDLE );

	m_bEnabled = false;
	ResetSequence(LookupSequence("close"));

	SetThink( &CNPC_RocketTurret::ClosingThink );
	SetNextThink( gpGlobals->curtime + 0.05 );
	SetEnemy( NULL );
}
예제 #27
0
파일: npc_ai.cpp 프로젝트: CCNHsK-Dev/SyPB
void NPC::TaskMoveTarget(void)
{
	if (FNullEnt(m_moveTargetEntity))
		return;

	if (DoWaypointNav())
		DeleteSearchNodes();

	int destIndex = g_waypoint->GetEntityWpIndex(m_moveTargetEntity);
	if (destIndex >= 0 && destIndex < g_numWaypoints)
	{
		bool moveToTarget = false;
		if (&m_navNode[0] != null)
		{
			PathNode *node = m_navNode;

			while (node->next != null)
				node = node->next;

			if (node->index == destIndex)
				moveToTarget = true;
		}

		if (!GoalIsValid() || (m_goalWaypoint != destIndex && !moveToTarget))
		{
			int srcIndex = m_currentWaypointIndex;
			if (m_currentWaypointIndex != g_waypoint->GetEntityWpIndex(GetEntity()))
			{
				if (*(g_waypoint->m_distMatrix + (m_currentWaypointIndex * g_numWaypoints) + destIndex) <=
					*(g_waypoint->m_distMatrix + (g_waypoint->GetEntityWpIndex(GetEntity()) * g_numWaypoints) + destIndex))
					srcIndex = m_currentWaypointIndex;
				else
					srcIndex = g_waypoint->GetEntityWpIndex(GetEntity());
			}

			DeleteSearchNodes();
			m_currentWaypointIndex = srcIndex;
			m_navTime = gpGlobals->time + 5.0f;
			SetWaypointOrigin();

			m_goalWaypoint = destIndex;
			FindShortestPath(m_currentWaypointIndex, m_goalWaypoint);
		}

		if (m_currentWaypointIndex == m_goalWaypoint)
			SetEnemy(m_moveTargetEntity);
	}
}
예제 #28
0
//=========================================================
// SelectIdealState()
// 
//=========================================================
NPC_STATE CNPC_Scient::SelectIdealState( void )
{
	switch (m_NPCState)
	{
		case NPC_STATE_COMBAT:
		{
			if (GetEnemy() != NULL)
			{
				SetEnemy(NULL);
				return NPC_STATE_ALERT;
			}

			break;
		}
	}

	return BaseClass::SelectIdealState();
}
예제 #29
0
//---------------------------------------------------------
//---------------------------------------------------------
int CFastZombie::SelectSchedule ( void )
{
    if ( HasCondition( COND_ZOMBIE_RELEASECRAB ) )
    {
        // Death waits for no man. Or zombie. Or something.
        return SCHED_ZOMBIE_RELEASECRAB;
    }

    if ( HasCondition( COND_FASTZOMBIE_CLIMB_TOUCH ) )
    {
        return SCHED_FASTZOMBIE_UNSTICK_JUMP;
    }

    switch ( m_NPCState )
    {
    case NPC_STATE_COMBAT:
        if ( HasCondition( COND_LOST_ENEMY ) || ( HasCondition( COND_ENEMY_UNREACHABLE ) && MustCloseToAttack() ) )
        {
            // Set state to alert and recurse!
            SetState( NPC_STATE_ALERT );
            return SelectSchedule();
        }
        break;

    case NPC_STATE_ALERT:
        if ( HasCondition( COND_LOST_ENEMY ) || ( HasCondition( COND_ENEMY_UNREACHABLE ) && MustCloseToAttack() ) )
        {
            ClearCondition( COND_LOST_ENEMY );
            ClearCondition( COND_ENEMY_UNREACHABLE );
            SetEnemy( NULL );

#ifdef DEBUG_ZOMBIES
            DevMsg("Wandering\n");
#endif

            // Just lost track of our enemy.
            // Wander around a bit so we don't look like a dingus.
            return SCHED_ZOMBIE_WANDER_MEDIUM;
        }
        break;
    }

    return BaseClass::SelectSchedule();
}
예제 #30
0
//-----------------------------------------------------------------------------
// Purpose: The turret has been tipped over and will thrash for awhile
//-----------------------------------------------------------------------------
void CNPC_Portal_FloorTurret::HeldThink( void )
{
	PreThink( (turretState_e)PORTAL_TURRET_PICKUP );

	SetNextThink( gpGlobals->curtime + 0.05f );
	SetEnemy( NULL );

	StudioFrameAdvance();

	IPhysicsObject *pTurretPhys = VPhysicsGetObject();

	// If we're not held anymore, stop thrashing
	if ( !(pTurretPhys->GetGameFlags() & FVPHYSICS_PLAYER_HELD) )
	{
		m_fNextTalk = gpGlobals->curtime + 1.25f;

		if ( m_lifeState == LIFE_ALIVE )
			SetThink( &CNPC_FloorTurret::ActiveThink );
		else
			SetThink( &CNPC_FloorTurret::InactiveThink );
	}

	LaserOn();
	RopesOn();

	//See if we should continue to thrash
	if ( !IsDissolving() )
	{
		if ( m_flShotTime < gpGlobals->curtime )
		{
			SetActivity( (Activity) ACT_FLOOR_TURRET_OPEN_IDLE );

			DryFire();

			m_flShotTime = gpGlobals->curtime + RandomFloat( 0.25f, 0.75f );

			m_vecGoalAngles.x = GetAbsAngles().x + RandomFloat( -15, 15 );
			m_vecGoalAngles.y = GetAbsAngles().y + RandomFloat( -40, 40 );
		}

		UpdateFacing();
	}
}