Files
cruiseSimulator/Assets/BigShipTycoon/Runtime/FirstVoyageGuide.cs
josh 290e4cb45d Add riverboat captain career and distinct ship classes
Add class-specific vessel geometry and sea motion, a guided helm qualification path, dockside sailing orders, and local excursions at all 24 ports.
2026-11-29 20:41:00 -05:00

223 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.UIElements;
namespace BigShipTycoon
{
public sealed partial class TycoonApp
{
private enum GuideStep
{
Off, GetShip, Cabins, Dining, SetCourse, Bunker, Fare, CastOff, Review, AtSea
}
private const int StarterCabinModules = 4;
private static int StarterBerths => StarterCabinModules * Market.Facilities[(int)Facility.Cabin].Capacity;
private static int GuideBerths(Ship ship) => ship.HullIndex == Market.River ? Market.Facilities[(int)Facility.Cabin].Capacity : StarterBerths;
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)
return;
if (underway != null)
{
guideContext = GuideStep.AtSea;
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 < GuideBerths(ship))
return GuideStep.Cabins;
if (ship.Meals < GuideBerths(ship))
return GuideStep.Dining;
Voyage quote = page == 3 ? company.Forecast(ship, inspectedPort) : null;
if (quote == null || !company.Permits[quote.Destination] || !Market.CanVisit(ship.HullIndex, quote.Destination))
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}/{GuideBerths(Ship)} berths");
case GuideStep.Dining:
return GuideFacility(Facility.Dining, $"Fit dining for {GuideBerths(Ship)} 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 company.IsCaptainCareer
? ("Clear departure", "Choose Cast off, then open the bridge to try your first helm check.", "dispatch")
: ("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", "Check the voyage profit and guest survey. You can refit the ship in Deck Plans.", "voyage-0");
case GuideStep.AtSea:
if (passageServiceArea >= 0)
return ("Work the service deck", "Walk up to the equipment and press F when the station prompt appears. You can switch operating modes here.", "service-assist");
if (company.IsCaptainCareer && !passageHelm.Practice.Qualified && !passageExploring)
return passageBridge
? ("Practise at the helm", "Use the heading and rudder readouts to complete the bridge check.", passageHelm.Manual ? null : "helm-toggle")
: ("Start your helm check", "Open the bridge and take the helm to log a qualification for this class.", "passage-bridge");
if (passageBridge)
return ("Navigate from the bridge", "Face the wheel and press F to take the helm. Return to autopilot to walk around again.", "helm-toggle");
if (passageExploring)
return ("Make your rounds", "Walk with WASD. Face a counter, room, or station and press F to help the crew.", null);
return ("Make the crossing count", "Set onboard prices, offer specials, and watch for events. Choose Bridge or a deck view to look around.", "passage-business");
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");
if (deckTools != DeckTools.GuestFacilities)
return (heading, "Open Guest facilities to fit cabins and dining.", "facility-guests");
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] || !Market.CanVisit(Ship.HullIndex, next))
continue;
string port = Market.Ports[next].Name;
if (!RiverChart && !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");
}
}
}