mission2.adb

with GAda.Graphics ;
with Plongee ;
with Gada.Text_IO ;


procedure Mission2 is

   package Gr renames GAda.Graphics ;
   package PP renames Plongee ;
   package Txt renames Gada.Text_IO ;

   -- Duree max : 10 heures
   Temps_Max : constant Integer := 60 * 10 ;

   -- Remontee a  10 metres par minute
   Vitesse_Remontee : constant Integer := 10 ;

   -- La profondeur est exprimee en multiples de 10 metres.
   Coef_Profondeur : constant Integer := 10 ;

   -- Et la duree en multiples de 10 minutes
   Coef_Duree : constant Integer := 10 ;

   -- Calcul du temps de remontee.
   function Temps_Remontee (D : PP.T_Duree ; P : PP.T_Profondeur) return Natural is
      Temps_Voyage, Temps_Paliers, Temps_Total : Natural ;
      Paliers : PP.T_Resultat ;
   begin
      Paliers := PP.Table(P,D) ;
      if Paliers.Definis then
         -- Temps sans les paliers
         Temps_Voyage := (P * Coef_Profondeur) / Vitesse_Remontee ;

         -- Temps des paliers
         Temps_Paliers :=
           Paliers.Sequence.Trois +
           Paliers.Sequence.Six +
           Paliers.Sequence.Neuf +
           Paliers.Sequence.Douze +
           Paliers.Sequence.Quinze ;

         Temps_Total := Temps_Voyage + Temps_Paliers ;
      else
         Temps_Total := Temps_Max ;
      end if ;

      return Temps_Total ;
   end Temps_Remontee ;

   procedure Tester_Temps_Remontee (D : PP.T_Duree ; P : PP.T_Profondeur) is
   begin
      Txt.Put_Line ("Temps de remontee pour P = " & Integer'Image(P) &
                   " et D = " & Integer'Image(D) & "  ==  " & Integer'Image(Temps_Remontee(D, P)) & " minutes.") ;
   end Tester_Temps_Remontee ;

   -- Trouve la profondeur max a ne pas depasser.
   function Chercher_Profondeur (T : Natural ; D : PP.T_Duree) return PP.T_Profondeur is
      Prof : Natural ;
      Trouve : Boolean ;
   begin
      Prof := PP.T_Profondeur'First ;
      Trouve := False ;

      while (not Trouve) and (Prof <= PP.T_Profondeur'Last) loop
         if D * Coef_Duree + Temps_Remontee(D,Prof) > T then
            Trouve := True ;
         else
            Prof := Prof + 1 ;
         end if ;
      end loop ;

      if Trouve then return Prof ;
      else return PP.T_Profondeur'Last ;
      end if ;

   end Chercher_Profondeur ;

   procedure Tester_Chercher_Profondeur (T : Natural ; D : PP.T_Duree) is
   begin
      Txt.Put_Line("Chercher profondeur T = " & Integer'Image(T) & "  D = " & Integer'Image(D) &
                  "  ==  " & Integer'Image(Chercher_Profondeur(T, D)) & "0 metres.") ;
   end Tester_Chercher_Profondeur ;


   --
   -- Importe' de la mission 1
   --

   type T_Coords is record
      PosX, PosY : Integer ;
   end record ;

   -- Trace un cercle ou un disque
   procedure Disque (Position : T_Coords ; Duree : Natural) is
      Couleur : Gr.T_Couleur := (255, 80, 80) ;
   begin
      if Duree = 0 then Gr.Cercle(Position.PosX, Position.PosY, 5, Couleur) ;
      else Gr.Disque(Position.PosX, Position.PosY, 5, Couleur) ;
      end if ;
   end Disque ;

   -- Transformation d'un couple (D, P) en coordonnees
   function Transformer (D : PP.T_Duree ; P : PP.T_Profondeur) return T_Coords is
      Coords : T_Coords ;
   begin
      Coords.PosX := 40 + (D * 420) / 36 ;
      Coords.PosY := 360 - (P * 320) / 6 ;
      return Coords ;
   end Transformer ;


   --
   -- Suite
   --
   procedure Trace_Courbe_De_Securite (Capacite : Natural) is
   begin
      for D in PP.T_Duree loop
         Disque(Transformer(D, Chercher_Profondeur(Capacite, D)) , 1) ;
      end loop ;
   end Trace_Courbe_De_Securite ;

begin

   Gr.Resize(500,400) ;

   Tester_Temps_Remontee (6, 3) ;
   Tester_Chercher_Profondeur (110, 6) ;

   Trace_Courbe_De_Securite (120) ;

end Mission2 ;