Add riverboat captain career and distinct ship classes

Add class-specific vessel geometry and sea motion, a guided helm qualification path, dockside sailing orders, and local excursions at all 24 ports.
This commit is contained in:
josh
2026-11-29 20:41:00 -05:00
parent 46624bf5ba
commit 290e4cb45d
67 changed files with 1783 additions and 301 deletions

View File

@@ -25,7 +25,7 @@ namespace BigShipTycoon
private float yaw = DefaultYaw, pitch = DefaultPitch, zoom = 1f;
private float targetYaw = DefaultYaw, targetPitch = DefaultPitch, targetZoom = 1f;
private Vector3 orbitOffset, targetOrbitOffset;
private float seaTime, seaSeverity, passageDistance;
private float seaTime, seaSeverity, passageDistance, passageHeading;
private Vector3 hullMotion, hullMotionVelocity;
private bool sailing;
private Bounds hullBounds;
@@ -46,6 +46,8 @@ namespace BigShipTycoon
public RenderTexture Frame { get; private set; }
internal Vector3 PassageWorldPosition => vessel != null ? vessel.position : Vector3.zero;
internal Vector3 PassageSeaMotion => hullMotion;
internal float HorizonRoll => Mathf.Asin(Mathf.Clamp(viewCamera.transform.right.y, -1, 1)) * Mathf.Rad2Deg;
internal bool PassageUsesPerspective => sailing && cameraMode == CameraMode.Orbit && !viewCamera.orthographic;
internal Vector3 FirstPersonPosition => freePosition;
internal bool FirstPersonPositionIsClear => walkSpace != null && walkSpace.CanStand(freePosition);
@@ -346,12 +348,15 @@ namespace BigShipTycoon
sailing = true;
seaSeverity = (int)weather / 2f;
seaTime = 0;
float nominalKnots = 17f + 2f * (displayedShip?.HullIndex ?? 0);
bool river = displayedShip?.HullIndex == Market.River;
float nominalKnots = river ? 10f : 17f + 2f * (displayedShip?.HullIndex ?? 0);
float weatherSlowdown = weather == WeatherCondition.Storm ? 1.32f : weather == WeatherCondition.Swell ? 1.14f : 1f;
passageDistance = nominalKnots * .514444f * duration / weatherSlowdown;
hullMotion = hullMotionVelocity = Vector3.zero;
passageHeading = 0;
water.SetFloat("_WeatherSeverity", seaSeverity);
Shader.SetGlobalFloat("_TycoonSeaWeather", seaSeverity);
Shader.SetGlobalFloat("_TycoonRiverWater", river ? 1f : 0f);
Shader.SetGlobalFloat("_TycoonSeaSailing", 1);
wake.Reset();
SetPassage(Vector2.zero, 0, 0, 0);
@@ -365,48 +370,76 @@ namespace BigShipTycoon
float sine = Mathf.Sin(headingRadians);
float cosine = Mathf.Cos(headingRadians);
var center = new Vector2(routePosition.x, -routePosition.y) * passageDistance;
bool river = displayedShip?.HullIndex == Market.River;
if (vessel != null && delta > 0)
{
// Use wave heights along the waterline to drive a damped heave, pitch and roll.
Vector2 bow = new Vector2(cosine, -sine) * (vesselLength * .36f);
Vector2 port = new Vector2(sine, cosine) * (vesselBeam * .86f);
float fore = WaveHeight(center + bow), aft = WaveHeight(center - bow);
float left = WaveHeight(center + port), right = WaveHeight(center - port);
var target = new Vector3((fore + aft + left + right) * .25f,
Mathf.Atan2(right - left, 2 * port.magnitude) * Mathf.Rad2Deg,
Mathf.Atan2(fore - aft, 2 * bow.magnitude) * Mathf.Rad2Deg);
float response = .48f + vesselLength * .005f;
hullMotion = Vector3.SmoothDamp(hullMotion, target, ref hullMotionVelocity, response, Mathf.Infinity, delta);
Vector3 target = SampleSeaResponse(center, seaTime, heading, vesselLength, vesselBeam, seaSeverity, river);
float mass = Mathf.InverseLerp(28f, 300f, vesselLength);
float turnRate = Mathf.Clamp(Mathf.DeltaAngle(passageHeading, heading) / delta, -18f, 18f);
target.y += turnRate * Mathf.Clamp01(speed / (river ? 10f : 19f)) * Mathf.Lerp(.105f, .05f, mass);
hullMotion.x = Mathf.SmoothDamp(hullMotion.x, target.x, ref hullMotionVelocity.x,
Mathf.Lerp(.30f, .77f, mass), Mathf.Infinity, delta);
hullMotion.y = Mathf.SmoothDamp(hullMotion.y, target.y, ref hullMotionVelocity.y,
Mathf.Lerp(.32f, 1.03f, mass), Mathf.Infinity, delta);
hullMotion.z = Mathf.SmoothDamp(hullMotion.z, target.z, ref hullMotionVelocity.z,
Mathf.Lerp(.38f, 1.12f, mass), Mathf.Infinity, delta);
}
passageHeading = heading;
if (vessel != null)
vessel.SetLocalPositionAndRotation(new Vector3(center.x, hullMotion.x, center.y),
Quaternion.Euler(hullMotion.y, heading, hullMotion.z));
Quaternion.AngleAxis(heading, Vector3.up) * Quaternion.Euler(hullMotion.y, 0, hullMotion.z));
Vector4 hull = water.GetVector("_HullSpan");
hull.z = center.x;
hull.w = center.y;
water.SetVector("_HullSpan", hull);
water.SetVector("_HullCourse", new Vector4(cosine, sine, Mathf.Clamp01(speed / 19f), 0));
water.SetVector("_HullCourse", new Vector4(cosine, sine, Mathf.Clamp01(speed / (river ? 12f : 19f)), 0));
water.SetFloat("_SeaTime", seaTime);
water.SetFloat("_Underway", 1);
waterSurface.localPosition = new Vector3(center.x, 0, center.y);
Shader.SetGlobalFloat("_TycoonSeaTime", seaTime);
wake.Update(center, new Vector2(cosine, -sine), speed, vesselLength, vesselBeam, seaTime, seaSeverity);
wake.Update(center, new Vector2(cosine, -sine), speed, vesselLength, vesselBeam, seaTime, seaSeverity, river);
PresentRiverBanks(center);
}
private float WaveHeight(Vector2 point)
internal static Vector3 SampleSeaResponse(Vector2 center, float time, float heading, float length, float halfBeam,
float severity, bool river)
{
float amplitude = Mathf.Lerp(.35f, 1.46f, seaSeverity * seaSeverity);
return amplitude * (.65f * Mathf.Sin(.052f * point.x + .115f * point.y - .93f * seaTime)
+ .25f * Mathf.Sin(-.073f * point.x + .17f * point.y - 1.22f * seaTime + 1.30f)
+ .10f * Mathf.Sin(.217f * point.x - .136f * point.y - 1.64f * seaTime + 2.9f));
// Measure the same travelling waves as the water material at five points on the waterline.
float radians = heading * Mathf.Deg2Rad;
float sine = Mathf.Sin(radians), cosine = Mathf.Cos(radians);
float bowSpan = length * .32f, beamSpan = halfBeam * .78f;
var bow = new Vector2(cosine, -sine) * bowSpan;
var beam = new Vector2(sine, cosine) * beamSpan;
float fore = WaveHeight(center + bow, time, severity, river), aft = WaveHeight(center - bow, time, severity, river);
float port = WaveHeight(center + beam, time, severity, river), starboard = WaveHeight(center - beam, time, severity, river);
float amidships = WaveHeight(center, time, severity, river);
float mass = Mathf.InverseLerp(28f, 300f, length);
float heave = (amidships * .24f + (fore + aft + port + starboard) * .19f) * Mathf.Lerp(1f, .64f, mass);
float roll = Mathf.Atan2(starboard - port, 2f * beamSpan) * Mathf.Rad2Deg * Mathf.Lerp(1.12f, .78f, mass);
float pitch = Mathf.Atan2(fore - aft, 2f * bowSpan) * Mathf.Rad2Deg * Mathf.Lerp(1.19f, .78f, mass);
return new Vector3(heave, Mathf.Clamp(roll, river ? -3.2f : -9f, river ? 3.2f : 9f),
Mathf.Clamp(pitch, -4.3f, 4.3f));
}
private static float WaveHeight(Vector2 point, float time, float severity, bool river)
{
if (river)
return Mathf.Lerp(.22f, .44f, severity) * (.49f * Mathf.Sin(.197f * point.x + .235f * point.y - 1.55f * time)
+ .39f * Mathf.Sin(-.088f * point.x + .13f * point.y - 1.02f * time + 1.3f)
+ .12f * Mathf.Sin(.40f * point.x - .31f * point.y - 2.03f * time + 2.9f));
return Mathf.Lerp(.61f, 1.95f, severity * severity) * (.49f * Mathf.Sin(.052f * point.x + .115f * point.y - .93f * time)
+ .39f * Mathf.Sin(-.024f * point.x + .054f * point.y - .75f * time + 1.3f)
+ .12f * Mathf.Sin(.217f * point.x - .136f * point.y - 1.64f * time + 2.9f));
}
public void EndPassage()
{
sailing = false;
HideRiverBanks();
waterSurface.localPosition = Vector3.zero;
wake.Reset();
Shader.SetGlobalFloat("_TycoonSeaSailing", 0);
Shader.SetGlobalFloat("_TycoonRiverWater", 0);
if (vessel != null)
vessel.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
Vector4 hull = water.GetVector("_HullSpan");
@@ -458,7 +491,14 @@ namespace BigShipTycoon
private Vector3 OrbitFocus(Vector3 offset)
{
Vector3 local = OverviewFocus() + offset;
return vessel != null ? vessel.TransformPoint(local) : local;
if (vessel == null || !sailing)
return vessel != null ? vessel.TransformPoint(local) : local;
// Follow the track with a level camera. Close inspections follow more of the point on the deck.
Vector3 level = vessel.localPosition - Vector3.up * hullMotion.x
+ Quaternion.AngleAxis(passageHeading, Vector3.up) * local;
float tracking = Mathf.Lerp(.21f, .89f, 1f - Mathf.InverseLerp(.17f, .78f, zoom));
return Vector3.Lerp(transform.TransformPoint(level), vessel.TransformPoint(local), tracking);
}
private Vector3 FilmToShip(Vector2 filmOffset, float aspect, float height)
@@ -554,8 +594,11 @@ namespace BigShipTycoon
viewCamera.orthographic = false;
viewCamera.nearClipPlane = .095f;
viewCamera.fieldOfView = freeFov;
float follow = cameraMode == CameraMode.Bridge ? .73f : cameraMode == CameraMode.OutdoorWalk ? .61f : .87f;
Quaternion comfort = transform.rotation * Quaternion.AngleAxis(passageHeading, Vector3.up)
* Quaternion.Euler(hullMotion.y * follow, 0, hullMotion.z * follow);
viewCamera.transform.SetPositionAndRotation(vessel.TransformPoint(freePosition),
vessel.rotation * Quaternion.Euler(freePitch, freeYaw, 0));
comfort * Quaternion.Euler(freePitch, freeYaw, 0));
}
FitViewport();
}
@@ -673,7 +716,10 @@ namespace BigShipTycoon
vesselLength = ship.Hull.Length;
float beam = vesselBeam = ship.Hull.Beam * .5f;
vesselTop = VesselExterior.DeckBase + deckCount * VesselExterior.DeckSpacing + (ship.HasAftTerrace ? 10.5f : 5.95f);
vesselTop = MegaDeckGeometry.RoofHeight(deckCount, SunDeckZone.Sky, ship) + (hullIndex switch
{
Market.River => 3.5f, Market.Ocean => 7.35f, Market.Mega => 10.5f, _ => 5.95f
});
water.SetVector("_HullSpan", new Vector4(vesselLength, beam, 0, 0));
hullBounds = new Bounds(new Vector3(0, (vesselTop - 2.65f) * .5f, 0), new Vector3(vesselLength * 1.05f, vesselTop + 2.65f, beam * 2.26f));
@@ -740,6 +786,11 @@ namespace BigShipTycoon
VesselExterior.Paint.AtriumGlass => ("154450", .16f, .53f, 0f, .07f),
VesselExterior.Paint.DeckTrack => ("A85E4E", .83f, .02f, 0f, .21f),
VesselExterior.Paint.FritGlass => ("6F8794", .25f, .38f, 0f, .08f),
VesselExterior.Paint.CoastalHull => ("CEDAD8", .43f, .14f, 0f, .39f),
VesselExterior.Paint.CoastalBlue => ("29608C", .39f, .16f, 0f, .31f),
VesselExterior.Paint.RegionalHull => ("DCE3DB", .36f, .19f, 0f, .26f),
VesselExterior.Paint.RegionalTeal => ("076B70", .33f, .21f, 0f, .24f),
VesselExterior.Paint.OceanRed => ("8A3B34", .53f, .08f, 0f, .29f),
_ => ("318994", .16f, .40f, .05f, .13f)
};
ColorUtility.TryParseHtmlString("#" + hex, out Color color);
@@ -749,7 +800,8 @@ namespace BigShipTycoon
material.SetFloat("_Emissive", emissive);
material.SetFloat("_Weather", weather);
material.SetFloat("_Waterline", paint is VesselExterior.Paint.Navy or VesselExterior.Paint.Antifouling
or VesselExterior.Paint.Black or VesselExterior.Paint.MegaHull ? 1f : 0f);
or VesselExterior.Paint.Black or VesselExterior.Paint.MegaHull or VesselExterior.Paint.OceanRed
or VesselExterior.Paint.CoastalHull or VesselExterior.Paint.RegionalHull ? 1f : 0f);
SurfaceFinish finish = paint switch
{
VesselExterior.Paint.Teak or VesselExterior.Paint.TeakSeam => SurfaceFinish.Timber,
@@ -757,7 +809,8 @@ namespace BigShipTycoon
or VesselExterior.Paint.Lounge or VesselExterior.Paint.AtriumGlass => SurfaceFinish.Glass,
VesselExterior.Paint.DeckCanvas => SurfaceFinish.Fabric,
VesselExterior.Paint.Steel or VesselExterior.Paint.Gold => SurfaceFinish.Alloy,
VesselExterior.Paint.Navy or VesselExterior.Paint.Antifouling or VesselExterior.Paint.MegaHull => SurfaceFinish.Hull,
VesselExterior.Paint.Navy or VesselExterior.Paint.Antifouling or VesselExterior.Paint.MegaHull
or VesselExterior.Paint.CoastalHull or VesselExterior.Paint.RegionalHull or VesselExterior.Paint.OceanRed => SurfaceFinish.Hull,
VesselExterior.Paint.Ivory => SurfaceFinish.Panel,
VesselExterior.Paint.Pool => SurfaceFinish.Pool,
VesselExterior.Paint.Turf or VesselExterior.Paint.Fringe => SurfaceFinish.Turf,
@@ -803,6 +856,7 @@ namespace BigShipTycoon
ReleaseFrame();
ReleaseShip();
ReleasePortQuay();
ReleaseRiverBanks();
wake?.Dispose();
foreach (Material material in materials.Values)
Destroy(material);