1 with Ada
.Text_IO
; use Ada
.Text_IO
;
2 with Ada
.Float_Text_IO
; use Ada
.Float_Text_IO
;
4 with Simulator
.Controller
;
7 with Simulator
.Car
.Gui
; use Simulator
.Car
.Gui
;
10 with Gtk
.Label
; use Gtk
.Label
;
11 with Gtk
.Button
; use Gtk
.Button
;
12 with Gtk
.Scale
; use Gtk
.Scale
;
14 package body Simulator
.Car
is
15 package DurationIO
is new Ada
.Text_IO
.Fixed_Io
(Duration);
18 -- Oggetto che iidentifica l'auto. Non può essere locale alle funzioni.
19 Own_Car
: aliased Car_Type
;
21 --Task da eseguire solo quando Own_Car è inizializzato completamente
23 type Racer_Access
is access Racer
;
24 Racer_Instance
: Racer_Access
;
28 Simulator
.Track
.PutOnPitLane
(Own_Car
.CarProperties
);
29 Print
("Il task Racer terminato. Simulazione conclusa");
32 function Init
(Tires
: Tires_T
;
33 CarWeight
: CarWeight_T
;
35 CarPerformance
: CarPerformance_T
) return Boolean is
36 use Simulator
.Controller
;
38 Registered
: Boolean := False;
41 --iscrivo l'auto alla gara e ottengo l'id dell'auto
42 Print
("LOG: Registro l'auto alla corsa.");
43 Simulator
.Controller
.GetRace
.CarRegister
(id
, Success
);
44 if (Success
= True) then
45 --creo l'istanza di CarProperties_T
46 Own_Car
.CarProperties
:= (id
,Tires
,0.0,CarFuel
,CarPerformance
);
47 Registered
:= Simulator
.Controller
.RegisterCar
(Own_Car
'Access, id
);
48 -- aggiorno GUI con il nuovo id
49 Set_Text
(ValId
, Own_Car
.CarProperties
.CarId
'Img);
50 Print
("LOG: Auto inizializzata. Parametri: " & Own_Car
.CarProperties
.CarId
'Img &","& Own_Car
.CarProperties
.Tires
'Img&","&Own_Car
.CarProperties
.CarPerformance
'Img&","&Own_Car
.CarProperties
.CarFuel
'Img&"." );
51 Racer_Instance
:= new Racer
;
52 SetWinTitle
("Car "&id
'Img);
59 --PROCEDURE DI SERVIZIO
61 -- chiamata a procedura di circuito che avverte di fermarsi
62 -- ai box appena possibile
63 procedure CallForPitStop
(CarFuel
:CarFuel_T
; Tires
:Tires_T
) is
65 Simulator
.Track
.CallForPitStop
(Own_Car
.CarProperties
.CarId
,CarFuel
, Tires
);
68 -- chiamata a procedura di gara che permette di ritirare
69 -- un auto dalla corsa
70 CurrentLap
: Integer := 0;
71 FuelLevel
: Integer :=0;
72 TyresLevel
: Float := 0.0;
73 PitStopRequest
: Boolean := False;
77 Simulator
.Controller
.GetRace
.Kill
(Own_Car
.CarProperties
.CarId
);
80 procedure UpdateProperties
(This
: access Car_Type
;
83 TiresConsumption
: TiresConsumption_T
;
85 CarPerformance
: CarPerformance_T
;
89 SectorDuration
: Duration) is
90 str
: String := "aaaaaaaaaa";
91 time
: String := "bbbbbbbbb";
93 This
.CarProperties
.CarId
:= CarId
;
94 This
.CarProperties
.Tires
:= Tires
;
95 This
.CarProperties
.TiresConsumption
:= TiresConsumption
;
96 This
.CarProperties
.CarFuel
:= CarFuel
;
97 This
.CarProperties
.CarPerformance
:= CarPerformance
;
99 if (Lap
/= CurrentLap
or else Lap
=0) then
101 SetUsage
(FuelLevel
- Integer(Get_Value
(ValFuel
)),Float(Get_Value
(ValTyresConsum
)) - TyresLevel
) ;
103 FuelLevel
:= Integer(Own_Car
.CarProperties
.CarFuel
);
104 TyresLevel
:=Float(Own_Car
.CarProperties
.TiresConsumption
);
109 Set_Value
(ValFuel
, GDouble
(Own_Car
.CarProperties
.CarFuel
));
110 Set_Value
(ValTyresConsum
, GDouble
(Own_Car
.CarProperties
.TiresConsumption
));
112 if ((Get_Value
(ValFuel
) <= Get_Value
(ValFuelLimit
) or else Get_Value
(ValTyresConsum
) >= Get_Value
(ValTyresConsumLimit
)) and then PitStopRequest
= False) then
114 PitStopRequest
:= True;
118 Put
(str
, Float(Speed
*3.6), Aft
=> 3, Exp
=> 0);
119 DurationIO
.Put
(time
, SectorDuration
, Aft
=> 3);
121 if (Sector
= 500) then
123 Print
("LOG: Tratto: "&"Box"&","&time
&"s,"&str
&"km/h.");
124 PitStopRequest
:= False;
127 Print
("LOG: Tratto: "&Sector
'Img&","&time
&"s,"&str
&"km/h.");
129 end UpdateProperties
;