< Summary

Information
Class: Trailblazer.Navigation.Motor.FallLocomotion
Assembly: Trailblazer
File(s): /home/runner/work/Trailblazer/Trailblazer/src/Trailblazer/Navigation/Motor/Locomotion/FallLocomotion.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 119
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%
get_FallHeight()100%11100%
RecordData(...)100%44100%

File(s)

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

#LineLine coverage
 1//=======================================================================
 2// FallLocomotion.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 the scout’s behavior when falling, including tracking fall distance and applying movement constraints.
 16/// </summary>
 17public class FallLocomotion : ILocomotion
 18{
 19    #region Constants
 20
 21    /// <summary>
 22    /// The default maximum height a scout can fall before a fatal impact occurs.
 23    /// </summary>
 124    public static readonly Fixed64 DefaultMaxFallHeight = (Fixed64)30;
 25
 26    /// <summary>
 27    /// Default movement control multiplier when falling.
 28    /// Reduces movement responsiveness to simulate loss of control while airborne.
 29    /// </summary>
 130    public static readonly Fixed64 DefaultFallControlMultiplier = Fixed64.FromFraction(3, 16); // 50% control when falli
 31
 32    #endregion
 33
 34    #region Configuration State
 35
 36    /// <summary>
 37    /// Determines whether falling mechanics are enabled.
 38    /// If disabled, the scout will not experience fall behavior.
 39    /// </summary>
 120140    private bool _isEnabled = true;
 41
 42    /// <summary>
 43    /// The maximum allowable fall height before the scout reaches a critical threshold (e.g., death or heavy impact).
 44    /// </summary>
 120145    public Fixed64 MaxFallHeight = DefaultMaxFallHeight;
 46
 47    /// <summary>
 48    /// A multiplier controlling how much movement input affects the scout while falling.
 49    /// Lower values reduce movement responsiveness.
 50    /// </summary>
 120151    public Fixed64 FallControlMultiplier = DefaultFallControlMultiplier;
 52
 53    #endregion
 54
 55    #region Transient State
 56
 57    /// <inheritdoc cref="ILocomotion.IsEnabled"/>
 58    public bool IsEnabled
 59    {
 217960        get => _isEnabled;
 61        set
 62        {
 363            _isEnabled = value;
 364            if (!value)
 265                this.ClearTransientState();
 366        }
 67    }
 68
 69    /// <summary>
 70    /// Indicates whether the scout is currently falling.
 71    /// </summary>
 72    [Transient]
 73    public bool IsFalling { get; set; }
 74
 75    /// <summary>
 76    /// The vertical position where the scout started falling.
 77    /// </summary>
 78    [Transient]
 79    public Fixed64 FallStart { get; set; }
 80
 81    /// <summary>
 82    /// The vertical position where the scout landed.
 83    /// </summary>
 84    [Transient]
 85    public Fixed64 FallEnd { get; set; }
 86
 87    /// <summary>
 88    /// The total distance fallen, calculated as the difference between <see cref="FallStart"/> and <see cref="FallEnd"/
 89    /// </summary>
 1790    public Fixed64 FallHeight => FallStart - FallEnd;
 91
 92    #endregion
 93
 94    /// <inheritdoc />
 95    public void RecordData(IChronicler chronicler)
 96    {
 16497        RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true);
 16498        RecordValues.Look(chronicler, ref MaxFallHeight, "MaxFallHeight", DefaultMaxFallHeight);
 16499        RecordValues.Look(chronicler, ref FallControlMultiplier, "FallControlMultiplier", DefaultFallControlMultiplier);
 100
 164101        bool isFalling = IsFalling;
 164102        Fixed64 fallStart = FallStart;
 164103        Fixed64 fallEnd = FallEnd;
 104
 164105        RecordValues.Look(chronicler, ref isFalling, "IsFalling", false);
 164106        RecordValues.Look(chronicler, ref fallStart, "FallStart", Fixed64.Zero);
 164107        RecordValues.Look(chronicler, ref fallEnd, "FallEnd", Fixed64.Zero);
 108
 164109        if (chronicler.Mode == SerializationMode.Loading)
 110        {
 77111            IsFalling = isFalling;
 77112            FallStart = fallStart;
 77113            FallEnd = fallEnd;
 114
 77115            if (!_isEnabled)
 2116                this.ClearTransientState();
 117        }
 164118    }
 119}