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