253 lines
14 KiB
C#
253 lines
14 KiB
C#
using UnityEngine;
|
|
|
|
namespace Soundings
|
|
{
|
|
internal sealed partial class DeckPassengers
|
|
{
|
|
private readonly struct DeckGrid
|
|
{
|
|
public readonly int Columns, Rows;
|
|
public readonly float Start, CellWidth, RowDepth, HalfWidth;
|
|
|
|
public DeckGrid(int columns, int rows, float start, float cellWidth, float rowDepth, float halfWidth)
|
|
{
|
|
Columns = columns;
|
|
Rows = rows;
|
|
Start = start;
|
|
CellWidth = cellWidth;
|
|
RowDepth = rowDepth;
|
|
HalfWidth = halfWidth;
|
|
}
|
|
|
|
public int Slot(int col, int row) => row * Columns + col;
|
|
public float Edge(int col) => Start + col * CellWidth;
|
|
public float Center(int col) => Edge(col) + CellWidth * .5f;
|
|
public float Row(int row) => -HalfWidth + (row + .5f) * RowDepth + row * AisleWidth;
|
|
public float Aisle(int row) => Row(row) + (RowDepth + AisleWidth) * .5f;
|
|
}
|
|
|
|
private void BuildDeckPlan(int index, Layout layout, Geometry structure, Geometry interior, Geometry cutaway,
|
|
DeckGrid grid, float aft, float fore, float floor)
|
|
{
|
|
Deck plan = ship.Decks[index];
|
|
var owners = new int[plan.Cells.Length];
|
|
for (int slot = 0; slot < owners.Length; slot++)
|
|
owners[slot] = plan.AnchorAt(slot, grid.Columns);
|
|
|
|
int Owner(int col, int row) => owners[grid.Slot(col, row)];
|
|
bool Linked(int col, int aisle) => col >= 0 && col < grid.Columns
|
|
&& aisle >= 0 && aisle < grid.Rows - 1 && Owner(col, aisle) == Owner(col, aisle + 1);
|
|
|
|
// Furnish only the anchor. The plan below supplies the floor and bulkheads for its whole footprint.
|
|
for (int anchor = 0; anchor < owners.Length; anchor++)
|
|
{
|
|
if (owners[anchor] != anchor)
|
|
continue;
|
|
Facility facility = plan.Cells[anchor];
|
|
var footprint = Market.Facilities[(int)facility].Footprint(plan.RotationAt(anchor));
|
|
int row = anchor / grid.Columns, column = anchor % grid.Columns;
|
|
if (footprint.Count == 1 && facility != Facility.Shop)
|
|
{
|
|
Vector3 center = new(grid.Center(column), floor + .055f, grid.Row(row));
|
|
Room(structure, layout, facility, center, grid.CellWidth - .19f, grid.RowDepth - .18f,
|
|
index * 70 + anchor, row == 0 ? -1 : 1, index == programDeck && anchor == programRoom);
|
|
continue;
|
|
}
|
|
|
|
foreach (Vector2Int bay in footprint)
|
|
structure.Box(FacilityFloor(facility), new Vector3(grid.Center(column + bay.x), floor + .037f, grid.Row(row + bay.y)),
|
|
new Vector3(grid.CellWidth, .045f, grid.RowDepth));
|
|
FurnishFootprint(index, anchor, plan.RotationAt(anchor), footprint, facility, layout, structure, grid, floor);
|
|
}
|
|
|
|
for (int row = 0; row < grid.Rows; row++)
|
|
{
|
|
float z = grid.Row(row);
|
|
for (int col = 0; col <= grid.Columns; col++)
|
|
{
|
|
if (col == 0 || col == grid.Columns || Owner(col - 1, row) != Owner(col, row))
|
|
SolidDeckWall(layout, interior, cutaway, new Vector3(grid.Edge(col), floor, z), .15f, grid.RowDepth);
|
|
}
|
|
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
float wallZ = z + side * grid.RowDepth * .5f;
|
|
if (side < 0 && row == 0 || side > 0 && row == grid.Rows - 1)
|
|
{
|
|
for (int col = 0; col < grid.Columns; col++)
|
|
RoomWindow(interior, cutaway, grid.Center(col), floor, wallZ, grid.CellWidth, side,
|
|
IsGlazed(plan.Cells[Owner(col, row)]));
|
|
continue;
|
|
}
|
|
|
|
int aisle = side < 0 ? row - 1 : row;
|
|
for (int start = 0; start < grid.Columns;)
|
|
{
|
|
int owner = Owner(start, row);
|
|
int end = start + 1;
|
|
bool joined = Linked(start, aisle);
|
|
while (end < grid.Columns && Owner(end, row) == owner && Linked(end, aisle) == joined)
|
|
end++;
|
|
if (!joined)
|
|
{
|
|
Facility facility = plan.Cells[owner];
|
|
float width = (end - start) * grid.CellWidth;
|
|
float door = facility switch
|
|
{
|
|
Facility.Empty => 2.4f,
|
|
Facility.Cabin => 1.18f,
|
|
Facility.Suite or Facility.GrandSuite => 1.56f,
|
|
_ => end - start > 1 ? 2.20f : 1.48f
|
|
};
|
|
RoomEntrance(layout, interior, cutaway, (grid.Edge(start) + grid.Edge(end)) * .5f, floor,
|
|
wallZ, width, Mathf.Min(door, width - .42f), side, index, owner, facility);
|
|
}
|
|
start = end;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int aisle = 0; aisle < grid.Rows - 1; aisle++)
|
|
{
|
|
float z = grid.Aisle(aisle);
|
|
float publicStart = aft;
|
|
for (int col = 0; col <= grid.Columns; col++)
|
|
{
|
|
bool openLeft = Linked(col - 1, aisle), openRight = Linked(col, aisle);
|
|
if (openLeft != openRight || openLeft && Owner(col - 1, aisle) != Owner(col, aisle))
|
|
CrossAisleBoundary(layout, interior, cutaway, grid.Edge(col), floor, z,
|
|
openLeft ? plan.Cells[Owner(col - 1, aisle)] : Facility.Empty,
|
|
openRight ? plan.Cells[Owner(col, aisle)] : Facility.Empty);
|
|
if (!openLeft && openRight)
|
|
PublicAisle(index, aisle, publicStart, grid.Edge(col), floor, z, grid.CellWidth, layout, structure, interior);
|
|
if (openLeft && !openRight)
|
|
publicStart = grid.Edge(col);
|
|
if (openRight)
|
|
structure.Box(FacilityFloor(plan.Cells[Owner(col, aisle)]), new Vector3(grid.Center(col), floor + .037f, z),
|
|
new Vector3(grid.CellWidth, .045f, AisleWidth));
|
|
}
|
|
PublicAisle(index, aisle, publicStart, fore, floor, z, grid.CellWidth, layout, structure, interior);
|
|
}
|
|
}
|
|
|
|
private void FurnishFootprint(int index, int anchor, int rotation, System.Collections.Generic.IReadOnlyList<Vector2Int> footprint,
|
|
Facility facility, Layout layout, Geometry structure, DeckGrid grid, float floor)
|
|
{
|
|
int col = anchor % grid.Columns, row = anchor / grid.Columns;
|
|
Vector2Int min = footprint[0], max = min;
|
|
foreach (Vector2Int offset in footprint)
|
|
{
|
|
min = Vector2Int.Min(min, offset);
|
|
max = Vector2Int.Max(max, offset);
|
|
}
|
|
int seed = index * 70 + anchor;
|
|
if (facility == Facility.ShoppingArcade)
|
|
{
|
|
FitRetailArcade(structure, layout, grid, footprint, col, row, floor, rotation, seed);
|
|
return;
|
|
}
|
|
|
|
Vector3 center = new((grid.Center(col + min.x) + grid.Center(col + max.x)) * .5f, floor + .06f,
|
|
(grid.Row(row + min.y) + grid.Row(row + max.y)) * .5f);
|
|
float width = (max.x - min.x + 1) * grid.CellWidth - .19f;
|
|
float depth = (max.y - min.y + 1) * grid.RowDepth + (max.y - min.y) * AisleWidth - .18f;
|
|
if ((rotation & 1) != 0)
|
|
(width, depth) = (depth, width);
|
|
var room = new Venue(structure, layout, center, row == 0 ? -1 : 1, seed, rotation);
|
|
if (facility is Facility.Shop or Facility.Spa or Facility.WaterPark)
|
|
FitNewVenue(room, facility, width, depth);
|
|
else
|
|
{
|
|
StationKind? station = FacilityStation(facility);
|
|
if (station.HasValue)
|
|
room.Station(station.Value, 0, -depth * .33f);
|
|
FitVenue(room, facility, width, depth, index == programDeck && anchor == programRoom);
|
|
}
|
|
}
|
|
|
|
private static void CrossAisleBoundary(Layout layout, Geometry interior, Geometry cutaway, float x, float floor, float z,
|
|
Facility left, Facility right)
|
|
{
|
|
const float opening = 1.28f;
|
|
float panel = (AisleWidth - opening) * .5f;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
SolidDeckWall(layout, interior, cutaway, new Vector3(x, floor, z + side * (opening + panel) * .5f), .14f, panel);
|
|
interior.Box(Joinery, new Vector3(x, floor + 1.02f, z + side * opening * .5f), new Vector3(.165f, 2.04f, .05f));
|
|
}
|
|
interior.Box(Joinery, new Vector3(x, floor + 2.07f, z), new Vector3(.17f, .08f, opening));
|
|
interior.Box(Bulkhead, new Vector3(x, floor + 2.25f, z), new Vector3(.14f, .36f, opening));
|
|
interior.Box(Alloy, new Vector3(x, floor + .058f, z), new Vector3(.22f, .020f, opening));
|
|
if (left != Facility.Empty)
|
|
DirectionSign(left, 1);
|
|
if (right != Facility.Empty)
|
|
DirectionSign(right, -1);
|
|
|
|
void DirectionSign(Facility facility, int side)
|
|
{
|
|
interior.Box(DeckTrim, new Vector3(x + side * .09f, floor + 2.21f, z), new Vector3(.035f, .132f, .97f));
|
|
PlaceSign(layout.Interior.transform, Market.Facilities[(int)facility].Name.ToUpperInvariant(),
|
|
new Vector3(x + side * .112f, floor + 2.21f, z), -side * 90, .047f);
|
|
}
|
|
}
|
|
|
|
private static void PublicAisle(int index, int aisle, float start, float end, float floor, float z, float bay,
|
|
Layout layout, Geometry structure, Geometry interior)
|
|
{
|
|
float length = end - start;
|
|
float mid = (end + start) * .5f;
|
|
structure.Box(PromenadeRunner, new Vector3(mid, floor + .037f, z), new Vector3(length, .018f, AisleWidth - .21f));
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
structure.Box(Joinery, new Vector3(mid, floor + .049f, z + side * .615f), new Vector3(length, .008f, .025f));
|
|
structure.Box(DeckTrim, new Vector3(mid, floor + .049f, z + side * .702f), new Vector3(length, .008f, .075f));
|
|
interior.Box(DeckTrim, new Vector3(mid, floor + DeckCeiling - .083f, z + side * .60f), new Vector3(length, .12f, .028f));
|
|
}
|
|
int lights = Mathf.Max(1, Mathf.RoundToInt(length / bay));
|
|
for (int i = 0; i < lights; i++)
|
|
{
|
|
float x = Mathf.Lerp(start, end, (i + .5f) / lights);
|
|
interior.Box(Gasket, new Vector3(x, floor + DeckCeiling - .009f, z), new Vector3(Mathf.Min(2.22f, length), .045f, .43f));
|
|
interior.Box(LightStrip, new Vector3(x, floor + DeckCeiling - .031f, z), new Vector3(Mathf.Min(2.04f, length), .018f, .28f));
|
|
structure.Box(Joinery, new Vector3(x, floor + .048f, z), new Vector3(.035f, .009f, 1.23f));
|
|
}
|
|
if (length < 5f)
|
|
return;
|
|
int walkers = Mathf.Max(1, lights / 2);
|
|
for (int i = 0; i < walkers; i++)
|
|
{
|
|
var route = new Vector3(start + 1.35f, floor + .055f, z);
|
|
layout.People.Add(new DeckGuest(route, end - 1.2f, .37f, (i + .29f * aisle) / walkers,
|
|
index * 53 + aisle * 17 + i * 11, .19f + i * .14f));
|
|
}
|
|
}
|
|
|
|
private static bool IsGlazed(Facility facility) => facility is Facility.Cabin or Facility.Dining or Facility.Bar or Facility.Amenity
|
|
or Facility.Suite or Facility.GrandSuite or Facility.Restaurant or Facility.ResortPool or Facility.CocktailLounge
|
|
or Facility.Shop or Facility.ShoppingArcade or Facility.Spa or Facility.WaterPark;
|
|
|
|
private static int FacilityFloor(Facility facility) => facility switch
|
|
{
|
|
Facility.Cabin => Carpet, Facility.Dining or Facility.Restaurant => Joinery,
|
|
Facility.Entertainment or Facility.GrandTheater => 11, Facility.Bar or Facility.CocktailLounge => 7,
|
|
Facility.Suite or Facility.GrandSuite => SuiteCarpet, Facility.ResortPool or Facility.Spa or Facility.WaterPark => PoolDeck,
|
|
Facility.Shop or Facility.ShoppingArcade => Marble,
|
|
Facility.Amenity => PoolDeck, Facility.Galley or Facility.Workshop => BridgeFloor, _ => DeckTrim
|
|
};
|
|
|
|
private static StationKind? FacilityStation(Facility facility) => facility switch
|
|
{
|
|
Facility.Cabin or Facility.Suite or Facility.GrandSuite => StationKind.Cabins,
|
|
Facility.Dining or Facility.Restaurant => StationKind.Dining,
|
|
Facility.Bar or Facility.CocktailLounge => StationKind.Bar,
|
|
Facility.Entertainment or Facility.GrandTheater => StationKind.Stage,
|
|
Facility.Amenity or Facility.ResortPool or Facility.Spa or Facility.WaterPark => StationKind.Pool,
|
|
Facility.Galley => StationKind.Galley, Facility.Stores => StationKind.Stores,
|
|
Facility.Water => StationKind.Water, Facility.Waste => StationKind.Waste,
|
|
Facility.Workshop => StationKind.Maintenance,
|
|
Facility.Shop or Facility.ShoppingArcade => StationKind.Retail,
|
|
_ => null
|
|
};
|
|
}
|
|
}
|