package Entities.Triggers is
-- A Trigger is an entity that performs an action when a condition is met at
-- a configurable time. For example, when a player collides with a trigger,
-- a new level may be loaded.
type Trigger is abstract new Entity with private;
type A_Trigger is access all Trigger'Class;
-- Implement this procedure to execute the trigger's action. Execute is
-- called when the conditions for executing the trigger are met. 'action' is
-- canonically lower case. 'activator' may be null if there is no activating
-- entity. (ie: executing on world load)
procedure Execute( this : access Trigger;
action,
argument : String;
activator : A_Entity ) is abstract;
-- A class pattern that matches all trigger class ids registered in the
-- entity factory.
CLASS_PATTERN : constant String := "Entities.Triggers.*";
private
-- Valid values for the "When" attribute are:
-- OnActivate - The player manually activated a trigger
-- OnLoad - The world was loaded
-- OnTouch - The player touched the trigger (once per collision)
WHEN_ATTR : constant String := "When"; -- when the trigger may trip
CONDITION_ATTR : constant String := "Condition"; -- the necessary condition
ACTION_ATTR : constant String := "Action"; -- what the trigger will do
ARG_ATTR : constant String := "Argument"; -- parameterizes the action
type Trigger is abstract new Entity with
record
activatable : Boolean := True;
end record;
-- Raises an exception if 'icon' can't be found in library 'libName'.
procedure Construct( this : access Trigger;
libName : String;
icon : String );
-- Evaluates the given conditional expression and returns the result. If
-- the expression can't be properly evaluated, the result will be False.
function Evaluate( this : not null access Trigger'Class;
expression : String ) return Boolean;
procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Trigger );
for Trigger'Read use Object_Read;
procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Trigger );
for Trigger'Write use Object_Write;
-- Called when the trigger is manually activated by entity 'activator'.
-- Don't override this procedure.
procedure On_Activate( this : access Trigger;
activator : not null A_Entity );
-- Called when the trigger is touched by an entity. Don't override this
-- procedure.
procedure On_Collide( this : access Trigger; e : not null A_Entity );
-- Called when the triggers's world is loaded from disk. Don't override this
-- procedure.
procedure On_Load( this : access Trigger );
-- Deletes the Trigger.
procedure Delete( this : in out A_Trigger );
pragma Postcondition( this = null );
end Entities.Triggers;