1. package Entities.Triggers is 
  2.  
  3.     -- A Trigger is an entity that performs an action when a condition is met at 
  4.     -- a configurable time. For example, when a player collides with a trigger, 
  5.     -- a new level may be loaded. 
  6.     type Trigger is abstract new Entity with private; 
  7.     type A_Trigger is access all Trigger'Class; 
  8.  
  9.     -- Implement this procedure to execute the trigger's action. Execute is 
  10.     -- called when the conditions for executing the trigger are met. 'action' is 
  11.     -- canonically lower case. 'activator' may be null if there is no activating 
  12.     -- entity. (ie: executing on world load) 
  13.     procedure Execute( this      : access Trigger; 
  14.                        action, 
  15.                        argument  : String; 
  16.                        activator : A_Entity ) is abstract; 
  17.  
  18.     -- A class pattern that matches all trigger class ids registered in the 
  19.     -- entity factory. 
  20.     CLASS_PATTERN : constant String := "Entities.Triggers.*"; 
  21.  
  22. private 
  23.  
  24.     -- Valid values for the "When" attribute are: 
  25.     --   OnActivate - The player manually activated a trigger 
  26.     --   OnLoad     - The world was loaded 
  27.     --   OnTouch    - The player touched the trigger (once per collision) 
  28.  
  29.     WHEN_ATTR      : constant String := "When";       -- when the trigger may trip 
  30.     CONDITION_ATTR : constant String := "Condition";  -- the necessary condition 
  31.     ACTION_ATTR    : constant String := "Action";     -- what the trigger will do 
  32.     ARG_ATTR       : constant String := "Argument";   -- parameterizes the action 
  33.  
  34.     type Trigger is abstract new Entity with 
  35.         record 
  36.             activatable : Boolean := True; 
  37.         end record; 
  38.  
  39.     -- Raises an exception if 'icon' can't be found in library 'libName'. 
  40.     procedure Construct( this    : access Trigger; 
  41.                          libName : String; 
  42.                          icon    : String ); 
  43.  
  44.     -- Evaluates the given conditional expression and returns the result. If 
  45.     -- the expression can't be properly evaluated, the result will be False. 
  46.     function Evaluate( this       : not null access Trigger'Class; 
  47.                        expression : String ) return Boolean; 
  48.  
  49.     procedure Object_Read( stream : access Root_Stream_Type'Class; obj : out Trigger ); 
  50.     for Trigger'Read use Object_Read; 
  51.  
  52.     procedure Object_Write( stream : access Root_Stream_Type'Class; obj : Trigger ); 
  53.     for Trigger'Write use Object_Write; 
  54.  
  55.     -- Called when the trigger is manually activated by entity 'activator'. 
  56.     -- Don't override this procedure. 
  57.     procedure On_Activate( this      : access Trigger; 
  58.                            activator : not null A_Entity ); 
  59.  
  60.     -- Called when the trigger is touched by an entity. Don't override this 
  61.     -- procedure. 
  62.     procedure On_Collide( this : access Trigger; e : not null A_Entity ); 
  63.  
  64.     -- Called when the triggers's world is loaded from disk. Don't override this 
  65.     -- procedure. 
  66.     procedure On_Load( this : access Trigger ); 
  67.  
  68.     -- Deletes the Trigger. 
  69.     procedure Delete( this : in out A_Trigger ); 
  70.     pragma Postcondition( this = null ); 
  71.  
  72. end Entities.Triggers;