| | | 1 | | using Chronicler; |
| | | 2 | | using FixedMathSharp; |
| | | 3 | | using Trailblazer.Pathing; |
| | | 4 | | |
| | | 5 | | namespace Trailblazer.Navigation; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Stores the follow-up chart-backed leg for a object-owned volume exit handoff. |
| | | 9 | | /// </summary> |
| | | 10 | | internal sealed class GuidedVolumeExitHandoff : IRecordable |
| | | 11 | | { |
| | | 12 | | public TrailblazerWorldContext? Context; |
| | | 13 | | |
| | | 14 | | public string? TransitionId; |
| | | 15 | | |
| | | 16 | | public Vector3d ChartOriginPosition; |
| | | 17 | | |
| | | 18 | | public Vector3d TargetPosition; |
| | | 19 | | |
| | | 20 | | public SolidPathAlgorithm ChartPathMode = SolidPathAlgorithm.AStar; |
| | | 21 | | |
| | | 22 | | public bool AllowUnwalkableEndpoints; |
| | | 23 | | |
| | | 24 | | public bool AllowTraversalTransitions; |
| | | 25 | | |
| | 74 | 26 | | public Fixed64 MaxClimbHeight = Fixed64.One; |
| | | 27 | | |
| | | 28 | | public HeuristicMethod AStarHeuristic = HeuristicMethod.Manhattan; |
| | | 29 | | |
| | 74 | 30 | | public int FlowFieldExtraFloodRange = FlowFieldPathRequest.DefaultExtraFloodRange; |
| | | 31 | | |
| | 74 | 32 | | public int MovementGroupId = -1; |
| | | 33 | | |
| | | 34 | | public bool IsRequestingClimb; |
| | | 35 | | |
| | | 36 | | public bool IsValid => |
| | 61 | 37 | | !string.IsNullOrWhiteSpace(TransitionId) |
| | 61 | 38 | | && (ChartPathMode == SolidPathAlgorithm.AStar || ChartPathMode == SolidPathAlgorithm.FlowField); |
| | | 39 | | |
| | | 40 | | public bool TryCreateFollowupRequest( |
| | | 41 | | TrailblazerWorldContext context, |
| | | 42 | | Vector3d currentPosition, |
| | | 43 | | Fixed64 unitSize, |
| | | 44 | | out IPathRequest? request) |
| | | 45 | | { |
| | 17 | 46 | | PathRequestContextResolver.ThrowIfUnusable(context); |
| | 17 | 47 | | request = null; |
| | 17 | 48 | | if (!IsValid) |
| | 2 | 49 | | return false; |
| | 15 | 50 | | switch (ChartPathMode) |
| | | 51 | | { |
| | | 52 | | case SolidPathAlgorithm.AStar: |
| | 9 | 53 | | var aStar = AStarPathRequest.Create( |
| | 9 | 54 | | context, |
| | 9 | 55 | | ChartOriginPosition, |
| | 9 | 56 | | TargetPosition, |
| | 9 | 57 | | unitSize, |
| | 9 | 58 | | AStarHeuristic, |
| | 9 | 59 | | AllowUnwalkableEndpoints, |
| | 9 | 60 | | AllowTraversalTransitions); |
| | 9 | 61 | | if (aStar == null || !aStar.TrySetOrigin(currentPosition)) |
| | 1 | 62 | | return false; |
| | | 63 | | |
| | 8 | 64 | | aStar.MaxClimbHeight = MaxClimbHeight; |
| | 8 | 65 | | request = aStar; |
| | 8 | 66 | | return true; |
| | | 67 | | |
| | | 68 | | case SolidPathAlgorithm.FlowField: |
| | 6 | 69 | | var flowField = FlowFieldPathRequest.Create( |
| | 6 | 70 | | context, |
| | 6 | 71 | | ChartOriginPosition, |
| | 6 | 72 | | TargetPosition, |
| | 6 | 73 | | unitSize, |
| | 6 | 74 | | AllowUnwalkableEndpoints, |
| | 6 | 75 | | AllowTraversalTransitions); |
| | 6 | 76 | | if (flowField == null || !flowField.TrySetOrigin(currentPosition)) |
| | 1 | 77 | | return false; |
| | | 78 | | |
| | 5 | 79 | | flowField.MaxClimbHeight = MaxClimbHeight; |
| | 5 | 80 | | flowField.ExtraFloodRange = FlowFieldExtraFloodRange; |
| | 5 | 81 | | request = flowField; |
| | 5 | 82 | | return true; |
| | | 83 | | |
| | | 84 | | default: |
| | 0 | 85 | | return false; |
| | | 86 | | } |
| | | 87 | | } |
| | | 88 | | |
| | | 89 | | public void RecordData(IChronicler chronicler) |
| | | 90 | | { |
| | 12 | 91 | | RecordValues.Look(chronicler, ref TransitionId, "TransitionId", null); |
| | 12 | 92 | | RecordValues.Look(chronicler, ref ChartOriginPosition, "ChartOriginPosition", Vector3d.Zero); |
| | 12 | 93 | | RecordValues.Look(chronicler, ref TargetPosition, "TargetPosition", Vector3d.Zero); |
| | 12 | 94 | | RecordValues.Look(chronicler, ref ChartPathMode, "ChartPathMode", SolidPathAlgorithm.AStar); |
| | 12 | 95 | | RecordValues.Look(chronicler, ref AllowUnwalkableEndpoints, "AllowUnwalkableEndpoints", false); |
| | 12 | 96 | | RecordValues.Look(chronicler, ref AllowTraversalTransitions, "AllowTraversalTransitions", false); |
| | 12 | 97 | | RecordValues.Look(chronicler, ref MaxClimbHeight, "MaxClimbHeight", Fixed64.One); |
| | 12 | 98 | | RecordValues.Look(chronicler, ref AStarHeuristic, "AStarHeuristic", HeuristicMethod.Manhattan); |
| | 12 | 99 | | RecordValues.Look(chronicler, ref FlowFieldExtraFloodRange, "FlowFieldExtraFloodRange", FlowFieldPathRequest.Def |
| | 12 | 100 | | RecordValues.Look(chronicler, ref MovementGroupId, "MovementGroupId", -1); |
| | 12 | 101 | | RecordValues.Look(chronicler, ref IsRequestingClimb, "IsRequestingClimb", false); |
| | 12 | 102 | | } |
| | | 103 | | } |