Add fleet save slots and rotatable onboard venues
This commit is contained in:
@@ -1,7 +1,16 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
[Serializable]
|
||||
internal sealed class HelmSnapshot
|
||||
{
|
||||
public Vector2 Position, ApproachWaypoint;
|
||||
public float RouteDuration, Heading, Rudder, Speed, Progress, TurnRate;
|
||||
public bool Manual, PropulsionStopped, Arrived, ExtendingApproach;
|
||||
}
|
||||
|
||||
internal sealed class HelmNavigation
|
||||
{
|
||||
private const float RudderLimit = 35f;
|
||||
@@ -102,5 +111,46 @@ namespace Soundings
|
||||
extendingApproach = false;
|
||||
Arrived = Progress >= 1;
|
||||
}
|
||||
|
||||
internal HelmSnapshot CaptureState() => new HelmSnapshot
|
||||
{
|
||||
Position = Position, ApproachWaypoint = approachWaypoint, RouteDuration = duration, Heading = Heading,
|
||||
Rudder = Rudder, Speed = Speed, Progress = Progress, TurnRate = turnRate, Manual = Manual,
|
||||
PropulsionStopped = PropulsionStopped, Arrived = Arrived, ExtendingApproach = extendingApproach
|
||||
};
|
||||
|
||||
internal bool RestoreState(HelmSnapshot state)
|
||||
{
|
||||
if (state == null || !Finite(state.RouteDuration) || state.RouteDuration < 1
|
||||
|| !Finite(state.Position.x) || !Finite(state.Position.y)
|
||||
|| !Finite(state.ApproachWaypoint.x) || !Finite(state.ApproachWaypoint.y)
|
||||
|| !Finite(state.Heading) || Mathf.Abs(state.Heading) > 180
|
||||
|| !Finite(state.Rudder) || Mathf.Abs(state.Rudder) > RudderLimit
|
||||
|| !Finite(state.Speed) || state.Speed < 0 || state.Speed > 120
|
||||
|| !Finite(state.Progress) || state.Progress < 0 || state.Progress > 1 || (state.Arrived && state.Progress != 1)
|
||||
|| !Finite(state.TurnRate) || Mathf.Abs(state.TurnRate) > 40)
|
||||
return false;
|
||||
|
||||
float scale = duration / state.RouteDuration;
|
||||
Vector2 position = state.Position * scale;
|
||||
Vector2 waypoint = state.ApproachWaypoint * scale;
|
||||
if (!Finite(position.sqrMagnitude) || !Finite(waypoint.sqrMagnitude))
|
||||
return false;
|
||||
|
||||
Position = position;
|
||||
approachWaypoint = waypoint;
|
||||
Heading = state.Heading;
|
||||
Rudder = state.Rudder;
|
||||
Speed = state.Speed;
|
||||
Progress = state.Progress;
|
||||
turnRate = state.TurnRate;
|
||||
Manual = state.Manual;
|
||||
PropulsionStopped = state.PropulsionStopped;
|
||||
Arrived = state.Arrived;
|
||||
extendingApproach = state.ExtendingApproach;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool Finite(float value) => !float.IsNaN(value) && !float.IsInfinity(value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user