//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ====
//
// Purpose: Vortigaunt - now much friendlier!
//
//=============================================================================

#include "cbase.h"
#include "hl2wars/npc/hlw_npc_vortigaunt_episodic.h"
#include "hl2wars/rts_globalresource.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


//---------------------------------------------------------
// Save/Restore
//---------------------------------------------------------
BEGIN_DATADESC( CHLW_NPC_Vortigaunt )
END_DATADESC()

LINK_ENTITY_TO_CLASS( hlw_npc_vortigaunt, CHLW_NPC_Vortigaunt );

void CHLW_NPC_Vortigaunt::Spawn()
{
	BaseClass::Spawn();

	CapabilitiesAdd( bits_CAP_NO_HIT_PLAYER | bits_CAP_NO_HIT_SQUADMATES | bits_CAP_FRIENDLY_DMG_IMMUNE );
}

//------------------------------------------------------------------------------
// Purpose: Select a schedule
//------------------------------------------------------------------------------
int CHLW_NPC_Vortigaunt::SelectSchedule( void )
{
	// Always recharge in this case
	if ( m_bForceArmorRecharge )
	{
		m_flNextHealTime = 0;
		int nSchedule = SelectHealSchedule();
		return nSchedule;
	}

#ifndef HL2_EPISODIC
	if ( BehaviorSelectSchedule() )
		return BaseClass::SelectSchedule();
#else
	if ( IsInAScript() )
		return BaseClass::SelectSchedule();
#endif

	// If we're currently supposed to be doing something scripted, do it immediately.
	if ( m_bExtractingBugbait )
		return SCHED_VORTIGAUNT_EXTRACT_BUGBAIT;

	return CAI_BaseActor::SelectSchedule();
}

//------------------------------------------------------------------------------
// Purpose: 
//------------------------------------------------------------------------------
int CHLW_NPC_Vortigaunt::SelectScheduleBehaviorNormalCombat()
{
	int schedule = SelectHealSchedule();
	if ( schedule != SCHED_NONE )
		return schedule;

	if ( HasCondition(COND_VORTIGAUNT_DISPEL_ANTLIONS ) )
	{
		ClearCondition( COND_VORTIGAUNT_DISPEL_ANTLIONS );
		return SCHED_VORTIGAUNT_DISPEL_ANTLIONS;
	}

	// Heal a player if they can be
	if ( HasCondition( COND_VORTIGAUNT_CAN_HEAL ) )
		return SCHED_VORTIGAUNT_HEAL;

	return BaseClass::SelectScheduleBehaviorNormalCombat();
}

//------------------------------------------------------------------------------
// Purpose: 
//------------------------------------------------------------------------------
int CHLW_NPC_Vortigaunt::SelectScheduleBehaviorAggressiveCombat()
{
	int schedule = SelectHealSchedule();
	if ( schedule != SCHED_NONE )
		return schedule;

	if ( HasCondition(COND_VORTIGAUNT_DISPEL_ANTLIONS ) )
	{
		ClearCondition( COND_VORTIGAUNT_DISPEL_ANTLIONS );
		return SCHED_VORTIGAUNT_DISPEL_ANTLIONS;
	}

	// Heal a player if they can be
	if ( HasCondition( COND_VORTIGAUNT_CAN_HEAL ) )
		return SCHED_VORTIGAUNT_HEAL;

	return BaseClass::SelectScheduleBehaviorAggressiveCombat();
}


//-----------------------------------------------------------------------------
// Purpose: Our unit type depends on our weapons and flags
//-----------------------------------------------------------------------------
void CHLW_NPC_Vortigaunt::InitUnitIndex()
{
	const char *m_sUnitType = "UNIT_VORTIGAUNT";
	m_iUnitIndex = g_pRTSResource->GetUnitIndex( m_sUnitType );
}