Make voyages active with dockside orders, crew calls, and ship PA

This commit is contained in:
josh
2026-11-27 23:14:38 -05:00
parent 7951e1c878
commit cc7620c431
71 changed files with 2723 additions and 233 deletions

View File

@@ -27,6 +27,7 @@ namespace Soundings
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;
@@ -34,7 +35,7 @@ namespace Soundings
private Layout bridge;
private Transform helmWheel;
private float rudderDegrees;
private Mesh clothes, head;
private readonly PassengerCrowd passengerCrowd = new();
private int activeIndex = -1;
private bool bridgeView;
private float animationTime;
@@ -43,7 +44,9 @@ namespace Soundings
{
public readonly GameObject Room, Crowd, Interior, Cutaway;
public readonly ShipWalkSpace WalkSpace;
public readonly List<Passenger> People = new();
public readonly List<DeckGuest> People = new();
public readonly List<ShipStation> Stations = new();
public Mesh CrowdMesh;
public Layout(string name, Transform parent, ShipWalkSpace walkSpace = null)
{
@@ -58,15 +61,6 @@ namespace Soundings
}
}
private sealed class Passenger
{
public Transform Body;
public Vector3 Position;
public int Slot, Service;
public float Yaw, Phase, Travel;
public bool Seated;
}
public DeckPassengers(Transform parent, Ship ship, float length, float beam, Shader surface)
{
shipRoot = parent;
@@ -75,7 +69,16 @@ namespace Soundings
this.beam = beam;
shader = surface;
decks = new Layout[ship.Decks.Count];
BuildPeopleMeshes();
Facility programVenue = ship.Entertainment > 0 ? Facility.Entertainment : 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);
}
@@ -107,6 +110,8 @@ namespace Soundings
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)
{
@@ -177,55 +182,50 @@ namespace Soundings
public void Tick(OnboardSession session, float delta)
{
if (bridgeView || session == null)
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);
int guests = Math.Max(1, session.Quote.Guests);
foreach (Passenger person in layout.People)
{
float proportion = person.Service < 0 ? Mathf.Clamp01(guests / 100f)
: Mathf.Clamp01(session.Get((OnboardService)person.Service).Served / (float)guests);
bool appears = guests >= 10 && (person.Slot == 0 ? proportion > 0 : (person.Slot == 1 ? proportion > .2f : proportion > .48f));
if (person.Body.gameObject.activeSelf != appears)
person.Body.gameObject.SetActive(appears);
if (!appears)
continue;
float time = animationTime + person.Phase;
Vector3 point = person.Position;
if (person.Travel > 0)
{
float drift = Mathf.Sin(time * .65f);
point.x += drift * person.Travel;
point.y += Mathf.Abs(Mathf.Sin(time * 8)) * .105f;
person.Body.localRotation = Quaternion.Euler(0, Mathf.Cos(time * .65f) >= 0 ? 90 : -90, 0);
}
else
{
point.y += Mathf.Sin(time * 2.9f) * .035f;
person.Body.localRotation = Quaternion.Euler(person.Seated ? 7f : 0, person.Yaw + Mathf.Sin(time * 2.1f) * 6f, 0);
}
person.Body.localPosition = point;
}
layout.CrowdMesh ??= passengerCrowd.CreateMesh(layout.Crowd, length, beam);
passengerCrowd.Draw(layout.CrowdMesh, layout.People, session, activeIndex < 0, animationTime, delta);
}
private Layout BuildPromenade()
{
var layout = new Layout("Open promenade", shipRoot);
float y = BridgeHeight + .04f;
float width = beam * (.82f - (ship.Decks.Count - 1) * .044f);
for (int i = 0; i < 16; i++)
int deck = ship.Decks.Count - 1;
float y = BridgeHeight + .015f;
float deckLength = VesselExterior.DeckLength(length, deck);
float width = VesselExterior.DeckHalfBeam(beam, deck);
float offset = VesselExterior.DeckOffset(length, deck);
float aft = offset - deckLength * .305f;
float fore = Mathf.Min(BridgeCenter - 6.0f, offset + deckLength * .17f);
int walkers = 7 + ship.HullIndex * 3;
for (int side = -1; side <= 1; side += 2)
{
float z = (i % 2 == 0 ? -1 : 1) * width * .76f;
float x = length * Mathf.Lerp(-.32f, .23f, i / 15f);
AddPerson(layout, new Vector3(x, y, z), -1, i % 3, i, i % 5 == 0 ? 0 : 1.2f, false);
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 * .865f);
layout.People.Add(new DeckGuest(route, fore, width * .075f, (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);
}
AddPerson(layout, new Vector3(-1.5f, y, -2.0f), (int)OnboardService.Amenities, 0, 16, 0, false, 0);
AddPerson(layout, new Vector3(3.0f, y, 1.95f), (int)OnboardService.Drinks, 1, 17, 0, false, 180);
float pool = offset + deckLength * .01f;
AddGuest(layout, GuestActivity.Talk, new Vector3(pool - 3.40f, y, -1.14f), 37, 0, (int)OnboardService.Amenities, .20f);
AddGuest(layout, GuestActivity.Talk, new Vector3(pool - 3.62f, y, -.20f), 214, 167, (int)OnboardService.Amenities, .44f);
AddGuest(layout, GuestActivity.Rest, new Vector3(pool + 1.77f, y, width * .67f + .07f), 35, 180, (int)OnboardService.Amenities, .23f, .26f);
AddGuest(layout, GuestActivity.Photograph, new Vector3(pool + .9f, y, -2.32f), 62, 180, (int)OnboardService.Amenities, .64f);
return layout;
}
@@ -330,14 +330,23 @@ namespace Soundings
if (row < rows - 1)
RoomEntrance(layout, interior, cutaway, x, y, center.z + halfRow, cellWidth, door, 1, index, slot, facility);
Room(structure, layout, facility, center, cellWidth - .19f, rowDepth - .18f, index * 70 + slot,
row == 0 ? -1 : 1);
row == 0 ? -1 : 1, index == programDeck && slot == programRoom);
if (row == 0 || row == rows - 1)
RoomWindow(interior, cutaway, x, y, halfWidth * (row == 0 ? -1 : 1), cellWidth, row == 0 ? -1 : 1,
facility is Facility.Cabin or Facility.Dining or Facility.Bar or Facility.Amenity);
}
}
AddPerson(layout, new Vector3(aft + usableLength * .23f, y + .055f, AisleCenter(0)), -1, 0, index * 6, 1.6f, false);
AddPerson(layout, new Vector3(aft + usableLength * .72f, y + .055f, AisleCenter(rows - 2)), -1, 1, index * 6 + 1, 1.5f, false);
for (int aisle = 0; aisle < rows - 1; aisle++)
{
int walkers = columns / 2;
for (int walker = 0; walker < walkers; walker++)
{
float start = (walker + .29f * aisle) / walkers;
var route = new Vector3(aft + 1.35f, y + .055f, AisleCenter(aisle));
layout.People.Add(new DeckGuest(route, fore - 1.2f, .37f, start,
index * 53 + aisle * 17 + walker * 11, .19f + walker * .14f));
}
}
structure.Finish();
interior.Finish();
cutaway.Finish();
@@ -425,7 +434,8 @@ namespace Soundings
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)
private void Room(Geometry shape, Layout layout, Facility facility, Vector3 pos, float width, float depth,
int seed, int facing, bool programVenue)
{
int floor = facility switch
{
@@ -439,18 +449,41 @@ namespace Soundings
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)
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);
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;
int service = -1;
StationKind? station = facility switch
{
Facility.Cabin => StationKind.Cabins,
Facility.Dining => StationKind.Dining,
Facility.Bar => StationKind.Bar,
Facility.Entertainment => StationKind.Stage,
Facility.Amenity => StationKind.Pool,
Facility.Galley => StationKind.Galley,
Facility.Stores => StationKind.Stores,
Facility.Water => StationKind.Water,
Facility.Waste => StationKind.Waste,
Facility.Workshop => StationKind.Maintenance,
_ => null
};
if (station.HasValue)
layout.Stations.Add(new ShipStation(station.Value, pos + new Vector3(0, 1.45f, -.33f * depth * facing)));
switch (facility)
{
case Facility.Cabin:
@@ -471,7 +504,8 @@ namespace Soundings
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);
service = (int)OnboardService.Rooms;
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)
@@ -488,9 +522,13 @@ namespace Soundings
Box(LightStrip, x + .22f, .85f, place + .05f, .065f, .080f, .065f);
}
Seat(x, -.58f, Upholstery);
Seat(x, .81f, Upholstery);
Seat(x, .81f, Upholstery, -1);
Guest(GuestActivity.Dine, x, -.61f, side + 1, OnboardService.Meals, side < 0 ? .21f : .56f, .54f);
Guest(GuestActivity.Dine, x, .84f, side + 4, OnboardService.Meals, side < 0 ? .75f : .93f, .54f, -1);
}
service = (int)OnboardService.Meals;
if (programVenue)
Guest(GuestActivity.Guitar, 0, .32f, 32, OnboardService.Shows, .22f, direction: -1,
program: EntertainmentProgram.LiveMusic);
break;
case Facility.Bar:
Solid(Joinery, 0, .48f, depth * .18f, width * .77f, .94f, .81f);
@@ -503,9 +541,16 @@ namespace Soundings
Box(i % 2 == 0 ? SafetyGreen : 13, x + .12f, 1.117f, depth * .19f, .07f, .18f, .071f);
Box(Alloy, x + .12f, 1.224f, depth * .19f, .055f, .06f, .044f);
if (i != 0)
Seat(x, depth * .18f - .91f, 6);
{
float stool = depth * .18f - .97f;
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, .30f, .035f, .23f);
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 ? .35f : .73f, .80f);
}
}
service = (int)OnboardService.Drinks;
break;
case Facility.Entertainment:
Solid(Gasket, 0, .19f, depth * .307f, width * .82f, .38f, .99f);
@@ -516,9 +561,23 @@ namespace Soundings
for (int row = -1; row <= 0; row++)
for (int i = -2; i <= 2; i++)
if (i != 0)
Seat(i * width * .139f, -.37f + row * .62f, 10);
AddPerson(layout, pos + new Vector3(0, .425f, depth * .31f * facing), (int)OnboardService.Shows, 0, seed + 41, 0, false, 180);
service = (int)OnboardService.Shows;
{
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, .54f);
}
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:
Solid(Ivory, 0, .18f, depth * .18f, width * .65f, .33f, depth * .44f);
@@ -529,8 +588,9 @@ namespace Soundings
{
Solid(Joinery, side * width * .308f, .25f, -depth * .25f, 1.41f, .34f, .53f);
Box(Ivory, side * width * .308f, .451f, -depth * .25f, 1.35f, .105f, .49f);
Guest(side > 0 ? GuestActivity.Read : GuestActivity.Rest, side * width * .308f, -depth * .25f,
side + 3, OnboardService.Amenities, side < 0 ? .30f : .75f, .60f);
}
service = (int)OnboardService.Amenities;
break;
case Facility.Tank:
var start = pos + new Vector3(-width * .32f, .61f, 0);
@@ -578,15 +638,6 @@ namespace Soundings
break;
}
if (service < 0)
return;
bool seats = facility is Facility.Dining or Facility.Bar or Facility.Entertainment or Facility.Amenity;
float sittingZ = facility == Facility.Bar ? -depth * .10f : -depth * .26f;
for (int i = 0; i < (seats ? 3 : 2); i++)
{
float x = (i - (seats ? 1f : .5f)) * width * .23f;
AddPerson(layout, pos + new Vector3(x, seats ? .23f : .03f, sittingZ * facing), service, i, seed + i, 0, seats);
}
}
private Layout BuildBridge()
@@ -671,6 +722,7 @@ namespace Soundings
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));
@@ -846,31 +898,9 @@ namespace Soundings
private float BridgeCenter => VesselExterior.BridgeCenter(length, ship.Decks.Count);
private void BuildPeopleMeshes()
{
var body = new HarborMesh();
body.Rod(new Vector3(0, .54f, 0), new Vector3(0, 1.15f, 0), .20f, 7);
body.Rod(new Vector3(-.094f, .05f, .025f), new Vector3(-.090f, .57f, 0), .074f, 6);
body.Rod(new Vector3(.094f, .045f, -.035f), new Vector3(.090f, .57f, 0), .074f, 6);
body.Rod(new Vector3(-.28f, .71f, .07f), new Vector3(-.16f, 1.08f, 0), .066f, 6);
body.Rod(new Vector3(.28f, .76f, .13f), new Vector3(.16f, 1.08f, 0), .066f, 6);
var face = new HarborMesh();
face.Radome(new Vector3(0, 1.29f, .025f), .151f);
clothes = Bake(body);
head = Bake(face);
}
private void AddPerson(Layout layout, Vector3 position, int service, int slot, int seed, float travel, bool seated, float yaw = 0)
{
GameObject person = Piece(service < 0 ? "Walking passenger" : OnboardSession.ServiceLabel((OnboardService)service), layout.Crowd.transform);
person.transform.localPosition = position;
person.transform.localScale = new Vector3(1, seated ? .74f : 1, 1) * (1f + seed % 3 * .045f);
RenderMesh("Outfit", person.transform, clothes, MaterialFor(19 + seed % 6));
RenderMesh("Head", person.transform, head, MaterialFor(16 + seed % 3));
layout.People.Add(new Passenger { Body = person.transform, Position = position, Phase = seed * 1.37f, Slot = slot,
Service = service, Travel = travel, Yaw = yaw, Seated = seated });
person.SetActive(false);
}
private static void AddGuest(Layout layout, GuestActivity activity, Vector3 station, int seed, float heading,
int service, float occupancy, float seatHeight = 0, EntertainmentProgram? program = null) =>
layout.People.Add(new DeckGuest(activity, station, seed, heading, service, occupancy, seatHeight, program));
private static void Chair(Geometry shape, Vector3 at, int color, int side)
{
@@ -947,6 +977,7 @@ namespace Soundings
public void Dispose()
{
passengerCrowd.Dispose();
foreach (Mesh mesh in meshes)
UnityEngine.Object.Destroy(mesh);
foreach (Material material in paint.Values)