| | | 1 | | using Chronicler; |
| | | 2 | | using FixedMathSharp; |
| | | 3 | | using Trailblazer.Support; |
| | | 4 | | |
| | | 5 | | namespace Trailblazer.Navigation.Motor; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Handles the scout's sliding behavior when traversing steep surfaces. |
| | | 9 | | /// </summary> |
| | | 10 | | /// <remarks> |
| | | 11 | | /// This locomotion module determines when the scout should slide based on terrain steepness |
| | | 12 | | /// and controls how much influence the scout has over the slide direction and speed. |
| | | 13 | | /// </remarks> |
| | | 14 | | public class SlideLocomotion : ILocomotion |
| | | 15 | | { |
| | | 16 | | #region Constants |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// The default speed at which the scout slides down steep surfaces. |
| | | 20 | | /// </summary> |
| | 1 | 21 | | public static readonly Fixed64 DefaultSlidingSpeed = (Fixed64)30; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// The default amount of control the scout has while sliding sideways. |
| | | 25 | | /// </summary> |
| | | 26 | | /// <remarks> |
| | | 27 | | /// A value of 0.5 allows the scout to slide sideways at half the speed of downward sliding. |
| | | 28 | | /// </remarks> |
| | 1 | 29 | | public static readonly Fixed64 DefaultSidewaysControl = (Fixed64)1; |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// The default amount the scout can influence sliding speed. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <remarks> |
| | | 35 | | /// A value of 0.5 allows the scout to increase sliding speed up to 150% or reduce it to 50%. |
| | | 36 | | /// </remarks> |
| | 1 | 37 | | public static readonly Fixed64 DefaultSpeedControl = (Fixed64)0.5d; |
| | | 38 | | |
| | | 39 | | #endregion |
| | | 40 | | |
| | | 41 | | #region Configuration State |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Determines whether sliding mechanics are enabled. |
| | | 45 | | /// </summary> |
| | 783 | 46 | | private bool _isEnabled = true; |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// The speed at which the scout slides when on a steep surface. |
| | | 50 | | /// </summary> |
| | 783 | 51 | | public Fixed64 SlidingSpeed = DefaultSlidingSpeed; |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Determines how much control the scout has while sliding sideways. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <remarks> |
| | | 57 | | /// A higher value increases lateral movement freedom during a slide. |
| | | 58 | | /// </remarks> |
| | 783 | 59 | | public Fixed64 SidewaysControl = DefaultSidewaysControl; |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Determines how much the scout can influence sliding speed. |
| | | 63 | | /// </summary> |
| | 783 | 64 | | public Fixed64 SpeedControl = DefaultSpeedControl; |
| | | 65 | | |
| | | 66 | | #endregion |
| | | 67 | | |
| | | 68 | | #region Transient State |
| | | 69 | | |
| | | 70 | | /// <inheritdoc cref="ILocomotion.IsEnabled"/> |
| | | 71 | | public bool IsEnabled |
| | | 72 | | { |
| | 222 | 73 | | get => _isEnabled; |
| | | 74 | | set |
| | | 75 | | { |
| | 1 | 76 | | _isEnabled = value; |
| | 1 | 77 | | if (!_isEnabled) |
| | 1 | 78 | | this.ClearTransientState(); |
| | 1 | 79 | | } |
| | | 80 | | } |
| | | 81 | | |
| | | 82 | | /// <summary> |
| | | 83 | | /// Indicates whether the scout is currently sliding. |
| | | 84 | | /// </summary> |
| | | 85 | | [Transient] |
| | | 86 | | public bool IsSliding { get; set; } |
| | | 87 | | |
| | | 88 | | #endregion |
| | | 89 | | |
| | | 90 | | /// <inheritdoc /> |
| | | 91 | | public void RecordData(IChronicler chronicler) |
| | | 92 | | { |
| | 100 | 93 | | RecordValues.Look(chronicler, ref _isEnabled, "IsEnabled", true); |
| | 100 | 94 | | RecordValues.Look(chronicler, ref SlidingSpeed, "SlidingSpeed", DefaultSlidingSpeed); |
| | 100 | 95 | | RecordValues.Look(chronicler, ref SidewaysControl, "SidewaysControl", DefaultSidewaysControl); |
| | 100 | 96 | | RecordValues.Look(chronicler, ref SpeedControl, "SpeedControl", DefaultSpeedControl); |
| | | 97 | | |
| | 100 | 98 | | bool isSliding = IsSliding; |
| | 100 | 99 | | RecordValues.Look(chronicler, ref isSliding, "IsSliding", false); |
| | | 100 | | |
| | 100 | 101 | | if (chronicler.Mode == SerializationMode.Loading) |
| | | 102 | | { |
| | 50 | 103 | | IsSliding = isSliding; |
| | | 104 | | |
| | 50 | 105 | | if (!_isEnabled) |
| | 2 | 106 | | this.ClearTransientState(); |
| | | 107 | | } |
| | 100 | 108 | | } |
| | | 109 | | } |