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

@@ -0,0 +1,199 @@
using UnityEngine;
using UnityEngine.UIElements;
namespace Soundings
{
public sealed partial class SoundingsApp
{
private enum GuideStep
{
Off, GetShip, Cabins, Dining, SetCourse, Bunker, Fare, CastOff, Review
}
private const int StarterCabinModules = 4;
private static int StarterBerths => StarterCabinModules * Market.Facilities[(int)Facility.Cabin].Capacity;
private GuideStep guideContext;
private Ship guideFareShip;
private int guideInitialFare;
private void StartGuide(bool financed)
{
guideFareShip = null;
company.TutorialStep = (int)(financed ? GuideStep.GetShip : GuideStep.SetCourse);
}
private void RestartGuide()
{
StartGuide(Ship == null);
paused = false;
Notify(null);
Save();
Render();
}
private void ReviewGuideVoyage()
{
if (company.TutorialStep > 0 && company.Voyages > 0)
company.TutorialStep = (int)GuideStep.Review;
}
private void RefreshGuide()
{
guideContext = GuideStep.Off;
if (title || company == null || company.TutorialStep == 0 || underway != null)
return;
Ship ship = Ship;
if (guideFareShip != ship)
{
guideFareShip = ship;
guideInitialFare = ship?.Fare ?? 0;
}
var reached = (GuideStep)company.TutorialStep;
guideContext = FindGuideContext(ship, reached);
if ((int)guideContext <= company.TutorialStep)
return;
company.TutorialStep = (int)guideContext;
Save();
}
private GuideStep FindGuideContext(Ship ship, GuideStep reached)
{
if (reached == GuideStep.Review)
return GuideStep.Review;
if (ship == null)
return GuideStep.GetShip;
if (ship.Beds < StarterBerths)
return GuideStep.Cabins;
if (ship.Meals < StarterBerths)
return GuideStep.Dining;
Voyage quote = page == 3 ? company.Forecast(ship, inspectedPort) : null;
if (quote == null || !company.Permits[quote.Destination] || ship.HullIndex < Market.Ports[quote.Destination].MinimumHull)
return GuideStep.SetCourse;
if (ship.Fuel < quote.RequiredFuel)
return GuideStep.Bunker;
if (reached == GuideStep.CastOff || ship.Fare != guideInitialFare || company.DepartureBlock(ship, quote) != null)
return GuideStep.CastOff;
return GuideStep.Fare;
}
private void DrawGuide(VisualElement shell)
{
if (guideContext == GuideStep.Off)
return;
(string heading, string note, string target) = GuideMessage();
var guide = Add(shell, "voyage-guide");
guide.pickingMode = PickingMode.Ignore;
GameIcon(guide, "compass");
var instructions = Add(guide, "voyage-guide-copy");
instructions.pickingMode = PickingMode.Ignore;
AddText(instructions, heading, "voyage-guide-heading");
AddText(instructions, note, "voyage-guide-note");
bool reviewing = guideContext == GuideStep.Review && page == 4 && !ledgerAccounts;
guide.Add(Action(reviewing ? "Finish" : "Skip", () =>
{
company.TutorialStep = (int)GuideStep.Off;
Save();
Render();
}, "voyage-guide-close", reviewing ? "guide-finish" : "guide-skip"));
if (!string.IsNullOrEmpty(target))
{
var control = shell.Q<VisualElement>(target);
if (control != null && control.enabledInHierarchy)
control.AddToClassList("guide-target");
}
}
private (string Heading, string Note, string Target) GuideMessage()
{
switch (guideContext)
{
case GuideStep.GetShip:
if (page != 2)
return ("Register your first ship", "Open Shipyard to buy or commission a hull.", "nav-2");
return ("Register your first ship", "Choose a hull you can afford and sign the commission or purchase.", "buy-ship");
case GuideStep.Cabins:
return GuideFacility(Facility.Cabin, $"Outfit passenger cabins · {Ship.Beds}/{StarterBerths} berths");
case GuideStep.Dining:
return GuideFacility(Facility.Dining, $"Fit dining for {StarterBerths} guests");
case GuideStep.Bunker:
Voyage crossing = company.Forecast(Ship, inspectedPort);
if (crossing.RequiredFuel > Ship.Tank)
return ("Extend your range", "Fit a bunker tank in Deck Plans or select a shorter sailing.", "nav-1");
return ("Take on fuel", "In the route sheet, buy enough fuel to cover the burn and reserve.", "buy-fuel");
case GuideStep.Fare:
return ("Set the fare", "Try + or − to see the forecast change, or cast off at the current fare.", "fare-plus");
case GuideStep.CastOff:
Voyage departure = company.Forecast(Ship, inspectedPort);
if (Ship.Condition < 25)
return ("Clear departure", "Visit Shipyard to overhaul the ship before departing.", "nav-2");
if (departure.Guests == 0)
return ("Attract passengers", "Lower the fare until guests are expected to book.", "fare-minus");
string blocker = company.DepartureBlock(Ship, departure);
if (blocker != null)
return ("Clear departure", blocker, null);
return ("Clear departure", "Choose Cast off. Watch the crossing or skip to arrival.", "dispatch");
case GuideStep.Review:
if (page != 4)
return ("Read the arrival statement", "Open the Logbook to see your voyage profit and cash change.", "nav-4");
if (ledgerAccounts)
return ("Read the arrival statement", "Switch to Voyage records to review your latest crossing.", "log-voyages");
return ("Check the passage", "Compare net profit and cash change. You can refit the ship in Deck Plans.", "voyage-0");
default:
return GuideCourse();
}
}
private (string Heading, string Note, string Target) GuideFacility(Facility facility, string heading)
{
if (page != 1)
return (heading, "Open Deck Plans to lay out your ship.", "nav-1");
string facilityName = Market.Facilities[(int)facility].Name;
if (tool != facility)
return (heading, $"Select {facilityName} in the facility tray.", $"facility-{(int)facility}");
int floor = Mathf.Clamp(deckIndex, 0, Ship.Decks.Count - 1);
Facility[] cells = Ship.Decks[floor].Cells;
for (int i = 0; i < cells.Length; i++)
if (cells[i] == Facility.Empty)
return (heading, "Select any empty berth to place it.", $"berth-{i}");
return (heading, "Choose another deck or clear a berth to make room.", null);
}
private (string Heading, string Note, string Target) GuideCourse()
{
const string heading = "Plot the first passage";
if (page == 0)
return (heading, "Choose Set course to see the route from your current berth.", "plan-voyage");
if (page != 3)
return (heading, "Open Chart to select a route and review the departure forecast.", "nav-3");
foreach (Lane lane in Market.Lanes)
{
int next = lane.Other(Ship.Port);
if (next < 0 || !company.Permits[next] || Ship.HullIndex < Market.Ports[next].MinimumHull)
continue;
string port = Market.Ports[next].Name;
if (!worldChart && next >= Market.StarterPortCount)
return (heading, $"Switch to World and select {port} to review that sailing.", "chart-world");
return (heading, $"Select {port}, an open port linked to your current berth.", $"port-{next}");
}
return (heading, "Choose a linked port and acquire a permit before departing.", "chart-directory");
}
}
}