From 7951e1c878320cf795fb8b2ae854750168664de3 Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 27 Nov 2026 22:44:09 -0500 Subject: [PATCH] Add manual helm, grounded interiors, and taller ship classes --- .../Soundings/Editor/EconomyVerification.cs | 29 + Assets/Soundings/Editor/SoundingsBuild.cs | 2 +- .../Soundings/Resources/BridgeGlazing.shader | 46 ++ .../Resources/BridgeGlazing.shader.meta | 10 + Assets/Soundings/Resources/HarborWater.shader | 38 +- Assets/Soundings/Resources/Passage.uss | 17 + .../Soundings/Resources/ServiceSurface.shader | 76 ++ .../Resources/ServiceSurface.shader.meta | 9 + Assets/Soundings/Runtime/Company.cs | 17 +- Assets/Soundings/Runtime/ConstructionPages.cs | 19 +- Assets/Soundings/Runtime/DeckPassengers.cs | 704 +++++++++++++++--- Assets/Soundings/Runtime/FirstVoyageGuide.cs | 6 +- Assets/Soundings/Runtime/Harbor.cs | 204 ++--- Assets/Soundings/Runtime/HelmControls.cs | 94 +++ Assets/Soundings/Runtime/HelmControls.cs.meta | 2 + Assets/Soundings/Runtime/HelmNavigation.cs | 106 +++ .../Soundings/Runtime/HelmNavigation.cs.meta | 2 + Assets/Soundings/Runtime/Market.cs | 17 +- Assets/Soundings/Runtime/PassageInterface.cs | 17 +- Assets/Soundings/Runtime/ServiceDeckModel.cs | 393 +++++++--- Assets/Soundings/Runtime/ShipWalkSpace.cs | 129 ++++ .../Soundings/Runtime/ShipWalkSpace.cs.meta | 2 + Assets/Soundings/Runtime/SoundingsApp.cs | 5 +- Assets/Soundings/Runtime/VesselExterior.cs | 70 +- Assets/Soundings/Runtime/VisualSmoke.cs | 94 ++- .../Soundings/Runtime/VoyagePresentation.cs | 52 +- Docs/Design.md | 4 +- ProjectSettings/ProjectSettings.asset | 2 +- README.md | 8 +- 29 files changed, 1745 insertions(+), 429 deletions(-) create mode 100644 Assets/Soundings/Resources/BridgeGlazing.shader create mode 100644 Assets/Soundings/Resources/BridgeGlazing.shader.meta create mode 100644 Assets/Soundings/Resources/ServiceSurface.shader create mode 100644 Assets/Soundings/Resources/ServiceSurface.shader.meta create mode 100644 Assets/Soundings/Runtime/HelmControls.cs create mode 100644 Assets/Soundings/Runtime/HelmControls.cs.meta create mode 100644 Assets/Soundings/Runtime/HelmNavigation.cs create mode 100644 Assets/Soundings/Runtime/HelmNavigation.cs.meta create mode 100644 Assets/Soundings/Runtime/ShipWalkSpace.cs create mode 100644 Assets/Soundings/Runtime/ShipWalkSpace.cs.meta diff --git a/Assets/Soundings/Editor/EconomyVerification.cs b/Assets/Soundings/Editor/EconomyVerification.cs index e13d4af..489861a 100644 --- a/Assets/Soundings/Editor/EconomyVerification.cs +++ b/Assets/Soundings/Editor/EconomyVerification.cs @@ -9,6 +9,7 @@ namespace Soundings.Editor { VerifyUsedStartAndProfit(); VerifyFinancedStartAndConstruction(); + VerifyHullDeckProgression(); VerifyFlagshipCampaign(); VerifyLiveCrossingSettlement(); VerifyStormAndShipSystems(); @@ -101,6 +102,34 @@ namespace Soundings.Editor Debug.Log($"Global circuit returned to Miami on day {company.Day} with ${company.Cash:N0} cash."); } + private static void VerifyHullDeckProgression() + { + Company company = Company.Start(false); + company.Cash = 2_000_000; + company.Reputation = 70; + company.Voyages = 12; + Ship coastal = company.ActiveShip; + Require(company.AddDeck(coastal) == null, "expand Coastal to its deck limit"); + Require(company.Acquire(1, true, null) == null, "buy a taller Regional hull"); + Ship regional = company.ActiveShip; + Require(regional.Decks.Count == 4 && regional.Decks.Count > coastal.Decks.Count + && regional.Hull.Length > coastal.Hull.Length, "new Regional is bigger than a fully expanded Coastal"); + Require(company.AddDeck(regional) == null, "expand Regional to its deck limit"); + Require(company.Acquire(Market.Ocean, false, "Crownhaven") == null, "commission a taller Ocean Class hull"); + Ship ocean = company.ActiveShip; + Require(ocean.Decks.Count == 6 && ocean.Decks.Count > regional.Decks.Count + && ocean.Hull.Length > regional.Hull.Length, "new Ocean Class is bigger than a fully expanded Regional"); + + Require(company.Build(regional, 2, 0, Facility.Stores) == null, "fit an existing Regional deck"); + regional.Decks.RemoveRange(3, regional.Decks.Count - 3); + ocean.Decks.RemoveRange(2, ocean.Decks.Count - 2); + Require(company.CanLoad(), "legacy hulls remain loadable"); + company.RestoreHullDecks(); + company.RestoreHullDecks(); + Require(regional.Decks.Count == 4 && regional.Decks[2].Cells[0] == Facility.Stores + && ocean.Decks.Count == 6, "older saves gain missing decks without losing their fit-out"); + } + private static void VerifyLiveCrossingSettlement() { Company company = Company.Start(false); diff --git a/Assets/Soundings/Editor/SoundingsBuild.cs b/Assets/Soundings/Editor/SoundingsBuild.cs index 297bf71..f5c1c59 100644 --- a/Assets/Soundings/Editor/SoundingsBuild.cs +++ b/Assets/Soundings/Editor/SoundingsBuild.cs @@ -24,7 +24,7 @@ namespace Soundings.Editor EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) }; PlayerSettings.companyName = "Soundings"; PlayerSettings.productName = "Soundings"; - PlayerSettings.bundleVersion = "0.3.0"; + PlayerSettings.bundleVersion = "0.4.0"; PlayerSettings.defaultScreenWidth = 1920; PlayerSettings.defaultScreenHeight = 1080; PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow; diff --git a/Assets/Soundings/Resources/BridgeGlazing.shader b/Assets/Soundings/Resources/BridgeGlazing.shader new file mode 100644 index 0000000..6658009 --- /dev/null +++ b/Assets/Soundings/Resources/BridgeGlazing.shader @@ -0,0 +1,46 @@ +Shader "Soundings/Bridge Glazing" +{ + Properties + { + _Color ("Glass tint", Color) = (.52,.74,.79,1) + } + SubShader + { + Tags { "Queue" = "Transparent" "RenderType" = "Transparent" } + Blend SrcAlpha OneMinusSrcAlpha + Cull Off + ZWrite Off + + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + fixed4 _Color; + struct Input { float4 vertex : POSITION; float3 normal : NORMAL; }; + struct Output { float4 clip : SV_POSITION; float3 world : TEXCOORD0; float3 normal : TEXCOORD1; }; + + Output vert(Input input) + { + Output output; + output.clip = UnityObjectToClipPos(input.vertex); + output.world = mul(unity_ObjectToWorld, input.vertex).xyz; + output.normal = UnityObjectToWorldNormal(input.normal); + return output; + } + + fixed4 frag(Output input) : SV_Target + { + float3 eye = normalize(_WorldSpaceCameraPos.xyz - input.world); + float3 normal = normalize(input.normal); + float edge = pow(1 - abs(dot(eye, normal)), 2); + float reflection = pow(saturate(reflect(-eye, normal).y), 4); + float3 tint = lerp(_Color.rgb * .64, float3(.89,.82,.66), reflection * .36); + return fixed4(tint, .041 + edge * .21 + reflection * .058); + } + ENDCG + } + } +} diff --git a/Assets/Soundings/Resources/BridgeGlazing.shader.meta b/Assets/Soundings/Resources/BridgeGlazing.shader.meta new file mode 100644 index 0000000..4e3c2e5 --- /dev/null +++ b/Assets/Soundings/Resources/BridgeGlazing.shader.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 47adb39f54f8432ca58db6eab81a2b16 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Soundings/Resources/HarborWater.shader b/Assets/Soundings/Resources/HarborWater.shader index ada0adc..5bf0ffe 100644 --- a/Assets/Soundings/Resources/HarborWater.shader +++ b/Assets/Soundings/Resources/HarborWater.shader @@ -5,6 +5,7 @@ Shader "Soundings/Harbor Water" _Backdrop ("Harbor photograph", 2D) = "black" {} _BackdropCrop ("Harbor crop", Vector) = (1,1,0,0) _HullSpan ("Hull length and beam", Vector) = (71,7,0,0) + _HullCourse ("Hull heading and wake strength", Vector) = (1,0,0,0) _Underway ("Open water blend", Range(0,1)) = 0 _WeatherSeverity ("Sea conditions", Range(0,1)) = 0 } @@ -21,27 +22,36 @@ Shader "Soundings/Harbor Water" #include "UnityCG.cginc" sampler2D _Backdrop; - float4 _BackdropCrop, _HullSpan; - float _Underway, _WeatherSeverity; - struct Output { float4 clip : SV_POSITION; float4 screen : TEXCOORD0; float2 world : TEXCOORD1; }; + float4 _BackdropCrop, _HullSpan, _HullCourse, _ViewSize; + float3 _ViewOrigin, _ViewForward, _ViewRight, _ViewUp; + float _Underway, _WeatherSeverity, _SeaTime; + struct Output { float4 clip : SV_POSITION; float2 screen : TEXCOORD0; }; Output vert(appdata_base input) { Output output; - output.clip = UnityObjectToClipPos(input.vertex); - output.screen = ComputeScreenPos(output.clip); - output.world = mul(unity_ObjectToWorld, input.vertex).xz; + float2 corner = input.vertex.xz / 2000; + output.clip = float4(corner.x, corner.y * _ProjectionParams.x, .99, 1); + output.screen = corner * .5 + .5; return output; } fixed4 frag(Output input) : SV_Target { - float2 screen = input.screen.xy / input.screen.w; + float2 screen = input.screen; + float2 offsetOnFilm = (screen * 2 - 1) * _ViewSize.xy; + float3 viewOffset = offsetOnFilm.x * _ViewRight + offsetOnFilm.y * _ViewUp; + float3 origin = _ViewOrigin + viewOffset * _ViewSize.z; + float3 ray = normalize(_ViewForward + viewOffset * (1 - _ViewSize.z)); + float distanceToWater = min(2600, max(0, -origin.y / min(ray.y, -.0001))); + float2 world = origin.xz + ray.xz * distanceToWater; float2 uv = (screen - .5) * _BackdropCrop.xy + .5 + _BackdropCrop.zw; float waterMask = 1 - smoothstep(.55,.69,uv.y); - float2 p = input.world - _HullSpan.zw; - float t = _Time.y; - float textureWave = sin(p.y * 1.94 + p.x * .30 + sin(p.x * .44 - t * (.30 + 1.2 * _WeatherSeverity))) + float2 relative = world - _HullSpan.zw; + float2 p = float2(dot(relative, float2(_HullCourse.x, -_HullCourse.y)), + dot(relative, _HullCourse.yx)); + float t = lerp(_Time.y, _SeaTime, _Underway); + float textureWave = sin(world.y * 1.94 + world.x * .30 + sin(world.x * .44 - t * (.30 + 1.2 * _WeatherSeverity))) * (.0015 + .003 * _WeatherSeverity); uv += waterMask * float2(textureWave, textureWave * .14); float3 color = tex2D(_Backdrop, uv).rgb; @@ -50,15 +60,15 @@ Shader "Soundings/Harbor Water" float seaHeight = clamp(uv.y * .59 + .056, .055, .49); float drift = sin(p.y * .166 + t * .19) * .017; float3 openWater = tex2D(_Backdrop, float2(saturate(uv.x + drift), seaHeight)).rgb; - float skyBand = smoothstep(.67, .70, screen.y); - float twilight = saturate((screen.y - .70) * 3.8); + float skyBand = lerp(smoothstep(-.006, .004, ray.y), smoothstep(.67, .70, screen.y), _ViewSize.z); + float twilight = lerp(saturate(ray.y * 2.8), saturate((screen.y - .70) * 3.8), _ViewSize.z); float west = pow(1 - screen.x, 1.65); float3 horizon = lerp(float3(.45,.53,.59), float3(.83,.60,.46), west); float3 sky = lerp(horizon, float3(.13,.24,.38), twilight); float cloud = .76 + .24 * sin(screen.x * 18 + screen.y * 8 + sin(screen.x * 41 - t * .2)); float3 stormSky = lerp(float3(.37,.45,.49), float3(.10,.15,.20), twilight) * cloud; sky = lerp(sky, stormSky, _WeatherSeverity); - float chop = sin(p.y * .83 + p.x * .45 - t * 2.4) * sin(p.x * .48 + p.y * 2.2 + t * 1.6); + float chop = sin(world.y * .83 + world.x * .45 - t * 2.4) * sin(world.x * .48 + world.y * 2.2 + t * 1.6); openWater = lerp(openWater, openWater * .56 + float3(.055,.082,.09), _WeatherSeverity); openWater += max(0, chop - .70) * .19 * _WeatherSeverity; color = lerp(color, lerp(openWater, sky, skyBand), _Underway); @@ -92,7 +102,7 @@ Shader "Soundings/Harbor Water" + .22 * sin(p.y * 13.7 - p.x * .37 - t * 2.2); float wake = smoothstep(.05, 2, trail) * (1 - smoothstep(1, 5 + trail * .062, abs(v))) * (1 - smoothstep(12, 89, trail)) * turbulence; - color = lerp(color, float3(.72,.84,.84), wake * waterMask * .43 * _Underway); + color = lerp(color, float3(.72,.84,.84), wake * waterMask * .43 * _Underway * _HullCourse.z); } return fixed4(color, 1); } diff --git a/Assets/Soundings/Resources/Passage.uss b/Assets/Soundings/Resources/Passage.uss index ca1414e..2d61cdc 100644 --- a/Assets/Soundings/Resources/Passage.uss +++ b/Assets/Soundings/Resources/Passage.uss @@ -134,3 +134,20 @@ .voyage-camera { margin-right: 15px; } .voyage-camera-help { color: #c4d4cf; font-size: 11px; margin-top: 5px; } .action.voyage-skip { flex-shrink: 0; } + +.passage-helm { + position: absolute; + right: 30px; + bottom: 151px; + width: 280px; + padding: 10px; + background-color: rgba(9, 22, 31, .95); + border-width: 1px; + border-top-width: 2px; + border-color: #ad9468; +} +.helm-readout { color: #eee0bd; font-size: 15px; margin: 4px 0 7px; } +.helm-throttle { flex-direction: row; margin-bottom: 3px; } +.action.helm-order { flex-grow: 1; min-height: 25px; padding: 2px 4px; margin-right: 2px; font-size: 11px; } +.helm-help { color: #b7c8c4; font-size: 11px; margin: 2px 0 6px; } +.action.helm-toggle { min-height: 32px; font-size: 12px; } diff --git a/Assets/Soundings/Resources/ServiceSurface.shader b/Assets/Soundings/Resources/ServiceSurface.shader new file mode 100644 index 0000000..bca3217 --- /dev/null +++ b/Assets/Soundings/Resources/ServiceSurface.shader @@ -0,0 +1,76 @@ +Shader "Soundings/Service Deck Surface" +{ + Properties + { + _Color ("Finish", Color) = (1,1,1,1) + _Roughness ("Roughness", Range(.02,1)) = .58 + _Metal ("Metal", Range(0,1)) = 0 + _Emissive ("Emission", Range(0,1)) = 0 + _BayLength ("Compartment length", Float) = 6 + _RoomLight ("Compartment fixture offset", Float) = 4 + _DeckTread ("Deck surface", Float) = 0 + } + SubShader + { + Tags { "RenderType"="Opaque" } + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + + fixed4 _Color; + float _Roughness, _Metal, _Emissive, _BayLength, _RoomLight, _DeckTread; + struct Input { float4 vertex : POSITION; float3 normal : NORMAL; }; + struct Output { float4 clip : SV_POSITION; float3 local : TEXCOORD0; float3 normal : TEXCOORD1; }; + + Output vert(Input input) + { + Output output; + output.clip = UnityObjectToClipPos(input.vertex); + output.local = input.vertex.xyz; + output.normal = input.normal; + return output; + } + + float3 fixture(float3 delta, float3 viewDirection, float3 normal, float3 tint) + { + float distanceSq = max(.19, dot(delta, delta)); + float3 incident = delta * rsqrt(distanceSq); + float diffuse = saturate(dot(normal, incident)); + float3 halfVector = normalize(incident + viewDirection); + float specular = pow(saturate(dot(normal, halfVector)), lerp(104, 12, _Roughness)); + return tint * (diffuse * .69 + specular * lerp(.12, .64, _Metal)) / (1 + distanceSq * .21); + } + + fixed4 frag(Output input) : SV_Target + { + float3 p = input.local; + float3 normal = normalize(input.normal); + float3 eye = mul(unity_WorldToObject, float4(_WorldSpaceCameraPos, 1)).xyz; + float3 viewDirection = normalize(eye - p); + float interval = _BayLength * .5; + float dx = (frac(p.x / interval) - .5) * interval; + float nearestRoom = p.z < 0 ? -_RoomLight : _RoomLight; + float3 corridor = fixture(float3(-dx, 2.85 - p.y, -p.z), viewDirection, normal, float3(1.00, .87, .67)); + float3 work = fixture(float3(-dx, 2.89 - p.y, nearestRoom - p.z), viewDirection, normal, float3(.90, .94, .93)); + corridor *= 1 - .62 * smoothstep(1.10, 2.25, abs(p.z)); + work *= smoothstep(.35, 1.88, abs(p.z)); + float fill = lerp(.72, 1, saturate(p.y * .72)); + float grain = p.x * 112 + p.y * 91; + float matte = .98 + .018 * (1 - smoothstep(.5, 2.4, fwidth(grain))) * sin(grain) * sin(p.z * 87 - p.y * 30); + float2 treadCoord = p.xz / .145; + float2 cell = abs(frac(treadCoord) - .5); + float relief = 1 - smoothstep(.30, .46, cell.x + cell.y); + float detail = 1 - smoothstep(.45, 1.3, fwidth(treadCoord.x) + fwidth(treadCoord.y)); + matte += .086 * relief * detail * _DeckTread * saturate(normal.y); + float3 diffuse = _Color.rgb * (float3(.34, .40, .42) * fill + corridor + work) * matte; + float fresnel = pow(1 - saturate(dot(viewDirection, normal)), 3); + float3 bounce = float3(.14, .20, .23) * fresnel * (.20 + _Metal * .40); + return fixed4(saturate(diffuse + bounce + _Color.rgb * _Emissive * .66), 1); + } + ENDCG + } + } +} diff --git a/Assets/Soundings/Resources/ServiceSurface.shader.meta b/Assets/Soundings/Resources/ServiceSurface.shader.meta new file mode 100644 index 0000000..c8eef66 --- /dev/null +++ b/Assets/Soundings/Resources/ServiceSurface.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f5afa05c8d244ee4a24c372c911b5697 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Soundings/Runtime/Company.cs b/Assets/Soundings/Runtime/Company.cs index 1e0895b..9c28306 100644 --- a/Assets/Soundings/Runtime/Company.cs +++ b/Assets/Soundings/Runtime/Company.cs @@ -34,6 +34,8 @@ namespace Soundings public double BurnPerMile => Hull.TonsPerMile * (1 + (100 - Condition) * .003); public int SafeRange => Math.Max(0, (int)Math.Floor(Math.Min(Fuel - 6, Fuel * 100 / 112) / BurnPerMile)); + internal void AddEmptyDeck() => Decks.Add(new Deck(Hull.Columns * Hull.Rows)); + public int Count(Facility facility) { int count = 0; @@ -104,7 +106,7 @@ namespace Soundings if (ship == null || string.IsNullOrWhiteSpace(ship.Name) || ship.HullIndex < 0 || ship.HullIndex >= Market.Hulls.Count || ship.Port < 0 || ship.Port >= Permits.Length || !Permits[ship.Port] || ship.Condition < 24 || ship.Condition > 100 || ship.Fare < Market.MinFare || ship.Fare > Market.MaxFare - || ship.Decks == null || ship.Decks.Count < Market.FirstDecks || ship.Decks.Count > ship.Hull.MaxDecks + || ship.Decks == null || ship.Decks.Count < Market.Hulls[0].StarterDecks || ship.Decks.Count > ship.Hull.MaxDecks || ship.Fuel < 0 || double.IsNaN(ship.FuelValue) || double.IsInfinity(ship.FuelValue) || ship.FuelValue < 0) return false; @@ -128,6 +130,13 @@ namespace Soundings return true; } + public void RestoreHullDecks() + { + foreach (Ship ship in Fleet) + while (ship.Decks.Count < ship.Hull.StarterDecks) + ship.AddEmptyDeck(); + } + public string ShipyardBlock(int hullIndex, bool used) { HullSpec hull = Market.Hulls[hullIndex]; @@ -179,8 +188,8 @@ namespace Soundings Fuel = original ? 48 : used ? 25 : 0 }; ship.FuelValue = ship.Fuel * Market.FuelPrice(0, 1); - for (int i = 0; i < Market.FirstDecks; i++) - ship.Decks.Add(new Deck(ship.Hull.Columns * ship.Hull.Rows)); + for (int i = 0; i < ship.Hull.StarterDecks; i++) + ship.AddEmptyDeck(); if (used) { for (int i = 0; i < 8; i++) @@ -204,7 +213,7 @@ namespace Soundings if (Cash < price) return "The company needs more cash."; Cash -= price; - ship.Decks.Add(new Deck(ship.Hull.Columns * ship.Hull.Rows)); + ship.AddEmptyDeck(); return null; } diff --git a/Assets/Soundings/Runtime/ConstructionPages.cs b/Assets/Soundings/Runtime/ConstructionPages.cs index ff69ba1..8e6eb90 100644 --- a/Assets/Soundings/Runtime/ConstructionPages.cs +++ b/Assets/Soundings/Runtime/ConstructionPages.cs @@ -291,14 +291,14 @@ namespace Soundings AddText(heading, used ? "Fitted for service · 72% condition at delivery" : hull.Description, "ship-work-detail"); var stamp = Add(titleBar, "work-yard-stamp"); AddText(stamp, "DELIVERY AT MIAMI", "work-caption"); - AddText(stamp, $"{hull.MaxDecks} decks max · {hull.Columns * hull.Rows} berths per deck · {hull.Tank} t fuel", "work-yard-specs"); + AddText(stamp, $"{hull.StarterDecks} decks delivered · {hull.MaxDecks} max · {hull.Tank} t fuel", "work-yard-specs"); var slipway = Add(work, "work-slipway"); slipway.generateVisualContent += context => DrawYardElevation(context, hullIndex, used); var markings = Add(slipway, "work-draft-markings"); markings.pickingMode = PickingMode.Ignore; AddText(markings, "STARBOARD ELEVATION", "work-caption"); - AddText(markings, used ? "FITTED HULL" : $"BARE HULL / {Market.FirstDecks} STARTER DECKS", "work-caption"); + AddText(markings, used ? "FITTED HULL" : $"BARE HULL / {hull.StarterDecks} STARTER DECKS", "work-caption"); var inventory = Add(work, "work-ship-inventory"); for (int item = 0; item < Offers.Length; item++) @@ -534,13 +534,14 @@ namespace Soundings Path(.026f,.609f, .119f,.627f, .885f,.627f, .959f,.579f); pen.Stroke(); - int levels = Market.FirstDecks; + int levels = Market.Hulls[hullIndex].StarterDecks; int allowedDecks = Market.Hulls[hullIndex].MaxDecks; + const float deckRise = .047f; pen.strokeColor = new Color(DraftFine.r, DraftFine.g, DraftFine.b, .28f); pen.BeginPath(); for (int level = levels; level < allowedDecks; level++) { - float y = .561f - level * .068f; + float y = .561f - level * deckRise; float left = .079f + level * .031f; float right = .872f - level * .04f; for (float x = left; x < right; x += .022f) @@ -549,14 +550,14 @@ namespace Soundings pen.Stroke(); for (int level = 0; level < levels; level++) { - float bottom = .561f - level * .068f; + float bottom = .561f - level * deckRise; float left = .079f + level * .031f; float right = .872f - level * .04f; pen.fillColor = new Color(.17f + .022f * level, .29f, .30f); pen.strokeColor = DraftFine; pen.lineWidth = 1.25f; pen.BeginPath(); - Path(left,bottom, left + .006f,bottom - .055f, right - .036f,bottom - .062f, right,bottom); + Path(left,bottom, left + .006f,bottom - .038f, right - .036f,bottom - .044f, right,bottom); pen.ClosePath(); pen.Fill(); pen.Stroke(); @@ -564,14 +565,14 @@ namespace Soundings pen.BeginPath(); if (used) for (float x = left + .022f; x < right - .04f; x += .028f) - Path(x,bottom - .036f, x + .014f,bottom - .036f); + Path(x,bottom - .022f, x + .014f,bottom - .022f); else for (float x = left + .025f; x < right - .04f; x += .1f) - Path(x,bottom - .026f, x + .050f,bottom - .026f); + Path(x,bottom - .019f, x + .050f,bottom - .019f); pen.Stroke(); } - float top = .57f - levels * .068f; + float top = .57f - levels * deckRise; pen.fillColor = new Color(.38f, .30f, .19f); pen.strokeColor = DraftGold; pen.BeginPath(); diff --git a/Assets/Soundings/Runtime/DeckPassengers.cs b/Assets/Soundings/Runtime/DeckPassengers.cs index 66ba605..b94aead 100644 --- a/Assets/Soundings/Runtime/DeckPassengers.cs +++ b/Assets/Soundings/Runtime/DeckPassengers.cs @@ -6,13 +6,21 @@ namespace Soundings { internal sealed class DeckPassengers : IDisposable { - private const float BaseFloor = 5.38f; - private const float FloorSpacing = 1.88f; + private const float EyeHeight = 1.64f; + private const float DeckCeiling = 2.44f; + private const float AisleWidth = 1.80f; + private const int Bulkhead = 25, Joinery = 26, Alloy = 27, DeckTrim = 28, Carpet = 29, + Ivory = 30, LightStrip = 31, Gasket = 32, DisplayDark = 33, ScreenChart = 34, + ScreenGreen = 35, ScreenAmber = 36, BridgeFloor = 37, Upholstery = 38, SafetyGreen = 39, + ScreenWater = 40, ScreenLand = 41, ScreenRed = 42, WindowGlass = 43; private static readonly string[] Paint = { "142C3F", "E1DBCA", "B88754", "8A613C", "283846", "678B93", "B45944", "497975", "D3A064", "688566", "354B64", "54435D", "AAD4D4", "D7906C", "ECE4D7", "337F9A", - "573B2E", "A46C50", "DFAB86", "40577D", "BF7756", "D3B973", "76ADA8", "A684AB", "E3DED0" + "573B2E", "A46C50", "DFAB86", "40577D", "BF7756", "D3B973", "76ADA8", "A684AB", "E3DED0", + "B7BFC0", "AD825C", "91A9AF", "284550", "385361", "DCE1DB", "FFF1D7", "202D36", + "111D25", "8ED9E0", "65C89B", "E7B868", "3F565C", "416172", "527D65", "29485A", "A8AB71", + "D66D57", "80B6C5" }; private readonly Transform shipRoot; @@ -24,6 +32,8 @@ namespace Soundings private readonly Layout[] decks; private readonly Layout promenade; private Layout bridge; + private Transform helmWheel; + private float rudderDegrees; private Mesh clothes, head; private int activeIndex = -1; private bool bridgeView; @@ -31,13 +41,20 @@ namespace Soundings private sealed class Layout { - public readonly GameObject Room, Crowd; + public readonly GameObject Room, Crowd, Interior, Cutaway; + public readonly ShipWalkSpace WalkSpace; public readonly List People = new(); - public Layout(string name, Transform parent) + public Layout(string name, Transform parent, ShipWalkSpace walkSpace = null) { Room = Piece(name, parent); Crowd = Piece("Passenger activity", Room.transform); + if (walkSpace == null) + return; + WalkSpace = walkSpace; + Interior = Piece("Ceiling and bulkheads", Room.transform); + Cutaway = Piece("Cutaway walls", Room.transform); + Interior.SetActive(false); } } @@ -63,26 +80,45 @@ namespace Soundings promenade.Crowd.SetActive(false); } - public float FloorHeight(int index) => BaseFloor + index * FloorSpacing + .08f; + public float FloorHeight(int index) => VesselExterior.DeckBase + index * VesselExterior.DeckSpacing + .08f; + + private (float Aft, float Fore, float HalfWidth) RoomEnvelope(int index) + { + if (index < 2) + return (-length * .356f, length * .323f, beam * .77f); + + float footprint = VesselExterior.DeckLength(length, index); + float offset = VesselExterior.DeckOffset(length, index); + return (offset - footprint * .43f, offset + footprint * .31f, VesselExterior.DeckHalfBeam(beam, index) * .83f); + } public Vector3 WalkOrigin(int index) { - float aisle = ship.Hull.Rows == 3 ? -beam * .34f : 0; - return new Vector3(-length * .34f, FloorHeight(index) + 1.57f, aisle); + var envelope = RoomEnvelope(index); + float rowDepth = (envelope.HalfWidth * 2 - (ship.Hull.Rows - 1) * AisleWidth) / ship.Hull.Rows; + return new Vector3(envelope.Aft + .85f, FloorHeight(index) + EyeHeight, -envelope.HalfWidth + rowDepth + AisleWidth * .5f); } - private float BridgeHeight => BaseFloor + ship.Decks.Count * FloorSpacing; + private float BridgeHeight => VesselExterior.DeckBase + ship.Decks.Count * VesselExterior.DeckSpacing; + private float BridgeHalfWidth => beam * .66f; + private float BridgeAft => BridgeCenter - 4.45f; + private float BridgeFore => BridgeCenter + 4.32f; - public Vector3 BridgeOrigin() => new(BridgeCenter - 1.2f, BridgeHeight + 1.65f, 0); + public Vector3 BridgeOrigin() => new(BridgeCenter - 1.74f, BridgeHeight + EyeHeight, 0); + internal ShipWalkSpace BridgeWalkSpace => bridge.WalkSpace; + internal ShipWalkSpace WalkSpace(int index) => decks[index].WalkSpace; - public Vector3 ClampBridgePosition(Vector3 position) + internal void SetRudder(float degrees) { - position.x = Mathf.Clamp(position.x, BridgeCenter - 3.2f, BridgeCenter + 1.3f); - position.z = Mathf.Clamp(position.z, -beam * .44f, beam * .44f); - position.y = BridgeHeight + 1.65f; - return position; + if (Mathf.Approximately(rudderDegrees, degrees)) + return; + rudderDegrees = degrees; + if (helmWheel != null) + helmWheel.localRotation = WheelRotation(); } + private Quaternion WheelRotation() => Quaternion.Euler(rudderDegrees * -2.6f, 0, 0); + public void Select(int index) { if (activeIndex >= 0 && decks[activeIndex] != null) @@ -96,7 +132,17 @@ namespace Soundings return; if (decks[index] == null) decks[index] = BuildDeck(index); - decks[index].Room.SetActive(true); + Layout deck = decks[index]; + deck.Interior.SetActive(false); + deck.Cutaway.SetActive(true); + deck.Room.SetActive(true); + } + + internal void Explore(int index) + { + Select(index); + decks[index].Interior.SetActive(true); + decks[index].Cutaway.SetActive(false); } public void SelectBridge() @@ -185,20 +231,42 @@ namespace Soundings private Layout BuildDeck(int index) { - var layout = new Layout($"Deck {index + 1} cutaway", shipRoot); + var (aft, fore, halfWidth) = RoomEnvelope(index); + var layout = new Layout($"Deck {index + 1}", shipRoot, + new ShipWalkSpace(aft, fore, -halfWidth, halfWidth)); float y = FloorHeight(index); var structure = new Geometry(this, layout.Room.transform); - Vector2[] outline = Outline(.97f, beam * .98f); - structure.Mesh(0).Loft(outline, Vector2.zero, false, + var interior = new Geometry(this, layout.Interior.transform); + var cutaway = new Geometry(this, layout.Cutaway.transform); + Vector2[] hull = Outline(.97f, beam * .98f); + float baseLevel = VesselExterior.DeckBase; + structure.Mesh(0).Loft(hull, Vector2.zero, false, new Vector3(.93f, -1.2f, .69f), new Vector3(.99f, 0, .95f), - new Vector3(1f, 2.0f, 1f), new Vector3(1f, y - .20f, 1f)); - structure.Mesh(1).Loft(outline, Vector2.zero, false, - new Vector3(1.002f, y - .21f, 1.003f), new Vector3(1.003f, y, 1.003f)); - structure.Mesh(2).Loft(outline, Vector2.zero, true, - new Vector3(.998f, y - .01f, .998f), new Vector3(.998f, y + .01f, .998f)); - structure.Mesh(8).Loft(outline, Vector2.zero, false, + new Vector3(1f, 2.0f, 1f), new Vector3(1f, baseLevel - .20f, 1f)); + structure.Mesh(1).Loft(hull, Vector2.zero, false, + new Vector3(1.002f, baseLevel - .21f, 1.003f), new Vector3(1.003f, baseLevel, 1.003f)); + structure.Mesh(2).Loft(hull, Vector2.zero, true, + new Vector3(.998f, baseLevel - .01f, .998f), new Vector3(.998f, baseLevel + .01f, .998f)); + structure.Mesh(8).Loft(hull, Vector2.zero, false, new Vector3(1.003f, 3.3f, 1.004f), new Vector3(1.003f, 3.37f, 1.004f)); + Vector2[] outline = hull; + for (int layer = 0; layer < index; layer++) + { + float layerBase = baseLevel + layer * VesselExterior.DeckSpacing; + float layerRoof = layerBase + VesselExterior.DeckSpacing; + float offset = VesselExterior.DeckOffset(length, layer); + Vector2 center = new(offset, 0); + outline = Outline(VesselExterior.DeckLength(length, layer) / length, VesselExterior.DeckHalfBeam(beam, layer), offset); + structure.Mesh(Ivory).Loft(outline, center, false, new Vector3(.98f, layerBase, .86f), + new Vector3(.99f, layerBase + .57f, .88f)); + structure.Mesh(DeckTrim).Loft(outline, center, false, new Vector3(.99f, layerBase + .57f, .88f), + new Vector3(.99f, layerRoof - .39f, .88f)); + structure.Mesh(Ivory).Loft(outline, center, false, new Vector3(.99f, layerRoof - .39f, .88f), + new Vector3(1, layerRoof - .18f, 1), new Vector3(1, layerRoof, 1)); + structure.Mesh(2).Loft(outline, center, true, new Vector3(1, layerRoof, 1), new Vector3(.998f, layerRoof + .037f, .998f)); + } + for (int i = 0; i < outline.Length; i++) { Vector2 a = outline[i], b = outline[(i + 1) % outline.Length]; @@ -206,113 +274,280 @@ namespace Soundings structure.Mesh(1).Rod(HarborMesh.Point(a, y), HarborMesh.Point(a, y + .52f), .035f); } - float total = length * .68f; + float usableLength = fore - aft; + float endCrossing = 1.95f; + float roomStart = aft + endCrossing; int columns = ship.Hull.Columns, rows = ship.Hull.Rows; - float cellWidth = total / columns; - float rowDepth = beam * 1.48f / rows; - for (int i = 0; i < 3; i++) - structure.Box(3, new Vector3(-length * .025f, y + .013f, (i - 1) * .28f), new Vector3(total + 5, .014f, .025f)); + float rowDepth = (halfWidth * 2 - (rows - 1) * AisleWidth) / rows; + float RowCenter(int row) => -halfWidth + (row + .5f) * rowDepth + row * AisleWidth; + float AisleCenter(int aisle) => RowCenter(aisle) + (rowDepth + AisleWidth) * .5f; + float cellWidth = (usableLength - endCrossing * 2) / columns; + float mid = (fore + aft) * .5f; + structure.Box(Carpet, new Vector3(mid, y + .020f, 0), new Vector3(usableLength, .028f, halfWidth * 2)); + interior.Box(Ivory, new Vector3(mid, y + DeckCeiling + .06f, 0), new Vector3(usableLength + .32f, .12f, halfWidth * 2 + .30f)); + for (int side = -1; side <= 1; side += 2) + { + float z = side * halfWidth; + DeckWall(interior, cutaway, new Vector3(aft + endCrossing * .5f, y, z), endCrossing, .15f); + DeckWall(interior, cutaway, new Vector3(fore - endCrossing * .5f, y, z), endCrossing, .15f); + DeckWall(interior, cutaway, new Vector3(side < 0 ? aft : fore, y, 0), .14f, halfWidth * 2); + } + + for (int aisle = 0; aisle < rows - 1; aisle++) + { + float z = AisleCenter(aisle); + structure.Box(DeckTrim, new Vector3(mid, y + .037f, z), new Vector3(usableLength, .018f, AisleWidth - .21f)); + for (int side = -1; side <= 1; side += 2) + { + structure.Box(Joinery, new Vector3(mid, y + .049f, z + side * .615f), new Vector3(usableLength, .008f, .025f)); + interior.Box(DeckTrim, new Vector3(mid, y + DeckCeiling - .083f, z + side * .60f), new Vector3(usableLength, .12f, .028f)); + } + + for (int col = 0; col < columns; col++) + { + float x = roomStart + (col + .5f) * cellWidth; + interior.Box(Gasket, new Vector3(x, y + DeckCeiling - .009f, z), new Vector3(2.22f, .045f, .43f)); + interior.Box(LightStrip, new Vector3(x, y + DeckCeiling - .031f, z), new Vector3(2.04f, .018f, .28f)); + structure.Box(Joinery, new Vector3(x, y + .048f, z), new Vector3(.035f, .009f, 1.23f)); + } + } + for (int col = 0; col < columns; col++) { - float x = -.025f * length - total * .5f + (col + .5f) * cellWidth; + float x = roomStart + (col + .5f) * cellWidth; for (int row = 0; row < rows; row++) { int slot = row * columns + col; - float z = (row - (rows - 1) * .5f) * (rowDepth + .47f); - var center = new Vector3(x, y + .026f, z); + var center = new Vector3(x, y + .055f, RowCenter(row)); Facility facility = ship.Decks[index].Cells[slot]; - Room(structure, layout, facility, center, cellWidth - .60f, rowDepth - .21f, index * 70 + slot); + float halfRow = rowDepth * .5f; + float door = facility == Facility.Empty ? Mathf.Min(2.4f, cellWidth - .6f) : (facility == Facility.Cabin ? 1.18f : 1.48f); + if (col == 0) + SolidDeckWall(layout, interior, cutaway, new Vector3(x - cellWidth * .5f, y, center.z), .15f, rowDepth); + SolidDeckWall(layout, interior, cutaway, new Vector3(x + cellWidth * .5f, y, center.z), .15f, rowDepth); + if (row > 0) + RoomEntrance(layout, interior, cutaway, x, y, center.z - halfRow, cellWidth, door, -1, index, slot, facility); + 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); + 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(-length * .30f, y + .021f, rows == 3 ? beam * .36f : .03f), -1, 0, index * 6, 1.1f, false); - AddPerson(layout, new Vector3(length * .29f, y + .021f, rows == 3 ? -beam * .36f : -.03f), -1, 1, index * 6 + 1, 1.2f, false); + 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); structure.Finish(); + interior.Finish(); + cutaway.Finish(); return layout; } - private void Room(Geometry shape, Layout layout, Facility facility, Vector3 pos, float width, float depth, int seed) + private static void DeckWall(Geometry interior, Geometry cutaway, Vector3 ground, float width, float depth) + { + interior.Box(Bulkhead, ground + Vector3.up * (DeckCeiling * .5f), new Vector3(width, DeckCeiling, depth)); + interior.Box(DeckTrim, ground + Vector3.up * .16f, new Vector3(width + .02f, .32f, depth + .02f)); + interior.Box(Joinery, ground + Vector3.up * 1.03f, new Vector3(width + .025f, .083f, depth + .025f)); + cutaway.Box(Ivory, ground + Vector3.up * .24f, new Vector3(width, .48f, depth)); + cutaway.Box(Joinery, ground + Vector3.up * .489f, new Vector3(width + .026f, .022f, depth + .026f)); + } + + private static void SolidDeckWall(Layout layout, Geometry interior, Geometry cutaway, Vector3 ground, float width, float depth) + { + DeckWall(interior, cutaway, ground, width, depth); + layout.WalkSpace.Block(ground, new Vector3(width, DeckCeiling, depth)); + } + + private void RoomEntrance(Layout layout, Geometry interior, Geometry cutaway, float x, float y, float z, + float width, float door, int side, int deck, int slot, Facility facility) + { + float segment = (width - door) * .5f; + for (int part = -1; part <= 1; part += 2) + { + float panelX = x + part * (door + segment) * .5f; + SolidDeckWall(layout, interior, cutaway, new Vector3(panelX, y, z), segment, .13f); + interior.Box(Joinery, new Vector3(x + part * (door * .5f + .013f), y + 1.02f, z), new Vector3(.07f, 2.04f, .17f)); + } + interior.Box(Joinery, new Vector3(x, y + 2.06f, z), new Vector3(door + .11f, .085f, .17f)); + interior.Box(Bulkhead, new Vector3(x, y + 2.25f, z), new Vector3(door, .36f, .13f)); + interior.Box(Alloy, new Vector3(x, y + .058f, z), new Vector3(door - .03f, .020f, .22f)); + if (facility == Facility.Empty) + return; + string label = facility == Facility.Cabin ? $"{deck + 1}{slot + 1:00}" : Market.Facilities[(int)facility].Name.ToUpperInvariant(); + float plaqueX = x + (door * .5f + .39f) * side; + interior.Box(DeckTrim, new Vector3(plaqueX, y + 1.63f, z + side * .088f), new Vector3(.61f, .15f, .045f)); + PlaceSign(layout.Interior.transform, label, new Vector3(plaqueX, y + 1.63f, z + side * .116f), side > 0 ? 180 : 0, + facility == Facility.Cabin ? .087f : .049f); + } + + private static void RoomWindow(Geometry shape, Geometry cutaway, float x, float y, float z, float width, int side, bool glazed) + { + if (!glazed) + { + DeckWall(shape, cutaway, new Vector3(x, y, z), width, .15f); + return; + } + float windowWidth = Mathf.Min(1.56f, width * .54f); + float sidePanel = (width - windowWidth) * .5f; + shape.Box(Bulkhead, new Vector3(x, y + .59f, z), new Vector3(windowWidth, 1.18f, .15f)); + shape.Box(Bulkhead, new Vector3(x, y + 2.22f, z), new Vector3(windowWidth, .44f, .15f)); + shape.Box(Joinery, new Vector3(x, y + 1.18f, z - side * .088f), new Vector3(windowWidth + .07f, .065f, .11f)); + shape.Box(Joinery, new Vector3(x, y + 2.0f, z - side * .088f), new Vector3(windowWidth + .07f, .065f, .11f)); + cutaway.Box(Ivory, new Vector3(x, y + .24f, z), new Vector3(windowWidth, .48f, .15f)); + shape.Mesh(WindowGlass).Quad(new Vector3(x - windowWidth * .5f, y + 1.19f, z), new Vector3(x + windowWidth * .5f, y + 1.19f, z), + new Vector3(x + windowWidth * .5f, y + 1.99f, z), new Vector3(x - windowWidth * .5f, y + 1.99f, z)); + for (int fold = -1; fold <= 1; fold += 2) + { + DeckWall(shape, cutaway, new Vector3(x + fold * (windowWidth + sidePanel) * .5f, y, z), sidePanel, .15f); + float edge = x + fold * (windowWidth * .5f + .075f); + shape.Box(Joinery, new Vector3(x + fold * windowWidth * .5f, y + 1.59f, z - side * .088f), new Vector3(.061f, .86f, .11f)); + shape.Box(Upholstery, new Vector3(edge, y + 1.57f, z - side * .16f), new Vector3(.18f, .98f, .23f)); + } + } + + private static void PlaceSign(Transform parent, string copy, Vector3 position, float yaw, float height) + { + GameObject sign = Piece(copy, parent); + sign.transform.SetLocalPositionAndRotation(position, Quaternion.Euler(0, yaw, 0)); + TextMesh letters = sign.AddComponent(); + Font font = Resources.Load("Interface"); + if (font != null) + { + letters.font = font; + sign.GetComponent().sharedMaterial = font.material; + } + letters.text = copy; + letters.fontSize = 64; + letters.characterSize = height / 4.4f; + letters.anchor = TextAnchor.MiddleCenter; + letters.alignment = TextAlignment.Center; + 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) { int floor = facility switch { - Facility.Cabin => 5, Facility.Dining => 6, Facility.Entertainment => 11, Facility.Bar => 7, - Facility.Amenity => 9, Facility.Tank => 4, Facility.Galley => 6, Facility.Stores => 5, - Facility.Water => 15, Facility.Waste => 11, Facility.Workshop => 7, _ => 3 + Facility.Cabin => Carpet, Facility.Dining => Joinery, Facility.Entertainment => 11, Facility.Bar => 7, + Facility.Amenity => Alloy, Facility.Galley or Facility.Workshop => BridgeFloor, _ => DeckTrim }; void Box(int color, float x, float y, float z, float w, float height, float d) - => shape.Box(color, pos + new Vector3(x, y, z), new Vector3(w, height, d)); - Box(floor, 0, .006f, 0, width, .045f, depth); - if (facility == Facility.Empty) + => shape.Box(color, pos + new Vector3(x, y, z * facing), new Vector3(w, height, d)); + void Solid(int color, float x, float y, float z, float w, float h, float d) { - Box(8, 0, .04f, depth * .48f, width, .025f, .045f); - return; + 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) + { + Vector3 center = pos + new Vector3(x, 0, z * facing); + Chair(shape, center, color, facing); + layout.WalkSpace.Block(center, new Vector3(.50f, .91f, .54f)); } - Box(1, 0, .20f, depth * .49f, width, .36f, .12f); - Box(1, -width * .48f, .21f, 0, .12f, .40f, depth); - Box(1, width * .48f, .21f, 0, .12f, .40f, depth); + Box(floor, 0, -.018f, 0, width, .045f, depth); + if (facility == Facility.Empty) + return; + int service = -1; switch (facility) { case Facility.Cabin: for (int side = -1; side <= 1; side += 2) { - Box(4, width * .25f * side, .23f, depth * .018f, 1.07f, .40f, 1.63f); - Box(14, width * .25f * side, .49f, depth * .018f, 1.04f, .18f, 1.58f); - Box(12, width * .25f * side, .61f, -depth * .11f, 1.02f, .06f, 1.02f); - Box(14, width * .25f * side, .62f, depth * .23f, .83f, .07f, .29f); + float x = side * width * .19f; + float z = depth * .16f; + Solid(Joinery, x, .257f, z, 1.03f, .52f, 1.88f); + Box(Ivory, x, .562f, z, 1.05f, .191f, 1.88f); + Box(Upholstery, x, .678f, z - .22f, 1.07f, .075f, 1.34f); + Box(Ivory, x, .71f, z + .59f, .62f, .108f, .35f); + Box(Joinery, x, .77f, z + .91f, 1.12f, .87f, .10f); + Box(LightStrip, x, 1.12f, z + .837f, .48f, .036f, .049f); + Box(8, x, .72f, z - .86f, 1.07f, .014f, .045f); } - Box(8, 0, .35f, depth * .23f, .72f, .64f, .57f); + Solid(Joinery, width * .395f, .44f, -depth * .214f, .80f, .88f, .96f); + Box(Ivory, width * .395f, .906f, -depth * .214f, .86f, .055f, 1.01f); + 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; break; case Facility.Dining: for (int side = -1; side <= 1; side += 2) { - float x = side * width * .24f; - Box(3, x, .34f, 0, .22f, .54f, .19f); - Box(14, x, .67f, 0, 1.16f, .15f, .94f); - Box(13, x, .77f, -.13f, .36f, .06f, .27f); - Chair(shape, pos + new Vector3(x, 0, -depth * .31f), 4); - Chair(shape, pos + new Vector3(x, 0, depth * .27f), 4); + float x = side * width * .25f; + Box(Alloy, x, .34f, .12f, .19f, .62f, .19f); + Solid(Ivory, x, .746f, .12f, 1.12f, .12f, .91f); + Box(8, x, .813f, .12f, .33f, .015f, .86f); + for (int seat = -1; seat <= 1; seat += 2) + { + float place = seat * .31f + .12f; + shape.Mesh(14).Rod(pos + new Vector3(x + .04f, .817f, place * facing), + pos + new Vector3(x + .04f, .840f, place * facing), .112f, 12); + Box(LightStrip, x + .22f, .85f, place + .05f, .065f, .080f, .065f); + } + Seat(x, -.58f, Upholstery); + Seat(x, .81f, Upholstery); } service = (int)OnboardService.Meals; break; case Facility.Bar: - Box(3, 0, .47f, depth * .28f, width * .80f, .88f, .73f); - Box(8, 0, .96f, depth * .28f, width * .83f, .13f, .78f); - for (int i = -1; i <= 1; i++) + Solid(Joinery, 0, .48f, depth * .18f, width * .77f, .94f, .81f); + Box(Gasket, 0, .974f, depth * .18f, width * .79f, .10f, .92f); + Box(8, 0, .20f, depth * .18f - .44f, width * .74f, .050f, .045f); + Box(LightStrip, 0, .867f, depth * .18f - .422f, width * .74f, .031f, .043f); + for (int i = -2; i <= 2; i++) { - float x = i * width * .21f; - Box(11, x, 1.09f, depth * .28f, .12f, .20f, .16f); - Chair(shape, pos + new Vector3(x, .17f, -depth * .10f), 6); + float x = i * width * .115f; + 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); } service = (int)OnboardService.Drinks; break; case Facility.Entertainment: - Box(4, 0, .30f, depth * .28f, width * .82f, .52f, .66f); - Box(13, 0, .88f, depth * .42f, width * .80f, .68f, .13f); - for (int i = -1; i <= 1; i++) - Chair(shape, pos + new Vector3(i * width * .23f, 0, -depth * .23f), 10); - AddPerson(layout, pos + new Vector3(0, .55f, depth * .23f), (int)OnboardService.Shows, 0, seed + 41, 0, false, 180); + Solid(Gasket, 0, .19f, depth * .307f, width * .82f, .38f, .99f); + Box(Joinery, 0, .393f, depth * .307f, width * .82f, .044f, .99f); + Box(11, 0, 1.24f, depth * .444f, width * .80f, 1.65f, .13f); + for (int i = -4; i <= 4; i++) + Box(6, i * width * .093f, 1.24f, depth * .436f, .079f, 1.65f, .082f); + 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; break; case Facility.Amenity: - Box(14, 0, .18f, depth * .16f, width * .66f, .30f, depth * .44f); - Box(15, 0, .35f, depth * .16f, width * .55f, .04f, depth * .34f); - Box(8, -width * .29f, .25f, -depth * .26f, 1.38f, .42f, .43f); - Box(8, width * .29f, .25f, -depth * .26f, 1.38f, .42f, .43f); + Solid(Ivory, 0, .18f, depth * .18f, width * .65f, .33f, depth * .44f); + Box(ScreenChart, 0, .356f, depth * .18f, width * .57f, .023f, depth * .36f); + for (int i = -4; i <= 4; i++) + Box(15, i * width * .062f, .370f, depth * .18f, .021f, .004f, depth * .34f); + for (int side = -1; side <= 1; side += 2) + { + Solid(Joinery, side * width * .308f, .25f, -depth * .25f, 1.41f, .34f, .53f); + Box(Ivory, side * width * .308f, .451f, -depth * .25f, 1.35f, .105f, .49f); + } service = (int)OnboardService.Amenities; break; case Facility.Tank: var start = pos + new Vector3(-width * .32f, .61f, 0); shape.Mesh(5).Rod(start, pos + new Vector3(width * .32f, .61f, 0), .49f, 12); Box(8, 0, .94f, -.12f, .29f, .22f, .24f); + layout.WalkSpace.Block(pos, new Vector3(width * .65f, .95f, 1.03f)); return; case Facility.Galley: - Box(3, 0, .45f, depth * .23f, width * .82f, .88f, .76f); - Box(14, 0, .94f, depth * .23f, width * .84f, .11f, .87f); + Solid(Alloy, 0, .45f, depth * .23f, width * .82f, .88f, .76f); + Box(Ivory, 0, .94f, depth * .23f, width * .84f, .11f, .87f); for (int i = -1; i <= 1; i++) + { Box(4, i * width * .24f, 1.02f, depth * .23f, .55f, .06f, .50f); - Box(14, 0, 1.53f, depth * .32f, width * .78f, .34f, .55f); + Box(Gasket, i * width * .24f, .50f, depth * .23f - .394f, .62f, .51f, .027f); + Box(Alloy, i * width * .24f, .704f, depth * .23f - .421f, .45f, .042f, .041f); + } + Box(Alloy, 0, 1.76f, depth * .32f, width * .78f, .34f, .55f); break; case Facility.Stores: for (int shelf = 1; shelf <= 2; shelf++) @@ -322,19 +557,21 @@ namespace Soundings for (int i = -1; i <= 1; i++) Box(i == 0 ? 6 : 5, i * width * .24f, y + .21f, depth * .28f, width * .19f, .34f, .47f); } + layout.WalkSpace.Block(pos + new Vector3(0, 0, depth * .28f * facing), new Vector3(width * .82f, 1.24f, .6f)); break; case Facility.Water: case Facility.Waste: for (int side = -1; side <= 1; side += 2) { - var foot = pos + new Vector3(side * width * .24f, .18f, depth * .17f); + var foot = pos + new Vector3(side * width * .24f, .18f, depth * .17f * facing); shape.Mesh(facility == Facility.Water ? 15 : 11).Rod(foot, foot + Vector3.up * 1.15f, .39f, 12); - Box(3, side * width * .24f, .12f, depth * .17f, .94f, .22f, .92f); + Solid(Gasket, side * width * .24f, .12f, depth * .17f, .94f, .22f, .92f); + Box(Alloy, side * width * .24f, .72f, depth * .17f - .399f, .23f, .25f, .043f); } Box(14, 0, .99f, depth * .34f, width * .53f, .15f, .13f); break; case Facility.Workshop: - Box(3, 0, .47f, depth * .28f, width * .83f, .88f, .72f); + Solid(Joinery, 0, .47f, depth * .28f, width * .83f, .88f, .72f); Box(8, 0, .97f, depth * .28f, width * .86f, .12f, .79f); Box(4, 0, 1.42f, depth * .46f, width * .78f, .77f, .12f); Box(7, width * .24f, 1.10f, depth * .27f, .47f, .20f, .34f); @@ -348,57 +585,266 @@ namespace Soundings 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), service, i, seed + i, 0, seats); + AddPerson(layout, pos + new Vector3(x, seats ? .23f : .03f, sittingZ * facing), service, i, seed + i, 0, seats); } } private Layout BuildBridge() { - var layout = new Layout("Bridge interior", shipRoot); - var geometry = new Geometry(this, layout.Room.transform); float y = BridgeHeight; float x = BridgeCenter; - float extent = beam * .65f; - geometry.Box(2, new Vector3(x, y, 0), new Vector3(8.8f, .18f, extent * 2)); - geometry.Box(4, new Vector3(x + 3.5f, y + .46f, 0), new Vector3(.30f, .88f, extent * 2)); - geometry.Box(1, new Vector3(x + 3.5f, y + 2.62f, 0), new Vector3(.28f, .33f, extent * 2)); - geometry.Box(1, new Vector3(x, y + 2.85f, 0), new Vector3(8.9f, .26f, extent * 2)); - geometry.Box(4, new Vector3(x - 4.15f, y + 1.45f, 0), new Vector3(.25f, 2.9f, extent * 2)); - for (int i = -2; i <= 2; i++) - { - float z = i * extent * .48f; - geometry.Mesh(1).Rod(new Vector3(x + 3.56f, y + .78f, z), new Vector3(x + 3.18f, y + 2.52f, z), .088f, 6); - } + float extent = BridgeHalfWidth; + var walk = new ShipWalkSpace(BridgeAft, BridgeFore - .06f, -extent, extent); + var layout = new Layout("Wheelhouse", shipRoot, walk); + var geometry = new Geometry(this, layout.Room.transform); + geometry.Box(BridgeFloor, new Vector3(x - .075f, y - .04f, 0), new Vector3(8.84f, .15f, extent * 2)); + geometry.Box(Carpet, new Vector3(x - 1.94f, y + .04f, 0), new Vector3(4.64f, .012f, extent * 1.71f)); + geometry.Box(Ivory, new Vector3(x - .07f, y + 2.77f, 0), new Vector3(8.87f, .17f, extent * 2)); + geometry.Box(Bulkhead, new Vector3(BridgeAft, y + 1.365f, 0), new Vector3(.18f, 2.73f, extent * 2)); + geometry.Box(DeckTrim, new Vector3(BridgeAft + .096f, y + .171f, 0), new Vector3(.04f, .34f, extent * 2)); + geometry.Box(Joinery, new Vector3(BridgeAft + .099f, y + 1.12f, 0), new Vector3(.04f, .058f, extent * 2)); + geometry.Box(Gasket, new Vector3(BridgeAft + .10f, y + 1.125f, .23f), new Vector3(.082f, 2.23f, 1.18f)); + geometry.Box(Alloy, new Vector3(BridgeAft + .155f, y + 1.13f, .23f), new Vector3(.078f, 2.11f, 1.05f)); + geometry.Box(SafetyGreen, new Vector3(BridgeAft + .197f, y + 2.34f, .23f), new Vector3(.062f, .18f, .67f)); + PlaceSign(layout.Room.transform, "WHEELHOUSE", new Vector3(BridgeAft + .24f, y + 2.34f, .23f), -90, .068f); for (int side = -1; side <= 1; side += 2) { float z = side * extent; - geometry.Box(4, new Vector3(x, y + .48f, z), new Vector3(8.8f, .95f, .28f)); - for (int i = -1; i <= 1; i++) - geometry.Box(1, new Vector3(x + i * 3.4f, y + 1.8f, z), new Vector3(.15f, 1.75f, .18f)); + geometry.Box(DeckTrim, new Vector3(x - .09f, y + .45f, z), new Vector3(8.63f, .90f, .18f)); + geometry.Box(Ivory, new Vector3(x - .10f, y + 2.59f, z), new Vector3(8.64f, .28f, .18f)); + geometry.Box(Joinery, new Vector3(x - .08f, y + .88f, z + side * -.10f), new Vector3(8.60f, .085f, .18f)); + geometry.Box(Carpet, new Vector3(x - 3.25f, y + 1.64f, z), new Vector3(2.30f, 1.54f, .20f)); + for (int bay = 0; bay < 3; bay++) + { + float from = x - 2.12f + bay * 1.93f; + float to = from + 1.93f; + Vector3 Post(float at, float height) => new(at, y + height, z); + geometry.Mesh(WindowGlass).Quad(Post(from, .91f), Post(to, .91f), Post(to, 2.45f), Post(from, 2.45f)); + geometry.Box(Alloy, new Vector3(from, y + 1.68f, z), new Vector3(.075f, 1.60f, .18f)); + } + geometry.Box(Bulkhead, new Vector3(x + 3.75f, y + 1.685f, z), new Vector3(.28f, 1.56f, .22f)); + for (int run = -1; run <= 1; run++) + { + float lightX = x + run * 2.35f; + geometry.Box(Gasket, new Vector3(lightX, y + 2.68f, extent * .63f * side), new Vector3(1.28f, .045f, .32f)); + geometry.Box(LightStrip, new Vector3(lightX, y + 2.648f, extent * .63f * side), new Vector3(1.16f, .028f, .23f)); + } + float lockerZ = extent * side * .67f; + geometry.Box(Joinery, new Vector3(BridgeAft + .46f, y + .47f, lockerZ), new Vector3(.72f, .94f, 1.24f)); + geometry.Box(Ivory, new Vector3(BridgeAft + .49f, y + .963f, lockerZ), new Vector3(.81f, .064f, 1.30f)); + geometry.Box(Alloy, new Vector3(BridgeAft + .825f, y + .76f, lockerZ), new Vector3(.045f, .039f, .23f)); + walk.Block(new Vector3(BridgeAft + .46f, y, lockerZ), new Vector3(.78f, .94f, 1.24f)); } - for (int column = -1; column <= 1; column++) + + const int panes = 8; + Vector3 WindowPoint(float fraction, float height) { - float z = column * extent * .57f; - geometry.Box(4, new Vector3(x + 1.8f, y + .54f, z), new Vector3(1.02f, 1.03f, 1.96f)); - geometry.Box(10, new Vector3(x + 1.76f, y + 1.16f, z), new Vector3(.85f, .26f, 2.1f)); - geometry.Box(15, new Vector3(x + 1.45f, y + 1.36f, z + .42f), new Vector3(.13f, .41f, .63f)); - geometry.Box(12, new Vector3(x + 1.37f, y + 1.37f, z + .42f), new Vector3(.02f, .26f, .46f)); - for (int button = 0; button < 4; button++) - geometry.Box(button == 2 ? 13 : 12, new Vector3(x + 1.54f, y + 1.31f, z - .55f + button * .14f), new Vector3(.11f, .035f, .10f)); - Chair(geometry, new Vector3(x + .6f, y, z), 10); + float z = fraction * extent; + float sweep = .48f * Mathf.Pow(Mathf.Abs(fraction), 1.65f) + (height > 2f ? .36f : 0); + return new Vector3(BridgeFore - sweep, y + height, z); } - Vector3 fore = new(length * .355f, y - .28f, 0); - geometry.Mesh(2).Loft(new[] + for (int i = 0; i < panes; i++) { - new Vector2(fore.x - 8, -beam * .70f), new Vector2(fore.x + length * .11f, 0), - new Vector2(fore.x - 8, beam * .70f) - }, new Vector2(fore.x - 2f, 0), true, new Vector3(1f, y - .4f, 1f), new Vector3(1, y - .28f, 1f)); + float left = i * 2f / panes - 1; + float right = (i + 1) * 2f / panes - 1; + Vector3 a = WindowPoint(left, .89f), b = WindowPoint(right, .89f); + Vector3 c = WindowPoint(right, 2.56f), d = WindowPoint(left, 2.56f); + geometry.Mesh(WindowGlass).Quad(a, b, c, d); + geometry.Mesh(DeckTrim).Quad(a - Vector3.up * .91f, b - Vector3.up * .91f, b, a); + geometry.Mesh(Ivory).Quad(d, c, c + Vector3.up * .19f, d + Vector3.up * .19f); + geometry.Mesh(Joinery).Rod(a - Vector3.right * .07f, b - Vector3.right * .07f, .061f, 6); + geometry.Mesh(Gasket).Rod(d, c, .043f, 6); + geometry.Mesh(Alloy).Rod(a, d, .043f, 6); + Vector3 sill = (a + b) * .5f; + walk.Block(sill + Vector3.right * .039f, new Vector3(.16f + Mathf.Abs(a.x - b.x), .92f, b.z - a.z + .025f)); + if (i is 1 or 3 or 4 or 6) + { + Vector3 wiper = Vector3.Lerp(a, b, .30f) + new Vector3(.026f, .059f, 0); + Vector3 tip = Vector3.Lerp(wiper, Vector3.Lerp(c, d, .21f), .57f); + geometry.Mesh(Gasket).Rod(wiper, tip, .013f, 6); + geometry.Mesh(Gasket).Rod(tip - Vector3.up * .22f, tip + Vector3.up * .21f, .020f, 6); + } + if (i == panes - 1) + geometry.Mesh(Alloy).Rod(b, c, .043f, 6); + } + + float stationOffset = extent * .66f; + BridgeConsole(geometry, walk, new Vector3(x + 1.39f, y, 0), 2.27f, 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)); + for (int side = -1; side <= 1; side += 2) + { + var seat = new Vector3(x + .31f, y, side * .72f); + BridgeChair(geometry, seat); + walk.Block(seat + Vector3.left * .08f, new Vector3(.62f, 1.20f, .46f)); + } + geometry.Box(Gasket, new Vector3(BridgeFore - .43f, y + 2.64f, 0), new Vector3(.079f, .16f, 1.12f)); + PlaceSign(layout.Room.transform, "NAVIGATION", new Vector3(BridgeFore - .478f, y + 2.64f, 0), 90, .067f); + DrawForedeck(geometry); geometry.Finish(); return layout; } - private float BridgeCenter => length * (.190f - ship.Decks.Count * .014f); + private static void BridgeConsole(Geometry shape, ShipWalkSpace walk, Vector3 origin, float width, int style) + { + void Box(int paint, float x, float y, float z, float d, float h, float w) + => shape.Box(paint, origin + new Vector3(x, y, z), new Vector3(d, h, w)); + Box(Gasket, 0, .48f, 0, .99f, .94f, width * .95f); + Box(DeckTrim, -.516f, .529f, 0, .048f, .70f, width * .81f); + Box(Joinery, 0, .987f, 0, 1.06f, .077f, width); + Box(Upholstery, .07f, 1.05f, 0, .82f, .075f, width * .96f); + Box(Alloy, -.535f, .943f, 0, .026f, .071f, width * .95f); + walk.Block(origin, new Vector3(1.09f, 1.05f, width)); + for (int i = -1; i <= 1; i += 2) + { + float z = i * width * .243f; + Box(Gasket, .34f, 1.302f, z, .20f, .47f, width * .402f); + Vector3 screen = origin + new Vector3(.234f, 1.308f, z); + BridgeScreen(shape, screen, .36f, width * .353f, (style + (i > 0 ? 1 : 0)) % 3); + Box(Alloy, .354f, 1.557f, z, .24f, .030f, width * .41f); + for (int key = 0; key < 5; key++) + Box(key == 3 ? ScreenAmber : ScreenChart, -.26f + key * .042f, 1.093f, + z - width * .11f, .022f, .016f, .047f); + } + Box(DisplayDark, -.19f, 1.09f, 0, .30f, .030f, .29f); + Box(Alloy, -.09f, 1.211f, 0, .036f, .215f, .036f); + Box(ScreenAmber, -.11f, 1.33f, 0, .09f, .074f, .12f); + Box(ScreenRed, -.35f, 1.112f, .151f, .066f, .047f, .065f); + } + + private void BuildHelmWheel(Geometry bridgeGeometry, Transform parent, Vector3 axis) + { + var mount = Piece("Steering wheel mount", parent).transform; + mount.SetLocalPositionAndRotation(axis, Quaternion.Euler(0, 0, -16.9f)); + helmWheel = Piece("Steering wheel", mount).transform; + helmWheel.localRotation = WheelRotation(); + var wheel = new Geometry(this, helmWheel); + Vector3 Rim(float angle) => new(0, Mathf.Sin(angle) * .177f, Mathf.Cos(angle) * .177f); + for (int part = 0; part < 20; part++) + { + float angle = part * Mathf.PI * .10f; + wheel.Mesh(Gasket).Rod(Rim(angle), Rim(angle + Mathf.PI * .10f), .023f, 7); + } + for (int spoke = 0; spoke < 3; spoke++) + { + float angle = Mathf.PI * .5f + spoke * Mathf.PI * 2 / 3; + wheel.Mesh(Alloy).Rod(Vector3.zero, Rim(angle), .014f, 6); + } + wheel.Mesh(Alloy).Rod(-Vector3.right * .025f, Vector3.right * .025f, .055f, 10); + wheel.Box(Gasket, -Vector3.right * .030f, new Vector3(.030f, .064f, .064f)); + wheel.Finish(); + bridgeGeometry.Mesh(Alloy).Rod(axis, axis + mount.localRotation * Vector3.right * .18f, .037f, 8); + } + + private static void BridgeScreen(Geometry shape, Vector3 face, float height, float width, int mode) + { + void Flat(int paint, float y, float z, float h, float w, float depth = .01f) + => shape.Box(paint, face + new Vector3(-depth, y, z), new Vector3(.007f, h, w)); + void Line(int paint, Vector2 from, Vector2 to, float radius = .003f) + => shape.Mesh(paint).Rod(face + new Vector3(-.029f, from.x, from.y), face + new Vector3(-.029f, to.x, to.y), radius, 5); + Flat(mode == 1 ? ScreenWater : DisplayDark, 0, 0, height, width); + Flat(Alloy, height * .445f, 0, .012f, width * .92f, .024f); + Flat(ScreenAmber, -height * .43f, width * .29f, .013f, width * .23f, .025f); + if (mode == 0) + { + for (int ring = 1; ring <= 3; ring++) + { + float radius = ring * height * .113f; + Vector2 previous = new(radius, 0); + for (int i = 1; i <= 20; i++) + { + float angle = i * Mathf.PI / 10f; + Vector2 current = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * radius; + Line(ScreenGreen, previous, current, .0019f); + previous = current; + } + } + Line(ScreenGreen, Vector2.zero, new Vector2(.108f, .054f)); + Flat(ScreenChart, .019f, -.067f, .014f, .016f, .03f); + Flat(ScreenAmber, -.047f, .068f, .01f, .014f, .03f); + } + else if (mode == 1) + { + for (int i = 0; i < 4; i++) + Flat(Alloy, (i - 1.5f) * height * .18f, 0, .004f, width * .94f, .025f); + for (int i = 0; i < 6; i++) + { + float z = (i - 2.5f) * width * .12f; + float stagger = Mathf.Sin(i * 1.59f) * height * .17f; + Flat(ScreenLand, height * .20f - stagger * .35f, z - width * .17f, height * .23f + stagger, width * .132f, .022f); + } + Line(ScreenAmber, new Vector2(-height * .26f, width * .28f), new Vector2(.02f, width * .11f)); + Line(ScreenAmber, new Vector2(.02f, width * .11f), new Vector2(height * .28f, width * .16f)); + } + else + { + for (int i = 0; i < 11; i++) + { + float z = (i - 5) * width * .075f; + float h = height * (.30f + Mathf.Sin(1.27f * i) * .13f); + Flat(i is 3 or 4 ? ScreenAmber : ScreenChart, -height * .12f + h * .34f, z, h, width * .029f, .024f); + } + Flat(ScreenGreen, height * .30f, -width * .25f, .017f, width * .35f, .03f); + } + } + + private static void BridgeChair(Geometry shape, Vector3 at) + { + shape.Box(Upholstery, at + new Vector3(.01f, .60f, 0), new Vector3(.44f, .131f, .44f)); + shape.Box(Upholstery, at + new Vector3(-.211f, .91f, 0), new Vector3(.138f, .61f, .42f)); + shape.Box(DeckTrim, at + new Vector3(-.194f, .98f, 0), new Vector3(.025f, .39f, .35f)); + shape.Mesh(Alloy).Rod(at + Vector3.up * .11f, at + Vector3.up * .54f, .083f, 9); + for (int spoke = 0; spoke < 5; spoke++) + { + float angle = spoke * Mathf.PI * .4f; + Vector3 foot = at + new Vector3(Mathf.Cos(angle) * .274f, .065f, Mathf.Sin(angle) * .274f); + shape.Mesh(Alloy).Rod(at + Vector3.up * .10f, foot, .031f, 6); + shape.Mesh(Gasket).Radome(foot - Vector3.up * .022f, .046f); + } + for (int side = -1; side <= 1; side += 2) + { + shape.Box(Gasket, at + new Vector3(-.025f, .771f, side * .245f), new Vector3(.34f, .068f, .059f)); + shape.Mesh(Alloy).Rod(at + new Vector3(.096f, .642f, side * .245f), at + new Vector3(.096f, .754f, side * .245f), .023f); + } + } + + private void DrawForedeck(Geometry shape) + { + float level = VesselExterior.DeckBase + .04f; + float from = BridgeFore - 1.44f; + float nose = length * .498f; + Vector2[] outline = + { + new(from, -beam * .89f), new(length * .37f, -beam * .74f), new(length * .44f, -beam * .46f), + new(length * .482f, -beam * .18f), new(nose, 0), new(length * .482f, beam * .18f), + new(length * .44f, beam * .46f), new(length * .37f, beam * .74f), new(from, beam * .89f) + }; + var center = new Vector2((from + nose) * .5f, 0); + shape.Mesh(2).Loft(outline, center, true, new Vector3(1, level - .15f, 1), new Vector3(1, level, 1)); + shape.Mesh(Ivory).Loft(outline, center, false, new Vector3(.99f, level - .52f, .98f), new Vector3(1, level -.15f, 1)); + for (int i = 0; i < outline.Length - 1; i++) + { + Vector2 a = outline[i], b = outline[i + 1]; + shape.Mesh(Alloy).Rod(HarborMesh.Point(a, level + .77f), HarborMesh.Point(b, level + .77f), .031f); + shape.Mesh(Alloy).Rod(HarborMesh.Point(a, level + .43f), HarborMesh.Point(b, level + .43f), .022f); + for (int column = 0; column < 3; column++) + { + Vector2 post = Vector2.Lerp(a, b, column / 3f); + shape.Mesh(Ivory).Rod(HarborMesh.Point(post, level), HarborMesh.Point(post, level + .77f), .027f); + } + } + for (int side = -1; side <= 1; side += 2) + { + float z = side * beam * .30f; + shape.Box(Ivory, new Vector3(nose - length * .10f, level + .12f, z), new Vector3(.50f, .23f, .56f)); + shape.Mesh(Gasket).Rod(new Vector3(nose - length * .10f, level + .19f, z), + new Vector3(nose - length * .10f, level + .39f, z), .13f, 10); + } + } + + private float BridgeCenter => VesselExterior.BridgeCenter(length, ship.Decks.Count); private void BuildPeopleMeshes() { @@ -426,20 +872,23 @@ namespace Soundings person.SetActive(false); } - private static void Chair(Geometry shape, Vector3 at, int color) + private static void Chair(Geometry shape, Vector3 at, int color, int side) { - shape.Box(color, at + new Vector3(0, .39f, 0), new Vector3(.42f, .12f, .39f)); - shape.Box(4, at + new Vector3(0, .19f, 0), new Vector3(.12f, .35f, .12f)); + shape.Box(color, at + new Vector3(0, .45f, 0), new Vector3(.44f, .089f, .41f)); + shape.Box(color, at + new Vector3(0, .69f, -.185f * side), new Vector3(.43f, .41f, .085f)); + for (int x = -1; x <= 1; x += 2) + for (int z = -1; z <= 1; z += 2) + shape.Box(Joinery, at + new Vector3(x * .167f, .208f, z * .158f), new Vector3(.044f, .414f, .044f)); } - private Vector2[] Outline(float size, float width) + private Vector2[] Outline(float size, float width, float offset = 0) { int steps = 22; var points = new Vector2[steps * 2 + 2]; for (int i = 0; i <= steps; i++) { float t = i / (float)steps; - float x = (t - .5f) * length * size; + float x = offset + (t - .5f) * length * size; float shape = t < .20f ? Mathf.Lerp(.66f, 1, 1f - Mathf.Pow(1f - t / .20f, 2)) : t > .69f ? Mathf.Sqrt(Mathf.Clamp01(1f - Mathf.Pow((t - .69f) / .31f, 1.72f))) : 1f; float z = Mathf.Max(.012f, width * shape); @@ -454,10 +903,23 @@ namespace Soundings if (paint.TryGetValue(id, out Material material)) return material; ColorUtility.TryParseHtmlString("#" + Paint[id], out Color color); - material = new Material(shader) { color = color, name = "Deck fittings " + Paint[id] }; - material.SetFloat("_Roughness", .77f); - material.SetFloat("_Metal", id == 4 ? .4f : .03f); - material.SetFloat("_Emissive", id is 12 or 15 ? .24f : .025f); + Shader finish = id == WindowGlass ? Resources.Load("BridgeGlazing") : shader; + material = new Material(finish) { color = color, name = "Deck fittings " + Paint[id] }; + if (id != WindowGlass) + { + bool metal = id is 4 or Alloy or Gasket; + material.SetFloat("_Roughness", metal ? .39f : .76f); + material.SetFloat("_Metal", metal ? .45f : .04f); + material.SetFloat("_Weather", id is Carpet or BridgeFloor or Upholstery ? .57f : .12f); + material.SetFloat("_Emissive", id switch + { + LightStrip => .97f, + ScreenGreen or ScreenAmber or ScreenChart or ScreenRed => .64f, + 12 or 15 or SafetyGreen => .22f, + Bulkhead or Joinery or Ivory => .22f, + _ => .08f + }); + } paint.Add(id, material); return material; } diff --git a/Assets/Soundings/Runtime/FirstVoyageGuide.cs b/Assets/Soundings/Runtime/FirstVoyageGuide.cs index 95167b0..2242b59 100644 --- a/Assets/Soundings/Runtime/FirstVoyageGuide.cs +++ b/Assets/Soundings/Runtime/FirstVoyageGuide.cs @@ -158,8 +158,10 @@ namespace Soundings case GuideStep.AtSea: if (passageServiceArea >= 0) return ("Run the service deck", "Inspect each station. You can switch between Assisted and Manual operations here.", "service-assist"); - if (passageBridge || passageExploring) - return ("Walk the ship", "Move with WASD and hold the right mouse button to look. Exterior returns to the ship view.", null); + if (passageBridge) + return ("Navigate from the bridge", "Choose Take the helm to steer. Return to autopilot to walk around again.", "helm-toggle"); + if (passageExploring) + return ("Walk the ship", "Move with WASD. Hold the right mouse button to look, or turn with Q and E.", null); return ("Make the crossing count", "Set onboard prices, offer specials, and watch for events. Choose Bridge or a deck view to look around.", "passage-business"); default: diff --git a/Assets/Soundings/Runtime/Harbor.cs b/Assets/Soundings/Runtime/Harbor.cs index 0578d70..a740bd9 100644 --- a/Assets/Soundings/Runtime/Harbor.cs +++ b/Assets/Soundings/Runtime/Harbor.cs @@ -14,14 +14,15 @@ namespace Soundings private Material water; private Mesh waterMesh; private Shader surface, reflection; - private float backplateRatio, vesselLength = 71; + private float backplateRatio, vesselLength = 72, vesselTop = 16.4f; private int lastHull = -2, lastDecks; private string currentBackplate; private ulong lastLayout; private const float DefaultYaw = 37f, DefaultPitch = 17.5f; private float yaw = DefaultYaw, pitch = DefaultPitch, zoom = 1f; private float targetYaw = DefaultYaw, targetPitch = DefaultPitch, targetZoom = 1f; - private float passage; + private float seaTime, seaSeverity; + private Vector3 hullMotion, hullMotionVelocity; private bool sailing; private Bounds hullBounds; private DeckPassengers decks; @@ -33,11 +34,13 @@ namespace Soundings private CameraMode cameraMode; private float freeYaw, freePitch, freeFov = 47f; private Vector3 freePosition; - private float walkHeight; + private ShipWalkSpace walkSpace; - private enum CameraMode { Orbit, Flight, DeckWalk, Bridge, Service } + private enum CameraMode { Orbit, DeckWalk, Bridge, Service } public RenderTexture Frame { get; private set; } + internal Vector3 FirstPersonPosition => freePosition; + internal bool FirstPersonPositionIsClear => walkSpace != null && walkSpace.CanStand(freePosition); public void Initialize() { @@ -65,6 +68,7 @@ namespace Soundings ocean.Quad(new Vector3(-2000, 0, -2000), new Vector3(-2000, 0, 2000), new Vector3(2000, 0, 2000), new Vector3(2000, 0, -2000)); waterMesh = ocean.Bake(); + waterMesh.bounds = new Bounds(Vector3.zero, Vector3.one * 4000); waterObject.GetComponent().sharedMesh = waterMesh; waterObject.GetComponent().sharedMaterial = water; } @@ -79,6 +83,16 @@ namespace Soundings targetPitch = Mathf.Clamp(targetPitch + drag.y * .13f, 12f, deckIndex >= 0 ? 78f : 48f); } + public void RotateView(float degrees) + { + if (Mathf.Abs(degrees) < .0001f) + return; + if (cameraMode == CameraMode.Orbit) + Orbit(new Vector2(degrees / .18f, 0)); + else + freeYaw = Mathf.Repeat(freeYaw + degrees, 360); + } + public void Zoom(float delta) { if (cameraMode != CameraMode.Orbit) @@ -101,12 +115,18 @@ namespace Soundings ExploreServiceArea(serviceArea); return; } + if (cameraMode == CameraMode.DeckWalk) + { + ExploreDeck(deckIndex); + return; + } ResetOrbit(immediate); } private void ResetOrbit(bool immediate) { cameraMode = CameraMode.Orbit; + walkSpace = null; viewCamera.orthographic = true; targetYaw = deckIndex >= 0 ? 17f : DefaultYaw; targetPitch = deckIndex >= 0 ? 55f : DefaultPitch; @@ -124,61 +144,23 @@ namespace Soundings if (!sailing || drag.sqrMagnitude < .0001f) return; if (cameraMode == CameraMode.Orbit) - EnterFlight(); + { + Orbit(drag); + return; + } freeYaw = Mathf.Repeat(freeYaw + drag.x * .22f, 360f); freePitch = Mathf.Clamp(freePitch + drag.y * .19f, -80f, 84f); } - public void Fly(Vector3 input, float delta, bool boost) + public void Walk(Vector2 input, float delta, bool boost) { - if (!sailing || input.sqrMagnitude < .0001f || delta <= 0) + if (!sailing || walkSpace == null || input.sqrMagnitude < .0001f || delta <= 0) return; - if (cameraMode == CameraMode.Orbit) - EnterFlight(); - input = Vector3.ClampMagnitude(input, 1f); - bool interior = cameraMode is CameraMode.DeckWalk or CameraMode.Bridge or CameraMode.Service; - Quaternion heading = Quaternion.Euler(interior ? 0 : freePitch, freeYaw, 0); - Vector3 movement = heading * new Vector3(input.x, 0, input.z); - if (!interior) - movement += Vector3.up * input.y; - float speed = interior ? (boost ? 6.4f : 3.3f) : (boost ? 52f : 20f); - freePosition += movement * (speed * Mathf.Min(.10f, delta)); - if (cameraMode == CameraMode.DeckWalk) - { - freePosition.x = Mathf.Clamp(freePosition.x, -vesselLength * .38f, vesselLength * .31f); - freePosition.z = Mathf.Clamp(freePosition.z, -vesselBeam * .77f, vesselBeam * .77f); - freePosition.y = walkHeight; - } - else if (cameraMode == CameraMode.Bridge) - { - freePosition = decks.ClampBridgePosition(freePosition); - } - else if (cameraMode == CameraMode.Service) - { - freePosition.x = Mathf.Clamp(freePosition.x, -vesselLength * .358f, vesselLength * .358f); - freePosition.z = Mathf.Clamp(freePosition.z, -vesselBeam * .79f, vesselBeam * .79f); - freePosition.y = walkHeight; - } - else - { - Vector3 origin = vessel != null ? vessel.position : Vector3.zero; - freePosition.x = Mathf.Clamp(freePosition.x, origin.x - 235, origin.x + 235); - freePosition.y = Mathf.Clamp(freePosition.y, 1.4f, 150f); - freePosition.z = Mathf.Clamp(freePosition.z, origin.z - 180, origin.z + 180); - } - } - - private void EnterFlight() - { - cameraMode = CameraMode.Flight; - freeFov = 47f; - Vector3 angles = viewCamera.transform.eulerAngles; - freeYaw = angles.y; - freePitch = Mathf.DeltaAngle(0f, angles.x); - float distance = viewCamera.orthographicSize / Mathf.Tan(freeFov * .5f * Mathf.Deg2Rad); - freePosition = OrbitFocus() - viewCamera.transform.forward * distance; - freePosition.y = Mathf.Max(1.4f, freePosition.y); - viewCamera.orthographic = false; + input = Vector2.ClampMagnitude(input, 1f); + Quaternion heading = Quaternion.Euler(0, freeYaw, 0); + Vector3 movement = heading * new Vector3(input.x, 0, input.y); + float speed = boost ? 2.85f : 1.65f; + freePosition = walkSpace.Move(freePosition, movement * (speed * Mathf.Min(.10f, delta))); } public void ShowDeck(int index) @@ -199,14 +181,8 @@ namespace Soundings if (!sailing || displayedShip == null || index < 0 || index >= displayedShip.Decks.Count) return; ShowDeck(index); - cameraMode = CameraMode.DeckWalk; - freeFov = 62f; - freePitch = 1.8f; - freeYaw = 90f; - freePosition = decks.WalkOrigin(index); - walkHeight = freePosition.y; - viewCamera.orthographic = false; - ComposeCamera(); + decks.Explore(index); + EnterWalk(CameraMode.DeckWalk, decks.WalkSpace(index), decks.WalkOrigin(index), 62f, 1.8f, 90f); } public void ViewBridge() @@ -216,34 +192,33 @@ namespace Soundings if (serviceDeck != null) serviceDeck.Root.SetActive(false); deckIndex = -1; - cameraMode = CameraMode.Bridge; exteriorRoot.gameObject.SetActive(false); decks.SelectBridge(); - freeFov = 68f; - freePitch = 1.3f; - freeYaw = 90f; - freePosition = decks.BridgeOrigin(); - viewCamera.orthographic = false; - ComposeCamera(); + EnterWalk(CameraMode.Bridge, decks.BridgeWalkSpace, decks.BridgeOrigin(), 68f, 1.3f, 90f); } public void ExploreServiceArea(int area) { - if (!sailing || vessel == null || area < 0 || area > 5) + if (!sailing || vessel == null || area < 0 || area >= ServiceDeckModel.Areas.Length) return; if (serviceDeck == null) serviceDeck = new ServiceDeckModel(vessel, vesselLength, vesselBeam, surface); deckIndex = -1; serviceArea = area; - cameraMode = CameraMode.Service; exteriorRoot.gameObject.SetActive(false); decks.HideRooms(); serviceDeck.Root.SetActive(true); - freeFov = 66f; - freePitch = 2f; - freeYaw = serviceDeck.Heading(area); - freePosition = serviceDeck.Entry(area); - walkHeight = freePosition.y; + EnterWalk(CameraMode.Service, serviceDeck.WalkSpace, serviceDeck.Entry(area), 66f, 2f, serviceDeck.Heading(area)); + } + + private void EnterWalk(CameraMode mode, ShipWalkSpace space, Vector3 entry, float fieldOfView, float lookDown, float heading) + { + cameraMode = mode; + walkSpace = space; + freeFov = fieldOfView; + freePitch = lookDown; + freeYaw = heading; + freePosition = walkSpace.Entry(entry); viewCamera.orthographic = false; ComposeCamera(); } @@ -254,6 +229,8 @@ namespace Soundings decks.Tick(session, delta); } + internal void SetRudder(float degrees) => decks?.SetRudder(degrees); + public bool IsShipAt(Vector2 viewportPoint) { return vessel != null && hullBounds.IntersectRay(viewCamera.ViewportPointToRay(viewportPoint)); @@ -262,36 +239,66 @@ namespace Soundings public void BeginPassage(WeatherCondition weather = WeatherCondition.Calm) { sailing = true; - water.SetFloat("_WeatherSeverity", (int)weather / 2f); + seaSeverity = (int)weather / 2f; + seaTime = 0; + hullMotion = hullMotionVelocity = Vector3.zero; + water.SetFloat("_WeatherSeverity", seaSeverity); cameraMode = CameraMode.Orbit; viewCamera.orthographic = true; targetYaw = 22f; targetPitch = 16f; targetZoom = 1.02f; - SetPassage(0); + SetPassage(Vector2.zero, 0, 0, 0); } - public void SetPassage(float progress) + public void SetPassage(Vector2 routePosition, float heading, float speed, float delta) { - passage = progress; - float travel = Mathf.Lerp(-3.6f, 9.25f, progress); + seaTime += delta * (1 + speed * .033f); + float headingRadians = heading * Mathf.Deg2Rad; + float sine = Mathf.Sin(headingRadians); + float cosine = Mathf.Cos(headingRadians); + var center = new Vector2(routePosition.x * 13f - 3.6f, -routePosition.y * 13f); + 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); + } if (vessel != null) - vessel.localPosition = new Vector3(travel, Mathf.Sin(progress * 19f) * .073f, 0); + vessel.SetLocalPositionAndRotation(new Vector3(center.x, hullMotion.x, center.y), + Quaternion.Euler(hullMotion.y, heading, hullMotion.z)); Vector4 hull = water.GetVector("_HullSpan"); - hull.z = travel; + hull.z = center.x; + hull.w = center.y; water.SetVector("_HullSpan", hull); - water.SetFloat("_Underway", Mathf.SmoothStep(.3f, 1, Mathf.Clamp01(progress * 5))); + water.SetVector("_HullCourse", new Vector4(cosine, sine, Mathf.Clamp01(speed / 19f), 0)); + water.SetFloat("_SeaTime", seaTime); + water.SetFloat("_Underway", 1); + } + + private float WaveHeight(Vector2 point) + { + float amplitude = Mathf.Lerp(.12f, 1.45f, seaSeverity * seaSeverity); + return amplitude * (.72f * Mathf.Sin(.052f * point.x + .115f * point.y - .93f * seaTime) + + .28f * Mathf.Sin(-.073f * point.x + .17f * point.y - 1.22f * seaTime + 1.30f)); } public void EndPassage() { sailing = false; - passage = 0; if (vessel != null) - vessel.localPosition = Vector3.zero; + vessel.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity); Vector4 hull = water.GetVector("_HullSpan"); - hull.z = 0; + hull.z = hull.w = 0; water.SetVector("_HullSpan", hull); + water.SetVector("_HullCourse", new Vector4(1, 0, 0, 0)); water.SetFloat("_Underway", 0); water.SetFloat("_WeatherSeverity", 0); ShowDeck(-1); @@ -320,10 +327,10 @@ namespace Soundings private Vector3 OrbitFocus() { - float level = deckIndex >= 0 && decks != null ? decks.FloorHeight(deckIndex) + .5f : 4.25f; + float level = deckIndex >= 0 && decks != null ? decks.FloorHeight(deckIndex) + .5f : vesselTop * .39f; var center = new Vector3(deckIndex >= 0 ? -2f : 2.1f, level, 0); - if (sailing) - center.x += Mathf.Lerp(-2, 6.5f, passage); + if (sailing && vessel != null) + center = vessel.TransformPoint(center); return center; } @@ -341,9 +348,8 @@ namespace Soundings viewCamera.orthographic = false; viewCamera.nearClipPlane = .095f; viewCamera.fieldOfView = freeFov; - Vector3 placement = cameraMode is CameraMode.Bridge or CameraMode.DeckWalk or CameraMode.Service - ? vessel.TransformPoint(freePosition) : freePosition; - viewCamera.transform.SetPositionAndRotation(placement, Quaternion.Euler(freePitch, freeYaw, 0)); + viewCamera.transform.SetPositionAndRotation(vessel.TransformPoint(freePosition), + vessel.rotation * Quaternion.Euler(freePitch, freeYaw, 0)); } FitViewport(); } @@ -388,6 +394,13 @@ namespace Soundings return; float aspect = (float)Frame.width / Frame.height; viewCamera.orthographicSize = Mathf.Max(17.6f, vesselLength * .71f / aspect) * zoom; + Transform view = viewCamera.transform; + float viewHeight = viewCamera.orthographic ? viewCamera.orthographicSize : Mathf.Tan(viewCamera.fieldOfView * Mathf.Deg2Rad * .5f); + water.SetVector("_ViewOrigin", view.position); + water.SetVector("_ViewForward", view.forward); + water.SetVector("_ViewRight", view.right); + water.SetVector("_ViewUp", view.up); + water.SetVector("_ViewSize", new Vector4(viewHeight * aspect, viewHeight, viewCamera.orthographic ? 1 : 0, 0)); if (backplateRatio <= 0) return; float cropX = Mathf.Min(1, aspect / backplateRatio) * .95f; @@ -434,10 +447,11 @@ namespace Soundings exteriorRoot = new GameObject("Exterior").transform; exteriorRoot.SetParent(vessel, false); - vesselLength = 71 + hullIndex * 12; - float beam = vesselBeam = 6.65f + hullIndex * .87f; + vesselLength = ship.Hull.Length; + float beam = vesselBeam = ship.Hull.Beam * .5f; + vesselTop = VesselExterior.DeckBase + deckCount * VesselExterior.DeckSpacing + 5.95f; water.SetVector("_HullSpan", new Vector4(vesselLength, beam, 0, 0)); - hullBounds = new Bounds(new Vector3(0, 5.5f, 0), new Vector3(vesselLength, 12.3f + deckCount * 1.7f, beam * 2.1f)); + hullBounds = new Bounds(new Vector3(0, (vesselTop - 2.65f) * .5f, 0), new Vector3(vesselLength, vesselTop + 2.65f, beam * 2.1f)); FitViewport(); var exterior = new VesselExterior(ship, vesselLength, beam); diff --git a/Assets/Soundings/Runtime/HelmControls.cs b/Assets/Soundings/Runtime/HelmControls.cs new file mode 100644 index 0000000..f44a90c --- /dev/null +++ b/Assets/Soundings/Runtime/HelmControls.cs @@ -0,0 +1,94 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace Soundings +{ + public sealed partial class SoundingsApp + { + private static readonly string[] HelmOrders = { "Stop", "Economy", "Cruise", "Power" }; + private readonly Button[] helmOrderButtons = new Button[HelmOrders.Length]; + private Label helmReadout; + private float courseBearing; + + private int HelmOrder => passageHelm.PropulsionStopped ? -1 : livePassage.EngineMode; + + private void DrawHelmControls(VisualElement overlay) + { + helmReadout = null; + if (!passageBridge && !passageHelm.Manual) + return; + + var station = Add(overlay, "passage-helm"); + AddText(station, passageHelm.Manual ? "MANUAL HELM" : "AUTOPILOT", "voyage-caption"); + courseBearing = CourseBearing(Market.Ports[underway.Origin], Market.Ports[underway.Destination]); + helmReadout = AddText(station, "", "helm-readout"); + if (passageHelm.Manual) + { + var throttle = Add(station, "helm-throttle"); + for (int i = 0; i < HelmOrders.Length; i++) + { + int order = i - 1; + helmOrderButtons[i] = Action(HelmOrders[i], () => SetHelmOrder(order), "helm-order", $"helm-order-{i}"); + throttle.Add(helmOrderButtons[i]); + } + AddText(station, "A / D rudder · W / S throttle", "helm-help"); + } + station.Add(Action(passageHelm.Manual ? "Return to autopilot H" : "Take the helm H", ToggleHelm, + "helm-toggle", "helm-toggle")); + UpdateHelmControls(); + } + + private void ToggleHelm() + { + if (passageHelm.Manual) + ReleaseHelm(); + else if (passageBridge) + passageHelm.Manual = true; + Render(); + } + + private void ReleaseHelm() + { + passageHelm.Manual = false; + passageHelm.PropulsionStopped = false; + } + + private void SetHelmOrder(int order) + { + if (order < -1 || order > 2 || (order >= 0 && !livePassage.CanSetEngineMode(order))) + return; + passageHelm.PropulsionStopped = order == -1; + if (order >= 0) + livePassage.SetEngineMode(order); + UpdateHelmControls(); + } + + private void UpdateHelmControls() + { + if (helmReadout == null || passageHelm == null) + return; + int heading = Mathf.RoundToInt(Mathf.Repeat(courseBearing + passageHelm.Heading, 360)) % 360; + int rudder = Mathf.RoundToInt(passageHelm.Rudder); + string rudderText = rudder == 0 ? "Centered" : $"{Mathf.Abs(rudder)}° {(rudder < 0 ? "Port" : "Stbd")}"; + SetPassageText(helmReadout, $"{heading:000}° true · {passageHelm.Speed:0.0} kn\nRudder {rudderText}"); + if (!passageHelm.Manual) + return; + for (int i = 0; i < helmOrderButtons.Length; i++) + { + helmOrderButtons[i].EnableInClassList("voyage-control-active", HelmOrder == i - 1); + helmOrderButtons[i].SetEnabled(i == 0 || livePassage.CanSetEngineMode(i - 1)); + } + } + + private static float CourseBearing(PortSpec origin, PortSpec destination) + { + float originLatitude = origin.Latitude * Mathf.Deg2Rad; + float destinationLatitude = destination.Latitude * Mathf.Deg2Rad; + float longitudeDifference = (destination.Longitude - origin.Longitude) * Mathf.Deg2Rad; + float east = Mathf.Sin(longitudeDifference) * Mathf.Cos(destinationLatitude); + float north = Mathf.Cos(originLatitude) * Mathf.Sin(destinationLatitude) + - Mathf.Sin(originLatitude) * Mathf.Cos(destinationLatitude) * Mathf.Cos(longitudeDifference); + return Mathf.Atan2(east, north) * Mathf.Rad2Deg; + } + } +} diff --git a/Assets/Soundings/Runtime/HelmControls.cs.meta b/Assets/Soundings/Runtime/HelmControls.cs.meta new file mode 100644 index 0000000..2abfbd9 --- /dev/null +++ b/Assets/Soundings/Runtime/HelmControls.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: d7f548f54b0a90e2e8fc84a3200aed6b \ No newline at end of file diff --git a/Assets/Soundings/Runtime/HelmNavigation.cs b/Assets/Soundings/Runtime/HelmNavigation.cs new file mode 100644 index 0000000..e62456e --- /dev/null +++ b/Assets/Soundings/Runtime/HelmNavigation.cs @@ -0,0 +1,106 @@ +using UnityEngine; + +namespace Soundings +{ + internal sealed class HelmNavigation + { + private const float RudderLimit = 35f; + private const float RudderSlew = 15f; + private const float IntegrationStep = .1f; + private readonly float duration, cruiseKnots, turnRateLimit, inertia, arrivalRadius; + private float turnRate; + private Vector2 approachWaypoint; + private bool extendingApproach; + + public HelmNavigation(float duration, int hullIndex) + { + this.duration = Mathf.Max(1, duration); + cruiseKnots = 17f + 2f * hullIndex; + turnRateLimit = 4.2f - .5f * hullIndex; + inertia = 1f + .16f * hullIndex; + arrivalRadius = Mathf.Min(this.duration * .15f, Mathf.Clamp(this.duration * .006f, .6f, 1.8f)); + } + + public bool Manual { get; set; } + public bool PropulsionStopped { get; set; } + public float Heading { get; private set; } + public float Rudder { get; private set; } + public float Speed { get; private set; } + public float Progress { get; private set; } + public Vector2 Position { get; private set; } + public bool Arrived { get; private set; } + public float RemainingSeconds => Arrived ? 0 : (new Vector2(duration, 0) - Position).magnitude; + + public void Advance(float seconds, float rudderInput, float engineSpeedFactor, WeatherCondition weather) + { + if (Arrived || seconds <= 0) + return; + + // Simulated X/Y use nominal route seconds. The route duration already includes the sea-state penalty. + float cruising = cruiseKnots / (weather switch + { + WeatherCondition.Swell => 1.14f, + WeatherCondition.Storm => 1.32f, + _ => 1f + }); + float targetSpeed = PropulsionStopped ? 0 : cruising * Mathf.Max(0, engineSpeedFactor); + float requestedRudder = Mathf.Clamp(rudderInput, -1f, 1f) * RudderLimit; + if (Manual) + extendingApproach = false; + for (int step = 0, steps = Mathf.CeilToInt(seconds / IntegrationStep); step < steps && !Arrived; step++) + { + float delta = Mathf.Min(IntegrationStep, seconds - step * IntegrationStep); + Vector2 toPort = new Vector2(duration, 0) - Position; + float rudderDemand = Manual ? requestedRudder : CourseRudder(toPort); + float previousSpeed = Speed; + float acceleration = targetSpeed > Speed ? 1.55f : 1.02f; + Speed = Mathf.MoveTowards(Speed, targetSpeed, delta * acceleration / inertia); + Rudder = Mathf.MoveTowards(Rudder, rudderDemand, delta * RudderSlew); + + float waterFlow = Mathf.Clamp01((previousSpeed + Speed) * .5f / cruising); + float desiredTurnRate = Rudder / RudderLimit * turnRateLimit * waterFlow; + turnRate = Mathf.MoveTowards(turnRate, desiredTurnRate, delta * 3.2f / inertia); + float yawStep = turnRate * delta; + float course = (Heading + yawStep * .5f) * Mathf.Deg2Rad; + Heading = Mathf.Repeat(Heading + yawStep + 180f, 360f) - 180f; + + float distance = (previousSpeed + Speed) * .5f / cruising * delta; + Position += new Vector2(Mathf.Cos(course), Mathf.Sin(course)) * distance; + Arrived = RemainingSeconds <= arrivalRadius; + Progress = Arrived ? 1 : Mathf.Max(Progress, Mathf.Clamp01(1 - RemainingSeconds / duration)); + } + } + + private float CourseRudder(Vector2 toPort) + { + Vector2 toWaypoint = approachWaypoint - Position; + if (extendingApproach && toWaypoint.magnitude < 6) + extendingApproach = false; + + float course = Mathf.Atan2(toPort.y, toPort.x) * Mathf.Rad2Deg; + float cruiseTurnRadius = Mathf.Rad2Deg / turnRateLimit; + if (!extendingApproach && toPort.magnitude < cruiseTurnRadius * 1.5f + && Mathf.Abs(Mathf.DeltaAngle(Heading, course)) > 55f) + { + // Make room for a full turn if the destination is already inside the ship's turning circle. + float heading = Heading * Mathf.Deg2Rad; + toWaypoint = new Vector2(Mathf.Cos(heading), Mathf.Sin(heading)) * (cruiseTurnRadius * 4f); + approachWaypoint = Position + toWaypoint; + extendingApproach = true; + } + if (extendingApproach) + course = Mathf.Atan2(toWaypoint.y, toWaypoint.x) * Mathf.Rad2Deg; + float courseError = Mathf.DeltaAngle(Heading, course); + return Mathf.Clamp(courseError * 1.55f - turnRate * 3.6f, -RudderLimit, RudderLimit); + } + + internal void SetProgress(float progress) + { + Progress = Mathf.Clamp01(progress); + Position = new Vector2(duration * Progress, 0); + Heading = Rudder = turnRate = 0; + extendingApproach = false; + Arrived = Progress >= 1; + } + } +} diff --git a/Assets/Soundings/Runtime/HelmNavigation.cs.meta b/Assets/Soundings/Runtime/HelmNavigation.cs.meta new file mode 100644 index 0000000..9200c6a --- /dev/null +++ b/Assets/Soundings/Runtime/HelmNavigation.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 31e7cdbccdb63b8abb5fbf4d6d186679 \ No newline at end of file diff --git a/Assets/Soundings/Runtime/Market.cs b/Assets/Soundings/Runtime/Market.cs index a7d4514..1a3256f 100644 --- a/Assets/Soundings/Runtime/Market.cs +++ b/Assets/Soundings/Runtime/Market.cs @@ -25,16 +25,18 @@ namespace Soundings public sealed class HullSpec { public readonly string Name, Description; - public readonly int Columns, Rows, MaxDecks, Price, Voyages, Reputation, Tank, CrewPerDay, HullWearCost; + public readonly int Columns, Rows, StarterDecks, MaxDecks, Price, Voyages, Reputation, Tank, CrewPerDay, HullWearCost; + public readonly float Length, Beam; public readonly double TonsPerMile; - public HullSpec(string name, string description, int columns, int rows, int maxDecks, int price, - int voyages, int reputation, int tank, double tonsPerMile, int crewPerDay, int hullWearCost) + public HullSpec(string name, string description, int columns, int rows, int starterDecks, int maxDecks, int price, + int voyages, int reputation, int tank, double tonsPerMile, int crewPerDay, int hullWearCost, float length, float beam) { Name = name; Description = description; Columns = columns; Rows = rows; + StarterDecks = starterDecks; MaxDecks = maxDecks; Price = price; Voyages = voyages; @@ -43,6 +45,8 @@ namespace Soundings TonsPerMile = tonsPerMile; CrewPerDay = crewPerDay; HullWearCost = hullWearCost; + Length = length; + Beam = beam; } } @@ -91,7 +95,6 @@ namespace Soundings { public const int StarterPortCount = 8; public static int UsedPrice(int hull) => hull == 0 ? 105000 : 245000; - public const int FirstDecks = 2; public const int MaxFleet = 8; public const int Ocean = 2; public const int Bermuda = 5; @@ -117,9 +120,9 @@ namespace Soundings public static readonly IReadOnlyList Hulls = new[] { - new HullSpec("Coastal", "A compact hull for short Caribbean crossings.", 6, 2, 3, 210000, 0, 0, 74, .092, 7200, 1200), - new HullSpec("Regional", "More deck space and range for island chains.", 8, 3, 4, 355000, 3, 24, 185, .121, 12800, 2300), - new HullSpec("Ocean Class", "A transatlantic hull for a world-class flagship.", 10, 3, 6, 690000, 9, 42, 440, .152, 21800, 4700) + new HullSpec("Coastal", "A compact hull for short Caribbean crossings.", 6, 2, 2, 3, 210000, 0, 0, 74, .092, 7200, 1200, 72, 14), + new HullSpec("Regional", "More deck space and range for island chains.", 8, 3, 4, 5, 355000, 3, 24, 185, .121, 12800, 2300, 104, 19), + new HullSpec("Ocean Class", "A transatlantic hull for a world-class flagship.", 10, 3, 6, 8, 690000, 9, 42, 440, .152, 21800, 4700, 142, 25) }; public static readonly IReadOnlyList Ports = new[] diff --git a/Assets/Soundings/Runtime/PassageInterface.cs b/Assets/Soundings/Runtime/PassageInterface.cs index 1a53226..cbf7dac 100644 --- a/Assets/Soundings/Runtime/PassageInterface.cs +++ b/Assets/Soundings/Runtime/PassageInterface.cs @@ -110,11 +110,13 @@ namespace Soundings var camera = Add(rail, "voyage-camera"); AddText(camera, "CAMERA", "voyage-caption"); - AddText(camera, passageBridge || passageExploring || passageServiceArea >= 0 - ? "WASD to walk · Right-drag to look" - : "Wheel to zoom · Hold RMB + WASD / Q E to fly", "voyage-camera-help"); + string cameraHelp = passageBridge && passageHelm.Manual ? "Right-drag to look · Q / E to turn" + : passageBridge || passageExploring ? "WASD to walk · Q / E to turn" + : "Drag or Q / E to orbit · Wheel to zoom"; + AddText(camera, cameraHelp, "voyage-camera-help"); rail.Add(Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now")); - UpdatePassageUi(Mathf.Clamp01(passageElapsed / PassageDuration(underway))); + DrawHelmControls(overlay); + UpdatePassageUi(passageHelm.Progress); } private void DrawPassageBusiness(VisualElement left) @@ -195,9 +197,10 @@ namespace Soundings passageProgress.style.width = Length.Percent(100 * progress); renderedPassageProgress = progress; } - int miles = Mathf.RoundToInt(underway.Miles * (1 - progress)); - int seconds = Mathf.CeilToInt((1 - progress) * PassageDuration(underway) / (passageSpeed * livePassage.SpeedFactor)); - string remaining = $"{miles:N0} nm remaining · {seconds / 60}:{seconds % 60:00} to arrival"; + int miles = Mathf.RoundToInt(underway.Miles * passageHelm.RemainingSeconds / PassageDuration(underway)); + int seconds = Mathf.CeilToInt(passageHelm.RemainingSeconds / (passageSpeed * livePassage.SpeedFactor)); + string status = passageHelm.PropulsionStopped ? "Engines stopped" : $"{seconds / 60}:{seconds % 60:00} estimated"; + string remaining = $"{miles:N0} nm remaining · {status}"; if (passageRemaining.text != remaining) passageRemaining.text = remaining; if (Time.unscaledTime >= nextPassageReadout || livePassage.CurrentEvent?.Title != passageEventTitle) diff --git a/Assets/Soundings/Runtime/ServiceDeckModel.cs b/Assets/Soundings/Runtime/ServiceDeckModel.cs index ed51da1..ef4e777 100644 --- a/Assets/Soundings/Runtime/ServiceDeckModel.cs +++ b/Assets/Soundings/Runtime/ServiceDeckModel.cs @@ -6,39 +6,56 @@ namespace Soundings internal sealed class ServiceDeckModel { public static readonly string[] Areas = { "Engine room", "Galley", "Stores", "Maintenance", "Water plant", "Sewage treatment" }; + private static readonly string[] StationLabels = { "MACHINERY CONTROL", "MAIN GALLEY", "PROVISION STORES", "TECHNICAL WORKSHOP", "FRESH WATER", "WASTEWATER TREATMENT" }; + private const int Wall = 0xB9C1BB, WallBase = 0x718589, Rib = 0x596F75, Floor = 0x344A50, + RoomFloor = 0x505B56, Grating = 0x87989A, Ceiling = 0x869692, Dark = 0x243539, + White = 0xE0DED0, Steel = 0x9AAEB0, SteelDark = 0x526C70, Rubber = 0x263738, + FixtureLight = 0xFFE7BA, EmergencyLight = 0xB9F6D1, Warning = 0xDCAF58, + Red = 0xA64C3E, Motor = 0x547469, Water = 0x397D95, Waste = 0x5C7966, + Amber = 0xE7AA49, Monitor = 0x79B7B6; + private const float CorridorHalfWidth = 1.45f, CeilingHeight = 3.1f; private readonly Dictionary batches = new Dictionary(); private readonly List meshes = new List(); private readonly List materials = new List(); - private readonly float span, width; + private readonly float span, halfWidth, bayLength, doorway; + private readonly Font font; public GameObject Root { get; } + internal ShipWalkSpace WalkSpace { get; } - public ServiceDeckModel(Transform parent, float length, float beam, Shader surface) + public ServiceDeckModel(Transform parent, float length, float beam, Shader fallbackSurface) { span = length * .68f; - width = beam * 1.75f; + halfWidth = Mathf.Clamp(beam * .72f, 4.75f, 7.1f); + bayLength = span / Areas.Length; + doorway = Mathf.Min(3.15f, bayLength * .56f); + WalkSpace = new ShipWalkSpace(-span * .5f, span * .5f, -halfWidth, halfWidth); Root = new GameObject("Service deck"); Root.layer = 8; Root.transform.SetParent(parent, false); - BuildEnvelope(); + font = Resources.Load("Interface"); + BuildPassage(); for (int area = 0; area < Areas.Length; area++) - { - float x = AreaCenter(area); - int accent = area switch { 0 => 0xB88E58, 1 => 0xB77661, 2 => 0x9DA775, 3 => 0xCEAC61, 4 => 0x65B3C7, _ => 0x73AB82 }; - Box(accent, x, .022f, .82f, span / Areas.Length - .35f, .03f, .14f); - Box(0x263744, x, 2.72f, width * .5f - .15f, 4.7f, .64f, .16f); - Sign(Areas[area].ToUpperInvariant(), x, 2.72f, width * .5f - .26f, new Color32(235, 224, 193, 255)); - BuildArea(area, x, accent); - } + BuildBay(area, AreaCenter(area)); + Shader surface = Resources.Load("ServiceSurface"); foreach (var pair in batches) { var game = new GameObject("Service deck finish", typeof(MeshFilter), typeof(MeshRenderer)); game.layer = 8; game.transform.SetParent(Root.transform, false); Mesh mesh = pair.Value.Bake(); - var material = new Material(surface) { color = ColorOf(pair.Key) }; - material.SetFloat("_Roughness", .56f); - material.SetFloat("_Emissive", pair.Key == 0xFFF1C8 ? 1 : .21f); + var material = new Material(surface != null ? surface : fallbackSurface) { color = ColorOf(pair.Key) }; + bool steel = pair.Key is Steel or SteelDark or Grating; + float emission = pair.Key switch { FixtureLight => .85f, EmergencyLight => .60f, Monitor => .34f, Amber => .18f, _ => 0 }; + material.SetFloat("_Roughness", steel ? .30f : .68f); + material.SetFloat("_Metal", steel ? .62f : .025f); + material.SetFloat("_Emissive", emission); + if (surface != null) + { + material.SetFloat("_BayLength", bayLength); + material.SetFloat("_RoomLight", Mathf.Lerp(CorridorHalfWidth, halfWidth, .55f)); + material.SetFloat("_DeckTread", pair.Key is Floor or RoomFloor or Grating ? 1 : 0); + } game.GetComponent().sharedMesh = mesh; game.GetComponent().sharedMaterial = material; meshes.Add(mesh); @@ -48,132 +65,274 @@ namespace Soundings Root.SetActive(false); } - public Vector3 Entry(int area) => new Vector3(AreaCenter(area), 1.65f, -.75f); + public Vector3 Entry(int area) => new Vector3(AreaCenter(area), 1.65f, -.90f); public float Heading(int area) => 0; - private float AreaCenter(int area) => -span * .5f + span * (Mathf.Clamp(area, 0, Areas.Length - 1) + .5f) / Areas.Length; + private float AreaCenter(int area) => -span * .5f + bayLength * (Mathf.Clamp(area, 0, Areas.Length - 1) + .5f); - private void BuildEnvelope() + private void BuildPassage() { - Box(0x596666, 0, -.13f, 0, span, .24f, width); - Box(0x626B6D, 0, 3.31f, 0, span, .22f, width); + Box(RoomFloor, 0, -.10f, 0, span, .18f, halfWidth * 2); + Box(Floor, 0, -.025f, 0, span - .035f, .054f, CorridorHalfWidth * 2); + Box(Ceiling, 0, CeilingHeight + .07f, 0, span, .14f, halfWidth * 2); for (int side = -1; side <= 1; side += 2) { - Box(0x81918C, 0, 1.63f, side * width * .5f, span, 3.35f, .2f); - Box(0x37454D, 0, .32f, side * (width * .5f - .13f), span, .65f, .13f); - Box(0xB8AD82, 0, .018f, side * 1.12f, span - .20f, .024f, .06f); - Box(0x9F6E48, side * span * .5f, 1.62f, 0, .22f, 3.35f, width); - Pipe(0x638FAA, new Vector3(-span * .49f, 2.87f, side * (width * .5f - .43f)), - new Vector3(span * .49f, 2.87f, side * (width * .5f - .43f)), .12f); + Box(Wall, 0, CeilingHeight * .5f, side * halfWidth, span, CeilingHeight, .14f, true); + Box(WallBase, 0, .32f, side * (halfWidth - .078f), span, .62f, .025f); + Box(Wall, side * span * .5f, CeilingHeight * .5f, 0, .18f, CeilingHeight, halfWidth * 2, true); + Box(WallBase, side * (span * .5f - .10f), .30f, 0, .04f, .58f, halfWidth * 2); + Box(WallBase, 0, .003f, side * 1.06f, span - .32f, .012f, .060f); + Pipe(Water, new Vector3(-span * .495f, 2.85f, side * .97f), new Vector3(span * .495f, 2.85f, side * .97f), .060f, 12); + Pipe(0xB88F57, new Vector3(-span * .495f, 2.85f, side * 1.18f), new Vector3(span * .495f, 2.85f, side * 1.18f), .045f, 12); + Box(SteelDark, 0, 2.94f, side * 1.37f, span - .16f, .19f, .19f); + Box(WallBase, 0, 2.92f, side * (halfWidth - .30f), span - .22f, .16f, .38f); + Box(EmergencyLight, side * (span * .5f - .104f), 2.36f, 0, .03f, .17f, .61f); } - - for (int i = 0; i <= 12; i++) + for (int rib = 0; rib <= Areas.Length * 2; rib++) { - float x = span * (i / 12f - .5f); - Box(0x42545A, x, .002f, 0, .043f, .026f, width); - Box(0x52636B, x, 3.13f, 0, .24f, .14f, width); - Box(0xFFF1C8, x, 3.04f, -.20f, .57f, .038f, 1.05f); - } - for (int i = 1; i < Areas.Length; i++) - { - float x = span * (i / (float)Areas.Length - .5f); - Box(0x778580, x, 1.6f, width * .391f, .19f, 3.2f, width * .235f); - Box(0x263744, x, 1.6f, -width * .414f, .19f, 3.2f, width * .18f); + float x = -span * .5f + bayLength * rib * .5f; + Box(Rib, x, 2.96f, 0, .15f, .23f, halfWidth * 2); + if (rib == Areas.Length * 2) + continue; + float fixtureX = x + bayLength * .25f; + Light(fixtureX, 0, 2.90f, 1.26f); + for (int side = -1; side <= 1; side += 2) + Light(fixtureX, side * Mathf.Lerp(CorridorHalfWidth, halfWidth, .55f), 2.93f, 1.4f); } } - private void BuildArea(int area, float x, int accent) + private void BuildBay(int area, float x) { - float wall = width * .5f; - float z = Mathf.Min(3.25f, wall - 1.35f); + float xLeft = x - bayLength * .5f; + float roomWidth = halfWidth - CorridorHalfWidth; + for (int side = -1; side <= 1; side += 2) + { + if (area > 0) + Box(Wall, xLeft, CeilingHeight * .5f, side * (CorridorHalfWidth + roomWidth * .5f), .15f, CeilingHeight, roomWidth, true); + float wallLength = (bayLength - doorway) * .5f; + for (int end = -1; end <= 1; end += 2) + { + float px = x + end * (bayLength + doorway) * .25f; + Box(Wall, px, CeilingHeight * .5f, side * CorridorHalfWidth, wallLength, CeilingHeight, .14f, true); + Box(WallBase, px, .34f, side * (CorridorHalfWidth - .078f), wallLength - .04f, .60f, .035f); + Box(Rib, x + end * (doorway * .5f + .045f), 1.10f, side * CorridorHalfWidth, .116f, 2.20f, .21f, true); + } + Box(Wall, x, 2.66f, side * CorridorHalfWidth, doorway, .89f, .14f); + Box(Rib, x, 2.215f, side * CorridorHalfWidth, doorway + .19f, .12f, .24f); + Box(SteelDark, x, .022f, side * CorridorHalfWidth, doorway, .045f, .32f); + Box(Grating, x, .048f, side * CorridorHalfWidth, doorway - .13f, .016f, .29f); + } + Box(Dark, x, 2.55f, CorridorHalfWidth - .084f, Mathf.Min(doorway - .12f, 2.68f), .295f, .04f); + Sign(StationLabels[area], x, 2.55f, CorridorHalfWidth - .111f, .034f, White); + Box(Warning, x, 2.37f, CorridorHalfWidth - .092f, .27f, .026f, .037f); + + float z = halfWidth - 1.13f; + float workSpan = Mathf.Min(bayLength - .90f, 7f); switch (area) { - case 0: - for (int side = -1; side <= 1; side += 2) - { - Box(0x3D484B, x, .16f, side * z, 5.4f, .33f, 1.75f); - Box(accent, x, .69f, side * z, 4.7f, .92f, 1.35f); - Pipe(0x526A74, new Vector3(x - 3.05f, .69f, side * z), new Vector3(x + 2.35f, .69f, side * z), .18f); - for (int i = -2; i <= 2; i++) - { - Box(0x7B8584, x + i * .86f, 1.27f, side * z, .51f, .30f, .80f); - Pipe(0xAA8170, new Vector3(x + i * .86f, 1.38f, side * z), new Vector3(x + i * .86f, 2.64f, side * z), .079f); - } - } - Panel(x + 2.94f, z, 0x62F0B4); - break; - case 1: - Box(0x92A19F, x, .49f, z, 5.40f, .92f, 1.54f); - Box(0xC7C8B9, x, 1.00f, z, 5.65f, .14f, 1.69f); - for (int i = 0; i < 3; i++) - { - float px = x - 1.65f + i * 1.66f; - Box(0x293943, px, 1.10f, z, 1.12f, .08f, 1.08f); - Pipe(accent, new Vector3(px, 1.12f, z), new Vector3(px, 1.38f, z), .26f); - } - Box(0x657478, x, 2.29f, z + .1f, 5.49f, .42f, 1.55f); - Box(0x839690, x, .61f, -z, 3.8f, 1.22f, 1.55f); - break; - case 2: - for (int shelf = 1; shelf <= 3; shelf++) - { - float level = shelf * .62f; - Box(0x655C48, x, level, z, 5.4f, .10f, 1.40f); - for (int i = -2; i <= 2; i++) - Box(i % 2 == 0 ? accent : 0xAF8F70, x + .91f * i, level + .21f, z, .70f, .36f, .76f); - } - for (int side = -1; side <= 1; side += 2) - Box(0x626B62, x + side * 2.45f, 1.13f, z, .12f, 2.26f, 1.59f); - break; - case 3: - Box(0x656B69, x, .48f, z, 5.30f, .93f, 1.35f); - Box(accent, x, .99f, z, 5.53f, .13f, 1.5f); - Box(0x4D6062, x, 1.83f, z + .65f, 5.30f, 1.01f, .14f); - for (int i = -3; i <= 3; i++) - { - float px = x + .61f * i; - Pipe(0xD2CAAF, new Vector3(px, 1.51f, z + .53f), new Vector3(px, 1.96f, z + .53f), .043f); - Box(i % 2 == 0 ? 0xAC784C : 0x748C84, px, 1.42f, z + .53f, .12f, .18f, .14f); - } - Box(0x705E56, x, .59f, -z, 3.14f, 1.18f, 1.25f); - break; - default: - for (int i = -1; i <= 1; i++) - { - float px = x + 1.49f * i; - Pipe(accent, new Vector3(px, .35f, z), new Vector3(px, 2.40f, z), .56f, 16); - Pipe(0xC3BFA7, new Vector3(px, 2.34f, z), new Vector3(px, 2.72f, z), .105f); - Box(0x3F5358, px, 1.40f, z - .49f, .24f, .48f, .26f); - } - Pipe(accent, new Vector3(x - 2.85f, 2.7f, z), new Vector3(x + 2.85f, 2.7f, z), .12f); - Panel(x + 2.94f, z, accent); - break; + case 0: Machinery(x, z, workSpan); break; + case 1: Galley(x, z, workSpan); break; + case 2: Stores(x, z, workSpan); break; + case 3: Workshop(x, z, workSpan); break; + case 4: Plant(x, z, workSpan, true); break; + case 5: Plant(x, z, workSpan, false); break; } } - private void Panel(float x, float z, int signal) + private void Machinery(float x, float z, float span) { - Box(0x48595E, x, .66f, z, .96f, 1.32f, .83f); - Box(0x223240, x, 1.32f, z - .16f, 1.02f, .39f, .65f); - for (int i = -1; i <= 1; i++) - Box(signal, x + i * .21f, 1.38f, z - .493f, .08f, .08f, .022f); + float engineLength = span * .63f; + for (int side = -1; side <= 1; side += 2) + { + float px = x - span * .13f; + float pz = side * (z - .48f); + Box(Dark, px, .10f, pz, engineLength + .59f, .19f, 1.53f, true); + Box(Motor, px, .65f, pz, engineLength, .81f, 1.05f); + Box(SteelDark, px, 1.07f, pz, engineLength - .08f, .17f, .98f); + Box(Rubber, px + engineLength * .31f, .65f, pz - side * .55f, engineLength * .29f, .45f, .055f); + Pipe(SteelDark, new Vector3(px - engineLength * .64f, .67f, pz), new Vector3(px - engineLength * .48f, .67f, pz), .43f, 18); + for (int i = 0; i < 5; i++) + { + float piston = px - engineLength * .40f + engineLength * .19f * i; + Box(Motor, piston, 1.17f, pz, engineLength * .15f, .19f, .69f); + Pipe(Steel, new Vector3(piston, 1.26f, pz), new Vector3(piston, 1.54f, pz + .26f), .074f, 12); + Pipe(Steel, new Vector3(piston, 1.54f, pz + .26f), new Vector3(piston, 1.54f, pz + .55f), .074f, 12); + Box(SteelDark, piston, .68f, pz - side * .53f, .059f, .55f, .061f); + } + Pipe(Steel, new Vector3(px - engineLength * .47f, 1.54f, pz + .55f), new Vector3(px + engineLength * .49f, 1.54f, pz + .55f), .112f, 14); + for (int i = 0; i < 9; i++) + Box(SteelDark, px + engineLength * (.188f + .029f * i), .66f, pz - side * .587f, .041f, .35f, .035f); + Box(Warning, px - engineLength * .29f, .64f, pz - side * .544f, .22f, .13f, .018f); + Box(Warning, px, .01f, pz - side * 1.00f, engineLength + .62f, .017f, .039f); + Pipe(Steel, new Vector3(px - engineLength * .43f, 1.21f, pz + side * .37f), new Vector3(px - engineLength * .43f, 2.72f, pz + side * .37f), .119f, 15); + } + ControlCabinet(x + span * .34f, z - .23f, 1.04f, "PROPULSION"); + ControlCabinet(x + span * .36f, -z + .28f, .91f, null); } - private void Sign(string words, float x, float y, float z, Color color) + private void Galley(float x, float z, float span) + { + float range = span * .70f; + float px = x - span * .12f; + Counter(SteelDark, px, z + .05f, range, .91f); + Box(Steel, px, 1.94f, z + .41f, range + .14f, 1.31f, .11f); + Box(Steel, px, 2.11f, z + .09f, range + .38f, .32f, 1.15f); + Box(Rubber, px, 1.938f, z - .05f, range + .12f, .04f, .77f); + Box(FixtureLight, px, 1.904f, z - .38f, range * .84f, .025f, .055f); + for (int i = 0; i < 4; i++) + { + float sx = px + range * (.25f * i - .375f); + Box(Dark, sx, .53f, z - .39f, range * .20f, .37f, .020f); + Box(Steel, sx, .732f, z - .402f, range * .16f, .041f, .056f); + Pipe(Rubber, new Vector3(sx, .99f, z + .02f), new Vector3(sx, 1.042f, z + .02f), .18f, 18); + Pipe(Steel, new Vector3(sx, 1.043f, z + .02f), new Vector3(sx, 1.06f, z + .02f), .128f, 18); + Box(Amber, sx - .12f, .86f, z - .40f, .024f, .035f, .015f); + } + Counter(Steel, x, -z + .22f, span * .64f, 1.05f); + Box(White, x - span * .14f, 1.03f, -z + .24f, .54f, .071f, .38f); + Box(Red, x - span * .145f, 1.09f, -z + .18f, .24f, .065f, .24f); + ColdCabinet(x + span * .37f, z, .88f); + } + + private void Stores(float x, float z, float span) + { + float rackWidth = span * .74f; + ProvisionRack(x - span * .12f, z + .10f, rackWidth, .74f); + ProvisionRack(x, -z + .13f, span * .78f, .74f); + ColdCabinet(x + span * .39f, z, .83f); + Box(Warning, x, .013f, z - .62f, span * .90f, .019f, .042f); + } + + private void ProvisionRack(float x, float z, float span, float depth) + { + WalkSpace.Block(new Vector3(x, 1.07f, z), new Vector3(span, 2.14f, depth)); + for (int level = 0; level < 3; level++) + { + float y = .26f + level * .59f; + Box(SteelDark, x, y, z, span, .09f, depth); + for (int bin = 0; bin < 6; bin++) + { + float bx = x + (bin - 2.5f) * span / 6; + float bWidth = span / 6 - .07f; + int color = ((level + bin * 2) % 4) switch { 0 => 0xAD875C, 1 => 0xB8A88A, 2 => 0x657F70, _ => 0xB2AB91 }; + Box(color, bx, y + .24f, z, bWidth, .38f, depth - .15f); + Box(White, bx - bWidth * .28f, y + .26f, z - Mathf.Sign(z) * (depth * .5f - .074f), .12f, .083f, .014f); + } + } + for (int side = -1; side <= 1; side += 2) + for (int brace = -1; brace <= 1; brace += 2) + Box(SteelDark, x + side * (span * .5f - .04f), 1.05f, z + brace * (depth * .5f - .042f), .081f, 2.10f, .075f); + } + + private void Workshop(float x, float z, float span) + { + float bench = span * .78f; + Counter(SteelDark, x, z + .12f, bench, .81f); + Box(Dark, x, 1.57f, z + .54f, bench, .86f, .073f); + Box(FixtureLight, x, 2.01f, z + .48f, bench * .84f, .04f, .085f); + for (int i = 0; i < 6; i++) + { + float handleX = x + (i - 2.5f) * bench / 7; + Pipe(Steel, new Vector3(handleX, 1.34f, z + .48f), new Vector3(handleX + .06f, 1.73f, z + .48f), .032f); + Box(Warning, handleX, 1.34f, z + .48f, .08f, .102f, .042f); + } + Box(Red, x - bench * .22f, 1.08f, z + .13f, .47f, .35f, .52f); + Box(Steel, x - bench * .22f, 1.22f, z + .13f, .53f, .082f, .55f); + float lockerX = x + span * .22f; + Box(Dark, lockerX, .70f, -z, 1.32f, 1.39f, .62f, true); + for (int i = 0; i < 5; i++) + { + float y = .22f + i * .22f; + Box(Red, lockerX, y, -z + .328f, 1.21f, .18f, .071f); + Box(Steel, lockerX, y + .03f, -z + .376f, .69f, .034f, .021f); + } + ColdCabinet(x - span * .26f, -z, .81f); + } + + private void Plant(float x, float z, float span, bool fresh) + { + int paint = fresh ? Water : Waste; + string label = fresh ? "POTABLE" : "BIOREACTOR"; + float start = x - span * .33f; + for (int side = -1; side <= 1; side += 2) + { + float pz = side * (z - .22f); + for (int i = 0; i < 3; i++) + { + float tankX = start + i * span * .239f; + float tankRadius = Mathf.Min(.49f, span * .103f); + Box(Dark, tankX, .14f, pz, tankRadius * 2.27f, .25f, tankRadius * 2.25f, true); + Pipe(paint, new Vector3(tankX, .24f, pz), new Vector3(tankX, 2.15f, pz), tankRadius, 22); + for (int band = 0; band <= 2; band++) + { + float height = .38f + band * .79f; + Pipe(SteelDark, new Vector3(tankX, height, pz), new Vector3(tankX, height + .081f, pz), tankRadius + .018f, 22); + } + Pipe(Steel, new Vector3(tankX, 2.10f, pz), new Vector3(tankX, 2.65f, pz), .094f, 13); + Pipe(White, new Vector3(tankX, 1.23f, pz - side * (tankRadius - .01f)), new Vector3(tankX, 1.23f, pz - side * (tankRadius + .092f)), .112f, 18); + Box(Warning, tankX, .98f, pz - side * (tankRadius + .012f), .19f, .09f, .024f); + } + Pipe(paint, new Vector3(start - .19f, 2.64f, pz), new Vector3(x + span * .31f, 2.64f, pz), .113f, 14); + Pipe(SteelDark, new Vector3(start - .16f, .49f, pz - side * .28f), new Vector3(x + span * .36f, .49f, pz - side * .28f), .093f, 14); + } + ControlCabinet(x + span * .37f, z, .80f, label); + } + + private void Counter(int finish, float x, float z, float span, float depth) + { + Box(finish, x, .43f, z, span, .82f, depth - .09f); + Box(Steel, x, .91f, z, span + .12f, .13f, depth, true); + Box(Rubber, x, .08f, z, span, .16f, depth - .21f); + } + + private void ColdCabinet(float x, float z, float width) + { + float front = z - Mathf.Sign(z) * .49f; + Box(SteelDark, x, 1.04f, z, width, 2.08f, .95f, true); + Box(Steel, x, 1.11f, front, width - .095f, 1.71f, .11f); + Box(Dark, x, .14f, front, width - .14f, .14f, .079f); + for (int vent = 0; vent < 5; vent++) + Box(Steel, x, .099f + vent * .019f, front - Mathf.Sign(z) * .042f, width - .20f, .009f, .022f); + Pipe(Rubber, new Vector3(x - width * .27f, .79f, front - Mathf.Sign(z) * .068f), + new Vector3(x - width * .27f, 1.14f, front - Mathf.Sign(z) * .068f), .039f); + } + + private void ControlCabinet(float x, float z, float width, string words) + { + float side = Mathf.Sign(z); + float face = z - side * .334f; + Box(SteelDark, x, .91f, z, width, 1.82f, .68f, true); + Box(Steel, x, .90f, face, width - .052f, 1.55f, .047f); + Box(Dark, x, 1.30f, face - side * .028f, width * .69f, .36f, .021f); + Box(Monitor, x, 1.32f, face - side * .043f, width * .53f, .22f, .019f); + for (int row = 0; row < 4; row++) + Box(SteelDark, x, 1.26f + row * .04f, face - side * .055f, width * .42f, .012f, .011f); + for (int lamp = -1; lamp <= 1; lamp++) + Box(lamp == 1 ? Amber : EmergencyLight, x + lamp * width * .17f, .99f, face - side * .038f, .054f, .040f, .019f); + if (words != null) + Sign(words, x, 1.63f, face - side * .040f, .035f, Dark); + } + + private void Light(float x, float z, float y, float length) + { + Box(SteelDark, x, y, z, length + .12f, .10f, .25f); + Box(FixtureLight, x, y - .057f, z, length, .034f, .135f); + } + + private void Sign(string words, float x, float y, float z, float size, int color) { var game = new GameObject(words, typeof(TextMesh)); game.layer = 8; game.transform.SetParent(Root.transform, false); game.transform.localPosition = new Vector3(x, y, z); var text = game.GetComponent(); - Font font = Resources.Load("Interface"); text.font = font; text.text = words; text.fontStyle = FontStyle.Bold; - text.fontSize = 52; - text.characterSize = .10f; + text.fontSize = 48; + text.characterSize = size; text.anchor = TextAnchor.MiddleCenter; - text.color = color; + text.color = ColorOf(color); game.GetComponent().sharedMaterial = font.material; } @@ -187,10 +346,16 @@ namespace Soundings return mesh; } - private void Box(int color, float x, float y, float z, float w, float h, float d) => - Paint(color).Box(new Vector3(x, y, z), new Vector3(w, h, d)); + private void Box(int color, float x, float y, float z, float w, float h, float d, bool solid = false) + { + var center = new Vector3(x, y, z); + var size = new Vector3(w, h, d); + Paint(color).Box(center, size); + if (solid) + WalkSpace.Block(center, size); + } - private void Pipe(int color, Vector3 from, Vector3 to, float radius, int sides = 9) => Paint(color).Rod(from, to, radius, sides); + private void Pipe(int color, Vector3 from, Vector3 to, float radius, int sides = 10) => Paint(color).Rod(from, to, radius, sides); private static Color32 ColorOf(int rgb) => new Color32((byte)(rgb >> 16), (byte)(rgb >> 8), (byte)rgb, 255); diff --git a/Assets/Soundings/Runtime/ShipWalkSpace.cs b/Assets/Soundings/Runtime/ShipWalkSpace.cs new file mode 100644 index 0000000..90901e7 --- /dev/null +++ b/Assets/Soundings/Runtime/ShipWalkSpace.cs @@ -0,0 +1,129 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace Soundings +{ + internal sealed class ShipWalkSpace + { + private const float BodyRadius = .29f; + private const float ContactGap = .006f; + private const float MinMotion = .0001f; + private readonly Rect limits; + private readonly List solids = new(); + + public ShipWalkSpace(float minX, float maxX, float minZ, float maxZ) + { + limits = Rect.MinMaxRect(minX + BodyRadius, minZ + BodyRadius, maxX - BodyRadius, maxZ - BodyRadius); + } + + // A room's solids and camera both use vessel coordinates, so heave and travel never move one through the other. + public void Block(Vector3 center, Vector3 size) => Block(Plan(center), Plan(size)); + + public void Block(Vector2 center, Vector2 size) + { + Vector2 half = size * .5f + Vector2.one * BodyRadius; + solids.Add(Rect.MinMaxRect(center.x - half.x, center.y - half.y, center.x + half.x, center.y + half.y)); + } + + public bool CanStand(Vector3 position) => CanStand(Plan(position)); + + public Vector3 Entry(Vector3 requested) + { + Vector2 origin = Confine(Plan(requested)); + if (CanStand(origin)) + return AtHeight(origin, requested.y); + + // Keep entry safe even after a refit puts furniture close to the original spawn. + for (float radius = .12f; radius <= 4; radius += .12f) + { + for (int i = 0; i < 24; i++) + { + float angle = i * (Mathf.PI / 12f); + Vector2 nearby = Confine(origin + radius * new Vector2(Mathf.Cos(angle), Mathf.Sin(angle))); + if (CanStand(nearby)) + return AtHeight(nearby, requested.y); + } + } + return AtHeight(origin, requested.y); + } + + public Vector3 Move(Vector3 position, Vector3 motion) + { + Vector2 origin = Plan(position); + if (!CanStand(origin)) + return Entry(position); + + Vector2 remaining = Plan(motion); + for (int contact = 0; contact < 4; contact++) + { + remaining = Confine(origin + remaining) - origin; + if (remaining.sqrMagnitude < MinMotion * MinMotion) + break; + + float time = 1; + Vector2 normal = Vector2.zero; + foreach (Rect solid in solids) + { + if (Sweep(origin, remaining, solid, out float hit, out Vector2 surface) && hit < time) + { + time = hit; + normal = surface; + } + } + + if (normal == Vector2.zero) + { + origin += remaining; + break; + } + + float shortOfContact = Mathf.Max(0, time - ContactGap / remaining.magnitude); + origin += remaining * shortOfContact; + remaining *= 1 - time; + remaining -= Vector2.Dot(remaining, normal) * normal; + } + return AtHeight(Confine(origin), position.y); + } + + private bool CanStand(Vector2 point) + { + if (point.x < limits.xMin || point.x > limits.xMax || point.y < limits.yMin || point.y > limits.yMax) + return false; + foreach (Rect solid in solids) + if (solid.xMin < point.x && point.x < solid.xMax && solid.yMin < point.y && point.y < solid.yMax) + return false; + return true; + } + + private static bool Sweep(Vector2 origin, Vector2 motion, Rect solid, out float time, out Vector2 normal) + { + time = 0; + float exit = 1; + normal = Vector2.zero; + return SweepAxis(origin.x, motion.x, solid.xMin, solid.xMax, Vector2.right, ref time, ref exit, ref normal) + && SweepAxis(origin.y, motion.y, solid.yMin, solid.yMax, Vector2.up, ref time, ref exit, ref normal) + && normal != Vector2.zero && time < exit; + } + + private static bool SweepAxis(float origin, float motion, float lower, float upper, Vector2 axis, + ref float enter, ref float exit, ref Vector2 normal) + { + if (motion == 0) + return lower < origin && origin < upper; + float first = (lower - origin) / motion; + float second = (upper - origin) / motion; + float near = Mathf.Min(first, second); + if (near >= enter) + { + enter = near; + normal = motion > 0 ? -axis : axis; + } + exit = Mathf.Min(exit, Mathf.Max(first, second)); + return enter <= exit; + } + + private Vector2 Confine(Vector2 point) => new(Mathf.Clamp(point.x, limits.xMin, limits.xMax), Mathf.Clamp(point.y, limits.yMin, limits.yMax)); + private static Vector2 Plan(Vector3 point) => new(point.x, point.z); + private static Vector3 AtHeight(Vector2 point, float height) => new(point.x, height, point.y); + } +} diff --git a/Assets/Soundings/Runtime/ShipWalkSpace.cs.meta b/Assets/Soundings/Runtime/ShipWalkSpace.cs.meta new file mode 100644 index 0000000..e3e0076 --- /dev/null +++ b/Assets/Soundings/Runtime/ShipWalkSpace.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: c8425de6006543478f18cacdecff62b0 diff --git a/Assets/Soundings/Runtime/SoundingsApp.cs b/Assets/Soundings/Runtime/SoundingsApp.cs index acc7a17..3f006df 100644 --- a/Assets/Soundings/Runtime/SoundingsApp.cs +++ b/Assets/Soundings/Runtime/SoundingsApp.cs @@ -75,7 +75,10 @@ namespace Soundings { Company loaded = JsonUtility.FromJson(PlayerPrefs.GetString(SaveKey)); if (loaded != null && loaded.CanLoad()) + { + loaded.RestoreHullDecks(); return loaded; + } } catch (ArgumentException exception) { @@ -464,7 +467,7 @@ namespace Soundings if (paused || pointerId >= 0 || (evt.button != 0 && evt.button != 1)) return; pointerId = evt.pointerId; - freeLook = underway != null && evt.button == 1; + freeLook = underway != null && evt.button == 1 && (passageBridge || passageExploring); SetPassageFreeLook(freeLook); start = last = evt.localPosition; dragging = false; diff --git a/Assets/Soundings/Runtime/VesselExterior.cs b/Assets/Soundings/Runtime/VesselExterior.cs index 8e99740..5140cb2 100644 --- a/Assets/Soundings/Runtime/VesselExterior.cs +++ b/Assets/Soundings/Runtime/VesselExterior.cs @@ -5,6 +5,7 @@ namespace Soundings { internal sealed class VesselExterior { + internal const float DeckBase = 5.38f, DeckSpacing = 2.62f; internal enum Paint { Navy, Ivory, Pearl, Gold, Teak, TeakSeam, Steel, Black, Glass, BlueGlass, LitGlass, Lounge, Lifeboat, Pool } private readonly Dictionary batches = new Dictionary(); @@ -50,7 +51,7 @@ namespace Soundings new Vector3(1.013f, 5.14f, 1.027f), new Vector3(1.003f, 5.32f, 1.015f)); Vector2[] promenade = Outline(length * .971f, beam * .979f, 0); Coat(Paint.Teak).Loft(promenade, center, true, new Vector3(.997f, 5.32f, 1), - new Vector3(1, 5.38f, 1)); + new Vector3(1, DeckBase, 1)); Rails(promenade, 5.39f, 5.99f, 2.7f); for (int side = -1; side <= 1; side += 2) @@ -80,18 +81,19 @@ namespace Soundings private void BuildPassengerDeck(int deck) { - float y = 5.38f + deck * 1.88f; + float y = DeckBase + deck * DeckSpacing; + float roof = y + DeckSpacing; var (deckLength, deckBeam, offset) = DeckFootprint(deck); Vector2 center = new Vector2(offset, 0); Vector2[] outline = Outline(deckLength, deckBeam, offset); Coat(Paint.Ivory).Loft(outline, center, false, new Vector3(.97f, y, .77f), - new Vector3(.99f, y + .25f, .83f), new Vector3(.99f, y + 1.49f, .83f)); - Coat(Paint.Pearl).Loft(outline, center, true, new Vector3(.993f, y + 1.49f, .96f), - new Vector3(1.017f, y + 1.57f, 1.01f), new Vector3(1.017f, y + 1.73f, 1.015f), - new Vector3(1, y + 1.82f, 1)); - Coat(Paint.Teak).Loft(outline, center, true, new Vector3(.992f, y + 1.82f, .989f), - new Vector3(.994f, y + 1.88f, .992f)); - Rails(outline, y + 1.88f, y + 2.38f, 2.4f); + new Vector3(.99f, y + .25f, .83f), new Vector3(.99f, roof - .39f, .83f)); + Coat(Paint.Pearl).Loft(outline, center, true, new Vector3(.993f, roof - .39f, .96f), + new Vector3(1.017f, roof - .31f, 1.01f), new Vector3(1.017f, roof - .15f, 1.015f), + new Vector3(1, roof - .06f, 1)); + Coat(Paint.Teak).Loft(outline, center, true, new Vector3(.992f, roof - .06f, .989f), + new Vector3(.994f, roof, .992f)); + Rails(outline, roof, roof + .73f, 2.4f); float width = .70f * deckLength / balconies; for (int i = 0; i < balconies; i++) @@ -105,8 +107,8 @@ namespace Soundings int row = side < 0 ? 0 : ship.Hull.Rows - 1; Facility facility = ship.Decks[deck].Cells[row * ship.Hull.Columns + column]; float z = side * deckBeam * cross; - Vector3 glass = new Vector3(x, y + .91f, z * .846f); - Coat(Paint.Black).Box(glass, new Vector3(width * 1.01f, 1.21f, .17f)); + Vector3 glass = new Vector3(x, y + 1.27f, z * .846f); + Coat(Paint.Black).Box(glass, new Vector3(width * 1.01f, 1.80f, .17f)); float divider = width * .21f; Paint illumination = facility switch { @@ -118,14 +120,14 @@ namespace Soundings }; for (int pane = -1; pane <= 1; pane += 2) Coat(pane < 0 ? illumination : Paint.BlueGlass).Box(glass + new Vector3(pane * divider, .025f, side * .09f), - new Vector3(width * .38f, .98f, .09f)); + new Vector3(width * .38f, 1.54f, .09f)); if (facility == Facility.Tank) continue; Coat(Paint.Teak).Box(new Vector3(x, y + .28f, z * .935f), new Vector3(width * 1.10f, .12f, Mathf.Abs(z) * .19f)); - Coat(Paint.BlueGlass).Box(new Vector3(x, y + .48f, z * 1.016f), new Vector3(width * .96f, .32f, .05f)); - Coat(Paint.Pearl).Box(new Vector3(x, y + .67f, z * 1.02f), new Vector3(width * 1.045f, .047f, .055f)); - Coat(Paint.Pearl).Box(new Vector3(x + width * .52f, y + .52f, z * 1.02f), new Vector3(.055f, .32f, .075f)); + Coat(Paint.BlueGlass).Box(new Vector3(x, y + .63f, z * 1.016f), new Vector3(width * .96f, .48f, .05f)); + Coat(Paint.Pearl).Box(new Vector3(x, y + .92f, z * 1.02f), new Vector3(width * 1.045f, .047f, .055f)); + Coat(Paint.Pearl).Box(new Vector3(x + width * .52f, y + .65f, z * 1.02f), new Vector3(.055f, .52f, .075f)); } } } @@ -134,31 +136,31 @@ namespace Soundings { int deck = ship.Decks.Count - 1; var (deckLength, deckBeam, offset) = DeckFootprint(deck); - float top = 5.38f + ship.Decks.Count * 1.88f; - float bridge = offset + deckLength * .30f; + float top = DeckBase + ship.Decks.Count * DeckSpacing; + float bridge = BridgeCenter(length, ship.Decks.Count); Vector2 center = new Vector2(bridge, 0); - Vector2[] capsule = Outline(deckLength * .27f, deckBeam * .83f, bridge); + Vector2[] capsule = Outline(9.15f, beam * .67f, bridge); Coat(Paint.Ivory).Loft(capsule, center, false, new Vector3(.91f, top, .91f), - new Vector3(1, top + .32f, 1)); - Coat(Paint.Glass).Loft(capsule, center, false, new Vector3(1, top + .32f, 1), - new Vector3(.90f, top + 1.09f, .95f)); - Coat(Paint.Pearl).Loft(capsule, center, true, new Vector3(.905f, top + 1.07f, .955f), - new Vector3(.975f, top + 1.22f, 1.025f), new Vector3(.82f, top + 1.40f, .90f)); + new Vector3(1, top + .88f, 1)); + Coat(Paint.Glass).Loft(capsule, center, false, new Vector3(1, top + .88f, 1), + new Vector3(.90f, top + 2.62f, .95f)); + Coat(Paint.Pearl).Loft(capsule, center, true, new Vector3(.905f, top + 2.59f, .955f), + new Vector3(.975f, top + 2.72f, 1.025f), new Vector3(.82f, top + 2.91f, .90f)); foreach (Vector2 point in capsule) if (point.x > bridge - .5f) - Coat(Paint.Steel).Rod(HarborMesh.Point(center + (point - center), top + .34f), - HarborMesh.Point(center + (point - center) * .937f, top + 1.08f), .026f); + Coat(Paint.Steel).Rod(HarborMesh.Point(point, top + .89f), + HarborMesh.Point(center + Vector2.Scale(point - center, new Vector2(.90f, .95f)), top + 2.61f), .031f); float mast = bridge + 1.15f; - Coat(Paint.Ivory).Rod(new Vector3(mast, top + 1.38f, 0), new Vector3(mast - .48f, top + 4.22f, 0), .135f, 8); + Coat(Paint.Ivory).Rod(new Vector3(mast, top + 2.88f, 0), new Vector3(mast - .48f, top + 5.72f, 0), .135f, 8); for (int i = 0; i < 3; i++) { - float y = top + 1.85f + i * .66f; + float y = top + 3.35f + i * .66f; float span = 1.98f - i * .36f; Coat(Paint.Pearl).Rod(new Vector3(mast - .27f, y, -span), new Vector3(mast - .27f, y, span), .055f); Coat(Paint.Black).Rod(new Vector3(mast - .24f, y, span * .84f), new Vector3(mast - .24f, y + .40f, span * .84f), .022f); } - Coat(Paint.LitGlass).Radome(new Vector3(mast - .48f, top + 4.27f, 0), .13f); + Coat(Paint.LitGlass).Radome(new Vector3(mast - .48f, top + 5.77f, 0), .13f); float stack = offset - deckLength * .24f; for (int side = -1; side <= 1; side += 2) @@ -236,11 +238,19 @@ namespace Soundings } } - private (float Length, float Beam, float Offset) DeckFootprint(int deck) + internal static float BridgeCenter(float hullLength, int deckCount) { - return (length * (.79f - .038f * deck), beam * (.84f - .030f * deck), -length * .034f - deck * .51f); + int deck = deckCount - 1; + return DeckOffset(hullLength, deck) + DeckLength(hullLength, deck) * .29f; } + internal static float DeckLength(float hullLength, int deck) => hullLength * (.81f - .027f * deck); + internal static float DeckOffset(float hullLength, int deck) => -hullLength * (.034f + .0065f * deck); + internal static float DeckHalfBeam(float halfBeam, int deck) => halfBeam * (.85f - .024f * deck); + + private (float Length, float Beam, float Offset) DeckFootprint(int deck) => + (DeckLength(length, deck), DeckHalfBeam(beam, deck), DeckOffset(length, deck)); + private static float SideWidth(float t) { if (t < .16f) diff --git a/Assets/Soundings/Runtime/VisualSmoke.cs b/Assets/Soundings/Runtime/VisualSmoke.cs index d09ed0f..be8b45c 100644 --- a/Assets/Soundings/Runtime/VisualSmoke.cs +++ b/Assets/Soundings/Runtime/VisualSmoke.cs @@ -61,12 +61,54 @@ namespace Soundings if (!SubmitSmoke("passage-deck-1") || !CheckSmoke(passageDeck == 1, "Inspect the second guest deck")) yield break; yield return CaptureSmoke(directory, "06-guest-deck"); - if (!SubmitSmoke("passage-bridge") || !CheckSmoke(passageBridge, "Enter the first-person bridge")) + if (!SubmitSmoke("passage-bridge") || !CheckSmoke(passageBridge && harbor.FirstPersonPositionIsClear, "Enter the first-person bridge")) yield break; yield return CaptureSmoke(directory, "06a-bridge"); + Vector3 bridgeEntry = harbor.FirstPersonPosition; + WalkSmoke(Vector2.up, 35); + float bridgeWalk = Vector3.Distance(bridgeEntry, harbor.FirstPersonPosition); + if (!CheckSmoke(bridgeWalk > 1 && bridgeWalk < 3 && harbor.FirstPersonPositionIsClear, "Bridge console blocks grounded movement") + || !SubmitSmoke("passage-camera-reset") || !SubmitSmoke("helm-toggle") + || !CheckSmoke(passageHelm.Manual, "Take physical control on the bridge")) + yield break; + passageHelm.Advance(8, 0, livePassage.SpeedFactor, underway.Weather); + float originalHeading = passageHelm.Heading; + for (int i = 0; i < 100; i++) + passageHelm.Advance(.1f, 1, livePassage.SpeedFactor, underway.Weather); + PresentVessel(.1f); + if (!CheckSmoke(passageHelm.Heading > originalHeading + 5 && passageHelm.Position.y > .3f, "Rudder changes the ship heading and track")) + yield break; + yield return CaptureSmoke(directory, "06a-manual-helm"); + if (!SubmitSmoke("helm-order-0") || !CheckSmoke(passageHelm.PropulsionStopped, "Stop order at the helm")) + yield break; + float coastingSpeed = passageHelm.Speed; + passageHelm.Advance(.55f, 0, livePassage.SpeedFactor, underway.Weather); + if (!CheckSmoke(passageHelm.Speed > 0 && passageHelm.Speed < coastingSpeed, "Ship coasts when propulsion is stopped") + || !SubmitSmoke("helm-toggle") || !CheckSmoke(!passageHelm.Manual && !passageHelm.PropulsionStopped, "Autopilot resumes propulsion")) + yield break; if (!SubmitSmoke("passage-deck-0") || !SubmitSmoke("passage-explore") - || !CheckSmoke(passageExploring && passageDeck == 0, "Explore inside the cabin deck") - || !SubmitSmoke("passage-service") || !CheckSmoke(passageServiceArea == 0, "Enter engineering")) + || !CheckSmoke(passageExploring && passageDeck == 0 && harbor.FirstPersonPositionIsClear, "Explore inside the cabin deck")) + yield break; + yield return CaptureSmoke(directory, "06a-cabin-corridor"); + Vector3 corridorEntry = harbor.FirstPersonPosition; + WalkSmoke(Vector2.up, 9); + WalkSmoke(Vector2.right, 12); + Vector3 nearBulkhead = harbor.FirstPersonPosition; + if (!CheckSmoke(nearBulkhead.x > corridorEntry.x + 2 && Mathf.Abs(nearBulkhead.z - corridorEntry.z) < .8f, + "Cabin corridor is clear and bulkheads block sideways movement")) + yield break; + WalkSmoke(Vector2.up, 8); + WalkSmoke(Vector2.right, 6); + if (!CheckSmoke(Mathf.Abs(harbor.FirstPersonPosition.z - corridorEntry.z) > 1 && harbor.FirstPersonPositionIsClear, + "Walk into a cabin through its open doorway")) + yield break; + if (!SubmitSmoke("passage-service") || !CheckSmoke(passageServiceArea == 0 && harbor.FirstPersonPositionIsClear, "Enter engineering")) + yield break; + Vector3 serviceEntry = harbor.FirstPersonPosition; + WalkSmoke(Vector2.up, 38); + float serviceWalk = Vector3.Distance(serviceEntry, harbor.FirstPersonPosition); + if (!CheckSmoke(serviceWalk > 1.6f && serviceWalk < 5 && harbor.FirstPersonPositionIsClear, "Walk through an engineering doorway and stop at the machinery") + || !SubmitSmoke("passage-camera-reset")) yield break; int cruiseBurn = livePassage.ProjectedFuelBurn; if (!SubmitSmoke("service-engine-0") || !CheckSmoke(livePassage.ProjectedFuelBurn < cruiseBurn, "Economy throttle saves fuel") @@ -83,9 +125,9 @@ namespace Soundings yield break; if (!SubmitSmoke("company-menu") || !CheckSmoke(paused, "Pause voyage")) yield break; - float elapsed = passageElapsed; + Vector2 pausedPosition = passageHelm.Position; yield return new WaitForSecondsRealtime(.15f); - if (!CheckSmoke(passageElapsed == elapsed, "Paused passage clock") || !SubmitSmoke("resume-game")) + if (!CheckSmoke(passageHelm.Position == pausedPosition, "Paused passage clock") || !SubmitSmoke("resume-game")) yield break; if (!SubmitSmoke("dock-now") || !CheckSmoke(Ship.Port == 1 && company.Voyages == 1 && page == 4 && guideContext == GuideStep.Review, "Arrival settles once and opens the guided log")) yield break; @@ -157,18 +199,56 @@ namespace Soundings if (!SubmitSmoke("buy-fuel") || !CheckSmoke(Ship.Fuel > 0 && guideContext == GuideStep.Fare, "Bunkering and guide progress") || !SubmitSmoke("guide-skip") || !CheckSmoke(company.TutorialStep == 0, "Guide can be skipped")) yield break; + + company.Cash = 2_000_000; + company.Voyages = 10; + company.Reputation = 70; + if (!SubmitSmoke("nav-2") || !SubmitSmoke("yard-2") || !SubmitSmoke("buy-ship") + || !CheckSmoke(Ship.HullIndex == 1 && Ship.Decks.Count == 4, "Regional hull is delivered with four decks") + || !SubmitSmoke("nav-0")) + yield break; + yield return CaptureSmoke(directory, "15-regional-hull"); + + if (!SubmitSmoke("nav-2") || !SubmitSmoke("yard-4")) + yield break; + TextField vesselName = root.Q("vessel-name"); + if (!CheckSmoke(vesselName != null, "Name the Ocean Class commission")) + yield break; + vesselName.value = "Crownhaven"; + if (!SubmitSmoke("buy-ship") + || !CheckSmoke(Ship.HullIndex == Market.Ocean && Ship.Decks.Count == 6, "Ocean Class is delivered with six decks") + || !SubmitSmoke("add-deck") || !SubmitSmoke("add-deck") + || !CheckSmoke(Ship.Decks.Count == 8, "Ocean Class can add two more decks")) + yield break; + if (!CheckSmoke(company.Build(Ship, 0, 0, Facility.Cabin) == null + && company.Build(Ship, 1, 0, Facility.Dining) == null && company.Build(Ship, 7, 0, Facility.Bar) == null + && company.Refuel(Ship, 100) == null, "Fit and fuel the largest hull") || !SubmitSmoke("nav-0")) + yield break; + yield return CaptureSmoke(directory, "16-ocean-class-hull"); + if (!SubmitSmoke("plan-voyage") || !SubmitSmoke("port-1") || !SubmitSmoke("dispatch") + || !SubmitSmoke("passage-deck-7") || !CheckSmoke(passageDeck == 7, "Select the eighth deck during the voyage")) + yield break; + yield return CaptureSmoke(directory, "17-ocean-class-cutaway"); + if (!SubmitSmoke("passage-explore") || !CheckSmoke(harbor.FirstPersonPositionIsClear, "Walk safely on the eighth deck")) + yield break; Debug.Log($"Soundings player smoke passed at {Screen.width} × {Screen.height}."); Application.Quit(0); } private void MovePassageToSmoke(float progress) { - passageElapsed = PassageDuration(underway) * progress; + passageHelm.SetProgress(progress); livePassage.AdvanceTo(progress); - harbor.SetPassage(progress); + PresentVessel(0); UpdatePassageUi(progress); } + private void WalkSmoke(Vector2 movement, int steps) + { + for (int i = 0; i < steps; i++) + harbor.Walk(movement, .1f, true); + } + private bool SubmitSmoke(string element) { Button button = root.Q