using System.Collections.Generic; using UnityEngine; namespace Soundings { internal sealed class VesselExterior { internal const float DeckBase = 5.38f, DeckSpacing = 2.62f; internal const float PoolHalfLength = 2.61f, PoolHalfWidth = 1.43f, PoolWaterHeight = .24f; internal const float LoungerSeatHeight = .32f, LoungerBeamFraction = .67f; private const int HullStations = 36, DeckStations = 28, BridgeStations = 20; internal enum Paint { Navy, Ivory, Pearl, Gold, Teak, TeakSeam, Steel, Black, Glass, BlueGlass, LitGlass, Lounge, Lifeboat, Pool, Antifouling, DeckCanvas, PortLight, StarboardLight } private readonly Dictionary batches = new Dictionary(); 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 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, HullStations); Vector2 center = Vector2.zero; Coat(Paint.Antifouling).Loft(outline, center, false, new Vector3(.875f, -2.65f, .53f), new Vector3(.936f, -1.78f, .73f), new Vector3(.967f, -.83f, .87f), new Vector3(.984f, -.13f, .933f)); Coat(Paint.Black).Loft(outline, center, false, new Vector3(.984f, -.13f, .933f), new Vector3(.991f, .27f, .969f)); Coat(Paint.Navy).Loft(outline, center, false, new Vector3(.991f, .27f, .969f), new Vector3(.996f, 1.22f, .988f), new Vector3(1, 2.39f, 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.61f, 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, HullStations); Coat(Paint.Teak).Loft(promenade, center, true, new Vector3(.997f, 5.32f, 1), new Vector3(1, DeckBase, 1)); Rails(promenade, DeckBase, DeckBase + .77f, 2.1f); for (int side = -1; side <= 1; side += 2) { int portholes = 25 + ship.HullIndex * 7; for (int i = 0; i < portholes; i++) { float station = Mathf.Lerp(.105f, .837f, i / (float)(portholes - 1)); var (at, along, outward) = SideFrame(station, 2.76f, length * 1.002f, beam * 1.006f, 0, side, HullStations); Coat(Paint.Steel).Disc(at + outward * .043f, along * (side * .22f), Vector3.up * .238f, 12); Coat(Paint.Black).Disc(at + outward * .048f, along * (side * .178f), Vector3.up * .194f, 12); Paint pane = (i + 5 * side) % 7 == 0 ? Paint.Lounge : Paint.Glass; Coat(pane).Disc(at + outward * .052f, along * (side * .145f), Vector3.up * .161f, 12); } var (door, hinge, face) = SideFrame(.56f, 3.22f, length * 1.004f, beam * 1.016f, 0, side, HullStations); SidePanel(Coat(Paint.Black), door + face * .027f, hinge, side, 2.22f, 1.66f); SidePanel(Coat(Paint.Navy), door + face * .032f, hinge, side, 2.10f, 1.53f); SidePanel(Coat(Paint.Steel), door + face * .04f + hinge * .82f, hinge, side, .21f, .08f); } BuildForecastle(); } private void BuildForecastle() { float mast = length * .416f; Coat(Paint.Pearl).Rod(new Vector3(mast, DeckBase, 0), new Vector3(mast, DeckBase + 2.25f, 0), .095f, 9, true); Coat(Paint.Steel).Rod(new Vector3(mast, DeckBase + 1.24f, -.72f), new Vector3(mast, DeckBase + 1.24f, .72f), .043f); Coat(Paint.LitGlass).Rod(new Vector3(mast, DeckBase + 2.04f, 0), new Vector3(mast, DeckBase + 2.24f, 0), .114f, 9, true); float winch = length * .336f; Coat(Paint.Steel).Box(new Vector3(winch, DeckBase + .13f, 0), new Vector3(1.77f, .26f, 1.57f)); Coat(Paint.Navy).Box(new Vector3(winch, DeckBase + .40f, 0), new Vector3(1.09f, .50f, .64f)); for (int side = -1; side <= 1; side += 2) { Vector3 spool = new Vector3(winch, DeckBase + .55f, side * .74f); Coat(Paint.Black).Rod(spool - Vector3.forward * .41f, spool + Vector3.forward * .41f, .30f, 12, true); Coat(Paint.Steel).Rod(spool - Vector3.forward * .21f, spool + Vector3.forward * .21f, .34f, 12, true); Vector3 fairlead = new Vector3(length * .397f, DeckBase + .055f, side * beam * .27f); Coat(Paint.Black).Rod(spool + new Vector3(.16f, -.19f, side * .10f), fairlead, .049f, 8); Coat(Paint.Steel).Box(fairlead, new Vector3(.58f, .13f, .41f)); Coat(Paint.Black).Rod(fairlead, fairlead + Vector3.up * .20f, .12f, 8, true); for (int i = 0; i < 3; i++) { float x = length * (.326f + i * .042f); float z = side * beam * (.58f - i * .185f); Vector3 bollard = new Vector3(x, DeckBase, z); Coat(Paint.Steel).Box(bollard + Vector3.up * .055f, new Vector3(.71f, .11f, .33f)); Coat(Paint.Black).Rod(bollard + new Vector3(-.18f, .08f, 0), bollard + new Vector3(-.18f, .29f, 0), .097f, 8, true); Coat(Paint.Black).Rod(bollard + new Vector3(.18f, .08f, 0), bollard + new Vector3(.18f, .29f, 0), .097f, 8, true); } } } private void BuildPassengerDeck(int deck) { float y = DeckBase + deck * DeckSpacing; float roof = y + DeckSpacing; var (deckLength, deckBeam, offset) = DeckFootprint(deck); Vector2 center = new Vector2(offset, 0); Vector2[] outline = Outline(deckLength, deckBeam, offset, DeckStations); Coat(Paint.Ivory).Loft(outline, center, false, new Vector3(.97f, y, .77f), new Vector3(.99f, y + .24f, .83f), new Vector3(.99f, roof - .37f, .83f)); Coat(Paint.Black).Loft(outline, center, false, new Vector3(.992f, roof - .39f, .835f), new Vector3(.995f, roof - .34f, .946f)); Coat(Paint.Pearl).Loft(outline, center, false, new Vector3(.995f, roof - .34f, .946f), new Vector3(1.008f, roof - .26f, 1.005f), new Vector3(1.008f, roof - .11f, 1.008f), new Vector3(.994f, roof - .06f, .992f)); Coat(Paint.Teak).Loft(outline, center, true, new Vector3(.992f, roof - .06f, .989f), new Vector3(.994f, roof, .992f)); Rails(outline, roof, roof + .78f, 2.1f); float width = .72f * deckLength / balconies; for (int i = 0; i < balconies; i++) { float station = Mathf.Lerp(.101f, .821f, (i + .5f) / balconies); 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].FacilityAt(row * ship.Hull.Columns + column, ship.Hull.Columns); var (floor, along, outward) = SideFrame(station, y, deckLength * .99f, deckBeam * .83f, offset, side, DeckStations); switch (facility) { case Facility.Cabin: case Facility.Suite: case Facility.GrandSuite: bool occupied = (i * 3 + deck * 5 + row * 7) % 11 < 3; BuildWindow(floor, along, outward, side, width * .76f, 1.03f, 1.73f, 2, occupied ? Paint.Lounge : Paint.Glass); BuildBalcony(floor, along, outward, width, Mathf.Abs(floor.z) * .23f); break; case Facility.Dining: case Facility.Entertainment: case Facility.Bar: case Facility.Amenity: case Facility.Restaurant: case Facility.CocktailLounge: case Facility.GrandTheater: case Facility.ResortPool: case Facility.Shop: case Facility.ShoppingArcade: case Facility.Spa: case Facility.WaterPark: BuildWindow(floor, along, outward, side, width * .88f, 1.35f, 1.23f, 3, (i + deck * 2) % 6 == 0 ? Paint.Lounge : Paint.Glass); break; case Facility.Empty: BuildWindow(floor, along, outward, side, width * .49f, 1.42f, .76f, 2, Paint.Glass); break; default: if (i % 2 == 0) BuildVent(floor + outward * .065f + Vector3.up * 1.63f, along, outward, side, width * .43f); break; } } } for (int side = -1; side <= 1; side += 2) { for (int i = 0; i < 3; i++) { var (floor, along, outward) = SideFrame(.845f + i * .039f, y, deckLength * .99f, deckBeam * .83f, offset, side, DeckStations); BuildWindow(floor, along, outward, side, width * .70f, 1.32f, 1.14f, 2, Paint.Glass); } } } private void BuildWindow(Vector3 floor, Vector3 along, Vector3 outward, int side, float width, float height, float opening, int panes, Paint illumination) { Vector3 at = floor + Vector3.up * height + outward * .055f; SidePanel(Coat(Paint.Black), at, along, side, width, opening); float pane = (width - .10f) / panes; for (int i = 0; i < panes; i++) { Vector3 center = at + outward * .007f + along * ((i + .5f - panes * .5f) * pane); SidePanel(Coat(i == 0 ? illumination : Paint.Glass), center, along, side, pane - .037f, opening - .112f); } Coat(Paint.Pearl).Box(at - Vector3.up * (opening * .5f) + outward * .041f, new Vector3(width + .09f, .047f, .14f), along); } private void BuildBalcony(Vector3 floor, Vector3 along, Vector3 outward, float width, float depth) { Coat(Paint.Teak).Box(floor + outward * (.52f * depth) + Vector3.up * .057f, new Vector3(width * .94f, .106f, depth * 1.08f), along); Vector3 rail = floor + outward * depth; float span = width * .93f; HarborMesh frame = Coat(Paint.Steel); frame.Box(rail + Vector3.up * .12f, new Vector3(span, .09f, .085f), along); frame.Box(rail + Vector3.up * .51f, new Vector3(span, .032f, .044f), along); Coat(Paint.Teak).Box(rail + Vector3.up * .89f, new Vector3(span, .055f, .087f), along); for (int i = -1; i <= 1; i++) { Vector3 post = rail + along * (i * span * .48f); frame.Box(post + Vector3.up * .48f, new Vector3(.035f, .80f, .052f), along); } Coat(Paint.Ivory).Box(floor + along * (span * .50f) + outward * (depth * .46f) + Vector3.up * .59f, new Vector3(.048f, 1.07f, depth * .81f), along); } private void BuildVent(Vector3 center, Vector3 along, Vector3 outward, int side, float width) { SidePanel(Coat(Paint.Steel), center, along, side, width, .37f); for (int slat = -2; slat <= 2; slat++) SidePanel(Coat(Paint.Black), center + outward * .003f + Vector3.up * (slat * .059f), along, side, width - .092f, .027f); } private void BuildBridgeAndRoof() { int deck = ship.Decks.Count - 1; var (deckLength, deckBeam, offset) = DeckFootprint(deck); float top = DeckBase + ship.Decks.Count * DeckSpacing; float bridge = BridgeCenter(length, ship.Decks.Count); Vector2 center = new Vector2(bridge, 0); Vector2[] capsule = Outline(9.15f, beam * .67f, bridge, BridgeStations); Coat(Paint.Ivory).Loft(capsule, center, false, new Vector3(.91f, top, .91f), new Vector3(1, top + .88f, 1)); Coat(Paint.Black).Loft(capsule, center, false, new Vector3(1.002f, top + .80f, 1.006f), new Vector3(1.002f, top + .91f, 1.006f)); Coat(Paint.Glass).Loft(capsule, center, false, new Vector3(1, top + .88f, 1), new Vector3(.90f, top + 2.62f, .95f)); Coat(Paint.Pearl).Loft(capsule, center, true, new Vector3(.905f, top + 2.59f, .955f), new Vector3(.985f, top + 2.68f, 1.037f), new Vector3(.975f, top + 2.78f, 1.025f), new Vector3(.87f, top + 2.94f, .91f)); for (int i = 0; i < capsule.Length; i += 2) { Vector2 frame = (capsule[i] - center) * 1.005f; Coat(Paint.Pearl).Rod(HarborMesh.Point(center + frame, top + .88f), HarborMesh.Point(center + Vector2.Scale(frame, new Vector2(.90f, .95f)), top + 2.62f), .039f); } float mast = bridge + 1.15f; Coat(Paint.Pearl).Box(new Vector3(mast - .20f, top + 3.03f, 0), new Vector3(1.35f, .24f, 1.11f)); Coat(Paint.Ivory).Rod(new Vector3(mast, top + 3.11f, 0), new Vector3(mast - .48f, top + 5.72f, 0), .145f, 8, true); for (int i = 0; i < 3; i++) { float y = top + 3.35f + 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); for (int side = -1; side <= 1; side += 2) Coat(Paint.Black).Rod(new Vector3(mast - .24f, y, span * .84f * side), new Vector3(mast - .24f, y + .40f, span * .84f * side), .022f, 6, true); } Coat(Paint.LitGlass).Radome(new Vector3(mast - .48f, top + 5.77f, 0), .13f); Coat(Paint.Pearl).Box(new Vector3(mast - .31f, top + 4.03f, 0), new Vector3(.26f, .14f, 2.41f)); Coat(Paint.Black).Box(new Vector3(mast - .16f, top + 4.03f, 0), new Vector3(.07f, .066f, 2.30f)); float stack = offset - deckLength * .24f; for (int side = -1; side <= 1; side += 2) { BuildBridgeWing(bridge, top, side); float z = side * deckBeam * .23f; Vector2 foot = new Vector2(stack, z); Vector2[] funnel = Outline(3.85f, .94f, stack, 14, 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)); for (int exhaust = -1; exhaust <= 1; exhaust++) { Vector3 pipe = new Vector3(stack + exhaust * .65f, top + 3.22f, z); Coat(Paint.Steel).Rod(pipe, pipe + Vector3.up * .21f, .185f, 10); Coat(Paint.Black).Disc(pipe + Vector3.up * .142f, Vector3.right * .17f, Vector3.back * .17f, 10); } var (vent, along, outward) = SideFrame(.29f, top + 1.45f, 3.67f, .82f, stack, side, 14); BuildVent(vent + Vector3.forward * z + outward * .027f, along, outward, side, .64f); Vector3 radome = new Vector3(stack + 6.10f, top, side * deckBeam * .50f); Coat(Paint.Steel).Rod(radome, radome + Vector3.up * .68f, .16f, 9, true); Coat(Paint.Pearl).Radome(radome + Vector3.up * .90f, .54f); } BuildSunDeck(SunDeck(ship), top); } private void BuildBridgeWing(float bridge, float top, int side) { Vector3 root = new Vector3(bridge + .72f, top, side * beam * .766f); Vector3 outward = Vector3.forward * side; float span = beam * .26f; Coat(Paint.Ivory).Box(root + Vector3.up * .30f, new Vector3(3.41f, .60f, span)); Coat(Paint.Black).Box(root + Vector3.up * .79f, new Vector3(3.32f, .41f, span * .96f)); Coat(Paint.Glass).Box(root + Vector3.up * 1.32f, new Vector3(3.21f, .87f, span * .93f)); Coat(Paint.Pearl).Box(root + Vector3.up * 1.83f, new Vector3(3.47f, .16f, span * 1.04f)); for (int i = -1; i <= 1; i++) Coat(Paint.Pearl).Box(root + outward * (span * .468f) + new Vector3(i * 1.008f, 1.31f, 0), new Vector3(.063f, .88f, .055f)); Vector3 lamp = root + outward * (span * .51f) + new Vector3(.89f, .24f, 0); Coat(Paint.Black).Box(lamp, new Vector3(.43f, .24f, .21f)); Coat(side < 0 ? Paint.PortLight : Paint.StarboardLight).Box(lamp + outward * .117f, new Vector3(.27f, .12f, .052f)); } private void BuildSunDeck(SunDeckLayout plan, float top) { float pool = plan.PoolCenter; if (plan.HasPool) PoolBasin(Coat(Paint.Pearl), Coat(Paint.BlueGlass), Coat(Paint.Pool), new Vector3(pool, top, 0), plan.PoolHalfSize, .37f, PoolWaterHeight); for (int side = -1; side <= 1; side += 2) { if (plan.HasPool) PoolRails(Coat(Paint.Steel), new Vector3(pool - plan.PoolHalfSize.x + .53f, top, side * plan.PoolHalfSize.y), side); for (int i = 0; i < plan.Loungers; i++) BuildLounger(plan.LoungerX(i), top, plan.LoungerDistance, side); float shadeX = plan.Resort ? pool + plan.PoolHalfSize.x + 1.32f : pool + 3.81f; BuildParasol(new Vector3(shadeX, top, side * plan.HalfBeam * .55f), side > 0); if (!plan.Resort) continue; // Floating dividers leave three clear routes through the long basin. float span = plan.PoolHalfSize.x - .80f; for (int i = 0; i < 24; i++) { float x = pool + Mathf.Lerp(-span, span, (float)i / 24); float z = side * plan.PoolHalfSize.y / 3; Vector3 rope = new Vector3(x, top + PoolWaterHeight + .023f, z); Coat(i % 5 == 0 ? Paint.Pearl : Paint.BlueGlass).Rod(rope, rope + Vector3.right * (span / 12), .025f); } } if (plan.Theater) BuildOpenAirStage(plan, top); } private void BuildOpenAirStage(SunDeckLayout plan, float top) { float x = plan.StageCenter; float span = plan.StageHalfWidth; Coat(Paint.Navy).Box(new Vector3(x, top + .205f, 0), new Vector3(3.12f, .41f, span * 2)); Coat(Paint.Teak).Box(new Vector3(x + .05f, top + .417f, 0), new Vector3(3.03f, .053f, span * 1.94f)); Coat(Paint.DeckCanvas).Box(new Vector3(x - 1.35f, top + 1.59f, 0), new Vector3(.19f, 2.37f, span * 1.84f)); Coat(Paint.Gold).Box(new Vector3(x + 1.58f, top + .34f, 0), new Vector3(.042f, .061f, span * 1.96f)); for (int side = -1; side <= 1; side += 2) { Vector3 basePoint = new Vector3(x - .96f, top + .43f, side * span * .95f); Coat(Paint.Steel).Rod(basePoint, basePoint + Vector3.up * 2.85f, .045f, 8, true); Coat(Paint.Black).Box(basePoint + new Vector3(.14f, .51f, -side * .16f), new Vector3(.68f, .89f, .45f)); Coat(Paint.Glass).Box(basePoint + new Vector3(.497f, .51f, -side * .16f), new Vector3(.04f, .67f, .32f)); Coat(Paint.Steel).Rod(basePoint + Vector3.up * 2.72f, basePoint + new Vector3(2.52f, 2.32f, 0), .032f); } Coat(Paint.Steel).Rod(new Vector3(x - .96f, top + 3.16f, -span * .95f), new Vector3(x - .96f, top + 3.16f, span * .95f), .044f); for (int light = -2; light <= 2; light++) Coat(Paint.LitGlass).Box(new Vector3(x - .9f, top + 3.03f, light * span * .34f), new Vector3(.24f, .14f, .23f)); for (int row = 0; row < 2; row++) for (int side = -1; side <= 1; side += 2) { float seatX = plan.StageSeatX(row); float z = side * span * .56f; Coat(Paint.Teak).Box(new Vector3(seatX, top + .17f, z), new Vector3(.48f, .34f, span * .76f)); Coat(Paint.DeckCanvas).Box(new Vector3(seatX, top + .37f, z), new Vector3(.46f, .11f, span * .73f)); Coat(Paint.Pearl).Box(new Vector3(seatX + .22f, top + .53f, z), new Vector3(.10f, .24f, span * .77f)); } } internal static void PoolBasin(HarborMesh coping, HarborMesh tile, HarborMesh water, Vector3 foot, Vector2 halfSize, float rimHeight, float waterHeight) { Vector2 center = new Vector2(foot.x, foot.z); float radius = Mathf.Min(.31f, halfSize.y * .45f); const float surround = .23f; Vector2[] inner = RoundedRectangle(center, halfSize.x, halfSize.y, radius); Vector2[] outer = RoundedRectangle(center, halfSize.x + surround, halfSize.y + surround, radius + surround); float rim = foot.y + rimHeight; float surface = foot.y + waterHeight; coping.Loft(outer, center, false, new Vector3(1f, foot.y, 1f), new Vector3(1f, rim, 1f)); water.Loft(inner, center, true, new Vector3(1f, surface, 1f)); for (int i = 0; i < outer.Length; i++) { int next = (i + 1) % outer.Length; coping.Quad(HarborMesh.Point(outer[next], rim), HarborMesh.Point(outer[i], rim), HarborMesh.Point(inner[i], rim), HarborMesh.Point(inner[next], rim)); tile.Quad(HarborMesh.Point(inner[i], surface), HarborMesh.Point(inner[next], surface), HarborMesh.Point(inner[next], rim), HarborMesh.Point(inner[i], rim)); } } internal static void PoolRails(HarborMesh steel, Vector3 edge, int side) { for (int rail = -1; rail <= 1; rail += 2) { Vector3 foot = edge + new Vector3(rail * .23f, .03f, side * .36f); Vector3 elbow = foot + new Vector3(0, .72f, -side * .13f); Vector3 end = foot + new Vector3(0, .31f, -side * .55f); steel.Rod(foot, elbow, .028f, 8, true); steel.Rod(elbow, end, .028f, 8, true); } for (int rung = 0; rung < 2; rung++) { Vector3 left = edge + new Vector3(-.23f, .14f + rung * .18f, -side * .15f); steel.Rod(left, left + Vector3.right * .46f, .024f, 8, true); } } internal readonly struct SunDeckLayout { internal readonly float Length, Offset, HalfBeam, PoolCenter, StageCenter, StageHalfWidth; internal readonly bool HasPool, Resort, Theater; internal readonly Vector2 PoolHalfSize; internal SunDeckLayout(Ship ship) { int deck = ship.Decks.Count - 1; Length = DeckLength(ship.Hull.Length, deck); Offset = DeckOffset(ship.Hull.Length, deck); HalfBeam = DeckHalfBeam(ship.Hull.Beam * .5f, deck); Facility[] cells = ship.Decks[deck].Cells; bool waterPark = System.Array.IndexOf(cells, Facility.WaterPark) >= 0; Resort = waterPark || System.Array.IndexOf(cells, Facility.ResortPool) >= 0; Theater = System.Array.IndexOf(cells, Facility.GrandTheater) >= 0; HasPool = Resort || ship.Count(Facility.Amenity) > 0; PoolCenter = Offset + Length * (Resort ? .033f : .01f); PoolHalfSize = waterPark ? new Vector2(Mathf.Min(8.95f, Length * .105f), Mathf.Min(3f, HalfBeam * .40f)) : Resort ? new Vector2(Mathf.Min(7.15f, Length * .089f), Mathf.Min(2.77f, HalfBeam * .39f)) : new Vector2(PoolHalfLength, PoolHalfWidth); StageCenter = Offset - Length * .376f; StageHalfWidth = Mathf.Min(2.85f, HalfBeam * .39f); } internal int Loungers => Resort ? 10 : 8; internal float LoungerDistance => HalfBeam * LoungerBeamFraction; internal float LoungerX(int index) => Resort ? PoolCenter + Mathf.Lerp(-PoolHalfSize.x + .44f, PoolHalfSize.x - .44f, (float)index / (Loungers - 1)) : PoolCenter - 3f + index * .94f; internal float StageSeatX(int row) => StageCenter + 3.04f + row * 1.04f; } internal static SunDeckLayout SunDeck(Ship ship) => new SunDeckLayout(ship); private void BuildLounger(float x, float top, float sideDistance, int side) { Vector3 seat = new Vector3(x, top + LoungerSeatHeight, side * sideDistance); Vector3 head = seat + new Vector3(0, .38f, side * .64f); Coat(Paint.DeckCanvas).Box(seat + Vector3.back * (side * .31f), new Vector3(.54f, .077f, 1.22f)); Vector3 halfWidth = Vector3.right * .262f; Vector3 hinge = seat + Vector3.forward * (side * .30f); Coat(Paint.DeckCanvas).Quad(hinge - halfWidth, side > 0 ? head - halfWidth : hinge + halfWidth, head + halfWidth, side > 0 ? hinge + halfWidth : head - halfWidth); HarborMesh frame = Coat(Paint.Pearl); for (int rail = -1; rail <= 1; rail += 2) { Vector3 edge = Vector3.right * (rail * .29f); frame.Rod(seat + edge + Vector3.back * (side * .92f), hinge + edge, .026f); frame.Rod(hinge + edge, head + edge, .026f); frame.Rod(seat + edge + Vector3.back * (side * .67f), seat + edge + new Vector3(0, -.32f, side * -.76f), .026f); frame.Rod(hinge + edge, hinge + edge + new Vector3(0, -.32f, side * .10f), .026f); } frame.Rod(head - halfWidth, head + halfWidth, .023f); } private void BuildParasol(Vector3 foot, bool accent) { Coat(Paint.Steel).Rod(foot, foot + Vector3.up * 2.24f, .036f, 8, true); Coat(Paint.Black).Rod(foot, foot + Vector3.up * .095f, .21f, 12, true); Vector3 top = foot + Vector3.up * 2.23f; const int panels = 8; for (int i = 0; i < panels; i++) { Vector3 edge = ParasolEdge(foot, i, panels); Vector3 next = ParasolEdge(foot, i + 1, panels); Vector3 crown = top + (edge - foot - Vector3.up * 1.86f) * .23f; Vector3 nextCrown = top + (next - foot - Vector3.up * 1.86f) * .23f; HarborMesh fabric = Coat((i + (accent ? 1 : 0)) % 4 == 0 ? Paint.DeckCanvas : Paint.Ivory); fabric.Quad(next, edge, crown, nextCrown); fabric.Quad(edge, next, nextCrown, crown); Coat(Paint.Ivory).Rod(top, edge, .009f); } Coat(Paint.Ivory).Disc(top, Vector3.right * .295f, Vector3.back * .295f, panels); } private static Vector3 ParasolEdge(Vector3 foot, int panel, int panelCount) { float angle = panel * Mathf.PI * 2 / panelCount; return foot + new Vector3(Mathf.Cos(angle) * 1.24f, 1.86f, Mathf.Sin(angle) * 1.24f); } 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, 12, 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)); for (int window = 0; window < 3; window++) { var (at, along, outward) = SideFrame(.42f + window * .115f, 6.91f, 3.63f, .50f, x, side, 12); Vector3 pane = at + Vector3.forward * z + outward * .018f; SidePanel(Coat(Paint.Glass), pane, along, side, .32f, .14f); } 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); float lower = low + .33f; float upper = low + .55f; for (int i = 0; i < contour.Length; i++) { Vector2 a = contour[i]; Vector2 b = contour[(i + 1) % contour.Length]; Coat(Paint.Teak).Rod(HarborMesh.Point(a, high), HarborMesh.Point(b, high), .036f); metal.Rod(HarborMesh.Point(a, lower), HarborMesh.Point(b, lower), .018f, 4); metal.Rod(HarborMesh.Point(a, upper), HarborMesh.Point(b, upper), .018f, 4); 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); } } } internal static float BridgeCenter(float hullLength, int deckCount) { int deck = deckCount - 1; return DeckOffset(hullLength, deck) + DeckLength(hullLength, deck) * .29f; } internal static float DeckLength(float hullLength, int deck) => hullLength * (.81f - .027f * deck); internal static float DeckOffset(float hullLength, int deck) => -hullLength * (.034f + .0065f * deck); internal static float DeckHalfBeam(float halfBeam, int deck) => halfBeam * (.85f - .024f * deck); private (float Length, float Beam, float Offset) DeckFootprint(int deck) => (DeckLength(length, deck), DeckHalfBeam(beam, deck), DeckOffset(length, deck)); private static (Vector3 Position, Vector3 Along, Vector3 Outward) SideFrame(float station, float y, float length, float halfBeam, float offset, int side, int samples) { float sample = station * samples; int first = Mathf.Min(samples - 1, Mathf.FloorToInt(sample)); float startWidth = SideWidth(first / (float)samples); float endWidth = SideWidth((first + 1f) / samples); float z = side * halfBeam * Mathf.Lerp(startWidth, endWidth, sample - first); Vector3 along = new Vector3(length / samples, 0, side * halfBeam * (endWidth - startWidth)).normalized; return (new Vector3(offset + (station - .5f) * length, y, z), along, Vector3.Cross(along, Vector3.up) * side); } private static void SidePanel(HarborMesh mesh, Vector3 center, Vector3 along, int side, float width, float height) { Vector3 across = along * (width * side * .5f); Vector3 up = Vector3.up * (height * .5f); mesh.Quad(center - across - up, center + across - up, center + across + up, center - across + up); } 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, int intervals, float z = 0) { 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; } private static Vector2[] RoundedRectangle(Vector2 center, float halfLength, float halfWidth, float radius) { const int cornerPoints = 5; var contour = new Vector2[4 * cornerPoints]; for (int corner = 0; corner < 4; corner++) { float x = corner is 0 or 3 ? halfLength - radius : radius - halfLength; float z = corner < 2 ? halfWidth - radius : radius - halfWidth; Vector2 arcCenter = center + new Vector2(x, z); for (int point = 0; point < cornerPoints; point++) { float angle = (corner + point / (float)(cornerPoints - 1)) * Mathf.PI * .5f; contour[corner * cornerPoints + point] = arcCenter + new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius; } } return contour; } } }