Files
cruiseSimulator/Assets/BigShipTycoon/Runtime/ConstructionPages.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

991 lines
48 KiB
C#
Raw Permalink 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 System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace BigShipTycoon
{
public sealed partial class TycoonApp
{
private static readonly (int HullIndex, bool Used)[] Offers =
{ (Market.Coastal, true), (Market.Coastal, false), (Market.Regional, true), (Market.Regional, false),
(Market.Ocean, false), (Market.Mega, false), (Market.River, true), (Market.River, false) };
private enum DeckTools { GuestFacilities, LargerVenues, LeisureAndRetail, ShipSystems, Gaming, MegaVenues, MegaSystems }
private DeckTools deckTools;
private int toolRotation;
private Action refreshDeckPlacement;
private static readonly Facility[] GuestTools = { Facility.Cabin, Facility.Dining, Facility.Entertainment,
Facility.Tank, Facility.Bar, Facility.Amenity, Facility.Empty };
private static readonly Facility[] ExpandedTools = { Facility.Suite, Facility.GrandSuite, Facility.Restaurant,
Facility.GrandTheater, Facility.ResortPool, Facility.CocktailLounge, Facility.Empty };
private static readonly Facility[] LeisureTools = { Facility.Shop, Facility.ShoppingArcade, Facility.Spa, Facility.WaterPark, Facility.Empty };
private static readonly Facility[] CasinoTools = { Facility.CasinoLounge, Facility.Casino, Facility.GrandCasino, Facility.Empty };
private static readonly Facility[] SystemsTools = { Facility.Galley, Facility.Stores, Facility.Water,
Facility.Waste, Facility.Workshop, Facility.Empty };
private static readonly Facility[] MegaVenueTools = { Facility.SkyResidence, Facility.MarketHall, Facility.OceanArena,
Facility.PanoramaClub, Facility.ThermalSpa, Facility.Galleria, Facility.RoyalCasino, Facility.Empty };
private static readonly Facility[] MegaSystemTools = { Facility.ProductionGalley, Facility.ColdChain, Facility.MembranePlant,
Facility.ReclamationPlant, Facility.EngineeringCenter, Facility.BunkerFarm, Facility.LaundryPlant, Facility.Empty };
private static readonly Color DraftGrid = new Color(.37f, .62f, .65f, .19f);
private static readonly Color DraftFine = new Color(.47f, .75f, .74f, .42f);
private static readonly Color DraftInk = new Color(.64f, .89f, .82f, .88f);
private static readonly Color DraftGold = new Color(.91f, .70f, .42f, .88f);
private void DrawDecks(VisualElement workspace)
{
var work = Add(workspace, "ship-work deck-work");
Ship ship = Ship;
if (ship == null)
{
var empty = Add(work, "ship-work-empty");
AddDisplay(empty, "No vessel in dock", "ship-work-heading");
AddText(empty, "Acquire a hull at the shipyard before fitting a deck.", "ship-work-detail");
empty.Add(Action("Visit shipyard", () => ChangePage(2), "work-primary", "open-shipyard"));
return;
}
bool mega = ship.HasAftTerrace;
work.EnableInClassList("work-mega", mega);
deckIndex = Mathf.Clamp(deckIndex, 0, ship.Decks.Count - 1);
var titleBar = Add(work, "ship-work-head");
var heading = Add(titleBar, "ship-work-name");
AddText(heading, "DECK PLANS", "work-caption");
AddDisplay(heading, ship.Name, "ship-work-heading");
string deckTitle = sunDeckEditing ? "Open-air sun deck" : $"Deck {deckIndex + 1} of {ship.Decks.Count}";
AddText(heading, $"{ship.Hull.Name} hull · {deckTitle}", "ship-work-detail");
var deckControls = Add(titleBar, "work-deck-controls");
var selector = Add(deckControls, "work-deck-selector");
VisualElement band = mega ? Add(selector, "work-deck-band") : selector;
Button sunDeck = Action("Sun deck", () =>
{
sunDeckEditing = true;
Notify(null);
Render();
}, "work-deck-tab", "sun-deck-open");
if (ship.HullIndex == Market.River)
{
sunDeck.SetEnabled(false);
sunDeck.tooltip = "The riverboat has a fixed roof.";
}
sunDeck.EnableInClassList("work-selected", sunDeckEditing);
band.Add(sunDeck);
for (int i = ship.Decks.Count - 1; i >= 0; i--)
{
if (mega && ship.Decks.Count - i == 8)
band = Add(selector, "work-deck-band work-deck-band-lower");
int floor = i;
Button level = Action($"Deck {i + 1}", () =>
{
deckIndex = floor;
sunDeckEditing = false;
Notify(null);
Render();
}, "work-deck-tab", $"deck-{i}");
level.EnableInClassList("work-selected", !sunDeckEditing && deckIndex == i);
band.Add(level);
}
int deckPrice = company.DeckPrice(ship);
string addLabel = ship.Decks.Count == ship.Hull.MaxDecks ? "Deck limit reached" : $"+ Deck {Money(deckPrice)}";
Button add = Action(addLabel, () =>
{
string failure = company.AddDeck(ship);
if (failure == null)
{
deckIndex = ship.Decks.Count - 1;
sunDeckEditing = false;
}
Apply(failure, "New deck ready to fit out.");
}, "work-deck-add", "add-deck");
add.SetEnabled(ship.Decks.Count < ship.Hull.MaxDecks && company.AvailableCash >= deckPrice);
deckControls.Add(add);
if (sunDeckEditing)
{
refreshDeckPlacement = null;
DrawSunDeckEditor(work, ship);
return;
}
var board = Add(work, "work-draft");
board.generateVisualContent += context => DrawDeckOutline(context, ship.Hull.Columns);
var markings = Add(board, "work-draft-markings");
markings.pickingMode = PickingMode.Ignore;
AddText(markings, "STERN", "work-caption");
AddText(markings, "TOP VIEW", "work-caption");
AddText(markings, "BOW →", "work-caption");
var layout = Add(board, "work-berth-grid");
var placement = Add(board, "work-placement");
var placementLabel = AddText(placement, PlacementInstruction(ship, tool, toolRotation), "work-placement-text");
placementLabel.name = "berth-placement";
refreshDeckPlacement = DrawBerthGrid(layout, placementLabel, ship);
var fittings = Add(work, "work-fittings");
var gauges = Add(fittings, "work-capacity-strip");
if (deckTools is DeckTools.ShipSystems or DeckTools.MegaSystems)
{
AddText(gauges, $"{ship.GalleyCapacity:N0} galley covers", "work-capacity");
AddText(gauges, $"{ship.FoodCapacity:N0} stored portions", "work-capacity");
AddText(gauges, $"{ship.WaterCapacity:N0} L freshwater", "work-capacity");
AddText(gauges, $"{ship.WasteCapacity:N0} L sewage buffer", "work-capacity");
if (deckTools == DeckTools.MegaSystems)
{
AddText(gauges, $"{ship.Tank:N0} t bunker capacity", "work-capacity");
AddText(gauges, $"{ship.FittedLaundryCapacity:N0} added laundry loads/day", "work-capacity");
}
}
else
{
string rooms = ship.SuiteBerths == 0 ? $"{ship.Beds:N0} berths" : $"{ship.Beds:N0} berths · {ship.SuiteBerths:N0} in suites";
AddText(gauges, rooms, "work-capacity");
AddText(gauges, $"{ship.Meals:N0} meal covers", "work-capacity");
AddText(gauges, $"{ship.Entertainment:N0} show seats", "work-capacity");
if (deckTools == DeckTools.LargerVenues || deckTools == DeckTools.LeisureAndRetail)
{
AddText(gauges, $"{ship.PoolCapacity:N0} amenity admissions", "work-capacity");
if (deckTools == DeckTools.LeisureAndRetail)
AddText(gauges, $"{ship.RetailCapacity:N0} retail orders", "work-capacity");
else
AddText(gauges, $"{ship.BarCapacity:N0} drink orders", "work-capacity");
}
else if (deckTools is DeckTools.Gaming or DeckTools.MegaVenues)
AddText(gauges, $"{ship.CasinoCapacity:N0} gaming seats", "work-capacity");
else
AddText(gauges, $"{ship.Tank:N0} t bunker capacity", "work-capacity");
AddText(gauges, $"{ship.Capacity:N0} guests per sailing", "work-capacity work-capacity-emphasis");
}
var toolMode = Add(fittings, "work-fit-modes");
AddBuildToolTab(toolMode, "Guest facilities", "facility-guests", DeckTools.GuestFacilities, Facility.Cabin);
AddBuildToolTab(toolMode, "Larger venues", "facility-larger", DeckTools.LargerVenues, Facility.Suite);
AddBuildToolTab(toolMode, "Leisure & retail", "facility-leisure", DeckTools.LeisureAndRetail, Facility.Shop);
AddBuildToolTab(toolMode, "Casinos", "facility-casino", DeckTools.Gaming, Facility.CasinoLounge);
AddBuildToolTab(toolMode, "Ship systems", "facility-systems", DeckTools.ShipSystems, Facility.Galley);
AddBuildToolTab(toolMode, "MEGA venues", "facility-mega-venues", DeckTools.MegaVenues, Facility.SkyResidence);
AddBuildToolTab(toolMode, "MEGA systems", "facility-mega-systems", DeckTools.MegaSystems, Facility.ProductionGalley);
FacilitySpec selectedSpec = Market.Facilities[(int)tool];
if (selectedSpec.BayCount > 1)
{
Button rotate = Action("Rotate R", RotateDeckTool, "work-tool-rotate", "facility-rotate");
rotate.tooltip = "Turn the selected fitting clockwise by 90°";
toolMode.Add(rotate);
AddText(toolMode, RotationLabel(selectedSpec), "work-tool-orientation").name = "facility-orientation";
}
var tools = Add(fittings, "work-tool-tray");
Facility[] options = deckTools switch
{
DeckTools.LargerVenues => ExpandedTools,
DeckTools.LeisureAndRetail => LeisureTools,
DeckTools.Gaming => CasinoTools,
DeckTools.ShipSystems => SystemsTools,
DeckTools.MegaVenues => MegaVenueTools,
DeckTools.MegaSystems => MegaSystemTools,
_ => GuestTools
};
foreach (Facility option in options)
{
FacilitySpec spec = Market.Facilities[(int)option];
bool locked = !Market.MeetsHullRequirement(ship.HullIndex, spec.MinimumHull);
Button button = Action("", () =>
{
if (tool != option)
toolRotation = 0;
tool = option;
Notify(null);
Render();
}, "work-tool work-tool-" + (int)option, "facility-" + (int)option);
button.EnableInClassList("work-selected", option == tool);
button.EnableInClassList("work-tool-locked", locked);
button.tooltip = locked ? VenueRequirement(spec) : spec.Details;
AddFacilityMark(button, option);
var copy = Add(button, "work-tool-copy");
copy.pickingMode = PickingMode.Ignore;
AddText(copy, spec.Name, "work-tool-name");
string price = option == Facility.Empty ? "25% refund" : Money(spec.Price);
if (spec.BayCount > 1)
{
price = $"{FootprintLabel(spec, 0)} · {price}";
button.AddToClassList("work-tool-larger");
}
AddText(copy, price, "work-tool-cost");
if (locked)
AddText(copy, $"{Market.Hulls[spec.MinimumHull].Name} hull required", "work-tool-lock");
tools.Add(button);
}
}
private Action DrawBerthGrid(VisualElement layout, Label instruction, Ship ship)
{
Deck deck = ship.Decks[deckIndex];
int columns = ship.Hull.Columns;
var berths = new Button[deck.Cells.Length];
var strips = new VisualElement[ship.Hull.Rows];
int hovered = -1, focused = -1;
void UpdatePreview()
{
int selected = hovered >= 0 ? hovered : focused;
for (int i = 0; i < berths.Length; i++)
{
berths[i].RemoveFromClassList("work-berth-preview");
berths[i].RemoveFromClassList("work-berth-blocked");
}
if (selected < 0)
{
instruction.text = PlacementInstruction(ship, tool, toolRotation);
return;
}
Facility room = deck.FacilityAt(selected, columns);
int anchor = room == Facility.Empty ? selected : deck.AnchorAt(selected, columns);
bool planning = room == Facility.Empty || room == tool;
FacilitySpec spec = Market.Facilities[(int)(planning ? tool : room)];
int rotation = planning ? toolRotation : deck.RotationAt(anchor);
string blocked = PlacementBlock(ship, selected);
instruction.text = BerthDescription(deck, columns, selected, room, tool, toolRotation, blocked);
foreach (Vector2Int offset in spec.Footprint(rotation))
if (deck.TryCellAt(anchor, columns, offset, out int bay))
berths[bay].AddToClassList(blocked == null ? "work-berth-preview" : "work-berth-blocked");
}
for (int row = 0; row < ship.Hull.Rows; row++)
{
var strip = Add(layout, "work-berth-row");
strips[row] = strip;
for (int column = 0; column < columns; column++)
{
int cell = row * columns + column;
int anchor = deck.AnchorAt(cell, columns);
Facility existing = deck.FacilityAt(cell, columns);
FacilitySpec room = Market.Facilities[(int)existing];
var slot = Add(strip, "work-berth-slot");
Button berth = Action("", () => BuildAtBerth(ship, deck, cell), "work-berth work-room-" + (int)Market.BaseFacility(existing), "berth-" + cell);
berths[cell] = berth;
slot.Add(berth);
berth.RegisterCallback<PointerEnterEvent>(_ => { hovered = cell; UpdatePreview(); });
berth.RegisterCallback<PointerLeaveEvent>(_ => { hovered = -1; UpdatePreview(); });
berth.RegisterCallback<FocusInEvent>(_ => { focused = cell; UpdatePreview(); });
berth.RegisterCallback<FocusOutEvent>(_ => { focused = -1; UpdatePreview(); });
AddText(berth, BerthName(cell, columns), "work-berth-index");
if (existing == Facility.Empty)
AddText(berth, "+", "work-berth-open");
else if (room.BayCount == 1)
AddVenueLabel(berth, existing);
else
{
berth.EnableInClassList("work-berth-join-left", column > 0 && SameVenue(cell - 1));
berth.EnableInClassList("work-berth-join-right", column + 1 < columns && SameVenue(cell + 1));
berth.EnableInClassList("work-berth-join-top", row > 0 && SameVenue(cell - columns));
berth.EnableInClassList("work-berth-join-bottom", row + 1 < ship.Hull.Rows && SameVenue(cell + columns));
}
bool SameVenue(int other) => deck.AnchorAt(other, columns) == anchor;
}
}
for (int anchor = 0; anchor < deck.Cells.Length; anchor++)
{
Facility room = deck.Cells[anchor];
FacilitySpec spec = Market.Facilities[(int)room];
if (spec.BayCount <= 1)
continue;
var (row, start, span) = CaptionRow(spec.Footprint(deck.RotationAt(anchor)));
var label = Add(strips[anchor / columns + row], "work-span-caption");
label.pickingMode = PickingMode.Ignore;
label.style.left = Length.Percent(100f * (anchor % columns + start) / columns);
label.style.width = Length.Percent(100f * span / columns);
AddVenueLabel(label, room);
}
Refresh();
return Refresh;
void Refresh()
{
for (int cell = 0; cell < berths.Length; cell++)
{
Facility room = deck.FacilityAt(cell, columns);
berths[cell].tooltip = BerthDescription(deck, columns, cell, room, tool, toolRotation,
PlacementBlock(ship, cell));
}
UpdatePreview();
}
}
private static (int Row, int First, int Span) CaptionRow(IReadOnlyList<Vector2Int> footprint)
{
(int row, int start, int span) = (0, 0, 1);
for (int first = 0; first < footprint.Count;)
{
int end = first + 1;
while (end < footprint.Count && footprint[end].y == footprint[first].y)
end++;
if (end - first > span)
(row, start, span) = (footprint[first].y, footprint[first].x, end - first);
first = end;
}
return (row, start, span);
}
private string PlacementBlock(Ship ship, int cell)
{
FacilitySpec spec = Market.Facilities[(int)tool];
return !Market.MeetsHullRequirement(ship.HullIndex, spec.MinimumHull)
? VenueRequirement(spec) : company.BuildBlock(ship, deckIndex, cell, tool, toolRotation);
}
private void BuildAtBerth(Ship ship, Deck deck, int cell)
{
int columns = ship.Hull.Columns;
int anchor = deck.AnchorAt(cell, columns);
Facility previous = deck.FacilityAt(cell, columns);
int oldRotation = deck.RotationAt(anchor);
FacilitySpec room = Market.Facilities[(int)(tool == Facility.Empty ? previous : tool)];
int footprintRotation = tool == Facility.Empty ? oldRotation : toolRotation;
string area = BerthNames(deck, columns, previous == Facility.Empty ? cell : anchor, room.Footprint(footprintRotation));
string failure = company.Build(ship, deckIndex, cell, tool, toolRotation);
bool turned = previous == tool && previous != Facility.Empty && oldRotation != deck.RotationAt(anchor);
if (failure == null && (previous != tool || turned))
SetRecommendedFuel();
string confirmation = tool == Facility.Empty
? $"Removed {room.Name.ToLowerInvariant()} from {area}."
: $"{(turned ? "Rotated" : "Built")} {room.Name.ToLowerInvariant()} at {area}.";
Apply(failure, previous == tool && !turned ? null : confirmation);
}
private void AddBuildToolTab(VisualElement parent, string label, string id, DeckTools group, Facility initial)
{
Button tab = Action(label, () =>
{
if (deckTools == group)
return;
deckTools = group;
tool = initial;
toolRotation = 0;
Notify(null);
Render();
}, deckTools == group ? "work-selected" : "", id);
parent.Add(tab);
}
private static void AddVenueLabel(VisualElement parent, Facility facility)
{
var center = Add(parent, "work-berth-center");
center.pickingMode = PickingMode.Ignore;
AddFacilityMark(center, facility);
AddText(center, Market.Facilities[(int)facility].Name, "work-berth-name").pickingMode = PickingMode.Ignore;
}
private static string VenueRequirement(FacilitySpec spec)
{
HullSpec hull = Market.Hulls[spec.MinimumHull];
if (spec.MinimumHull == Market.Mega)
return $"Requires a {hull.Name}. Complete the flagship charter, reach {hull.Voyages} voyages and earn {hull.Reputation} reputation.";
return $"Requires a {hull.Name} hull. Unlock the hull with {hull.Voyages} completed voyages and {hull.Reputation} reputation.";
}
private string RotationLabel(FacilitySpec spec) => $"{FootprintLabel(spec, toolRotation)} · {toolRotation * 90}°";
private void RotateDeckTool()
{
if (sunDeckEditing)
{
RotateSunDeckTool();
return;
}
FacilitySpec spec = Market.Facilities[(int)tool];
if (spec.BayCount <= 1 || root.Q<Label>("facility-orientation") is not Label orientation)
return;
toolRotation = (toolRotation + 1) & 3;
orientation.text = RotationLabel(spec);
refreshDeckPlacement?.Invoke();
}
private static string PlacementInstruction(Ship ship, Facility selected, int rotation)
{
FacilitySpec spec = Market.Facilities[(int)selected];
if (selected == Facility.Empty)
return "Select any bay in a fitted room to remove it and recover 25%.";
if (!Market.MeetsHullRequirement(ship.HullIndex, spec.MinimumHull))
return VenueRequirement(spec);
string plan = spec.BayCount == 1 ? "Select an open bay" : $"Point at a bay to preview the {FootprintLabel(spec, rotation)} fitting";
return $"{plan}. {spec.Name} · {spec.Details} · {Money(spec.Price)}";
}
private static string BerthName(int cell, int columns) => $"{(char)('A' + cell / columns)}{cell % columns + 1}";
private static string FootprintLabel(FacilitySpec spec, int rotation)
{
int left = 0, right = 0, depth = 1;
foreach (Vector2Int offset in spec.Footprint(rotation))
{
left = Mathf.Min(left, offset.x);
right = Mathf.Max(right, offset.x);
depth = Mathf.Max(depth, offset.y + 1);
}
int width = right - left + 1;
return spec.BayCount == width * depth ? $"{width}×{depth} bays" : $"L-shaped · {spec.BayCount} bays";
}
private static string BerthNames(Deck deck, int columns, int anchor, IReadOnlyList<Vector2Int> footprint)
{
var names = new List<string>(footprint.Count);
foreach (Vector2Int offset in footprint)
if (deck.TryCellAt(anchor, columns, offset, out int bay))
names.Add(BerthName(bay, columns));
return string.Join(", ", names);
}
private static string BerthDescription(Deck deck, int columns, int cell, Facility room, Facility selected, int rotation, string blocked)
{
FacilitySpec existing = Market.Facilities[(int)room];
if (blocked != null)
return room == Facility.Empty ? $"{BerthName(cell, columns)} · {blocked}"
: $"{BerthName(cell, columns)} · {existing.Name} · {blocked}";
if (room == Facility.Empty)
{
FacilitySpec fitting = Market.Facilities[(int)selected];
string location = BerthNames(deck, columns, cell, fitting.Footprint(rotation));
return selected == Facility.Empty
? $"{location} is already clear."
: $"{location} · {fitting.Name} · {fitting.Details} · {Money(fitting.Price)}";
}
int anchor = deck.AnchorAt(cell, columns);
if (selected == room && rotation != deck.RotationAt(anchor))
{
string newArea = BerthNames(deck, columns, anchor, existing.Footprint(rotation));
return $"{existing.Name} · Rotate to {rotation * 90}° across {newArea}";
}
string area = BerthNames(deck, columns, anchor, existing.Footprint(deck.RotationAt(anchor)));
return selected == Facility.Empty
? $"{area} · Remove {existing.Name.ToLowerInvariant()} and recover {Money(existing.Price / 4)}"
: $"{area} · {existing.Name} · {existing.Details}";
}
private static void AddFacilityMark(VisualElement parent, Facility facility)
{
var mark = Add(parent, "work-facility-icon work-mark-" + (int)facility);
mark.pickingMode = PickingMode.Ignore;
mark.generateVisualContent += context =>
{
Painter2D pen = context.painter2D;
float scale = context.visualElement.contentRect.width / 24;
Vector2 Point(float x, float y) => new Vector2(x * scale, y * scale);
pen.strokeColor = new Color(.88f, .94f, .89f);
pen.lineWidth = 1.6f;
pen.BeginPath();
void Line(float x1, float y1, float x2, float y2)
{
pen.MoveTo(Point(x1, y1));
pen.LineTo(Point(x2, y2));
}
void Segment(params float[] xy)
{
pen.MoveTo(Point(xy[0], xy[1]));
for (int i = 2; i < xy.Length; i += 2)
pen.LineTo(Point(xy[i], xy[i + 1]));
}
switch (facility == Facility.LaundryPlant ? facility : Market.BaseFacility(facility))
{
case Facility.Cabin:
case Facility.Suite:
case Facility.GrandSuite:
Segment(3,18,3,6,5,6,5,12,20,12,20,18);
Line(4,16,20,16);
Segment(6,11,6,9,10,9,10,11);
Segment(11,11,11,8,18,8,20,10,20,12);
break;
case Facility.Dining:
case Facility.Restaurant:
Segment(9,9,11,7,15,7,17,10,17,14,15,17,11,17,9,15,9,9);
Segment(3,5,3,10,5,12,7,10,7,5);
Line(5,11,5,19);
Segment(21,5,19,8,19,12,21,12,21,19);
break;
case Facility.Entertainment:
case Facility.GrandTheater:
Segment(3,19,3,5,21,5,21,19);
Segment(4,7,9,7,7,13,4,16);
Segment(20,7,15,7,17,13,20,16);
Line(9,19,15,19);
break;
case Facility.Tank:
Segment(6,20,6,9,8,7,16,7,18,9,18,20,6,20);
Segment(10,7,10,4,14,4,14,7);
Line(6,11,18,11);
Line(6,16,18,16);
break;
case Facility.Bar:
case Facility.CocktailLounge:
Segment(4,5,20,5,12,13,4,5);
Segment(12,13,12,20,7,20);
Line(12,20,17,20);
Line(8,8,16,8);
break;
case Facility.Amenity:
case Facility.ResortPool:
case Facility.WaterPark:
Segment(4,11,6,7,10,5,14,5,18,7,20,11,4,11);
Line(12,11,12,17);
Segment(3,19,6,17,9,19,12,17,15,19,18,17,21,19);
break;
case Facility.Spa:
Segment(4,13,20,13,18,18,6,18,4,13);
Segment(8,10,7,8,9,5,8,3);
Segment(12,10,11,8,13,5,12,3);
Segment(16,10,15,8,17,5,16,3);
break;
case Facility.Shop:
case Facility.ShoppingArcade:
Segment(5,8,19,8,21,20,3,20,5,8);
Segment(9,9,9,6,10,4,14,4,15,6,15,9);
Line(8,15,16,15);
break;
case Facility.Casino:
case Facility.CasinoLounge:
case Facility.GrandCasino:
Segment(5,10,11,4,20,13,14,19,5,10);
Segment(4,12,12,21,15,20);
Segment(11,10,13,8,15,11,13,14,11,10);
break;
case Facility.Galley:
Segment(3,13,17,13,15,18,5,18,3,13);
Line(17,13,22,11);
Line(8,10,8,6);
Line(12,10,12,5);
break;
case Facility.Stores:
Segment(4,5,20,5,20,19,4,19,4,5);
Line(4,11,20,11);
Line(8,8,16,8);
Line(8,15,16,15);
break;
case Facility.Water:
case Facility.Waste:
Segment(12,3,18,11,19,15,17,19,12,21,7,19,5,15,6,11,12,3);
Line(8,16,16,16);
break;
case Facility.Workshop:
Segment(6,19,15,10,14,7,18,5,20,7,19,10,16,11,8,21,6,19);
break;
case Facility.LaundryPlant:
Segment(4,4,20,4,20,21,4,21,4,4);
Line(4,8,20,8);
Segment(8,13,9,11,15,11,17,14,16,17,10,18,8,16,8,13);
break;
default:
Line(6,6,18,18);
Line(6,18,18,6);
break;
}
pen.Stroke();
};
}
private void DrawShipyard(VisualElement workspace)
{
var work = Add(workspace, "ship-work yard-work");
(int hullIndex, bool used) = Offers[yardSelection];
HullSpec hull = Market.Hulls[hullIndex];
work.EnableInClassList("yard-work-mega", hullIndex == Market.Mega);
var titleBar = Add(work, "ship-work-head");
var heading = Add(titleBar, "ship-work-name");
AddText(heading, "MIAMI SHIPYARD", "work-caption");
AddDisplay(heading, used ? $"Pre-owned {hull.Name}" : $"{hull.Name} commission", "ship-work-heading");
AddText(heading, used ? "Fitted for service · 72% condition at delivery" : hull.Description, "ship-work-detail");
var stamp = Add(titleBar, "work-yard-stamp");
AddText(stamp, "DELIVERY AT MIAMI", "work-caption");
AddText(stamp, $"{hull.Length:N0} × {hull.Beam:N0} m · {hull.StarterDecks} decks delivered · {hull.MaxDecks} max · {hull.Tank:N0} t fuel", "work-yard-specs");
var slipway = Add(work, "work-slipway");
slipway.generateVisualContent += context => DrawYardElevation(context, hullIndex, used);
var markings = Add(slipway, "work-draft-markings");
markings.pickingMode = PickingMode.Ignore;
AddText(markings, "STARBOARD ELEVATION", "work-caption");
AddText(markings, used ? "FITTED HULL" : $"BARE HULL / {hull.StarterDecks} STARTER DECKS", "work-caption");
var inventory = Add(work, "work-ship-inventory");
for (int item = 0; item < Offers.Length; item++)
{
int selection = item;
var offer = Offers[item];
if (offer.HullIndex == Market.River && !company.IsCaptainCareer)
continue;
HullSpec candidate = Market.Hulls[offer.HullIndex];
string requirement = company.ShipyardUnlock(offer.HullIndex);
Button option = Action("", () =>
{
yardSelection = selection;
Notify(null);
Render();
}, "work-offer", "yard-" + item);
option.EnableInClassList("work-selected", selection == yardSelection);
option.EnableInClassList("work-offer-mega", offer.HullIndex == Market.Mega);
option.tooltip = requirement ?? candidate.Description;
AddText(option, requirement != null ? "LOCKED" : offer.Used ? "PRE-OWNED" : "NEW HULL", "work-caption");
AddText(option, candidate.Name, "work-offer-name");
AddText(option, Money(offer.Used ? Market.UsedPrice(offer.HullIndex) : candidate.Price), "work-offer-price");
inventory.Add(option);
}
var order = Add(work, "work-order");
DrawShipyardOrder(order, hullIndex, used);
if (Ship != null)
DrawShipyardService(order, Ship);
}
private void DrawShipyardOrder(VisualElement order, int hullIndex, bool used)
{
var purchase = Add(order, "work-purchase");
if (!used)
{
var nameControl = Add(purchase, "work-name-control");
AddText(nameControl, "VESSEL NAME", "work-caption");
var field = new TextField { value = shipName, maxLength = 24, name = "vessel-name" };
field.AddToClassList("work-name-field");
field.RegisterValueChangedCallback(evt => shipName = evt.newValue);
nameControl.Add(field);
}
string block = company.ShipyardBlock(hullIndex, used);
var contract = Add(purchase, "work-contract");
long price = used ? Market.UsedPrice(hullIndex) : Market.Hulls[hullIndex].Price;
Button buy = Action(used ? $"Purchase · {Money(price)}" : $"Commission · {Money(price)}", () =>
{
string failure = company.Acquire(hullIndex, used, shipName);
if (failure == null)
{
deckIndex = 0;
ResetItinerary();
page = used ? 0 : 1;
}
Apply(failure, used ? "The vessel is ready in Miami." : "The hull is ready. Fit cabins and dining before sailing.");
}, "work-primary work-commission", "buy-ship");
buy.SetEnabled(block == null);
contract.Add(buy);
if (block != null)
AddText(contract, block, "work-contract-block");
else if (company.IsCaptainCareer)
{
var (previous, trips, checks) = Company.CommandRequirement(hullIndex);
if (previous >= 0)
AddText(contract, $"{Market.Hulls[previous].Name} command signed off · {trips} voyages · {checks} helm qualifications",
"work-yard-specs");
}
}
private void DrawShipyardService(VisualElement order, Ship ship)
{
var service = Add(order, "work-service");
var shipInfo = Add(service, "work-service-info");
AddText(shipInfo, ship.Name, "work-offer-name");
AddText(shipInfo, $"{ship.Condition}% condition", "work-yard-specs");
int price = company.ServiceCost(ship);
Button overhaul = Action(price > 0 ? $"Overhaul · {Money(price)}" : "No repairs needed", () =>
{
string failure = company.Service(ship);
if (failure == null)
SetRecommendedFuel();
Apply(failure, "The ship has been restored to 100% condition.");
}, "work-overhaul", "overhaul");
overhaul.SetEnabled(price > 0 && company.AvailableCash >= price);
service.Add(overhaul);
}
private static void DrawDeckOutline(MeshGenerationContext context, int columns)
{
Rect bounds = context.visualElement.contentRect;
if (bounds.width <= 0 || bounds.height <= 0)
return;
Painter2D pen = context.painter2D;
Vector2 P(float x, float y) => new Vector2(bounds.width * x, bounds.height * y);
DrawDraftGrid(pen, bounds, 26);
void Hull(float inset)
{
Vector2 aftPort = P(.047f + inset, .37f + inset);
Vector2 portShoulder = P(.17f + inset, .145f + inset);
Vector2 portBow = P(.75f - inset, .145f + inset);
Vector2 bow = P(.965f - inset, .50f);
Vector2 starboardBow = P(.75f - inset, .855f - inset);
Vector2 starboardShoulder = P(.17f + inset, .855f - inset);
Vector2 aftStarboard = P(.047f + inset, .63f - inset);
pen.MoveTo(aftPort);
TraceDraftCurve(pen, aftPort, P(.078f + inset, .16f + inset), portShoulder);
pen.LineTo(portBow);
TraceDraftCurve(pen, portBow, P(.91f - inset, .15f + inset), bow);
TraceDraftCurve(pen, bow, P(.91f - inset, .85f - inset), starboardBow);
pen.LineTo(starboardShoulder);
TraceDraftCurve(pen, starboardShoulder, P(.078f + inset, .84f - inset), aftStarboard);
pen.LineTo(aftPort);
}
pen.fillColor = new Color(.065f, .18f, .217f, .98f);
pen.strokeColor = DraftInk;
pen.lineWidth = 2;
pen.BeginPath();
Hull(0);
pen.Fill();
pen.Stroke();
pen.strokeColor = DraftFine;
pen.lineWidth = 1;
pen.BeginPath();
Hull(.014f);
pen.Stroke();
pen.BeginPath();
void Guide(float x, float top, float control, float bottom)
{
Vector2 start = P(x, top);
pen.MoveTo(start);
TraceDraftCurve(pen, start, P(control, .50f), P(x, bottom));
}
Guide(.104f, .23f, .145f, .77f);
Guide(.780f, .18f, .853f, .82f);
Guide(.824f, .21f, .894f, .79f);
Guide(.872f, .28f, .937f, .72f);
pen.Stroke();
pen.BeginPath();
bool expanded = columns > Market.Hulls[Market.Ocean].Columns;
float firstBay = expanded ? .12f : .135f;
float lastBay = expanded ? .83f : .785f;
for (int i = 0; i <= columns; i++)
{
float station = Mathf.Lerp(firstBay, lastBay, i / (float)columns);
pen.MoveTo(P(station, .198f));
pen.LineTo(P(station, .256f));
pen.MoveTo(P(station, .744f));
pen.LineTo(P(station, .80f));
}
for (int i = 0; i < 9; i++)
{
float y = .37f + .033f * i;
pen.MoveTo(P(.073f, y));
pen.LineTo(P(.094f, y));
}
pen.MoveTo(P(.055f, .50f));
pen.LineTo(P(.131f, .50f));
pen.MoveTo(P(.789f, .50f));
pen.LineTo(P(.948f, .50f));
pen.Stroke();
pen.strokeColor = DraftGold;
pen.BeginPath();
pen.MoveTo(P(.91f, .47f));
pen.LineTo(P(.934f, .50f));
pen.LineTo(P(.91f, .53f));
pen.Stroke();
}
private static void DrawYardElevation(MeshGenerationContext context, int hullIndex, bool used)
{
Rect bounds = context.visualElement.contentRect;
if (bounds.width <= 0 || bounds.height <= 0)
return;
Painter2D pen = context.painter2D;
DrawDraftGrid(pen, bounds, 33);
Vector2 P(float x, float y) => new Vector2(bounds.width * x, bounds.height * y);
int rank = Market.HullRank(hullIndex);
float stern = .207f - rank * .029f;
float bow = .804f + rank * .029f;
float L(float position) => Mathf.Lerp(stern, bow, position);
void Path(params float[] xy)
{
pen.MoveTo(P(L(xy[0]), xy[1]));
for (int i = 2; i < xy.Length; i += 2)
pen.LineTo(P(L(xy[i]), xy[i + 1]));
}
pen.strokeColor = DraftFine;
pen.lineWidth = 1;
pen.BeginPath();
for (int i = 0; i < 33; i++)
{
float x = .055f + i * .028f;
pen.MoveTo(P(x, .80f));
pen.LineTo(P(x, i % 4 == 0 ? .85f : .825f));
}
pen.MoveTo(P(.055f, .80f));
pen.LineTo(P(.955f, .80f));
for (int i = 1; i < 13; i++)
{
float position = i / 13f;
pen.MoveTo(P(L(position), .665f));
pen.LineTo(P(L(position - .022f), .80f));
pen.LineTo(P(L(position + .026f), .80f));
pen.ClosePath();
}
pen.Stroke();
pen.strokeColor = DraftGold;
pen.lineWidth = 1.35f;
pen.BeginPath();
Path(0,.875f, 0,.918f);
Path(0,.897f, 1,.897f);
Path(1,.875f, 1,.918f);
Path(0,.897f, .012f,.881f);
Path(0,.897f, .012f,.913f);
Path(1,.897f, .988f,.881f);
Path(1,.897f, .988f,.913f);
pen.Stroke();
pen.fillColor = hullIndex switch
{
Market.River => new Color(.17f, .30f, .31f),
Market.Coastal => new Color(.24f, .36f, .43f),
Market.Regional => new Color(.18f, .40f, .41f),
Market.Ocean => new Color(.12f, .22f, .31f),
_ => new Color(.22f, .32f, .36f)
};
pen.strokeColor = DraftInk;
pen.lineWidth = 1.8f;
pen.BeginPath();
Vector2 transom = P(stern, .56f);
Vector2 aftDeck = P(L(.21f), .565f);
Vector2 foreDeck = P(L(.79f), .565f);
Vector2 stem = P(bow, hullIndex is Market.River or Market.Coastal ? .548f : .49f);
Vector2 forwardKeel = P(L(hullIndex == Market.Ocean ? .844f : .937f), .712f);
Vector2 aftKeel = P(L(hullIndex is Market.River or Market.Coastal ? .070f : .145f), .712f);
pen.MoveTo(transom);
TraceDraftCurve(pen, transom, P(L(.11f), .57f), aftDeck);
pen.LineTo(foreDeck);
TraceDraftCurve(pen, foreDeck, P(L(.94f), .565f), stem);
TraceDraftCurve(pen, stem, P(L(.974f), .64f), forwardKeel);
pen.LineTo(aftKeel);
TraceDraftCurve(pen, aftKeel, P(L(.047f), .702f), transom);
pen.Fill();
pen.Stroke();
pen.strokeColor = DraftGold;
pen.lineWidth = 1;
pen.BeginPath();
Path(.026f,.609f, .119f,.627f, .885f,.627f, .959f,.579f);
pen.Stroke();
int levels = Market.Hulls[hullIndex].StarterDecks;
int allowedDecks = Market.Hulls[hullIndex].MaxDecks;
bool mega = hullIndex == Market.Mega;
float deckRise = mega ? .0275f : .047f;
float LeftEdge(int level) => hullIndex switch
{
Market.Regional => .10f + level * .047f,
Market.Ocean => .055f + level * .017f,
Market.Mega => level >= levels - 1 ? .285f : .055f + level * .0018f,
_ => .079f + level * .031f
};
float RightEdge(int level) => hullIndex switch
{
Market.Coastal => .79f - level * .023f,
Market.Ocean => .898f - level * .047f,
Market.Mega => .934f - level * .0041f,
_ => .872f - level * .04f
};
pen.strokeColor = new Color(DraftFine.r, DraftFine.g, DraftFine.b, .28f);
pen.BeginPath();
for (int level = levels; level < allowedDecks; level++)
{
float y = .561f - level * deckRise;
float left = LeftEdge(level), right = RightEdge(level);
for (float x = left; x < right; x += .022f)
Path(x, y, Mathf.Min(x + .012f, right), y);
}
pen.Stroke();
for (int level = 0; level < levels; level++)
{
float bottom = .561f - level * deckRise;
float left = LeftEdge(level), right = RightEdge(level);
pen.fillColor = new Color(.17f + (mega ? .010f : .022f) * level, .29f, .30f);
pen.strokeColor = DraftFine;
pen.lineWidth = 1.25f;
pen.BeginPath();
Path(left,bottom, left + .006f,bottom - deckRise * .81f, right - .036f,bottom - deckRise * .94f, right,bottom);
pen.ClosePath();
pen.Fill();
pen.Stroke();
pen.strokeColor = DraftInk;
pen.BeginPath();
if (used)
for (float x = left + .022f; x < right - .04f; x += .028f)
Path(x,bottom - deckRise * .47f, x + .014f,bottom - deckRise * .47f);
else
for (float x = left + .025f; x < right - .04f; x += .1f)
Path(x,bottom - deckRise * .40f, x + .050f,bottom - deckRise * .40f);
pen.Stroke();
}
float top = .57f - levels * deckRise;
pen.strokeColor = DraftGold;
void RoofDetail(Color fill, params float[] coordinates)
{
pen.fillColor = fill;
pen.BeginPath();
Path(coordinates);
pen.ClosePath();
pen.Fill();
pen.Stroke();
}
var glazing = new Color(.20f, .42f, .46f);
var red = new Color(.55f, .28f, .22f);
switch (hullIndex)
{
case Market.River:
RoofDetail(glazing, .63f,top, .63f,top - .069f, .80f,top - .069f, .818f,top);
break;
case Market.Coastal:
RoofDetail(red, .378f,top, .380f,top - .056f, .424f,top - .060f, .435f,top);
break;
case Market.Regional:
RoofDetail(glazing, .320f,top, .311f,top - .092f, .340f,top - .092f, .362f,top);
RoofDetail(glazing, .388f,top, .376f,top - .079f, .404f,top - .079f, .428f,top);
break;
case Market.Ocean:
RoofDetail(red, .263f,top, .236f,top - .128f, .291f,top - .128f, .330f,top);
break;
case Market.Mega:
RoofDetail(glazing, .36f,top, .38f,top - .063f, .46f,top - .062f, .48f,top);
RoofDetail(glazing, .662f,top, .689f,top - .062f, .71f,top - .077f, .736f,top - .054f, .753f,top);
break;
}
pen.strokeColor = DraftInk;
pen.BeginPath();
Path(.645f,top + .01f, .645f,top - .125f);
Path(.619f,top - .090f, .671f,top - .090f);
Path(.628f,top - .108f, .662f,top - .108f);
pen.Stroke();
}
private static void TraceDraftCurve(Painter2D pen, Vector2 start, Vector2 control, Vector2 end)
{
// Explicit line segments keep UI Toolkit from closing these curves through the drawing origin.
const int subdivisions = 18;
for (int index = 1; index <= subdivisions; index++)
{
float t = index / (float)subdivisions;
pen.LineTo(Vector2.Lerp(Vector2.Lerp(start, control, t), Vector2.Lerp(control, end, t), t));
}
}
private static void DrawDraftGrid(Painter2D pen, Rect bounds, float cell)
{
pen.strokeColor = DraftGrid;
pen.lineWidth = 1;
pen.BeginPath();
for (float x = bounds.width / 2 % cell; x < bounds.width; x += cell)
{
pen.MoveTo(new Vector2(x, 0));
pen.LineTo(new Vector2(x, bounds.height));
}
for (float y = bounds.height / 2 % cell; y < bounds.height; y += cell)
{
pen.MoveTo(new Vector2(0, y));
pen.LineTo(new Vector2(bounds.width, y));
}
pen.Stroke();
}
}
}