text
stringlengths
0
234
Function Definition: procedure Forward_All_Messages is
Function Body: begin
for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop
Forward_Messages (Element_Index);
end loop;
end Forward_All_Messages;
--
--
--
procedure Move_Element (Element_Index : Swarm_Element_Index) is
This_Element : Swarm_Element_State := Element (Swarm_State, Element_Index);
Interval : constant Real := Real'Min (Real (To_Duration (Clock - This_Element.Last_Update)), Max_Update_Interval);
begin
This_Element.Velocity.all.Write (This_Element.Velocity.all.Read + (Interval * This_Element.Acceleration.all.Read));
declare
Move_Start : constant Positions := This_Element.Position.all.Read;
Move_End : constant Positions := Move_Start + (Interval * This_Element.Velocity.all.Read);
begin
This_Element.Position.all.Write (Move_End);
This_Element.Charge.Level := Vehicle_Charges
(Real'Max (Real (Empty_Charge),
Real'Min (Real (Full_Charge),
Real (This_Element.Charge.Level)
- (Interval
* (Charging_Setup.Constant_Discharge_Rate_Per_Sec
+ Charging_Setup.Propulsion_Discharge_Rate_Per_Sec * abs (This_Element.Acceleration.all.Read))))));
for Globe_Ix in Globes'Range loop
declare
Globe_Pos : constant Positions := Globes (Globe_Ix).Position.all.Read;
Interratio : constant Real := (Globe_Pos - Move_Start) * ((Move_End - Move_Start) / (abs (Move_End - Move_Start)));
Intersection : constant Positions := Move_Start + Interratio * (Move_End - Move_Start);
Touching : constant Boolean := abs (Intersection - Globe_Pos) <= Energy_Globe_Detection and then Interratio >= 0.0 and then Interratio <= 1.0;
Slot_Passed : constant Boolean := Clock - This_Element.Charge.Charge_Time.all.Read > Charging_Setup.Max_Globe_Interval;
begin
if (not This_Element.Charge.Globes_Touched (Globe_Ix) or else Slot_Passed) and then Touching then
if Slot_Passed then
This_Element.Charge.Globes_Touched := No_Globes_Touched;
This_Element.Charge.Charge_No := 0;
end if;
This_Element.Charge.Charge_No := This_Element.Charge.Charge_No + 1;
This_Element.Charge.Globes_Touched (Globe_Ix) := True;
This_Element.Charge.Charge_Time.all.Write (Clock);
if This_Element.Charge.Charge_No = Charging_Setup.Globes_Required then
This_Element.Charge.Level := Full_Charge;
This_Element.Charge.Charge_No := 0;
This_Element.Charge.Globes_Touched := No_Globes_Touched;
end if;
end if;
Function Definition: procedure Move_All_Elements is
Function Body: begin
for Element_Index in First_Index (Swarm_State) .. Last_Index (Swarm_State) loop
Move_Element (Element_Index);
end loop;
end Move_All_Elements;
--
--
--
procedure Update_Rotation (Element_Index : Swarm_Element_Index) is
function Vector_Yaw (In_Vector : Vector_3D) return Real is
(if In_Vector (x) = 0.0 and then In_Vector (z) = 0.0
then 0.0
else Arctan (In_Vector (x), In_Vector (z)));
function Vector_Pitch (In_Vector : Vector_3D) return Real is
((Pi / 2.0) - Angle_Between (In_Vector, (0.0, 1.0, 0.0)));
This_Element : constant Swarm_Element_State := Element (Swarm_State, Element_Index);
Velocity : constant Vector_3D := This_Element.Velocity.all.Read;
Element_Yaw : constant Real := Vector_Yaw (Velocity);
Element_Pitch : constant Real := Vector_Pitch (Velocity);
Rotation : constant Quaternion_Rotation := To_Rotation (0.0, -Element_Pitch, Element_Yaw + Pi);
Norm_Acc : constant Vector_3D := Rotate (This_Element.Acceleration.all.Read, Rotation);
Lateral_Acc : constant Real := Norm_Acc (x) * abs (Velocity);
Element_Roll : constant Real :=
Real'Max (-Pi / 2.0,
Real'Min (Pi / 2.0,
Lateral_Acc * (Pi / 2.0) / Max_Assumed_Acceleration));
begin
This_Element.Rotation.all.Write (To_Rotation (Element_Roll, -Element_Pitch, -Element_Yaw + Pi));
Replace_Element (Swarm_State, Element_Index, This_Element);