Make voyages active with dockside orders, crew calls, and ship PA
This commit is contained in:
56
Assets/Soundings/Runtime/HarborStations.cs
Normal file
56
Assets/Soundings/Runtime/HarborStations.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
internal enum StationKind { Helm, Engine, Galley, Stores, Maintenance, Water, Waste, Cabins, Dining, Bar, Stage, Pool }
|
||||
|
||||
internal readonly struct ShipStation
|
||||
{
|
||||
public readonly StationKind Kind;
|
||||
public readonly Vector3 Position;
|
||||
|
||||
public ShipStation(StationKind kind, Vector3 position)
|
||||
{
|
||||
Kind = kind;
|
||||
Position = position;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class Harbor
|
||||
{
|
||||
internal bool TryGetFacingStation(out StationKind kind)
|
||||
{
|
||||
kind = default;
|
||||
IReadOnlyList<ShipStation> targets = cameraMode switch
|
||||
{
|
||||
CameraMode.Bridge or CameraMode.DeckWalk => decks?.ActiveStations,
|
||||
CameraMode.Service => serviceDeck?.Stations,
|
||||
_ => null
|
||||
};
|
||||
if (targets == null || walkSpace == null)
|
||||
return false;
|
||||
|
||||
Vector3 facing = Quaternion.Euler(freePitch, freeYaw, 0) * Vector3.forward;
|
||||
float best = float.PositiveInfinity;
|
||||
for (int i = 0; i < targets.Count; i++)
|
||||
{
|
||||
ShipStation station = targets[i];
|
||||
Vector3 offset = station.Position - freePosition;
|
||||
float distance = offset.magnitude;
|
||||
if (distance < .05f || distance > 3.2f)
|
||||
continue;
|
||||
float alignment = Vector3.Dot(facing, offset) / distance;
|
||||
if (alignment < .955f)
|
||||
continue;
|
||||
float score = distance + (1 - alignment) * 9;
|
||||
if (score >= best || !walkSpace.HasSightLine(freePosition, station.Position))
|
||||
continue;
|
||||
best = score;
|
||||
kind = station.Kind;
|
||||
}
|
||||
return !float.IsPositiveInfinity(best);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user