1. with Events; 
  2. with Maps;                              use Maps; 
  3.  
  4. pragma Elaborate_All( Events ); 
  5.  
  6. package Events.World is 
  7.  
  8.     CREATE_WORLD_ID : constant Event_Id := To_Event_Id( "Create_World" ); 
  9.  
  10.     -- A command to create a new, empty world. 
  11.     type Create_World_Event is new Event with private; 
  12.     type A_Create_World_Event is access all Create_World_Event'Class; 
  13.  
  14.     -- Returns the domain of the world to create (map, platform, etc.) 
  15.     function Get_Domain( this : not null access Create_World_Event'Class ) return String; 
  16.     pragma Postcondition( Get_Domain'Result'Length > 0 ); 
  17.  
  18.     -- Returns the height of the new world in tiles. 
  19.     function Get_Height( this : not null access Create_World_Event'Class ) return Positive; 
  20.  
  21.     -- Returns the name of the library to be used for tiles. 
  22.     function Get_Library_Name( this : not null access Create_World_Event'Class ) return String; 
  23.     pragma Postcondition( Get_Library_Name'Result'Length > 0 ); 
  24.  
  25.     -- Returns the width of the new world in tiles. 
  26.     function Get_Width( this : not null access Create_World_Event'Class ) return Positive; 
  27.  
  28.     ---------------------------------------------------------------------------- 
  29.  
  30.     LOAD_WORLD_ID : constant Event_Id := To_Event_Id( "Load_World" ); 
  31.  
  32.     -- A command to load a world from disk. 
  33.     type Load_World_Event is new Event with private; 
  34.     type A_Load_World_Event is access all Load_World_Event'Class; 
  35.  
  36.     -- Returns the filename of the world to load. 
  37.     function Get_Filename( this : not null access Load_World_Event'Class ) return String; 
  38.  
  39.     ---------------------------------------------------------------------------- 
  40.  
  41.     NEW_WORLD_ID : constant Event_Id := To_Event_Id( "New_World" ); 
  42.  
  43.     -- A notification that a new world has been loaded/created/resized. 
  44.     type New_World_Event is new Event with private; 
  45.     type A_New_World_Event is access all New_World_Event'Class; 
  46.  
  47.     -- Returns the height of the world in tiles. 
  48.     function Get_Height( this : not null access New_World_Event'Class ) return Positive; 
  49.  
  50.     -- Returns the world map as an array of tile layers. 
  51.     function Get_Layers( this : not null access New_World_Event'Class ) return A_Layer_Array; 
  52.     pragma Postcondition( Get_Layers'Result /= null ); 
  53.  
  54.     -- Returns the name of the library used for tiles. 
  55.     function Get_Library_Name( this : not null access New_World_Event'Class ) return String; 
  56.     pragma Postcondition( Get_Library_Name'Result'Length > 0 ); 
  57.  
  58.     -- Returns the width of a tile in the world in pixels. 
  59.     function Get_Tile_Width( this : not null access New_World_Event'Class ) return Positive; 
  60.  
  61.     -- Returns the width of the world in tiles. 
  62.     function Get_Width( this : not null access New_World_Event'Class ) return Positive; 
  63.  
  64.     ---------------------------------------------------------------------------- 
  65.  
  66.     RESIZE_WORLD_ID : constant Event_Id := To_Event_Id( "Resize_World" ); 
  67.  
  68.     -- A command to resize the world map. 
  69.     type Resize_World_Event is new Event with private; 
  70.     type A_Resize_World_Event is access all Resize_World_Event'Class; 
  71.  
  72.     -- Returns the new height of the map in tiles. 
  73.     function Get_Height( this : not null access Resize_World_Event'Class ) return Positive; 
  74.  
  75.     -- Returns the new width of the map in tiles. 
  76.     function Get_Width( this : not null access Resize_World_Event'Class ) return Positive; 
  77.  
  78.     ---------------------------------------------------------------------------- 
  79.  
  80.     SET_TILE_ID : constant Event_Id := To_Event_Id( "Set_Tile" ); 
  81.  
  82.     -- A command to set the tile id at a specific location. 
  83.     type Set_Tile_Event is new Event with private; 
  84.     type A_Set_Tile_Event is access all Set_Tile_Event'Class; 
  85.  
  86.     -- Returns the layer of the tile to set. 
  87.     function Get_Layer( this : not null access Set_Tile_Event'Class ) return Integer; 
  88.  
  89.     -- Returns new tile id to set. 
  90.     function Get_Tile_ID( this : not null access Set_Tile_Event'Class ) return Natural; 
  91.  
  92.     -- Returns the X coordinate of the tile to set. 
  93.     function Get_X( this : not null access Set_Tile_Event'Class ) return Float; 
  94.  
  95.     -- Returns the Y coordinate of the tile to set. 
  96.     function Get_Y( this : not null access Set_Tile_Event'Class ) return Float; 
  97.  
  98.     ---------------------------------------------------------------------------- 
  99.  
  100.     SET_WORLD_PROPERTY_ID : constant Event_Id := To_Event_Id( "Set_World_Property" ); 
  101.  
  102.     -- A command to set the value of a world property. 
  103.     type Set_World_Property_Event is new Event with private; 
  104.     type A_Set_World_Property_Event is access all Set_World_Property_Event'Class; 
  105.  
  106.     -- Returns the name of the property that changed. 
  107.     function Get_Property_Name( this : not null access Set_World_Property_Event'Class ) return String; 
  108.     pragma Postcondition( Get_Property_Name'Result'Length > 0 ); 
  109.  
  110.     -- Returns the new value of the world property. 
  111.     function Get_Value( this : not null access Set_World_Property_Event'Class ) return String; 
  112.  
  113.     ---------------------------------------------------------------------------- 
  114.  
  115.     TILE_CHANGED_ID : constant Event_Id := To_Event_Id( "Tile_Changed" ); 
  116.  
  117.     -- A notification that a tile in the map changed. 
  118.     type Tile_Changed_Event is new Event with private; 
  119.     type A_Tile_Changed_Event is access all Tile_Changed_Event'Class; 
  120.  
  121.     -- Returns the map layer of the tile that changed. 
  122.     function Get_Layer( this : not null access Tile_Changed_Event'Class ) return Integer; 
  123.  
  124.     -- Returns the new tile id. 
  125.     function Get_Tile_ID( this : not null access Tile_Changed_Event'Class ) return Natural; 
  126.  
  127.     -- Returns the X coordinate of the tile that changed. 
  128.     function Get_X( this : not null access Tile_Changed_Event'Class ) return Natural; 
  129.  
  130.     -- Returns the Y coordinate of the tile that changed. 
  131.     function Get_Y( this : not null access Tile_Changed_Event'Class ) return Natural; 
  132.  
  133.     ---------------------------------------------------------------------------- 
  134.  
  135.     WORLD_MODIFIED_ID : constant Event_Id := To_Event_Id( "World_Modified" ); 
  136.  
  137.     -- A notification that the world has been modified somehow. 
  138.     type World_Modified_Event is new Event with private; 
  139.     type A_World_Modified_Event is access all World_Modified_Event'Class; 
  140.  
  141.     ---------------------------------------------------------------------------- 
  142.  
  143.     WORLD_PROPERTY_CHANGED_ID : constant Event_Id := To_Event_Id( "World_Property_Changed" ); 
  144.  
  145.     -- A notification that a world property changed. 
  146.     type World_Property_Changed_Event is new Event with private; 
  147.     type A_World_Property_Changed_Event is access all World_Property_Changed_Event'Class; 
  148.  
  149.     -- Returns the name of the property that changed. 
  150.     function Get_Property_Name( this : not null access World_Property_Changed_Event'Class ) return String; 
  151.     pragma Postcondition( Get_Property_Name'Result'Length > 0 ); 
  152.  
  153.     -- Returns the property's new value. 
  154.     function Get_Value( this : not null access World_Property_Changed_Event'Class ) return String; 
  155.  
  156.     ---------------------------------------------------------------------------- 
  157.  
  158.     -- Creates a new, empty world synchronously. An exception is raised on error. 
  159.     procedure Trigger_Create_World( width, 
  160.                                     height : Positive; 
  161.                                     libName, 
  162.                                     domain : String ); 
  163.     pragma Precondition( libName'Length > 0 ); 
  164.     pragma Precondition( domain'Length > 0 ); 
  165.  
  166.     -- Load a world from disk asynchronously. 
  167.     procedure Queue_Load_World( filename : String ); 
  168.  
  169.     -- Loads a world from disk synchronously. An exception is raised on error. 
  170.     procedure Trigger_Load_World( filename : String ); 
  171.     pragma Precondition( filename'Length > 0 ); 
  172.  
  173.     -- A world has been loaded into the Game, by loading from disk, by creating 
  174.     -- a new world, etc. 
  175.     procedure Queue_New_World( width, 
  176.                                height, 
  177.                                tileWidth : Positive; 
  178.                                layers    : not null A_Layer_Array; 
  179.                                libName   : String ); 
  180.     pragma Precondition( libName'Length > 0 ); 
  181.  
  182.     -- Resizes the world sychronously. An exception is raised on failure. 
  183.     -- (ie: parameters rejected) 
  184.     procedure Trigger_Resize_World( width, height : Positive ); 
  185.  
  186.     -- Set a tile in the world by location (layer, x, y). 
  187.     procedure Queue_Set_Tile( layer   : Integer; 
  188.                               x, y    : Float;      -- world pixel coordinates 
  189.                               tile_id : Natural ); 
  190.  
  191.     -- Asynchronously set a world property. Below is a list of the basic 
  192.     -- properties used by the engine. Additional properties can be added by a 
  193.     -- game implementation. To add a new property, just set it. 
  194.     -- 
  195.     -- Basic world properties: 
  196.     -- "filename"     : the filename 
  197.     -- "music"        : the background music track name 
  198.     -- "introduction" : the introduction text 
  199.     procedure Queue_Set_World_Property( name, value : String ); 
  200.     pragma Precondition( name'Length > 0 ); 
  201.  
  202.     -- A tile in the world has changed. 
  203.     procedure Queue_Tile_Changed( layer   : Integer; 
  204.                                   x, y    : Natural; 
  205.                                   tile_id : Natural ); 
  206.  
  207.     -- Something about the world has changed. This is an indication that the 
  208.     -- world has changed since it was loaded from disk. 
  209.     procedure Queue_World_Modified; 
  210.  
  211.     -- A property of the world has changed. Below is a list of the basic 
  212.     -- properties used by the engine. Additional properties can be added by a 
  213.     -- game implementation. 
  214.     -- 
  215.     -- Basic world properties: 
  216.     -- "filename"     : the filename 
  217.     -- "music"        : the background music track name 
  218.     -- "introduction" : the introduction text 
  219.     procedure Queue_World_Property_Changed( name, value : String ); 
  220.     pragma Precondition( name'Length > 0 ); 
  221.  
  222. private 
  223.  
  224.     type Create_World_Event is new Event with 
  225.         record 
  226.             width, 
  227.             height  : Positive := 1; 
  228.             libName : Unbounded_String; 
  229.             domain  : Unbounded_String; 
  230.         end record; 
  231.  
  232.     procedure Construct( this    : access Create_World_Event; 
  233.                          width, 
  234.                          height  : Positive; 
  235.                          libName, 
  236.                          domain  : String ); 
  237.     pragma Precondition( libName'Length > 0 ); 
  238.     pragma Precondition( domain'Length > 0 ); 
  239.  
  240.     ---------------------------------------------------------------------------- 
  241.  
  242.     type Load_World_Event is new Event with 
  243.         record 
  244.             filename : Unbounded_String; 
  245.         end record; 
  246.  
  247.     procedure Construct( this : access Load_World_Event; filename : String ); 
  248.  
  249.     function To_String( this : access Load_World_Event ) return String; 
  250.  
  251.     ---------------------------------------------------------------------------- 
  252.  
  253.     type New_World_Event is new Event with 
  254.         record 
  255.             width, 
  256.             height, 
  257.             tileWidth : Positive := 1; 
  258.             layers    : A_Layer_Array := null; 
  259.             libName   : Unbounded_String; 
  260.         end record; 
  261.  
  262.     procedure Adjust( this : access New_World_Event ); 
  263.  
  264.     procedure Construct( this      : access New_World_Event; 
  265.                          width, 
  266.                          height, 
  267.                          tileWidth : Positive; 
  268.                          layers    : not null A_Layer_Array; 
  269.                          libName   : String ); 
  270.     pragma Precondition( libName'Length > 0 ); 
  271.  
  272.     procedure Delete( this : in out New_World_Event ); 
  273.  
  274.     ---------------------------------------------------------------------------- 
  275.  
  276.     type Resize_World_Event is new Event with 
  277.         record 
  278.             width, 
  279.             height : Positive := 1; 
  280.         end record; 
  281.  
  282.     procedure Construct( this   : access Resize_World_Event; 
  283.                          width, 
  284.                          height : Positive ); 
  285.  
  286.     ---------------------------------------------------------------------------- 
  287.  
  288.     type Set_Tile_Event is new Event with 
  289.         record 
  290.             layer   : Integer := 0; 
  291.             x, y    : Float := 0.0; 
  292.             tile_id : Natural := 0; 
  293.         end record; 
  294.  
  295.     procedure Construct( this    : access Set_Tile_Event; 
  296.                          layer   : Integer; 
  297.                          x, y    : Float; 
  298.                          tile_id : Natural ); 
  299.  
  300.     ---------------------------------------------------------------------------- 
  301.  
  302.     type Set_World_Property_Event is new Event with 
  303.         record 
  304.             name, 
  305.             value : Unbounded_String; 
  306.         end record; 
  307.  
  308.     procedure Construct( this  : access Set_World_Property_Event; 
  309.                          name, 
  310.                          value : String ); 
  311.     pragma Precondition( name'Length > 0 ); 
  312.  
  313.     function To_String( this : access Set_World_Property_Event ) return String; 
  314.  
  315.     ---------------------------------------------------------------------------- 
  316.  
  317.     type Tile_Changed_Event is new Event with 
  318.         record 
  319.             layer   : Integer := 0; 
  320.             x, y    : Natural := 0; 
  321.             tile_id : Natural := 0; 
  322.         end record; 
  323.  
  324.     procedure Construct( this    : access Tile_Changed_Event; 
  325.                          layer   : Integer; 
  326.                          x, y    : Natural; 
  327.                          tile_id : Natural ); 
  328.  
  329.     ---------------------------------------------------------------------------- 
  330.  
  331.     type World_Modified_Event is new Event with null record; 
  332.  
  333.     ---------------------------------------------------------------------------- 
  334.  
  335.     type World_Property_Changed_Event is new Event with 
  336.         record 
  337.             name, 
  338.             value : Unbounded_String; 
  339.         end record; 
  340.  
  341.     procedure Construct( this  : access World_Property_Changed_Event; 
  342.                          name, 
  343.                          value : String ); 
  344.     pragma Precondition( name'Length > 0 ); 
  345.  
  346.     function To_String( this : access World_Property_Changed_Event ) return String; 
  347.  
  348. end Events.World;