1. -- 
  2. -- Uwe R. Zimmer, Australia, July 2011 
  3. -- 
  4.  
  5. with Ada.Task_Identification;     use Ada.Task_Identification; 
  6.  
  7. with Swarm_Configuration;         use Swarm_Configuration; 
  8. with Swarm_Data;                 use Swarm_Data; 
  9. with Swarm_Structures;           use Swarm_Structures; 
  10. with Vehicle_Task_Id;            use Vehicle_Task_Id; 
  11.  
  12. package body Vehicle_Interface is 
  13.  
  14.    use Swarm_Vectors; 
  15.  
  16.    -- 
  17.  
  18.    function Position return Positions is 
  19.  
  20.    begin 
  21.       return Element (Swarm_State, Id_Task (Current_Task)).Position; 
  22.    end Position; 
  23.  
  24.    -- 
  25.  
  26.    function Velocity return Velocities is 
  27.  
  28.    begin 
  29.       return Element (Swarm_State, Id_Task (Current_Task)).Velocity; 
  30.    end Velocity; 
  31.  
  32.    -- 
  33.  
  34.    function Acceleration return Accelerations is 
  35.  
  36.    begin 
  37.       return Element (Swarm_State, Id_Task (Current_Task)).Acceleration; 
  38.    end Acceleration; 
  39.  
  40.    ------------------ 
  41.    -- Set_Steering -- 
  42.    ------------------ 
  43.  
  44.    procedure Set_Destination (V : Vector_3D) is 
  45.  
  46.    begin 
  47.       Element (Swarm_State, Id_Task (Current_Task)).Controls.Set_Steering (V); 
  48.    end Set_Destination; 
  49.  
  50.    ------------------ 
  51.    -- Set_Thruttle -- 
  52.    ------------------ 
  53.  
  54.    procedure Set_Throttle (T : Throttle_T) is 
  55.  
  56.    begin 
  57.       Element (Swarm_State, Id_Task (Current_Task)).Controls.Set_Throttle (T); 
  58.    end Set_Throttle; 
  59.  
  60.    -- 
  61.  
  62.    function Throttle_Is_On_Idle return Boolean is 
  63.  
  64.    begin 
  65.       return Element (Swarm_State, Id_Task (Current_Task)).Controls.Read_Throttle = Idle_Throttle; 
  66.    end Throttle_Is_On_Idle; 
  67.  
  68.    ---------- 
  69.    -- Send -- 
  70.    ---------- 
  71.  
  72.    procedure Send (Message :     Inter_Vehicle_Messages) is 
  73.  
  74.    begin 
  75.       Element (Swarm_State, Id_Task (Current_Task)).Comms.Send (Message); 
  76.    end Send; 
  77.  
  78.    ------------- 
  79.    -- Receive -- 
  80.    ------------- 
  81.  
  82.    procedure Receive (Message : out Inter_Vehicle_Messages) is 
  83.  
  84.    begin 
  85.       Element (Swarm_State, Id_Task (Current_Task)).Comms.Receive (Message); 
  86.    end Receive; 
  87.  
  88.    -- 
  89.  
  90.    function Messages_Waiting return Boolean is 
  91.  
  92.    begin 
  93.       return Element (Swarm_State, Id_Task (Current_Task)).Comms.Has_Incoming_Messages; 
  94.    end Messages_Waiting; 
  95.  
  96.    -- 
  97.  
  98.    function Current_Charge return Vehicle_Charges is 
  99.  
  100.    begin 
  101.       return Element (Swarm_State, Id_Task (Current_Task)).Charge.Level; 
  102.    end Current_Charge; 
  103.  
  104.    -- 
  105.  
  106.    function Discharge_Per_Sec return Float is 
  107.  
  108.    begin 
  109.       return Charging_Setup.Discharge_Rate_Per_Sec; 
  110.    end Discharge_Per_Sec; 
  111.  
  112.    -- 
  113.  
  114.    function Energy_Globes_Around return Energy_Globes_A is 
  115.  
  116.       Globes_Found          : Natural                         := 0; 
  117.       Globes_Detected       : array (Globes'Range) of Boolean := (others => False); 
  118.       This_Element_Position : constant Positions              := Element (Swarm_State, Id_Task (Current_Task)).Position; 
  119.  
  120.    begin 
  121.       for Globe_Ix in Globes'Range loop 
  122.          if abs (This_Element_Position - Globes (Globe_Ix).Position) <= Energy_Globe_Detection then 
  123.             Globes_Detected (Globe_Ix) := True; 
  124.             Globes_Found := Globes_Found + 1; 
  125.          end if; 
  126.       end loop; 
  127.  
  128.       declare 
  129.          Found_Globes : Energy_Globes_A (1 .. Globes_Found); 
  130.          Found_Globes_Ix : Natural := Globes'First; 
  131.       begin 
  132.          for Globe_Ix in Globes'Range loop 
  133.             if Globes_Detected (Globe_Ix) then 
  134.                Found_Globes (Found_Globes_Ix) := Globes (Globe_Ix); 
  135.                Found_Globes_Ix := Found_Globes_Ix + 1; 
  136.             end if; 
  137.          end loop; 
  138.          return Found_Globes; 
  139.       end; 
  140.    end Energy_Globes_Around; 
  141.  
  142.    -- 
  143.  
  144.    procedure Wait_For_Next_Physics_Update is 
  145.  
  146.    begin 
  147.       Simulator_Tick.Wait_For_Next_Tick; 
  148.    end Wait_For_Next_Physics_Update; 
  149.  
  150.    -- 
  151.  
  152. end Vehicle_Interface;