Add class-specific vessel geometry and sea motion, a guided helm qualification path, dockside sailing orders, and local excursions at all 24 ports.
196 lines
9.8 KiB
C#
196 lines
9.8 KiB
C#
using UnityEngine;
|
|
|
|
namespace BigShipTycoon
|
|
{
|
|
internal sealed partial class VesselExterior
|
|
{
|
|
private static float HullWidth(float station, int hull)
|
|
{
|
|
(float sternWidth, float sternEnd, float bowStart, float taper) = hull switch
|
|
{
|
|
Market.Coastal => (.78f, .115f, .74f, .71f),
|
|
Market.Regional => (.46f, .205f, .70f, 1.02f),
|
|
Market.Ocean => (.23f, .23f, .615f, 1.39f),
|
|
_ => (0, 0, 0, 0)
|
|
};
|
|
if (sternEnd == 0)
|
|
return SideWidth(station);
|
|
if (station < sternEnd)
|
|
return Mathf.Lerp(sternWidth, 1, Mathf.Sin(station / sternEnd * Mathf.PI * .5f));
|
|
if (station < bowStart)
|
|
return 1;
|
|
if (station >= 1)
|
|
return 0;
|
|
return Mathf.Pow(Mathf.Max(0, Mathf.Cos((station - bowStart) / (1 - bowStart) * Mathf.PI * .5f)), taper);
|
|
}
|
|
|
|
private void BuildClassHullMarkings(int hull, int samples)
|
|
{
|
|
if (hull == Market.Ocean)
|
|
{
|
|
Vector2[] outline = Outline(length, beam, 0, samples, hullStyle: hull);
|
|
Coat(Paint.OceanRed).Loft(outline, Vector2.zero, false, new Vector3(.995f, .31f, .973f), new Vector3(.997f, .93f, .987f));
|
|
Coat(Paint.Gold).Loft(outline, Vector2.zero, false, new Vector3(1.009f, 3.54f, 1.022f), new Vector3(1.01f, 3.61f, 1.023f));
|
|
return;
|
|
}
|
|
|
|
bool coastal = hull == Market.Coastal;
|
|
HarborMesh paint = Coat(coastal ? Paint.CoastalBlue : Paint.RegionalTeal);
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
for (int section = 1; section < samples - 1; section++)
|
|
{
|
|
float t0 = section / (float)samples, t1 = (section + 1f) / samples;
|
|
var (y0, width0) = Stripe(t0);
|
|
var (y1, width1) = Stripe(t1);
|
|
Vector3 a = HullMark(t0, y0, side, hull);
|
|
Vector3 b = HullMark(t1, y1, side, hull);
|
|
Vector3 c = HullMark(t1, y1 + width1, side, hull);
|
|
Vector3 d = HullMark(t0, y0 + width0, side, hull);
|
|
if (side > 0)
|
|
paint.Quad(a, b, c, d);
|
|
else
|
|
paint.Quad(b, a, d, c);
|
|
}
|
|
}
|
|
|
|
(float Lower, float Width) Stripe(float station)
|
|
{
|
|
float sweep = Mathf.SmoothStep(0, 1, Mathf.InverseLerp(.51f, .96f, station));
|
|
return coastal ? (1.28f + sweep * .27f, .64f)
|
|
: (.62f + 2.99f * sweep, Mathf.Lerp(.70f, .17f, sweep));
|
|
}
|
|
}
|
|
|
|
private Vector3 HullMark(float station, float height, int side, int hull)
|
|
{
|
|
(float x, float z) = height switch
|
|
{
|
|
< 1.22f => (Mathf.Lerp(.991f, .996f, Mathf.InverseLerp(.27f, 1.22f, height)),
|
|
Mathf.Lerp(.969f, .988f, Mathf.InverseLerp(.27f, 1.22f, height))),
|
|
< 2.39f => (Mathf.Lerp(.996f, 1, Mathf.InverseLerp(1.22f, 2.39f, height)),
|
|
Mathf.Lerp(.988f, 1, Mathf.InverseLerp(1.22f, 2.39f, height))),
|
|
_ => (Mathf.Lerp(1, 1.01f, Mathf.InverseLerp(2.39f, 4.65f, height)),
|
|
Mathf.Lerp(1, 1.03f, Mathf.InverseLerp(2.39f, 4.65f, height)))
|
|
};
|
|
return new Vector3((station - .5f) * length * x, height, side * (beam * z * HullWidth(station, hull) + .045f));
|
|
}
|
|
|
|
private void BuildClassDeckGlazing(int deck, float floor, float deckLength, float halfBeam, float offset, int side)
|
|
{
|
|
bool liner = ship.HullIndex == Market.Ocean;
|
|
if (!liner && (ship.HullIndex != Market.Regional || deck < ship.Decks.Count - 3))
|
|
return;
|
|
|
|
float start = liner ? .716f + deck * .0045f : .105f + deck * .004f;
|
|
float end = liner ? .921f : .267f;
|
|
const int panes = 8;
|
|
for (int pane = 0; pane < panes; pane++)
|
|
{
|
|
float a = Mathf.Lerp(start, end, pane / (float)panes);
|
|
float b = Mathf.Lerp(start, end, (pane + 1f) / panes);
|
|
var (lowA, _, normalA) = SideFrame(a, floor + .48f, deckLength * .993f, halfBeam * .957f, offset, side, DeckStations);
|
|
var (lowB, _, normalB) = SideFrame(b, floor + .48f, deckLength * .993f, halfBeam * .957f, offset, side, DeckStations);
|
|
lowA += normalA * .045f;
|
|
lowB += normalB * .045f;
|
|
Vector3 highA = lowA + Vector3.up * 1.76f;
|
|
Vector3 highB = lowB + Vector3.up * 1.76f;
|
|
HarborMesh glass = Coat(liner ? Paint.AtriumGlass : Paint.BlueGlass);
|
|
if (side > 0)
|
|
glass.Quad(lowA, lowB, highB, highA);
|
|
else
|
|
glass.Quad(lowB, lowA, highA, highB);
|
|
Coat(liner ? Paint.Gold : Paint.RegionalTeal).Rod(lowA, lowB, .059f, 6);
|
|
Coat(Paint.Pearl).Rod(lowA, highA, .045f, 5);
|
|
}
|
|
}
|
|
|
|
private void BuildClassFunnel(float top, float stack)
|
|
{
|
|
if (ship.HullIndex == Market.Coastal)
|
|
{
|
|
var foot = new Vector3(stack, top, 0);
|
|
Coat(Paint.Ivory).Box(foot + Vector3.up * .26f, new Vector3(3.70f, .52f, 2.54f));
|
|
Vector3 collar = foot + Vector3.up * 2.06f;
|
|
Vector3 cap = collar + new Vector3(-.18f, .45f, 0);
|
|
FunnelCourse(foot + Vector3.up * .49f, collar, new Vector2(1.03f, .79f), new Vector2(.91f, .74f), Paint.Lifeboat);
|
|
FunnelCourse(collar, cap, new Vector2(1.01f, .82f), new Vector2(.85f, .72f), Paint.Black);
|
|
Coat(Paint.Black).Disc(cap, Vector3.right * .85f, Vector3.back * .72f, 24);
|
|
ExhaustOutlet(cap, .27f);
|
|
return;
|
|
}
|
|
|
|
if (ship.HullIndex == Market.Regional)
|
|
{
|
|
float deckBeam = DeckFootprint(ship.Decks.Count - 1).Beam;
|
|
for (int side = -1; side <= 1; side += 2)
|
|
{
|
|
var foot = new Vector3(stack + side * .41f, top, side * deckBeam * .22f);
|
|
Vector3 collar = foot + new Vector3(-.57f, side < 0 ? 4.28f : 3.54f, side * .09f);
|
|
Vector3 cap = collar + new Vector3(-.22f, .61f, side * .05f);
|
|
FunnelCourse(foot, foot + Vector3.up * .56f, new Vector2(1.26f, .87f), new Vector2(1.13f, .76f), Paint.Ivory);
|
|
FunnelCourse(foot + Vector3.up * .56f, collar, new Vector2(1.13f, .76f), new Vector2(.96f, .65f), Paint.RegionalTeal);
|
|
FunnelCourse(collar, cap, new Vector2(.98f, .67f), new Vector2(.86f, .57f), Paint.Black);
|
|
Coat(Paint.Black).Disc(cap, Vector3.right * .86f, Vector3.back * .57f, 24);
|
|
ExhaustOutlet(cap, .21f);
|
|
}
|
|
return;
|
|
}
|
|
|
|
var basePoint = new Vector3(stack + .11f, top, 0);
|
|
var waist = basePoint + new Vector3(-.33f, .93f, 0);
|
|
var shoulders = basePoint + new Vector3(-.59f, 5.76f, 0);
|
|
var crown = basePoint + new Vector3(-.95f, 6.86f, 0);
|
|
FunnelCourse(basePoint, waist, new Vector2(2.08f, 1.94f), new Vector2(1.90f, 1.84f), Paint.Ivory);
|
|
FunnelCourse(waist, shoulders, new Vector2(1.90f, 1.84f), new Vector2(1.57f, 1.47f), Paint.OceanRed);
|
|
FunnelCourse(shoulders, crown, new Vector2(1.61f, 1.51f), new Vector2(1.28f, 1.31f), Paint.Black);
|
|
Coat(Paint.Black).Disc(crown, Vector3.right * 1.28f, Vector3.back * 1.31f, 24);
|
|
ExhaustOutlet(crown + Vector3.forward * .36f, .27f);
|
|
ExhaustOutlet(crown - Vector3.forward * .36f, .27f);
|
|
}
|
|
|
|
private void FunnelCourse(Vector3 low, Vector3 high, Vector2 bottomRadii, Vector2 topRadii, Paint paint)
|
|
{
|
|
const int segments = 24;
|
|
HarborMesh mesh = Coat(paint);
|
|
Vector3 Point(Vector3 center, Vector2 radii, int index)
|
|
{
|
|
float angle = index * Mathf.PI * 2 / segments;
|
|
return center + new Vector3(Mathf.Cos(angle) * radii.x, 0, Mathf.Sin(angle) * radii.y);
|
|
}
|
|
for (int side = 0; side < segments; side++)
|
|
mesh.Quad(Point(low, bottomRadii, side), Point(high, topRadii, side),
|
|
Point(high, topRadii, side + 1), Point(low, bottomRadii, side + 1));
|
|
}
|
|
|
|
private void ExhaustOutlet(Vector3 cap, float radius)
|
|
{
|
|
Coat(Paint.Steel).Rod(cap, cap + Vector3.up * .24f, radius, 14);
|
|
Coat(Paint.Black).Disc(cap + Vector3.up * .20f, Vector3.right * (radius - .022f), Vector3.back * (radius - .022f), 14);
|
|
}
|
|
|
|
private void BuildLinerBreakwater()
|
|
{
|
|
if (ship.HullIndex != Market.Ocean)
|
|
return;
|
|
|
|
var forward = new[]
|
|
{
|
|
new Vector2(.404f, -.17f), new Vector2(.447f, -.065f), new Vector2(.467f, 0),
|
|
new Vector2(.447f, .065f), new Vector2(.404f, .17f)
|
|
};
|
|
for (int segment = 1; segment < forward.Length; segment++)
|
|
{
|
|
Vector2 a = forward[segment - 1], b = forward[segment];
|
|
Vector3 lowA = new(a.x * length, DeckBase - .06f, a.y * beam);
|
|
Vector3 lowB = new(b.x * length, DeckBase - .06f, b.y * beam);
|
|
Vector3 highA = lowA + Vector3.up * Mathf.Lerp(.29f, 1.43f, Mathf.InverseLerp(.40f, .467f, a.x));
|
|
Vector3 highB = lowB + Vector3.up * Mathf.Lerp(.29f, 1.43f, Mathf.InverseLerp(.40f, .467f, b.x));
|
|
Coat(Paint.Navy).Quad(lowA, lowB, highB, highA);
|
|
Coat(Paint.Navy).Quad(lowB, lowA, highA, highB);
|
|
Coat(Paint.Pearl).Rod(highA, highB, .12f, 7);
|
|
}
|
|
}
|
|
}
|
|
}
|