diff --git a/Assets/BigShipTycoon/Editor/TycoonBuild.cs b/Assets/BigShipTycoon/Editor/TycoonBuild.cs index 9c17520..b2761cf 100644 --- a/Assets/BigShipTycoon/Editor/TycoonBuild.cs +++ b/Assets/BigShipTycoon/Editor/TycoonBuild.cs @@ -24,7 +24,7 @@ namespace BigShipTycoon.Editor EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) }; PlayerSettings.companyName = "Big Ship Tycoon"; PlayerSettings.productName = "Big Ship Tycoon"; - PlayerSettings.bundleVersion = "0.15.0"; + PlayerSettings.bundleVersion = "0.16.0"; PlayerSettings.defaultScreenWidth = 1920; PlayerSettings.defaultScreenHeight = 1080; PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow; diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage.meta new file mode 100644 index 0000000..b5579f3 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 17ff24892f0610e528a4b85b7a2472e1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav new file mode 100644 index 0000000..0d71e1c Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav.meta new file mode 100644 index 0000000..85bf1f1 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/AlignBerth.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 56f8111954b6244c594f07b26e9b66f0 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav new file mode 100644 index 0000000..5ffae8f Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav.meta new file mode 100644 index 0000000..802dfbb --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Approach.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 8c571121c8c2ed5cebab0a9656793335 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav new file mode 100644 index 0000000..c336a6a Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav.meta new file mode 100644 index 0000000..a00e236 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Autopilot.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: ef7151acc78fb9efb9cd6829159f1cd5 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav new file mode 100644 index 0000000..9318a87 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav.meta new file mode 100644 index 0000000..bd7a3bc --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/FollowChannel.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 0ffb90f3578f07e14af94bab212fde8e +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav new file mode 100644 index 0000000..ad0017d Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav.meta new file mode 100644 index 0000000..fef37dc --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/GetUnderWay.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 0c6296a98a6d3430b96221d19ca38ea9 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav new file mode 100644 index 0000000..87410c6 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav.meta new file mode 100644 index 0000000..008a84e --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Liner.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 270546940693f84549fe128dba8b4c30 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav new file mode 100644 index 0000000..c75f048 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav.meta new file mode 100644 index 0000000..8ccf271 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Radar.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 16f9848613fe1254e81ffa290d20884b +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav new file mode 100644 index 0000000..6c95b20 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav.meta new file mode 100644 index 0000000..e88d531 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/ReleaseLines.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 7b0371893ec1502dca6a9cf374db3abc +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav new file mode 100644 index 0000000..d104d79 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav.meta new file mode 100644 index 0000000..379ef27 --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SecureLines.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: c0eb01ae9a54800128f7482601fbb14b +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav new file mode 100644 index 0000000..b298a06 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav.meta new file mode 100644 index 0000000..db4130a --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/SlowShip.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 147949bd794a3e98682aad8c2776051a +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav new file mode 100644 index 0000000..6559510 Binary files /dev/null and b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav differ diff --git a/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav.meta b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav.meta new file mode 100644 index 0000000..186a06e --- /dev/null +++ b/Assets/BigShipTycoon/Resources/Audio/Pilotage/Thruster.wav.meta @@ -0,0 +1,23 @@ +fileFormatVersion: 2 +guid: 682c10eddc2025a439157875627cec57 +AudioImporter: + externalObjects: {} + serializedVersion: 8 + defaultSettings: + serializedVersion: 2 + loadType: 0 + sampleRateSetting: 0 + sampleRateOverride: 44100 + compressionFormat: 1 + quality: 1 + conversionMode: 0 + preloadAudioData: 0 + platformSettingOverrides: {} + forceToMono: 0 + normalize: 1 + loadInBackground: 0 + ambisonic: 0 + 3D: 1 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/BridgeInstrument.shader b/Assets/BigShipTycoon/Resources/BridgeInstrument.shader new file mode 100644 index 0000000..39aa38f --- /dev/null +++ b/Assets/BigShipTycoon/Resources/BridgeInstrument.shader @@ -0,0 +1,27 @@ +Shader "BigShipTycoon/Bridge Instrument" +{ + Properties { _MainTex ("Display", 2D) = "black" {} } + SubShader + { + Tags { "Queue"="Geometry+1" "RenderType"="Opaque" } + Cull Off + Pass + { + CGPROGRAM + #pragma vertex vert + #pragma fragment frag + #include "UnityCG.cginc" + sampler2D _MainTex; + struct Output { float4 position : SV_POSITION; float2 uv : TEXCOORD0; }; + Output vert(appdata_base input) + { + Output output; + output.position = UnityObjectToClipPos(input.vertex); + output.uv = input.texcoord.xy; + return output; + } + fixed4 frag(Output input) : SV_Target { return tex2D(_MainTex, input.uv); } + ENDCG + } + } +} diff --git a/Assets/BigShipTycoon/Resources/BridgeInstrument.shader.meta b/Assets/BigShipTycoon/Resources/BridgeInstrument.shader.meta new file mode 100644 index 0000000..560b1eb --- /dev/null +++ b/Assets/BigShipTycoon/Resources/BridgeInstrument.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: bee2b05ade4159f758fd5f21a0dd1011 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/BigShipTycoon/Resources/DockManeuver.uss b/Assets/BigShipTycoon/Resources/DockManeuver.uss new file mode 100644 index 0000000..353d19e --- /dev/null +++ b/Assets/BigShipTycoon/Resources/DockManeuver.uss @@ -0,0 +1,103 @@ +.dock-console-host { + position: absolute; + left: 0; + right: 0; + bottom: 18px; + align-items: center; +} +.dock-console { + width: 772px; + max-width: 94%; + padding: 9px 12px 7px; + border-width: 1px; + border-top-width: 2px; + border-color: #7e7158; + border-top-color: #c5a675; + background-color: rgba(8, 22, 30, .96); +} +.dock-header, .dock-instruments { + flex-direction: row; + justify-content: space-between; +} +.dock-header { + align-items: center; + margin-bottom: 7px; +} +.dock-title-group { flex-grow: 1; } +.dock-title { + color: #f5e4c1; + font-size: 22px; + margin: 1px 0 0; +} +.dock-chart { + width: 194px; + flex-shrink: 0; + margin-right: 13px; +} +.dock-chart-legend { + flex-direction: row; + justify-content: space-between; + margin: 0 1px 4px; +} +.dock-plan { + height: 67px; + background-color: #173744; + border-color: #56706b; + border-width: 1px; +} +.dock-speed { + color: #f1dbab; + margin-top: 6px; + font-size: 13px; +} +.dock-course { + margin-top: 1px; + color: #bfceca; + font-size: 11px; +} +.dock-controls { + flex-grow: 1; + min-width: 0; +} +.dock-controls-row { + flex-direction: row; + align-items: center; +} +.dock-orders, .dock-steering { margin-top: 3px; } +.dock-steering { margin-bottom: 4px; } +.dock-input-group { margin-right: 9px; } +.dock-input-group > .voyage-caption { margin-bottom: 2px; } +.dock-console .action.voyage-view-button { + height: 27px; + min-height: 27px; + white-space: normal; + margin: 0 4px 0 0; +} +.dock-orders .action.dock-order { + flex-grow: 1; + flex-basis: 0; + min-width: 0; + padding: 0 2px; + font-size: 10px; +} +.dock-lines { margin-top: 3px; } +.dock-lines .action.dock-line, .dock-lines .action.dock-handoff { + font-size: 11px; + flex-grow: 1; + flex-basis: 0; + min-width: 0; + padding: 0 3px; +} +.dock-line.dock-line-complete:disabled { color: #b9dcc8; opacity: .78; } +.dock-instruction { + border-top-width: 1px; + border-top-color: #41575b; + padding-top: 6px; + margin-top: 8px; + color: #d5dfd7; + white-space: normal; + font-size: 11px; +} +.dock-instruction.dock-instruction-warning { + color: #edb795; +} diff --git a/Assets/BigShipTycoon/Resources/DockManeuver.uss.meta b/Assets/BigShipTycoon/Resources/DockManeuver.uss.meta new file mode 100644 index 0000000..43898bd --- /dev/null +++ b/Assets/BigShipTycoon/Resources/DockManeuver.uss.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 7b5d18de696846a38af71d685fb07299 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0} + disableValidation: 0 + unsupportedSelectorAction: 0 diff --git a/Assets/BigShipTycoon/Resources/Passage.uss b/Assets/BigShipTycoon/Resources/Passage.uss index 0745098..d95543c 100644 --- a/Assets/BigShipTycoon/Resources/Passage.uss +++ b/Assets/BigShipTycoon/Resources/Passage.uss @@ -271,6 +271,7 @@ white-space: normal; margin-top: 2px; } +.passage-announcement.dock-passage-announcement { bottom: 237px; } .voyage-map { position: absolute; diff --git a/Assets/BigShipTycoon/Runtime/DeckPassengers.cs b/Assets/BigShipTycoon/Runtime/DeckPassengers.cs index 0cde1d9..1fc8426 100644 --- a/Assets/BigShipTycoon/Runtime/DeckPassengers.cs +++ b/Assets/BigShipTycoon/Runtime/DeckPassengers.cs @@ -797,16 +797,23 @@ namespace BigShipTycoon } float stationOffset = extent * .66f; - BridgeConsole(geometry, walk, new Vector3(x + 1.39f, y, 0), 2.27f, 0); + bool river = ship.HullIndex == Market.River; + bool advanced = ship.HullIndex is Market.Ocean or Market.Mega; + DockInstrumentKind navigation = river ? DockInstrumentKind.Compass : DockInstrumentKind.Radar; + BridgeConsole(geometry, walk, layout.Room.transform, new Vector3(x + 1.39f, y, 0), 2.27f, 0, + DockInstrumentKind.Conning, navigation, true); layout.Stations.Add(new ShipStation(StationKind.Helm, new Vector3(x + .38f, y + 1.40f, 0))); - BridgeConsole(geometry, walk, new Vector3(x + 1.83f, y, -stationOffset), 1.72f, 1); - BridgeConsole(geometry, walk, new Vector3(x + 1.83f, y, stationOffset), 1.72f, 2); + BridgeConsole(geometry, walk, layout.Room.transform, new Vector3(x + 1.83f, y, -stationOffset), 1.72f, 1, + DockInstrumentKind.Repeater, advanced ? DockInstrumentKind.Approach : DockInstrumentKind.Conning); + BridgeConsole(geometry, walk, layout.Room.transform, new Vector3(x + 1.83f, y, stationOffset), 1.72f, 2, + DockInstrumentKind.Machinery, river ? DockInstrumentKind.Compass : DockInstrumentKind.Repeater); if (ship.HasAftTerrace) { for (int side = -1; side <= 1; side += 2) { float stationZ = side * extent * .32f; - BridgeConsole(geometry, walk, new Vector3(x + 2.18f, y, stationZ), 2.48f, side > 0 ? 1 : 0); + BridgeConsole(geometry, walk, layout.Room.transform, new Vector3(x + 2.18f, y, stationZ), 2.48f, side > 0 ? 1 : 0, + side > 0 ? DockInstrumentKind.Machinery : DockInstrumentKind.Radar, DockInstrumentKind.Approach); geometry.Box(Carpet, new Vector3(x + .13f, y + .042f, stationZ), new Vector3(2f, .018f, 2.43f)); geometry.Box(Gasket, new Vector3(x + 2.58f, y + 2.34f, stationZ), new Vector3(.10f, .34f, 2.57f)); PlaceSign(layout.Room.transform, side < 0 ? "ROUTE MONITOR" : "ENGINE CONTROL", new Vector3(x + 2.524f, y + 2.34f, stationZ), 90, .09f); @@ -826,7 +833,8 @@ namespace BigShipTycoon return layout; } - private static void BridgeConsole(Geometry shape, ShipWalkSpace walk, Vector3 origin, float width, int style) + private void BridgeConsole(Geometry shape, ShipWalkSpace walk, Transform parent, Vector3 origin, float width, int style, + DockInstrumentKind port, DockInstrumentKind starboard, bool helm = false) { 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)); @@ -842,14 +850,27 @@ namespace BigShipTycoon 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); + dockMonitors.Add((parent, screen, .35f, width * .350f, i > 0 ? starboard : port)); 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); + if (helm) + { + bridgeTelegraph = Piece("Engine order telegraph lever", parent).transform; + bridgeTelegraph.localPosition = origin + new Vector3(-.09f, 1.10f, 0); + var lever = new Geometry(this, bridgeTelegraph); + lever.Box(Alloy, new Vector3(0, .11f, 0), new Vector3(.036f, .215f, .036f)); + lever.Box(ScreenAmber, new Vector3(-.02f, .23f, 0), new Vector3(.09f, .074f, .12f)); + lever.Finish(); + } + else + { + 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); } @@ -1083,6 +1104,7 @@ namespace BigShipTycoon public void Dispose() { + ReleaseDockDisplays(); passengerCrowd.Dispose(); foreach (Mesh mesh in meshes) UnityEngine.Object.Destroy(mesh); diff --git a/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs b/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs new file mode 100644 index 0000000..a4a9c69 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs @@ -0,0 +1,101 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace BigShipTycoon +{ + internal sealed partial class DeckPassengers + { + private readonly List<(Transform Parent, Vector3 Face, float Height, float Width, DockInstrumentKind Kind)> dockMonitors = new(); + private readonly List dockDisplays = new(); + private readonly Dictionary dockDisplayMaterials = new(); + private Mesh dockDisplayMesh; + private DockInstrumentRaster dockRaster; + private Transform bridgeTelegraph; + private float nextDockDisplayUpdate; + private bool showingDockDisplays; + + internal int LiveDockDisplayCount => showingDockDisplays ? dockDisplays.Count : 0; + internal bool DockRadarRunning => showingDockDisplays && dockDisplayMaterials.ContainsKey(DockInstrumentKind.Radar); + + internal void PresentDockBridge(DockManeuver dock, float range, bool northUp) + { + if (bridgeTelegraph != null) + bridgeTelegraph.localRotation = Quaternion.Euler(0, 0, -(int)(dock?.Order ?? DockOrder.Stop) * 13f); + bool show = bridgeView && dock != null; + if (show && dockDisplays.Count == 0) + CreateDockDisplays(); + if (showingDockDisplays != show) + { + showingDockDisplays = show; + nextDockDisplayUpdate = 0; + foreach (GameObject display in dockDisplays) + display.SetActive(show); + } + float now = Time.unscaledTime; + if (!show || now < nextDockDisplayUpdate) + return; + + nextDockDisplayUpdate = now + .09f; + foreach (var display in dockDisplayMaterials) + { + dockRaster.Render(dock, display.Key, range, northUp, Mathf.Repeat(now * .4f, 1)); + display.Value.Texture.SetPixels32(dockRaster.Pixels); + display.Value.Texture.Apply(false, false); + } + } + + private void CreateDockDisplays() + { + Shader screenShader = Resources.Load("BridgeInstrument"); + dockRaster = new DockInstrumentRaster(); + dockDisplayMesh = new Mesh { name = "Wheelhouse instrument glass" }; + dockDisplayMesh.vertices = new[] { new Vector3(0, -.5f, .5f), new Vector3(0, -.5f, -.5f), + new Vector3(0, .5f, -.5f), new Vector3(0, .5f, .5f) }; + dockDisplayMesh.uv = new[] { Vector2.zero, Vector2.right, Vector2.one, Vector2.up }; + dockDisplayMesh.triangles = new[] { 0, 2, 1, 0, 3, 2 }; + dockDisplayMesh.RecalculateBounds(); + + foreach (var monitor in dockMonitors) + { + if (!dockDisplayMaterials.TryGetValue(monitor.Kind, out var display)) + { + var texture = new Texture2D(DockInstrumentRaster.Width, DockInstrumentRaster.Height, TextureFormat.RGBA32, false) + { + name = monitor.Kind + " bridge display", filterMode = FilterMode.Bilinear, wrapMode = TextureWrapMode.Clamp + }; + var material = new Material(screenShader) { name = monitor.Kind + " bridge material", mainTexture = texture }; + display = (material, texture); + dockDisplayMaterials.Add(monitor.Kind, display); + } + + GameObject panel = Piece(monitor.Kind + " instrument", monitor.Parent); + panel.transform.localPosition = monitor.Face + Vector3.left * .052f; + panel.transform.localScale = new Vector3(1, monitor.Height, monitor.Width); + panel.AddComponent().sharedMesh = dockDisplayMesh; + panel.AddComponent().sharedMaterial = display.Material; + dockDisplays.Add(panel); + } + } + + private void ReleaseDockDisplays() + { + if (dockDisplayMesh != null) + UnityEngine.Object.Destroy(dockDisplayMesh); + foreach (var display in dockDisplayMaterials.Values) + { + UnityEngine.Object.Destroy(display.Material); + UnityEngine.Object.Destroy(display.Texture); + } + } + } + + public sealed partial class Harbor + { + internal int LiveDockDisplayCount => decks?.LiveDockDisplayCount ?? 0; + internal bool DockRadarRunning => decks?.DockRadarRunning == true; + internal bool DockExteriorVisible => exteriorRoot != null && exteriorRoot.gameObject.activeSelf && cameraMode == CameraMode.Orbit; + + internal void PresentDockBridge(DockManeuver dock, float range, bool northUp) => + decks?.PresentDockBridge(dock, range, northUp); + } +} diff --git a/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs.meta b/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs.meta new file mode 100644 index 0000000..e6796b4 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockBridgeInstruments.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: b0958ea76f036a465bf27896399fe58c \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs b/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs new file mode 100644 index 0000000..3e0d356 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs @@ -0,0 +1,339 @@ +using System; +using UnityEngine; + +namespace BigShipTycoon +{ + internal enum DockInstrumentKind { Compass, Radar, Conning, Machinery, Approach, Repeater } + + internal sealed class DockInstrumentRaster + { + internal const int Width = 384, Height = 192; + private static readonly Color32 Ink = new(5, 15, 20, 255); + private static readonly Color32 Subpanel = new(9, 28, 34, 255); + private static readonly Color32 Grid = new(33, 65, 68, 255); + private static readonly Color32 Muted = new(127, 176, 181, 255); + private static readonly Color32 Cyan = new(112, 224, 235, 255); + private static readonly Color32 Paper = new(235, 249, 243, 255); + private static readonly Color32 Green = new(111, 225, 160, 255); + private static readonly Color32 Gold = new(255, 200, 114, 255); + private static readonly Color32 Rose = new(247, 133, 115, 255); + + internal Color32[] Pixels { get; } = new Color32[Width * Height]; + + internal void Render(DockManeuver dock, DockInstrumentKind kind, float range, bool northUp, float sweep) + { + Array.Fill(Pixels, Ink); + if (dock == null) + return; + + switch (kind) + { + case DockInstrumentKind.Radar: Radar(dock, Mathf.Max(20, range), northUp, sweep); break; + case DockInstrumentKind.Conning: Conning(dock); break; + case DockInstrumentKind.Machinery: Machinery(dock); break; + case DockInstrumentKind.Approach: Approach(dock); break; + case DockInstrumentKind.Repeater: Repeater(dock); break; + default: Compass(dock); break; + } + } + + private void Compass(DockManeuver dock) + { + Header("COMPASS", dock); + Text("HEADING", 18, 141, 2, Muted); + Text(Heading(dock.Heading), 17, 99, 5, Paper); + Text("DEG", 115, 100, 2, Cyan); + HeadingTape(dock.Heading, 163, 111, 200); + Card(13, 14, 162, 64, "SPEED KN", Signed(dock.SpeedKnots), Cyan, 4); + Card(190, 14, 181, 64, "RUDDER", Direction(dock.Rudder), Gold, 3); + } + + private void Conning(DockManeuver dock) + { + Header("CONNING", dock); + Card(13, 87, 109, 67, "HDG DEG", Heading(dock.Heading), Paper, 4); + Card(137, 87, 109, 67, "SPEED KN", Signed(dock.SpeedKnots), Cyan, 4); + Card(261, 87, 110, 67, "SOG KN", $"{dock.SpeedOverGroundKnots:0.0}", Cyan, 4); + Text("RUDDER", 14, 57, 2, Muted); + Text(Direction(dock.Rudder), 15, 34, 2, Gold); + Gauge(132, 45, 231, dock.Rudder / 35f, Gold); + } + + private void Machinery(DockManeuver dock) + { + Header("MACHINERY", dock); + Card(13, 88, 358, 66, "ENGINE ORDER", Order(dock.Order), Paper, 3); + if (dock.HasBowThruster) + { + Text("BOW THRUST", 14, 63, 2, Muted); + Text(Mathf.Abs(dock.BowThruster) < .005f ? "IDLE" + : $"{Mathf.RoundToInt(Mathf.Abs(dock.BowThruster) * 100)}% {(dock.BowThruster < 0 ? "P" : "S")}", + 14, 40, 2, Cyan); + Gauge(165, 52, 199, dock.BowThruster, Cyan); + Text($"DRIFT {Signed(dock.LateralSpeedKnots)} KN", 14, 14, 2, Green); + } + else + { + Text("RUDDER", 14, 57, 2, Muted); + Text(Direction(dock.Rudder), 14, 34, 2, Gold); + Gauge(148, 46, 216, dock.Rudder / 35f, Gold); + } + } + + private void Approach(DockManeuver dock) + { + Header("APPROACH", dock); + Card(13, 95, 157, 57, "TURN DEG/S", Signed(dock.TurnRate), Gold, 4); + Card(189, 95, 182, 57, "DISPLACEMENT T", $"{dock.DisplacementTonnes:0}", Paper, 3); + Vector2 target = dock.Arriving ? dock.Berth : new Vector2(dock.ChannelEnd, 0); + Text(dock.Arriving ? "BERTH OFFSETS" : "CHANNEL OFFSETS", 14, 66, 2, Muted); + Text($"ALONG {Signed(target.x - dock.Position.x)} M", 14, 43, 2, Cyan); + Text($"CROSS {Signed(target.y - dock.Position.y)} M", 14, 19, 2, Cyan); + Text("COAST EST", 232, 46, 2, Muted); + Text($"{dock.NeutralCoastMetres:0} M", 232, 16, 3, Green); + } + + private void Repeater(DockManeuver dock) + { + Header("HELM REPEATER", dock); + Card(13, 85, 160, 69, "HEADING DEG", Heading(dock.Heading), Paper, 5); + Card(188, 85, 183, 69, "SPEED KN", Signed(dock.SpeedKnots), Cyan, 5); + Text(Order(dock.Order), 14, 47, 3, Muted); + Text($"RUDDER {Direction(dock.Rudder)}", 14, 16, 2, Gold); + } + + private void Radar(DockManeuver dock, float range, bool northUp, float sweep) + { + Header("HARBOR RADAR", dock); + Vector2 center = new(107, 80); + const int radius = 69; + float heading = dock.Heading * Mathf.Deg2Rad; + float turn = northUp ? 0 : heading; + float cosine = Mathf.Cos(turn), sine = Mathf.Sin(turn); + float scale = radius / range; + + Zone(15, 7, 182, 148, Subpanel); + Circle(107, 80, 23, Grid); + Circle(107, 80, 46, Grid); + Circle(107, 80, radius, Muted); + Line(38, 80, 176, 80, Grid); + Line(107, 11, 107, 149, Grid); + + float sweepAngle = Mathf.Repeat(sweep, 1f) * Mathf.PI * 2f; + for (int ray = 20; ray >= 0; ray--) + { + float angle = sweepAngle - ray * .012f; + Vector2 end = center + radius * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle)); + Color32 tint = ray == 0 ? Green : new Color32(22, (byte)(89 - ray * 2.5f), 57, 255); + Line(107, 80, Mathf.RoundToInt(end.x), Mathf.RoundToInt(end.y), tint); + } + + Vector2 Project(float along, float across) + { + Vector2 relative = new Vector2(along, across) - dock.Position; + return new Vector2(relative.y * cosine - relative.x * sine, relative.x * cosine + relative.y * sine) * scale; + } + + void Trace(float ax, float ay, float bx, float by, Color32 color) + { + Vector2 a = Project(ax, ay), b = Project(bx, by); + int samples = Mathf.Max(1, Mathf.CeilToInt(Vector2.Distance(a, b) * 1.48f)); + for (int sample = 0; sample <= samples; sample++) + { + Vector2 point = Vector2.LerpUnclamped(a, b, (float)sample / samples); + if (point.sqrMagnitude > radius * radius) + continue; + point += center; + Dot(Mathf.RoundToInt(point.x), Mathf.RoundToInt(point.y), color); + } + } + + float pierMin = dock.Berth.x - dock.PierHalfLength; + float pierMax = dock.Berth.x + dock.PierHalfLength; + float farPierY = dock.PierY + 12; + Trace(pierMin, dock.PierY, pierMax, dock.PierY, Gold); + Trace(pierMin, farPierY, pierMax, farPierY, Muted); + Trace(pierMin, dock.PierY, pierMin, farPierY, Muted); + Trace(pierMax, dock.PierY, pierMax, farPierY, Muted); + Trace(dock.ChannelEnd, -dock.ChannelHalfWidth, dock.ChannelEnd, dock.ChannelHalfWidth, Grid); + float length = (dock.ChannelEnd - 65f) / .42f; + float signal = Mathf.Clamp(length * .024f, .84f, 2.25f); + for (int mark = 0; mark < 4; mark++) + { + float gate = dock.ChannelEnd * Mathf.Lerp(.26f, 1, mark / 3f); + float outer = dock.ChannelHalfWidth + signal * .46f; + float pierSide = gate < dock.PierHalfLength ? Mathf.Min(outer, dock.PierY - signal * .74f) : outer; + RadarEcho(Project(gate, pierSide), center, radius, Green); + RadarEcho(Project(gate, -outer), center, radius, Rose); + } + + float ownAngle = heading - turn; + Vector2 bow = new(Mathf.Sin(ownAngle), Mathf.Cos(ownAngle)); + Vector2 side = new(bow.y, -bow.x); + Vector2 tip = center + bow * 8f; + Vector2 left = center - bow * 6f - side * 4f; + Vector2 right = center - bow * 6f + side * 4f; + Line(tip, left, Paper); + Line(tip, right, Paper); + Line(left, right, Paper); + + Vector2 north = center + (radius - 7) * new Vector2(-sine, cosine); + Text("N", Mathf.RoundToInt(north.x) - 2, Mathf.RoundToInt(north.y) - 3, 1, Paper); + Text(northUp ? "NORTH UP" : "HEAD UP", 218, 135, 2, Green); + Text("RANGE", 218, 105, 2, Muted); + Text($"{range:0} M", 218, 80, 3, Paper); + Text($"HDG {Heading(dock.Heading)}", 218, 52, 2, Cyan); + Text($"SOG {dock.SpeedOverGroundKnots:0.0} KN", 218, 25, 2, Cyan); + } + + private void RadarEcho(Vector2 projected, Vector2 center, int radius, Color32 color) + { + if (projected.sqrMagnitude >= (radius - 4) * (radius - 4)) + return; + Vector2 at = projected + center; + int x = Mathf.RoundToInt(at.x), y = Mathf.RoundToInt(at.y); + Zone(x - 1, y - 1, 3, 3, color); + } + + private void Header(string title, DockManeuver dock) + { + Zone(0, 166, Width, 26, Subpanel); + Zone(0, 165, Width, 1, Grid); + Text(title, 14, 172, 2, Cyan); + string status = dock.Secured ? "SECURED" : dock.LinesAttached ? "LINES ON" + : dock.AtChannelEdge ? "CHANNEL EDGE" : dock.ReadyForAutopilot ? "CLEAR" : "IN CHANNEL"; + Text(status, Width - 12 - TextWidth(status, 1), 176, 1, dock.AtChannelEdge ? Gold : Green); + } + + private void Card(int x, int y, int width, int height, string name, string value, Color32 color, int scale) + { + Zone(x, y, width, height, Subpanel); + Zone(x, y, width, 1, Grid); + Text(name, x + 9, y + height - 19, 2, Muted); + Text(value, x + 9, y + 8, scale, color); + } + + private void HeadingTape(float heading, int x, int y, int width) + { + Zone(x, y, width, 32, Subpanel); + Line(x, y + 6, x + width, y + 6, Grid); + int near = Mathf.RoundToInt(heading / 10f) * 10; + for (int tick = near - 30; tick <= near + 30; tick += 10) + { + int at = x + width / 2 + Mathf.RoundToInt((tick - heading) * 3); + if (at < x + 12 || at > x + width - 12) + continue; + Line(at, y + 6, at, y + 13, Muted); + Text(Heading(tick), at - 8, y + 18, 1, Muted); + } + int center = x + width / 2; + Line(center, y + 3, center, y + 14, Gold); + } + + private void Gauge(int x, int y, int width, float input, Color32 color) + { + int center = x + width / 2; + int tip = center + Mathf.RoundToInt(Mathf.Clamp(input, -1, 1) * width * .5f); + Zone(x, y - 3, width, 7, Grid); + Zone(Mathf.Min(tip, center), y - 4, Mathf.Abs(tip - center), 9, color); + Line(center, y - 7, center, y + 7, Paper); + Text("P", x, y - 25, 2, Muted); + Text("S", x + width - 10, y - 25, 2, Muted); + } + + private static string Direction(float angle) => Mathf.Abs(angle) < .5f + ? "CENTER" : $"{Mathf.Abs(angle):0} DEG {(angle < 0 ? "P" : "S")}"; + private static string Heading(float degrees) => $"{Mathf.RoundToInt(Mathf.Repeat(degrees, 360)) % 360:000}"; + private static string Signed(float value) => Mathf.Abs(value) < .05f ? "0.0" : $"{value:+0.0;-0.0;0.0}"; + private static string Order(DockOrder order) => order switch + { + DockOrder.HalfAstern => "HALF ASTERN", + DockOrder.DeadSlowAstern => "DEAD SLOW ASTERN", + DockOrder.DeadSlowAhead => "DEAD SLOW AHEAD", + DockOrder.HalfAhead => "HALF AHEAD", + _ => "STOP" + }; + + private void Circle(int x, int y, int radius, Color32 color) + { + int previousX = x, previousY = y + radius; + for (int point = 1; point <= 90; point++) + { + float radians = point * Mathf.PI * 2f / 90f; + int nextX = x + Mathf.RoundToInt(radius * Mathf.Sin(radians)); + int nextY = y + Mathf.RoundToInt(radius * Mathf.Cos(radians)); + Line(previousX, previousY, nextX, nextY, color); + (previousX, previousY) = (nextX, nextY); + } + } + + private void Line(Vector2 a, Vector2 b, Color32 color) => + Line(Mathf.RoundToInt(a.x), Mathf.RoundToInt(a.y), Mathf.RoundToInt(b.x), Mathf.RoundToInt(b.y), color); + + private void Line(int x, int y, int toX, int toY, Color32 color) + { + int dx = Mathf.Abs(toX - x), dy = -Mathf.Abs(toY - y); + int sx = x < toX ? 1 : -1, sy = y < toY ? 1 : -1; + int error = dx + dy; + while (true) + { + Dot(x, y, color); + if (x == toX && y == toY) + return; + int twice = error * 2; + if (twice >= dy) { error += dy; x += sx; } + if (twice <= dx) { error += dx; y += sy; } + } + } + + private void Dot(int x, int y, Color32 color) + { + if ((uint)x < Width && (uint)y < Height) + Pixels[y * Width + x] = color; + } + + private void Zone(int x, int y, int width, int height, Color32 color) + { + int left = Mathf.Max(0, x), right = Mathf.Min(Width, x + width); + int bottom = Mathf.Max(0, y), top = Mathf.Min(Height, y + height); + for (int row = bottom; row < top; row++) + for (int column = left; column < right; column++) + Pixels[row * Width + column] = color; + } + + private static int TextWidth(string value, int scale) => value.Length * 6 * scale - scale; + + private void Text(string value, int x, int y, int scale, Color32 color) + { + foreach (char letter in value) + { + int glyph = Alphabet.IndexOf(letter); + if (glyph >= 0) + for (int row = 0; row < 7; row++) + for (int column = 0; column < 5; column++) + if ((Letters[glyph, row] & 1 << (4 - column)) != 0) + Zone(x + column * scale, y + (6 - row) * scale, scale, scale, color); + x += 6 * scale; + } + } + + private const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-./:%"; + private static readonly byte[,] Letters = + { + {14,17,17,31,17,17,17}, {30,17,17,30,17,17,30}, {15,16,16,16,16,16,15}, + {30,17,17,17,17,17,30}, {31,16,16,30,16,16,31}, {31,16,16,30,16,16,16}, + {15,16,16,23,17,17,15}, {17,17,17,31,17,17,17}, {31,4,4,4,4,4,31}, + {7,2,2,2,18,18,12}, {17,18,20,24,20,18,17}, {16,16,16,16,16,16,31}, + {17,27,21,21,17,17,17}, {17,25,21,19,17,17,17}, {14,17,17,17,17,17,14}, + {30,17,17,30,16,16,16}, {14,17,17,17,21,18,13}, {30,17,17,30,20,18,17}, + {15,16,16,14,1,1,30}, {31,4,4,4,4,4,4}, {17,17,17,17,17,17,14}, + {17,17,17,17,17,10,4}, {17,17,17,21,21,27,17}, {17,17,10,4,10,17,17}, + {17,17,10,4,4,4,4}, {31,1,2,4,8,16,31}, + {14,17,19,21,25,17,14}, {4,12,4,4,4,4,14}, {14,17,1,2,4,8,31}, + {30,1,1,14,1,1,30}, {2,6,10,18,31,2,2}, {31,16,16,30,1,1,30}, + {14,16,16,30,17,17,14}, {31,1,2,4,8,8,8}, {14,17,17,14,17,17,14}, + {14,17,17,15,1,1,14}, {0,4,4,31,4,4,0}, {0,0,0,31,0,0,0}, + {0,0,0,0,0,6,6}, {1,2,2,4,8,8,16}, {0,6,6,0,6,6,0}, {25,26,2,4,8,11,19} + }; + } +} diff --git a/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs.meta b/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs.meta new file mode 100644 index 0000000..adff456 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockInstrumentRaster.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 291c640fcee7235a8b51a95f978f73ac \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/DockManeuver.cs b/Assets/BigShipTycoon/Runtime/DockManeuver.cs new file mode 100644 index 0000000..ff1b74c --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockManeuver.cs @@ -0,0 +1,309 @@ +using System; +using UnityEngine; + +namespace BigShipTycoon +{ + internal enum DockOrder + { + HalfAstern = -2, DeadSlowAstern = -1, Stop = 0, DeadSlowAhead = 1, HalfAhead = 2 + } + + [Serializable] + internal sealed class DockManeuverSnapshot + { + public bool Arriving, BowLine, SternLine, AtChannelEdge; + public Vector2 Position; + public float Heading, Surge, Sway, TurnRate, Engine, Rudder, BowThruster; + public DockOrder Order; + } + + internal sealed class DockManeuver + { + private const float MetresPerKnot = .514444f; + private const float RudderLimit = 35f; + private const float IntegrationStep = .05f; + private const float WaterDensity = 1025f; + internal const float LinesSpeedLimit = .43f; + internal const float LinesHeadingLimit = 12f; + internal const float HandoffHeadingLimit = 14f; + internal const float HandoffMinimumSpeed = .65f; + internal const float HandoffMaximumSpeed = 6.8f; + + private readonly float length, beam, surgeMass, swayMass, yawInertia, engineForce, bowForce, rudderArea; + private readonly float drag, linearDrag, turnDamping, engineResponse, turnLimit; + private float surge, sway, engine; + + internal DockManeuver(int hullIndex, bool arriving, float approachSpeed = 0) + { + HullSpec hull = Market.Hulls[hullIndex]; + length = hull.Length; + beam = hull.Beam; + float draft = hullIndex switch + { + Market.River => 1.38f, Market.Coastal => 3.15f, Market.Regional => 4.4f, + Market.Ocean => 5.85f, _ => 8.55f + }; + float block = hullIndex switch + { + Market.River => .68f, Market.Coastal => .60f, Market.Regional => .63f, + Market.Ocean => .56f, _ => .69f + }; + float mass = (hullIndex == Market.River ? 1000f : WaterDensity) * length * beam * draft * block; + DisplacementTonnes = mass * .001f; + float scale = Mathf.InverseLerp(5.4f, 8f, Mathf.Log10(mass)); + // Water pushed and turned with the hull adds more inertia in a sideways manoeuvre. + surgeMass = mass * 1.08f; + swayMass = mass * 1.64f; + yawInertia = mass * (.058f * length * length + .12f * beam * beam); + rudderArea = beam * draft * .245f; + engineForce = surgeMass * Mathf.Lerp(.48f, .20f, scale); + bowForce = swayMass * Mathf.Lerp(.116f, .050f, scale); + drag = Mathf.Lerp(.047f, .030f, scale); + linearDrag = Mathf.Lerp(.051f, .017f, scale); + turnDamping = Mathf.Lerp(.37f, .23f, scale); + engineResponse = Mathf.Lerp(.92f, 3.0f, scale); + turnLimit = Mathf.Lerp(7.6f, 2.6f, scale); + + Arriving = arriving; + HasBowThruster = hullIndex is Market.Regional or Market.Ocean or Market.Mega; + Berth = new Vector2(0, Mathf.Max(5f, beam * .42f + 1.2f)); + PierY = Berth.y + beam * .5f + Mathf.Max(1f, beam * .07f); + PierHalfLength = length * .57f + 6f; + ChannelEnd = Mathf.Max(length * .42f + 65f, PierHalfLength + Mathf.Max(length * .32f, 18f)); + ChannelHalfWidth = beam * 1.30f + 16f; + if (arriving) + { + // Larger ships enter on the berth-side leading line to leave room for the stern to swing. + Position = new Vector2(ChannelEnd, HasBowThruster ? Berth.y * .42f : 0); + Heading = 180f; + surge = Mathf.Clamp(approachSpeed, 0, HandoffMaximumSpeed) * MetresPerKnot; + } + else + { + Position = Berth; + BowLine = SternLine = true; + } + } + + internal bool Arriving { get; } + internal bool HasBowThruster { get; } + internal float DisplacementTonnes { get; } + internal Vector2 Berth { get; } + internal float PierY { get; } + internal float PierHalfLength { get; } + internal float ChannelEnd { get; } + internal float ChannelHalfWidth { get; } + internal float BerthAlongTolerance => Mathf.Max(5f, length * .055f); + internal float BerthCrossTolerance => Mathf.Max(3.3f, beam * .21f); + internal float HandoffCrossTolerance => Mathf.Max(4.2f, beam * .36f); + internal float TargetHeading => Arriving ? 180f : 0f; + internal Vector2 Position { get; private set; } + internal float Heading { get; private set; } + internal float SpeedKnots => surge / MetresPerKnot; + internal float LateralSpeedKnots => sway / MetresPerKnot; + internal float SpeedOverGroundKnots => new Vector2(surge, sway).magnitude / MetresPerKnot; + internal float NeutralCoastMetres => Mathf.Abs(surge) <= LinesSpeedLimit * MetresPerKnot ? 0 + : Mathf.Log((linearDrag + drag * Mathf.Abs(surge)) / (linearDrag + drag * LinesSpeedLimit * MetresPerKnot)) / drag; + internal float Rudder { get; private set; } + internal float TurnRate { get; private set; } + internal float BowThruster { get; private set; } + internal DockOrder Order { get; private set; } + internal bool BowLine { get; private set; } + internal bool SternLine { get; private set; } + internal bool AtChannelEdge { get; private set; } + internal bool LinesAttached => BowLine || SternLine; + internal bool ChannelClear => !Arriving && !LinesAttached && Position.x >= ChannelEnd; + internal bool AtBerth => IsAtBerth(Position, Heading); + internal bool ReadyForAutopilot => ChannelClear && Mathf.Abs(Position.y) <= HandoffCrossTolerance + && Mathf.Abs(Mathf.DeltaAngle(Heading, TargetHeading)) <= HandoffHeadingLimit + && SpeedKnots >= HandoffMinimumSpeed && SpeedKnots <= HandoffMaximumSpeed; + internal bool Secured => Arriving && BowLine && SternLine; + private float MinX => -Mathf.Max(26f, length * .31f); + private float MaxX => ChannelEnd + Mathf.Max(32f, length * .24f); + + internal void SetOrder(DockOrder order) + { + if (!LinesAttached && order is >= DockOrder.HalfAstern and <= DockOrder.HalfAhead) + Order = order; + } + + internal bool CanToggleLine(bool bow) + { + bool attached = bow ? BowLine : SternLine; + if (!Arriving) + return attached; + return !attached && (LinesAttached || AtBerth && SpeedOverGroundKnots <= LinesSpeedLimit + && Mathf.Abs(TurnRate) <= .75f && Order == DockOrder.Stop + && Mathf.Abs(engine) <= .055f && Mathf.Abs(BowThruster) <= .075f); + } + + internal bool ToggleLine(bool bow) + { + if (!CanToggleLine(bow)) + return false; + if (bow) + BowLine = Arriving; + else + SternLine = Arriving; + if (Arriving) + { + surge = sway = engine = TurnRate = BowThruster = 0; + Order = DockOrder.Stop; + } + return true; + } + + internal void Advance(float seconds, float rudderInput, float thrusterInput) + { + if (!(seconds > 0) || !Finite(seconds)) + return; + float requestedRudder = Mathf.Clamp(rudderInput, -1f, 1f) * RudderLimit; + float requestedThruster = HasBowThruster ? Mathf.Clamp(thrusterInput, -1f, 1f) : 0f; + for (int step = 0, steps = Mathf.CeilToInt(seconds / IntegrationStep); step < steps; step++) + { + float delta = Mathf.Min(IntegrationStep, seconds - step * IntegrationStep); + AdvanceStep(delta, requestedRudder, requestedThruster); + } + } + + private void AdvanceStep(float delta, float rudder, float thruster) + { + Rudder = Mathf.MoveTowards(Rudder, rudder, delta * 25f); + if (LinesAttached) + return; + + float engineOrder = Order switch + { + DockOrder.HalfAstern => -.65f, DockOrder.DeadSlowAstern => -.22f, + DockOrder.DeadSlowAhead => .29f, DockOrder.HalfAhead => .86f, _ => 0f + }; + engine = Mathf.MoveTowards(engine, engineOrder, delta / engineResponse); + // A transverse jet loses authority once water flows briskly past its tunnel. + float thrusterAuthority = 1f - Mathf.InverseLerp(1.4f, 4.35f, Mathf.Abs(SpeedKnots)); + BowThruster = Mathf.MoveTowards(BowThruster, thruster * thrusterAuthority, delta * 2.3f); + float lateralThrust = BowThruster * bowForce; + float propellerWash = engine * (engine > 0 ? 4.95f : .8f); + float rudderFlow = surge + propellerWash; + float rudderForce = .52f * WaterDensity * rudderArea * rudderFlow * Mathf.Abs(rudderFlow) * (Rudder / RudderLimit); + float power = engine * engineForce; + float surgeDamping = surge * (linearDrag + drag * Mathf.Abs(surge)); + float swayDamping = sway * (.30f + .18f * Mathf.Abs(sway)); + float angularVelocity = TurnRate * Mathf.Deg2Rad; + float previousSurge = surge, previousSway = sway; + surge += (power / surgeMass - surgeDamping + angularVelocity * previousSway) * delta; + sway += ((lateralThrust - rudderForce) / swayMass - swayDamping - angularVelocity * previousSurge) * delta; + float torque = length * (.46f * rudderForce + .39f * lateralThrust); + TurnRate = Mathf.Clamp(TurnRate + (torque / yawInertia * Mathf.Rad2Deg + - TurnRate * (turnDamping + .11f * Mathf.Abs(surge))) * delta, -turnLimit, turnLimit); + + float nextHeading = Mathf.DeltaAngle(0, Heading + TurnRate * delta); + Vector2 forward = Forward(Heading + TurnRate * delta * .5f); + Vector2 right = new Vector2(-forward.y, forward.x); + Vector2 next = Position + (forward * (previousSurge + surge) + right * (previousSway + sway)) * (.5f * delta); + Constrain(next, nextHeading, delta); + } + + private void Constrain(Vector2 next, float heading, float delta) + { + float x = Mathf.Clamp(next.x, MinX, MaxX); + AtChannelEdge = !Mathf.Approximately(x, next.x); + if (!TryChannelLimits(x, heading, out float left, out float right)) + { + heading = Heading; + TurnRate = 0; + AtChannelEdge = true; + if (!TryChannelLimits(x, heading, out left, out right)) + { + x = Position.x; + TryChannelLimits(x, heading, out left, out right); + } + } + + float y = Mathf.Clamp(next.y, left, right); + if (!Mathf.Approximately(y, next.y) || AtChannelEdge) + { + AtChannelEdge = true; + Vector2 forward = Forward(heading), across = new Vector2(-forward.y, forward.x); + Vector2 velocity = forward * surge + across * sway; + if ((next.y - y) * velocity.y > 0) + velocity.y = 0; + if ((next.x - x) * velocity.x > 0) + velocity.x = 0; + surge = Vector2.Dot(velocity, forward); + sway = Vector2.Dot(velocity, across); + TurnRate *= Mathf.Exp(-3f * delta); + } + Position = new Vector2(x, y); + Heading = heading; + } + + private bool TryChannelLimits(float x, float heading, out float left, out float right) + { + Vector2 direction = Forward(heading); + float along = ProjectedHullReach(Mathf.Abs(direction.x) * length, Mathf.Abs(direction.y) * beam); + float across = ProjectedHullReach(Mathf.Abs(direction.y) * length, Mathf.Abs(direction.x) * beam); + left = -ChannelHalfWidth + across; + right = ChannelHalfWidth - across; + if (Mathf.Abs(x) < PierHalfLength + along) + right = Mathf.Min(right, PierY - across); + return left <= right; + } + + // The ends taper before the maximum beam. A rectangular footprint would + // stop a bow or stern swinging into clear water beside the fenders. + private static float ProjectedHullReach(float along, float across) => + Mathf.Max(along * .485f + across * .34f, along * .33f + across * .5f); + + private bool IsAtBerth(Vector2 position, float heading) => + Mathf.Abs(position.x - Berth.x) <= BerthAlongTolerance && Mathf.Abs(position.y - Berth.y) <= BerthCrossTolerance + && Mathf.Abs(Mathf.DeltaAngle(heading, TargetHeading)) <= LinesHeadingLimit; + + private static Vector2 Forward(float heading) + { + float radians = heading * Mathf.Deg2Rad; + return new Vector2(Mathf.Cos(radians), Mathf.Sin(radians)); + } + + internal DockManeuverSnapshot Capture() => new DockManeuverSnapshot + { + Arriving = Arriving, BowLine = BowLine, SternLine = SternLine, AtChannelEdge = AtChannelEdge, + Position = Position, Heading = Heading, Surge = surge, Sway = sway, TurnRate = TurnRate, + Engine = engine, Rudder = Rudder, BowThruster = BowThruster, Order = Order + }; + + internal bool Restore(DockManeuverSnapshot state) + { + if (state == null || state.Arriving != Arriving || !Finite(state.Position.x) || !Finite(state.Position.y) + || !Finite(state.Heading, 180) || !Finite(state.Rudder, RudderLimit) + || !Finite(state.Surge, 12) || !Finite(state.Sway, 8) || !Finite(state.TurnRate, turnLimit) + || !Finite(state.Engine, 1) || !Finite(state.BowThruster, 1) || !HasBowThruster && state.BowThruster != 0 + || state.Order is < DockOrder.HalfAstern or > DockOrder.HalfAhead + || !TryChannelLimits(state.Position.x, state.Heading, out float left, out float right) + || state.Position.x < MinX - .001f || state.Position.x > MaxX + .001f + || state.Position.y < left - .001f || state.Position.y > right + .001f) + return false; + + if ((state.BowLine || state.SternLine) && (state.Surge != 0 || state.Sway != 0 || state.Engine != 0 + || state.TurnRate != 0 || state.BowThruster != 0 || state.Order != DockOrder.Stop + || !IsAtBerth(state.Position, state.Heading))) + return false; + + BowLine = state.BowLine; + SternLine = state.SternLine; + AtChannelEdge = state.AtChannelEdge; + Position = state.Position; + Heading = state.Heading; + surge = state.Surge; + sway = state.Sway; + TurnRate = state.TurnRate; + engine = state.Engine; + Rudder = state.Rudder; + BowThruster = state.BowThruster; + Order = state.Order; + return true; + } + + private static bool Finite(float number) => !float.IsNaN(number) && !float.IsInfinity(number); + private static bool Finite(float number, float magnitude) => Finite(number) && Mathf.Abs(number) <= magnitude; + } +} diff --git a/Assets/BigShipTycoon/Runtime/DockManeuver.cs.meta b/Assets/BigShipTycoon/Runtime/DockManeuver.cs.meta new file mode 100644 index 0000000..4099194 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockManeuver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: cfafbbc0990284a3db1ce5f1f960fda6 \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs b/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs new file mode 100644 index 0000000..8e179b9 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs @@ -0,0 +1,403 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace BigShipTycoon +{ + public sealed partial class TycoonApp + { + private static readonly string[] DockOrderNames = { "Half astern", "Dead slow astern", "Stop", "Dead slow ahead", "Half ahead" }; + private static readonly Color DockRouteColor = new(.33f, .61f, .66f); + private static readonly Color DockMarkColor = new(.87f, .73f, .47f); + private readonly Button[] dockOrderButtons = new Button[DockOrderNames.Length]; + private Button dockBowLineButton, dockSternLineButton, dockAutopilotButton; + private Label dockSpeedReadout, dockCourseReadout, dockPrecisionReadout, dockInstruction; + private VisualElement dockPlan; + private StyleSheet dockManeuverStyle; + private float dockRudderHold, dockThrusterHold, dockRudderPulse, dockThrusterPulse; + private float dockRudderUntil, dockThrusterUntil, dockNextPlanPaint; + + private void DrawDockManeuverControls(VisualElement overlay) + { + DockManeuver maneuver = ActiveDockManeuver; + if (maneuver == null) + return; + + dockRudderHold = dockThrusterHold = dockRudderPulse = dockThrusterPulse = 0; + dockRudderUntil = dockThrusterUntil = dockNextPlanPaint = 0; + var host = Add(overlay, "dock-console-host"); + host.pickingMode = PickingMode.Ignore; + dockManeuverStyle ??= Resources.Load("DockManeuver"); + if (dockManeuverStyle != null) + host.styleSheets.Add(dockManeuverStyle); + + var console = Add(host, "dock-console"); + var header = Add(console, "dock-header"); + var title = Add(header, "dock-title-group"); + int port = maneuver.Arriving ? underway.Destination : underway.Origin; + AddText(title, Market.Ports[port].Name.ToUpperInvariant(), "voyage-caption"); + AddDisplay(title, maneuver.Arriving ? "Bring the ship alongside" : "Clear the harbor", "dock-title"); + var camera = Add(header, "dock-controls-row"); + camera.Add(Action("Bridge B", ShowDockBridge, PassageViewClass(passageBridge), "dock-bridge")); + camera.Add(Action("Exterior V", ShowDockExterior, PassageViewClass(!passageBridge), "dock-exterior")); + if (DockRadarAvailable) + camera.Add(Action("Radar range R", CycleDockRadarRange, "voyage-view-button", "dock-radar-range")); + if (DockAdvancedRadarAvailable) + camera.Add(Action("Radar orientation N", ToggleDockRadarOrientation, "voyage-view-button", "dock-radar-orientation")); + + var instruments = Add(console, "dock-instruments"); + var chart = Add(instruments, "dock-chart"); + var chartLegend = Add(chart, "dock-chart-legend"); + AddText(chartLegend, "BERTH", "voyage-caption"); + AddText(chartLegend, "CHANNEL EXIT", "voyage-caption"); + dockPlan = Add(chart, "dock-plan"); + dockPlan.pickingMode = PickingMode.Ignore; + dockPlan.generateVisualContent += ctx => PaintDockPlan(ctx, maneuver); + dockSpeedReadout = AddText(chart, "", "dock-speed"); + dockCourseReadout = AddText(chart, "", "dock-course"); + dockPrecisionReadout = DockAdvancedRadarAvailable ? AddText(chart, "", "dock-course") : null; + + var controls = Add(instruments, "dock-controls"); + AddText(controls, "ENGINE ORDER · W / S", "voyage-caption"); + var orders = Add(controls, "dock-controls-row dock-orders"); + for (int index = 0; index < DockOrderNames.Length; index++) + { + DockOrder order = (DockOrder)(index - 2); + Button button = Action(DockOrderNames[index], () => + { + maneuver.SetOrder(order); + RefreshDockManeuverControls(maneuver); + }, + "voyage-view-button dock-order", $"dock-order-{(int)order}"); + if (order == DockOrder.Stop) + button.tooltip = "X sets Stop. The ship keeps its way until drag or reverse thrust slows it."; + if (index == DockOrderNames.Length - 1) + button.style.marginRight = 0; + dockOrderButtons[index] = button; + orders.Add(button); + } + + var steering = Add(controls, "dock-controls-row dock-steering"); + var rudder = Add(steering, "dock-input-group"); + AddText(rudder, "RUDDER · A / D", "voyage-caption"); + var rudderButtons = Add(rudder, "dock-controls-row"); + rudderButtons.Add(DockMomentaryButton("Port", "dock-rudder-port", false, -1)); + rudderButtons.Add(DockMomentaryButton("Starboard", "dock-rudder-starboard", false, 1)); + if (maneuver.HasBowThruster) + { + var thruster = Add(steering, "dock-input-group"); + AddText(thruster, "BOW THRUSTER · Z / C", "voyage-caption"); + var thrustButtons = Add(thruster, "dock-controls-row"); + thrustButtons.Add(DockMomentaryButton("Push port", "dock-thruster-port", true, -1)); + thrustButtons.Add(DockMomentaryButton("Push starboard", "dock-thruster-starboard", true, 1)); + } + + var lines = Add(controls, "dock-controls-row dock-lines"); + dockBowLineButton = Action("", () => ToggleDockLine(maneuver, true), "voyage-view-button dock-line", "dock-bow-line"); + dockSternLineButton = Action("", () => ToggleDockLine(maneuver, false), "voyage-view-button dock-line", "dock-stern-line"); + lines.Add(dockBowLineButton); + lines.Add(dockSternLineButton); + dockAutopilotButton = null; + if (!maneuver.Arriving) + { + dockAutopilotButton = Action("Engage autopilot H", EngageDockAutopilot, + "voyage-view-button dock-handoff", "dock-autopilot"); + lines.Add(dockAutopilotButton); + } + dockInstruction = AddText(console, "", "dock-instruction"); + RefreshDockManeuverControls(maneuver); + } + + private void UpdateDockManeuverControls(float delta) + { + DockManeuver maneuver = ActiveDockManeuver; + if (maneuver == null) + return; + + bool acceptsInput = Application.isFocused && !EditingText(); + if (acceptsInput) + { + if (Input.GetKeyDown(KeyCode.W)) + maneuver.SetOrder((DockOrder)Mathf.Min(2, (int)maneuver.Order + 1)); + if (Input.GetKeyDown(KeyCode.S)) + maneuver.SetOrder((DockOrder)Mathf.Max(-2, (int)maneuver.Order - 1)); + if (Input.GetKeyDown(KeyCode.X)) + maneuver.SetOrder(DockOrder.Stop); + if (Input.GetKeyDown(KeyCode.F)) + maneuver.ToggleLine(true); + if (Input.GetKeyDown(KeyCode.G)) + maneuver.ToggleLine(false); + if (Input.GetKeyDown(KeyCode.B)) + ShowDockBridge(); + if (Input.GetKeyDown(KeyCode.V)) + ShowDockExterior(); + if (DockRadarAvailable && Input.GetKeyDown(KeyCode.R)) + CycleDockRadarRange(); + if (DockAdvancedRadarAvailable && Input.GetKeyDown(KeyCode.N)) + ToggleDockRadarOrientation(); + if (maneuver.ReadyForAutopilot && Input.GetKeyDown(KeyCode.H)) + { + EngageDockAutopilot(); + return; + } + } + else + { + dockRudderHold = dockThrusterHold = 0; + dockRudderUntil = dockThrusterUntil = 0; + } + + float rudder = 0, thruster = 0; + if (acceptsInput) + { + float now = Time.unscaledTime; + rudder = DockInput(MoveAxis(KeyCode.D, KeyCode.A), dockRudderHold, now < dockRudderUntil ? dockRudderPulse : 0); + if (maneuver.HasBowThruster) + thruster = DockInput(MoveAxis(KeyCode.C, KeyCode.Z), dockThrusterHold, now < dockThrusterUntil ? dockThrusterPulse : 0); + } + maneuver.Advance(delta, rudder, thruster); + RefreshDockManeuverControls(maneuver); + } + + private void RefreshDockManeuverControls(DockManeuver maneuver) + { + if (dockInstruction == null) + return; + + float heading = Mathf.Repeat(maneuver.Heading, 360); + int headingRounded = Mathf.RoundToInt(heading) % 360; + float remaining = maneuver.Arriving ? Vector2.Distance(maneuver.Position, maneuver.Berth) + : Mathf.Max(0, maneuver.ChannelEnd - maneuver.Position.x); + string way = Mathf.Abs(maneuver.SpeedKnots) < .05f + ? maneuver.SpeedOverGroundKnots < .05f ? "stopped" : "sideways" + : maneuver.SpeedKnots > 0 ? "ahead" : "astern"; + SetPassageText(dockSpeedReadout, $"{maneuver.SpeedOverGroundKnots:0.0} kn over ground · {way}"); + SetPassageText(dockCourseReadout, $"Heading {headingRounded:000}° · {remaining:0} m to {(maneuver.Arriving ? "berth" : "exit")}"); + if (dockPrecisionReadout != null) + SetPassageText(dockPrecisionReadout, + $"Turn {maneuver.TurnRate:+0.0;-0.0;0.0}°/s · Drift {maneuver.LateralSpeedKnots:+0.0;-0.0;0.0} kn"); + + for (int index = 0; index < dockOrderButtons.Length; index++) + { + dockOrderButtons[index].EnableInClassList("voyage-control-active", (int)maneuver.Order == index - 2); + dockOrderButtons[index].SetEnabled(!maneuver.LinesAttached || index == 2); + } + RefreshDockLine(dockBowLineButton, maneuver, true); + RefreshDockLine(dockSternLineButton, maneuver, false); + if (dockAutopilotButton != null) + { + dockAutopilotButton.SetEnabled(maneuver.ReadyForAutopilot); + dockAutopilotButton.EnableInClassList("voyage-control-active", maneuver.ReadyForAutopilot); + } + + string instruction = DockHelmInstruction(maneuver); + SetPassageText(dockInstruction, instruction); + dockInstruction.EnableInClassList("dock-instruction-warning", maneuver.AtChannelEdge); + if (dockPlan != null && Time.unscaledTime >= dockNextPlanPaint) + { + dockNextPlanPaint = Time.unscaledTime + .08f; + dockPlan.MarkDirtyRepaint(); + } + } + + private bool DockRadarAvailable => Ship != null && Market.HullRank(Ship.HullIndex) >= Market.HullRank(Market.Coastal); + + private bool DockAdvancedRadarAvailable => Ship != null && Market.HullRank(Ship.HullIndex) >= Market.HullRank(Market.Ocean); + + private void ToggleDockLine(DockManeuver maneuver, bool bow) + { + maneuver.ToggleLine(bow); + RefreshDockManeuverControls(maneuver); + } + + private static void RefreshDockLine(Button button, DockManeuver maneuver, bool bow) + { + bool secure = bow ? maneuver.BowLine : maneuver.SternLine; + string line = bow ? "bow line" : "stern line"; + string shortcut = bow ? "F" : "G"; + button.text = maneuver.Arriving + ? secure ? $"{(bow ? "Bow" : "Stern")} line secure" : $"Make fast {line} {shortcut}" + : secure ? $"Haul in {line} {shortcut}" : $"{(bow ? "Bow" : "Stern")} line aboard"; + button.SetEnabled(maneuver.CanToggleLine(bow)); + button.EnableInClassList("dock-line-complete", maneuver.Arriving ? secure : !secure); + button.tooltip = maneuver.Arriving ? "Bring this end of the ship close to the berth and stop to secure its line." + : "Bring this line aboard before leaving the berth."; + } + + private static string DockHelmInstruction(DockManeuver maneuver) + { + if (maneuver.Arriving) + { + if (maneuver.Secured) + return "Both lines are secure."; + if (maneuver.CanToggleLine(true) || maneuver.CanToggleLine(false)) + return "Make fast the bow and stern lines when both ends are alongside."; + if (maneuver.AtBerth) + return $"Set Stop and slow below {DockManeuver.LinesSpeedLimit:0.00} kn before securing the lines. Use a short astern order to check forward way."; + } + if (maneuver.AtChannelEdge) + return "Shallow water or quay edge. Slow down and steer back into the marked channel."; + if (maneuver.Arriving) + { + float approachLead = Mathf.Max(25f, 4f * maneuver.BerthAlongTolerance); + if (Vector2.Distance(maneuver.Position, maneuver.Berth) < approachLead) + return $"Line up alongside at {maneuver.TargetHeading:000}°. Set Stop and let the ship coast, or use astern power to check forward way."; + return "Follow the marked channel toward the berth. Reduce power early for a slow, parallel approach."; + } + if (maneuver.BowLine || maneuver.SternLine) + return "Haul in both lines, then select Dead slow ahead to leave the berth."; + if (maneuver.ReadyForAutopilot) + return "The ship is clear of the channel. Engage autopilot when ready."; + if (maneuver.ChannelClear) + return $"Keep heading near {maneuver.TargetHeading:000}°, center the ship, and make {DockManeuver.HandoffMinimumSpeed:0.0}–{DockManeuver.HandoffMaximumSpeed:0.0} kn ahead to engage autopilot."; + return $"Follow the marked channel toward its exit. Use the rudder to bring the heading back to {maneuver.TargetHeading:000}°."; + } + + private static float DockInput(float keyboard, float held, float pulse) => keyboard != 0 ? keyboard : held != 0 ? held : pulse; + + private Button DockMomentaryButton(string label, string id, bool thruster, float direction) + { + Button button = Action(label, null, "voyage-view-button dock-momentary", id); + int pointer = -1; + float pressedAt = 0; + void SetHold(float value) + { + if (thruster) + dockThrusterHold = value; + else + dockRudderHold = value; + button.EnableInClassList("voyage-control-active", value != 0); + } + void Pulse() + { + if (thruster) + { + dockThrusterPulse = direction; + dockThrusterUntil = Time.unscaledTime + .32f; + } + else + { + dockRudderPulse = direction; + dockRudderUntil = Time.unscaledTime + .32f; + } + } + button.tooltip = thruster ? "Hold to push the bow sideways at low speed." : "Hold to turn the rudder while water is flowing past it."; + button.RegisterCallback(evt => + { + if (evt.button != 0 || pointer != -1) + return; + pointer = evt.pointerId; + pressedAt = Time.unscaledTime; + SetHold(direction); + button.CapturePointer(pointer); + button.Focus(); + evt.StopImmediatePropagation(); + }, TrickleDown.TrickleDown); + button.RegisterCallback(evt => + { + if (evt.pointerId != pointer) + return; + if (Time.unscaledTime - pressedAt < .12f) + Pulse(); + SetHold(0); + pointer = -1; + button.ReleasePointer(evt.pointerId); + evt.StopImmediatePropagation(); + }, TrickleDown.TrickleDown); + button.RegisterCallback(evt => + { + if (evt.pointerId == pointer) + button.ReleasePointer(pointer); + }); + button.RegisterCallback(_ => + { + pointer = -1; + SetHold(0); + }); + button.RegisterCallback(evt => + { + Pulse(); + evt.StopImmediatePropagation(); + }, TrickleDown.TrickleDown); + return button; + } + + private static void PaintDockPlan(MeshGenerationContext context, DockManeuver maneuver) + { + Rect bounds = context.visualElement.contentRect; + if (bounds.width < 32f || bounds.height < 32f) + return; + Painter2D painter = context.painter2D; + float channelLength = maneuver.ChannelEnd - maneuver.Berth.x; + float berthSide = maneuver.PierY >= 0 ? 1 : -1; + float halfWidth = Mathf.Max(maneuver.ChannelHalfWidth, Mathf.Abs(maneuver.PierY)) * 1.13f; + float left = maneuver.Berth.x - .10f * channelLength; + float right = maneuver.ChannelEnd + .10f * channelLength; + Vector2 Point(float along, float lateral) => new( + Mathf.Lerp(10, bounds.width - 10, Mathf.InverseLerp(left, right, along)), + Mathf.Lerp(7, bounds.height - 7, Mathf.InverseLerp(-halfWidth, halfWidth, lateral))); + + float pierEnd = maneuver.Berth.x + maneuver.PierHalfLength; + Vector2 pierStart = Point(left, maneuver.PierY); + Vector2 pierTip = Point(pierEnd, berthSide * halfWidth); + painter.fillColor = new Color(.35f, .32f, .24f); + painter.BeginPath(); + painter.MoveTo(pierStart); + painter.LineTo(new Vector2(pierTip.x, pierStart.y)); + painter.LineTo(pierTip); + painter.LineTo(new Vector2(pierStart.x, pierTip.y)); + painter.ClosePath(); + painter.Fill(); + + painter.strokeColor = new Color(.37f, .58f, .59f, .67f); + painter.lineWidth = 1; + painter.BeginPath(); + painter.MoveTo(Point(maneuver.Berth.x, maneuver.Berth.y)); + painter.LineTo(Point(maneuver.Berth.x + channelLength * .30f, 0)); + painter.LineTo(Point(right, 0)); + painter.Stroke(); + + float channelSide = maneuver.ChannelHalfWidth * .82f; + for (int row = 1; row <= 4; row++) + { + float markX = Mathf.Lerp(maneuver.Berth.x, maneuver.ChannelEnd, row * .25f); + DockMapMark(painter, Point(markX, -channelSide), new Color(.26f, .70f, .53f)); + DockMapMark(painter, Point(markX, channelSide), new Color(.80f, .39f, .31f)); + } + + painter.strokeColor = DockMarkColor; + painter.lineWidth = 1.1f; + painter.BeginPath(); + painter.MoveTo(Point(maneuver.ChannelEnd, -channelSide)); + painter.LineTo(Point(maneuver.ChannelEnd, channelSide)); + painter.Stroke(); + DockMapMark(painter, Point(maneuver.Berth.x, maneuver.Berth.y), DockRouteColor); + + Vector2 ship = Point(maneuver.Position.x, maneuver.Position.y); + float radians = maneuver.Heading * Mathf.Deg2Rad; + Vector2 bow = new(Mathf.Cos(radians), Mathf.Sin(radians)); + Vector2 wing = new(-bow.y, bow.x); + painter.fillColor = DockMarkColor; + painter.strokeColor = new Color(.18f, .24f, .24f); + painter.lineWidth = 1.25f; + painter.BeginPath(); + painter.MoveTo(ship + bow * 9); + painter.LineTo(ship - bow * 6 + wing * 4); + painter.LineTo(ship - bow * 6 - wing * 4); + painter.ClosePath(); + painter.Fill(); + painter.Stroke(); + } + + private static void DockMapMark(Painter2D painter, Vector2 point, Color color) + { + painter.fillColor = color; + painter.BeginPath(); + painter.MoveTo(point + Vector2.up * 3); + painter.LineTo(point + Vector2.right * 3); + painter.LineTo(point + Vector2.down * 3); + painter.LineTo(point + Vector2.left * 3); + painter.ClosePath(); + painter.Fill(); + } + } +} diff --git a/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs.meta b/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs.meta new file mode 100644 index 0000000..03a49f2 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockManeuverControls.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 22d7069bf7ec752c1a8a9eb2d38b099b \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/DockPassage.cs b/Assets/BigShipTycoon/Runtime/DockPassage.cs new file mode 100644 index 0000000..16fe511 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockPassage.cs @@ -0,0 +1,131 @@ +using UnityEngine; + +namespace BigShipTycoon +{ + public sealed partial class TycoonApp + { + private static readonly float[] DockRadarRanges = { 75f, 150f, 300f, 600f }; + + private DockManeuver ActiveDockManeuver => underway != null && Ship != null + && fleetPassages.TryGetValue(Ship, out FleetPassage passage) ? passage.Dock : null; + + private void FocusDockManeuver(DockManeuver dock) + { + ResetPassageView(); + passageBusinessOpen = false; + ReleaseHelm(); + harbor.PresentDockBridge(null, 0, false); + harbor.ShowDeck(-1); + harbor.BeginDockManeuver(dock.Arriving ? underway.Destination : underway.Origin, dock); + harbor.PresentDockManeuver(dock, 0); + } + + private void BeginDockArrival(FleetPassage passage, Ship ship) + { + passage.Dock = new DockManeuver(ship.HullIndex, true, passage.Helm.Speed); + passage.Speed = 1; + passage.RestoredView = null; + if (ship != Ship) + { + ShowFleetArrivalNotice($"{ship.Name} is waiting for you at the {Market.Ports[passage.Voyage.Destination].Name} channel entrance.", false); + return; + } + + passageSpeed = 1; + ResetShorePlanning(); + passageAudio.AnnounceApproach(); + FocusDockManeuver(passage.Dock); + Save(); + Render(); + } + + private void UpdateActiveDockManeuver(DockManeuver dock, float delta) + { + if (fleetOpen) + { + SetPassageFreeLook(false); + return; + } + + UpdateDockManeuverControls(delta); + if (ActiveDockManeuver != dock) + return; + + UpdatePassageCameraLook(delta); + harbor.PresentDockManeuver(dock, delta); + DisplayDockInstruments(dock); + harbor.UpdatePassengers(livePassage, delta); + UpdateAnnouncement(); + UpdatePilotageGuide(dock); + if (dock.Arriving && dock.Secured) + FinishVoyage(); + } + + private void EngageDockAutopilot() + { + if (paused || fleetOpen || ActiveDockManeuver is not { Arriving: false, ReadyForAutopilot: true } dock) + return; + + FleetPassage passage = fleetPassages[Ship]; + passage.Dock = null; + StopPilotageGuide(); + passageHelm.TakeDepartureSpeed(dock.SpeedKnots); + harbor.PresentDockBridge(null, 0, false); + harbor.EndDockManeuver(); + harbor.BeginPassage(underway.Weather, PassageDuration(underway)); + PresentVessel(0); + if (passageBridge) + harbor.ViewBridge(); + passageAudio.Announce(PassageAnnouncement.Departure); + Save(); + Render(); + } + + private void ShowDockBridge() + { + if (ActiveDockManeuver == null) + return; + passageBridge = true; + harbor.ViewBridge(); + DisplayDockInstruments(ActiveDockManeuver); + Render(); + } + + private void ShowDockExterior() + { + if (ActiveDockManeuver == null) + return; + passageBridge = false; + harbor.ShowDeck(-1); + harbor.PresentDockBridge(null, 0, false); + harbor.ResetView(true); + Render(); + } + + private void DisplayDockInstruments(DockManeuver dock) + { + if (!passageBridge || dock == null) + return; + FleetPassage passage = fleetPassages[Ship]; + harbor.PresentDockBridge(dock, DockRadarRanges[passage.DockRadarRange], passage.DockRadarNorthUp); + } + + private void CycleDockRadarRange() + { + if (ActiveDockManeuver == null || !DockRadarAvailable) + return; + FleetPassage passage = fleetPassages[Ship]; + passage.DockRadarRange = (passage.DockRadarRange + 1) % DockRadarRanges.Length; + DisplayDockInstruments(passage.Dock); + } + + private void ToggleDockRadarOrientation() + { + if (ActiveDockManeuver == null || !DockAdvancedRadarAvailable) + return; + FleetPassage passage = fleetPassages[Ship]; + passage.DockRadarNorthUp = !passage.DockRadarNorthUp; + DisplayDockInstruments(passage.Dock); + } + } +} diff --git a/Assets/BigShipTycoon/Runtime/DockPassage.cs.meta b/Assets/BigShipTycoon/Runtime/DockPassage.cs.meta new file mode 100644 index 0000000..833e18a --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/DockPassage.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 04b43a30d795bff738e5539184c58552 \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/FirstVoyageGuide.cs b/Assets/BigShipTycoon/Runtime/FirstVoyageGuide.cs index 65defc2..ca2a6d6 100644 --- a/Assets/BigShipTycoon/Runtime/FirstVoyageGuide.cs +++ b/Assets/BigShipTycoon/Runtime/FirstVoyageGuide.cs @@ -90,6 +90,11 @@ namespace BigShipTycoon { if (guideContext == GuideStep.Off) return; + if (ActiveDockManeuver is DockManeuver dock) + { + DrawPilotageGuide(shell, dock); + return; + } (string heading, string note, string target) = GuideMessage(); var guide = Add(shell, "voyage-guide"); @@ -148,7 +153,7 @@ namespace BigShipTycoon if (blocker != null) return ("Clear departure", blocker, null); return company.IsCaptainCareer - ? ("Clear departure", "Choose Cast off, then open the bridge to try your first helm check.", "dispatch") + ? ("Clear departure", "Choose Cast off to release the lines and pilot out through the channel.", "dispatch") : ("Clear departure", "Choose Cast off. Watch the crossing or skip to arrival.", "dispatch"); case GuideStep.Review: diff --git a/Assets/BigShipTycoon/Runtime/FleetOverview.cs b/Assets/BigShipTycoon/Runtime/FleetOverview.cs index d84bf57..9db2cca 100644 --- a/Assets/BigShipTycoon/Runtime/FleetOverview.cs +++ b/Assets/BigShipTycoon/Runtime/FleetOverview.cs @@ -119,7 +119,7 @@ namespace BigShipTycoon int sailing = 0; foreach (FleetRow row in rows) { - var (voyage, session, helm, speed) = FleetStatus(row.Ship); + var (voyage, session, helm, dock, speed) = FleetStatus(row.Ship); if (row.Voyage != voyage) { row.Voyage = voyage; @@ -150,8 +150,11 @@ namespace BigShipTycoon { sailing++; calls[voyage.Origin] = calls[voyage.Destination] = true; - SetPassageText(row.Status, $"Underway · {Market.Ports[voyage.Origin].Name} → {Market.Ports[voyage.Destination].Name}"); - string motion = FleetMotion(voyage, session, helm, speed); + SetPassageText(row.Status, dock == null + ? $"Underway · {Market.Ports[voyage.Origin].Name} → {Market.Ports[voyage.Destination].Name}" + : $"Pilot required · {Market.Ports[dock.Arriving ? voyage.Destination : voyage.Origin].Name}"); + string motion = dock == null ? FleetMotion(voyage, session, helm, speed) + : dock.Arriving ? "Waiting for manual docking" : "Waiting for manual departure"; SetPassageText(row.Readout, $"{voyage.Guests:N0} guests · {motion}"); } } diff --git a/Assets/BigShipTycoon/Runtime/FleetPassageSave.cs b/Assets/BigShipTycoon/Runtime/FleetPassageSave.cs index 81eca27..79b8386 100644 --- a/Assets/BigShipTycoon/Runtime/FleetPassageSave.cs +++ b/Assets/BigShipTycoon/Runtime/FleetPassageSave.cs @@ -7,11 +7,15 @@ namespace BigShipTycoon internal sealed class FleetPassageSnapshot { public int ShipIndex, Speed; - public bool ApproachAnnounced, HasDeparturePlan, HasView; + public int DockRadarRange; + public int PilotageCuesPlayed; + public bool DockRadarNorthUp, HasRadarSettings; + public bool ApproachAnnounced, HasDeparturePlan, HasView, HasDockManeuver; public Voyage Voyage; public HelmSnapshot Helm; public OnboardSessionSnapshot Session; public PassageViewSnapshot View; + public DockManeuverSnapshot Dock; } [Serializable] @@ -45,7 +49,10 @@ namespace BigShipTycoon HasDeparturePlan = hasDeparturePlan, ApproachAnnounced = foreground ? passageAudio.ApproachSent : passage.ApproachAnnounced, Helm = passage.Helm.CaptureState(), Session = passage.Session.CaptureState(), - HasView = view != null, View = view + HasView = view != null, View = view, + HasDockManeuver = passage.Dock != null, Dock = passage.Dock?.Capture(), + HasRadarSettings = company.IsCaptainCareer, DockRadarRange = passage.DockRadarRange, + DockRadarNorthUp = passage.DockRadarNorthUp, PilotageCuesPlayed = passage.PilotageCuesPlayed }); } return snapshots.ToArray(); @@ -78,7 +85,16 @@ namespace BigShipTycoon FocusPassage(passage, false); PassageViewSnapshot view = passage.RestoredView; passage.RestoredView = null; - if (view != null) + if (passage.Dock != null) + { + if (view?.Bridge == true) + { + passageBridge = true; + harbor.ViewBridge(); + DisplayDockInstruments(passage.Dock); + } + } + else if (view != null) RestorePassageView(view); else if (passage.Helm.Manual) { @@ -161,6 +177,32 @@ namespace BigShipTycoon if (!passage.Helm.RestoreState(snapshot.Helm) || !passage.Session.RestoreState(snapshot.Session)) return false; passage.Speed = snapshot.Speed; + passage.PilotageCuesPlayed = snapshot.PilotageCuesPlayed & ((1 << 11) - 1); + if (snapshot.HasRadarSettings) + { + if ((uint)snapshot.DockRadarRange >= (uint)DockRadarRanges.Length) + return false; + passage.DockRadarRange = snapshot.DockRadarRange; + passage.DockRadarNorthUp = snapshot.DockRadarNorthUp; + } + if (snapshot.HasDockManeuver) + { + DockManeuverSnapshot dock = snapshot.Dock; + if (!savedCompany.IsCaptainCareer || dock == null || passage.Speed != 1 + || dock.Arriving != passage.Helm.Arrived + || !dock.Arriving && passage.Helm.Position.sqrMagnitude > 0) + return false; + passage.Dock = new DockManeuver(ship.HullIndex, dock.Arriving); + if (!passage.Dock.Restore(dock)) + return false; + } + else if (savedCompany.IsCaptainCareer && (passage.Helm.Arrived + || passage.Helm.Position.sqrMagnitude == 0 && passage.Helm.Speed == 0 && !passage.Helm.Manual)) + { + // Older careers could be saved at the opening of a port cinematic. + passage.Dock = new DockManeuver(ship.HullIndex, passage.Helm.Arrived, passage.Helm.Speed); + passage.Speed = 1; + } passage.ApproachAnnounced = snapshot.ApproachAnnounced; PassageViewSnapshot view = snapshot.View; if (snapshot.HasView && view != null && view.Deck >= -1 && view.Deck < ship.Decks.Count diff --git a/Assets/BigShipTycoon/Runtime/FleetPassages.cs b/Assets/BigShipTycoon/Runtime/FleetPassages.cs index cb682bc..996016c 100644 --- a/Assets/BigShipTycoon/Runtime/FleetPassages.cs +++ b/Assets/BigShipTycoon/Runtime/FleetPassages.cs @@ -13,6 +13,10 @@ namespace BigShipTycoon public readonly Voyage Voyage; public readonly OnboardSession Session; public readonly HelmNavigation Helm; + public DockManeuver Dock; + public int DockRadarRange; + public int PilotageCuesPlayed; + public bool DockRadarNorthUp; public int Speed = 1; public bool ApproachAnnounced; public PassageViewSnapshot RestoredView; @@ -22,13 +26,14 @@ namespace BigShipTycoon Voyage = voyage; Session = new OnboardSession(ship, voyage) { Assisted = assisted }; Helm = new HelmNavigation(PassageDuration(voyage), ship.HullIndex); + DockRadarRange = ship.HullIndex is Market.Ocean or Market.Mega ? 2 : 1; } } - private (Voyage Voyage, OnboardSession Session, HelmNavigation Helm, int Speed) FleetStatus(Ship ship) + private (Voyage Voyage, OnboardSession Session, HelmNavigation Helm, DockManeuver Dock, int Speed) FleetStatus(Ship ship) { if (ship != null && fleetPassages.TryGetValue(ship, out FleetPassage passage)) - return (passage.Voyage, passage.Session, passage.Helm, passage.Speed); + return (passage.Voyage, passage.Session, passage.Helm, passage.Dock, passage.Speed); return default; } @@ -48,7 +53,11 @@ namespace BigShipTycoon if (underway != null) { if (fleetPassages.TryGetValue(Ship, out FleetPassage previous)) + { previous.ApproachAnnounced = passageAudio.ApproachSent; + if (previous.Dock != null) + previous.RestoredView = CapturePassageView(); + } ReleaseHelm(); harbor.EndPassage(); } @@ -61,8 +70,8 @@ namespace BigShipTycoon deckIndex = 0; ResetItinerary(); Notify(null); - if (fleetPassages.TryGetValue(Ship, out FleetPassage selected)) - FocusPassage(selected, false); + if (fleetPassages.ContainsKey(Ship)) + ResumeSelectedSavedPassage(); else harbor.ResetView(true); @@ -80,13 +89,19 @@ namespace BigShipTycoon harbor.Show(Ship); harbor.BeginPassage(underway.Weather, PassageDuration(underway)); harbor.ShowDeck(-1); - PresentVessel(0); + if (passage.Dock is DockManeuver dock) + FocusDockManeuver(dock); + else + PresentVessel(0); harbor.UpdatePassengers(livePassage, 0); - passageAudio.Begin(underway.Destination, departure, passage.ApproachAnnounced); + passageAudio.Begin(underway.Destination, departure && passage.Dock == null, passage.ApproachAnnounced); + if (passage.Dock is { Arriving: true }) + passageAudio.AnnounceApproach(); } private void ResetPassageView() { + StopPilotageGuide(); passageDeck = passageServiceArea = -1; passageBridge = passageExploring = false; passageSunZone = null; @@ -149,14 +164,21 @@ namespace BigShipTycoon bool docked = false; foreach (Ship ship in company.Fleet) { - if (ship == foreground || !fleetPassages.TryGetValue(ship, out FleetPassage passage)) + if (ship == foreground || !fleetPassages.TryGetValue(ship, out FleetPassage passage) || passage.Dock != null) continue; - passage.Helm.Advance(delta * passage.Speed, 0, passage.Session.SpeedFactor, passage.Voyage.Weather); + passage.Helm.Advance(delta * passage.Speed, 0, PassageEngineSpeed(passage.Helm, passage.Session), passage.Voyage.Weather); passage.Session.AdvanceTo(passage.Helm.Progress); if (!passage.Helm.Arrived) continue; + if (company.IsCaptainCareer) + { + BeginDockArrival(passage, ship); + Save(); + continue; + } + string failure = SettleFleetPassage(ship, passage.Session); if (failure == null) { diff --git a/Assets/BigShipTycoon/Runtime/Harbor.cs b/Assets/BigShipTycoon/Runtime/Harbor.cs index 06ce015..e78a0ab 100644 --- a/Assets/BigShipTycoon/Runtime/Harbor.cs +++ b/Assets/BigShipTycoon/Runtime/Harbor.cs @@ -179,8 +179,8 @@ namespace BigShipTycoon { cameraMode = CameraMode.Orbit; walkSpace = null; - targetYaw = deckIndex >= 0 ? 17f : sailing ? 24f : DefaultYaw; - targetPitch = deckIndex >= 0 ? 57f : sailing ? 13f : DefaultPitch; + targetYaw = DockManeuverVisible ? dockOrbitYaw : deckIndex >= 0 ? 17f : sailing ? 24f : DefaultYaw; + targetPitch = DockManeuverVisible ? 17f : deckIndex >= 0 ? 57f : sailing ? 13f : DefaultPitch; targetZoom = OverviewZoom; targetOrbitOffset = Vector3.zero; if (!immediate) @@ -434,6 +434,8 @@ namespace BigShipTycoon public void EndPassage() { + PresentDockBridge(null, 0, false); + EndDockManeuver(); sailing = false; HideRiverBanks(); waterSurface.localPosition = Vector3.zero; @@ -853,6 +855,7 @@ namespace BigShipTycoon private void OnDestroy() { + ReleaseDockManeuver(); ReleaseFrame(); ReleaseShip(); ReleasePortQuay(); diff --git a/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs b/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs new file mode 100644 index 0000000..28926cb --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs @@ -0,0 +1,278 @@ +using System.Collections.Generic; +using UnityEngine; + +namespace BigShipTycoon +{ + public sealed partial class Harbor + { + private readonly List dockMeshes = new(); + private readonly List dockFinishes = new(); + private readonly Vector3[] ropePoints = new Vector3[9]; + private GameObject dockSite; + private PortScenery dockWaterfront; + private LineRenderer dockBowRope, dockSternRope; + private Vector3 dockBowBollard, dockSternBollard; + private float dockSeaSeverity, dockOrbitYaw; + + internal bool DockManeuverVisible => dockSite != null && dockSite.activeSelf && portQuay != null && portQuay.activeSelf; + internal (bool Bow, bool Stern) DockLinesVisible => (dockBowRope != null && dockBowRope.enabled, dockSternRope != null && dockSternRope.enabled); + + internal void BeginDockManeuver(int port, DockManeuver maneuver) + { + if (vessel == null || maneuver == null || (uint)port >= (uint)PortProfiles.Length) + return; + + EndDockManeuver(); + if (!sailing) + BeginPassage(); + HideRiverBanks(); + portScenery?.SetVisible(false); + portMatteAspect = 0; + dockSite = new GameObject(Market.Ports[port].Name + " maneuvering area"); + dockSite.transform.SetParent(transform, false); + + float berthLength = maneuver.PierHalfLength * 2f; + if (portQuay == null || !Mathf.Approximately(quayLength, berthLength)) + { + ReleaseCinematicQuay(); + quayLength = berthLength; + portQuay = BuildPortQuay(); + } + float quayZ = -maneuver.PierY - QuayWidth * .5f; + portQuay.transform.SetLocalPositionAndRotation(new Vector3(maneuver.Berth.x, 0, quayZ), + Quaternion.Euler(0, 180f, 0)); + portQuay.SetActive(true); + Vector3 quay = portQuay.transform.position; + water.SetVector("_PortBerth", new Vector4(quay.x, quay.z, quayLength * .5f, QuayWidth * .5f)); + + PortProfile profile = PortProfiles[port]; + BuildDockWaterfront(port, profile, maneuver); + BuildDockChannel(maneuver); + quayFinishes[0].color = Color.Lerp(new Color(.41f, .44f, .45f), profile.Facade, .35f); + quayFinishes[1].color = Color.Lerp(new Color(.53f, .52f, .47f), profile.Facade, .5f); + water.SetColor("_PortSky", profile.Sky); + water.SetFloat("_PortShallows", port is 1 or 3 or 13 or 16 ? .72f : .25f); + water.SetFloat("_PortMatteActive", 0); + water.SetFloat("_PortMotion", 1); + dockOrbitYaw = maneuver.Arriving ? 153f : -153f; + dockSeaSeverity = seaSeverity * .37f; + water.SetFloat("_WeatherSeverity", dockSeaSeverity); + Shader.SetGlobalFloat("_TycoonSeaWeather", dockSeaSeverity); + hullMotion = hullMotionVelocity = Vector3.zero; + wake.Reset(); + PresentDockManeuver(maneuver, 0); + ResetOrbit(true); + } + + internal void PresentDockManeuver(DockManeuver maneuver, float delta) + { + if (dockSite == null || vessel == null) + return; + + seaTime += delta; + Vector2 center = new(maneuver.Position.x, -maneuver.Position.y); + float heading = maneuver.Heading; + float speed = maneuver.SpeedKnots; + bool river = displayedShip?.HullIndex == Market.River; + if (delta > 0) + { + float wash = Mathf.Lerp(.16f, river ? .41f : .30f, Mathf.Clamp01(maneuver.SpeedOverGroundKnots / 5f)); + Vector3 target = SampleSeaResponse(center, seaTime, heading, vesselLength, vesselBeam, dockSeaSeverity, river) * wash; + float response = Mathf.Lerp(.39f, .92f, Mathf.InverseLerp(32f, 300f, vesselLength)); + hullMotion = Vector3.SmoothDamp(hullMotion, target, ref hullMotionVelocity, response, Mathf.Infinity, delta); + } + passageHeading = heading; + vessel.SetLocalPositionAndRotation(new Vector3(center.x, hullMotion.x, center.y), + Quaternion.AngleAxis(heading, Vector3.up) * Quaternion.Euler(hullMotion.y, 0, hullMotion.z)); + + Vector2 bow = PortBow(heading); + water.SetVector("_HullSpan", new Vector4(vesselLength, vesselBeam, center.x, center.y)); + water.SetVector("_HullCourse", new Vector4(bow.x, -bow.y, Mathf.Clamp01(Mathf.Max(0, speed) / 19f), 0)); + water.SetFloat("_SeaTime", seaTime); + waterSurface.localPosition = new Vector3(center.x, 0, center.y); + Shader.SetGlobalFloat("_TycoonSeaTime", seaTime); + float wakeSpeed = (speed >= 0 ? speed : Mathf.Abs(speed) * .60f) * (river ? .72f : 1f); + wake.Update(center, bow, wakeSpeed, vesselLength, vesselBeam, seaTime, dockSeaSeverity, sheltered: true); + SetRudder(maneuver.Rudder); + SetDockRope(dockBowRope, dockBowBollard, maneuver.BowLine, true, maneuver.Arriving); + SetDockRope(dockSternRope, dockSternBollard, maneuver.SternLine, false, maneuver.Arriving); + } + + internal void EndDockManeuver() + { + if (dockSite == null) + return; + ReleaseDockManeuver(); + if (portQuay != null) + { + portQuay.SetActive(false); + portQuay.transform.localRotation = Quaternion.identity; + } + water.SetFloat("_PortMotion", 0); + water.SetFloat("_WeatherSeverity", sailing ? seaSeverity : 0); + Shader.SetGlobalFloat("_TycoonSeaWeather", sailing ? seaSeverity : 0); + wake.Reset(); + } + + private void ReleaseDockManeuver() + { + dockWaterfront?.Release(); + dockWaterfront = null; + if (dockSite != null) + { + dockSite.SetActive(false); + Destroy(dockSite); + dockSite = null; + } + foreach (Mesh mesh in dockMeshes) + Destroy(mesh); + foreach (Material material in dockFinishes) + Destroy(material); + dockMeshes.Clear(); + dockFinishes.Clear(); + dockBowRope = dockSternRope = null; + } + + private void BuildDockWaterfront(int port, PortProfile profile, DockManeuver maneuver) + { + var shore = new GameObject("Port shoreline orientation").transform; + shore.SetParent(dockSite.transform, false); + float shoreDatum = Market.IsRiverPort(port) ? 27f : 46f; + float apronDepth = profile.Terrain is PortTerrain.Cliffs or PortTerrain.Volcanic ? 25f : 16f; + float shoreZ = -maneuver.PierY - QuayWidth - apronDepth + shoreDatum; + shore.SetLocalPositionAndRotation(new Vector3(0, 0, shoreZ), Quaternion.Euler(0, 180f, 0)); + dockWaterfront = new PortScenery(shore, port, profile); + + var apron = new HarborMesh(); + float apronWidth = Mathf.Clamp(vesselLength * .35f, 12f, 52f); + float edge = -maneuver.PierY - QuayWidth; + apron.Box(new Vector3(maneuver.Berth.x, .53f, edge - apronDepth * .5f), + new Vector3(apronWidth, 1.55f, apronDepth + 1.1f)); + DockBatch(apron, "Cargo apron between quay and shore", Color.Lerp(profile.Facade, new Color(.43f, .45f, .44f), .67f)); + } + + private void BuildDockChannel(DockManeuver maneuver) + { + var red = new HarborMesh(); + var green = new HarborMesh(); + var white = new HarborMesh(); + var work = new HarborMesh(); + var shadows = new HarborMesh(); + float signal = Mathf.Clamp(vesselLength * .024f, .84f, 2.25f); + for (int mark = 0; mark < 4; mark++) + { + float x = maneuver.ChannelEnd * Mathf.Lerp(.26f, 1f, mark / 3f); + float lateral = maneuver.ChannelHalfWidth + signal * .46f; + float shoreSide = x < maneuver.PierHalfLength ? Mathf.Min(lateral, maneuver.PierY - signal * .74f) : lateral; + BuildDockMark(green, white, shadows, x, -shoreSide, signal, false, mark == 3); + BuildDockMark(red, white, shadows, x, lateral, signal, true, mark == 3); + } + + float mooringX = vesselLength * .365f; + float sign = maneuver.Arriving ? -1f : 1f; + float bollardZ = -maneuver.PierY - 1.29f; + dockBowBollard = new Vector3(maneuver.Berth.x + sign * mooringX, 1.76f, bollardZ); + dockSternBollard = new Vector3(maneuver.Berth.x - sign * mooringX, 1.76f, bollardZ); + BuildDockBollard(work, shadows, dockBowBollard); + BuildDockBollard(work, shadows, dockSternBollard); + DockBatch(red, "Red channel marks", new Color(.82f, .18f, .105f)); + DockBatch(green, "Green channel marks", new Color(.11f, .57f, .36f)); + DockBatch(white, "Channel lamps and range boards", new Color(.89f, .86f, .73f), .12f); + DockBatch(work, "Mooring bollard jackets and deck paint", new Color(.87f, .63f, .22f)); + DockBatch(shadows, "Channel mark metalwork", new Color(.20f, .23f, .25f)); + + var rope = new Material(surface) { color = new Color(.94f, .79f, .52f), name = "Mooring line fibre" }; + rope.SetFloat("_Roughness", .83f); + rope.SetFloat("_Finish", (float)SurfaceFinish.Fabric); + rope.SetFloat("_Emissive", .05f); + dockFinishes.Add(rope); + dockBowRope = CreateDockRope("Bow mooring line", rope); + dockSternRope = CreateDockRope("Stern mooring line", rope); + } + + private static void BuildDockMark(HarborMesh paint, HarborMesh light, HarborMesh metal, float x, float z, + float size, bool conical, bool gate) + { + Vector3 foot = new(x, -.11f, z); + Vector3 cap = foot + Vector3.up * (size * (gate ? 3.65f : 2.75f)); + paint.Rod(foot, foot + Vector3.up * size * .83f, size * .47f, 12, true); + metal.Rod(foot + Vector3.up * size * .64f, cap, size * .105f, 8, true); + float signRadius = size * (gate ? .54f : .44f); + Vector3 board = cap - Vector3.up * size * .69f; + if (conical) + paint.Loft(DockMarkRing(board, signRadius), new Vector2(x, z), true, + new Vector3(1, board.y, 1), new Vector3(.07f, board.y + size * .67f, .07f)); + else + paint.Box(board + Vector3.up * size * .24f, new Vector3(signRadius * 1.5f, size * .62f, signRadius * 1.8f)); + light.Radome(cap + Vector3.up * size * .059f, size * .16f); + if (gate) + light.Rod(foot + Vector3.up * size * .39f, foot + Vector3.up * size * .61f, size * .475f, 12, true); + } + + private static Vector2[] DockMarkRing(Vector3 point, float radius) + { + var ring = new Vector2[10]; + for (int i = 0; i < ring.Length; i++) + { + float angle = i * Mathf.PI * 2f / ring.Length; + ring[i] = new Vector2(point.x + Mathf.Cos(angle) * radius, point.z - Mathf.Sin(angle) * radius); + } + return ring; + } + + private static void BuildDockBollard(HarborMesh paint, HarborMesh metal, Vector3 foot) + { + metal.Rod(foot - Vector3.up * .44f, foot, .24f, 10, true); + paint.Rod(foot - Vector3.up * .04f, foot + Vector3.up * .14f, .31f, 10, true); + paint.Box(foot + new Vector3(0, -.406f, .77f), new Vector3(1.52f, .023f, .21f)); + } + + private LineRenderer CreateDockRope(string label, Material material) + { + var gameObject = new GameObject(label, typeof(LineRenderer)) { layer = 8 }; + gameObject.transform.SetParent(dockSite.transform, false); + var renderer = gameObject.GetComponent(); + renderer.sharedMaterial = material; + renderer.positionCount = ropePoints.Length; + renderer.useWorldSpace = true; + renderer.generateLightingData = true; + renderer.widthMultiplier = Mathf.Clamp(vesselLength * .0036f, .093f, .26f); + renderer.SetPositions(ropePoints); + return renderer; + } + + private void SetDockRope(LineRenderer rope, Vector3 bollard, bool attached, bool bow, bool arriving) + { + rope.enabled = attached; + if (!attached) + return; + float side = arriving ? 1f : -1f; + float deckHeight = VesselExterior.BaseDeck(displayedShip); + float reach = bow ? .67f : .93f; + Vector3 cleat = vessel.TransformPoint(new Vector3(vesselLength * (bow ? .365f : -.365f), deckHeight + .18f, side * vesselBeam * reach)); + Vector3 pier = transform.TransformPoint(bollard); + float sag = Mathf.Clamp(Vector3.Distance(cleat, pier) * .054f, .10f, .47f); + for (int i = 0; i < ropePoints.Length; i++) + { + float t = i / (ropePoints.Length - 1f); + ropePoints[i] = Vector3.Lerp(cleat, pier, t) - Vector3.up * (4f * t * (1f - t) * sag); + } + rope.SetPositions(ropePoints); + } + + private void DockBatch(HarborMesh batch, string name, Color color, float emission = 0) + { + var model = new GameObject(name, typeof(MeshFilter), typeof(MeshRenderer)) { layer = 8 }; + model.transform.SetParent(dockSite.transform, false); + Mesh mesh = batch.Bake(); + var material = new Material(surface) { color = color, name = name }; + material.SetFloat("_Roughness", .76f); + material.SetFloat("_Weather", .32f); + material.SetFloat("_Emissive", emission); + model.GetComponent().sharedMesh = mesh; + model.GetComponent().sharedMaterial = material; + dockMeshes.Add(mesh); + dockFinishes.Add(material); + } + } +} diff --git a/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs.meta b/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs.meta new file mode 100644 index 0000000..3ae11ac --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/HarborDockManeuver.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 8eae8bc33bc6d29939cfb5a2ccf560dc \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/HelmNavigation.cs b/Assets/BigShipTycoon/Runtime/HelmNavigation.cs index 594355e..420b7ab 100644 --- a/Assets/BigShipTycoon/Runtime/HelmNavigation.cs +++ b/Assets/BigShipTycoon/Runtime/HelmNavigation.cs @@ -55,12 +55,7 @@ namespace BigShipTycoon 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 cruising = cruiseKnots / WeatherSlowdown(weather); float targetSpeed = PropulsionStopped ? 0 : cruising * Mathf.Max(0, engineSpeedFactor); float requestedRudder = Mathf.Clamp(rudderInput, -1f, 1f) * RudderLimit; if (Manual) @@ -122,6 +117,21 @@ namespace BigShipTycoon return Mathf.Clamp(courseError * 1.55f - turnRate * 3.6f, -RudderLimit, RudderLimit); } + internal void TakeDepartureSpeed(float speedKnots) + { + Manual = PropulsionStopped = false; + Speed = Mathf.Clamp(speedKnots, 0, cruiseKnots); + } + + internal float HarborApproachFactor(float cruiseFactor, WeatherCondition weather) + { + float approachFactor = Mathf.Min(cruiseFactor, 4.3f * WeatherSlowdown(weather) / cruiseKnots); + return Mathf.Lerp(cruiseFactor, approachFactor, Mathf.SmoothStep(0, 1, Mathf.InverseLerp(.84f, .99f, Progress))); + } + + private static float WeatherSlowdown(WeatherCondition weather) => + weather switch { WeatherCondition.Swell => 1.14f, WeatherCondition.Storm => 1.32f, _ => 1f }; + internal void SetProgress(float progress) { Progress = Mathf.Clamp01(progress); diff --git a/Assets/BigShipTycoon/Runtime/PassageAnnouncements.cs b/Assets/BigShipTycoon/Runtime/PassageAnnouncements.cs index 0827839..9aa511e 100644 --- a/Assets/BigShipTycoon/Runtime/PassageAnnouncements.cs +++ b/Assets/BigShipTycoon/Runtime/PassageAnnouncements.cs @@ -10,6 +10,7 @@ namespace BigShipTycoon private void DrawAnnouncement(VisualElement overlay) { announcementBanner = Add(overlay, "passage-announcement"); + announcementBanner.EnableInClassList("dock-passage-announcement", ActiveDockManeuver != null); announcementBanner.pickingMode = PickingMode.Ignore; AddText(announcementBanner, "SHIP PA", "voyage-caption"); announcementCaption = AddText(announcementBanner, "", "passage-announcement-caption"); diff --git a/Assets/BigShipTycoon/Runtime/PassageInterface.cs b/Assets/BigShipTycoon/Runtime/PassageInterface.cs index af14386..8a711d3 100644 --- a/Assets/BigShipTycoon/Runtime/PassageInterface.cs +++ b/Assets/BigShipTycoon/Runtime/PassageInterface.cs @@ -23,6 +23,12 @@ namespace BigShipTycoon { var overlay = Add(workspace, "voyage-overlay"); overlay.pickingMode = PickingMode.Ignore; + if (ActiveDockManeuver != null) + { + DrawDockManeuverControls(overlay); + DrawAnnouncement(overlay); + return; + } var left = Add(overlay, "voyage-business"); left.pickingMode = PickingMode.Ignore; @@ -149,10 +155,8 @@ namespace BigShipTycoon : passageBridge || passageExploring ? "WASD to walk · Q / E to turn" : "Drag or Q / E to orbit · Wheel to zoom · Middle-drag to pan"; AddText(camera, cameraHelp, "voyage-camera-help"); - Button skip = Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now"); - if (company.IsCaptainCareer) - skip.tooltip = "Skipping finishes the trip without logging helm practice. Let the boat reach port to qualify."; - rail.Add(skip); + if (!company.IsCaptainCareer) + rail.Add(Action("Skip to arrival", FinishVoyage, "voyage-view-button voyage-skip", "dock-now")); DrawHelmControls(overlay); DrawStationInteractions(overlay); DrawVoyageMap(overlay); diff --git a/Assets/BigShipTycoon/Runtime/PilotageGuide.cs b/Assets/BigShipTycoon/Runtime/PilotageGuide.cs new file mode 100644 index 0000000..6ddfcaf --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/PilotageGuide.cs @@ -0,0 +1,154 @@ +using UnityEngine; +using UnityEngine.UIElements; + +namespace BigShipTycoon +{ + public sealed partial class TycoonApp + { + private enum PilotageLesson + { + ReleaseLines, GetUnderWay, FollowChannel, Autopilot, Approach, SlowShip, AlignBerth, SecureLines, + Radar, Thruster, Liner + } + + private AudioSource pilotageVoice; + private bool pilotageVoicePaused; + private PilotageLesson? pilotageReplay, voicedPilotageLesson; + private Label pilotageHeading, pilotageText; + private readonly AudioClip[] pilotageClips = new AudioClip[11]; + + private void InitializePilotageGuide() + { + pilotageVoice = gameObject.AddComponent(); + pilotageVoice.playOnAwake = false; + pilotageVoice.spatialBlend = 0; + pilotageVoice.volume = .96f; + } + + private static PilotageLesson CurrentPilotageLesson(DockManeuver dock) + { + if (!dock.Arriving) + { + if (dock.LinesAttached) + return PilotageLesson.ReleaseLines; + if (dock.ReadyForAutopilot) + return PilotageLesson.Autopilot; + return dock.Position.x < 9 && dock.SpeedKnots < .8f + ? PilotageLesson.GetUnderWay : PilotageLesson.FollowChannel; + } + if (dock.CanToggleLine(true) || dock.CanToggleLine(false) || dock.Secured) + return PilotageLesson.SecureLines; + if (dock.Position.x > Mathf.Max(25f, dock.ChannelEnd * .45f)) + return PilotageLesson.Approach; + return dock.SpeedOverGroundKnots > 1.35f + ? PilotageLesson.SlowShip : PilotageLesson.AlignBerth; + } + + private static (string Heading, string Copy) PilotageCopy(PilotageLesson lesson) => lesson switch + { + PilotageLesson.ReleaseLines => ("Release both mooring lines", "Bring in the bow and stern lines. The engine stays at Stop while either line is attached."), + PilotageLesson.GetUnderWay => ("Build a little forward speed", "Select Dead slow ahead or press W. Water needs to flow over the rudder before it can turn the boat."), + PilotageLesson.FollowChannel => ("Follow the marked channel", "Use small rudder inputs with A and D. Cross the outer marks on the centerline with forward way on."), + PilotageLesson.Autopilot => ("Hand over the helm", "You are clear and on course. Press H or select Engage autopilot to begin the crossing."), + PilotageLesson.Approach => ("Take the ship into port", "Follow the channel to the berth. Watch your speed and leave room to brake."), + PilotageLesson.SlowShip => ("Take the way off", "Press X for Stop and watch your speed. Apply a little astern if the ship is still closing too fast."), + PilotageLesson.AlignBerth => ("Bring the ship alongside", "Aim for the marked berth and line up parallel to the quay. Set Stop once you're alongside."), + PilotageLesson.SecureLines => ("Make the ship fast", "The ship is ready to secure. Attach both mooring lines to complete the arrival."), + PilotageLesson.Radar => ("Read the bridge radar", "The radar shows nearby shore and channel marks relative to the ship. Press R to change range."), + PilotageLesson.Thruster => ("Use the bow thruster at low speed", "Hold Z or C to move the bow to port or starboard. Release before the bow swings too far."), + _ => ("Allow for the liner’s momentum", "Watch the approach and turn-rate readouts. Plan your braking earlier and use N to change radar orientation.") + }; + + private PilotageLesson BridgePilotageLesson() => DockAdvancedRadarAvailable ? PilotageLesson.Liner + : ActiveDockManeuver.HasBowThruster ? PilotageLesson.Thruster : PilotageLesson.Radar; + + private AudioClip PilotageClip(PilotageLesson lesson) => + pilotageClips[(int)lesson] ??= Resources.Load($"Audio/Pilotage/{lesson}"); + + private void DrawPilotageGuide(VisualElement shell, DockManeuver dock) + { + var guide = Add(shell, "voyage-guide"); + guide.pickingMode = PickingMode.Ignore; + GameIcon(guide, "compass"); + var instructions = Add(guide, "voyage-guide-copy"); + instructions.pickingMode = PickingMode.Ignore; + var (heading, message) = PilotageCopy(CurrentPilotageLesson(dock)); + pilotageHeading = AddText(instructions, heading, "voyage-guide-heading"); + pilotageHeading.name = "pilotage-guide-heading"; + pilotageText = AddText(instructions, message, "voyage-guide-note"); + guide.Add(Action("Replay", () => pilotageReplay = CurrentPilotageLesson(dock), "voyage-guide-close", "pilotage-replay")); + if (passageBridge && DockRadarAvailable) + guide.Add(Action("Bridge tip", () => pilotageReplay = BridgePilotageLesson(), "voyage-guide-close", "pilotage-bridge-tip")); + guide.Add(Action("Hide guide", () => + { + company.TutorialStep = (int)GuideStep.Off; + StopPilotageGuide(); + Save(); + Render(); + }, "voyage-guide-close", "guide-skip")); + } + + private void UpdatePilotageGuide(DockManeuver dock) + { + if (company.TutorialStep == (int)GuideStep.Off || pilotageHeading?.panel == null) + return; + + PilotageLesson current = CurrentPilotageLesson(dock); + FleetPassage passage = fleetPassages[Ship]; + PilotageLesson cue = pilotageReplay ?? current; + if (pilotageVoice.isPlaying && voicedPilotageLesson is PilotageLesson previous + && (int)previous < (int)PilotageLesson.Radar && previous != current && !pilotageReplay.HasValue) + pilotageVoice.Stop(); + var (heading, copy) = PilotageCopy(pilotageReplay ?? ActiveEquipmentLesson() ?? current); + SetPassageText(pilotageHeading, heading); + SetPassageText(pilotageText, copy); + + if (passageAudio.CurrentAnnouncement.HasValue || pilotageVoicePaused || pilotageVoice.isPlaying && !pilotageReplay.HasValue) + return; + int bit = 1 << (int)cue; + if (!pilotageReplay.HasValue && (passage.PilotageCuesPlayed & bit) != 0) + { + if (!passageBridge || current is not (PilotageLesson.FollowChannel or PilotageLesson.Approach) || !DockRadarAvailable) + return; + cue = BridgePilotageLesson(); + bit = 1 << (int)cue; + if ((passage.PilotageCuesPlayed & bit) != 0) + return; + } + + pilotageReplay = null; + passage.PilotageCuesPlayed |= bit; + voicedPilotageLesson = cue; + pilotageVoice.clip = PilotageClip(cue); + if (pilotageVoice.clip != null) + pilotageVoice.Play(); + } + + private PilotageLesson? ActiveEquipmentLesson() + { + return pilotageVoice.isPlaying && voicedPilotageLesson is PilotageLesson lesson && (int)lesson >= (int)PilotageLesson.Radar ? lesson : null; + } + + private void PausePilotageVoice(bool pause) + { + if (pause && pilotageVoice.isPlaying) + { + pilotageVoice.Pause(); + pilotageVoicePaused = true; + } + else if (!pause && pilotageVoicePaused) + { + pilotageVoice.UnPause(); + pilotageVoicePaused = false; + } + } + + private void StopPilotageGuide() + { + pilotageVoice?.Stop(); + pilotageVoicePaused = false; + pilotageReplay = voicedPilotageLesson = null; + pilotageHeading = pilotageText = null; + } + } +} diff --git a/Assets/BigShipTycoon/Runtime/PilotageGuide.cs.meta b/Assets/BigShipTycoon/Runtime/PilotageGuide.cs.meta new file mode 100644 index 0000000..977b971 --- /dev/null +++ b/Assets/BigShipTycoon/Runtime/PilotageGuide.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e2302163ba9b8a4c98870e13649b7eec \ No newline at end of file diff --git a/Assets/BigShipTycoon/Runtime/TycoonApp.cs b/Assets/BigShipTycoon/Runtime/TycoonApp.cs index 19bca20..8c0e30f 100644 --- a/Assets/BigShipTycoon/Runtime/TycoonApp.cs +++ b/Assets/BigShipTycoon/Runtime/TycoonApp.cs @@ -50,6 +50,7 @@ namespace BigShipTycoon harbor.Initialize(); passageAudio = gameObject.AddComponent(); passageAudio.Initialize(); + InitializePilotageGuide(); deckAmbience = gameObject.AddComponent(); deckAmbience.Initialize(harbor); displayFont = Resources.Load("Display"); @@ -318,7 +319,8 @@ namespace BigShipTycoon if (underway != null) { DrawUnderway(scene); - DrawServiceNavigation(scene); + if (ActiveDockManeuver == null) + DrawServiceNavigation(scene); } else { diff --git a/Assets/BigShipTycoon/Runtime/VisualSmoke.cs b/Assets/BigShipTycoon/Runtime/VisualSmoke.cs index 02bb54d..6aa37fc 100644 --- a/Assets/BigShipTycoon/Runtime/VisualSmoke.cs +++ b/Assets/BigShipTycoon/Runtime/VisualSmoke.cs @@ -950,6 +950,27 @@ namespace BigShipTycoon private IEnumerator CaptainSmoke(string directory) { + float lastDisplacement = 0, lastCoast = 0; + foreach (int hull in new[] { Market.River, Market.Coastal, Market.Regional, Market.Ocean, Market.Mega }) + { + var moving = new DockManeuver(hull, true, 3f); + if (!CheckSmoke(moving.DisplacementTonnes > lastDisplacement && moving.NeutralCoastMetres > lastCoast, + "At the same speed, larger hulls displace more water and coast farther")) + yield break; + lastDisplacement = moving.DisplacementTonnes; + lastCoast = moving.NeutralCoastMetres; + moving.Advance(.1f, 0, 0); + if (!CheckSmoke(moving.SpeedKnots > 2.85f, "Stop does not erase existing momentum")) + yield break; + + var resting = new DockManeuver(hull, true); + resting.Advance(2, 0, -1); + if (!CheckSmoke(resting.HasBowThruster + ? resting.BowThruster < 0 && resting.LateralSpeedKnots < 0 && resting.TurnRate < 0 + : resting.BowThruster == 0 && resting.LateralSpeedKnots == 0, + "Only fitted bow thrusters can produce movement at a standstill")) + yield break; + } Vector3 calm = PeakSeaResponseSmoke(Market.Coastal, 0); Vector3 storm = PeakSeaResponseSmoke(Market.Coastal, 1); Vector3 river = PeakSeaResponseSmoke(Market.River, 1); @@ -972,8 +993,29 @@ namespace BigShipTycoon && underway.Plan.Order == PassageOrder.Economy && underway.DepartureFuelBurn <= underway.FuelBurn, "Cast off on a short river trip with the planned economy order")) yield break; - holdCinematicClock = true; - yield return CapturePortAndSkipSmoke(directory, "03-river-departure", 1.3f); + if (!CheckSmoke(!harbor.PortCinematicActive && ActiveDockManeuver is { Arriving: false, BowLine: true, SternLine: true } + && harbor.DockManeuverVisible && harbor.DockLinesVisible == (true, true) + && root.Q