1046 lines
58 KiB
C#
1046 lines
58 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Soundings
|
|
{
|
|
internal sealed partial class DeckPassengers : IDisposable
|
|
{
|
|
private const float EyeHeight = 1.64f;
|
|
private const float DeckCeiling = 2.44f;
|
|
private const float AisleWidth = 1.80f;
|
|
private const float ChairSeatHeight = .515f;
|
|
private const int Bulkhead = 25, Joinery = 26, Alloy = 27, DeckTrim = 28, Carpet = 29,
|
|
Ivory = 30, LightStrip = 31, Gasket = 32, DisplayDark = 33, ScreenChart = 34,
|
|
ScreenGreen = 35, ScreenAmber = 36, BridgeFloor = 37, Upholstery = 38, SafetyGreen = 39,
|
|
ScreenWater = 40, ScreenLand = 41, ScreenRed = 42, WindowGlass = 43, PoolWater = 44, PoolTile = 45,
|
|
SuiteCarpet = 46, Brass = 47, ShowVelvet = 48, PoolDeck = 49, LoungeLeather = 50, Marble = 51;
|
|
private static readonly string[] Paint =
|
|
{
|
|
"142C3F", "E1DBCA", "B88754", "8A613C", "283846", "678B93", "B45944", "497975",
|
|
"D3A064", "688566", "354B64", "54435D", "AAD4D4", "D7906C", "ECE4D7", "337F9A",
|
|
"573B2E", "A46C50", "DFAB86", "40577D", "BF7756", "D3B973", "76ADA8", "A684AB", "E3DED0",
|
|
"B7BFC0", "AD825C", "91A9AF", "284550", "385361", "DCE1DB", "FFF1D7", "202D36",
|
|
"111D25", "8ED9E0", "65C89B", "E7B868", "3F565C", "416172", "527D65", "29485A", "A8AB71",
|
|
"D66D57", "80B6C5", "3796A3", "47878F", "485C6C", "BD9660", "85424D", "6A908E", "59716B", "E7E0D5"
|
|
};
|
|
|
|
private readonly Transform shipRoot;
|
|
private readonly Ship ship;
|
|
private readonly float length, beam;
|
|
private readonly Shader shader;
|
|
private readonly int programDeck = -1, programRoom = -1;
|
|
private readonly Dictionary<int, Material> paint = new();
|
|
private readonly List<Mesh> meshes = new();
|
|
private readonly Layout[] decks;
|
|
private readonly Layout promenade;
|
|
private Layout bridge;
|
|
private Transform helmWheel;
|
|
private float rudderDegrees;
|
|
private readonly PassengerCrowd passengerCrowd = new();
|
|
private int activeIndex = -1;
|
|
private bool bridgeView;
|
|
private float animationTime;
|
|
|
|
internal bool HasActiveGuest(GuestActivity activity) => !bridgeView
|
|
&& (activeIndex < 0 ? promenade : decks[activeIndex])?.Crowd.activeInHierarchy == true
|
|
&& passengerCrowd.HasActiveGuest(activity);
|
|
|
|
private sealed class Layout
|
|
{
|
|
public readonly GameObject Room, Crowd, Interior, Cutaway;
|
|
public readonly ShipWalkSpace WalkSpace;
|
|
public readonly List<DeckGuest> People = new();
|
|
public readonly List<ShipStation> Stations = new();
|
|
public Mesh CrowdMesh;
|
|
|
|
public Layout(string name, Transform parent, ShipWalkSpace walkSpace = null)
|
|
{
|
|
Room = Piece(name, parent);
|
|
Crowd = Piece("Passenger activity", Room.transform);
|
|
if (walkSpace == null)
|
|
return;
|
|
WalkSpace = walkSpace;
|
|
Interior = Piece("Ceiling and bulkheads", Room.transform);
|
|
Cutaway = Piece("Cutaway walls", Room.transform);
|
|
Interior.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public DeckPassengers(Transform parent, Ship ship, float length, float beam, Shader surface)
|
|
{
|
|
shipRoot = parent;
|
|
this.ship = ship;
|
|
this.length = length;
|
|
this.beam = beam;
|
|
shader = surface;
|
|
decks = new Layout[ship.Decks.Count];
|
|
Facility programVenue = ship.Count(Facility.GrandTheater) > 0 ? Facility.GrandTheater
|
|
: ship.Count(Facility.Entertainment) > 0 ? Facility.Entertainment
|
|
: ship.Count(Facility.Restaurant) > 0 ? Facility.Restaurant : Facility.Dining;
|
|
for (int index = 0; index < ship.Decks.Count; index++)
|
|
{
|
|
int room = Array.IndexOf(ship.Decks[index].Cells, programVenue);
|
|
if (room < 0)
|
|
continue;
|
|
programDeck = index;
|
|
programRoom = room;
|
|
break;
|
|
}
|
|
promenade = BuildPromenade();
|
|
promenade.Crowd.SetActive(false);
|
|
}
|
|
|
|
public float FloorHeight(int index) => VesselExterior.DeckBase + index * VesselExterior.DeckSpacing + .08f;
|
|
|
|
private (float Aft, float Fore, float HalfWidth) RoomEnvelope(int index)
|
|
{
|
|
if (index < 2)
|
|
return (-length * .356f, length * .323f, beam * .77f);
|
|
|
|
float footprint = VesselExterior.DeckLength(length, index);
|
|
float offset = VesselExterior.DeckOffset(length, index);
|
|
return (offset - footprint * .43f, offset + footprint * .31f, VesselExterior.DeckHalfBeam(beam, index) * .83f);
|
|
}
|
|
|
|
public Vector3 WalkOrigin(int index)
|
|
{
|
|
var envelope = RoomEnvelope(index);
|
|
float rowDepth = (envelope.HalfWidth * 2 - (ship.Hull.Rows - 1) * AisleWidth) / ship.Hull.Rows;
|
|
return new Vector3(envelope.Aft + .85f, FloorHeight(index) + EyeHeight, -envelope.HalfWidth + rowDepth + AisleWidth * .5f);
|
|
}
|
|
|
|
private float BridgeHeight => VesselExterior.DeckBase + ship.Decks.Count * VesselExterior.DeckSpacing;
|
|
private float BridgeHalfWidth => beam * .66f;
|
|
private float BridgeAft => BridgeCenter - 4.45f;
|
|
private float BridgeFore => BridgeCenter + 4.32f;
|
|
|
|
public Vector3 BridgeOrigin() => new(BridgeCenter - 1.74f, BridgeHeight + EyeHeight, 0);
|
|
internal ShipWalkSpace BridgeWalkSpace => bridge.WalkSpace;
|
|
internal ShipWalkSpace WalkSpace(int index) => decks[index].WalkSpace;
|
|
internal IReadOnlyList<ShipStation> ActiveStations => bridgeView ? bridge.Stations
|
|
: activeIndex < 0 ? Array.Empty<ShipStation>() : decks[activeIndex].Stations;
|
|
|
|
internal void SetRudder(float degrees)
|
|
{
|
|
if (Mathf.Approximately(rudderDegrees, degrees))
|
|
return;
|
|
rudderDegrees = degrees;
|
|
if (helmWheel != null)
|
|
helmWheel.localRotation = WheelRotation();
|
|
}
|
|
|
|
private Quaternion WheelRotation() => Quaternion.Euler(rudderDegrees * -2.6f, 0, 0);
|
|
|
|
public void Select(int index)
|
|
{
|
|
if (activeIndex >= 0 && decks[activeIndex] != null)
|
|
decks[activeIndex].Room.SetActive(false);
|
|
if (bridgeView)
|
|
bridge.Room.SetActive(false);
|
|
bridgeView = false;
|
|
activeIndex = index;
|
|
promenade.Room.SetActive(index == -1);
|
|
if (index < 0)
|
|
return;
|
|
if (decks[index] == null)
|
|
decks[index] = BuildDeck(index);
|
|
Layout deck = decks[index];
|
|
deck.Interior.SetActive(false);
|
|
deck.Cutaway.SetActive(true);
|
|
deck.Room.SetActive(true);
|
|
}
|
|
|
|
internal void Explore(int index)
|
|
{
|
|
Select(index);
|
|
decks[index].Interior.SetActive(true);
|
|
decks[index].Cutaway.SetActive(false);
|
|
}
|
|
|
|
public void SelectBridge()
|
|
{
|
|
if (activeIndex >= 0 && decks[activeIndex] != null)
|
|
decks[activeIndex].Room.SetActive(false);
|
|
promenade.Room.SetActive(false);
|
|
activeIndex = -1;
|
|
if (bridge == null)
|
|
bridge = BuildBridge();
|
|
bridgeView = true;
|
|
bridge.Room.SetActive(true);
|
|
}
|
|
|
|
public void HideRooms()
|
|
{
|
|
if (activeIndex >= 0 && decks[activeIndex] != null)
|
|
decks[activeIndex].Room.SetActive(false);
|
|
if (bridgeView)
|
|
bridge.Room.SetActive(false);
|
|
bridgeView = false;
|
|
activeIndex = -1;
|
|
promenade.Room.SetActive(false);
|
|
}
|
|
|
|
public void HidePassengers()
|
|
{
|
|
HideCrowd(promenade);
|
|
foreach (Layout deck in decks)
|
|
if (deck != null)
|
|
HideCrowd(deck);
|
|
}
|
|
|
|
private static void HideCrowd(Layout layout)
|
|
{
|
|
layout.Crowd.SetActive(false);
|
|
foreach (DeckGuest guest in layout.People)
|
|
guest.Initialized = false;
|
|
}
|
|
|
|
public void Tick(OnboardSession session, float delta, Camera view)
|
|
{
|
|
if (session == null)
|
|
return;
|
|
animationTime += Mathf.Max(0, delta);
|
|
if (bridgeView)
|
|
return;
|
|
Layout layout = activeIndex < 0 ? promenade : decks[activeIndex];
|
|
if (!layout.Crowd.activeSelf)
|
|
layout.Crowd.SetActive(true);
|
|
layout.CrowdMesh ??= passengerCrowd.CreateMesh(layout.Crowd, length, beam);
|
|
passengerCrowd.Draw(layout.CrowdMesh, layout.People, session, activeIndex < 0, animationTime, delta, view);
|
|
}
|
|
|
|
private Layout BuildPromenade()
|
|
{
|
|
var layout = new Layout("Open promenade", shipRoot);
|
|
float y = BridgeHeight + .015f;
|
|
VesselExterior.SunDeckLayout plan = VesselExterior.SunDeck(ship);
|
|
float width = plan.HalfBeam;
|
|
float aft = plan.Offset - plan.Length * .305f;
|
|
float fore = Mathf.Min(BridgeCenter - 6.0f, plan.Offset + plan.Length * .17f);
|
|
float pool = plan.PoolCenter;
|
|
int sunDeckService = plan.HasPool ? (int)OnboardService.Amenities : -1;
|
|
int walkers = 7 + ship.HullIndex * 3;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
for (int i = 0; i < walkers; i++)
|
|
{
|
|
float occupancy = Mathf.Lerp(.15f, .95f, i / (float)(walkers - 1));
|
|
var route = new Vector3(aft, y, side * width * .895f);
|
|
layout.People.Add(new DeckGuest(route, fore, .285f, (i + (side > 0 ? .43f : 0)) / walkers,
|
|
15 + i * 13 + (side > 0 ? 131 : 0), occupancy));
|
|
}
|
|
|
|
float rail = width - .56f;
|
|
float heading = side < 0 ? 180 : 0;
|
|
AddGuest(layout, GuestActivity.Rail, new Vector3(fore + .92f, y, side * rail), 78 + side, heading, -1, .28f);
|
|
AddGuest(layout, GuestActivity.Photograph, new Vector3(aft - .98f, y, side * (rail - .16f)), 32 + side, heading, -1, .57f);
|
|
|
|
float seatZ = side * (plan.LoungerDistance + .105f);
|
|
for (int chair = 0; chair < 3; chair++)
|
|
{
|
|
float x = plan.LoungerX(chair * 3 + (side > 0 ? 1 : 0));
|
|
AddGuest(layout, GuestActivity.Lounge, new Vector3(x, y, seatZ), 96 + chair * 7 + side * 4,
|
|
heading + 180, sunDeckService, .19f + chair * .20f, VesselExterior.LoungerSeatHeight + .065f);
|
|
}
|
|
}
|
|
|
|
float poolLength = plan.PoolHalfSize.x;
|
|
float poolWidth = plan.PoolHalfSize.y;
|
|
AddGuest(layout, GuestActivity.Talk, new Vector3(pool - poolLength - .96f, y, -.61f), 37, 22, sunDeckService, .28f);
|
|
AddGuest(layout, GuestActivity.Talk, new Vector3(pool - poolLength - .60f, y, .26f), 214, 202, sunDeckService, .44f);
|
|
if (plan.HasPool)
|
|
{
|
|
float waterY = BridgeHeight + VesselExterior.PoolWaterHeight;
|
|
AddGuest(layout, GuestActivity.Swim, new Vector3(pool, waterY, -poolWidth * (plan.Resort ? .61f : .47f)),
|
|
440, 90, sunDeckService, .20f, swimHalfLength: poolLength - 1.11f);
|
|
AddGuest(layout, GuestActivity.Swim, new Vector3(pool - .32f, waterY, plan.Resort ? 0 : .25f),
|
|
587, -90, sunDeckService, .53f, swimHalfLength: poolLength - 1.43f);
|
|
if (plan.Resort)
|
|
AddGuest(layout, GuestActivity.Swim, new Vector3(pool - .64f, waterY, poolWidth * .61f),
|
|
387, 90, sunDeckService, .62f, swimHalfLength: poolLength - 1.76f);
|
|
AddGuest(layout, GuestActivity.Wade, new Vector3(pool + poolLength - .89f, waterY, poolWidth * .55f),
|
|
768, -96, sunDeckService, .33f);
|
|
AddGuest(layout, GuestActivity.Wade, new Vector3(pool + poolLength - 1.61f, waterY, poolWidth * .64f),
|
|
921, 82, sunDeckService, .67f);
|
|
AddGuest(layout, GuestActivity.Photograph, new Vector3(pool + poolLength + .31f, y, -poolWidth - .52f), 62, -53,
|
|
sunDeckService, .64f);
|
|
}
|
|
if (plan.Theater)
|
|
{
|
|
int shows = (int)OnboardService.Shows;
|
|
Vector3 stage = new(plan.StageCenter, y + .43f, 0);
|
|
AddGuest(layout, GuestActivity.Perform, stage, 782, 90, shows, .10f);
|
|
AddGuest(layout, GuestActivity.Guitar, stage, 823, 90, shows, .1f, program: EntertainmentProgram.LiveMusic);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
AddGuest(layout, GuestActivity.Revue, stage + Vector3.forward * side * .83f, 706 + side, 90, shows, .10f,
|
|
program: EntertainmentProgram.Headline);
|
|
for (int row = 0; row < 2; row++)
|
|
for (int seat = 0; seat < 2; seat++)
|
|
AddGuest(layout, GuestActivity.Watch, new Vector3(plan.StageSeatX(row), y,
|
|
side * plan.StageHalfWidth * (.44f + seat * .27f)), 540 + row * 15 + seat * 31 + side * 4,
|
|
-90, shows, .24f + seat * .18f + row * .15f, .37f);
|
|
}
|
|
}
|
|
return layout;
|
|
}
|
|
|
|
private Layout BuildDeck(int index)
|
|
{
|
|
var (aft, fore, halfWidth) = RoomEnvelope(index);
|
|
var layout = new Layout($"Deck {index + 1}", shipRoot,
|
|
new ShipWalkSpace(aft, fore, -halfWidth, halfWidth));
|
|
float y = FloorHeight(index);
|
|
var structure = new Geometry(this, layout.Room.transform);
|
|
var interior = new Geometry(this, layout.Interior.transform);
|
|
var cutaway = new Geometry(this, layout.Cutaway.transform);
|
|
Vector2[] hull = Outline(.97f, beam * .98f);
|
|
float baseLevel = VesselExterior.DeckBase;
|
|
structure.Mesh(0).Loft(hull, Vector2.zero, false,
|
|
new Vector3(.93f, -1.2f, .69f), new Vector3(.99f, 0, .95f),
|
|
new Vector3(1f, 2.0f, 1f), new Vector3(1f, baseLevel - .20f, 1f));
|
|
structure.Mesh(1).Loft(hull, Vector2.zero, false,
|
|
new Vector3(1.002f, baseLevel - .21f, 1.003f), new Vector3(1.003f, baseLevel, 1.003f));
|
|
structure.Mesh(2).Loft(hull, Vector2.zero, true,
|
|
new Vector3(.998f, baseLevel - .01f, .998f), new Vector3(.998f, baseLevel + .01f, .998f));
|
|
structure.Mesh(8).Loft(hull, Vector2.zero, false,
|
|
new Vector3(1.003f, 3.3f, 1.004f), new Vector3(1.003f, 3.37f, 1.004f));
|
|
|
|
Vector2[] outline = hull;
|
|
for (int layer = 0; layer < index; layer++)
|
|
{
|
|
float layerBase = baseLevel + layer * VesselExterior.DeckSpacing;
|
|
float layerRoof = layerBase + VesselExterior.DeckSpacing;
|
|
float offset = VesselExterior.DeckOffset(length, layer);
|
|
Vector2 center = new(offset, 0);
|
|
outline = Outline(VesselExterior.DeckLength(length, layer) / length, VesselExterior.DeckHalfBeam(beam, layer), offset);
|
|
structure.Mesh(Ivory).Loft(outline, center, false, new Vector3(.98f, layerBase, .86f),
|
|
new Vector3(.99f, layerBase + .57f, .88f));
|
|
structure.Mesh(DeckTrim).Loft(outline, center, false, new Vector3(.99f, layerBase + .57f, .88f),
|
|
new Vector3(.99f, layerRoof - .39f, .88f));
|
|
structure.Mesh(Ivory).Loft(outline, center, false, new Vector3(.99f, layerRoof - .39f, .88f),
|
|
new Vector3(1, layerRoof - .18f, 1), new Vector3(1, layerRoof, 1));
|
|
structure.Mesh(2).Loft(outline, center, true, new Vector3(1, layerRoof, 1), new Vector3(.998f, layerRoof + .037f, .998f));
|
|
}
|
|
|
|
for (int i = 0; i < outline.Length; i++)
|
|
{
|
|
Vector2 a = outline[i], b = outline[(i + 1) % outline.Length];
|
|
structure.Mesh(Joinery).Rod(HarborMesh.Point(a, y + .98f), HarborMesh.Point(b, y + .98f), .033f);
|
|
structure.Mesh(Alloy).Rod(HarborMesh.Point(a, y + .65f), HarborMesh.Point(b, y + .65f), .017f);
|
|
structure.Mesh(Alloy).Rod(HarborMesh.Point(a, y + .33f), HarborMesh.Point(b, y + .33f), .015f);
|
|
int posts = Mathf.Max(1, Mathf.CeilToInt(Vector2.Distance(a, b) / 2.25f));
|
|
for (int post = 0; post < posts; post++)
|
|
{
|
|
Vector2 p = Vector2.Lerp(a, b, (float)post / posts);
|
|
structure.Mesh(Alloy).Rod(HarborMesh.Point(p, y), HarborMesh.Point(p, y + .98f), .026f);
|
|
}
|
|
}
|
|
|
|
float usableLength = fore - aft;
|
|
float endCrossing = 1.95f;
|
|
float roomStart = aft + endCrossing;
|
|
int columns = ship.Hull.Columns, rows = ship.Hull.Rows;
|
|
float rowDepth = (halfWidth * 2 - (rows - 1) * AisleWidth) / rows;
|
|
float cellWidth = (usableLength - endCrossing * 2) / columns;
|
|
float mid = (fore + aft) * .5f;
|
|
structure.Box(Carpet, new Vector3(mid, y + .020f, 0), new Vector3(usableLength, .028f, halfWidth * 2));
|
|
interior.Box(Ivory, new Vector3(mid, y + DeckCeiling + .06f, 0), new Vector3(usableLength + .32f, .12f, halfWidth * 2 + .30f));
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float z = side * halfWidth;
|
|
DeckWall(interior, cutaway, new Vector3(aft + endCrossing * .5f, y, z), endCrossing, .15f);
|
|
DeckWall(interior, cutaway, new Vector3(fore - endCrossing * .5f, y, z), endCrossing, .15f);
|
|
DeckWall(interior, cutaway, new Vector3(side < 0 ? aft : fore, y, 0), .14f, halfWidth * 2);
|
|
}
|
|
|
|
var grid = new DeckGrid(columns, rows, roomStart, cellWidth, rowDepth, halfWidth);
|
|
BuildDeckPlan(index, layout, structure, interior, cutaway, grid, aft, fore, y);
|
|
structure.Finish();
|
|
interior.Finish();
|
|
cutaway.Finish();
|
|
return layout;
|
|
}
|
|
|
|
private static void DeckWall(Geometry interior, Geometry cutaway, Vector3 ground, float width, float depth)
|
|
{
|
|
interior.Box(Bulkhead, ground + Vector3.up * (DeckCeiling * .5f), new Vector3(width, DeckCeiling, depth));
|
|
interior.Box(DeckTrim, ground + Vector3.up * .16f, new Vector3(width + .02f, .32f, depth + .02f));
|
|
interior.Box(Joinery, ground + Vector3.up * 1.03f, new Vector3(width + .025f, .083f, depth + .025f));
|
|
cutaway.Box(Ivory, ground + Vector3.up * .24f, new Vector3(width, .48f, depth));
|
|
cutaway.Box(Joinery, ground + Vector3.up * .489f, new Vector3(width + .026f, .022f, depth + .026f));
|
|
}
|
|
|
|
private static void SolidDeckWall(Layout layout, Geometry interior, Geometry cutaway, Vector3 ground, float width, float depth)
|
|
{
|
|
DeckWall(interior, cutaway, ground, width, depth);
|
|
layout.WalkSpace.Block(ground, new Vector3(width, DeckCeiling, depth));
|
|
}
|
|
|
|
private void RoomEntrance(Layout layout, Geometry interior, Geometry cutaway, float x, float y, float z,
|
|
float width, float door, int side, int deck, int slot, Facility facility)
|
|
{
|
|
float segment = (width - door) * .5f;
|
|
for (int part = -1; part <= 1; part += 2)
|
|
{
|
|
float panelX = x + part * (door + segment) * .5f;
|
|
SolidDeckWall(layout, interior, cutaway, new Vector3(panelX, y, z), segment, .13f);
|
|
interior.Box(Joinery, new Vector3(x + part * (door * .5f + .013f), y + 1.02f, z), new Vector3(.07f, 2.04f, .17f));
|
|
}
|
|
interior.Box(Joinery, new Vector3(x, y + 2.06f, z), new Vector3(door + .11f, .085f, .17f));
|
|
interior.Box(Bulkhead, new Vector3(x, y + 2.25f, z), new Vector3(door, .36f, .13f));
|
|
interior.Box(Alloy, new Vector3(x, y + .058f, z), new Vector3(door - .03f, .020f, .22f));
|
|
if (facility == Facility.Empty)
|
|
return;
|
|
string label = facility == Facility.Cabin ? $"{deck + 1}{slot + 1:00}" : Market.Facilities[(int)facility].Name.ToUpperInvariant();
|
|
float plaqueWidth = Mathf.Clamp(label.Length * .049f, .61f, 1.05f);
|
|
float plaqueX = x + (door * .5f + plaqueWidth * .5f + .08f) * side;
|
|
interior.Box(DeckTrim, new Vector3(plaqueX, y + 1.63f, z + side * .088f), new Vector3(plaqueWidth, .15f, .045f));
|
|
PlaceSign(layout.Interior.transform, label, new Vector3(plaqueX, y + 1.63f, z + side * .116f), side > 0 ? 180 : 0,
|
|
facility == Facility.Cabin ? .087f : .049f);
|
|
}
|
|
|
|
private static void RoomWindow(Geometry shape, Geometry cutaway, float x, float y, float z, float width, int side, bool glazed)
|
|
{
|
|
if (!glazed)
|
|
{
|
|
DeckWall(shape, cutaway, new Vector3(x, y, z), width, .15f);
|
|
return;
|
|
}
|
|
float windowWidth = Mathf.Min(1.56f, width * .54f);
|
|
float sidePanel = (width - windowWidth) * .5f;
|
|
shape.Box(Bulkhead, new Vector3(x, y + .59f, z), new Vector3(windowWidth, 1.18f, .15f));
|
|
shape.Box(Bulkhead, new Vector3(x, y + 2.22f, z), new Vector3(windowWidth, .44f, .15f));
|
|
shape.Box(Joinery, new Vector3(x, y + 1.18f, z - side * .088f), new Vector3(windowWidth + .07f, .065f, .11f));
|
|
shape.Box(Joinery, new Vector3(x, y + 2.0f, z - side * .088f), new Vector3(windowWidth + .07f, .065f, .11f));
|
|
cutaway.Box(Ivory, new Vector3(x, y + .24f, z), new Vector3(windowWidth, .48f, .15f));
|
|
shape.Mesh(WindowGlass).Quad(new Vector3(x - windowWidth * .5f, y + 1.19f, z), new Vector3(x + windowWidth * .5f, y + 1.19f, z),
|
|
new Vector3(x + windowWidth * .5f, y + 1.99f, z), new Vector3(x - windowWidth * .5f, y + 1.99f, z));
|
|
for (int fold = -1; fold <= 1; fold += 2)
|
|
{
|
|
DeckWall(shape, cutaway, new Vector3(x + fold * (windowWidth + sidePanel) * .5f, y, z), sidePanel, .15f);
|
|
float edge = x + fold * (windowWidth * .5f + .075f);
|
|
shape.Box(Joinery, new Vector3(x + fold * windowWidth * .5f, y + 1.59f, z - side * .088f), new Vector3(.061f, .86f, .11f));
|
|
shape.Box(Upholstery, new Vector3(edge, y + 1.57f, z - side * .16f), new Vector3(.18f, .98f, .23f));
|
|
}
|
|
}
|
|
|
|
private static void PlaceSign(Transform parent, string copy, Vector3 position, float yaw, float height)
|
|
{
|
|
GameObject sign = Piece(copy, parent);
|
|
sign.transform.SetLocalPositionAndRotation(position, Quaternion.Euler(0, yaw, 0));
|
|
TextMesh letters = sign.AddComponent<TextMesh>();
|
|
Font font = Resources.Load<Font>("Interface");
|
|
if (font != null)
|
|
{
|
|
letters.font = font;
|
|
sign.GetComponent<MeshRenderer>().sharedMaterial = font.material;
|
|
}
|
|
letters.text = copy;
|
|
letters.fontSize = 64;
|
|
letters.characterSize = height / 4.4f;
|
|
letters.anchor = TextAnchor.MiddleCenter;
|
|
letters.alignment = TextAlignment.Center;
|
|
letters.color = new Color32(222, 224, 212, 255);
|
|
}
|
|
|
|
private void Room(Geometry shape, Layout layout, Facility facility, Vector3 pos, float width, float depth,
|
|
int seed, int facing, bool programVenue)
|
|
{
|
|
int floor = FacilityFloor(facility);
|
|
void Box(int color, float x, float y, float z, float w, float height, float d)
|
|
=> shape.Box(color, pos + new Vector3(x, y, z * facing), new Vector3(w, height, d));
|
|
void Solid(int color, float x, float y, float z, float w, float h, float d)
|
|
{
|
|
Box(color, x, y, z, w, h, d);
|
|
layout.WalkSpace.Block(pos + new Vector3(x, y, z * facing), new Vector3(w, h, d));
|
|
}
|
|
void Seat(float x, float z, int color, int direction = 1)
|
|
{
|
|
Vector3 center = pos + new Vector3(x, 0, z * facing);
|
|
Chair(shape, center, color, facing * direction);
|
|
layout.WalkSpace.Block(center, new Vector3(.50f, .91f, .54f));
|
|
}
|
|
void Guest(GuestActivity activity, float x, float z, int variant, OnboardService service,
|
|
float occupancy, float seatHeight = 0, int direction = 1, float lift = 0, EntertainmentProgram? program = null)
|
|
{
|
|
float heading = facing * direction > 0 ? 0 : 180;
|
|
AddGuest(layout, activity, pos + new Vector3(x, lift, z * facing),
|
|
seed * 11 + variant, heading, (int)service, occupancy, seatHeight, program);
|
|
}
|
|
|
|
Box(floor, 0, -.018f, 0, width, .045f, depth);
|
|
if (facility == Facility.Empty)
|
|
return;
|
|
|
|
StationKind? station = FacilityStation(facility);
|
|
if (station.HasValue)
|
|
layout.Stations.Add(new ShipStation(station.Value, pos + new Vector3(0, 1.45f, -.33f * depth * facing)));
|
|
|
|
switch (facility)
|
|
{
|
|
case Facility.Cabin:
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float x = side * width * .19f;
|
|
float z = depth * .16f;
|
|
Solid(Joinery, x, .257f, z, 1.03f, .52f, 1.88f);
|
|
Box(Ivory, x, .562f, z, 1.05f, .191f, 1.88f);
|
|
Box(Upholstery, x, .678f, z - .22f, 1.07f, .075f, 1.34f);
|
|
Box(Ivory, x, .71f, z + .59f, .62f, .108f, .35f);
|
|
Box(Joinery, x, .77f, z + .91f, 1.12f, .87f, .10f);
|
|
Box(LightStrip, x, 1.12f, z + .837f, .48f, .036f, .049f);
|
|
Box(8, x, .72f, z - .86f, 1.07f, .014f, .045f);
|
|
}
|
|
Solid(Joinery, width * .395f, .44f, -depth * .214f, .80f, .88f, .96f);
|
|
Box(Ivory, width * .395f, .906f, -depth * .214f, .86f, .055f, 1.01f);
|
|
Box(Alloy, width * .35f, .765f, -depth * .31f, .38f, .034f, .054f);
|
|
Solid(Joinery, -width * .39f, .95f, -depth * .24f, .67f, 1.90f, .88f);
|
|
Box(Alloy, -width * .337f, 1.00f, -depth * .24f, .033f, .15f, .035f);
|
|
Guest(seed % 3 == 0 ? GuestActivity.Read : GuestActivity.Rail, .05f, -depth * .05f, 1,
|
|
OnboardService.Rooms, Mathf.Lerp(.31f, .98f, seed % 9 / 8f));
|
|
break;
|
|
case Facility.Dining:
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float x = side * width * .25f;
|
|
Box(Alloy, x, .34f, .12f, .19f, .62f, .19f);
|
|
Solid(Ivory, x, .746f, .12f, 1.12f, .12f, .91f);
|
|
Box(8, x, .813f, .12f, .33f, .015f, .86f);
|
|
for (int seat = -1; seat <= 1; seat += 2)
|
|
{
|
|
float place = seat * .31f + .12f;
|
|
shape.Mesh(14).Rod(pos + new Vector3(x + .04f, .817f, place * facing),
|
|
pos + new Vector3(x + .04f, .840f, place * facing), .112f, 12);
|
|
Box(LightStrip, x + .22f, .85f, place + .05f, .065f, .080f, .065f);
|
|
}
|
|
Seat(x, -.58f, Upholstery);
|
|
Seat(x, .81f, Upholstery, -1);
|
|
Guest(GuestActivity.Dine, x, -.61f, side + 1, OnboardService.Meals, side < 0 ? .21f : .56f, ChairSeatHeight);
|
|
Guest(GuestActivity.Dine, x, .84f, side + 4, OnboardService.Meals, side < 0 ? .75f : .93f, ChairSeatHeight, -1);
|
|
}
|
|
if (programVenue)
|
|
Guest(GuestActivity.Guitar, 0, .32f, 32, OnboardService.Shows, .22f, direction: -1,
|
|
program: EntertainmentProgram.LiveMusic);
|
|
break;
|
|
case Facility.Bar:
|
|
float counter = depth * .025f;
|
|
Solid(Joinery, 0, .48f, counter, width * .76f, .94f, .65f);
|
|
Box(Gasket, 0, .974f, counter, width * .79f, .10f, .75f);
|
|
Box(8, 0, .20f, counter - .378f, width * .74f, .050f, .045f);
|
|
Box(LightStrip, 0, .867f, counter - .35f, width * .74f, .031f, .043f);
|
|
float display = depth * .44f;
|
|
Box(DeckTrim, 0, 1.50f, display + .09f, width * .67f, .68f, .10f);
|
|
Box(Joinery, 0, 1.36f, display, width * .69f, .053f, .22f);
|
|
Box(LightStrip, 0, 1.80f, display + .047f, width * .66f, .045f, .09f);
|
|
for (int bottle = -8; bottle <= 8; bottle++)
|
|
{
|
|
float x = bottle * width * .035f;
|
|
int color = Mathf.Abs(bottle) % 3 == 1 ? SafetyGreen : Mathf.Abs(bottle) % 3 == 2 ? 13 : 12;
|
|
float height = .16f + (Mathf.Abs(bottle) % 4) * .022f;
|
|
Box(color, x, 1.393f + height * .5f, display - .024f, .067f, height, .063f);
|
|
Box(Alloy, x, 1.382f + height, display - .024f, .039f, .048f, .040f);
|
|
}
|
|
for (int i = -2; i <= 2; i++)
|
|
{
|
|
float x = i * width * .115f;
|
|
if (i == 0)
|
|
continue;
|
|
float stool = counter - .83f;
|
|
Box(Alloy, x, .057f, stool, .39f, .11f, .39f);
|
|
Box(Alloy, x, .35f, stool, .077f, .69f, .077f);
|
|
Box(Upholstery, x, .69f, stool, .38f, .10f, .39f);
|
|
Box(Alloy, x, .26f, stool + .035f, .30f, .035f, .25f);
|
|
Box(8, x, 1.028f, counter - .223f, .154f, .008f, .154f);
|
|
layout.WalkSpace.Block(pos + new Vector3(x, 0, stool * facing), new Vector3(.39f, .76f, .40f));
|
|
Guest(GuestActivity.Drink, x, stool, i + 4, OnboardService.Drinks, i is 1 or -1 ? .25f : .76f, .775f);
|
|
}
|
|
Box(SafetyGreen, width * .14f, 1.116f, counter + .13f, .07f, .18f, .071f);
|
|
Box(Alloy, width * .14f, 1.224f, counter + .13f, .055f, .06f, .044f);
|
|
Guest(GuestActivity.TendBar, 0, counter + .72f, 11, OnboardService.Drinks, .08f, direction: -1);
|
|
break;
|
|
case Facility.Entertainment:
|
|
Solid(Gasket, 0, .19f, depth * .307f, width * .82f, .38f, .99f);
|
|
Box(Joinery, 0, .393f, depth * .307f, width * .82f, .044f, .99f);
|
|
Box(11, 0, 1.24f, depth * .444f, width * .80f, 1.65f, .13f);
|
|
for (int i = -4; i <= 4; i++)
|
|
Box(6, i * width * .093f, 1.24f, depth * .436f, .079f, 1.65f, .082f);
|
|
for (int row = -1; row <= 0; row++)
|
|
for (int i = -2; i <= 2; i++)
|
|
if (i != 0)
|
|
{
|
|
float x = i * width * .139f;
|
|
float z = -.37f + row * .62f;
|
|
Seat(x, z, 10);
|
|
Guest(GuestActivity.Watch, x, z, 46 + i + row * 5, OnboardService.Shows,
|
|
row == 0 ? .29f + Mathf.Abs(i) * .13f : .59f + Mathf.Abs(i) * .13f, ChairSeatHeight);
|
|
}
|
|
Guest(GuestActivity.Perform, 0, depth * .31f, 30, OnboardService.Shows, .06f, direction: -1, lift: .42f);
|
|
if (programVenue)
|
|
{
|
|
Guest(GuestActivity.Guitar, 0, depth * .31f, 38, OnboardService.Shows, .22f, direction: -1, lift: .42f,
|
|
program: EntertainmentProgram.LiveMusic);
|
|
Guest(GuestActivity.Revue, -width * .145f, depth * .31f, 35, OnboardService.Shows, .22f,
|
|
direction: -1, lift: .42f, program: EntertainmentProgram.Headline);
|
|
Guest(GuestActivity.Revue, width * .145f, depth * .31f, 22, OnboardService.Shows, .22f,
|
|
direction: -1, lift: .42f, program: EntertainmentProgram.Headline);
|
|
}
|
|
break;
|
|
case Facility.Amenity:
|
|
Vector2 basin = new(Mathf.Min(2.58f, width * .295f), depth * .24f);
|
|
const float poolLevel = .44f;
|
|
float poolZ = depth * .13f;
|
|
Vector3 poolFoot = pos + Vector3.forward * (poolZ * facing);
|
|
VesselExterior.PoolBasin(shape.Mesh(Ivory), shape.Mesh(PoolTile), shape.Mesh(PoolWater), poolFoot, basin, .56f, poolLevel);
|
|
VesselExterior.PoolRails(shape.Mesh(Alloy), poolFoot + new Vector3(-basin.x * .69f, .18f, -basin.y * facing), -facing);
|
|
layout.WalkSpace.Block(poolFoot, new Vector3((basin.x + .23f) * 2f, .56f, (basin.y + .23f) * 2f));
|
|
Guest(GuestActivity.Wade, basin.x * .37f, poolZ - basin.y * .12f, 7, OnboardService.Amenities, .12f,
|
|
lift: poolLevel);
|
|
Guest(GuestActivity.Wade, -basin.x * .25f, poolZ + basin.y * .24f, 51, OnboardService.Amenities, .57f,
|
|
direction: -1, lift: poolLevel);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float seatX = side * width * .401f;
|
|
float bench = -depth * .36f;
|
|
Solid(Joinery, seatX, .20f, bench, .94f, .36f, .46f);
|
|
Box(Upholstery, seatX, .418f, bench, .92f, .089f, .46f);
|
|
Box(Upholstery, seatX, .61f, bench - .211f, .93f, .36f, .072f);
|
|
Guest(side > 0 ? GuestActivity.Read : GuestActivity.Rest, seatX, bench,
|
|
side + 3, OnboardService.Amenities, side < 0 ? .30f : .75f, .483f);
|
|
}
|
|
break;
|
|
case Facility.Tank:
|
|
var start = pos + new Vector3(-width * .32f, .61f, 0);
|
|
shape.Mesh(5).Rod(start, pos + new Vector3(width * .32f, .61f, 0), .49f, 12);
|
|
Box(8, 0, .94f, -.12f, .29f, .22f, .24f);
|
|
layout.WalkSpace.Block(pos, new Vector3(width * .65f, .95f, 1.03f));
|
|
return;
|
|
case Facility.Galley:
|
|
Solid(Alloy, 0, .45f, depth * .23f, width * .82f, .88f, .76f);
|
|
Box(Ivory, 0, .94f, depth * .23f, width * .84f, .11f, .87f);
|
|
for (int i = -1; i <= 1; i++)
|
|
{
|
|
Box(4, i * width * .24f, 1.02f, depth * .23f, .55f, .06f, .50f);
|
|
Box(Gasket, i * width * .24f, .50f, depth * .23f - .394f, .62f, .51f, .027f);
|
|
Box(Alloy, i * width * .24f, .704f, depth * .23f - .421f, .45f, .042f, .041f);
|
|
}
|
|
Box(Alloy, 0, 1.76f, depth * .32f, width * .78f, .34f, .55f);
|
|
break;
|
|
case Facility.Stores:
|
|
for (int shelf = 1; shelf <= 2; shelf++)
|
|
{
|
|
float y = shelf * .53f;
|
|
Box(8, 0, y, depth * .28f, width * .82f, .09f, .60f);
|
|
for (int i = -1; i <= 1; i++)
|
|
Box(i == 0 ? 6 : 5, i * width * .24f, y + .21f, depth * .28f, width * .19f, .34f, .47f);
|
|
}
|
|
layout.WalkSpace.Block(pos + new Vector3(0, 0, depth * .28f * facing), new Vector3(width * .82f, 1.24f, .6f));
|
|
break;
|
|
case Facility.Water:
|
|
case Facility.Waste:
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
var foot = pos + new Vector3(side * width * .24f, .18f, depth * .17f * facing);
|
|
shape.Mesh(facility == Facility.Water ? 15 : 11).Rod(foot, foot + Vector3.up * 1.15f, .39f, 12);
|
|
Solid(Gasket, side * width * .24f, .12f, depth * .17f, .94f, .22f, .92f);
|
|
Box(Alloy, side * width * .24f, .72f, depth * .17f - .399f, .23f, .25f, .043f);
|
|
}
|
|
Box(14, 0, .99f, depth * .34f, width * .53f, .15f, .13f);
|
|
break;
|
|
case Facility.Workshop:
|
|
Solid(Joinery, 0, .47f, depth * .28f, width * .83f, .88f, .72f);
|
|
Box(8, 0, .97f, depth * .28f, width * .86f, .12f, .79f);
|
|
Box(4, 0, 1.42f, depth * .46f, width * .78f, .77f, .12f);
|
|
Box(7, width * .24f, 1.10f, depth * .27f, .47f, .20f, .34f);
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
private Layout BuildBridge()
|
|
{
|
|
float y = BridgeHeight;
|
|
float x = BridgeCenter;
|
|
float extent = BridgeHalfWidth;
|
|
var walk = new ShipWalkSpace(BridgeAft, BridgeFore - .06f, -extent, extent);
|
|
var layout = new Layout("Wheelhouse", shipRoot, walk);
|
|
var geometry = new Geometry(this, layout.Room.transform);
|
|
geometry.Box(BridgeFloor, new Vector3(x - .075f, y - .04f, 0), new Vector3(8.84f, .15f, extent * 2));
|
|
geometry.Box(Carpet, new Vector3(x - 1.94f, y + .04f, 0), new Vector3(4.64f, .012f, extent * 1.71f));
|
|
geometry.Box(Ivory, new Vector3(x - .07f, y + 2.77f, 0), new Vector3(8.87f, .17f, extent * 2));
|
|
geometry.Box(Bulkhead, new Vector3(BridgeAft, y + 1.365f, 0), new Vector3(.18f, 2.73f, extent * 2));
|
|
geometry.Box(DeckTrim, new Vector3(BridgeAft + .096f, y + .171f, 0), new Vector3(.04f, .34f, extent * 2));
|
|
geometry.Box(Joinery, new Vector3(BridgeAft + .099f, y + 1.12f, 0), new Vector3(.04f, .058f, extent * 2));
|
|
geometry.Box(Gasket, new Vector3(BridgeAft + .10f, y + 1.125f, .23f), new Vector3(.082f, 2.23f, 1.18f));
|
|
geometry.Box(Alloy, new Vector3(BridgeAft + .155f, y + 1.13f, .23f), new Vector3(.078f, 2.11f, 1.05f));
|
|
geometry.Box(SafetyGreen, new Vector3(BridgeAft + .197f, y + 2.34f, .23f), new Vector3(.062f, .18f, .67f));
|
|
PlaceSign(layout.Room.transform, "WHEELHOUSE", new Vector3(BridgeAft + .24f, y + 2.34f, .23f), -90, .068f);
|
|
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float z = side * extent;
|
|
geometry.Box(DeckTrim, new Vector3(x - .09f, y + .45f, z), new Vector3(8.63f, .90f, .18f));
|
|
geometry.Box(Ivory, new Vector3(x - .10f, y + 2.59f, z), new Vector3(8.64f, .28f, .18f));
|
|
geometry.Box(Joinery, new Vector3(x - .08f, y + .88f, z + side * -.10f), new Vector3(8.60f, .085f, .18f));
|
|
geometry.Box(Carpet, new Vector3(x - 3.25f, y + 1.64f, z), new Vector3(2.30f, 1.54f, .20f));
|
|
for (int bay = 0; bay < 3; bay++)
|
|
{
|
|
float from = x - 2.12f + bay * 1.93f;
|
|
float to = from + 1.93f;
|
|
Vector3 Post(float at, float height) => new(at, y + height, z);
|
|
geometry.Mesh(WindowGlass).Quad(Post(from, .91f), Post(to, .91f), Post(to, 2.45f), Post(from, 2.45f));
|
|
geometry.Box(Alloy, new Vector3(from, y + 1.68f, z), new Vector3(.075f, 1.60f, .18f));
|
|
}
|
|
geometry.Box(Bulkhead, new Vector3(x + 3.75f, y + 1.685f, z), new Vector3(.28f, 1.56f, .22f));
|
|
for (int run = -1; run <= 1; run++)
|
|
{
|
|
float lightX = x + run * 2.35f;
|
|
geometry.Box(Gasket, new Vector3(lightX, y + 2.68f, extent * .63f * side), new Vector3(1.28f, .045f, .32f));
|
|
geometry.Box(LightStrip, new Vector3(lightX, y + 2.648f, extent * .63f * side), new Vector3(1.16f, .028f, .23f));
|
|
}
|
|
float lockerZ = extent * side * .67f;
|
|
geometry.Box(Joinery, new Vector3(BridgeAft + .46f, y + .47f, lockerZ), new Vector3(.72f, .94f, 1.24f));
|
|
geometry.Box(Ivory, new Vector3(BridgeAft + .49f, y + .963f, lockerZ), new Vector3(.81f, .064f, 1.30f));
|
|
geometry.Box(Alloy, new Vector3(BridgeAft + .825f, y + .76f, lockerZ), new Vector3(.045f, .039f, .23f));
|
|
walk.Block(new Vector3(BridgeAft + .46f, y, lockerZ), new Vector3(.78f, .94f, 1.24f));
|
|
}
|
|
|
|
const int panes = 8;
|
|
Vector3 WindowPoint(float fraction, float height)
|
|
{
|
|
float z = fraction * extent;
|
|
float sweep = .48f * Mathf.Pow(Mathf.Abs(fraction), 1.65f) + (height > 2f ? .36f : 0);
|
|
return new Vector3(BridgeFore - sweep, y + height, z);
|
|
}
|
|
for (int i = 0; i < panes; i++)
|
|
{
|
|
float left = i * 2f / panes - 1;
|
|
float right = (i + 1) * 2f / panes - 1;
|
|
Vector3 a = WindowPoint(left, .89f), b = WindowPoint(right, .89f);
|
|
Vector3 c = WindowPoint(right, 2.56f), d = WindowPoint(left, 2.56f);
|
|
geometry.Mesh(WindowGlass).Quad(a, b, c, d);
|
|
geometry.Mesh(DeckTrim).Quad(a - Vector3.up * .91f, b - Vector3.up * .91f, b, a);
|
|
geometry.Mesh(Ivory).Quad(d, c, c + Vector3.up * .19f, d + Vector3.up * .19f);
|
|
geometry.Mesh(Joinery).Rod(a - Vector3.right * .07f, b - Vector3.right * .07f, .061f, 6);
|
|
geometry.Mesh(Gasket).Rod(d, c, .043f, 6);
|
|
geometry.Mesh(Alloy).Rod(a, d, .043f, 6);
|
|
Vector3 sill = (a + b) * .5f;
|
|
walk.Block(sill + Vector3.right * .039f, new Vector3(.16f + Mathf.Abs(a.x - b.x), .92f, b.z - a.z + .025f));
|
|
if (i is 1 or 3 or 4 or 6)
|
|
{
|
|
Vector3 wiper = Vector3.Lerp(a, b, .30f) + new Vector3(.026f, .059f, 0);
|
|
Vector3 tip = Vector3.Lerp(wiper, Vector3.Lerp(c, d, .21f), .57f);
|
|
geometry.Mesh(Gasket).Rod(wiper, tip, .013f, 6);
|
|
geometry.Mesh(Gasket).Rod(tip - Vector3.up * .22f, tip + Vector3.up * .21f, .020f, 6);
|
|
}
|
|
if (i == panes - 1)
|
|
geometry.Mesh(Alloy).Rod(b, c, .043f, 6);
|
|
}
|
|
|
|
float stationOffset = extent * .66f;
|
|
BridgeConsole(geometry, walk, new Vector3(x + 1.39f, y, 0), 2.27f, 0);
|
|
layout.Stations.Add(new ShipStation(StationKind.Helm, new Vector3(x + .38f, y + 1.40f, 0)));
|
|
BridgeConsole(geometry, walk, new Vector3(x + 1.83f, y, -stationOffset), 1.72f, 1);
|
|
BridgeConsole(geometry, walk, new Vector3(x + 1.83f, y, stationOffset), 1.72f, 2);
|
|
BuildHelmWheel(geometry, layout.Room.transform, new Vector3(x + .85f, y + 1.116f, 0));
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
var seat = new Vector3(x + .31f, y, side * .72f);
|
|
BridgeChair(geometry, seat);
|
|
walk.Block(seat + Vector3.left * .08f, new Vector3(.62f, 1.20f, .46f));
|
|
}
|
|
geometry.Box(Gasket, new Vector3(BridgeFore - .43f, y + 2.64f, 0), new Vector3(.079f, .16f, 1.12f));
|
|
PlaceSign(layout.Room.transform, "NAVIGATION", new Vector3(BridgeFore - .478f, y + 2.64f, 0), 90, .067f);
|
|
DrawForedeck(geometry);
|
|
geometry.Finish();
|
|
return layout;
|
|
}
|
|
|
|
private static void BridgeConsole(Geometry shape, ShipWalkSpace walk, Vector3 origin, float width, int style)
|
|
{
|
|
void Box(int paint, float x, float y, float z, float d, float h, float w)
|
|
=> shape.Box(paint, origin + new Vector3(x, y, z), new Vector3(d, h, w));
|
|
Box(Gasket, 0, .48f, 0, .99f, .94f, width * .95f);
|
|
Box(DeckTrim, -.516f, .529f, 0, .048f, .70f, width * .81f);
|
|
Box(Joinery, 0, .987f, 0, 1.06f, .077f, width);
|
|
Box(Upholstery, .07f, 1.05f, 0, .82f, .075f, width * .96f);
|
|
Box(Alloy, -.535f, .943f, 0, .026f, .071f, width * .95f);
|
|
walk.Block(origin, new Vector3(1.09f, 1.05f, width));
|
|
for (int i = -1; i <= 1; i += 2)
|
|
{
|
|
float z = i * width * .243f;
|
|
Box(Gasket, .34f, 1.302f, z, .20f, .47f, width * .402f);
|
|
Vector3 screen = origin + new Vector3(.234f, 1.308f, z);
|
|
BridgeScreen(shape, screen, .36f, width * .353f, (style + (i > 0 ? 1 : 0)) % 3);
|
|
Box(Alloy, .354f, 1.557f, z, .24f, .030f, width * .41f);
|
|
for (int key = 0; key < 5; key++)
|
|
Box(key == 3 ? ScreenAmber : ScreenChart, -.26f + key * .042f, 1.093f,
|
|
z - width * .11f, .022f, .016f, .047f);
|
|
}
|
|
Box(DisplayDark, -.19f, 1.09f, 0, .30f, .030f, .29f);
|
|
Box(Alloy, -.09f, 1.211f, 0, .036f, .215f, .036f);
|
|
Box(ScreenAmber, -.11f, 1.33f, 0, .09f, .074f, .12f);
|
|
Box(ScreenRed, -.35f, 1.112f, .151f, .066f, .047f, .065f);
|
|
}
|
|
|
|
private void BuildHelmWheel(Geometry bridgeGeometry, Transform parent, Vector3 axis)
|
|
{
|
|
var mount = Piece("Steering wheel mount", parent).transform;
|
|
mount.SetLocalPositionAndRotation(axis, Quaternion.Euler(0, 0, -16.9f));
|
|
helmWheel = Piece("Steering wheel", mount).transform;
|
|
helmWheel.localRotation = WheelRotation();
|
|
var wheel = new Geometry(this, helmWheel);
|
|
Vector3 Rim(float angle) => new(0, Mathf.Sin(angle) * .177f, Mathf.Cos(angle) * .177f);
|
|
for (int part = 0; part < 20; part++)
|
|
{
|
|
float angle = part * Mathf.PI * .10f;
|
|
wheel.Mesh(Gasket).Rod(Rim(angle), Rim(angle + Mathf.PI * .10f), .023f, 7);
|
|
}
|
|
for (int spoke = 0; spoke < 3; spoke++)
|
|
{
|
|
float angle = Mathf.PI * .5f + spoke * Mathf.PI * 2 / 3;
|
|
wheel.Mesh(Alloy).Rod(Vector3.zero, Rim(angle), .014f, 6);
|
|
}
|
|
wheel.Mesh(Alloy).Rod(-Vector3.right * .025f, Vector3.right * .025f, .055f, 10);
|
|
wheel.Box(Gasket, -Vector3.right * .030f, new Vector3(.030f, .064f, .064f));
|
|
wheel.Finish();
|
|
bridgeGeometry.Mesh(Alloy).Rod(axis, axis + mount.localRotation * Vector3.right * .18f, .037f, 8);
|
|
}
|
|
|
|
private static void BridgeScreen(Geometry shape, Vector3 face, float height, float width, int mode)
|
|
{
|
|
void Flat(int paint, float y, float z, float h, float w, float depth = .01f)
|
|
=> shape.Box(paint, face + new Vector3(-depth, y, z), new Vector3(.007f, h, w));
|
|
void Line(int paint, Vector2 from, Vector2 to, float radius = .003f)
|
|
=> shape.Mesh(paint).Rod(face + new Vector3(-.029f, from.x, from.y), face + new Vector3(-.029f, to.x, to.y), radius, 5);
|
|
Flat(mode == 1 ? ScreenWater : DisplayDark, 0, 0, height, width);
|
|
Flat(Alloy, height * .445f, 0, .012f, width * .92f, .024f);
|
|
Flat(ScreenAmber, -height * .43f, width * .29f, .013f, width * .23f, .025f);
|
|
if (mode == 0)
|
|
{
|
|
for (int ring = 1; ring <= 3; ring++)
|
|
{
|
|
float radius = ring * height * .113f;
|
|
Vector2 previous = new(radius, 0);
|
|
for (int i = 1; i <= 20; i++)
|
|
{
|
|
float angle = i * Mathf.PI / 10f;
|
|
Vector2 current = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius;
|
|
Line(ScreenGreen, previous, current, .0019f);
|
|
previous = current;
|
|
}
|
|
}
|
|
Line(ScreenGreen, Vector2.zero, new Vector2(.108f, .054f));
|
|
Flat(ScreenChart, .019f, -.067f, .014f, .016f, .03f);
|
|
Flat(ScreenAmber, -.047f, .068f, .01f, .014f, .03f);
|
|
}
|
|
else if (mode == 1)
|
|
{
|
|
for (int i = 0; i < 4; i++)
|
|
Flat(Alloy, (i - 1.5f) * height * .18f, 0, .004f, width * .94f, .025f);
|
|
for (int i = 0; i < 6; i++)
|
|
{
|
|
float z = (i - 2.5f) * width * .12f;
|
|
float stagger = Mathf.Sin(i * 1.59f) * height * .17f;
|
|
Flat(ScreenLand, height * .20f - stagger * .35f, z - width * .17f, height * .23f + stagger, width * .132f, .022f);
|
|
}
|
|
Line(ScreenAmber, new Vector2(-height * .26f, width * .28f), new Vector2(.02f, width * .11f));
|
|
Line(ScreenAmber, new Vector2(.02f, width * .11f), new Vector2(height * .28f, width * .16f));
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < 11; i++)
|
|
{
|
|
float z = (i - 5) * width * .075f;
|
|
float h = height * (.30f + Mathf.Sin(1.27f * i) * .13f);
|
|
Flat(i is 3 or 4 ? ScreenAmber : ScreenChart, -height * .12f + h * .34f, z, h, width * .029f, .024f);
|
|
}
|
|
Flat(ScreenGreen, height * .30f, -width * .25f, .017f, width * .35f, .03f);
|
|
}
|
|
}
|
|
|
|
private static void BridgeChair(Geometry shape, Vector3 at)
|
|
{
|
|
shape.Box(Upholstery, at + new Vector3(.01f, .60f, 0), new Vector3(.44f, .131f, .44f));
|
|
shape.Box(Upholstery, at + new Vector3(-.211f, .91f, 0), new Vector3(.138f, .61f, .42f));
|
|
shape.Box(DeckTrim, at + new Vector3(-.194f, .98f, 0), new Vector3(.025f, .39f, .35f));
|
|
shape.Mesh(Alloy).Rod(at + Vector3.up * .11f, at + Vector3.up * .54f, .083f, 9);
|
|
for (int spoke = 0; spoke < 5; spoke++)
|
|
{
|
|
float angle = spoke * Mathf.PI * .4f;
|
|
Vector3 foot = at + new Vector3(Mathf.Cos(angle) * .274f, .065f, Mathf.Sin(angle) * .274f);
|
|
shape.Mesh(Alloy).Rod(at + Vector3.up * .10f, foot, .031f, 6);
|
|
shape.Mesh(Gasket).Radome(foot - Vector3.up * .022f, .046f);
|
|
}
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
shape.Box(Gasket, at + new Vector3(-.025f, .771f, side * .245f), new Vector3(.34f, .068f, .059f));
|
|
shape.Mesh(Alloy).Rod(at + new Vector3(.096f, .642f, side * .245f), at + new Vector3(.096f, .754f, side * .245f), .023f);
|
|
}
|
|
}
|
|
|
|
private void DrawForedeck(Geometry shape)
|
|
{
|
|
float level = VesselExterior.DeckBase + .04f;
|
|
float from = BridgeFore - 1.44f;
|
|
float nose = length * .498f;
|
|
Vector2[] outline =
|
|
{
|
|
new(from, -beam * .89f), new(length * .37f, -beam * .74f), new(length * .44f, -beam * .46f),
|
|
new(length * .482f, -beam * .18f), new(nose, 0), new(length * .482f, beam * .18f),
|
|
new(length * .44f, beam * .46f), new(length * .37f, beam * .74f), new(from, beam * .89f)
|
|
};
|
|
var center = new Vector2((from + nose) * .5f, 0);
|
|
shape.Mesh(2).Loft(outline, center, true, new Vector3(1, level - .15f, 1), new Vector3(1, level, 1));
|
|
shape.Mesh(Ivory).Loft(outline, center, false, new Vector3(.99f, level - .52f, .98f), new Vector3(1, level -.15f, 1));
|
|
for (int i = 0; i < outline.Length - 1; i++)
|
|
{
|
|
Vector2 a = outline[i], b = outline[i + 1];
|
|
shape.Mesh(Alloy).Rod(HarborMesh.Point(a, level + .77f), HarborMesh.Point(b, level + .77f), .031f);
|
|
shape.Mesh(Alloy).Rod(HarborMesh.Point(a, level + .43f), HarborMesh.Point(b, level + .43f), .022f);
|
|
for (int column = 0; column < 3; column++)
|
|
{
|
|
Vector2 post = Vector2.Lerp(a, b, column / 3f);
|
|
shape.Mesh(Ivory).Rod(HarborMesh.Point(post, level), HarborMesh.Point(post, level + .77f), .027f);
|
|
}
|
|
}
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float z = side * beam * .30f;
|
|
shape.Box(Ivory, new Vector3(nose - length * .10f, level + .12f, z), new Vector3(.50f, .23f, .56f));
|
|
shape.Mesh(Gasket).Rod(new Vector3(nose - length * .10f, level + .19f, z),
|
|
new Vector3(nose - length * .10f, level + .39f, z), .13f, 10);
|
|
}
|
|
}
|
|
|
|
private float BridgeCenter => VesselExterior.BridgeCenter(length, ship.Decks.Count);
|
|
|
|
private static void AddGuest(Layout layout, GuestActivity activity, Vector3 station, int seed, float heading,
|
|
int service, float occupancy, float seatHeight = 0, EntertainmentProgram? program = null, float swimHalfLength = 0) =>
|
|
layout.People.Add(new DeckGuest(activity, station, seed, heading, service, occupancy, seatHeight, program, swimHalfLength));
|
|
|
|
private static void Chair(Geometry shape, Vector3 at, int color, int side)
|
|
{
|
|
shape.Box(color, at + new Vector3(0, .45f, 0), new Vector3(.44f, .089f, .41f));
|
|
shape.Box(color, at + new Vector3(0, .69f, -.185f * side), new Vector3(.43f, .41f, .085f));
|
|
for (int x = -1; x <= 1; x += 2)
|
|
for (int z = -1; z <= 1; z += 2)
|
|
shape.Box(Joinery, at + new Vector3(x * .167f, .208f, z * .158f), new Vector3(.044f, .414f, .044f));
|
|
}
|
|
|
|
private Vector2[] Outline(float size, float width, float offset = 0)
|
|
{
|
|
int steps = 22;
|
|
var points = new Vector2[steps * 2 + 2];
|
|
for (int i = 0; i <= steps; i++)
|
|
{
|
|
float t = i / (float)steps;
|
|
float x = offset + (t - .5f) * length * size;
|
|
float shape = t < .20f ? Mathf.Lerp(.66f, 1, 1f - Mathf.Pow(1f - t / .20f, 2))
|
|
: t > .69f ? Mathf.Sqrt(Mathf.Clamp01(1f - Mathf.Pow((t - .69f) / .31f, 1.72f))) : 1f;
|
|
float z = Mathf.Max(.012f, width * shape);
|
|
points[i] = new Vector2(x, -z);
|
|
points[points.Length - 1 - i] = new Vector2(x, z);
|
|
}
|
|
return points;
|
|
}
|
|
|
|
private Material MaterialFor(int id)
|
|
{
|
|
if (paint.TryGetValue(id, out Material material))
|
|
return material;
|
|
ColorUtility.TryParseHtmlString("#" + Paint[id], out Color color);
|
|
Shader finish = id == WindowGlass ? Resources.Load<Shader>("BridgeGlazing") : shader;
|
|
material = new Material(finish) { color = color, name = "Deck fittings " + Paint[id] };
|
|
if (id != WindowGlass)
|
|
{
|
|
bool metal = id is 4 or Alloy or Gasket or Brass;
|
|
Harbor.SurfaceFinish surfaceFinish = id switch
|
|
{
|
|
0 => Harbor.SurfaceFinish.Hull,
|
|
2 or Joinery => Harbor.SurfaceFinish.Timber,
|
|
Carpet or BridgeFloor or Upholstery or SuiteCarpet or ShowVelvet or LoungeLeather or 11 => Harbor.SurfaceFinish.Fabric,
|
|
Alloy or Brass => Harbor.SurfaceFinish.Alloy,
|
|
PoolWater => Harbor.SurfaceFinish.Pool,
|
|
_ => Harbor.SurfaceFinish.Paint
|
|
};
|
|
material.SetFloat("_Finish", (float)surfaceFinish);
|
|
if (id == 0)
|
|
material.SetFloat("_Waterline", 1);
|
|
material.SetFloat("_Roughness", id == PoolWater ? .16f : metal ? .39f : .76f);
|
|
material.SetFloat("_Metal", metal ? .45f : .04f);
|
|
material.SetFloat("_Weather", id is Carpet or BridgeFloor or Upholstery ? .57f : .12f);
|
|
material.SetFloat("_Emissive", id switch
|
|
{
|
|
LightStrip => .97f,
|
|
ScreenGreen or ScreenAmber or ScreenChart or ScreenRed => .64f,
|
|
12 or 15 or SafetyGreen => .22f,
|
|
Bulkhead or Joinery or Ivory => .22f,
|
|
_ => .08f
|
|
});
|
|
}
|
|
paint.Add(id, material);
|
|
return material;
|
|
}
|
|
|
|
private Mesh Bake(HarborMesh shape)
|
|
{
|
|
Mesh mesh = shape.Bake();
|
|
meshes.Add(mesh);
|
|
return mesh;
|
|
}
|
|
|
|
private static GameObject Piece(string name, Transform parent)
|
|
{
|
|
var result = new GameObject(name) { layer = 8 };
|
|
result.transform.SetParent(parent, false);
|
|
return result;
|
|
}
|
|
|
|
private static void RenderMesh(string name, Transform parent, Mesh mesh, Material material)
|
|
{
|
|
GameObject result = Piece(name, parent);
|
|
result.AddComponent<MeshFilter>().sharedMesh = mesh;
|
|
result.AddComponent<MeshRenderer>().sharedMaterial = material;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
passengerCrowd.Dispose();
|
|
foreach (Mesh mesh in meshes)
|
|
UnityEngine.Object.Destroy(mesh);
|
|
foreach (Material material in paint.Values)
|
|
UnityEngine.Object.Destroy(material);
|
|
}
|
|
|
|
private sealed class Geometry
|
|
{
|
|
private readonly Dictionary<int, HarborMesh> shapes = new();
|
|
private readonly DeckPassengers owner;
|
|
private readonly Transform parent;
|
|
|
|
public Geometry(DeckPassengers owner, Transform parent)
|
|
{
|
|
this.owner = owner;
|
|
this.parent = parent;
|
|
}
|
|
|
|
public HarborMesh Mesh(int color)
|
|
{
|
|
if (!shapes.TryGetValue(color, out HarborMesh shape))
|
|
shapes.Add(color, shape = new HarborMesh());
|
|
return shape;
|
|
}
|
|
|
|
public void Box(int color, Vector3 center, Vector3 size) => Mesh(color).Box(center, size);
|
|
|
|
public void Finish()
|
|
{
|
|
foreach (var (color, shape) in shapes)
|
|
RenderMesh("Deck structure", parent, owner.Bake(shape), owner.MaterialFor(color));
|
|
}
|
|
}
|
|
}
|
|
}
|