mirror of
https://github.com/db9979/uconsole_asw_game.git
synced 2026-12-06 21:04:18 +01:00
- C16: stateless draws keyed on the entity's saved sensor_seed instead of the process-global entity id (MPA MAD/radar, helicopter radar, sub radar alert, frigate HF/DF noise, raid, scope phase, sub contact report, boat ESM level), so a second game with the same seed in one process runs identically. - C18: save slots, autosave and the crash recovery autosave check the JSON text with the loader's size limit and strict validator before writing; a rejected document keeps the previous file, is recorded in the crash log and flashes a save error. - C20: the crewed boat's objective lines (custom reach, breakthrough, strait, swimmers, homecoming, pickup, datum) use the dead-reckoned position. - C22: drop thresholds that never trigger (HEARD_S, SUB_REPORT_CONTACT_S); manual states the effective 4 minutes for AI contact reports. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CW6FkwLLc6KvPHvCs5KTRo
77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
"""The crewed boat's objective line reads bearing and range from the
|
|
dead-reckoned position (``boat_nav``), like the free patrol's HQ orders:
|
|
the line must not reveal the navigation error the GPS fix would clear."""
|
|
|
|
import math
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
from src.core import boat_missions, boat_nav, custom_boat, mission_modes
|
|
from src.core.game import Game
|
|
from src.core.i18n import Translator, localize
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent))
|
|
from test_custom_boat_missions import _boat_mission # noqa: E402
|
|
|
|
ERROR = (2.5, -1.75)
|
|
|
|
|
|
def _boat_game(scenario, seed=61):
|
|
game = Game(seed=seed, start_menu=False, audio_enabled=False, language="en")
|
|
game.reset(seed, scenario)
|
|
game.local_side = "uboot"
|
|
game._update(0.05)
|
|
assert game.opfor is not None
|
|
return game, game.opfor
|
|
|
|
|
|
def _off_course(boat):
|
|
boat.orders.nav[0], boat.orders.nav[1] = ERROR
|
|
bx, by = boat_nav.position(boat)
|
|
assert (bx, by) == (boat.sub.x + ERROR[0], boat.sub.y + ERROR[1])
|
|
return bx, by
|
|
|
|
|
|
def _bearing_range(fx, fy, x, y):
|
|
return (f"{math.degrees(math.atan2(x - fx, -(y - fy))) % 360.0:03.0f}",
|
|
f"{math.hypot(x - fx, y - fy):.1f}")
|
|
|
|
|
|
def _text(value):
|
|
return localize(value, Translator("en").t)
|
|
|
|
|
|
def test_breakthrough_line_uses_the_navigated_position():
|
|
game, boat = _boat_game("s5_durchbruch")
|
|
bx, by = _off_course(boat)
|
|
point = boat_missions.goal(game)
|
|
bearing, distance = _bearing_range(bx, by, point["x"], point["y"])
|
|
true_bearing, true_distance = _bearing_range(boat.sub.x, boat.sub.y,
|
|
point["x"], point["y"])
|
|
assert (bearing, distance) != (true_bearing, true_distance)
|
|
assert _text(boat_missions.objective(game, boat)) == (
|
|
f"Break through to the goal area: bearing {bearing}, {distance} NM")
|
|
|
|
|
|
def test_homecoming_line_uses_the_navigated_position():
|
|
game, boat = _boat_game("s18_heimkehr")
|
|
assert boat_missions.mode(game) == "homecoming"
|
|
bx, by = _off_course(boat)
|
|
point = mission_modes.goal(game, "homecoming")
|
|
bearing, distance = _bearing_range(bx, by, point["x"], point["y"])
|
|
assert _text(boat_missions.objective(game, boat)) == (
|
|
f"Reach the home area: bearing {bearing}, {distance} NM")
|
|
|
|
|
|
def test_custom_reach_line_uses_the_navigated_position():
|
|
game = Game(seed=903, start_menu=False, audio_enabled=False, language="en")
|
|
game.local_side = "uboot"
|
|
mission = _boat_mission("reach", limit=3600.0)
|
|
mission["objective"]["reach"] = {"x": 300.0, "y": 240.0, "radius_nm": 2.0}
|
|
assert game.start_custom_mission(mission)
|
|
boat = game.claim_opfor_sub()
|
|
bx, by = _off_course(boat)
|
|
bearing, distance = _bearing_range(bx, by, 300.0, 240.0)
|
|
text = _text(custom_boat.objective(game, boat))
|
|
assert text.startswith(f"Reach the objective point: bearing {bearing}, {distance} nm")
|