diff --git a/data/commander/js/input/wiring.js b/data/commander/js/input/wiring.js index e14d1542..33447425 100644 --- a/data/commander/js/input/wiring.js +++ b/data/commander/js/input/wiring.js @@ -759,6 +759,8 @@ export function init() { const geometry = roleMapGeometry(gesture.role), state = roleMapViews[gesture.role]; if (geometry) plotClick(gesture.role, state.x + (x - rect.width / 2) / geometry.scale, state.y + (y - rect.height / 2) / geometry.scale); + } else if (contact && contact.ref.startsWith("blip-")) { + sendStationAction("opz_mark_blip", {ref: contact.ref}); } else if (contact) { selectTrack(contact.ref); } else if (!hits.length && gesture.role === "helicopter" && stationActionAvailable() && diff --git a/data/commander/js/state/schema.js b/data/commander/js/state/schema.js index ac95d664..7e294018 100644 --- a/data/commander/js/state/schema.js +++ b/data/commander/js/state/schema.js @@ -113,7 +113,7 @@ export function validateV2State(state) { bridge: ["navigation", "orders", "threat", "systems", "tactical_summary", "sightings"], sonar: ["observations", "settings", "visualization"], weapons: ["inventory", "readiness", "designated_target", "navigation", "tactical", "target_choices", "depth_m", "tubes", "own_weapons", "active_assets"], damage: ["compartments", "teams", "total", "sunk"], - opz: ["observations", "fusions", "radar", "defense", "asm_observations", "source_classifications", "designated_target_ref", "own_assets"], + opz: ["observations", "fusions", "radar", "defense", "asm_observations", "source_classifications", "radar_blips", "designated_target_ref", "own_assets"], radio: ["observations", "logged_fixes", "logged_bearings", "messages", "station_down", "navigation", "tactical"], engine: ["propulsion", "machinery", "controls", "environment_effects"], helicopter: ["asset", "waypoint", "buoys", "buoy_observations", "acoustic", "navigation", "tactical", "target_choices", "readiness", "dip_observations", "dip_environment"], eloka: ["intercepts", "station_down", "status", "hardware"], @@ -258,7 +258,9 @@ export function validateV2State(state) { !pictureRefs.has(row.ref) || typeof row.source !== "string" || typeof row.classification !== "string" || !row.classification || row.classification.length > 128) || new Set(payload.source_classifications.map((row) => row.ref)).size !== payload.source_classifications.length || - !exactKeys(payload.defense, ["vls", "ciws", "aa", "chaff_ready", "ciws_ready", "aa_ready", "ciws_released"]) || typeof payload.defense.ciws_released !== "boolean") throw new Error("protocol"); + !exactKeys(payload.defense, ["vls", "ciws", "aa", "chaff_ready", "ciws_ready", "aa_ready", "ciws_released"]) || typeof payload.defense.ciws_released !== "boolean" || + !boundedArray(payload.radar_blips, 16) || payload.radar_blips.some((row) => !exactKeys(row, ["ref", "x", "y", "age_s"]) || + typeof row.ref !== "string" || !/^blip-[0-9]{1,18}$/.test(row.ref) || [row.x, row.y, row.age_s].some((value) => !finite(value)))) throw new Error("protocol"); tacticalRows(payload.asm_observations, 128); if (payload.designated_target_ref !== null && (typeof payload.designated_target_ref !== "string" || !pictureRefs.has(payload.designated_target_ref))) throw new Error("protocol"); if (!exactKeys(payload.own_assets, ["ship", "helicopter", "weapons"]) || diff --git a/data/commander/js/views/role-map.js b/data/commander/js/views/role-map.js index 4d7e9589..235ba847 100644 --- a/data/commander/js/views/role-map.js +++ b/data/commander/js/views/role-map.js @@ -375,6 +375,17 @@ export function drawRoleMap(role) { plot.context.strokeRect(x - 4, y - 4, 8, 8); plot.context.fillStyle = plot.context.strokeStyle; plot.context.fillText(item.waypoint ? t("station_waypoint") : item.display || item.ref || t("helicopter"), x + 6, y + 12); } + if (role === "opz") { + // Bare mast/snorkel echoes: an afterglow dot, no symbol; a click marks it. + for (const blip of payload.radar_blips) { + const [x, y] = point(blip.x, blip.y); + addRoleMapHit(blip.ref, x, y); + plot.context.globalAlpha = Math.max(.25, 1 - blip.age_s / 6); + plot.context.fillStyle = palette().accent; + plot.context.beginPath(); plot.context.arc(x, y, 3, 0, Math.PI * 2); plot.context.fill(); + plot.context.globalAlpha = 1; + } + } if (role === "opz" && hasPosition(data.own)) { if (payload.radar.live && (payload.radar.surface || payload.radar.air)) { for (const range of [payload.radar.surface_effective_range_nm, payload.radar.air_effective_range_nm]) if (finite(range)) { plot.context.strokeStyle = "#365d69"; plot.context.beginPath(); plot.context.arc(ox, oy, range * scale, 0, Math.PI * 2); plot.context.stroke(); } diff --git a/data/i18n/de.json b/data/i18n/de.json index 0e3ee541..41c69ea8 100644 --- a/data/i18n/de.json +++ b/data/i18n/de.json @@ -2012,6 +2012,9 @@ "help.control.tma_range": "TMA-Seite: Hypothesenentfernung -/+ 1 sm (Strg 0,2 sm)", "help.control.tma_accept": "TMA-Seite: Hypothese als Fix \u00fcbernehmen / Umschalt: Solver-Vorschlag kopieren (Training)", "help.control.opz_clear_marks": "Alle markierten Meldungen abwählen", + "runtime.opz.blip_marked": "OPZ: Radarecho als Track {track} markiert.", + "runtime.opz.no_blip": "OPZ: kein frisches Radarecho zum Markieren.", + "help.control.opz_blip": "Neuestes bloßes Radarecho als Track markieren (oder das Echo anklicken)", "help.global.nations": "Nationen & Einheiten; im Sonar: Notchfilter", "help.global.map_zoom": "Kartenzoom nur auf Brücke, Waffen und Helikopter", "help.global.map_pan": "Karte verschieben (Brücke, Waffen und Helikopter)", @@ -2143,7 +2146,7 @@ "help.note.fire": "Feuer w\u00e4chst mit der Brandlast, greift \u00fcber hei\u00dfe Schotten \u00fcber und erstickt bei Flutung; Trupps l\u00f6schen erst nach ihrer Ankunft.", "help.note.assignment": "Zuweisung nur zu reparierbaren Schäden; belegte Kompartimente verdrängen kein anderes Team.", "help.note.damage_tactic": "Priorit\u00e4t: Maschinerie & Sonarzentrale, dann Rumpf. Feuer sofort besetzen.", - "help.note.radar": "Radar sieht Oberflächenfahrzeuge, Luftfahrzeuge und ASMs; getauchte U-Boote bleiben unsichtbar.", + "help.note.radar": "Radar sieht Oberflächenfahrzeuge, Luftfahrzeuge und ASMs; getauchte U-Boote bleiben unsichtbar, ein ausgefahrener Mast oder Schnorchel nur als bloßer Punkt (B oder Klick markiert ihn).", "help.note.ais_esm": "AIS liefert zivile Tracks; passive ESM-Auswertung ist bei ELOKA verfügbar.", "help.note.nato": "NATO-Rahmen: Freund blau, Neutral grün, Feind rot, Unbekannt gelb.", "help.note.ciws": "CIWS: automatisch abfangend < 1.5 NM (begrenzt).", diff --git a/data/i18n/en.json b/data/i18n/en.json index b033134b..8732169d 100644 --- a/data/i18n/en.json +++ b/data/i18n/en.json @@ -2012,6 +2012,9 @@ "help.control.tma_range": "TMA page: hypothesis range -/+ 1 NM (Ctrl 0.2 NM)", "help.control.tma_accept": "TMA page: accept hypothesis as fix / Shift: copy solver proposal (training)", "help.control.opz_clear_marks": "Clear all marked reports", + "runtime.opz.blip_marked": "OPZ: radar blip marked as track {track}.", + "runtime.opz.no_blip": "OPZ: no fresh radar blip to mark.", + "help.control.opz_blip": "Mark the newest bare radar blip as a track (or click the blip)", "help.global.nations": "Nations & units; in sonar: notch filter", "help.global.map_zoom": "Chart zoom only on bridge, weapons, and helicopter", "help.global.map_pan": "Pan chart (bridge, weapons, and helicopter)", @@ -2143,7 +2146,7 @@ "help.note.fire": "Fire grows with fuel load, spreads through hot bulkheads and is smothered by flooding; teams fight it once they arrive.", "help.note.assignment": "Teams can be assigned only to repairable damage; an occupied compartment does not displace another team.", "help.note.damage_tactic": "Prioritize machinery and sonar, then the hull. Assign a team to fire immediately.", - "help.note.radar": "Radar sees surface vessels, aircraft, and ASMs; submerged submarines remain invisible.", + "help.note.radar": "Radar sees surface vessels, aircraft, and ASMs; submerged submarines remain invisible, a raised mast or snorkel only as a bare blip (B or click marks it).", "help.note.ais_esm": "AIS supplies civilian tracks; passive ESM analysis is available at Electronic Warfare.", "help.note.nato": "NATO frames: friendly blue, neutral green, hostile red, unknown yellow.", "help.note.ciws": "CIWS intercepts automatically inside 1.5 NM (limited ammunition).", diff --git a/data/manual/05-opz.de.md b/data/manual/05-opz.de.md index 6c1eb9ed..2761e06e 100644 --- a/data/manual/05-opz.de.md +++ b/data/manual/05-opz.de.md @@ -17,6 +17,7 @@ Seite 1 ist eine freie Karte über die volle Höhe mit allen veröffentlichten T ``` - **Überwasserradar:** 30 sm, begrenzt durch Radarhorizont (20-m-Mast) und Zielhöhe; getauchte U-Boote sind unsichtbar. +- **Mast- und Schnorchelechos:** ein U-Boot auf Sehrohrtiefe mit ausgefahrenem Mast oder Schnorchelkopf (Mast einer Crew, ein schnorchelndes Boot oder eines auf Funktiefe) gibt ein winziges Echo: bei ruhiger See findet es etwa jeder zweite Umlauf auf 7 sm, bei Seegang 3 auf etwa 2,5 sm, bei Seegang 5 unter 1 sm. Es erscheint nur als bloßer Punkt, der etwa 6 s nachleuchtet, ohne Symbol, Beschriftung und Track. Den Punkt im PPI anklicken oder `B` drücken (neuester Punkt) markiert ihn: aus dieser Messung beginnt ein Radartrack `R-…`, und weitere Echos desselben Masts führen ihn fort; ohne neue Echos verblasst er nach 30 s. Echos und Markierung werden nicht gespeichert. - **Luftradar:** 100 sm für Flugzeuge und Seezielflugkörper (ASM). - Die Antenne dreht sich alle 4 s einmal: ein Kontakt wird nur aktualisiert, wenn der Strahl über ihn streicht, und jeder Umlauf erfasst ihn mit einer Wahrscheinlichkeit, die mit der Entfernung sinkt (50 % bei Nennreichweite für ein Schiff in Breitseite; Ziele mit spitzem Aspekt werden später gesehen, schwankende Echos können einen Umlauf verfehlen). Seegangsclutter wächst mit dem Seegang (etwa -5 % bei Seegang 4, -25 % bei 6), Regen dämpft das Echo (-10 % Überwasser, -20 % Luft); ab Seegang 5 nehmen Messfehler zu. Innerhalb 3 sm hält das Such-/Folgeradar des CIWS einen anfliegenden Flugkörper ununterbrochen, solange das CIWS freigegeben ist. - **AIS:** zivile Schiffe senden Kurs und Fahrt alle 2-10 s (vor Anker alle 3 min) und ihren Namen etwa alle 6 min. Der UKW-Empfänger hört sie nur in Sichtlinie (etwa 20 NM). Ein Radartrack eines Zivilschiffs zeigt Name und Kurs erst, wenn die passende AIS-Meldung empfangen wurde; Radar allein liefert nur die Position. Optionaler Live-AIS/ADS-B-Verkehr ist von simuliertem Verkehr nicht unterscheidbar. diff --git a/data/manual/05-opz.en.md b/data/manual/05-opz.en.md index 576965c9..2c04859e 100644 --- a/data/manual/05-opz.en.md +++ b/data/manual/05-opz.en.md @@ -17,6 +17,7 @@ Page 1 is a full-height free chart with all published tracks; page 2 is the targ ``` - **Surface radar:** 30 NM, limited by the radar horizon (20 m mast) and target height; submerged submarines are invisible. +- **Mast and snorkel echoes:** a submarine at periscope depth with a raised mast or snorkel head (a crew's mast, a snorkelling boat or one at radio depth) returns a tiny echo: in calm sea about half the sweeps find it at 7 NM, at sea state 3 at about 2.5 NM, at sea state 5 under 1 NM. It shows only as a bare dot that glows for about 6 s, with no symbol, no label and no track. Click the dot on the PPI or press `B` (newest dot) to mark it: a radar track `R-…` starts from that measurement and further echoes of the same mast update it; without new echoes it fades after 30 s. Blips and the mark are not saved. - **Air radar:** 100 NM for aircraft and anti-ship missiles (ASM). - The antenna turns once every 4 s: a contact is updated only when the beam sweeps past it, and each sweep detects it with a probability that falls with range (50 % at the nominal range for a broadside ship; bow-on targets are seen later, fluctuating echoes can miss a sweep). Sea clutter grows with sea state (about -5 % at sea state 4, -25 % at 6) and rain attenuates the echo (-10 % surface, -20 % air); from sea state 5 measurement errors increase. Inside 3 NM the CIWS search/track radar holds an inbound missile continuously while CIWS is released. - **AIS:** civilian ships broadcast course and speed every 2-10 s (3 min at anchor) and their name about every 6 min. The VHF receiver hears them only within line of sight (about 20 NM). A radar track of a civilian shows name and course only after the matching AIS report has been received; radar alone gives position only. Optional live AIS/ADS-B traffic is indistinguishable from simulated traffic. diff --git a/data/manual/10-reference.de.md b/data/manual/10-reference.de.md index e1ddd59a..642694f4 100644 --- a/data/manual/10-reference.de.md +++ b/data/manual/10-reference.de.md @@ -125,7 +125,7 @@ Die obere Leiste zeigt die sechs Stationen des Boots als Reiter: `1` Führung, ` - Der Crew-Zustand (Betriebsarten, Mast, Drähte, Plot, Alarmpeilungen) wird nicht gespeichert: nach dem Laden führt die KI das Boot, und jeder Crew-Torpedo hat seinen Draht verloren. - Das besetzte Boot funkt nicht und empfängt nichts; es gibt keine Kontaktmeldung von der Führung an Land. - Keine Leckwehr- oder Schadensteams an Bord; Schäden summieren sich nur. -- Ein ausgefahrener Mast wird vom Fregattenradar nicht erfasst (das Fregattenradar erfasst keine U-Boote), und Schnorcheln erzeugt kein Dieselgeräusch: es beendet nur die Schleichfahrt. +- Schnorcheln erzeugt kein Dieselgeräusch: es beendet nur die Schleichfahrt. Ein ausgefahrener Mast oder Schnorchelkopf erscheint auf dem Fregattenradar nur als bloßer Punkt (siehe Kapitel OPZ). - Kein Sehrohrbild und keine Sichtmeldungen vom Boot aus. ## Mission und Wertung {#ref-mission} diff --git a/data/manual/10-reference.en.md b/data/manual/10-reference.en.md index 6e7025b1..1efbca39 100644 --- a/data/manual/10-reference.en.md +++ b/data/manual/10-reference.en.md @@ -125,7 +125,7 @@ The top bar shows the boat's six stations as tabs: `1` Command, `2` Sonar, `3` W - Crew state (modes, mast, wires, plot, alarm bearings) is not saved: after a load the AI commands the boat and every crew torpedo has lost its wire. - The crewed boat sends no radio traffic and receives none; there is no contact report from home. - No damage-control teams aboard the boat; damage only accumulates. -- A raised mast is not detected by the frigate's radar (the frigate radar does not detect submarines), and snorkelling adds no diesel noise: it only ends silent running. +- Snorkelling adds no diesel noise: it only ends silent running. A raised mast or snorkel head is seen by the frigate's radar only as a bare blip (see the OPZ chapter). - No periscope view and no visual sightings from the boat. ## Mission and scoring {#ref-mission} diff --git a/docs/manual/manual.de.md b/docs/manual/manual.de.md index f5fdef47..a921fed9 100644 --- a/docs/manual/manual.de.md +++ b/docs/manual/manual.de.md @@ -574,6 +574,7 @@ Seite 1 ist eine freie Karte über die volle Höhe mit allen veröffentlichten T ``` - **Überwasserradar:** 30 sm, begrenzt durch Radarhorizont (20-m-Mast) und Zielhöhe; getauchte U-Boote sind unsichtbar. +- **Mast- und Schnorchelechos:** ein U-Boot auf Sehrohrtiefe mit ausgefahrenem Mast oder Schnorchelkopf (Mast einer Crew, ein schnorchelndes Boot oder eines auf Funktiefe) gibt ein winziges Echo: bei ruhiger See findet es etwa jeder zweite Umlauf auf 7 sm, bei Seegang 3 auf etwa 2,5 sm, bei Seegang 5 unter 1 sm. Es erscheint nur als bloßer Punkt, der etwa 6 s nachleuchtet, ohne Symbol, Beschriftung und Track. Den Punkt im PPI anklicken oder `B` drücken (neuester Punkt) markiert ihn: aus dieser Messung beginnt ein Radartrack `R-…`, und weitere Echos desselben Masts führen ihn fort; ohne neue Echos verblasst er nach 30 s. Echos und Markierung werden nicht gespeichert. - **Luftradar:** 100 sm für Flugzeuge und Seezielflugkörper (ASM). - Die Antenne dreht sich alle 4 s einmal: ein Kontakt wird nur aktualisiert, wenn der Strahl über ihn streicht, und jeder Umlauf erfasst ihn mit einer Wahrscheinlichkeit, die mit der Entfernung sinkt (50 % bei Nennreichweite für ein Schiff in Breitseite; Ziele mit spitzem Aspekt werden später gesehen, schwankende Echos können einen Umlauf verfehlen). Seegangsclutter wächst mit dem Seegang (etwa -5 % bei Seegang 4, -25 % bei 6), Regen dämpft das Echo (-10 % Überwasser, -20 % Luft); ab Seegang 5 nehmen Messfehler zu. Innerhalb 3 sm hält das Such-/Folgeradar des CIWS einen anfliegenden Flugkörper ununterbrochen, solange das CIWS freigegeben ist. - **AIS:** zivile Schiffe senden Kurs und Fahrt alle 2-10 s (vor Anker alle 3 min) und ihren Namen etwa alle 6 min. Der UKW-Empfänger hört sie nur in Sichtlinie (etwa 20 NM). Ein Radartrack eines Zivilschiffs zeigt Name und Kurs erst, wenn die passende AIS-Meldung empfangen wurde; Radar allein liefert nur die Position. Optionaler Live-AIS/ADS-B-Verkehr ist von simuliertem Verkehr nicht unterscheidbar. @@ -600,6 +601,7 @@ Seite 1 ist eine freie Karte über die volle Höhe mit allen veröffentlichten T | `Shift+R` | Luftraumradar an/aus (EMCON) | | `I` | CIWS-Feuerfreigabe umschalten (gesperrt = feuert nie auf anfliegende ASM) | | `Backspace` | Alle markierten Meldungen abwählen | +| `B` | Neuestes bloßes Radarecho als Track markieren (oder das Echo anklicken) | | `Enter` | Angriff nach Feind-Einstufung eines realen Kontakts bestätigen | | `K` | Kamera-Follow an/aus | @@ -1073,7 +1075,7 @@ Die obere Leiste zeigt die sechs Stationen des Boots als Reiter: `1` Führung, ` - Der Crew-Zustand (Betriebsarten, Mast, Drähte, Plot, Alarmpeilungen) wird nicht gespeichert: nach dem Laden führt die KI das Boot, und jeder Crew-Torpedo hat seinen Draht verloren. - Das besetzte Boot funkt nicht und empfängt nichts; es gibt keine Kontaktmeldung von der Führung an Land. - Keine Leckwehr- oder Schadensteams an Bord; Schäden summieren sich nur. -- Ein ausgefahrener Mast wird vom Fregattenradar nicht erfasst (das Fregattenradar erfasst keine U-Boote), und Schnorcheln erzeugt kein Dieselgeräusch: es beendet nur die Schleichfahrt. +- Schnorcheln erzeugt kein Dieselgeräusch: es beendet nur die Schleichfahrt. Ein ausgefahrener Mast oder Schnorchelkopf erscheint auf dem Fregattenradar nur als bloßer Punkt (siehe Kapitel OPZ). - Kein Sehrohrbild und keine Sichtmeldungen vom Boot aus. ### Mission und Wertung diff --git a/docs/manual/manual.en.md b/docs/manual/manual.en.md index fd50cb9f..e027535b 100644 --- a/docs/manual/manual.en.md +++ b/docs/manual/manual.en.md @@ -573,6 +573,7 @@ Page 1 is a full-height free chart with all published tracks; page 2 is the targ ``` - **Surface radar:** 30 NM, limited by the radar horizon (20 m mast) and target height; submerged submarines are invisible. +- **Mast and snorkel echoes:** a submarine at periscope depth with a raised mast or snorkel head (a crew's mast, a snorkelling boat or one at radio depth) returns a tiny echo: in calm sea about half the sweeps find it at 7 NM, at sea state 3 at about 2.5 NM, at sea state 5 under 1 NM. It shows only as a bare dot that glows for about 6 s, with no symbol, no label and no track. Click the dot on the PPI or press `B` (newest dot) to mark it: a radar track `R-…` starts from that measurement and further echoes of the same mast update it; without new echoes it fades after 30 s. Blips and the mark are not saved. - **Air radar:** 100 NM for aircraft and anti-ship missiles (ASM). - The antenna turns once every 4 s: a contact is updated only when the beam sweeps past it, and each sweep detects it with a probability that falls with range (50 % at the nominal range for a broadside ship; bow-on targets are seen later, fluctuating echoes can miss a sweep). Sea clutter grows with sea state (about -5 % at sea state 4, -25 % at 6) and rain attenuates the echo (-10 % surface, -20 % air); from sea state 5 measurement errors increase. Inside 3 NM the CIWS search/track radar holds an inbound missile continuously while CIWS is released. - **AIS:** civilian ships broadcast course and speed every 2-10 s (3 min at anchor) and their name about every 6 min. The VHF receiver hears them only within line of sight (about 20 NM). A radar track of a civilian shows name and course only after the matching AIS report has been received; radar alone gives position only. Optional live AIS/ADS-B traffic is indistinguishable from simulated traffic. @@ -599,6 +600,7 @@ Page 1 is a full-height free chart with all published tracks; page 2 is the targ | `Shift+R` | Air-search radar on/off (EMCON) | | `I` | Toggle CIWS fire release (withheld = never fires on inbound ASMs) | | `Backspace` | Clear all marked reports | +| `B` | Mark the newest bare radar blip as a track (or click the blip) | | `Enter` | Confirm attack after classifying a real contact hostile | | `K` | Camera follow on/off | @@ -1072,7 +1074,7 @@ The top bar shows the boat's six stations as tabs: `1` Command, `2` Sonar, `3` W - Crew state (modes, mast, wires, plot, alarm bearings) is not saved: after a load the AI commands the boat and every crew torpedo has lost its wire. - The crewed boat sends no radio traffic and receives none; there is no contact report from home. - No damage-control teams aboard the boat; damage only accumulates. -- A raised mast is not detected by the frigate's radar (the frigate radar does not detect submarines), and snorkelling adds no diesel noise: it only ends silent running. +- Snorkelling adds no diesel noise: it only ends silent running. A raised mast or snorkel head is seen by the frigate's radar only as a bare blip (see the OPZ chapter). - No periscope view and no visual sightings from the boat. ### Mission and scoring diff --git a/src/commander/bridge.py b/src/commander/bridge.py index f83d7961..d3729cea 100644 --- a/src/commander/bridge.py +++ b/src/commander/bridge.py @@ -283,6 +283,14 @@ def _sonar_set_tow_depth(game, params, _bindings): return game.set_sonar_tow_depth(params["depth_m"]) +def _opz_mark_blip(game, params, _bindings): + # Blip refs are "blip-": a display counter, never a target identity. + ref = params["ref"] + if not ref.startswith("blip-") or not ref[5:].isdigit() or len(ref) > 24: + return "unknown_ref" + return game.mark_radar_blip(int(ref[5:])) + + def _sonar_measure_bt(game, params, _bindings): return game.measure_sonar_bt() @@ -622,6 +630,7 @@ _V2_ACTION_HANDLERS = { "opz_set_track_id": _opz_set_track_id, "opz_create_fusion": _opz_create_fusion, "opz_dissolve_fusion": _opz_dissolve_fusion, + "opz_mark_blip": _opz_mark_blip, "opz_set_radar": _opz_set_radar, "opz_set_ciws": _opz_set_ciws, "opz_set_range": _opz_set_range, diff --git a/src/commander/projections.py b/src/commander/projections.py index 505e77ad..5d97cfd0 100644 --- a/src/commander/projections.py +++ b/src/commander/projections.py @@ -1003,6 +1003,11 @@ def build_role_states(game, status, rows, target_ref, focus_ref, ref_by_track, for row in rows if row.get("_opz") and row["ref"] in direct_fire_refs["opz"]], source_classifications=source_classifications, + # Bare mast/snorkel echoes: measured position and age only. + radar_blips=[dict(ref=f"blip-{blip['seq']}", x=_number(blip["x"]), + y=_number(blip["y"]), + age_s=_age(game.sim_t, blip["t"])) + for blip in game.radar_blip_view()][-16:], designated_target_ref=(target_ref if any( row.get("_opz") and row["ref"] == target_ref for row in rows) else None), diff --git a/src/commander/server.py b/src/commander/server.py index 943e28f6..60014351 100644 --- a/src/commander/server.py +++ b/src/commander/server.py @@ -569,6 +569,7 @@ V2_ACTION_REGISTRY = { "opz_dissolve_fusion": V2Action(frozenset({"opz"}), _single_ref_params, revision_bound=True), "opz_set_radar": V2Action(frozenset({"opz"}), _radar_params), + "opz_mark_blip": V2Action(frozenset({"opz"}), _single_ref_params), "opz_set_ciws": V2Action(frozenset({"opz"}), _bool_params("enabled")), "opz_set_range": V2Action(frozenset({"opz"}), _range_params), "opz_designate_target": V2Action(frozenset({"opz"}), _single_ref_params), diff --git a/src/core/config.py b/src/core/config.py index 34f03410..c27348b4 100644 --- a/src/core/config.py +++ b/src/core/config.py @@ -350,6 +350,14 @@ RADAR_SURFACE_WEATHER_LOSS = 0.25 RADAR_AIR_WEATHER_LOSS = 0.10 RADAR_WEATHER_ERROR_GAIN = 1.5 RADAR_TRACK_STALE_S = 30.0 +# A raised submarine mast or snorkel head: a tiny, low echo (relative to the +# broadside reference ship) that sea clutter soon hides. It shows as a bare +# blip on the PPI only; the OPZ must mark it to start a radar track. +SUB_MAST_HEIGHT_M = 1.5 +SUB_MAST_RCS_FACTOR = 0.01 +RADAR_BLIP_LIFE_S = 6.0 +RADAR_BLIP_MAX = 24 +RADAR_BLIP_GATE_NM = 1.0 RADAR_BEARING_ERR_DEG = 0.8 RADAR_RANGE_ERR_FRAC = 0.015 # Air-search radar height estimate: a game model of a 3D radar's altitude diff --git a/src/core/game.py b/src/core/game.py index c959af5b..ee4445a4 100644 --- a/src/core/game.py +++ b/src/core/game.py @@ -797,6 +797,11 @@ class Game: self.asm_sel = 0 self.air_picture = TrackPicture( config.RADAR_TRACK_STALE_S, maximum=MAX_AIR_PICTURE_TRACKS) + # Unmarked mast/snorkel echoes (transient display, never saved) and the + # boats whose echoes the OPZ marked into a track: sub id -> track id. + self.radar_blips = deque(maxlen=config.RADAR_BLIP_MAX) + self.radar_blip_seq = 0 + self._radar_marked = {} self.ais = AISReceiver(seed) self.opz_selected_track_id = None self.opz_contact_filter = "ALL" @@ -3020,6 +3025,8 @@ class Game: self.deploy_buoys() elif self.station is Station.ELOKA: self._cycle_eloka_filter("band") + elif self.station is Station.OPZ: + self._mark_newest_blip() elif e.key == pygame.K_y: if self.station is Station.SONAR: if self.damage.station_down("sonar"): @@ -3302,6 +3309,8 @@ class Game: action = opz_action_at(self, canvas, config.OPZ_STATION_RECT) if isinstance(action, tuple) and action[0] == "select": self.opz_selected_track_id = action[1] + elif isinstance(action, tuple) and action[0] == "blip": + self.mark_radar_blip(action[1]) elif action == "classify": self._cycle_opz_classification() elif action == "affiliate": @@ -3900,6 +3909,98 @@ class Game: return (detrand.u01(self.seed, "radar-look-" + domain, key, tick) < radar_physics.pd_from_sinr(sinr)) + @staticmethod + def _mast_up(sub) -> bool: + """A mast or snorkel head above the water: the crew's raised mast or + snorkel, or an AI boat snorkelling or at radio depth.""" + from src.sensors.platform import MAST_DEPTH_M + if sub.sunk or sub.depth > MAST_DEPTH_M: + return False + crew = getattr(sub, "crew", None) + if sub.manual and crew is not None and crew.mast: + return True + endurance = sub.endurance + return endurance is not None and endurance.phase in ("SNORKEL", "RADIO") + + def _update_mast_echoes(self, surface_live, swept_deg, error_scale) -> None: + """Surface-radar looks at raised masts: a bare blip, or an update of + the track the OPZ marked for that boat.""" + for sub_id, (_track_id, last) in tuple(self._radar_marked.items()): + if self.sim_t - last > config.RADAR_TRACK_STALE_S: + del self._radar_marked[sub_id] + if not surface_live: + return + horizon = config.radar_horizon_nm(config.RADAR_ANTENNA_HEIGHT_M, + config.SUB_MAST_HEIGHT_M) + tick = math.floor(self.sim_t * 4.0 + 1e-6) + for sub in self.subs: + if not self._mast_up(sub): + continue + dist = math.hypot(sub.x - self.ship.x, sub.y - self.ship.y) + bearing = math.degrees(math.atan2(sub.x - self.ship.x, + -(sub.y - self.ship.y))) % 360.0 + if (dist > horizon or not self._radar_look( + "surface", sub.sensor_seed, dist, bearing, swept_deg=swept_deg, + rcs_factor=config.SUB_MAST_RCS_FACTOR) + or self.world.land_blocks_line(self.ship.x, self.ship.y, sub.x, sub.y)): + continue + bearing_error = config.RADAR_BEARING_ERR_DEG * error_scale + range_error = config.RADAR_RANGE_ERR_FRAC * error_scale + brg = (bearing + detrand.uniform(-bearing_error, bearing_error, self.seed, + "radar-mast-brg", sub.sensor_seed, tick)) % 360.0 + measured = max(0.0, dist * (1.0 + detrand.uniform( + -range_error, range_error, self.seed, "radar-mast-rng", sub.sensor_seed, tick))) + marked = self._radar_marked.get(sub.id) + if marked is not None: + self._observe_mast(marked[0], sub.id, brg, measured, + self.ship.x, self.ship.y, bearing_error) + continue + self.radar_blip_seq += 1 + rad = math.radians(brg) + self.radar_blips.append(dict( + seq=self.radar_blip_seq, t=float(self.sim_t), target=sub.id, + bearing=brg, range_nm=measured, error=bearing_error, + observer_x=self.ship.x, observer_y=self.ship.y, + x=self.ship.x + measured * math.sin(rad), + y=self.ship.y - measured * math.cos(rad))) + + def _observe_mast(self, track_id, sub_id, bearing, range_nm, observer_x, observer_y, + bearing_error) -> None: + self._radar_marked[sub_id] = (track_id, float(self.sim_t)) + self.air_picture.observe(track_id=track_id, kind="SURFACE", target_id=sub_id, + source="RADAR-S", bearing=bearing, range_nm=range_nm, + observer_x=observer_x, observer_y=observer_y, course=None, quality=.5, + now=self.sim_t, label=track_id, + bearing_uncertainty_deg=bearing_error / math.sqrt(3.0)) + + def radar_blip_view(self) -> list: + """Unmarked radar blips still glowing (measured positions only).""" + if not (self.surface_radar_on and not self.damage.station_down("opz")): + return [] + return [blip for blip in self.radar_blips + if 0.0 <= self.sim_t - blip["t"] < config.RADAR_BLIP_LIFE_S + and blip["target"] not in self._radar_marked] + + def mark_radar_blip(self, seq): + """OPZ: start a radar track from a blip (its measurement only).""" + if type(seq) is not int: + return "invalid_value" + blip = next((item for item in self.radar_blip_view() if item["seq"] == seq), None) + if blip is None: + return "stale_ref" + track_id = f"R-{blip['seq']}" + self._observe_mast(track_id, blip["target"], blip["bearing"], blip["range_nm"], + blip["observer_x"], blip["observer_y"], blip["error"]) + self.announce(message("runtime.opz.blip_marked", track=track_id), "opz", 2.0) + return True + + def _mark_newest_blip(self) -> None: + blips = self.radar_blip_view() + if not blips: + self.flash(message("runtime.opz.no_blip"), 1.5) + return + self.mark_radar_blip(blips[-1]["seq"]) + def radar_sweep_bearing(self) -> float: """Nautische Peilung: zunehmende Werte drehen Nord -> Ost rechtsherum.""" return self.radar_scan_phase @@ -4801,6 +4902,7 @@ class Game: course=None, quality=.9, now=self.sim_t, label=f"S-{w.id}", bearing_uncertainty_deg=bearing_error / math.sqrt(3.0)) + self._update_mast_echoes(surface_live, swept_deg, error_scale) for f in self.flights.flights: dist = f.distance_nm(self.ship) bearing = f.bearing_to_frigate(self.ship) diff --git a/src/core/help.py b/src/core/help.py index be8c21cb..d0bb54a4 100644 --- a/src/core/help.py +++ b/src/core/help.py @@ -117,6 +117,7 @@ STATION_HELP = { ("G", "help.control.chaff"), ("R", "help.control.surface_radar"), ("Shift+R", "help.control.air_radar"), ("I", "help.control.ciws_release"), ("Backspace", "help.control.opz_clear_marks"), + ("B", "help.control.opz_blip"), ("Enter", "help.control.confirm_live_engage"), ("K", "help.control.follow")], ["help.note.radar", "help.note.ais_esm", "help.note.nato", "help.note.ciws", diff --git a/src/ui/stations_view.py b/src/ui/stations_view.py index 9a0de43b..acbd4237 100644 --- a/src/ui/stations_view.py +++ b/src/ui/stations_view.py @@ -1333,6 +1333,10 @@ def opz_action_at(game, pos, station_rect=None): point = _opz_track_point(game, track, chart, view) if point is not None and _near_point(pos, point, 15): return ("select", track.observation_id) + # A bare radar blip: clicking it marks it into a track. + for blip in reversed(game.radar_blip_view() if hasattr(game, "radar_blip_view") else []): + if _near_point(pos, view.world_to_screen(blip["x"], blip["y"]), 12): + return ("blip", blip["seq"]) return None @@ -1673,6 +1677,16 @@ def draw_opz_view(game, tr=None) -> None: layout.blit_line(s, track["source"], (int(sx) - 22, int(sy) - 21, 66, 18), col, size=12) + # Unmarked mast/snorkel echoes: a bare afterglow dot, no symbol or label, + # dimming with the time since the sweep painted it. + for blip in (game.radar_blip_view() if hasattr(game, "radar_blip_view") else []): + px, py = view.world_to_screen(blip["x"], blip["y"]) + if not chart.collidepoint(px, py): + continue + fade = 1.0 - (game.sim_t - blip["t"]) / config.RADAR_BLIP_LIFE_S + pygame.draw.circle(s, _scale_color((120, 255, 150), max(.2, fade)), + (int(px), int(py)), 3) + # Gemeinsames Lagebild: Oberflaeche, Luft und Flugkoerper im selben Scope. for track in (t for t in cic_tracks if _observation_position(t)[0] is not None): observed_x, observed_y = _observation_position(track) diff --git a/tests/test_commander_browser_sessions_v2.py b/tests/test_commander_browser_sessions_v2.py index 3cb149af..39f268ad 100644 --- a/tests/test_commander_browser_sessions_v2.py +++ b/tests/test_commander_browser_sessions_v2.py @@ -957,7 +957,7 @@ def _direct_fire_browser_states(): defense=dict(vls=8, ciws=200, aa=40, chaff_ready=True, ciws_ready=True, aa_ready=True, ciws_released=True), asm_observations=[asm_row], - source_classifications=[], designated_target_ref=None, + source_classifications=[], radar_blips=[], designated_target_ref=None, own_assets=dict(ship=navigation, helicopter=helicopter_asset, weapons=[ dict(ref="opaque-torpedo-reference-one", x=251.0, y=249.0, depth_m=60.0, course=90.0, state="RUN")]))) diff --git a/tests/test_commander_projections_v2.py b/tests/test_commander_projections_v2.py index c00b3fff..4ffbef61 100644 --- a/tests/test_commander_projections_v2.py +++ b/tests/test_commander_projections_v2.py @@ -116,7 +116,7 @@ def test_role_allowlists_detachment_bounds_and_no_hidden_identifiers(published): "own_weapons", "active_assets"}, "damage": {"compartments", "teams", "total", "sunk"}, "opz": {"observations", "fusions", "radar", "source_classifications", - "designated_target_ref", "own_assets", "defense", + "radar_blips", "designated_target_ref", "own_assets", "defense", "asm_observations"}, "radio": {"observations", "logged_fixes", "logged_bearings", "messages", "station_down", "navigation", "tactical"}, diff --git a/tests/test_radar_mast_blip.py b/tests/test_radar_mast_blip.py new file mode 100644 index 00000000..468f883b --- /dev/null +++ b/tests/test_radar_mast_blip.py @@ -0,0 +1,135 @@ +"""A raised submarine mast or snorkel is a bare radar blip until the OPZ marks it.""" + +import math + +import pytest + +from src.core import config +from src.core.game import Game +from src.sensors import radar as radar_physics + + +def _game(seed=83): + game = Game(seed=seed, start_menu=False, audio_enabled=False, language="en") + game._radar_conditions = lambda: dict(sea_state=1, rain_intensity=0.0, capability=1.0) + game.world.land_blocks_line = lambda *args: False + game.surface_radar_on = True + return game + + +def _place_sub(game, distance_nm=3.0, mast=True): + sub = game.subs[0] + sub.x, sub.y = game.ship.x + distance_nm, game.ship.y + sub.depth = sub.target_depth = 12.0 + game.claim_opfor_sub() + boat = game.opfor + assert boat is not None and boat.sub is sub + boat.orders.mast = mast + return sub + + +def _sweeps(game, revolutions=6): + for _ in range(revolutions): + game._update_air_picture(full_scan=True) + game.sim_t += 4.0 + + +def test_mast_echo_is_a_blip_without_a_track(): + game = _game() + sub = _place_sub(game) + tracks_before = {track.track_id for track in game.air_picture.tracks(game.sim_t)} + _sweeps(game) + assert any(blip["target"] == sub.id for blip in game.radar_blips) + # No radar track is created from the echo alone. + assert {track.track_id for track in game.air_picture.tracks(game.sim_t)} == tracks_before + game.audio.shutdown() + + +def test_no_blip_with_the_mast_down_or_deep(): + game = _game() + _place_sub(game, mast=False) + _sweeps(game) + assert not game.radar_blips + game.opfor.orders.mast = True + game.opfor.sub.depth = 60.0 + _sweeps(game) + assert not game.radar_blips + game.audio.shutdown() + + +def test_marking_a_blip_starts_a_track_that_later_echoes_update(): + game = _game() + sub = _place_sub(game) + for _ in range(12): + game._update_air_picture(full_scan=True) + game.sim_t += 1.0 + if game.radar_blip_view(): + break + blips = game.radar_blip_view() + assert blips + assert game.mark_radar_blip(blips[-1]["seq"]) is True + track_id = f"R-{blips[-1]['seq']}" + track = next(track for track in game.air_picture.tracks(game.sim_t) + if track.track_id == track_id) + assert track.source == "RADAR-S" and track.kind == "SURFACE" + assert game.radar_blip_view() == [] # The marked boat no longer blips. + first = track.last_seen + _sweeps(game, 8) + updated = next(track for track in game.air_picture.tracks(game.sim_t) + if track.track_id == track_id) + assert updated.last_seen > first + assert game.mark_radar_blip(10**9) == "stale_ref" + assert game.mark_radar_blip("1") == "invalid_value" + assert sub.id in game._radar_marked + game.audio.shutdown() + + +def test_blips_are_deterministic(): + runs = [] + for _ in range(2): + game = _game(seed=91) + _place_sub(game, distance_nm=4.0) + _sweeps(game, 10) + runs.append([(blip["seq"], round(blip["x"], 9), round(blip["y"], 9)) + for blip in game.radar_blips]) + game.audio.shutdown() + assert runs[0] == runs[1] and runs[0] + + +@pytest.mark.parametrize("sea_state,low,high", [(1, 6.0, 8.5), (3, 1.8, 3.5), (5, 0.3, 1.2)]) +def test_mast_echo_range_falls_with_sea_state(sea_state, low, high): + """Documented Pd = 0.5 ranges of the mast echo (manual, OPZ chapter).""" + distance = None + for tenth in range(1, 400): + value = tenth / 10.0 + sinr = radar_physics.sinr(value, config.RADAR_SURFACE_RANGE_NM, + rcs_factor=config.SUB_MAST_RCS_FACTOR, domain="surface", + jnr=0.0, sea_state=sea_state, rain_intensity=0.0, + capability=1.0) + if radar_physics.pd_from_sinr(sinr) < 0.5: + distance = value + break + assert distance is not None and low <= distance <= high + + +def test_web_opz_sees_blips_and_marks_them(): + from src.commander.bridge import CommanderBridge + import sys + from pathlib import Path + sys.path.insert(0, str(Path(__file__).parent)) + from test_commander_bridge import Server + + game = _game() + _place_sub(game) + _sweeps(game) + server, bridge = Server(), CommanderBridge() + bridge.pump(game, server, now=1.0) + blips = server.v2_states["opz"]["opz"]["radar_blips"] + if not blips: + pytest.skip("no fresh blip at publication") + assert set(blips[0]) == {"ref", "x", "y", "age_s"} and blips[0]["ref"].startswith("blip-") + from src.commander.bridge import _opz_mark_blip + assert _opz_mark_blip(game, {"ref": blips[-1]["ref"]}, {}) is True + assert _opz_mark_blip(game, {"ref": "track-1"}, {}) == "unknown_ref" + assert math.isfinite(blips[0]["x"]) + game.audio.shutdown()