1. with Entities;                          use Entities; 
  2. with Hashed_Strings;                    use Hashed_Strings; 
  3. with Objects;                           use Objects; 
  4.  
  5. limited with Games; 
  6.  
  7. private with Object_Factory; 
  8.  
  9. pragma Elaborate_All( Object_Factory ); 
  10.  
  11. package Actors is 
  12.  
  13.     -- Actor is an abstract class which defines the behavior of an Entity. It 
  14.     -- should be subclassed and implemented once for each Entity subclass to be 
  15.     -- controlled. Actor subclasses register an allocator and the class name of 
  16.     -- the Entity they can control with the Actor Factory so that an appropriate 
  17.     -- Actor can be instantiated, given an Entity to control. 
  18.     type Actor is abstract new Limited_Object with private; 
  19.     type A_Actor is access all Actor'Class; 
  20.  
  21.     -- Creates a new actor, given a controllable entity's class name. The 
  22.     -- allocator used for creation is registered at elaboration time. 
  23.     function Create_Actor( entityClass : String ) return A_Actor; 
  24.     pragma Precondition( entityClass'Length > 0 ); 
  25.  
  26.     -- Handles Impulses given by a player. 
  27.     procedure Impulse( this : access Actor; name : Hashed_String ) is abstract; 
  28.  
  29.     -- This will be called when the game is paused. Override this to stop any 
  30.     -- on-going actions begun with a previous impulse so the entity doesn't 
  31.     -- continue doing something while gameplay is paused or when gameplay is 
  32.     -- resumed and the previously on-going action is no longer appropriate. 
  33.     procedure Pause( this : access Actor ) is null; 
  34.  
  35.     -- Returns True if the actor's lifespan is confined to the lifespan of the 
  36.     -- world in which its entity exists. The default for actors is True unless 
  37.     -- overridden. 
  38.     function Is_Temporal( this : access Actor ) return Boolean; 
  39.  
  40.     -- Sets the entity that the actor controls, returning True on acceptance. 
  41.     -- For non-temporal actors, this can be 'null' between worlds or before 
  42.     -- loading a world. The concrete subclasses should override this function to 
  43.     -- verify the entity's class before calling the base Set_Entity procedure. 
  44.     function Set_Entity( this : access Actor; e : A_Entity ) return Boolean; 
  45.  
  46.     -- Sets the entity that the actor controls. The actor must be able to 
  47.     -- control entities of the given class. 
  48.     procedure Set_Entity( this : not null access Actor'Class; e : A_Entity ); 
  49.  
  50.     -- Sets the Actor's reference to its parent Game object. 
  51.     procedure Set_Game( this : not null access Actor'Class; 
  52.                         game : not null access Games.Game'Class ); 
  53.  
  54.     -- Deletes an Actor object. 
  55.     procedure Delete( this : in out A_Actor ); 
  56.  
  57.     ---------------------------------------------------------------------------- 
  58.  
  59.     -- Initializes the Actor factory for use. This should be called after all 
  60.     -- allocators have been registered. 
  61.     procedure Initialize; 
  62.  
  63.     -- Finalizes the Actor factory. This should be called before exiting. 
  64.     procedure Finalize; 
  65.  
  66. private 
  67.  
  68.     type Actor is abstract new Limited_Object with 
  69.         record 
  70.             entity : A_Entity := null;                 -- this is not owned by the actor 
  71.             game   : access Games.Game'Class := null;  -- the actor's parent game object 
  72.         end record; 
  73.  
  74.     ---------------------------------------------------------------------------- 
  75.  
  76.     package Factory is new Object_Factory( Actor, A_Actor, Delete ); 
  77.  
  78. end Actors;