< 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: 132
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
 1//=======================================================================
 2// FlyLocomotion.cs
 3//=======================================================================
 4// MIT License, Copyright (c) 2024-present David Oravsky (mrdav30)
 5// See LICENSE file in the project root for full license information.
 6//=======================================================================
 7
 8using Chronicler;
 9using FixedMathSharp;
 10using Trailblazer.Support;
 11
 12namespace Trailblazer.Navigation.Motor;
 13
 14/// <summary>
 15/// Handles controlled flight movement while the scout is airborne.
 16/// </summary>
 17/// <remarks>
 18/// Flight is distinct from both jumping and falling.
 19/// It provides active air control, optional gravity cancellation, and controlled ascent or descent.
 20/// </remarks>
 21public class FlyLocomotion : ILocomotion
 22{
 23    #region Constants
 24
 25    /// <summary>
 26    /// Default maximum horizontal flight speed.
 27    /// </summary>
 128    public static readonly Fixed64 DefaultMaxFlySpeed = Fixed64.FromFraction(3, 2);
 29
 30    /// <summary>
 31    /// Default maximum upward flight speed.
 32    /// </summary>
 133    public static readonly Fixed64 DefaultMaxAscendSpeed = Fixed64.FromFraction(3, 2);
 34
 35    /// <summary>
 36    /// Default maximum downward flight speed while actively descending.
 37    /// </summary>
 138    public static readonly Fixed64 DefaultMaxDescendSpeed = Fixed64.FromFraction(3, 2);
 39
 40    /// <summary>
 41    /// Default acceleration used while actively flying.
 42    /// </summary>
 143    public static readonly Fixed64 DefaultMaxFlyAcceleration = (Fixed64)20;
 44
 45    /// <summary>
 46    /// Default amount of gravity canceled while actively flying.
 47    /// </summary>
 148    public static readonly Fixed64 DefaultGravityCompensation = Fixed64.One;
 49
 50    #endregion
 51
 52    #region Configuration State
 53
 115154    private bool _isEnabled = true;
 55
 56    /// <summary>
 57    /// Determines whether the scout is allowed to enter controlled flight.
 58    /// </summary>
 115159    public bool CanFly = true;
 60
 61    /// <summary>
 62    /// The maximum horizontal speed while flying.
 63    /// </summary>
 115164    public Fixed64 MaxFlySpeed = DefaultMaxFlySpeed;
 65
 66    /// <summary>
 67    /// The maximum upward speed while flying.
 68    /// </summary>
 115169    public Fixed64 MaxAscendSpeed = DefaultMaxAscendSpeed;
 70
 71    /// <summary>
 72    /// The maximum downward speed while actively descending under flight control.
 73    /// </summary>
 115174    public Fixed64 MaxDescendSpeed = DefaultMaxDescendSpeed;
 75
 76    /// <summary>
 77    /// The maximum acceleration applied while steering in flight.
 78    /// </summary>
 115179    public Fixed64 MaxFlyAcceleration = DefaultMaxFlyAcceleration;
 80
 81    /// <summary>
 82    /// The amount of gravity canceled while flying, clamped between 0 and 1 by the motor.
 83    /// </summary>
 115184    public Fixed64 GravityCompensation = DefaultGravityCompensation;
 85
 86    #endregion
 87
 88    #region Transient State
 89
 90    /// <inheritdoc cref="ILocomotion.IsEnabled"/>
 91    public bool IsEnabled
 92    {
 435393        get => _isEnabled;
 94        set
 95        {
 896            _isEnabled = value;
 897            if (!_isEnabled)
 698                this.ClearTransientState();
 899        }
 100    }
 101
 102    /// <summary>
 103    /// Indicates whether controlled flight is currently active.
 104    /// </summary>
 105    [Transient]
 106    public bool IsFlying { get; set; }
 107
 108    #endregion
 109
 110    /// <inheritdoc />
 111    public void RecordData(IChronicler chronicler)
 112    {
 158113        RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true);
 158114        RecordValues.Look(chronicler, ref CanFly, "CanFly", true);
 158115        RecordValues.Look(chronicler, ref MaxFlySpeed, "MaxFlySpeed", DefaultMaxFlySpeed);
 158116        RecordValues.Look(chronicler, ref MaxAscendSpeed, "MaxAscendSpeed", DefaultMaxAscendSpeed);
 158117        RecordValues.Look(chronicler, ref MaxDescendSpeed, "MaxDescendSpeed", DefaultMaxDescendSpeed);
 158118        RecordValues.Look(chronicler, ref MaxFlyAcceleration, "MaxFlyAcceleration", DefaultMaxFlyAcceleration);
 158119        RecordValues.Look(chronicler, ref GravityCompensation, "GravityCompensation", DefaultGravityCompensation);
 120
 158121        bool isFlying = IsFlying;
 158122        RecordValues.Look(chronicler, ref isFlying, "IsFlying", false);
 123
 158124        if (chronicler.Mode == SerializationMode.Loading)
 125        {
 74126            IsFlying = isFlying;
 127
 74128            if (!_isEnabled)
 2129                this.ClearTransientState();
 130        }
 158131    }
 132}