Add multi-stop voyages, a live chart, and named port announcements
This commit is contained in:
@@ -18,6 +18,7 @@ namespace Soundings
|
||||
public int[] ServicePrices;
|
||||
public double FuelValue;
|
||||
public List<Deck> Decks = new List<Deck>();
|
||||
public CruiseItinerary Itinerary;
|
||||
|
||||
public HullSpec Hull => Market.Hulls[HullIndex];
|
||||
public int Beds => Count(Facility.Cabin) * Market.Facilities[(int)Facility.Cabin].Capacity;
|
||||
@@ -53,6 +54,7 @@ namespace Soundings
|
||||
public int Origin, Destination, Miles, Days, Day, Fare, Guests, RoomDemand, Capacity, FuelBurn, Reserve,
|
||||
TicketSales, OnboardSales, Crew, Catering, PortFees, FuelExpense, LoanInterest, Principal, ReputationChange;
|
||||
public string ShipName;
|
||||
public int ItineraryStartDay, ItineraryLeg, ItineraryLegs;
|
||||
public OnboardReport Onboard;
|
||||
public DeparturePlan Plan;
|
||||
public WeatherCondition Weather;
|
||||
@@ -64,7 +66,7 @@ namespace Soundings
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class Company
|
||||
public sealed partial class Company
|
||||
{
|
||||
public const int SaveVersion = 1;
|
||||
public const int MaxHistory = 30;
|
||||
@@ -121,7 +123,7 @@ namespace Soundings
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ship.Fuel > ship.Tank)
|
||||
if (ship.Fuel > ship.Tank || !ValidSavedItinerary(ship))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -318,8 +320,7 @@ namespace Soundings
|
||||
PortSpec from = Market.Ports[ship.Port];
|
||||
PortSpec to = Market.Ports[destination];
|
||||
int days = 1 + (int)Math.Ceiling(miles / 415.0);
|
||||
int fuel = (int)Math.Ceiling(ship.BurnPerMile * miles);
|
||||
int reserve = Math.Max(6, (int)Math.Ceiling(fuel * .12));
|
||||
var (fuel, reserve) = LegFuel(ship, miles);
|
||||
double referenceFare = 330 + days * 88 + to.Appeal * 125;
|
||||
double fareFactor = Math.Pow(referenceFare / ship.Fare, 1.55);
|
||||
double season = 1 + .13 * Math.Cos((Day + destination * 13) * 2 * Math.PI / 112);
|
||||
@@ -369,8 +370,10 @@ namespace Soundings
|
||||
|
||||
public string DepartureBlock(Ship ship, Voyage quote)
|
||||
{
|
||||
if (quote == null || quote.Destination == ship.Port)
|
||||
if (ship == null || quote == null || quote.Origin != ship.Port || !Market.TryDistance(ship.Port, quote.Destination, out _))
|
||||
return "Select a connected port from your itinerary.";
|
||||
if (ship.Itinerary is { HasNext: true } itinerary && quote.Destination != itinerary.NextPort)
|
||||
return $"This itinerary's next stop is {Market.Ports[itinerary.NextPort].Name}.";
|
||||
if (!Permits[quote.Destination])
|
||||
return "Obtain a destination permit in Ports.";
|
||||
if (ship.HullIndex < Market.Ports[quote.Destination].MinimumHull)
|
||||
@@ -393,8 +396,10 @@ namespace Soundings
|
||||
|
||||
public string Sail(Ship ship, int destination, OnboardSession live = null)
|
||||
{
|
||||
if (ship == null || !Fleet.Contains(ship))
|
||||
return "Choose a ship in this fleet.";
|
||||
Voyage quote = live?.Quote ?? Forecast(ship, destination);
|
||||
if (live != null && (live.Ship != ship || quote.Origin != ship.Port || quote.Destination != destination))
|
||||
if (live != null && (live.Ship != ship || quote.Origin != ship.Port || quote.Destination != destination || quote.Day <= Day))
|
||||
return "This sailing has already been settled or belongs to another ship.";
|
||||
string block = DepartureBlock(ship, quote);
|
||||
if (block != null)
|
||||
@@ -414,6 +419,7 @@ namespace Soundings
|
||||
ship.FuelValue *= (double)(ship.Fuel - quote.FuelBurn) / ship.Fuel;
|
||||
ship.Fuel -= quote.FuelBurn;
|
||||
ship.Condition = Market.Clamp(ship.Condition - Math.Max(1, quote.Days / 2) + (quote.Onboard?.Repair ?? 0), 24, 100);
|
||||
RecordItineraryArrival(ship, quote);
|
||||
ship.Port = quote.Destination;
|
||||
Day = quote.Day;
|
||||
Cash += quote.CashChange;
|
||||
|
||||
@@ -53,7 +53,14 @@ namespace Soundings
|
||||
|
||||
private void OpenVoyageChart()
|
||||
{
|
||||
int port = destination >= 0 ? destination : Ship?.Port ?? 0;
|
||||
itineraryEditorShip = null;
|
||||
int planned = Ship?.Itinerary?.NextPort ?? -1;
|
||||
int port = planned >= 0 ? planned : destination >= 0 ? destination : Ship?.Port ?? 0;
|
||||
if (planned >= 0 && destination != planned)
|
||||
{
|
||||
destination = planned;
|
||||
SetRecommendedFuel();
|
||||
}
|
||||
worldChart = port >= Market.StarterPortCount || (Ship?.Port ?? 0) >= Market.StarterPortCount;
|
||||
inspectedPort = port;
|
||||
chartScrollPosition = 0;
|
||||
@@ -75,6 +82,8 @@ namespace Soundings
|
||||
var switches = Add(board, "chart-scopes");
|
||||
switches.Add(Action("Atlantic", () => ChangeChart(false), worldChart ? "chart-scope" : "chart-scope chart-scope-current", "chart-atlantic"));
|
||||
switches.Add(Action("World", () => ChangeChart(true), worldChart ? "chart-scope chart-scope-current" : "chart-scope", "chart-world"));
|
||||
if (Ship != null)
|
||||
DrawItineraryButton(switches, Ship);
|
||||
|
||||
for (int i = 0; i < ChartPortCount; i++)
|
||||
{
|
||||
@@ -90,6 +99,13 @@ namespace Soundings
|
||||
styles += " chart-port-locked";
|
||||
if (selected)
|
||||
styles += " chart-port-selected";
|
||||
if (Ship?.Itinerary is CruiseItinerary itinerary)
|
||||
{
|
||||
if (IsPendingCall(itinerary, i))
|
||||
styles += " chart-port-planned";
|
||||
if (i == itinerary.NextPort)
|
||||
styles += " chart-port-next";
|
||||
}
|
||||
|
||||
var marker = Action("", () => InspectChartPort(portId), styles, "port-" + i);
|
||||
marker.tooltip = $"{port.Name} · {(berth ? "Current port" : cleared ? "Permit held" : "Permit required")}";
|
||||
@@ -99,7 +115,7 @@ namespace Soundings
|
||||
var light = Add(marker, "chart-pin-light");
|
||||
light.pickingMode = PickingMode.Ignore;
|
||||
var caption = AddText(marker, port.Name, point.x > .77f ? "chart-pin-label chart-pin-label-west" : "chart-pin-label");
|
||||
caption.EnableInClassList("chart-pin-label-on-focus", worldChart && !selected && !berth);
|
||||
caption.EnableInClassList("chart-pin-label-on-focus", worldChart && !selected && !berth && Ship?.Itinerary?.NextPort != i);
|
||||
plot.Add(marker);
|
||||
}
|
||||
|
||||
@@ -118,7 +134,10 @@ namespace Soundings
|
||||
var contents = Add(folio, "chart-folio-content");
|
||||
AddText(contents, "LOOK UP PORT", "chart-paper-kicker");
|
||||
AddChartDirectory(contents);
|
||||
DrawPortFolio(board, contents);
|
||||
if (EditingItinerary)
|
||||
DrawItineraryFolio(contents, Ship);
|
||||
else
|
||||
DrawPortFolio(board, contents);
|
||||
}
|
||||
|
||||
private static void ChartKey(VisualElement legend, string name, string color)
|
||||
@@ -154,11 +173,15 @@ namespace Soundings
|
||||
Voyage quote = ship == null ? null : company.Forecast(ship, selected);
|
||||
bool permitted = company.Permits[selected];
|
||||
bool eligible = ship == null || ship.HullIndex >= port.MinimumHull;
|
||||
int nextCall = ship?.Itinerary?.NextPort ?? -1;
|
||||
|
||||
AddDisplay(parent, port.Name, "chart-port-name");
|
||||
AddText(parent, $"{port.Country} · {port.Region}", "chart-paper-caption");
|
||||
|
||||
if (quote != null && permitted && eligible)
|
||||
if (nextCall >= 0)
|
||||
DrawNextCall(parent, ship.Itinerary, selected);
|
||||
|
||||
if (quote != null && permitted && eligible && (nextCall < 0 || selected == nextCall))
|
||||
{
|
||||
DrawVoyageFolio(board, parent, ship, quote);
|
||||
return;
|
||||
@@ -199,7 +222,7 @@ namespace Soundings
|
||||
AddText(parent, "Assign a vessel to plan a sailing.", "chart-paper-note");
|
||||
parent.Add(Action("Visit shipyard", () => ChangePage(2), "chart-ink-button chart-wide-button"));
|
||||
}
|
||||
else
|
||||
else if (nextCall < 0)
|
||||
{
|
||||
AddText(parent, $"There is no direct route from {Market.Ports[ship.Port].Name}. Select a linked port to plan this sailing.", "chart-paper-note");
|
||||
}
|
||||
@@ -209,10 +232,13 @@ namespace Soundings
|
||||
|
||||
private void InspectChartPort(int port)
|
||||
{
|
||||
if (port >= Market.StarterPortCount)
|
||||
worldChart = true;
|
||||
if (port != inspectedPort)
|
||||
chartScrollPosition = 0;
|
||||
inspectedPort = port;
|
||||
if (Ship != null && Market.TryDistance(Ship.Port, port, out _) && destination != port)
|
||||
if (Ship != null && !EditingItinerary && Ship.Itinerary?.HasNext != true
|
||||
&& Market.TryDistance(Ship.Port, port, out _) && destination != port)
|
||||
{
|
||||
destination = port;
|
||||
SetRecommendedFuel();
|
||||
@@ -304,9 +330,11 @@ namespace Soundings
|
||||
painter.Stroke();
|
||||
}
|
||||
|
||||
int berth = Ship?.Port ?? -1;
|
||||
Ship ship = Ship;
|
||||
int berth = ship?.Port ?? -1;
|
||||
int selectionOrigin = EditingItinerary && ship != null ? ItineraryTail(ship) : berth;
|
||||
bool CanShow(Lane lane) => lane.A < ChartPortCount && lane.B < ChartPortCount;
|
||||
bool IsSelected(Lane lane) => berth >= 0 && lane.Other(berth) == inspectedPort;
|
||||
bool IsSelected(Lane lane) => selectionOrigin >= 0 && lane.Other(selectionOrigin) == inspectedPort;
|
||||
|
||||
foreach (Lane lane in Market.Lanes)
|
||||
{
|
||||
@@ -323,6 +351,29 @@ namespace Soundings
|
||||
DrawLane(lane, new Color(.98f, .75f, .38f, 1), 2.3f);
|
||||
}
|
||||
|
||||
if (ship?.Itinerary is CruiseItinerary itinerary)
|
||||
{
|
||||
int from = itinerary.Origin;
|
||||
for (int i = 0; i < itinerary.TotalStops; i++)
|
||||
{
|
||||
int to = itinerary.Stops[i];
|
||||
var route = new Lane(from, to, 0);
|
||||
if (i != itinerary.CompletedStops && CanShow(route))
|
||||
{
|
||||
Color color = i < itinerary.CompletedStops ? new Color(.48f, .64f, .61f, .74f) : new Color(.48f, .88f, .78f);
|
||||
DrawLane(route, color, 2.4f);
|
||||
}
|
||||
from = to;
|
||||
}
|
||||
|
||||
var nextRoute = new Lane(berth, itinerary.NextPort, 0);
|
||||
if (itinerary.HasNext && CanShow(nextRoute))
|
||||
{
|
||||
DrawLane(nextRoute, new Color(.94f, .74f, .40f, .23f), 8);
|
||||
DrawLane(nextRoute, new Color(1f, .85f, .55f), 3f);
|
||||
}
|
||||
}
|
||||
|
||||
DrawCompass(painter, new Vector2(width - 69, height - 76), 34);
|
||||
|
||||
void DrawLane(Lane lane, Color color, float thickness)
|
||||
|
||||
138
Assets/Soundings/Runtime/CruiseItinerary.cs
Normal file
138
Assets/Soundings/Runtime/CruiseItinerary.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class CruiseItinerary
|
||||
{
|
||||
public int Origin, StartDay, CompletedStops;
|
||||
public List<int> Stops = new List<int>();
|
||||
|
||||
public int TotalStops => Stops?.Count ?? 0;
|
||||
public bool HasNext => CompletedStops >= 0 && CompletedStops < TotalStops;
|
||||
public int NextPort => HasNext ? Stops[CompletedStops] : -1;
|
||||
public int LastPort => TotalStops > 0 ? Stops[TotalStops - 1] : Origin;
|
||||
}
|
||||
|
||||
public sealed partial class Company
|
||||
{
|
||||
public string ItineraryStopBlock(Ship ship, int port)
|
||||
{
|
||||
if (ship == null || !Fleet.Contains(ship))
|
||||
return "Choose a ship in this fleet.";
|
||||
int origin = ship.Itinerary is { HasNext: true } itinerary ? itinerary.LastPort : ship.Port;
|
||||
return ItineraryLaneBlock(ship, origin, port);
|
||||
}
|
||||
|
||||
public string AppendItineraryStop(Ship ship, int port)
|
||||
{
|
||||
string block = ItineraryStopBlock(ship, port);
|
||||
if (block != null)
|
||||
return block;
|
||||
if (ship.Itinerary == null || !ship.Itinerary.HasNext)
|
||||
ship.Itinerary = new CruiseItinerary { Origin = ship.Port };
|
||||
ship.Itinerary.Stops.Add(port);
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ItineraryRemovalBlock(Ship ship, int index)
|
||||
{
|
||||
if (ship == null || !Fleet.Contains(ship))
|
||||
return "Choose a ship in this fleet.";
|
||||
CruiseItinerary itinerary = ship.Itinerary;
|
||||
if (itinerary == null || index < 0 || index >= itinerary.TotalStops)
|
||||
return "Select a planned stop.";
|
||||
if (index < itinerary.CompletedStops)
|
||||
return "This port call is already recorded.";
|
||||
if (index == itinerary.TotalStops - 1)
|
||||
return null;
|
||||
|
||||
int origin = index == 0 ? itinerary.Origin : itinerary.Stops[index - 1];
|
||||
return ItineraryLaneBlock(ship, origin, itinerary.Stops[index + 1]);
|
||||
}
|
||||
|
||||
public string RemoveItineraryStop(Ship ship, int index)
|
||||
{
|
||||
string block = ItineraryRemovalBlock(ship, index);
|
||||
if (block != null)
|
||||
return block;
|
||||
ship.Itinerary.Stops.RemoveAt(index);
|
||||
if (ship.Itinerary.TotalStops == 0)
|
||||
ship.Itinerary = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ClearItinerary(Ship ship)
|
||||
{
|
||||
if (ship == null || !Fleet.Contains(ship))
|
||||
return "Choose a ship in this fleet.";
|
||||
ship.Itinerary = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
private string ItineraryLaneBlock(Ship ship, int origin, int destination)
|
||||
{
|
||||
if (destination < 0 || destination >= Market.Ports.Count)
|
||||
return "Select a port to add to the itinerary.";
|
||||
if (destination == origin)
|
||||
return "Choose a different port for the next stop.";
|
||||
if (!Market.TryDistance(origin, destination, out int miles))
|
||||
return $"There is no direct lane from {Market.Ports[origin].Name} to {Market.Ports[destination].Name}.";
|
||||
|
||||
PortSpec port = Market.Ports[destination];
|
||||
if (!Permits[destination])
|
||||
return $"Acquire the permit for {port.Name} first.";
|
||||
if (ship.HullIndex < port.MinimumHull)
|
||||
return $"{port.Name} requires a {Market.Hulls[port.MinimumHull].Name} hull.";
|
||||
var (burn, reserve) = LegFuel(ship, miles);
|
||||
if (burn + reserve > ship.Tank)
|
||||
return $"This leg needs {burn + reserve} t including reserve. Fit a larger fuel tank first.";
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ValidSavedItinerary(Ship ship)
|
||||
{
|
||||
CruiseItinerary itinerary = ship.Itinerary;
|
||||
if (itinerary == null)
|
||||
return true;
|
||||
if (itinerary.CompletedStops < 0 || itinerary.CompletedStops > itinerary.TotalStops)
|
||||
return false;
|
||||
if (itinerary.TotalStops == 0)
|
||||
return itinerary.StartDay == 0;
|
||||
if (itinerary.Origin < 0 || itinerary.Origin >= Market.Ports.Count)
|
||||
return false;
|
||||
if (itinerary.CompletedStops == 0 ? itinerary.StartDay != 0 : itinerary.StartDay < 1 || itinerary.StartDay >= Day)
|
||||
return false;
|
||||
|
||||
int origin = itinerary.Origin;
|
||||
foreach (int port in itinerary.Stops)
|
||||
{
|
||||
if (port < 0 || port >= Market.Ports.Count || !Market.TryDistance(origin, port, out _))
|
||||
return false;
|
||||
origin = port;
|
||||
}
|
||||
|
||||
int berth = itinerary.CompletedStops == 0 ? itinerary.Origin : itinerary.Stops[itinerary.CompletedStops - 1];
|
||||
return berth == ship.Port || !itinerary.HasNext;
|
||||
}
|
||||
|
||||
private static (int Burn, int Reserve) LegFuel(Ship ship, int miles)
|
||||
{
|
||||
int burn = (int)Math.Ceiling(ship.BurnPerMile * miles);
|
||||
return (burn, Math.Max(6, (int)Math.Ceiling(burn * .12)));
|
||||
}
|
||||
|
||||
private void RecordItineraryArrival(Ship ship, Voyage quote)
|
||||
{
|
||||
if (ship.Itinerary is not { HasNext: true } itinerary)
|
||||
return;
|
||||
if (itinerary.CompletedStops == 0)
|
||||
itinerary.StartDay = Day;
|
||||
itinerary.CompletedStops++;
|
||||
quote.ItineraryStartDay = itinerary.StartDay;
|
||||
quote.ItineraryLeg = itinerary.CompletedStops;
|
||||
quote.ItineraryLegs = itinerary.TotalStops;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Soundings/Runtime/CruiseItinerary.cs.meta
Normal file
2
Assets/Soundings/Runtime/CruiseItinerary.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9d75326dc384c118cc5ddc7f54ed921
|
||||
176
Assets/Soundings/Runtime/ItineraryPage.cs
Normal file
176
Assets/Soundings/Runtime/ItineraryPage.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
public sealed partial class SoundingsApp
|
||||
{
|
||||
private Ship itineraryEditorShip;
|
||||
|
||||
private bool EditingItinerary => Ship != null && Ship == itineraryEditorShip;
|
||||
|
||||
private static int ItineraryTail(Ship ship) => ship.Itinerary?.HasNext == true ? ship.Itinerary.LastPort : ship.Port;
|
||||
|
||||
private static bool IsPendingCall(CruiseItinerary itinerary, int port)
|
||||
{
|
||||
for (int i = itinerary.CompletedStops; i < itinerary.TotalStops; i++)
|
||||
if (itinerary.Stops[i] == port)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private void DrawItineraryButton(VisualElement controls, Ship ship)
|
||||
{
|
||||
int calls = ship.Itinerary?.TotalStops ?? 0;
|
||||
string label = calls > 0 ? $"Itinerary · {calls}" : "Itinerary";
|
||||
Button button = Action(label, () =>
|
||||
{
|
||||
if (EditingItinerary)
|
||||
CloseItinerary();
|
||||
else
|
||||
{
|
||||
itineraryEditorShip = ship;
|
||||
portOrdersOpen = false;
|
||||
chartScrollPosition = 0;
|
||||
Notify(null);
|
||||
Render();
|
||||
}
|
||||
}, EditingItinerary ? "chart-scope chart-scope-current" : "chart-scope", "itinerary-open");
|
||||
button.tooltip = "Plan consecutive port calls for this ship";
|
||||
controls.Add(button);
|
||||
}
|
||||
|
||||
private void DrawItineraryFolio(VisualElement parent, Ship ship)
|
||||
{
|
||||
var header = Add(parent, "chart-itinerary-header");
|
||||
AddDisplay(header, "Itinerary", "chart-itinerary-title");
|
||||
header.Add(Action("Back", CloseItinerary, "chart-ink-button chart-itinerary-mini", "itinerary-close"));
|
||||
|
||||
CruiseItinerary itinerary = ship.Itinerary;
|
||||
if (itinerary?.HasNext == true)
|
||||
{
|
||||
parent.Add(Action($"Review next leg · {Market.Ports[itinerary.NextPort].Name}",
|
||||
CloseItinerary, "chart-ink-button chart-itinerary-review", "itinerary-next"));
|
||||
}
|
||||
else if (itinerary?.TotalStops > 0)
|
||||
AddText(parent, "Itinerary complete", "chart-itinerary-note");
|
||||
|
||||
AddText(parent, "PORT CALLS", "chart-paper-kicker chart-paper-section");
|
||||
int initial = itinerary?.Origin ?? ship.Port;
|
||||
var departure = Add(parent, "chart-itinerary-row");
|
||||
AddText(departure, "START", "chart-itinerary-number");
|
||||
AddText(departure, Market.Ports[initial].Name, "chart-itinerary-port");
|
||||
if (itinerary != null)
|
||||
{
|
||||
int from = itinerary.Origin;
|
||||
for (int index = 0; index < itinerary.TotalStops; index++)
|
||||
{
|
||||
int to = itinerary.Stops[index];
|
||||
var row = Add(parent, "chart-itinerary-row");
|
||||
row.EnableInClassList("chart-itinerary-row-next", index == itinerary.CompletedStops);
|
||||
AddText(row, $"{index + 1:00}", "chart-itinerary-number");
|
||||
var copy = Add(row, "chart-itinerary-call");
|
||||
AddText(copy, Market.Ports[to].Name, "chart-itinerary-port");
|
||||
Market.TryDistance(from, to, out int miles);
|
||||
string state = index < itinerary.CompletedStops ? "Visited" : index == itinerary.CompletedStops ? "Next" : "Planned";
|
||||
AddText(copy, $"{state} · {miles:N0} nm", "chart-itinerary-note");
|
||||
from = to;
|
||||
}
|
||||
|
||||
var controls = Add(parent, "chart-itinerary-controls");
|
||||
var remove = Action("Remove last call", () => UpdateItinerary(ship,
|
||||
company.RemoveItineraryStop(ship, itinerary.TotalStops - 1), "Last call removed."),
|
||||
"chart-ink-button chart-itinerary-mini", "itinerary-remove");
|
||||
remove.SetEnabled(itinerary.HasNext);
|
||||
controls.Add(remove);
|
||||
controls.Add(Action("Clear route", () => UpdateItinerary(ship, company.ClearItinerary(ship), "Itinerary cleared."),
|
||||
"chart-ink-button chart-itinerary-mini", "itinerary-clear"));
|
||||
}
|
||||
|
||||
int tail = ItineraryTail(ship);
|
||||
DrawItineraryConnections(parent, ship, tail);
|
||||
|
||||
int selected = inspectedPort;
|
||||
string portName = Market.Ports[selected].Name;
|
||||
string blocked = company.ItineraryStopBlock(ship, selected);
|
||||
AddText(parent, portName, "chart-itinerary-selection");
|
||||
if (Market.TryDistance(tail, selected, out int distance))
|
||||
AddText(parent, $"{distance:N0} nm from {Market.Ports[tail].Name}", "chart-itinerary-note");
|
||||
|
||||
var append = Action($"Add {portName}", () => UpdateItinerary(ship, company.AppendItineraryStop(ship, selected),
|
||||
$"Added {portName} to the itinerary."), "chart-ink-button chart-itinerary-review", "itinerary-add");
|
||||
append.SetEnabled(blocked == null);
|
||||
parent.Add(append);
|
||||
if (blocked != null)
|
||||
AddText(parent, blocked, "chart-itinerary-note");
|
||||
if (!company.Permits[selected] && Market.TryDistance(tail, selected, out _))
|
||||
{
|
||||
var permit = Action($"Acquire permit · {Money(Market.Ports[selected].Permit)}", () =>
|
||||
Apply(company.Permit(selected), $"{portName} is now licensed."),
|
||||
"chart-ink-button chart-itinerary-review", "permit");
|
||||
permit.SetEnabled(company.PermitBlock(selected) == null);
|
||||
parent.Add(permit);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawItineraryConnections(VisualElement parent, Ship ship, int tail)
|
||||
{
|
||||
AddText(parent, $"CONNECTED FROM {Market.Ports[tail].Name.ToUpperInvariant()}", "chart-paper-kicker chart-paper-section");
|
||||
var connections = Add(parent, "chart-itinerary-connections");
|
||||
foreach (Lane lane in Market.Lanes)
|
||||
{
|
||||
int port = lane.Other(tail);
|
||||
if (port < 0)
|
||||
continue;
|
||||
var choice = Action(Market.Ports[port].Name, () => InspectChartPort(port),
|
||||
"chart-ink-button chart-itinerary-mini chart-itinerary-choice", $"itinerary-port-{port}");
|
||||
choice.EnableInClassList("chart-itinerary-choice-selected", port == inspectedPort);
|
||||
string blocker = company.ItineraryStopBlock(ship, port);
|
||||
choice.EnableInClassList("chart-itinerary-choice-restricted", blocker != null);
|
||||
choice.tooltip = blocker ?? $"{lane.Miles:N0} nm from {Market.Ports[tail].Name}";
|
||||
connections.Add(choice);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawNextCall(VisualElement parent, CruiseItinerary itinerary, int selected)
|
||||
{
|
||||
var strip = Add(parent, "chart-itinerary-next");
|
||||
string name = Market.Ports[itinerary.NextPort].Name;
|
||||
AddText(strip, $"LEG {itinerary.CompletedStops + 1} OF {itinerary.TotalStops}", "chart-paper-kicker");
|
||||
if (selected != itinerary.NextPort)
|
||||
strip.Add(Action($"Review {name}", CloseItinerary, "chart-ink-button chart-itinerary-mini", "itinerary-next"));
|
||||
}
|
||||
|
||||
private void CloseItinerary()
|
||||
{
|
||||
itineraryEditorShip = null;
|
||||
int planned = Ship?.Itinerary?.NextPort ?? -1;
|
||||
if (planned >= 0)
|
||||
{
|
||||
destination = planned;
|
||||
SetRecommendedFuel();
|
||||
InspectChartPort(planned);
|
||||
}
|
||||
else
|
||||
{
|
||||
chartScrollPosition = 0;
|
||||
InspectChartPort(inspectedPort);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateItinerary(Ship ship, string failure, string success)
|
||||
{
|
||||
if (failure == null)
|
||||
{
|
||||
int planned = ship.Itinerary?.NextPort ?? -1;
|
||||
if (planned >= 0)
|
||||
{
|
||||
destination = planned;
|
||||
SetRecommendedFuel();
|
||||
}
|
||||
else
|
||||
ResetItinerary();
|
||||
}
|
||||
Apply(failure, success);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Soundings/Runtime/ItineraryPage.cs.meta
Normal file
2
Assets/Soundings/Runtime/ItineraryPage.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63dd5ad68fc8a95f7900594456f4bb71
|
||||
@@ -56,6 +56,9 @@ namespace Soundings
|
||||
AddText(register, "VOYAGE REGISTER", "log-small-title");
|
||||
AddDisplay(register, "Passages", "log-sheet-title");
|
||||
AddText(register, $"{company.Voyages:N0} completed", "log-secondary");
|
||||
if (Ship?.Itinerary is { HasNext: true, CompletedStops: > 0 } itinerary)
|
||||
register.Add(Action($"Plan next leg · {Market.Ports[itinerary.NextPort].Name}", OpenVoyageChart,
|
||||
"log-paper-action log-next-leg", "log-next-leg"));
|
||||
AddText(register, company.Flagship
|
||||
? "Flagship charter complete · Bermuda to Lisbon"
|
||||
: "Flagship charter · Bermuda to Lisbon",
|
||||
@@ -130,7 +133,8 @@ namespace Soundings
|
||||
|
||||
private void DrawVoyageEntry(VisualElement leaf, Voyage trip)
|
||||
{
|
||||
AddText(leaf, $"ARRIVED ON DAY {trip.Day}", "log-small-title");
|
||||
string leg = trip.ItineraryLeg > 0 ? $" · ITINERARY LEG {trip.ItineraryLeg} OF {trip.ItineraryLegs}" : "";
|
||||
AddText(leaf, $"ARRIVED ON DAY {trip.Day}{leg}", "log-small-title");
|
||||
string origin = Market.Ports[trip.Origin].Name;
|
||||
string destinationName = Market.Ports[trip.Destination].Name;
|
||||
AddDisplay(leaf, $"{origin} to {destinationName}", "log-sheet-title log-route-title");
|
||||
|
||||
@@ -3,7 +3,7 @@ using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
internal enum PassageAnnouncement { Departure, Dining, DiningSpecial, Bar, Show, Terrace }
|
||||
internal enum PassageAnnouncement { Departure, Dining, DiningSpecial, Bar, Show, Terrace, Approach }
|
||||
|
||||
internal sealed class PassageAudio : MonoBehaviour
|
||||
{
|
||||
@@ -20,15 +20,25 @@ namespace Soundings
|
||||
|
||||
private AudioSource wind, engine, effects, voice;
|
||||
private AudioClip step, hardStep, confirmation;
|
||||
private AudioClip departureForPort, approachForPort;
|
||||
private readonly AudioClip[] spoken = new AudioClip[Announcements.Length];
|
||||
private readonly float[] repeatAfter = new float[Announcements.Length];
|
||||
private readonly float[] repeatAfter = new float[(int)PassageAnnouncement.Approach + 1];
|
||||
private float distanceSinceStep;
|
||||
private float announcementTime, announcementGap, announcementClock;
|
||||
private bool leftFoot, crossing, voicePaused;
|
||||
private bool leftFoot, crossing, voicePaused, approachSent;
|
||||
private PassageAnnouncement? currentAnnouncement, pendingAnnouncement;
|
||||
private string nextPort;
|
||||
|
||||
internal PassageAnnouncement? CurrentAnnouncement => currentAnnouncement;
|
||||
internal string Caption => currentAnnouncement.HasValue ? Announcements[(int)currentAnnouncement.Value] : null;
|
||||
internal float ApproachSeconds => approachForPort != null ? approachForPort.length : 0;
|
||||
internal bool ApproachSent => approachSent;
|
||||
internal string Caption => currentAnnouncement switch
|
||||
{
|
||||
PassageAnnouncement.Departure when departureForPort != null => $"Welcome aboard. We are now under way, and our next port of call is {nextPort}.",
|
||||
PassageAnnouncement.Approach => $"May I have your attention, please. We are approaching {nextPort}.",
|
||||
PassageAnnouncement line => Announcements[(int)line],
|
||||
_ => null
|
||||
};
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
@@ -59,9 +69,13 @@ namespace Soundings
|
||||
spoken[i] = Resources.Load<AudioClip>($"Audio/PA/{(PassageAnnouncement)i}");
|
||||
}
|
||||
|
||||
internal void Begin()
|
||||
internal void Begin(int destination)
|
||||
{
|
||||
crossing = true;
|
||||
approachSent = false;
|
||||
nextPort = Market.Ports[destination].Name;
|
||||
departureForPort = LoadPortClip("Departure", destination);
|
||||
approachForPort = LoadPortClip("Approach", destination);
|
||||
distanceSinceStep = 0;
|
||||
announcementClock = announcementGap = 0;
|
||||
Array.Clear(repeatAfter, 0, repeatAfter.Length);
|
||||
@@ -76,12 +90,14 @@ namespace Soundings
|
||||
voice.Stop();
|
||||
voicePaused = false;
|
||||
currentAnnouncement = pendingAnnouncement = null;
|
||||
departureForPort = approachForPort = null;
|
||||
voice.clip = null;
|
||||
}
|
||||
|
||||
internal void Announce(PassageAnnouncement line)
|
||||
{
|
||||
int index = (int)line;
|
||||
if (!crossing || spoken[index] == null || currentAnnouncement == line || pendingAnnouncement == line
|
||||
if (!crossing || ClipFor(line) == null || currentAnnouncement == line || pendingAnnouncement == line
|
||||
|| repeatAfter[index] > announcementClock)
|
||||
return;
|
||||
|
||||
@@ -91,6 +107,28 @@ namespace Soundings
|
||||
PlayAnnouncement(line);
|
||||
}
|
||||
|
||||
internal void AnnounceApproach()
|
||||
{
|
||||
if (!crossing || approachSent || approachForPort == null)
|
||||
return;
|
||||
|
||||
approachSent = true;
|
||||
pendingAnnouncement = null;
|
||||
announcementGap = 0;
|
||||
voice.Stop();
|
||||
PlayAnnouncement(PassageAnnouncement.Approach);
|
||||
}
|
||||
|
||||
internal static AudioClip LoadPortClip(string announcement, int destination) =>
|
||||
Resources.Load<AudioClip>($"Audio/PA/{announcement}Port{destination:D2}");
|
||||
|
||||
private AudioClip ClipFor(PassageAnnouncement line) => line switch
|
||||
{
|
||||
PassageAnnouncement.Departure when departureForPort != null => departureForPort,
|
||||
PassageAnnouncement.Approach => approachForPort,
|
||||
_ => spoken[(int)line]
|
||||
};
|
||||
|
||||
internal void Mix(float delta, bool active, float knots, WeatherCondition weather, bool indoors, bool engineering)
|
||||
{
|
||||
UpdateAnnouncements(delta, active);
|
||||
@@ -119,7 +157,7 @@ namespace Soundings
|
||||
{
|
||||
int index = (int)line;
|
||||
currentAnnouncement = line;
|
||||
voice.clip = spoken[index];
|
||||
voice.clip = ClipFor(line);
|
||||
announcementTime = voice.clip.length;
|
||||
repeatAfter[index] = announcementClock + 20f;
|
||||
voice.Play();
|
||||
|
||||
@@ -69,6 +69,9 @@ namespace Soundings
|
||||
controls.Add(Action("Bridge", ViewPassageBridge, PassageViewClass(passageBridge), "passage-bridge"));
|
||||
controls.Add(Action("Explore", ExplorePassageDeck, PassageViewClass(passageExploring && passageServiceArea < 0), "passage-explore"));
|
||||
controls.Add(Action("Service deck", () => ExploreServiceArea(0), PassageViewClass(passageServiceArea >= 0), "passage-service"));
|
||||
Button map = Action("Voyage map", ToggleVoyageMap, PassageViewClass(voyageMapOpen), "voyage-map-toggle");
|
||||
map.tooltip = "Show or close the live voyage map (M)";
|
||||
controls.Add(map);
|
||||
controls.Add(Action("Reset camera", () =>
|
||||
{
|
||||
if (passageBridge)
|
||||
@@ -90,7 +93,8 @@ namespace Soundings
|
||||
_ => "Calm seas"
|
||||
};
|
||||
var routeContext = Add(route, "voyage-route-context");
|
||||
AddText(routeContext, $"UNDERWAY / {underway.ShipName.ToUpperInvariant()}", "voyage-caption");
|
||||
string leg = Ship.Itinerary is { HasNext: true } itinerary ? $"LEG {itinerary.CompletedStops + 1} OF {itinerary.TotalStops}" : "UNDERWAY";
|
||||
AddText(routeContext, $"{leg} / {underway.ShipName.ToUpperInvariant()}", "voyage-caption");
|
||||
AddText(routeContext, sea, underway.Weather == WeatherCondition.Storm
|
||||
? "voyage-conditions voyage-conditions-warning" : "voyage-conditions");
|
||||
AddDisplay(route, $"{Market.Ports[underway.Origin].Name} → {Market.Ports[underway.Destination].Name}", "voyage-route-name");
|
||||
@@ -120,8 +124,9 @@ namespace Soundings
|
||||
AddText(camera, cameraHelp, "voyage-camera-help");
|
||||
rail.Add(Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now"));
|
||||
DrawHelmControls(overlay);
|
||||
DrawAnnouncement(overlay);
|
||||
DrawStationInteractions(overlay);
|
||||
DrawVoyageMap(overlay);
|
||||
DrawAnnouncement(overlay);
|
||||
UpdatePassageUi(passageHelm.Progress);
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,12 @@ namespace Soundings
|
||||
bunkerTons = 0;
|
||||
if (Ship == null)
|
||||
return;
|
||||
if (Ship.Itinerary is { HasNext: true } itinerary)
|
||||
{
|
||||
destination = itinerary.NextPort;
|
||||
SetRecommendedFuel();
|
||||
return;
|
||||
}
|
||||
foreach (Lane lane in Market.Lanes)
|
||||
{
|
||||
int other = lane.Other(Ship.Port);
|
||||
@@ -384,7 +390,8 @@ namespace Soundings
|
||||
|
||||
var commands = Add(scene, "helm-orders");
|
||||
commands.pickingMode = PickingMode.Ignore;
|
||||
Button plan = Action("Set course", OpenVoyageChart, "primary helm-command", "plan-voyage");
|
||||
Button plan = Action(ship.Itinerary is { HasNext: true, CompletedStops: > 0 } ? "Plan next leg" : "Set course",
|
||||
OpenVoyageChart, "primary helm-command", "plan-voyage");
|
||||
GameIcon(plan, "chart");
|
||||
commands.Add(plan);
|
||||
var camera = Add(commands, "camera-legend");
|
||||
|
||||
@@ -20,6 +20,15 @@ namespace Soundings
|
||||
|
||||
string directory = args[index + 1];
|
||||
Directory.CreateDirectory(directory);
|
||||
for (int port = 0; port < Market.Ports.Count; port++)
|
||||
{
|
||||
if (!CheckSmoke(PassageAudio.LoadPortClip("Departure", port) is { length: > 1 }
|
||||
&& PassageAudio.LoadPortClip("Approach", port) is { length: > 1 }, "Named PA recordings for " + Market.Ports[port].Name))
|
||||
yield break;
|
||||
}
|
||||
Vector2[] pacific = MapPaths(new[] { 15, 16 })[0];
|
||||
if (!CheckSmoke(Mathf.Abs(pacific[MapSamples].x - pacific[0].x) < 45, "Voyage map wraps the date line"))
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "01-title");
|
||||
|
||||
if (!CheckSmoke(guidedCareer, "The guide is on by default")
|
||||
@@ -55,8 +64,8 @@ namespace Soundings
|
||||
&& underway.Plan?.FoodUnits == 1120 && underway.Plan.Program == EntertainmentProgram.LiveMusic,
|
||||
"Cast off into an assisted live crossing"))
|
||||
yield break;
|
||||
if (!CheckSmoke(passageAudio.CurrentAnnouncement == PassageAnnouncement.Departure && passageAudio.Caption.StartsWith("Welcome aboard"),
|
||||
"Cast off starts the spoken welcome and its caption"))
|
||||
if (!CheckSmoke(passageAudio.CurrentAnnouncement == PassageAnnouncement.Departure
|
||||
&& passageAudio.Caption.Contains("next port of call is Nassau"), "Cast off names Nassau on the ship's PA"))
|
||||
yield break;
|
||||
int mealPrice = livePassage.GetPrice(OnboardService.Meals);
|
||||
int provisions = livePassage.ProvisionsRemaining;
|
||||
@@ -204,24 +213,66 @@ namespace Soundings
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "10-world");
|
||||
|
||||
if (!SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-0") || !SubmitSmoke("weather-storm")
|
||||
if (!SubmitSmoke("nav-0") || !SubmitSmoke("plan-voyage") || !SubmitSmoke("port-0")
|
||||
|| !SubmitSmoke("itinerary-open") || !SubmitSmoke("itinerary-add") || !SubmitSmoke("itinerary-port-2")
|
||||
|| !SubmitSmoke("itinerary-add") || !CheckSmoke(Ship.Itinerary is { TotalStops: 2, NextPort: 0, LastPort: 2 }
|
||||
&& destination == 0, "Plan Nassau to Miami to Key West without changing the first departure"))
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "10a-itinerary-plan");
|
||||
if (!SubmitSmoke("itinerary-port-1") || !SubmitSmoke("itinerary-add") || !SubmitSmoke("itinerary-remove")
|
||||
|| !CheckSmoke(Ship.Itinerary.TotalStops == 2 && Ship.Itinerary.LastPort == 2, "Edit the last pending call")
|
||||
|| !SubmitSmoke("itinerary-next") || !SubmitSmoke("weather-storm")
|
||||
|| !SubmitSmoke("dispatch") || !CheckSmoke(underway.Weather == WeatherCondition.Storm
|
||||
&& livePassage.Get(OnboardService.Amenities).Capacity == 0, "Rough sea closes outdoor amenities"))
|
||||
&& livePassage.Get(OnboardService.Amenities).Capacity == 0 && passageAudio.Caption.Contains("Miami"),
|
||||
"Depart for the first planned call in a storm"))
|
||||
yield break;
|
||||
SelectPassageDeck(2);
|
||||
if (!CheckSmoke(passageDeck == 2, "Visit the newly fitted third deck during the next crossing"))
|
||||
yield break;
|
||||
MovePassageToSmoke(.42f);
|
||||
yield return CaptureSmoke(directory, "11-new-service-deck");
|
||||
if (!SubmitSmoke("voyage-map-toggle") || !CheckSmoke(voyageMapOpen && voyageMapPlot != null, "Open the live voyage map"))
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "11a-live-voyage-map");
|
||||
if (!SubmitSmoke("voyage-map-close"))
|
||||
yield break;
|
||||
SetPassageSpeed(4);
|
||||
if (!CheckSmoke(passageSpeed == 4, "Fast-forward setting"))
|
||||
yield break;
|
||||
MovePassageToSmoke(.95f);
|
||||
MovePassageToSmoke(.87f);
|
||||
UpdatePortApproach();
|
||||
if (!CheckSmoke(passageAudio.ApproachSent && passageAudio.CurrentAnnouncement == PassageAnnouncement.Approach
|
||||
&& passageAudio.Caption.Contains("approaching Miami"), "The ship announces its approach to Miami before docking"))
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "11b-approaching-miami");
|
||||
float timeout = Time.realtimeSinceStartup + 15;
|
||||
while (underway != null && Time.realtimeSinceStartup < timeout)
|
||||
yield return null;
|
||||
if (!CheckSmoke(underway == null && Ship.Port == 0 && company.Voyages == 2, "Timed passage and second settlement"))
|
||||
if (!CheckSmoke(underway == null && Ship.Port == 0 && company.Voyages == 2
|
||||
&& Ship.Itinerary is { CompletedStops: 1, NextPort: 2 }
|
||||
&& company.History[0].ItineraryLeg == 1, "Settle the first itinerary leg and remain in Miami"))
|
||||
yield break;
|
||||
company = JsonUtility.FromJson<Company>(JsonUtility.ToJson(company));
|
||||
if (!CheckSmoke(company.CanLoad() && Ship.Itinerary.NextPort == 2, "Continue the same ship's itinerary after reloading at a call"))
|
||||
yield break;
|
||||
ResetItinerary();
|
||||
Render();
|
||||
yield return CaptureSmoke(directory, "11c-intermediate-arrival");
|
||||
if (!SubmitSmoke("log-next-leg") || !CheckSmoke(destination == 2 && inspectedPort == 2, "Review the next call from the Logbook")
|
||||
|| !SubmitSmoke("buy-fuel") || !SubmitSmoke("dispatch")
|
||||
|| !CheckSmoke(underway.Origin == 0 && underway.Destination == 2 && passageAudio.Caption.Contains("Key West"),
|
||||
"Fuel at the intermediate stop and cast off with the correct new port name"))
|
||||
yield break;
|
||||
MovePassageToSmoke(.9f);
|
||||
UpdatePortApproach();
|
||||
if (!CheckSmoke(passageAudio.CurrentAnnouncement == PassageAnnouncement.Approach
|
||||
&& passageAudio.Caption.Contains("approaching Key West"), "The second leg announces Key West")
|
||||
|| !SubmitSmoke("dock-now") || !CheckSmoke(Ship.Port == 2 && company.Voyages == 3
|
||||
&& Ship.Itinerary is { CompletedStops: 2, HasNext: false }
|
||||
&& company.History[0].ItineraryLeg == 2 && company.History[0].ItineraryStartDay == company.History[1].ItineraryStartDay,
|
||||
"Complete the itinerary with two linked ledger records"))
|
||||
yield break;
|
||||
yield return CaptureSmoke(directory, "11d-itinerary-complete");
|
||||
|
||||
if (!SubmitSmoke("company-menu") || !SubmitSmoke("return-title") || !SubmitSmoke("start-financed") || !SubmitSmoke("replace")
|
||||
|| !CheckSmoke(company.Debt == 500000 && company.Fleet.Count == 0 && guideContext == GuideStep.GetShip, "Guided financed start"))
|
||||
|
||||
298
Assets/Soundings/Runtime/VoyageMap.cs
Normal file
298
Assets/Soundings/Runtime/VoyageMap.cs
Normal file
@@ -0,0 +1,298 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
public sealed partial class SoundingsApp
|
||||
{
|
||||
private const int MapSamples = 40;
|
||||
private static readonly Color MapCompleted = new(.49f, .66f, .65f);
|
||||
private static readonly Color MapCurrent = new(.98f, .79f, .44f);
|
||||
private static readonly Color MapPlanned = new(.31f, .79f, .68f);
|
||||
private bool voyageMapOpen;
|
||||
private VisualElement voyageMapPlot;
|
||||
private Label voyageMapReadout;
|
||||
private float nextMapUpdate;
|
||||
|
||||
private void ToggleVoyageMap()
|
||||
{
|
||||
voyageMapOpen = !voyageMapOpen;
|
||||
Render();
|
||||
}
|
||||
|
||||
private void DrawVoyageMap(VisualElement overlay)
|
||||
{
|
||||
voyageMapPlot = null;
|
||||
if (!voyageMapOpen)
|
||||
return;
|
||||
|
||||
CruiseItinerary itinerary = Ship.Itinerary;
|
||||
bool scheduled = itinerary is { HasNext: true } && itinerary.NextPort == underway.Destination;
|
||||
int currentLeg = scheduled ? itinerary.CompletedStops : 0;
|
||||
var ports = new int[scheduled ? itinerary.TotalStops + 1 : 2];
|
||||
ports[0] = scheduled ? itinerary.Origin : underway.Origin;
|
||||
if (scheduled)
|
||||
itinerary.Stops.CopyTo(ports, 1);
|
||||
else
|
||||
ports[1] = underway.Destination;
|
||||
|
||||
Vector2[][] paths = MapPaths(ports);
|
||||
var chart = Add(overlay, "voyage-map");
|
||||
var header = Add(chart, "voyage-map-header");
|
||||
var heading = Add(header, "voyage-map-heading");
|
||||
AddDisplay(heading, "Voyage map", "voyage-map-title");
|
||||
AddText(heading, scheduled ? $"Leg {currentLeg + 1} of {ports.Length - 1} · {underway.ShipName}" : underway.ShipName,
|
||||
"voyage-map-readout");
|
||||
header.Add(Action("Close M", ToggleVoyageMap, "voyage-view-button", "voyage-map-close"));
|
||||
|
||||
var plot = Add(chart, "voyage-map-plot");
|
||||
voyageMapPlot = plot;
|
||||
AddText(plot, "N ↑", "voyage-map-north").pickingMode = PickingMode.Ignore;
|
||||
var labels = new Dictionary<int, Label>();
|
||||
foreach (int port in ports)
|
||||
{
|
||||
if (labels.ContainsKey(port))
|
||||
continue;
|
||||
Label label = AddText(plot, Market.Ports[port].Name, "voyage-map-port");
|
||||
label.pickingMode = PickingMode.Ignore;
|
||||
if (port == underway.Destination)
|
||||
label.AddToClassList("voyage-map-port-next");
|
||||
labels.Add(port, label);
|
||||
}
|
||||
plot.generateVisualContent += context => PaintVoyageMap(context, paths, currentLeg);
|
||||
plot.RegisterCallback<GeometryChangedEvent>(change => PlaceMapLabels(change.newRect.size, paths, ports, labels));
|
||||
|
||||
var footer = Add(chart, "voyage-map-footer");
|
||||
voyageMapReadout = AddText(footer, "", "voyage-map-readout");
|
||||
var legend = Add(footer, "voyage-map-legend");
|
||||
if (currentLeg > 0)
|
||||
MapLegend(legend, "Sailed", MapCompleted);
|
||||
MapLegend(legend, "Current leg", MapCurrent);
|
||||
if (currentLeg < paths.Length - 1)
|
||||
MapLegend(legend, "Later calls", MapPlanned);
|
||||
nextMapUpdate = 0;
|
||||
UpdateVoyageMap();
|
||||
}
|
||||
|
||||
private static void MapLegend(VisualElement legend, string text, Color color)
|
||||
{
|
||||
var key = Add(legend, "voyage-map-key");
|
||||
Add(key, "voyage-map-swatch").style.backgroundColor = color;
|
||||
AddText(key, text, "voyage-map-readout");
|
||||
}
|
||||
|
||||
private void UpdateVoyageMap()
|
||||
{
|
||||
if (voyageMapPlot == null || Time.unscaledTime < nextMapUpdate)
|
||||
return;
|
||||
nextMapUpdate = Time.unscaledTime + .08f;
|
||||
float duration = PassageDuration(underway);
|
||||
int distance = Mathf.RoundToInt(underway.Miles * passageHelm.RemainingSeconds / duration);
|
||||
int heading = Mathf.RoundToInt(Mathf.Repeat(CourseBearing(Market.Ports[underway.Origin], Market.Ports[underway.Destination])
|
||||
+ passageHelm.Heading, 360)) % 360;
|
||||
SetPassageText(voyageMapReadout, $"{Market.Ports[underway.Destination].Name} · {distance:N0} nm · {heading:000}° · {passageHelm.Speed:F1} kn");
|
||||
voyageMapPlot.MarkDirtyRepaint();
|
||||
}
|
||||
|
||||
private static Vector2[][] MapPaths(int[] ports)
|
||||
{
|
||||
var paths = new Vector2[ports.Length - 1][];
|
||||
float longitude = Market.Ports[ports[0]].Longitude;
|
||||
for (int leg = 0; leg < paths.Length; leg++)
|
||||
{
|
||||
PortSpec origin = Market.Ports[ports[leg]], dest = Market.Ports[ports[leg + 1]];
|
||||
float start = longitude;
|
||||
longitude = start + Mathf.DeltaAngle(start, dest.Longitude);
|
||||
Vector3 a = GlobePoint(origin), b = GlobePoint(dest);
|
||||
Vector2[] path = paths[leg] = new Vector2[MapSamples + 1];
|
||||
for (int s = 0; s <= MapSamples; s++)
|
||||
{
|
||||
float t = (float)s / MapSamples;
|
||||
Vector3 point = Vector3.Slerp(a, b, t);
|
||||
float expected = Mathf.Lerp(start, longitude, t);
|
||||
float lon = Mathf.Atan2(point.z, point.x) * Mathf.Rad2Deg;
|
||||
path[s] = new Vector2(expected + Mathf.DeltaAngle(expected, lon), -Mathf.Asin(point.y) * Mathf.Rad2Deg);
|
||||
}
|
||||
}
|
||||
return paths;
|
||||
}
|
||||
|
||||
private static Vector3 GlobePoint(PortSpec port)
|
||||
{
|
||||
float lat = port.Latitude * Mathf.Deg2Rad, lon = port.Longitude * Mathf.Deg2Rad;
|
||||
return new Vector3(Mathf.Cos(lat) * Mathf.Cos(lon), Mathf.Sin(lat), Mathf.Cos(lat) * Mathf.Sin(lon));
|
||||
}
|
||||
|
||||
private readonly struct MapProjection
|
||||
{
|
||||
public readonly Vector2 Center, Dimensions;
|
||||
public readonly float Scale;
|
||||
|
||||
public MapProjection(Vector2 size, Vector2[][] paths)
|
||||
{
|
||||
var minimum = paths[0][0];
|
||||
var maximum = minimum;
|
||||
foreach (Vector2[] path in paths)
|
||||
foreach (Vector2 point in path)
|
||||
{
|
||||
minimum = Vector2.Min(minimum, point);
|
||||
maximum = Vector2.Max(maximum, point);
|
||||
}
|
||||
Center = (minimum + maximum) * .5f;
|
||||
Vector2 span = Vector2.Max(maximum - minimum, new Vector2(5.5f, 3.1f));
|
||||
Scale = Mathf.Max(.01f, Mathf.Min((size.x - 146) / span.x, (size.y - 86) / span.y));
|
||||
Dimensions = size;
|
||||
}
|
||||
|
||||
public Vector2 Pixel(Vector2 point) => Dimensions * .5f + (point - Center) * Scale;
|
||||
}
|
||||
|
||||
private static void PlaceMapLabels(Vector2 size, Vector2[][] paths, int[] ports, Dictionary<int, Label> labels)
|
||||
{
|
||||
var projection = new MapProjection(size, paths);
|
||||
var used = new HashSet<int>();
|
||||
var rows = new List<Rect>(ports.Length);
|
||||
for (int i = 0; i < ports.Length; i++)
|
||||
{
|
||||
int port = ports[i];
|
||||
if (!used.Add(port))
|
||||
continue;
|
||||
Vector2 pixel = projection.Pixel(i == 0 ? paths[0][0] : paths[i - 1][MapSamples]);
|
||||
Label label = labels[port];
|
||||
float width = Mathf.Min(150, label.text.Length * 7 + 12);
|
||||
float x = Mathf.Clamp(pixel.x + 10, 7, Mathf.Max(7, size.x - width - 7));
|
||||
float y = Mathf.Clamp(pixel.y - 21, 6, Mathf.Max(6, size.y - 26));
|
||||
var area = new Rect(x, y, width, 20);
|
||||
for (int j = 0; j < rows.Count; j++)
|
||||
{
|
||||
if (area.Overlaps(rows[j]))
|
||||
area.y = Mathf.Min(size.y - 26, rows[j].yMax + 2);
|
||||
}
|
||||
rows.Add(area);
|
||||
label.style.left = area.x;
|
||||
label.style.top = area.y;
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintVoyageMap(MeshGenerationContext context, Vector2[][] paths, int currentLeg)
|
||||
{
|
||||
Vector2 size = context.visualElement.contentRect.size;
|
||||
if (size.x < 50 || size.y < 50)
|
||||
return;
|
||||
var projection = new MapProjection(size, paths);
|
||||
Painter2D pen = context.painter2D;
|
||||
PaintMapGrid(pen, projection);
|
||||
PaintMapCoast(pen, projection);
|
||||
|
||||
for (int i = 0; i < paths.Length; i++)
|
||||
{
|
||||
if (i == currentLeg)
|
||||
continue;
|
||||
Color color = i < currentLeg ? MapCompleted : MapPlanned;
|
||||
PaintMapPath(pen, projection, paths[i], color, 1.65f);
|
||||
PaintMapPort(pen, projection.Pixel(paths[i][0]), color);
|
||||
PaintMapPort(pen, projection.Pixel(paths[i][MapSamples]), color);
|
||||
}
|
||||
|
||||
Vector2[] current = paths[currentLeg];
|
||||
PaintMapPath(pen, projection, current, new Color(.98f, .79f, .44f, .21f), 8);
|
||||
PaintMapPath(pen, projection, current, MapCurrent, 2.6f);
|
||||
PaintMapPort(pen, projection.Pixel(current[0]), MapCurrent);
|
||||
PaintMapPort(pen, projection.Pixel(current[MapSamples]), MapCurrent);
|
||||
Vector2 travel = passageHelm.Position / PassageDuration(underway);
|
||||
float step = travel.x * MapSamples;
|
||||
int segment = Mathf.Clamp(Mathf.FloorToInt(step), 0, MapSamples - 1);
|
||||
Vector2 tangent = (current[segment + 1] - current[segment]).normalized;
|
||||
Vector2 right = new(-tangent.y, tangent.x);
|
||||
float span = Vector2.Distance(current[0], current[MapSamples]);
|
||||
Vector2 course = Vector2.LerpUnclamped(current[segment], current[segment + 1], step - segment);
|
||||
Vector2 location = projection.Pixel(course + right * (travel.y * span));
|
||||
location.x = Mathf.Clamp(location.x, 14, size.x - 14);
|
||||
location.y = Mathf.Clamp(location.y, 14, size.y - 14);
|
||||
float angle = passageHelm.Heading * Mathf.Deg2Rad;
|
||||
Vector2 forward = tangent * Mathf.Cos(angle) + right * Mathf.Sin(angle);
|
||||
Vector2 wing = new(-forward.y, forward.x);
|
||||
pen.fillColor = MapCurrent;
|
||||
pen.strokeColor = new Color(.09f, .18f, .22f);
|
||||
pen.lineWidth = 1.5f;
|
||||
pen.BeginPath();
|
||||
pen.MoveTo(location + forward * 11);
|
||||
pen.LineTo(location - forward * 8 + wing * 6);
|
||||
pen.LineTo(location - forward * 4);
|
||||
pen.LineTo(location - forward * 8 - wing * 6);
|
||||
pen.ClosePath();
|
||||
pen.Fill();
|
||||
pen.Stroke();
|
||||
}
|
||||
|
||||
private static void PaintMapGrid(Painter2D pen, MapProjection map)
|
||||
{
|
||||
Vector2 reach = map.Dimensions / (2 * map.Scale);
|
||||
float wanted = reach.x / 4;
|
||||
float factor = Mathf.Pow(10, Mathf.Floor(Mathf.Log10(wanted)));
|
||||
float interval = factor * (wanted / factor >= 5 ? 5 : wanted / factor >= 2 ? 2 : 1);
|
||||
pen.strokeColor = new Color(.37f, .59f, .62f, .26f);
|
||||
pen.lineWidth = 1;
|
||||
pen.BeginPath();
|
||||
for (float lon = Mathf.Ceil((map.Center.x - reach.x) / interval) * interval; lon <= map.Center.x + reach.x; lon += interval)
|
||||
{
|
||||
float x = map.Pixel(new Vector2(lon, 0)).x;
|
||||
pen.MoveTo(new Vector2(x, 0));
|
||||
pen.LineTo(new Vector2(x, map.Dimensions.y));
|
||||
}
|
||||
for (float lat = Mathf.Ceil((map.Center.y - reach.y) / interval) * interval; lat <= map.Center.y + reach.y; lat += interval)
|
||||
{
|
||||
float y = map.Pixel(new Vector2(0, lat)).y;
|
||||
pen.MoveTo(new Vector2(0, y));
|
||||
pen.LineTo(new Vector2(map.Dimensions.x, y));
|
||||
}
|
||||
pen.Stroke();
|
||||
}
|
||||
|
||||
private static void PaintMapCoast(Painter2D pen, MapProjection projection)
|
||||
{
|
||||
float reach = projection.Dimensions.x / (2 * projection.Scale);
|
||||
int first = Mathf.FloorToInt((projection.Center.x - reach + 180) / 360);
|
||||
int last = Mathf.FloorToInt((projection.Center.x + reach + 180) / 360);
|
||||
pen.fillColor = new Color(.14f, .27f, .28f);
|
||||
pen.strokeColor = new Color(.48f, .61f, .51f, .73f);
|
||||
pen.lineWidth = 1.1f;
|
||||
for (int zone = first; zone <= last; zone++)
|
||||
foreach (Vector2[] coast in WorldCoastlines.Shapes)
|
||||
{
|
||||
pen.BeginPath();
|
||||
for (int i = 0; i < coast.Length; i++)
|
||||
{
|
||||
Vector2 visual = projection.Pixel(new Vector2(coast[i].x * 360 - 180 + zone * 360, coast[i].y * 137 - 76));
|
||||
if (i == 0)
|
||||
pen.MoveTo(visual);
|
||||
else
|
||||
pen.LineTo(visual);
|
||||
}
|
||||
pen.ClosePath();
|
||||
pen.Fill();
|
||||
pen.Stroke();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PaintMapPath(Painter2D pen, MapProjection projection, Vector2[] path, Color color, float width)
|
||||
{
|
||||
pen.strokeColor = color;
|
||||
pen.lineWidth = width;
|
||||
pen.BeginPath();
|
||||
pen.MoveTo(projection.Pixel(path[0]));
|
||||
for (int i = 1; i < path.Length; i++)
|
||||
pen.LineTo(projection.Pixel(path[i]));
|
||||
pen.Stroke();
|
||||
}
|
||||
|
||||
private static void PaintMapPort(Painter2D pen, Vector2 port, Color color)
|
||||
{
|
||||
pen.fillColor = color;
|
||||
pen.BeginPath();
|
||||
pen.Arc(port, 4.1f, 0, 360);
|
||||
pen.Fill();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Soundings/Runtime/VoyageMap.cs.meta
Normal file
2
Assets/Soundings/Runtime/VoyageMap.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cc64b45be7d86579a2f71999064a145
|
||||
@@ -19,7 +19,9 @@ namespace Soundings
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Escape))
|
||||
{
|
||||
if (title && pendingStart.HasValue)
|
||||
if (!paused && underway != null && voyageMapOpen)
|
||||
ToggleVoyageMap();
|
||||
else if (title && pendingStart.HasValue)
|
||||
{
|
||||
pendingStart = null;
|
||||
Render();
|
||||
@@ -62,6 +64,8 @@ namespace Soundings
|
||||
private void UpdateActivePassage()
|
||||
{
|
||||
float delta = Time.unscaledDeltaTime;
|
||||
if (Input.GetKeyDown(KeyCode.M))
|
||||
ToggleVoyageMap();
|
||||
if (Input.GetKeyDown(KeyCode.H) && (passageBridge || passageHelm.Manual))
|
||||
ToggleHelm();
|
||||
|
||||
@@ -76,6 +80,7 @@ namespace Soundings
|
||||
}
|
||||
passageHelm.Advance(delta * passageSpeed, rudder, livePassage.SpeedFactor, underway.Weather);
|
||||
float progress = passageHelm.Progress;
|
||||
UpdatePortApproach();
|
||||
bool performanceWasActive = livePassage.PerformanceActive;
|
||||
livePassage.AdvanceTo(progress);
|
||||
if (!performanceWasActive && livePassage.PerformanceActive)
|
||||
@@ -139,6 +144,18 @@ namespace Soundings
|
||||
UpdateHelmControls();
|
||||
UpdateStationInteractions();
|
||||
UpdateAnnouncement();
|
||||
UpdateVoyageMap();
|
||||
}
|
||||
|
||||
private void UpdatePortApproach()
|
||||
{
|
||||
if (passageAudio.ApproachSent || passageHelm.Arrived)
|
||||
return;
|
||||
|
||||
float usualApproach = Mathf.Clamp(PassageDuration(underway) * .17f, 18f, 44f);
|
||||
float speakingTime = (passageAudio.ApproachSeconds + 1.2f) * passageSpeed * livePassage.SpeedFactor;
|
||||
if (passageHelm.RemainingSeconds <= Mathf.Max(usualApproach, speakingTime))
|
||||
passageAudio.AnnounceApproach();
|
||||
}
|
||||
|
||||
private void TurnPassageCamera(float delta) =>
|
||||
@@ -199,6 +216,7 @@ namespace Soundings
|
||||
passageSpeed = 1;
|
||||
passageDeck = passageServiceArea = -1;
|
||||
passageBridge = passageExploring = false;
|
||||
voyageMapOpen = false;
|
||||
stationFeedbackText = null;
|
||||
passageBusinessOpen = true;
|
||||
SetPassageFreeLook(false);
|
||||
@@ -208,7 +226,7 @@ namespace Soundings
|
||||
harbor.BeginPassage(quote.Weather, PassageDuration(quote));
|
||||
harbor.ShowDeck(passageDeck);
|
||||
harbor.UpdatePassengers(livePassage, 0);
|
||||
passageAudio.Begin();
|
||||
passageAudio.Begin(quote.Destination);
|
||||
Render();
|
||||
}
|
||||
|
||||
@@ -289,6 +307,7 @@ namespace Soundings
|
||||
livePassage = null;
|
||||
passageHelm = null;
|
||||
passageServiceArea = -1;
|
||||
voyageMapOpen = false;
|
||||
passageAudio.End();
|
||||
serviceReadout = null;
|
||||
SetPassageFreeLook(false);
|
||||
@@ -303,7 +322,12 @@ namespace Soundings
|
||||
page = 4;
|
||||
ReviewGuideVoyage();
|
||||
}
|
||||
Apply(failure, $"Arrived in {Market.Ports[voyage.Destination].Name}.");
|
||||
string arrival = $"Arrived in {Market.Ports[voyage.Destination].Name}.";
|
||||
if (failure == null && voyage.ItineraryLeg > 0)
|
||||
arrival += Ship.Itinerary is { HasNext: true } itinerary
|
||||
? $" Next call is {Market.Ports[itinerary.NextPort].Name}."
|
||||
: " Itinerary complete.";
|
||||
Apply(failure, arrival);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user