Build Soundings cruise management simulator

This commit is contained in:
josh
2026-11-27 20:50:28 -05:00
parent 250dc988a3
commit ba7902dd5e
88 changed files with 6226 additions and 0 deletions

View File

@@ -0,0 +1,269 @@
using System.Collections.Generic;
using UnityEngine;
namespace Soundings
{
internal sealed class VesselExterior
{
internal enum Paint { Navy, Ivory, Pearl, Gold, Teak, TeakSeam, Steel, Black, Glass, BlueGlass, LitGlass, Lounge, Lifeboat, Pool }
private readonly Dictionary<Paint, HarborMesh> batches = new Dictionary<Paint, HarborMesh>();
private readonly Ship ship;
private readonly float length, beam;
private readonly int balconies;
public VesselExterior(Ship ship, float length, float beam)
{
this.ship = ship;
this.length = length;
this.beam = beam;
balconies = 21 + ship.HullIndex * 6;
}
public IReadOnlyDictionary<Paint, HarborMesh> Meshes()
{
BuildHull();
for (int deck = 0; deck < ship.Decks.Count; deck++)
BuildPassengerDeck(deck);
BuildBridgeAndRoof();
BuildLifeboats();
return batches;
}
private HarborMesh Coat(Paint paint)
{
if (!batches.TryGetValue(paint, out HarborMesh batch))
batches.Add(paint, batch = new HarborMesh());
return batch;
}
private void BuildHull()
{
Vector2[] outline = Outline(length, beam, 0);
Vector2 center = Vector2.zero;
Coat(Paint.Navy).Loft(outline, center, false, new Vector3(.88f, -2.65f, .55f),
new Vector3(.967f, -.83f, .87f), new Vector3(.99f, .28f, .97f),
new Vector3(1, 2.34f, 1), new Vector3(1.01f, 4.65f, 1.03f));
Coat(Paint.Gold).Loft(outline, center, false, new Vector3(1.013f, 3.54f, 1.025f),
new Vector3(1.013f, 3.69f, 1.026f));
Coat(Paint.Ivory).Loft(outline, center, true, new Vector3(.998f, 4.47f, 1.015f),
new Vector3(1.013f, 5.14f, 1.027f), new Vector3(1.003f, 5.32f, 1.015f));
Vector2[] promenade = Outline(length * .971f, beam * .979f, 0);
Coat(Paint.Teak).Loft(promenade, center, true, new Vector3(.997f, 5.32f, 1),
new Vector3(1, 5.38f, 1));
Rails(promenade, 5.39f, 5.99f, 2.7f);
for (int side = -1; side <= 1; side += 2)
{
for (int i = 0; i < 24; i++)
{
float x = -length * .40f + i * length * .0285f;
float z = side * beam * 1.024f * SideWidth(x / length + .50f);
Coat(Paint.Black).Box(new Vector3(x, 2.7f, z), new Vector3(.46f, .56f, .18f));
Paint pane = (i + 3 * side) % 5 == 0 ? Paint.LitGlass : Paint.BlueGlass;
Coat(pane).Box(new Vector3(x, 2.72f, z + side * .09f), new Vector3(.31f, .38f, .09f));
}
}
float fore = length * .397f;
Coat(Paint.Steel).Rod(new Vector3(fore, 5.35f, 0), new Vector3(fore, 7.24f, 0), .13f);
Coat(Paint.Gold).Rod(new Vector3(fore, 6.48f, -.82f), new Vector3(fore, 6.48f, .82f), .048f);
for (int side = -1; side <= 1; side += 2)
for (int i = 0; i < 3; i++)
{
float x = length * (.32f + i * .032f);
float z = side * beam * (.52f - i * .135f);
Coat(Paint.Black).Rod(new Vector3(x, 5.37f, z), new Vector3(x, 5.74f, z), .15f);
Coat(Paint.Steel).Box(new Vector3(x, 5.73f, z), new Vector3(.50f, .085f, .32f));
}
}
private void BuildPassengerDeck(int deck)
{
float y = 5.38f + deck * 1.88f;
var (deckLength, deckBeam, offset) = DeckFootprint(deck);
Vector2 center = new Vector2(offset, 0);
Vector2[] outline = Outline(deckLength, deckBeam, offset);
Coat(Paint.Ivory).Loft(outline, center, false, new Vector3(.97f, y, .77f),
new Vector3(.99f, y + .25f, .83f), new Vector3(.99f, y + 1.49f, .83f));
Coat(Paint.Pearl).Loft(outline, center, true, new Vector3(.993f, y + 1.49f, .96f),
new Vector3(1.017f, y + 1.57f, 1.01f), new Vector3(1.017f, y + 1.73f, 1.015f),
new Vector3(1, y + 1.82f, 1));
Coat(Paint.Teak).Loft(outline, center, true, new Vector3(.992f, y + 1.82f, .989f),
new Vector3(.994f, y + 1.88f, .992f));
Rails(outline, y + 1.88f, y + 2.38f, 2.4f);
float width = .70f * deckLength / balconies;
for (int i = 0; i < balconies; i++)
{
float x = offset + Mathf.Lerp(-.39f, .31f, (float)i / (balconies - 1)) * deckLength;
float cross = SideWidth((x - offset) / deckLength + .5f);
int column = i * ship.Hull.Columns / balconies;
for (int side = -1; side <= 1; side += 2)
{
int row = side < 0 ? 0 : ship.Hull.Rows - 1;
Facility facility = ship.Decks[deck].Cells[row * ship.Hull.Columns + column];
float z = side * deckBeam * cross;
Vector3 glass = new Vector3(x, y + .91f, z * .846f);
Coat(Paint.Black).Box(glass, new Vector3(width * 1.01f, 1.21f, .17f));
float divider = width * .21f;
Paint illumination = facility switch
{
Facility.Dining => Paint.LitGlass,
Facility.Entertainment => Paint.Lounge,
Facility.Cabin when (i + deck * 5 + row * 3) % 7 < 4 => Paint.LitGlass,
Facility.Tank => Paint.Black,
_ => Paint.Glass
};
for (int pane = -1; pane <= 1; pane += 2)
Coat(pane < 0 ? illumination : Paint.BlueGlass).Box(glass + new Vector3(pane * divider, .025f, side * .09f),
new Vector3(width * .38f, .98f, .09f));
if (facility == Facility.Tank)
continue;
Coat(Paint.Teak).Box(new Vector3(x, y + .28f, z * .935f), new Vector3(width * 1.10f, .12f, Mathf.Abs(z) * .19f));
Coat(Paint.BlueGlass).Box(new Vector3(x, y + .48f, z * 1.016f), new Vector3(width * .96f, .32f, .05f));
Coat(Paint.Pearl).Box(new Vector3(x, y + .67f, z * 1.02f), new Vector3(width * 1.045f, .047f, .055f));
Coat(Paint.Pearl).Box(new Vector3(x + width * .52f, y + .52f, z * 1.02f), new Vector3(.055f, .32f, .075f));
}
}
}
private void BuildBridgeAndRoof()
{
int deck = ship.Decks.Count - 1;
var (deckLength, deckBeam, offset) = DeckFootprint(deck);
float top = 5.38f + ship.Decks.Count * 1.88f;
float bridge = offset + deckLength * .30f;
Vector2 center = new Vector2(bridge, 0);
Vector2[] capsule = Outline(deckLength * .27f, deckBeam * .83f, bridge);
Coat(Paint.Ivory).Loft(capsule, center, false, new Vector3(.91f, top, .91f),
new Vector3(1, top + .32f, 1));
Coat(Paint.Glass).Loft(capsule, center, false, new Vector3(1, top + .32f, 1),
new Vector3(.90f, top + 1.09f, .95f));
Coat(Paint.Pearl).Loft(capsule, center, true, new Vector3(.905f, top + 1.07f, .955f),
new Vector3(.975f, top + 1.22f, 1.025f), new Vector3(.82f, top + 1.40f, .90f));
foreach (Vector2 point in capsule)
if (point.x > bridge - .5f)
Coat(Paint.Steel).Rod(HarborMesh.Point(center + (point - center), top + .34f),
HarborMesh.Point(center + (point - center) * .937f, top + 1.08f), .026f);
float mast = bridge + 1.15f;
Coat(Paint.Ivory).Rod(new Vector3(mast, top + 1.38f, 0), new Vector3(mast - .48f, top + 4.22f, 0), .135f, 8);
for (int i = 0; i < 3; i++)
{
float y = top + 1.85f + i * .66f;
float span = 1.98f - i * .36f;
Coat(Paint.Pearl).Rod(new Vector3(mast - .27f, y, -span), new Vector3(mast - .27f, y, span), .055f);
Coat(Paint.Black).Rod(new Vector3(mast - .24f, y, span * .84f), new Vector3(mast - .24f, y + .40f, span * .84f), .022f);
}
Coat(Paint.LitGlass).Radome(new Vector3(mast - .48f, top + 4.27f, 0), .13f);
float stack = offset - deckLength * .24f;
for (int side = -1; side <= 1; side += 2)
{
float z = side * deckBeam * .26f;
Vector2 foot = new Vector2(stack, z);
Vector2[] funnel = Outline(3.85f, .94f, stack, z);
Coat(Paint.Ivory).Loft(funnel, foot, false, new Vector3(1.13f, top, 1.12f),
new Vector3(.99f, top + .82f, .985f));
Coat(Paint.Navy).Loft(funnel, foot, false, new Vector3(.99f, top + .82f, .985f),
new Vector3(.95f, top + 2.37f, .86f));
Coat(Paint.Gold).Loft(funnel, foot, false, new Vector3(.95f, top + 2.37f, .86f),
new Vector3(.90f, top + 2.91f, .80f));
Coat(Paint.Black).Loft(funnel, foot, true, new Vector3(.90f, top + 2.91f, .80f),
new Vector3(.87f, top + 3.23f, .77f));
Coat(Paint.Steel).Rod(new Vector3(stack + 7.8f, top, z * 2), new Vector3(stack + 7.8f, top + .59f, z * 2), .16f);
Coat(Paint.Pearl).Radome(new Vector3(stack + 7.8f, top + .93f, z * 2), .49f);
}
float pool = offset + deckLength * .01f;
Coat(Paint.Pearl).Box(new Vector3(pool, top + .075f, 0), new Vector3(5.67f, .17f, 3.32f));
Coat(Paint.Pool).Box(new Vector3(pool, top + .17f, 0), new Vector3(5.21f, .073f, 2.89f));
for (int i = 0; i < 8; i++)
{
Coat(Paint.TeakSeam).Box(new Vector3(pool, top + .032f, (i - 3.5f) * .69f), new Vector3(10, .014f, .032f));
float x = pool - 3.4f + i * .94f;
Coat(Paint.Pearl).Box(new Vector3(x, top + .19f, deckBeam * .67f), new Vector3(.56f, .13f, .92f));
Coat(Paint.Steel).Box(new Vector3(x, top + .34f, deckBeam * .67f + .31f), new Vector3(.52f, .17f, .26f));
}
}
private void BuildLifeboats()
{
for (int i = 0; i < 5 + ship.HullIndex * 2; i++)
for (int side = -1; side <= 1; side += 2)
{
float x = -length * .31f + i * (ship.HullIndex == 0 ? 5.52f : 4.7f);
float z = side * beam * .974f;
Vector2 center = new Vector2(x, z);
Vector2[] capsule = Outline(4.31f, .60f, x, z);
Coat(Paint.Lifeboat).Loft(capsule, center, false, new Vector3(.86f, 6.27f, .59f),
new Vector3(1, 6.49f, .99f), new Vector3(1, 6.65f, 1));
Coat(Paint.Pearl).Loft(capsule, center, true, new Vector3(1, 6.65f, 1),
new Vector3(.875f, 6.94f, .82f), new Vector3(.78f, 7.04f, .65f));
Coat(Paint.Glass).Box(new Vector3(x + .96f, 6.94f, z + side * .44f), new Vector3(.50f, .15f, .13f));
for (int arm = -1; arm <= 1; arm += 2)
{
float mount = x + arm * 1.73f;
Vector3 from = new Vector3(mount, 6.15f, z - side * .67f);
Vector3 elbow = new Vector3(mount, 7.47f, z - side * .52f);
Vector3 tip = new Vector3(mount, 7.53f, z + side * .20f);
Coat(Paint.Ivory).Rod(from, elbow, .07f);
Coat(Paint.Ivory).Rod(elbow, tip, .065f);
Coat(Paint.Steel).Rod(tip, new Vector3(mount, 6.94f, tip.z), .021f);
}
}
}
private void Rails(Vector2[] contour, float low, float high, float stride)
{
HarborMesh metal = Coat(Paint.Pearl);
for (int i = 0; i < contour.Length; i++)
{
Vector2 a = contour[i];
Vector2 b = contour[(i + 1) % contour.Length];
metal.Rod(HarborMesh.Point(a, high), HarborMesh.Point(b, high), .031f);
metal.Rod(HarborMesh.Point(a, (high + low) * .5f), HarborMesh.Point(b, (high + low) * .5f), .021f);
int studs = Mathf.Max(1, Mathf.CeilToInt(Vector2.Distance(a, b) / stride));
for (int stud = 0; stud < studs; stud++)
{
Vector2 foot = Vector2.Lerp(a, b, stud / (float)studs);
metal.Rod(HarborMesh.Point(foot, low), HarborMesh.Point(foot, high), .035f);
}
}
}
private (float Length, float Beam, float Offset) DeckFootprint(int deck)
{
return (length * (.79f - .038f * deck), beam * (.84f - .030f * deck), -length * .034f - deck * .51f);
}
private static float SideWidth(float t)
{
if (t < .16f)
return Mathf.Lerp(.52f, 1, Mathf.Sin(Mathf.Clamp01(t / .16f) * Mathf.PI * .5f));
if (t < .69f)
return 1;
return Mathf.Cos(Mathf.Clamp01((t - .69f) / .31f) * Mathf.PI * .5f);
}
private static Vector2[] Outline(float length, float beam, float x, float z = 0)
{
const int intervals = 20;
var outline = new Vector2[intervals * 2 + 1];
for (int i = 0; i < intervals; i++)
{
float position = i / (float)intervals;
float width = beam * SideWidth(position);
float station = (position - .5f) * length + x;
outline[i] = new Vector2(station, z - width);
outline[outline.Length - 1 - i] = new Vector2(station, z + width);
}
outline[intervals] = new Vector2(length * .5f + x, z);
return outline;
}
}
}