feat(cockpit): ride the selected vessel from its bridge

With no aircraft tracked, Cockpit can ride the selected AIS vessel. Entry
needs only Live AIS Vessels and a selected vessel; C, double-click and the
entry buttons (reading BRIDGE with a ship icon) enter it, while voice stays
aircraft-only.

The eye sits on the AIS position at a representative bridge height for the
vessel's type family, looks along true heading and moves along course over
ground. The last fix is dead-reckoned for up to 180 s between the layer's
refreshes, and on rivers and lakes the waterline is read from the rendered
surface around the ship rather than the geoid.

The bridge HUD shows speed and course over ground, a straight heading
tape, window mullions, the AIS destination as a reported voyage and a
heading-up radar of nearby ships (3 to 24 NM). The arrow keys look around,
Home or 0 looks ahead again. The vessel layer hides the ridden ship's
sprite and card, ignores scene clicks while held, and returns the camera
to the vessel's map view on exit.
This commit is contained in:
Denis Groshev committed 2026-11-07 19:52:30 +01:00
1 parent 52187c91d1
commit 72112ecb45
58 files changed
+5313 -137

No files matched your search

+212
View File
@@ -11,6 +11,8 @@ import {
cockpitAltitudeDisplayFt,
cockpitUiUpdateDue,
compassDivisions,
compassMarkerSlot,
scrollingCompassDivisions,
formatAltitudeRulerTick,
formatCompassDivision,
formatCockpitEmergency,
@@ -22,10 +24,23 @@ import {
} from '../cockpitMath.js';
import {
COCKPIT_CONTEXT_UPDATE_MS,
cockpitUnitCase,
compassPointLabel,
formatCockpitCoordinate,
} from './cockpitPresentation.js';
import { createVisionState } from './cockpitInstrumentState.js';
import { unitLabel } from './unitLabels.js';
import {
VESSEL_BRIDGE_PITCH_DEG,
vesselCameraProfile,
} from '../cockpitSubjects.js';
import { lookIsOffset, lookReadoutParts, wrapLookYaw } from '../cockpitLook.js';
import {
RADAR_MAX_CONTACTS,
radarPicture,
radarRangeM,
radarRangeNm,
} from '../cockpitRadar.js';
/** A transponder status name (src/data/aircraftEmergency.js) for the HUD. */
const emergencyLabel = ({ name }) => t(name).toUpperCase();
@@ -68,20 +83,68 @@ export function publishInstrumentsView() {
meta: { ...view.meta },
speed: view.speed && { ...view.speed },
altitude: view.altitude && { ...view.altitude },
course: view.course && { ...view.course },
heading: view.heading && { ...view.heading },
speedRim: rim(view.speedRim),
altitudeRim: rim(view.altitudeRim),
compass: view.compass.map((division) => ({ ...division })),
compassMarkers: { ...view.compassMarkers },
look: { ...view.look },
});
}
/** Word a bridge look's readout parts (see `lookReadoutParts`). */
function wordLook({ side, bearingDeg, elevation, angleDeg }) {
const bearing = formatHeadingReadout(bearingDeg);
const angle = formatNumber(angleDeg);
let direction = '';
if (side === 'starboard') direction = t('LOOK STBD {bearing}°', { bearing });
else if (side === 'port') direction = t('LOOK PORT {bearing}°', { bearing });
else if (side === 'astern') direction = t('LOOK ASTERN');
let tilt = '';
if (elevation === 'up') tilt = t('UP {angle}°', { angle });
else if (elevation === 'down') tilt = t('DOWN {angle}°', { angle });
else if (elevation === 'level') tilt = t('LEVEL');
if (direction && tilt)
return t('{direction} · {elevation}', { direction, elevation: tilt });
if (tilt) return t('LOOK {elevation}', { elevation: tilt });
return direction;
}
/**
* Present the bridge look target: whether the view is turned off the bow,
* its yaw for the radar and its worded readout. Outside a bridge the look
* always rests. The caller publishes.
*/
export function presentLook() {
const target = this.lookTarget;
const offset =
this.active &&
this.subjectKind === 'vessel' &&
lookIsOffset(target, VESSEL_BRIDGE_PITCH_DEG);
this.instruments.look = offset
? {
offset: true,
yawDeg: wrapLookYaw(target.yawDeg),
readout: wordLook(lookReadoutParts(target, VESSEL_BRIDGE_PITCH_DEG)),
}
: { offset: false, yawDeg: 0, readout: '' };
}
export function updateHud(
info,
nowMs = performance.now(),
forceContext = false,
) {
if (info?.kind === 'vessel') {
updateVesselHud.call(this, info, nowMs, forceContext);
return;
}
this.lastAircraftInfo = info;
const view = this.instruments;
view.kind = 'aircraft';
view.trackSource = null;
view.course = null;
const heading = normalizeHeading(this.heading ?? info.track ?? 0);
view.callsign =
info.callsign || info.registration || info.icao24 || t('AIRCRAFT');
@@ -128,6 +191,7 @@ export function updateHud(
slot: index - 3,
label: compassPointLabel(formatCompassDivision(division)),
}));
view.compassMarkers = { prograde: null, retrograde: null };
view.clock = new Date().toISOString().slice(11, 19) + 'Z';
const lat = Number.isFinite(info.latitude)
? formatCockpitCoordinate(info.latitude, 'N', 'S')
@@ -175,6 +239,153 @@ export function updateHud(
}
}
/**
* Present the bridge readouts: speed and course over ground, true heading,
* the vessel type and its assumed eye height. Contact navigation and Live
* Signals stay aircraft-only, so the Contact card is withdrawn.
*/
function updateVesselHud(info, nowMs, forceContext) {
this.lastAircraftInfo = info;
const view = this.instruments;
view.kind = 'vessel';
view.trackSource = info.trackSource ?? null;
// A ship reporting neither heading nor course has no heading to read out
// and no bow to mark; the tape still follows the camera.
const headingKnown = Number.isFinite(info.track);
const cameraHeading = normalizeHeading(this.heading ?? info.track ?? 0);
const heading = headingKnown ? cameraHeading : null;
view.callsign = info.name;
const speedKt = Number.isFinite(info.speedKt)
? Math.max(0, info.speedKt)
: null;
view.speed = {
text: formatSpeedRulerTick(speedKt),
value: speedKt,
immediate: forceContext,
};
view.speedRim.unavailable = speedKt === null;
view.speedRim.value = formatSpeedRulerTick(speedKt);
placeRimTicks(
view.speedRim.ticks,
speedRulerTicks(speedKt, view.speedRim.ticks.length),
(tick) => formatSpeedRulerTick(tick.valueKt),
);
view.altitude = null;
view.altitudeRim.unavailable = true;
const course = Number.isFinite(info.course)
? normalizeHeading(info.course)
: null;
view.course = {
text: formatHeadingReadout(course),
value: course,
immediate: forceContext,
};
view.heading = {
text: formatHeadingReadout(heading),
value: heading,
immediate: forceContext,
};
// Looking around turns the tape with the camera; the readout above it
// keeps the ship's heading, and the bow and stern marks stay on the ship.
const viewHeading = normalizeHeading(
cameraHeading + (this.lookView?.yawDeg ?? 0),
);
// The tape scrolls continuously, so the caret reads the view's exact
// heading and the marks sit at their true bearings from it.
view.compass = scrollingCompassDivisions(viewHeading).map((division) => ({
slot: division.slot,
heading: division.heading,
active: division.nearest,
label: compassPointLabel(formatCompassDivision(division.heading)),
}));
view.compassMarkers = headingKnown
? {
prograde: compassMarkerSlot(heading, viewHeading),
retrograde: compassMarkerSlot(heading + 180, viewHeading),
}
: { prograde: null, retrograde: null };
view.clock = new Date().toISOString().slice(11, 19) + 'Z';
view.position = `${formatCockpitCoordinate(info.latitude, 'N', 'S')} · ${formatCockpitCoordinate(info.longitude, 'E', 'W')}`;
const eyeHeightM = vesselCameraProfile(info).upM;
view.meta.text = t('{vesselType} · {feedState} · EYE {height}', {
vesselType: info.typeLabel || t('VESSEL'),
feedState: info.stale ? t('STALE FEED') : t('LIVE AIS'),
height: `${formatNumber(Math.round(eyeHeightM))} ${cockpitUnitCase(unitLabel('m'))}`,
});
view.meta.emergency = false;
view.layer = info.layerId;
// Reworded here too, so a language switch reaches the look readout.
this.presentLook();
this.publishInstrumentsView();
updateVesselRoute.call(this, info);
if (
forceContext ||
cockpitUiUpdateDue(
nowMs,
this.lastContextUpdateMs,
COCKPIT_CONTEXT_UPDATE_MS,
)
) {
this.lastContextUpdateMs = nowMs;
this.updateLocalPosition(info);
this.maybeRefreshRegionalBrief(info);
this.updateRadar(info);
this.showContextCard(false);
this.pushCockpitSignal(
'context-status',
'info',
t('CONTACT NAVIGATION OFF'),
t('THE BRIDGE STAYS WITH THE SELECTED VESSEL'),
);
}
}
/**
* Publish the bridge radar: nearby AIS vessels drawn heading-up from the
* camera's current heading, within the chosen range.
* @param {object} info The vessel subject (`readVesselInfo`).
*/
export function updateRadar(info) {
const layer = this.services.aisLiveVesselsLayer;
if (!info || typeof layer?.getRadarContacts !== 'function') {
this.publishRadar(null);
return;
}
const rangeNm = radarRangeNm(this.radarRangeNm);
const contacts = layer.getRadarContacts(
info.latitude,
info.longitude,
radarRangeM(rangeNm),
RADAR_MAX_CONTACTS,
);
const picture = radarPicture(
{
latitude: info.latitude,
longitude: info.longitude,
headingDeg: normalizeHeading(this.heading ?? info.track ?? 0),
courseDeg: info.course,
},
contacts,
rangeNm,
);
this.publishRadar({
...picture,
rangeLabel: t('{range} NM', { range: formatNumber(rangeNm) }),
});
}
/** Show the AIS voyage destination; it is crew-entered text, not a place. */
function updateVesselRoute(info) {
const route = this.routeView;
route.kind = 'vessel';
route.from = '';
route.to = info.destination || t('UNKNOWN');
route.status = t('AIS DESTINATION · CREW REPORTED');
route.visible = Boolean(info.destination);
// No coordinates, so no arrow; clearing also publishes the card.
this.clearPredictiveRoute();
}
/** Publish the route card and destination arrow when either changed. */
export function publishRouteView() {
const signature = JSON.stringify(this.routeView);
@@ -188,6 +399,7 @@ export function publishRouteView() {
export function updateRoute(info) {
const route = this.routeView;
route.kind = 'aircraft';
const origin = info?.route?.origin;
const destination = info?.route?.destination;
const validDestination =