Rebuild Soundings around harbor gameplay and guided careers

This commit is contained in:
josh
2026-11-27 21:11:51 -05:00
parent 75afa1c194
commit 4b870fb0ce
30 changed files with 3523 additions and 819 deletions

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
@@ -7,113 +6,60 @@ namespace Soundings
{
public sealed partial class SoundingsApp
{
private void DrawOperations(VisualElement pageRoot)
private void DrawVoyageFolio(VisualElement folio, Ship ship, Voyage quote)
{
if (Ship == null)
{
var empty = Card(pageRoot, "No vessel in service");
AddText(empty, "Buy a pre-owned vessel or commission a hull from the shipyard.", "body-copy");
empty.Add(Action("Open shipyard →", () => ChangePage(2), "primary"));
return;
}
PortSpec origin = Market.Ports[quote.Origin];
AddText(folio, $"DEPARTURE FROM {origin.Name.ToUpperInvariant()}", "chart-paper-kicker chart-paper-section");
var passage = Add(folio, "chart-passage");
AddText(passage, $"{quote.Miles:N0} nm · {quote.Days} days", "chart-passage-distance");
AddText(passage, $"{quote.Guests} / {quote.Capacity} guests", "chart-passage-guests");
Ship ship = Ship;
Voyage quote = company.Forecast(ship, destination);
PortSpec port = Market.Ports[ship.Port];
var upper = Add(pageRoot, "columns");
var hero = Add(upper, "wide hero");
AddHarbor(hero);
var portTag = Add(hero, "hero-port");
AddText(portTag, $"● BERTHED IN {port.Name.ToUpperInvariant()}", "tag on-image");
var shipLabel = Add(hero, "hero-label");
AddDisplay(shipLabel, ship.Name, "hero-title");
AddText(shipLabel, $"{ship.Hull.Name.ToUpperInvariant()} / {ship.Decks.Count} DECKS", "eyebrow on-image");
var settlement = Add(folio, "chart-settlement");
AddText(settlement, "EST. VOYAGE PROFIT", "chart-paper-kicker");
AddDisplay(settlement, Money(quote.NetIncome), quote.NetIncome >= 0 ? "chart-projected-profit" : "chart-projected-profit chart-projected-loss");
var forecast = Card(upper, "Voyage forecast", "narrow forecast");
AddText(forecast, quote != null ? $"{port.Name} → {Market.Ports[destination].Name}" : "No itinerary selected", "forecast-route");
var paired = Add(forecast, "paired");
ForecastMetric(paired, "PROJECTED PROFIT", quote == null ? "—" : Money(quote.NetIncome),
quote == null ? "" : quote.NetIncome >= 0 ? "gain" : "loss");
ForecastMetric(paired, "EXPECTED GUESTS", quote == null ? "—" : $"{quote.Guests} / {quote.Capacity}");
AddLine(forecast, "Duration", quote == null ? "—" : $"{quote.Days} days");
AddLine(forecast, "Sailing distance", quote == null ? "—" : $"{quote.Miles:N0} nm");
AddLine(forecast, "Fuel burn + reserve", quote == null ? "—" : $"{quote.FuelBurn} + {quote.Reserve} t");
var lower = Add(pageRoot, "columns second-row");
var itinerary = Card(lower, "Itinerary & fares", "wide");
AddText(itinerary, "DESTINATION", "eyebrow control-label");
var choices = new List<string>();
var destinations = new List<int>();
foreach (Lane lane in Market.Lanes)
{
int other = lane.Other(ship.Port);
if (other < 0)
continue;
PortSpec candidate = Market.Ports[other];
string status = !company.Permits[other] ? " · Permit required" : ship.HullIndex < candidate.MinimumHull ? " · Larger hull" : "";
choices.Add($"{candidate.Name} · {lane.Miles:N0} nm{status}");
destinations.Add(other);
}
if (destinations.Count > 0)
{
int selected = destinations.IndexOf(destination);
var dropdown = new DropdownField(choices, selected) { name = "destination" };
dropdown.AddToClassList("field");
dropdown.RegisterValueChangedCallback(evt =>
{
destination = destinations[choices.IndexOf(evt.newValue)];
SetRecommendedFuel();
Notify(null);
Render();
});
itinerary.Add(dropdown);
}
var fare = Add(itinerary, "control-row");
var fareDescription = Add(fare, "control-copy");
AddText(fareDescription, "PASSENGER FARE", "eyebrow");
AddText(fareDescription, "Per guest, all sailing days", "muted");
Stepper(fare, Money(ship.Fare), "fare", () => ChangeFare(ship, -50), () => ChangeFare(ship, 50),
var fares = Add(folio, "chart-money-row");
AddText(fares, "Fare per guest", "chart-money-label");
ChartStepper(fares, Money(ship.Fare), "fare", () => ChangeFare(ship, -50), () => ChangeFare(ship, 50),
ship.Fare > Market.MinFare, ship.Fare < Market.MaxFare);
string reason = company.DepartureBlock(ship, quote);
var dispatch = Add(itinerary, "dispatch");
string readiness = reason ?? "Ready to depart. Settlement posts on arrival.";
AddText(dispatch, readiness, reason == null ? "readiness gain" : "readiness");
Button launch = Action("Dispatch voyage →", () =>
{
string failure = company.Sail(ship, destination);
if (failure == null)
{
ResetItinerary();
selectedVoyage = 0;
page = 4;
}
Apply(failure, $"Arrived in {Market.Ports[ship.Port].Name}. Voyage posted to the ledger.");
}, "primary", "dispatch");
launch.SetEnabled(reason == null);
dispatch.Add(launch);
var bunker = Card(lower, "Bunkering", "narrow bunker");
AddText(bunker, $"{port.Name} / {port.Country}", "muted");
AddLine(bunker, "Fuel aboard", $"{ship.Fuel} / {ship.Tank} t");
var meter = Add(bunker, "meter");
var fill = Add(meter, "meter-fill");
fill.style.width = Length.Percent(100f * ship.Fuel / ship.Tank);
AddLine(bunker, "Indicative safe range", $"{ship.SafeRange:N0} nm");
AddLine(bunker, "Local bunker price", $"{Money(Market.FuelPrice(ship.Port, company.Day))} / t");
var fuelControls = Add(bunker, "control-row fuel-controls");
Stepper(fuelControls, $"{bunkerTons} t", "tons", () => ChangeQuantity(ship, -10), () => ChangeQuantity(ship, 10),
DrawChartBunkering(folio, ship, quote);
string blocker = company.DepartureBlock(ship, quote);
if (!string.IsNullOrEmpty(blocker))
AddText(folio, blocker, "chart-paper-note chart-departure-blocker");
else
AddText(folio, "Cleared for departure", "chart-cleared");
Button launch = Action("Cast off →", () => BeginVoyage(quote), "chart-ink-button chart-wide-button chart-cast-off", "dispatch");
launch.SetEnabled(blocker == null);
folio.Add(launch);
}
private void DrawChartBunkering(VisualElement folio, Ship ship, Voyage quote = null)
{
PortSpec dock = Market.Ports[ship.Port];
AddText(folio, "FUEL AT BERTH", "chart-paper-kicker chart-paper-section");
ChartLine(folio, "Aboard / capacity", $"{ship.Fuel} / {ship.Tank} t");
var tank = Add(folio, "chart-tank");
Add(tank, "chart-tank-fill").style.width = Length.Percent(100f * ship.Fuel / ship.Tank);
if (quote != null)
ChartLine(folio, "Burn + reserve", $"{quote.FuelBurn} + {quote.Reserve} t");
else
ChartLine(folio, "Indicative safe range", $"{ship.SafeRange:N0} nm");
ChartLine(folio, $"Price in {dock.Name}", $"{Money(Market.FuelPrice(ship.Port, company.Day))} / t");
var buying = Add(folio, "chart-buying");
ChartStepper(buying, $"{bunkerTons} t", "tons", () => ChangeQuantity(ship, -10), () => ChangeQuantity(ship, 10),
bunkerTons > 0, bunkerTons < ship.Tank - ship.Fuel);
Button purchase = Action($"Buy · {Money(company.BunkerCost(ship, bunkerTons))}", () =>
Button buy = Action($"Buy {Money(company.BunkerCost(ship, bunkerTons))}", () =>
{
int quantity = bunkerTons;
string failure = company.Refuel(ship, quantity);
int ordered = bunkerTons;
string failure = company.Refuel(ship, ordered);
if (failure == null)
SetRecommendedFuel();
Apply(failure, $"Loaded {quantity} t of fuel in {port.Name}.");
}, "", "buy-fuel");
purchase.SetEnabled(bunkerTons > 0 && company.Cash >= company.BunkerCost(ship, bunkerTons));
fuelControls.Add(purchase);
Apply(failure, $"Loaded {ordered} t of fuel in {dock.Name}.");
}, "chart-ink-button chart-buy-fuel", "buy-fuel");
buy.SetEnabled(bunkerTons > 0 && company.Cash >= company.BunkerCost(ship, bunkerTons));
buying.Add(buy);
}
private void ChangeFare(Ship ship, int amount)
@@ -129,39 +75,26 @@ namespace Soundings
Render();
}
private static void Stepper(VisualElement parent, string value, string id, Action minus, Action plus, bool canMinus, bool canPlus)
private static void ChartStepper(VisualElement parent, string value, string id, Action minus, Action plus, bool canMinus, bool canPlus)
{
var stepper = Add(parent, "stepper");
Button down = Action("-", minus, "step", id + "-minus");
var stepper = Add(parent, "chart-stepper");
Button down = Action("-", minus, "chart-step", id + "-minus");
down.tooltip = id == "fare" ? "Lower passenger fare by $50" : "Buy 10 fewer tons";
down.SetEnabled(canMinus);
stepper.Add(down);
AddText(stepper, value, "step-value");
Button up = Action("+", plus, "step", id + "-plus");
AddText(stepper, value, "chart-step-value");
Button up = Action("+", plus, "chart-step", id + "-plus");
up.tooltip = id == "fare" ? "Raise passenger fare by $50" : "Buy 10 more tons";
up.SetEnabled(canPlus);
stepper.Add(up);
}
private static VisualElement Card(VisualElement parent, string titleText, string classes = "")
private static void ChartLine(VisualElement parent, string description, string value)
{
var card = Add(parent, "card " + classes);
AddText(card, titleText, "card-title");
return card;
var line = Add(parent, "chart-paper-line");
AddText(line, description, "chart-paper-caption");
AddText(line, value, "chart-paper-value");
}
private static void ForecastMetric(VisualElement parent, string caption, string value, string modifier = "")
{
var field = Add(parent, "forecast-metric");
AddText(field, caption, "eyebrow");
AddText(field, value, "forecast-value " + modifier);
}
private static void AddLine(VisualElement parent, string description, string value, string modifier = "")
{
var measure = Add(parent, "measure");
AddText(measure, description, "measure-label");
AddText(measure, value, "measure-value " + modifier);
}
}
}