Ejemplo n.º 1
0
//=========================================================
// SelectSchedule - Decides which type of schedule best suits
// the monster's current state and conditions. Then calls
// monster's member function to get a pointer to a schedule
// of the proper type.
//=========================================================
int CNPC_HL1Barney::SelectSchedule( void )
{
	if ( m_NPCState == NPC_STATE_COMBAT || GetEnemy() != NULL )
	{
		// Priority action!
		if (!m_fGunDrawn )
			return SCHED_ARM_WEAPON;
	}

	if ( GetFollowTarget() == NULL )
	{
		if ( HasCondition( COND_PLAYER_PUSHING ) && !(GetSpawnFlags() & SF_NPC_PREDISASTER ) )	// Player wants me to move
			return SCHED_HL1TALKER_FOLLOW_MOVE_AWAY;
	}

	if ( BehaviorSelectSchedule() )
		return BaseClass::SelectSchedule();

	if ( HasCondition( COND_HEAR_DANGER ) )
	{
		CSound *pSound;
		pSound = GetBestSound();

		ASSERT( pSound != NULL );

		if ( pSound && pSound->IsSoundType( SOUND_DANGER ) )
			return SCHED_TAKE_COVER_FROM_BEST_SOUND;
	}
	if ( HasCondition( COND_ENEMY_DEAD ) && IsOkToSpeak() )
	{
		Speak( BA_KILL );
	}

	switch( m_NPCState )
	{
	case NPC_STATE_COMBAT:
		{
			// dead enemy
			if ( HasCondition( COND_ENEMY_DEAD ) )
				 return BaseClass::SelectSchedule(); // call base class, all code to handle dead enemies is centralized there.
		
			// always act surprized with a new enemy
			if ( HasCondition( COND_NEW_ENEMY ) && HasCondition( COND_LIGHT_DAMAGE) )
				return SCHED_SMALL_FLINCH;
				
			if ( HasCondition( COND_HEAVY_DAMAGE ) )
				 return SCHED_TAKE_COVER_FROM_ENEMY;

			if ( !HasCondition(COND_SEE_ENEMY) )
			{
				// we can't see the enemy
				if ( !HasCondition(COND_ENEMY_OCCLUDED) )
				{
					// enemy is unseen, but not occluded!
					// turn to face enemy
					return SCHED_COMBAT_FACE;
				}
				else
				{
					return SCHED_CHASE_ENEMY;
				}
			}
		}
		break;

	case NPC_STATE_ALERT:	
	case NPC_STATE_IDLE:
		if ( HasCondition( COND_LIGHT_DAMAGE ) || HasCondition( COND_HEAVY_DAMAGE ) ) 
		{
			// flinch if hurt
			return SCHED_SMALL_FLINCH;
		}

		if ( GetEnemy() == NULL && GetFollowTarget() )
		{
			if ( !GetFollowTarget()->IsAlive() )
			{
				// UNDONE: Comment about the recently dead player here?
				StopFollowing();
				break;
			}
			else
			{

				return SCHED_TARGET_FACE;
			}
		}

		// try to say something about smells
		TrySmellTalk();
		break;
	}
	
	return BaseClass::SelectSchedule();
}
//-----------------------------------------------------------------------------
// Purpose: 
// Output : int
//-----------------------------------------------------------------------------
int CNPC_Bug_Warrior::SelectSchedule( void )
{
	ClearCondition( COND_WBUG_STOP_FLEEING );

	// Turn towards sounds
	if ( HasCondition(COND_HEAR_DANGER) || HasCondition(COND_HEAR_COMBAT) )
	{
		CSound *pSound = GetBestSound();
		if ( pSound)
		{
			if ( !HasCondition( COND_SEE_ENEMY ) && ( pSound->m_iType & (SOUND_PLAYER | SOUND_COMBAT) ) )
			{
				GetMotor()->SetIdealYawToTarget( pSound->GetSoundReactOrigin() );
			}
		}
	}

	switch ( m_NPCState )
	{
	case NPC_STATE_IDLE:
		{
			// If I have an enemy, but I don't have any nearby friends, flee
			if ( HasCondition( COND_SEE_ENEMY ) && ShouldFlee() )
			{
				SetState( NPC_STATE_ALERT );
				return SCHED_WBUG_FLEE_ENEMY;
			}

			// Fellow bug might be requesting assistance
			if ( HasCondition( COND_WBUG_ASSIST_FELLOW_BUG ) )
				return SCHED_WBUG_ASSIST_FELLOW_BUG;

			// BugHole might be requesting help
			if ( HasCondition( COND_WBUG_RETURN_TO_BUGHOLE ) )
				return SCHED_WBUG_RETURN_TO_BUGHOLE;

			// Return to my bughole
			return SCHED_WBUG_RETURN_TO_BUGHOLE_AND_REMOVE;
			break;
		}
	case NPC_STATE_ALERT:
		{
			// If I have an enemy, but I don't have any nearby friends, flee
			if ( HasCondition( COND_SEE_ENEMY ) && ShouldFlee() )
			{
				SetState( NPC_STATE_ALERT );
				return SCHED_WBUG_FLEE_ENEMY;
			}

			// Fellow bug might be requesting assistance
			if ( HasCondition( COND_WBUG_ASSIST_FELLOW_BUG ) )
				return SCHED_WBUG_ASSIST_FELLOW_BUG;

			// BugHole might be requesting help
			if ( HasCondition( COND_WBUG_RETURN_TO_BUGHOLE ) )
				return SCHED_WBUG_RETURN_TO_BUGHOLE;

			// If I have a patrol path, walk it
			if ( m_iszPatrolPathName != NULL_STRING )
				return SCHED_WBUG_PATROL;

			break;
		}
	case NPC_STATE_COMBAT:
		{
			// Did I lose my enemy?
			if ( HasCondition ( COND_LOST_ENEMY ) || HasCondition ( COND_ENEMY_UNREACHABLE ) )
			{
				SetEnemy( NULL );
				m_bFightingToDeath = false;
				SetState(NPC_STATE_IDLE);
				return BaseClass::SelectSchedule();
			}

			// If I have an enemy, but I don't have any nearby friends, flee
			if ( HasCondition( COND_SEE_ENEMY ) && ShouldFlee() )
				return SCHED_WBUG_FLEE_ENEMY;

			// If we're able to melee, do so
			if ( HasCondition( COND_CAN_MELEE_ATTACK1 ) )
				return BaseClass::SelectSchedule();
		}
		break;
	}

	return BaseClass::SelectSchedule();
}