Fix port cinematics and expand ship attractions
This commit is contained in:
250
Assets/Soundings/Runtime/SunDeckAttractions.cs
Normal file
250
Assets/Soundings/Runtime/SunDeckAttractions.cs
Normal file
@@ -0,0 +1,250 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Soundings
|
||||
{
|
||||
internal sealed partial class VesselExterior
|
||||
{
|
||||
private void BuildSunAttraction(SunDeckLayout plan, float top)
|
||||
{
|
||||
switch (plan.Attraction)
|
||||
{
|
||||
case SunAttraction.MiniGolf: BuildPuttingGreens(plan, top); break;
|
||||
case SunAttraction.GoKarts: BuildKartCircuit(plan, top); break;
|
||||
case SunAttraction.RollerCoaster: BuildCoaster(plan, top); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildPuttingGreens(SunDeckLayout plan, float top)
|
||||
{
|
||||
Vector2 half = plan.AttractionHalfSize;
|
||||
Coat(Paint.TeakSeam).Box(new Vector3(plan.AttractionCenter, top + .027f, 0), new Vector3(half.x * 1.96f, .06f, half.y * 1.88f));
|
||||
for (int lane = -1; lane <= 1; lane++)
|
||||
{
|
||||
Vector2 center = new(plan.AttractionCenter + lane * half.x * .09f, lane * half.y * .60f);
|
||||
var contour = new Vector2[36];
|
||||
for (int point = 0; point < contour.Length; point++)
|
||||
{
|
||||
float a = point * Mathf.PI * 2 / contour.Length;
|
||||
float x = Mathf.Cos(a);
|
||||
contour[point] = center + new Vector2(x * half.x * .83f,
|
||||
(Mathf.Sin(a) * (.237f + .035f * Mathf.Cos(3 * a + lane)) + .042f * x * lane) * half.y);
|
||||
}
|
||||
Coat(Paint.Fringe).Loft(contour, center, true, new Vector3(1, top + .052f, 1), new Vector3(1, top + .092f, 1));
|
||||
Coat(Paint.Turf).Loft(contour, center, true, new Vector3(.95f, top + .094f, .86f));
|
||||
float end = lane == 0 ? -1 : 1;
|
||||
Vector3 cup = new(center.x + end * half.x * .61f, top + .102f, center.y + .13f * lane);
|
||||
Coat(Paint.Black).Disc(cup, Vector3.right * .106f, Vector3.back * .106f, 14);
|
||||
Coat(Paint.Pearl).Rod(cup, cup + Vector3.up * .58f, .015f, 6);
|
||||
Coat(lane == 0 ? Paint.Lifeboat : Paint.PortLight).Box(cup + new Vector3(.14f, .49f, 0),
|
||||
new Vector3(.28f, .17f, .021f));
|
||||
Coat(Paint.Teak).Box(new Vector3(center.x - end * half.x * .56f, top + .105f, center.y), new Vector3(.56f, .019f, .37f));
|
||||
if (lane != 0)
|
||||
{
|
||||
Vector3 bunker = new(center.x + end * half.x * .10f, top + .105f, center.y - lane * half.y * .075f);
|
||||
Coat(Paint.Ivory).Disc(bunker, Vector3.right * .54f, Vector3.back * .20f, 18);
|
||||
}
|
||||
}
|
||||
|
||||
for (int end = -1; end <= 1; end += 2)
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
Vector3 pot = new(plan.AttractionCenter + end * half.x * .90f, top + .21f, side * half.y * .90f);
|
||||
Coat(Paint.Teak).Box(pot, new Vector3(.58f, .42f, .43f));
|
||||
Coat(Paint.Fringe).Radome(pot + Vector3.up * .27f, .30f);
|
||||
Coat(Paint.Turf).Radome(pot + new Vector3(.14f, .37f, .04f), .22f);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildKartCircuit(SunDeckLayout plan, float top)
|
||||
{
|
||||
float trackWidth = SunRideRoute.KartHalfWidth(plan);
|
||||
for (int i = 0; i < SunRideRoute.Segments; i++)
|
||||
{
|
||||
float first = i / (float)SunRideRoute.Segments, next = (i + 1f) / SunRideRoute.Segments;
|
||||
Vector3 a = SunRideRoute.Point(plan, top, first), b = SunRideRoute.Point(plan, top, next);
|
||||
Vector3 acrossA = SunRideRoute.Across(plan, top, first), acrossB = SunRideRoute.Across(plan, top, next);
|
||||
Ribbon(Paint.Black, a, b, acrossA, acrossB, trackWidth);
|
||||
bool stripe = i % 6 < 2;
|
||||
if (stripe)
|
||||
Ribbon(Paint.Ivory, a + Vector3.up * .008f, b + Vector3.up * .008f, acrossA, acrossB, .026f);
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
Vector3 edgeA = a + acrossA * (trackWidth * side), edgeB = b + acrossB * (trackWidth * side);
|
||||
Coat(i / 2 % 2 == 0 ? Paint.Ivory : Paint.PortLight).Rod(edgeA, edgeB, .072f, 5);
|
||||
if (side > 0)
|
||||
continue;
|
||||
edgeA -= acrossA * .13f;
|
||||
edgeB -= acrossB * .13f;
|
||||
Barrier(edgeA, edgeB, i % 3 == 0);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 start = SunRideRoute.Point(plan, top, .25f);
|
||||
Coat(Paint.Pearl).Box(start + Vector3.up * .014f, new Vector3(.19f, .012f, trackWidth * 2));
|
||||
for (int edge = -1; edge <= 1; edge += 2)
|
||||
{
|
||||
Vector3 pylon = start + Vector3.forward * edge * (trackWidth + .16f);
|
||||
Coat(Paint.Steel).Rod(pylon, pylon + Vector3.up * 1.24f, .043f, 6, true);
|
||||
}
|
||||
Coat(Paint.DeckCanvas).Box(start + Vector3.up * 1.27f, new Vector3(.26f, .22f, trackWidth * 2.32f));
|
||||
}
|
||||
|
||||
private void Barrier(Vector3 a, Vector3 b, bool post)
|
||||
{
|
||||
Coat(Paint.Steel).Rod(a + Vector3.up * .31f, b + Vector3.up * .31f, .027f, 6);
|
||||
if (post)
|
||||
Coat(Paint.Steel).Rod(a, a + Vector3.up * .31f, .026f, 6, true);
|
||||
}
|
||||
|
||||
private void Ribbon(Paint paint, Vector3 a, Vector3 b, Vector3 acrossA, Vector3 acrossB, float halfWidth)
|
||||
{
|
||||
Vector3 sideA = acrossA * halfWidth, sideB = acrossB * halfWidth;
|
||||
Coat(paint).Quad(a - sideA, a + sideA, b + sideB, b - sideB);
|
||||
}
|
||||
|
||||
private void BuildCoaster(SunDeckLayout plan, float top)
|
||||
{
|
||||
const float gauge = .31f;
|
||||
for (int i = 0; i < SunRideRoute.Segments; i++)
|
||||
{
|
||||
float first = i / (float)SunRideRoute.Segments, next = (i + 1f) / SunRideRoute.Segments;
|
||||
Vector3 a = SunRideRoute.Point(plan, top, first), b = SunRideRoute.Point(plan, top, next);
|
||||
Vector3 acrossA = SunRideRoute.Across(plan, top, first), acrossB = SunRideRoute.Across(plan, top, next);
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
Coat(Paint.Lifeboat).Rod(a + acrossA * (gauge * side), b + acrossB * (gauge * side), .057f, 7, true);
|
||||
Coat(Paint.Gold).Rod(a - acrossA * .38f, a + acrossA * .38f, .045f, 6);
|
||||
Coat(Paint.Navy).Rod(a - Vector3.up * .18f, b - Vector3.up * .18f, .047f, 6);
|
||||
if (i % 4 != 0)
|
||||
continue;
|
||||
Vector3 lower = a - Vector3.up * .10f;
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
{
|
||||
Vector3 foot = new(a.x, top + .045f, a.z);
|
||||
foot += acrossA * (side * .46f);
|
||||
Coat(Paint.Pearl).Box(foot, new Vector3(.24f, .098f, .24f));
|
||||
Coat(Paint.Steel).Rod(foot, lower, .063f, 8, true);
|
||||
if (a.y - top > 1.45f)
|
||||
Coat(Paint.Steel).Rod(foot, lower + Vector3.forward * .40f, .039f, 6);
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 station = SunRideRoute.Point(plan, top, .70f) + Vector3.forward * .63f;
|
||||
Coat(Paint.Teak).Box(new Vector3(station.x, top + .28f, station.z), new Vector3(2.92f, .54f, .83f));
|
||||
}
|
||||
}
|
||||
|
||||
internal static class SunRideRoute
|
||||
{
|
||||
internal const int Segments = 56;
|
||||
internal static float KartHalfWidth(VesselExterior.SunDeckLayout plan) => Mathf.Clamp(plan.AttractionHalfSize.y * .18f, .48f, .73f);
|
||||
|
||||
internal static Vector3 Point(VesselExterior.SunDeckLayout plan, float top, float cycle)
|
||||
{
|
||||
float angle = cycle * Mathf.PI * 2f;
|
||||
Vector2 half = plan.AttractionHalfSize;
|
||||
bool coaster = plan.Attraction == SunAttraction.RollerCoaster;
|
||||
float x = Mathf.Cos(angle) * half.x * .82f;
|
||||
float z = Mathf.Sin(angle) * half.y * (coaster ? .68f : .70f);
|
||||
if (!coaster)
|
||||
return new Vector3(plan.AttractionCenter + x, top + .081f, z);
|
||||
|
||||
float rise = Mathf.Clamp(half.x * .28f, 2.3f, 3.55f);
|
||||
float lift = .5f + .5f * Mathf.Sin(angle + .09f);
|
||||
return new Vector3(plan.AttractionCenter + x, top + .62f + rise * lift * lift + .13f * Mathf.Sin(angle * 2), z);
|
||||
}
|
||||
|
||||
internal static Vector3 Tangent(VesselExterior.SunDeckLayout plan, float top, float cycle) =>
|
||||
(Point(plan, top, cycle + .0015f) - Point(plan, top, cycle - .0015f)).normalized;
|
||||
|
||||
internal static Vector3 Across(VesselExterior.SunDeckLayout plan, float top, float cycle) =>
|
||||
Vector3.Cross(Tangent(plan, top, cycle), Vector3.up).normalized;
|
||||
}
|
||||
|
||||
internal sealed partial class DeckPassengers
|
||||
{
|
||||
private readonly Transform[] rideVehicles = new Transform[3];
|
||||
private VesselExterior.SunDeckLayout rideCourse;
|
||||
private float rideCycle, rideDeckHeight;
|
||||
|
||||
private void AddSunAttractionGuests(Layout layout, VesselExterior.SunDeckLayout plan, float height)
|
||||
{
|
||||
if (plan.Attraction == SunAttraction.MiniGolf)
|
||||
{
|
||||
for (int lane = -1; lane <= 1; lane++)
|
||||
{
|
||||
float end = lane == 0 ? -1 : 1;
|
||||
float x = plan.AttractionCenter + lane * plan.AttractionHalfSize.x * .09f - end * plan.AttractionHalfSize.x * .51f;
|
||||
var player = new Vector3(x, height + .085f, (lane * .60f + .115f) * plan.AttractionHalfSize.y);
|
||||
AddGuest(layout, GuestActivity.Talk, player, 347 + lane * 13, end * 90, (int)OnboardService.Amenities, .16f + (lane + 1) * .18f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (plan.Attraction is not (SunAttraction.GoKarts or SunAttraction.RollerCoaster))
|
||||
return;
|
||||
|
||||
rideCourse = plan;
|
||||
rideDeckHeight = height - .015f;
|
||||
bool coaster = plan.Attraction == SunAttraction.RollerCoaster;
|
||||
for (int i = 0; i < rideVehicles.Length; i++)
|
||||
{
|
||||
var car = Piece(coaster ? "Coaster car" : "Go-kart", layout.Room.transform);
|
||||
rideVehicles[i] = car.transform;
|
||||
FitRideVehicle(car.transform, coaster, i);
|
||||
}
|
||||
PositionRideVehicles();
|
||||
|
||||
Vector3 queue = new(plan.AttractionCenter - plan.AttractionHalfSize.x * .67f, height, plan.AttractionHalfSize.y * .94f);
|
||||
for (int i = 0; i < 3; i++)
|
||||
AddGuest(layout, GuestActivity.Talk, queue + Vector3.right * i * .52f, 198 + i * 17, 179,
|
||||
(int)OnboardService.Amenities, .16f + i * .21f);
|
||||
}
|
||||
|
||||
private void FitRideVehicle(Transform parent, bool coaster, int variant)
|
||||
{
|
||||
var shape = new Geometry(this, parent);
|
||||
int body = variant switch { 0 => ScreenRed, 1 => ScreenAmber, _ => ScreenChart };
|
||||
if (coaster)
|
||||
{
|
||||
shape.Box(body, new Vector3(0, .17f, 0), new Vector3(.77f, .28f, .78f));
|
||||
shape.Box(Gasket, new Vector3(0, .36f, -.21f), new Vector3(.61f, .31f, .16f));
|
||||
shape.Box(Alloy, new Vector3(0, .38f, .18f), new Vector3(.61f, .048f, .081f));
|
||||
shape.Box(DeckTrim, new Vector3(0, .08f, .01f), new Vector3(.83f, .088f, .42f));
|
||||
}
|
||||
else
|
||||
{
|
||||
shape.Box(Gasket, new Vector3(0, .135f, 0), new Vector3(.62f, .115f, 1.12f));
|
||||
shape.Box(body, new Vector3(0, .218f, .29f), new Vector3(.46f, .16f, .49f));
|
||||
shape.Box(Gasket, new Vector3(0, .29f, -.17f), new Vector3(.38f, .22f, .14f));
|
||||
shape.Box(Alloy, new Vector3(0, .29f, -.36f), new Vector3(.33f, .12f, .25f));
|
||||
for (int side = -1; side <= 1; side += 2)
|
||||
for (int end = -1; end <= 1; end += 2)
|
||||
{
|
||||
Vector3 axle = new(side * .28f, .119f, end * .34f);
|
||||
shape.Mesh(Gasket).Rod(axle, axle + Vector3.right * side * .14f, .118f, 10, true);
|
||||
}
|
||||
}
|
||||
shape.Finish();
|
||||
}
|
||||
|
||||
private void TickSunAttraction(OnboardSession session, float delta)
|
||||
{
|
||||
if (rideVehicles[0] == null || session.Quote.Weather == WeatherCondition.Storm || session.Get(OnboardService.Amenities).Served == 0)
|
||||
return;
|
||||
float pace = rideCourse.Attraction == SunAttraction.RollerCoaster ? .145f : .112f;
|
||||
rideCycle = Mathf.Repeat(rideCycle + Mathf.Max(0, delta) * pace, 1);
|
||||
PositionRideVehicles();
|
||||
}
|
||||
|
||||
private void PositionRideVehicles()
|
||||
{
|
||||
for (int i = 0; i < rideVehicles.Length; i++)
|
||||
{
|
||||
float spacing = rideCourse.Attraction == SunAttraction.RollerCoaster ? .028f : .31f;
|
||||
float t = rideCycle + .17f - i * spacing;
|
||||
rideVehicles[i].localPosition = SunRideRoute.Point(rideCourse, rideDeckHeight, t) + Vector3.up * .025f;
|
||||
rideVehicles[i].localRotation = Quaternion.LookRotation(SunRideRoute.Tangent(rideCourse, rideDeckHeight, t), Vector3.up);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user