< Summary

Information
Class: Trailblazer.Navigation.Motor.FlyLocomotion
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/FlyLocomotion.cs
Line coverage
100%
Covered lines: 31
Uncovered lines: 0
Coverable lines: 31
Total lines: 125
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.cctor()100%11100%
.ctor()100%11100%
get_IsEnabled()100%11100%
set_IsEnabled(...)100%22100%
RecordData(...)100%44100%

File(s)

/home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/FlyLocomotion.cs

#LineLine coverage
 1using Chronicler;
 2using FixedMathSharp;
 3using Trailblazer.Support;
 4
 5namespace Trailblazer.Navigation.Motor;
 6
 7/// <summary>
 8/// Handles controlled flight movement while the scout is airborne.
 9/// </summary>
 10/// <remarks>
 11/// Flight is distinct from both jumping and falling.
 12/// It provides active air control, optional gravity cancellation, and controlled ascent or descent.
 13/// </remarks>
 14public class FlyLocomotion : ILocomotion
 15{
 16    #region Constants
 17
 18    /// <summary>
 19    /// Default maximum horizontal flight speed.
 20    /// </summary>
 121    public static readonly Fixed64 DefaultMaxFlySpeed = (Fixed64)1.5d;
 22
 23    /// <summary>
 24    /// Default maximum upward flight speed.
 25    /// </summary>
 126    public static readonly Fixed64 DefaultMaxAscendSpeed = (Fixed64)1.5d;
 27
 28    /// <summary>
 29    /// Default maximum downward flight speed while actively descending.
 30    /// </summary>
 131    public static readonly Fixed64 DefaultMaxDescendSpeed = (Fixed64)1.5d;
 32
 33    /// <summary>
 34    /// Default acceleration used while actively flying.
 35    /// </summary>
 136    public static readonly Fixed64 DefaultMaxFlyAcceleration = (Fixed64)20;
 37
 38    /// <summary>
 39    /// Default amount of gravity canceled while actively flying.
 40    /// </summary>
 141    public static readonly Fixed64 DefaultGravityCompensation = Fixed64.One;
 42
 43    #endregion
 44
 45    #region Configuration State
 46
 78647    private bool _isEnabled = true;
 48
 49    /// <summary>
 50    /// Determines whether the scout is allowed to enter controlled flight.
 51    /// </summary>
 78652    public bool CanFly = true;
 53
 54    /// <summary>
 55    /// The maximum horizontal speed while flying.
 56    /// </summary>
 78657    public Fixed64 MaxFlySpeed = DefaultMaxFlySpeed;
 58
 59    /// <summary>
 60    /// The maximum upward speed while flying.
 61    /// </summary>
 78662    public Fixed64 MaxAscendSpeed = DefaultMaxAscendSpeed;
 63
 64    /// <summary>
 65    /// The maximum downward speed while actively descending under flight control.
 66    /// </summary>
 78667    public Fixed64 MaxDescendSpeed = DefaultMaxDescendSpeed;
 68
 69    /// <summary>
 70    /// The maximum acceleration applied while steering in flight.
 71    /// </summary>
 78672    public Fixed64 MaxFlyAcceleration = DefaultMaxFlyAcceleration;
 73
 74    /// <summary>
 75    /// The amount of gravity canceled while flying, clamped between 0 and 1 by the motor.
 76    /// </summary>
 78677    public Fixed64 GravityCompensation = DefaultGravityCompensation;
 78
 79    #endregion
 80
 81    #region Transient State
 82
 83    /// <inheritdoc cref="ILocomotion.IsEnabled"/>
 84    public bool IsEnabled
 85    {
 418086        get => _isEnabled;
 87        set
 88        {
 689            _isEnabled = value;
 690            if (!_isEnabled)
 491                this.ClearTransientState();
 692        }
 93    }
 94
 95    /// <summary>
 96    /// Indicates whether controlled flight is currently active.
 97    /// </summary>
 98    [Transient]
 99    public bool IsFlying { get; set; }
 100
 101    #endregion
 102
 103    /// <inheritdoc />
 104    public void RecordData(IChronicler chronicler)
 105    {
 100106        RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true);
 100107        RecordValues.Look(chronicler, ref CanFly, "CanFly", true);
 100108        RecordValues.Look(chronicler, ref MaxFlySpeed, "MaxFlySpeed", DefaultMaxFlySpeed);
 100109        RecordValues.Look(chronicler, ref MaxAscendSpeed, "MaxAscendSpeed", DefaultMaxAscendSpeed);
 100110        RecordValues.Look(chronicler, ref MaxDescendSpeed, "MaxDescendSpeed", DefaultMaxDescendSpeed);
 100111        RecordValues.Look(chronicler, ref MaxFlyAcceleration, "MaxFlyAcceleration", DefaultMaxFlyAcceleration);
 100112        RecordValues.Look(chronicler, ref GravityCompensation, "GravityCompensation", DefaultGravityCompensation);
 113
 100114        bool isFlying = IsFlying;
 100115        RecordValues.Look(chronicler, ref isFlying, "IsFlying", false);
 116
 100117        if (chronicler.Mode == SerializationMode.Loading)
 118        {
 50119            IsFlying = isFlying;
 120
 50121            if (!_isEnabled)
 2122                this.ClearTransientState();
 123        }
 100124    }
 125}