class ActionTargetPrereq extends IScriptablePrereq
{
	var m_targetRecord : weak< AIActionTarget_Record >;
	var m_invert : Bool;

	protected override function Initialize( recordID : TweakDBID )
	{
		var prereqRecord : ActionTargetPrereq_Record;
		prereqRecord = TweakDBInterface.GetActionTargetPrereqRecord( recordID );
		m_targetRecord = prereqRecord.Target();
		m_invert = prereqRecord.Invert();
	}

	protected const override function OnApplied( state : PrereqState, game : GameInstance, context : IScriptable )
	{
		state.OnChanged( IsFulfilled( game, context ) );
	}

	public const override function IsFulfilled( game : GameInstance, context : IScriptable ) : Bool
	{
		var targetObject : weak< GameObject >;
		var owner : weak< ScriptedPuppet >;
		var ownerContext : ScriptExecutionContext;
		owner = ( ( weak< weak< ScriptedPuppet > > )( context ) );
		if( !( AIHumanComponent.GetScriptContext( owner, ownerContext ) ) )
		{
			return ( ( m_invert ) ? ( true ) : ( false ) );
		}
		if( !( AIActionTarget.GetObject( ownerContext, m_targetRecord, targetObject ) ) )
		{
			return ( ( m_invert ) ? ( true ) : ( false ) );
		}
		return ( ( m_invert ) ? ( false ) : ( true ) );
	}

}

