mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-05 12:24:25 +01:00
Phase 7: hostile sensing, own TMA, crew reaction, mast-limited ESM/datalink
- Submarines no longer use the legacy snapshot gate: every boat senses through its PlatformSensorSuite. Bearing-only sonar contacts feed an own passive TMA (saved track, 30 s re-solve) and the boat opens TMA legs when range is unobservable; a range comes only from its own solution. - ESM works only with the mast up (<= 18 m); the hostile datalink is exchanged only by boats at mast depth or snorkelling/transmitting. - Torpedo alarms take a per-boat crew recognition time (lognormal 2-15 s, saved countdown) unless the boat is already evading. Manual EN/DE and simulation-gaps updated; tests adjusted to the delayed alarm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8f7970059c
commit
8e6b1d3227
11 files changed
+254
-21
No files matched your search
@@ -50,6 +50,7 @@ Der Automatikmodus (`A`) wählt Ziele und Techniken und koppelt das Stören wäh
|
||||
- Wechselt eine Erfassung bei stehender Peilung von Suche auf einen Puls-Doppler-Sucher mit hoher PRF, steht ein Flugkörperangriff bevor: sofort die OPZ warnen.
|
||||
- Das Zuordnen eines Radartyps (`C`) gibt die Peilung an die OPZ frei; das Löschen der Zuordnung zieht sie zurück.
|
||||
- Stören ist eine Aussendung. Gezielt einsetzen, nicht dauerhaft.
|
||||
- Das eigene Radar wird ebenfalls gehört: ein U-Boot auf Sehrohrtiefe (Mast oben, etwa 18 m) fängt es mit seinem ESM auf und kann die Peilung über seinen Datalink an andere Gegner weitergeben. Tief getauchte Boote hören weder Radar noch empfangen sie den Datalink.
|
||||
|
||||
## Nicht modelliert {#eloka-limits}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ Automatic mode (`A`) picks targets and techniques and couples jamming with soft-
|
||||
- An intercept that changes from search to a high PRF pulse-doppler seeker at a steady bearing is a missile about to attack: warn Operations immediately.
|
||||
- Assigning a radar type (`C`) releases the bearing to CIC; clearing the assignment withdraws it again.
|
||||
- Jamming is a transmission. Use it deliberately, not continuously.
|
||||
- Your own radar is heard too: a submarine at periscope depth (mast up, about 18 m) intercepts it on its ESM and can pass the bearing to other hostile units over its datalink. Deep boats neither hear radar nor receive the datalink.
|
||||
|
||||
## Not modelled {#eloka-limits}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ Alle Werte sind die Standardwerte der aktuellen Spielversion. Eigene Schwierigke
|
||||
|
||||
U-Boote weichen nach einem gehörten Ping oder Torpedo 240 s aus, können einen Täuschkörper ausstoßen, lauern, schnorcheln (durch HFDF und ESM erfassbar) und pingen gelegentlich aus 15 sm oder weniger.
|
||||
|
||||
U-Boot-Physik: der Rumpf beschleunigt auf die befohlene Fahrt (kein Sofortsprint); Tiefenruder brauchen Fahrt (unter etwa 4 kn ändert sich die Tiefe nur langsam); das abgestrahlte Geräusch steigt je Verdopplung der Fahrt um etwa 12 dB und springt, wenn die Schraube kavitiert, wobei die Kavitationsfahrt mit der Tiefe steigt; ein Torpedoausstoß erzeugt 8 s lang ein Transientengeräusch; ein stark geflutetes Boot bläst einmal an und steigt schnell und laut auf; unter der Testtiefe ermüdet der Druckkörper, bei 1,5-facher Testtiefe wird er zerdrückt; ein lauerndes Boot hält seine Position gegen die Strömung. Überwasserschiffe verlieren bei schwerer See Höchstfahrt (kleine Schiffe mehr).
|
||||
U-Boot-Physik: der Rumpf beschleunigt auf die befohlene Fahrt (kein Sofortsprint); Tiefenruder brauchen Fahrt (unter etwa 4 kn ändert sich die Tiefe nur langsam); das abgestrahlte Geräusch steigt je Verdopplung der Fahrt um etwa 12 dB und springt, wenn die Schraube kavitiert, wobei die Kavitationsfahrt mit der Tiefe steigt; ein Torpedoausstoß erzeugt 8 s lang ein Transientengeräusch; ein stark geflutetes Boot bläst einmal an und steigt schnell und laut auf; unter der Testtiefe ermüdet der Druckkörper, bei 1,5-facher Testtiefe wird er zerdrückt; ein lauerndes Boot hält seine Position gegen die Strömung. U-Boote orten wie Sie: passive Peilungen aus dem eigenen Sonar, eine Entfernung erst nach eigenen TMA-Schlägen (einige Minuten), ESM nur mit ausgefahrenem Mast, den Datalink nur auf Masttiefe oder beim Schnorcheln, und ein Torpedoalarm braucht einige Sekunden Reaktionszeit der Besatzung (2-15 s), bevor das Boot ausweicht. Überwasserschiffe verlieren bei schwerer See Höchstfahrt (kleine Schiffe mehr).
|
||||
|
||||
## Mission und Wertung {#ref-mission}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ All values are the defaults of the current game version. Custom difficulty and m
|
||||
|
||||
Submarines evade for 240 s after hearing a ping or a torpedo, may launch a decoy, lie in wait, snorkel (detectable by HFDF and ESM) and sometimes ping from 15 NM or less.
|
||||
|
||||
Submarine physics: the hull accelerates toward an ordered speed (no instant sprints); hydroplanes need speed (below about 4 kn depth changes are slow); radiated noise rises about 12 dB per doubling of speed and jumps when the screw cavitates, and the cavitation speed rises with depth; a torpedo launch makes an 8 s transient; a badly flooded boat blows ballast once and rises fast and loud; operating below test depth fatigues the hull, and 1.5 x test depth crushes it; a lurking boat holds its position against the current. Surface ships lose top speed in heavy seas (small ships more).
|
||||
Submarine physics: the hull accelerates toward an ordered speed (no instant sprints); hydroplanes need speed (below about 4 kn depth changes are slow); radiated noise rises about 12 dB per doubling of speed and jumps when the screw cavitates, and the cavitation speed rises with depth; a torpedo launch makes an 8 s transient; a badly flooded boat blows ballast once and rises fast and loud; operating below test depth fatigues the hull, and 1.5 x test depth crushes it; a lurking boat holds its position against the current. Submarines sense like you do: passive bearings from their own sonar, a range only after their own TMA legs (a few minutes), ESM only with the mast up, the datalink only at mast depth or snorkelling, and a torpedo alarm takes the crew a few seconds (2-15 s) before the boat evades. Surface ships lose top speed in heavy seas (small ships more).
|
||||
|
||||
## Mission and scoring {#ref-mission}
|
||||
|
||||
|
||||
@@ -85,9 +85,9 @@ Scope: Ship dynamics, weapons, enemy AI, air, sonar/sensors, world/environment.
|
||||
| ~~**LAUER is a speed brake, not a tactic**~~ | **Closed (Phase 6).** The lurking boat heads into the current at bare steerage way and holds station. | — |
|
||||
| ~~**No current / drift**~~ | **Fixed (2026-09).** `World.current_vec(x, y)` provides a deterministic current field, already applied to ship/sub/surface ships (`world.py:217-224`), and now also to torpedoes (both classes) and the free-drift enemy decoy. | — |
|
||||
| ~~**Torpedo launch is instantaneous**~~ | **Closed (Phases W2 + 6).** Motor spool-up, launch depth, and a loud 8 s tube-discharge transient on the firing boat. | — |
|
||||
| **No active sonar use by subs** | Subs only use passive detection (or legacy `snapshot_observation`) | Active ping capability with its own trade-offs (reveals position) |
|
||||
| **No ESM/ESB use by subs** | ESM sensor exists in catalog but `legacy_observation_model` short-circuits it for most profiles | Full `PlatformSensorSuite` path for subs when `propulsor_type != "unknown"` |
|
||||
| **No ASW coordination** | Each sub acts independently; no data-link between hostile subs | Friendly datalink (already exists in `PlatformSensorSuite` for "blue" side but not used for hostile subs) |
|
||||
| ~~**No active sonar use by subs**~~ | **Closed.** `Sub._maybe_active_ping` (aggressive boats, fresh contact, cooldown saved since Phase 0); the ping is heard by the frigate. | — |
|
||||
| ~~**No ESM/ESB use by subs**~~ | **Closed (Phase 7).** All submarines use their `PlatformSensorSuite` (legacy snapshot gate removed); ESM works only with the mast up (<= 18 m); range from their own passive TMA with TMA legs (saved track). | — |
|
||||
| ~~**No ASW coordination**~~ | **Closed (Phase 7).** Hostile red-group datalink shares tracks; a submerged boat only exchanges at mast depth or while snorkelling/transmitting, which makes the latency physical. | — |
|
||||
| **Damage model is scalar** | `self.damage: float` 0-100; affects speed (`speed_for_state`), noise, and sinking | Compartment flooding on subs; loss of specific systems; trim change; rudder damage |
|
||||
|
||||
### 2.3 Data structures / interfaces that would be touched
|
||||
@@ -164,7 +164,7 @@ Scope: Ship dynamics, weapons, enemy AI, air, sonar/sensors, world/environment.
|
||||
| **No wire dynamics** | Wire is abstracted as a timer (stale/broken) | Wire payout length limits range; wire drag; wire tension; spool dynamics |
|
||||
| **No propeller noise model** | Static LOFAR lines from catalog | Speed-dependent blade rate; cavitation at high speed; motor harmonics |
|
||||
| **Kill is binary** | Distance + depth threshold → instant hit or miss | Warhead proximity fuze with lethal radius; damage proportional to standoff; no partial hits |
|
||||
| ~~**No target reaction to torpedo**~~ | **Partially fixed (2026-09).** Beyond the existing 35 NM one-time launch-transient alert and the 1.2 NM homing-triggered alert, subs now also get a graduated, noise-scaled notice (`Sub.torpedo_notice_range_nm()`, up to `TORP_RUNNING_NOISE_RANGE_NM`) of a running torpedo's own machinery noise, scaled by the sub's own self-noise. Still open: no explicit reaction-time delay, no dedicated evasive-depth-change behaviour beyond the existing EVADE state. | Reaction-time delay; dedicated evasive depth change |
|
||||
| ~~**No target reaction to torpedo**~~ | **Closed (Phases W2 + 7 + 8).** Launch-transient and homing alerts, crew recognition delay (per-boat lognormal 2-15 s, saved countdown), evasive dive across the layer; Phase 8 makes the running-torpedo notice a sonar-equation detection. | — |
|
||||
| **No self-destruction timing** | SASE at max range or terrain block; no time-based self-destruct | Motor burn time; battery depletion |
|
||||
| **No wake / trail signature** | None | Torpedo wake detectable by passive sonar at close range |
|
||||
| **ASROC payload depth** | Fixed `target_depth_m` from observation (default 60 m) | No depth-keeping logic; no terminal dive |
|
||||
|
||||
+37
-1
@@ -38,6 +38,7 @@ from src.core.version import SAVE_SCHEMA, SAVE_VERSION
|
||||
from src.sensors.ais import AISReceiver
|
||||
from src.sonar import equation as sonar_equation
|
||||
from src.physics import ship_dynamics
|
||||
from src.sensors.platform import MAST_DEPTH_M
|
||||
from src.world.ocean import OceanEnvironment
|
||||
from src.core.save_schema import (
|
||||
COMPARTMENT_FIELDS, COMPARTMENT_STATES, DAMAGE_FIELDS, RNG_STREAMS,
|
||||
@@ -5841,6 +5842,10 @@ class Game:
|
||||
degraded = {"radar", "esm", "sonar", "ais"}
|
||||
candidates = [candidate for candidate in all_candidates
|
||||
if getattr(candidate, "side", None) != actor.side]
|
||||
suite.datalink_reachable = not (
|
||||
isinstance(actor, Sub) and actor.depth > MAST_DEPTH_M
|
||||
and getattr(getattr(actor, "endurance", None), "phase", "")
|
||||
not in ("SNORKEL", "RADIO"))
|
||||
suite.update(
|
||||
self.sim_t, actor, candidates, self.world, self.runtime_catalog,
|
||||
emcon={"radar": getattr(actor, "radar_emitting", False),
|
||||
@@ -6721,6 +6726,14 @@ class Game:
|
||||
decoy_cd=s._decoy_cd,
|
||||
active_ping_cd=s._active_ping_cd,
|
||||
speed_order=s.speed_order,
|
||||
tma_track=[dict(t=p.t, bearing=p.bearing, fx=p.fx, fy=p.fy,
|
||||
fcourse=p.fcourse,
|
||||
uncertainty_deg=p.uncertainty_deg,
|
||||
fspeed=p.fspeed)
|
||||
for p in s.tma_track.pts],
|
||||
tma_track_id=s.tma_track_id,
|
||||
tma_next_t=s.tma_next_t,
|
||||
torpedo_alarm_left=s.torpedo_alarm_left,
|
||||
blow_available=s.blow_available,
|
||||
emergency_ascent=s.emergency_ascent,
|
||||
transient_left=s.transient_left,
|
||||
@@ -7339,6 +7352,15 @@ class Game:
|
||||
s._decoy_cd = sd["decoy_cd"]
|
||||
s._active_ping_cd = sd["active_ping_cd"]
|
||||
s.speed_order = sd["speed_order"]
|
||||
s.tma_track = BearingTrack()
|
||||
s.tma_track.pts = [BearingPoint(p["t"], p["bearing"], p["fx"], p["fy"],
|
||||
p["fcourse"], p["uncertainty_deg"],
|
||||
None, p["fspeed"])
|
||||
for p in sd["tma_track"]]
|
||||
s.tma_track.version = len(s.tma_track.pts)
|
||||
s.tma_track_id = sd["tma_track_id"]
|
||||
s.tma_next_t = sd["tma_next_t"]
|
||||
s.torpedo_alarm_left = sd["torpedo_alarm_left"]
|
||||
s._last_actual_speed = s.speed
|
||||
s.blow_available = sd["blow_available"]
|
||||
s.emergency_ascent = sd["emergency_ascent"]
|
||||
@@ -8453,7 +8475,21 @@ class Game:
|
||||
and entry["blow_available"])
|
||||
or not bounded(entry.get("transient_left"), 0.0, 60.0)
|
||||
or not bounded(entry.get("hull_fatigue"), 0.0, 1.0)
|
||||
or not bounded(entry.get("speed_order"), 0.0, 100.0)):
|
||||
or not bounded(entry.get("speed_order"), 0.0, 100.0)
|
||||
or not isinstance(entry.get("tma_track"), list)
|
||||
or len(entry["tma_track"]) > config.BEARING_TRACK_MAX_PTS
|
||||
or any(not isinstance(point, dict) or set(point) != {
|
||||
"t", "bearing", "fx", "fy", "fcourse",
|
||||
"uncertainty_deg", "fspeed"}
|
||||
or not all(bounded(value, -1_000_000, 1e12)
|
||||
for value in point.values())
|
||||
or not 0.05 <= point["uncertainty_deg"] <= 180.0
|
||||
for point in entry["tma_track"])
|
||||
or (entry.get("tma_track_id") is not None
|
||||
and (not isinstance(entry["tma_track_id"], str)
|
||||
or len(entry["tma_track_id"]) > 64))
|
||||
or not bounded(entry.get("tma_next_t"), 0.0, 1e12)
|
||||
or not bounded(entry.get("torpedo_alarm_left"), -1.0, 15.0)):
|
||||
return False
|
||||
endurance_profile = runtime_catalog.endurances.get(
|
||||
f"endurance.{profile_key}")
|
||||
|
||||
+68
-5
@@ -9,6 +9,8 @@ import random
|
||||
|
||||
from src.core import config
|
||||
from src.physics import submarine as sub_physics
|
||||
from src.core import detrand
|
||||
from src.sonar.tma import BearingTrack, solve_tma
|
||||
from src.data import catalog
|
||||
from src.data import fingerprint as fingerprint_mod
|
||||
from src.sensors.platform import (
|
||||
@@ -30,6 +32,11 @@ if DECOY_PROFILE is None:
|
||||
"Kontaktkatalog unvollstaendig: Dekoy-Profil 'decoy' fehlt")
|
||||
|
||||
|
||||
SUB_REACTION_MEDIAN_S = 5.0
|
||||
SUB_TMA_RESOLVE_S = 30.0
|
||||
SUB_TMA_LEG_TURN_DEG = 35.0
|
||||
|
||||
|
||||
class SubType:
|
||||
"""Statik eines U-Boot-Typs (Captain's Log §2)."""
|
||||
|
||||
@@ -97,10 +104,9 @@ class Sub:
|
||||
self.endurance = (SubmarineEndurance(endurance_profile)
|
||||
if endurance_profile is not None else None)
|
||||
systems = runtime_catalog.profile_systems.get(source.key)
|
||||
self.legacy_observation_model = bool(
|
||||
systems is not None and systems.machine_key is not None
|
||||
and runtime_catalog.machines[
|
||||
systems.machine_key].propulsor_type == "unknown")
|
||||
# Every submarine now senses through its own sensor suite (passive
|
||||
# bearings, own TMA, ESM at periscope depth, hostile datalink).
|
||||
self.legacy_observation_model = False
|
||||
self.quiet_mult = quiet_mult # M7: Level-Faktor (leicht = lauter)
|
||||
self.attack_mult = attack_mult # M7: Level-Faktor Gegenangriff
|
||||
self.attack_cooldown = (config.SUB_ATTACK_COOLDOWN_S
|
||||
@@ -118,6 +124,11 @@ class Sub:
|
||||
# Physics state (saved): one emergency blow, blow in progress, loud
|
||||
# transient timer (launch/blow) and pressure-hull fatigue (0..1).
|
||||
self.blow_available = True
|
||||
# Own passive TMA on one bearing-only contact and crew reaction.
|
||||
self.tma_track = BearingTrack()
|
||||
self.tma_track_id = None
|
||||
self.tma_next_t = 0.0
|
||||
self.torpedo_alarm_left = -1.0
|
||||
self.emergency_ascent = False
|
||||
self.transient_left = 0.0
|
||||
self.hull_fatigue = 0.0
|
||||
@@ -175,8 +186,26 @@ class Sub:
|
||||
self.evade_offset = self.rng.uniform(-30.0, 30.0)
|
||||
self.decision_reason = "Aktives Sonar gehoert: Ausweichen"
|
||||
|
||||
def reaction_delay_s(self) -> float:
|
||||
"""Crew recognition time for a torpedo alarm (per boat, lognormal)."""
|
||||
spread = detrand.normal(self.sensor_seed, "crew-reaction")
|
||||
return config.clamp(math.exp(math.log(SUB_REACTION_MEDIAN_S) + 0.5 * spread),
|
||||
2.0, 15.0)
|
||||
|
||||
def alert_torpedo(self) -> None:
|
||||
"""Torpedo heard: after the crew's recognition time, evade hard."""
|
||||
if self.sunk or self.state == "SINKING":
|
||||
return
|
||||
if self.state == "EVADE" or self.torpedo_alarm_left == 0.0:
|
||||
# Already evading, or the recognition time has elapsed.
|
||||
self._react_to_torpedo()
|
||||
return
|
||||
if self.torpedo_alarm_left < 0.0:
|
||||
self.torpedo_alarm_left = self.reaction_delay_s()
|
||||
|
||||
def _react_to_torpedo(self) -> None:
|
||||
"""W2: Feindtorpedo gehört -> harte Ausweichreaktion + ggf. Dekoy."""
|
||||
self.torpedo_alarm_left = -1.0
|
||||
if not self.sunk and self.state != "SINKING":
|
||||
self.torpedo_alerted = True
|
||||
self.heard_ping = True
|
||||
@@ -353,6 +382,27 @@ class Sub:
|
||||
|
||||
# --- physics: planes, hull stress, cavitation, source level ---------------
|
||||
|
||||
def _ingest_bearing(self, observation) -> None:
|
||||
"""Own passive TMA from bearings of one tracked contact."""
|
||||
if observation.track_id != self.tma_track_id:
|
||||
self.tma_track = BearingTrack()
|
||||
self.tma_track_id = observation.track_id
|
||||
self.tma_track.add(observation.last_seen, observation.bearing, self.x,
|
||||
self.y, self.course,
|
||||
max(0.5, observation.bearing_uncertainty_deg or 0.5),
|
||||
None, self.speed)
|
||||
if observation.last_seen < self.tma_next_t:
|
||||
return
|
||||
self.tma_next_t = observation.last_seen + SUB_TMA_RESOLVE_S
|
||||
solution = solve_tma(self.tma_track)
|
||||
if solution is None or solution.quality < config.TMA_RANGE_MIN_QUALITY:
|
||||
return
|
||||
self.memory["contact"] = dict(
|
||||
x=solution.pos[0], y=solution.pos[1], speed=solution.speed,
|
||||
course=solution.course, noise=observation.signal)
|
||||
self.memory["contact_age"] = 0.0
|
||||
self.memory["contact_bearing"] = observation.bearing
|
||||
|
||||
def _update_hull_stress(self, dt: float) -> None:
|
||||
"""Pressure-hull fatigue below test depth; collapse beyond crush depth."""
|
||||
test = self.stype.max_depth_m
|
||||
@@ -428,6 +478,10 @@ class Sub:
|
||||
self.pinged_this_tick = False
|
||||
if self.sunk:
|
||||
return
|
||||
if self.torpedo_alarm_left > 0.0:
|
||||
self.torpedo_alarm_left = max(0.0, self.torpedo_alarm_left - dt)
|
||||
if self.torpedo_alarm_left == 0.0:
|
||||
self._react_to_torpedo()
|
||||
if self.speed != self._last_actual_speed:
|
||||
# Set from outside (spawn, scenario, test): order and actual.
|
||||
self.speed_order = self.speed
|
||||
@@ -515,7 +569,11 @@ class Sub:
|
||||
fresh_observation = (observation is not None and (
|
||||
observation.track_id in ("LEGACY", "MEMORY")
|
||||
or observation.last_seen > self.sensor_suite.last_consumed_s))
|
||||
if fresh_observation:
|
||||
if fresh_observation and observation.x is None and observation.domain == "sonar":
|
||||
self._ingest_bearing(observation)
|
||||
if fresh_observation and not (observation.x is None
|
||||
and self.memory["contact"] is not None
|
||||
and observation.domain == "sonar"):
|
||||
self.memory["contact"] = (
|
||||
dict(x=observation.x, y=observation.y,
|
||||
speed=observation.speed_kn or 0.0,
|
||||
@@ -617,6 +675,11 @@ class Sub:
|
||||
self.turn_delta = 0.0
|
||||
else:
|
||||
# Patrouille: lange, ruhige Legs statt dauernder Kreisfahrt.
|
||||
if (self.memory["contact"] is None and len(self.tma_track.pts) >= 4
|
||||
and self.tma_track.course_span_deg()
|
||||
< config.TMA_MIN_COURSE_CHG_DEG):
|
||||
# Bearing-only contact without range: open a TMA leg.
|
||||
self.target_course = (self.course + SUB_TMA_LEG_TURN_DEG) % 360.0
|
||||
self.turn_left -= dt
|
||||
if self.turn_left <= 0:
|
||||
self.turn_left = self.rng.uniform(300.0, 900.0)
|
||||
|
||||
+11
-2
@@ -174,6 +174,9 @@ class PlatformSensorSuite:
|
||||
float(now) + phase)
|
||||
self.local_picture = ObservationPicture(30.0, MAX_LOCAL_TRACKS)
|
||||
self.datalink_picture = ObservationPicture(30.0, MAX_DATALINK_TRACKS)
|
||||
# Radio reachability for the datalink this tick (a submerged boat
|
||||
# only exchanges with its antenna at mast depth); set by the owner.
|
||||
self.datalink_reachable = True
|
||||
|
||||
@property
|
||||
def datalink_id(self) -> str:
|
||||
@@ -213,7 +216,11 @@ class PlatformSensorSuite:
|
||||
target_domain = getattr(candidate, "sensor_domain", "surface")
|
||||
owner_domain = getattr(owner, "sensor_domain", "surface")
|
||||
if profile.domain in ("radar", "esm", "ais") and owner_domain == "subsurface":
|
||||
return
|
||||
# Masts only work at periscope/snorkel depth: ESM needs the
|
||||
# antenna above the surface; a submerged boat's radar/AIS never.
|
||||
if (profile.domain != "esm"
|
||||
or getattr(owner, "depth", 0.0) > MAST_DEPTH_M):
|
||||
return
|
||||
if ((profile.domain in ("radar", "esm", "ais")
|
||||
and target_domain == "subsurface")
|
||||
or (profile.domain == "ais" and target_domain != "surface")
|
||||
@@ -438,7 +445,8 @@ def exchange_friendly_datalink(
|
||||
never across groups.
|
||||
"""
|
||||
eligible = sorted(
|
||||
(suite for suite in suites if suite.datalink_group is not None),
|
||||
(suite for suite in suites if suite.datalink_group is not None
|
||||
and suite.datalink_reachable),
|
||||
key=lambda suite: suite.datalink_id)
|
||||
reports = {
|
||||
suite.datalink_id: tuple(
|
||||
@@ -475,6 +483,7 @@ def side_datalink_group(side: str) -> str | None:
|
||||
|
||||
# Own radiated-noise level at which catalog passive ranges were tuned.
|
||||
NPC_REFERENCE_NOISE = 0.8
|
||||
MAST_DEPTH_M = 18.0
|
||||
NPC_REFERENCE_SENSITIVITY_DB = -100.0
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,8 @@ def test_r10_submarine_components_preserve_draw_order_and_add_finite_decoys():
|
||||
assert rng.getstate() == expected_rng.getstate()
|
||||
assert submarine.motion.cruise_speed_kn == min(profile.speed_kn[1], 8.0)
|
||||
assert submarine.motion.maximum_speed_kn == profile.speed_kn[1]
|
||||
assert submarine.legacy_observation_model
|
||||
# Phase 7: every boat senses through its own suite.
|
||||
assert not submarine.legacy_observation_model
|
||||
assert machine_acoustics(CATALOG, key, submarine.speed) is None
|
||||
assert set(submarine.sensor_suite.controllers) == {
|
||||
f"sensor.{key}.sonar", f"sensor.{key}.esm"}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
"""Phase 7: submarines sense through their own suite, run their own TMA,
|
||||
react with a crew delay, use ESM only at mast depth and a mast-limited
|
||||
datalink."""
|
||||
|
||||
import math
|
||||
import random
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core import config
|
||||
from src.data.catalog import CATALOG
|
||||
from src.enemies.sub import Sub
|
||||
from src.sensors.platform import (MAST_DEPTH_M, PlatformObservation,
|
||||
PlatformSensorSuite, exchange_friendly_datalink)
|
||||
|
||||
|
||||
class Ocean:
|
||||
size_nm = 500.0
|
||||
sea_state = 1
|
||||
effective_sea_state = 1.0
|
||||
depth_m = staticmethod(lambda *a: 3000.0)
|
||||
thermocline_depth_m = staticmethod(lambda *a: 60.0)
|
||||
on_land = staticmethod(lambda *a: False)
|
||||
land_blocks_line = staticmethod(lambda *a: False)
|
||||
sonar_path_blocked = staticmethod(lambda *a: False)
|
||||
current_vec = staticmethod(lambda *a: (0.0, 0.0))
|
||||
|
||||
|
||||
def test_every_catalog_submarine_uses_its_sensor_suite():
|
||||
for key in CATALOG.subs:
|
||||
sub = Sub(0.0, 0.0, 100.0, 0.0, key, random.Random(1))
|
||||
assert sub.legacy_observation_model is False
|
||||
|
||||
|
||||
def _bearing_observation(sub, target, t):
|
||||
bearing = math.degrees(math.atan2(target[0] - sub.x, -(target[1] - sub.y))) % 360.0
|
||||
return PlatformObservation(
|
||||
track_id="Lcontact", domain="sonar", source="SONAR", observer_x=sub.x,
|
||||
observer_y=sub.y, bearing=bearing, range_nm=None, x=None, y=None,
|
||||
course=None, speed_kn=None, depth_m=None, quality=0.8, signal=0.6,
|
||||
last_seen=t, bearing_uncertainty_deg=0.5, range_uncertainty_nm=None,
|
||||
depth_uncertainty_m=None, label=None)
|
||||
|
||||
|
||||
def test_submarine_solves_its_own_tma_from_bearings():
|
||||
sub = Sub(100.0, 100.0, 80.0, 0.0, "aip_modern", random.Random(2))
|
||||
sub.endurance = None
|
||||
sub.speed = 6.0
|
||||
world = Ocean()
|
||||
target = [106.0, 96.0]
|
||||
vx = config.kn_to_nm_per_s(12.0)
|
||||
t = 0.0
|
||||
for _ in range(420):
|
||||
t += 1.0
|
||||
target[0] += vx
|
||||
sub.update(1.0, _bearing_observation(sub, target, t), world)
|
||||
if sub.memory["contact"] is not None:
|
||||
break
|
||||
contact = sub.memory["contact"]
|
||||
assert contact is not None
|
||||
assert math.hypot(contact["x"] - target[0], contact["y"] - target[1]) < 2.0
|
||||
|
||||
|
||||
def test_torpedo_alarm_waits_for_the_crew_reaction_time():
|
||||
sub = Sub(100.0, 100.0, 80.0, 0.0, "aip_modern", random.Random(3))
|
||||
sub.endurance = None
|
||||
delay = sub.reaction_delay_s()
|
||||
assert 2.0 <= delay <= 15.0
|
||||
sub.alert_torpedo()
|
||||
assert sub.state == "PATROLLE" and sub.torpedo_alarm_left == pytest.approx(delay)
|
||||
elapsed = 0.0
|
||||
while sub.state != "EVADE" and elapsed < 20.0:
|
||||
sub.update(0.5, None, Ocean())
|
||||
elapsed += 0.5
|
||||
assert sub.state == "EVADE"
|
||||
assert elapsed == pytest.approx(delay, abs=0.5)
|
||||
sub.alert_torpedo() # already evading: immediate
|
||||
assert sub.torpedo_alarm_left == -1.0
|
||||
|
||||
|
||||
def test_esm_only_works_with_the_mast_up():
|
||||
suite = PlatformSensorSuite(CATALOG, "aip_modern", 7, side="hostile",
|
||||
doctrine="submarine")
|
||||
profile = next(CATALOG.sensors[key] for key in suite.controllers
|
||||
if CATALOG.sensors[key].domain == "esm")
|
||||
emitter = SimpleNamespace(id=9, x=110.0, y=100.0, depth=0.0, course=0.0,
|
||||
speed=10.0, active=True, sunk=False,
|
||||
radar_emitting=True, sensor_domain="surface",
|
||||
noise_level=lambda: 0.5)
|
||||
for depth, expected in ((60.0, False), (MAST_DEPTH_M - 2.0, True)):
|
||||
suite = PlatformSensorSuite(CATALOG, "aip_modern", 7, side="hostile",
|
||||
doctrine="submarine")
|
||||
owner = SimpleNamespace(id=1, x=100.0, y=100.0, depth=depth, course=0.0,
|
||||
speed=4.0, sensor_domain="subsurface",
|
||||
noise_level=lambda: 0.1)
|
||||
suite._observe_candidate(1.0, owner, emitter, Ocean(), profile, 0, 1.0)
|
||||
assert bool(suite.local_picture.tracks(1.0)) is expected
|
||||
|
||||
|
||||
def test_datalink_skips_a_boat_without_antenna():
|
||||
sender = PlatformSensorSuite(CATALOG, "warship_01", 1, side="hostile",
|
||||
doctrine="surface_combatant", datalink_group="red")
|
||||
boat = PlatformSensorSuite(CATALOG, "aip_modern", 2, side="hostile",
|
||||
doctrine="submarine", datalink_group="red")
|
||||
sender.local_picture.observe(PlatformObservation(
|
||||
track_id="Lx", domain="radar", source="RADAR", observer_x=0.0,
|
||||
observer_y=0.0, bearing=90.0, range_nm=5.0, x=5.0, y=0.0, course=None,
|
||||
speed_kn=None, depth_m=None, quality=0.8, signal=0.8, last_seen=1.0,
|
||||
bearing_uncertainty_deg=1.0, range_uncertainty_nm=0.1,
|
||||
depth_uncertainty_m=None, label=None))
|
||||
boat.datalink_reachable = False
|
||||
exchange_friendly_datalink([sender, boat], 1.0)
|
||||
assert not boat.datalink_picture.tracks(1.0)
|
||||
boat.datalink_reachable = True
|
||||
exchange_friendly_datalink([sender, boat], 1.0)
|
||||
assert boat.datalink_picture.tracks(1.0)
|
||||
@@ -58,6 +58,11 @@ def assign_contact(game, target_id=9001):
|
||||
return contact
|
||||
|
||||
|
||||
def alarmed(sub):
|
||||
"""Alarm raised: immediate reaction or the crew's recognition countdown."""
|
||||
return sub.torpedo_alerted or sub.torpedo_alarm_left > 0.0
|
||||
|
||||
|
||||
def test_torpedo_launch_transient_alerts_subs_well_beyond_its_own_seeker_range(
|
||||
game, monkeypatch):
|
||||
"""A launch is a loud, one-time acoustic event: subs react to it from much
|
||||
@@ -75,8 +80,8 @@ def test_torpedo_launch_transient_alerts_subs_well_beyond_its_own_seeker_range(
|
||||
monkeypatch.setattr(game.audio, "play_effect", effects.append)
|
||||
assert game.launch_torpedo_at(contact, 50.0) is True
|
||||
|
||||
assert near.torpedo_alerted is True
|
||||
assert far.torpedo_alerted is False
|
||||
assert alarmed(near) is True
|
||||
assert alarmed(far) is False
|
||||
assert effects == ["torpedo_launch"]
|
||||
|
||||
|
||||
@@ -99,7 +104,7 @@ def test_quiet_sub_notices_running_torpedo_before_homing_range(game):
|
||||
|
||||
game._update_player_torpedoes(0.0)
|
||||
|
||||
assert quiet_sub.torpedo_alerted is True
|
||||
assert alarmed(quiet_sub) is True
|
||||
|
||||
|
||||
def test_loud_sub_does_not_notice_running_torpedo_at_the_same_distance(game):
|
||||
@@ -113,7 +118,7 @@ def test_loud_sub_does_not_notice_running_torpedo_at_the_same_distance(game):
|
||||
|
||||
game._update_player_torpedoes(0.0)
|
||||
|
||||
assert loud_sub.torpedo_alerted is False
|
||||
assert alarmed(loud_sub) is False
|
||||
|
||||
|
||||
def test_launch_torpedo_at_starts_the_motor_spoolup_ramp(game):
|
||||
@@ -281,8 +286,8 @@ def test_torpedo_warning_is_local_and_not_selected_target_telepathy(game, monkey
|
||||
game.torpedoes = [Torpedo(100.5, 100, 90, 50, far, 1,
|
||||
speed_kn=0, guidance_x=120, guidance_y=100)]
|
||||
game._update_player_torpedoes(0.1)
|
||||
assert near.torpedo_alerted is not blocked
|
||||
assert far.torpedo_alerted is False
|
||||
assert alarmed(near) is not blocked
|
||||
assert alarmed(far) is False
|
||||
|
||||
|
||||
def test_terminal_depth_tracking_loss_and_reacquisition():
|
||||
|
||||
Reference in new issue
Block a user