//===== Copyright © 1996-2005, Sander Corporation, All rights reserved. ========
//
// Purpose: 
//
//=============================================================================

#include "cbase.h"
#include "hl2wars/rts_shareddefs.h"
#include "hl2wars/rts_globalresource.h"
#include "hl2wars/rts_parsedata.h"

class CRTSAbilityController : public CPointEntity
{
public:
	DECLARE_CLASS( CRTSAbilityController , CPointEntity );
	DECLARE_DATADESC();

	// Constructor
	CRTSAbilityController ( void ) {}
	~CRTSAbilityController ( void ) {}

	void InputSetOverridable( inputdata_t &inputdata );
	void InputSetAvailable( inputdata_t &inputdata );

private:
	int m_iTeamID;
	string_t m_Ability;
};

LINK_ENTITY_TO_CLASS( rts_ability_controller, CRTSAbilityController  );
	
BEGIN_DATADESC( CRTSAbilityController  )	
    DEFINE_KEYFIELD( m_iTeamID, FIELD_INTEGER, "teamid" ),
	DEFINE_KEYFIELD( m_Ability, FIELD_STRING, "ability" ),	

	DEFINE_INPUTFUNC(FIELD_BOOLEAN, "InputSetOverridable", InputSetOverridable),
	DEFINE_INPUTFUNC(FIELD_BOOLEAN, "InputSetAvailable", InputSetAvailable),
END_DATADESC()

//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void CRTSAbilityController::InputSetOverridable( inputdata_t &inputdata ) 
{
	// make sure it's a bool, if it can't be converted just throw it away
	if ( !inputdata.value.Convert(FIELD_BOOLEAN) )
		return;

	//Msg("Setting %s to overridable %d\n", STRING(m_Ability), inputdata.value.Bool() );
	ABILITY_FILE_INFO_HANDLE handle = LookupAbilityInfoSlot(STRING(m_Ability) );

	g_pRTSResource->SetAbilityOverridable(m_iTeamID, inputdata.value.Bool(), handle);
}

//------------------------------------------------------------------------------
// Purpose:
//------------------------------------------------------------------------------
void CRTSAbilityController::InputSetAvailable( inputdata_t &inputdata ) 
{
	// make sure it's a bool, if it can't be converted just throw it away
	if ( !inputdata.value.Convert(FIELD_BOOLEAN) )
		return;

	//Msg("Setting %s to available %d\n", STRING(m_Ability), inputdata.value.Bool() );

	ABILITY_FILE_INFO_HANDLE handle = LookupAbilityInfoSlot(STRING(m_Ability) );
	g_pRTSResource->ModifyAbilityState(m_iTeamID, inputdata.value.Bool(), handle );
}
