/***********************************************************************/
/** Red Engine Script file
/***********************************************************************/
/** Exports & sample code for Reactions
/** Copyright © 2013
/***********************************************************************/

//----------------- Manager --------------------------//

/**
 * Manages sending and receiving interest points to actors
 */
import class CReactionsManager
{
	// Broadcasts a static interest point to the interested actors
	import final function BroadcastStaticInterestPoint( interestPoint : CInterestPoint, position : Vector, optional timeout : float );
	// Broadcasts a dynamic interest point to the interested actors
	import final function BroadcastDynamicInterestPoint( interestPoint : CInterestPoint, node : CNode, optional timeout : float );
	
	// Sends a static interest point to the interested actors
	import final function SendStaticInterestPoint( target : CNewNPC, interestPoint : CInterestPoint, position : Vector, optional timeout : float );
	// Sends a dynamic interest point to the interested actors
	import final function SendDynamicInterestPoint( target : CNewNPC, interestPoint : CInterestPoint, node : CNode, optional timeout : float );
};

//----------------- Interest point --------------------------//

/**
 * An interest point definition. Interest points have a feature of 'being interesting'
 * to actors which contain a reaction to the field the point is emitting.
 */
import class CInterestPoint
{	
};

// An interest point one can define in scripts
import class CScriptedInterestPoint extends CInterestPoint
{	
	function SetupInstance( instance : CInterestPointInstance, source : IScriptable )
	{
		// Set parameter for field generated by source. Example : sound loudness
		instance.SetFieldStrengthMultiplier( 0.0f );
	}
};

//----------------- Interest point instance --------------------------//

/**
 * An instance of the interest point, located somewhere in the game world.
 */
import class CInterestPointInstance
{
	// Returns the parent point of this instance
	import final function GetParentPoint() : CInterestPoint;
	// Returns the present world position of the interest point instance
	import final function GetWorldPosition() : Vector;
	// Returns the node the point is attached to (if there's one)
	import final function GetNode() : CNode;
	
	// Returns the name of the field the point emits
	import final function GetGeneratedFieldName() : name;
	// Get field strength at given point
	import final function GetFieldStrength( position : Vector ) : float;
	
	// Set instance parameter (used as a multiplier for potential field generation)
	import final function SetFieldStrengthMultiplier( param : float );
	// Get instance parameter
	import final function GetFieldStrengthMultiplier() : float;

	// Set parameter by test function (used 
	import final function SetTestParameter( param : float );
	// Get parameter set by test function
	import final function GetTestParameter() : float;
};

//----------------- Reaction condition --------------------------//

// A reaction condition one can define in scripts
import class CReactionScriptedCondition extends IReactionCondition
{
	function Perform( source : CNode, target : CNode, interestPoint : CInterestPointInstance ) : bool
	{
		// Here goes condition code
		return true;
	}
};

class CReactionRandomCondition extends CReactionScriptedCondition
{
	editable var percentageChance : int;

	function Perform( source : CNode, target : CNode, interestPoint : CInterestPointInstance ) : bool
	{		
		if ( (RandF() * 100.0f) < (float)percentageChance )
		{
			return true;
		}
		return false;
	}
};

//----------------- Reaction action --------------------------//

// A reaction one can define in scripts
import class CReactionScript extends IReactionAction
{
	function Perform( npc : CNewNPC, interestPoint : CInterestPointInstance, reactionIndex : int )
	{
		// Here goes reaction code
	}
};