class CheckFreeWorkspot extends AIbehaviorconditionScript
{
	editable var AIAction : gamedataWorkspotActionType;
	var workspotObject : weak< GameObject >;
	var workspotData : WorkspotEntryData;
	var globalRef : GlobalNodeRef;

	protected override function Activate( context : ScriptExecutionContext )
	{
		SetUpdateInterval( context, RandomizeOffsetForUpdateInterval( 0.2 ) );
	}

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		workspotObject = ScriptExecutionContext.GetArgumentObject( context, 'StimTarget' );
		workspotData = workspotObject.GetFreeWorkspotDataForAIAction( AIAction );
		globalRef = ResolveNodeRef( workspotData.workspotRef, GlobalNodeID.GetRoot() );
		if( GlobalNodeRef.IsDefined( globalRef ) )
		{
			workspotData.isAvailable = false;
			ScriptExecutionContext.SetArgumentNodeRef( context, 'WorkspotNode', workspotData.workspotRef );
			return true;
		}
		return false;
	}

	protected override function Deactivate( context : ScriptExecutionContext )
	{
		if( GlobalNodeRef.IsDefined( globalRef ) )
		{
			workspotData.isAvailable = true;
		}
	}

}

