diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 0fc5c1ae..35c02f0d 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -47,7 +47,7 @@ jobs: - name: Self-test a restart after a self-update # The update restarts the swapped exe from a process that carries the - # old one's extraction variables; it must unpack afresh (1.3.16 fix). + # old one's extraction variables; it must unpack afresh (1.3.17 fix). shell: pwsh run: | $exe = (Resolve-Path dist\U-Jagd-Windows.exe).Path diff --git a/AGENTS.md b/AGENTS.md index e444ce84..a31645ae 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,7 @@ ## Authority and scope -- This is U-Jagd 1.3.16 (`src/core/version.py`); current saves are v23-only. Treat these as compatibility contracts, not changelog entries. +- This is U-Jagd 1.3.17 (`src/core/version.py`); current saves are v23-only. Treat these as compatibility contracts, not changelog entries. - Resolve conflicts in this order: executable code and focused tests; packaged JSON/runtime resources; `pyproject.toml` and provenance/license notices; `README.md`; design/history documents under `docs/`. A plan or old comment is not an implementation contract. - Preserve explicit compatibility tests and user data unless a task intentionally changes the contract. Add a regression test for behavior changes. - Older phase/milestone labels under `docs/GDD.md`, `docs/implementation-plan.md`, `docs/plan-0.1.6.md`, and `docs/plan-0.1.7.md` are historical. Current resumable work is tracked in `docs/plan-1.3.md` and `docs/resume.md`. diff --git a/CHANGELOG.de.md b/CHANGELOG.de.md index f87779fb..bb4a96a0 100644 --- a/CHANGELOG.de.md +++ b/CHANGELOG.de.md @@ -4,14 +4,23 @@ Alle Versionen von U-Jagd, die neueste zuerst. Die [README](README.de.md) zeigt nur die neueste. -## 1.3.16 +## 1.3.17 -Version 1.3.16 behebt das Selbst-Update des Windows-Programms: Nach dem +Version 1.3.17 behebt das Selbst-Update des Windows-Programms: Nach dem Austausch startete die neue `U-Jagd-Windows.exe` nicht ("Failed to load Python DLL"), weil sie das bereits gelöschte Entpackverzeichnis des alten Prozesses erbte. Der Neustart entpackt jetzt frisch. Das Starterfenster zeigt außerdem den Link "Spendier mir einen Kaffee". Spielstände bleiben v23. +## 1.3.16 + +Version 1.3.16 bringt die **Bootskampagne**: fünf verkettete Bootsmissionen in +einem Seegebiet (Aufklärung, Durchbruch, Geleitzugangriff, Durchbruch, +Geleitzugangriff), gewählt mit `Tab` im Kampagnenbildschirm. Das Boot nimmt +Torpedos, Rumpfschaden und Ansehen bei der U-Boot-Führung von Mission zu +Mission mit; im Stützpunkt gibt es volle Überholung oder schnelles Auslaufen. +Gespeichert in `~/.u-jagd/boat_campaign.json`; Spielstände bleiben v23. + ## 1.3.15 Version 1.3.15 bringt Bootsmission 7, **Geleitzugangriff**: Die Fregatte diff --git a/CHANGELOG.md b/CHANGELOG.md index 07b9eb6a..adeeebaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,23 @@ Every U-Jagd release, newest first. The [README](README.md) shows only the latest one. -## 1.3.16 +## 1.3.17 -Release 1.3.16 fixes the Windows program's self-update: after swapping in the +Release 1.3.17 fixes the Windows program's self-update: after swapping in the new `U-Jagd-Windows.exe` it failed to start ("Failed to load Python DLL") because it inherited the old process's already deleted unpack directory. The restart now unpacks afresh. The starter window also shows the "Buy me a coffee" link. Saves stay v23. +## 1.3.16 + +Release 1.3.16 adds the **boat campaign**: five linked boat missions in one sea +area (reconnaissance, breakthrough, convoy attack, breakthrough, convoy +attack), chosen with `Tab` on the campaign screen. The boat carries its +torpedoes, hull damage and standing with U-boat command from mission to +mission; at its base it takes a full refit or a quick turnaround. Kept in +`~/.u-jagd/boat_campaign.json`; saves stay v23. + ## 1.3.15 Release 1.3.15 adds boat mission 7, **Convoy attack**: the frigate escorts four diff --git a/README.de.md b/README.de.md index dfe3068e..fcd6b29e 100644 --- a/README.de.md +++ b/README.de.md @@ -14,9 +14,9 @@ Sie führen eine fiktive Fregatte und wechseln zwischen neun Arbeitsplätzen, um zu navigieren, zu suchen, Kontakte zu klassifizieren, Ziele zu bekämpfen und das Schiff einsatzfähig zu halten. -Aktuelle Version: **1.3.16** +Aktuelle Version: **1.3.17** -Version 1.3.16 behebt das Selbst-Update des Windows-Programms: Nach dem +Version 1.3.17 behebt das Selbst-Update des Windows-Programms: Nach dem Austausch startete die neue `U-Jagd-Windows.exe` nicht ("Failed to load Python DLL"), weil sie das bereits gelöschte Entpackverzeichnis des alten Prozesses erbte. Der Neustart entpackt jetzt frisch. Das Starterfenster zeigt diff --git a/README.md b/README.md index 9902a61c..2c7b4520 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,9 @@ around the ClockworkPi uConsole's 1280 x 720 workspace. You command a fictional frigate and move between nine workstations to navigate, search, classify, engage, and keep the ship operational. -Current release: **1.3.16** +Current release: **1.3.17** -Release 1.3.16 fixes the Windows program's self-update: after swapping in the +Release 1.3.17 fixes the Windows program's self-update: after swapping in the new `U-Jagd-Windows.exe` it failed to start ("Failed to load Python DLL") because it inherited the old process's already deleted unpack directory. The restart now unpacks afresh. The starter window also shows the "Buy me a diff --git a/data/i18n/de.json b/data/i18n/de.json index 3f5ffaa5..e70d42dc 100644 --- a/data/i18n/de.json +++ b/data/i18n/de.json @@ -5229,7 +5229,7 @@ "campaign.port_refit": "1 Volle Werftliegezeit: {torpedoes} Torpedos, alle Reparaturen, neuer Hubschrauber (Ansehen -5)", "campaign.port_quick": "2 Schnell wieder auslaufen: {torpedoes} Torpedos, Schäden bleiben an Bord (Ansehen +3)", "campaign.sail_hint": "Enter: zum nächsten Einsatz auslaufen", - "campaign.menu_hint": "Enter auslaufen · 1/2 Hafenwahl · N neue Kampagne · Esc zurück", + "campaign.menu_hint": "Enter auslaufen · 1/2 Hafenwahl · N neue Kampagne · Tab Fregatte/Boot · Esc zurück", "campaign.confirm_new": "N erneut drücken, um die laufende Kampagne zu ersetzen", "campaign.scenario.s1_patrouille": "Patrouille", "campaign.scenario.s2_doppeljagd": "Doppeljagd", @@ -5564,5 +5564,14 @@ "uboot.end.convoy_sunk": "GELEITZUG GETROFFEN - SIEG", "runtime.merchant_torpedoed": "Torpedodetonation im Geleitzug: ein Handelsschiff ist getroffen", "commander.web.scenario_s7_geleitzug": "Geleitzug (Boot)", + "campaign.boat.title": "Bootskampagne", + "campaign.boat.none": "Noch keine Bootskampagne. N startet eine in diesem Seegebiet; du führst das U-Boot.", + "campaign.boat.standing": "Ansehen bei der U-Boot-Führung {reputation}/100 · Torpedos an Bord {torpedoes}", + "campaign.boat.condition": "Rumpfschaden {damage} %", + "campaign.boat.full_load": "volle Beladung", + "campaign.boat.status_lost": "Kampagne beendet: Boot verloren oder Kommandant abgelöst. N startet eine neue.", + "campaign.boat.port_refit": "1 Volle Überholung: volle Torpedobeladung, Rumpf repariert (Ansehen -5)", + "campaign.boat.port_quick": "2 Schnelles Auslaufen: {torpedoes} Torpedos, Rumpfschaden {damage} % bleibt (Ansehen +3)", + "campaign.boat.sail_hint": "Enter: zur nächsten Bootsmission auslaufen", "launcher.support": "Gefällt dir U-Jagd? Spendier mir einen Kaffee" } diff --git a/data/i18n/en.json b/data/i18n/en.json index 213f446c..0982981a 100644 --- a/data/i18n/en.json +++ b/data/i18n/en.json @@ -5229,7 +5229,7 @@ "campaign.port_refit": "1 Full refit: {torpedoes} torpedoes, all repairs, new helicopter (standing -5)", "campaign.port_quick": "2 Quick turnaround: {torpedoes} torpedoes, damage stays aboard (standing +3)", "campaign.sail_hint": "Enter: sail for the next mission", - "campaign.menu_hint": "Enter sail · 1/2 port choice · N new campaign · Esc back", + "campaign.menu_hint": "Enter sail · 1/2 port choice · N new campaign · Tab frigate/boat · Esc back", "campaign.confirm_new": "Press N again to replace the running campaign", "campaign.scenario.s1_patrouille": "Patrol", "campaign.scenario.s2_doppeljagd": "Double hunt", @@ -5564,5 +5564,14 @@ "uboot.end.convoy_sunk": "CONVOY HIT - VICTORY", "runtime.merchant_torpedoed": "Torpedo explosion in the convoy: a merchant is hit", "commander.web.scenario_s7_geleitzug": "Convoy attack (boat)", + "campaign.boat.title": "Boat campaign", + "campaign.boat.none": "No boat campaign yet. N starts one in this sea area; you command the submarine.", + "campaign.boat.standing": "Standing with U-boat command {reputation}/100 · torpedoes aboard {torpedoes}", + "campaign.boat.condition": "Hull damage {damage} %", + "campaign.boat.full_load": "full load", + "campaign.boat.status_lost": "Campaign over: boat lost or commander relieved. N starts a new one.", + "campaign.boat.port_refit": "1 Full refit: full torpedo load, hull repaired (standing -5)", + "campaign.boat.port_quick": "2 Quick turnaround: {torpedoes} torpedoes, hull damage {damage} % stays (standing +3)", + "campaign.boat.sail_hint": "Enter: put to sea for the next boat mission", "launcher.support": "Enjoying U-Jagd? Buy me a coffee" } diff --git a/data/manual/00-quickstart.de.md b/data/manual/00-quickstart.de.md index 20bf6525..dc5c8614 100644 --- a/data/manual/00-quickstart.de.md +++ b/data/manual/00-quickstart.de.md @@ -82,6 +82,7 @@ Die Statuszeile unten zeigt das neueste Ereignis und die wichtigste Telemetrie; - Menü: `1`-`7` Szenario (4 = Zufall mit eigener Schwierigkeit, 5 bis 7 = Bootsmissionen, siehe Referenzkapitel), `W` Weltmodus, `R` neuer Seed, `F` Vollbild, `Enter` Start. - **Ausbildung** (Hauptmenü): sechs geführte Lektionen, jede eine kurze Mission mit einem Hinweisbanner, das auf Sie wartet: 1 hören und peilen, 2 Zielbewegungsanalyse, 3 Torpedoangriff, 4 Hubschrauber und Sonarbojen; auf dem U-Boot (für diese beiden spielt die uConsole das Boot): 5 horchen und unter die Schicht (die Fregatte hören, als Kampfschiff klassifizieren, die Schicht per BT messen und darunter tauchen), 6 eine jagende Fregatte abschütteln (Seite Bedrohung lesen, mit `I` ausweichen, leise und tiefer als 100 m gehen, bis zwei Minuten lang kein Ping mehr kommt; die Fregatte pingt alle 45 s, bis Sie ausweichen, danach nur, solange ihre Pings Sie noch finden, und schießt nie). In den Lektionen 1, 2 und 4 ist das Boot neutral und greift nie an; Lektion 3 ist ein echter Angriff, der mit dem Versenken endet. Die übrigen Lektionen enden nach dem letzten Schritt als Sieg. `R` am Ende startet die Lektion neu. Eine gespeicherte Lektion beginnt ihre Hinweise nach dem Laden wieder bei Schritt 1 und überspringt bereits erledigte Schritte. Nach einer Lektion behält die uConsole die gespielte Seite. - **Kampagne** (Hauptmenü): sechs verkettete Einsätze in dem im Menü gewählten Seegebiet (Welt `W` und Seed; jeder Einsatz bleibt im selben Sektor). Übertragen werden die übrigen Torpedos (mindestens 2, höchstens 10), noch beschädigte Abteilungen, ein verlorener Hubschrauber und Ihr Ansehen bei der Führung (0-100, Start 50: +15 für einen Sieg, -20 für eine Niederlage, -10 für einen zivilen Verlust, +/-3 je erledigtem oder gescheitertem Auftrag). Nach jedem Einsatz läuft das Schiff in den Hafen: `1` volle Werftliegezeit (4 bis 8 Torpedos je nach Ansehen, alle Reparaturen, ein neuer Hubschrauber, Ansehen -5) oder `2` schnell wieder auslaufen (halbe Nachlieferung, Schäden bleiben an Bord, Ansehen +3); `Enter` läuft aus. Die Kampagne endet, wenn das Schiff verloren geht, das Ansehen unter 10 fällt oder der sechste Einsatz vorbei ist. Sie liegt in `~/.u-jagd/campaign.json`, getrennt von den Spielständen: ein während eines Kampagneneinsatzes gespeicherter Platz lädt als normale Mission; damit er zählt, wird der Einsatz aus dem Kampagnenbildschirm erneut gefahren. `N` startet eine neue Kampagne (bei laufender Kampagne zweimal). +- **Bootskampagne** (Hauptmenü, Kampagne, `Tab`): fünf verkettete Bootsmissionen im selben Seegebiet, gespielt auf der Bootsseite: Aufklärung, Durchbruch, Geleitzugangriff, Durchbruch, Geleitzugangriff. Übertragen werden die Torpedos des Boots, sein Rumpfschaden (höchstens 60 %) und Ihr Ansehen bei der U-Boot-Führung (0-100, Start 50: +15 für eine gewonnene, -20 für eine verlorene Mission). Nach jeder Mission läuft das Boot in seinen Stützpunkt: `1` volle Überholung (volle Torpedobeladung, Rumpf repariert, Ansehen -5) oder `2` schnell wieder auslaufen (die Hälfte von 4 bis 8 Torpedos je nach Ansehen kommt dazu, der Rumpfschaden bleibt, Ansehen +3); `Enter` läuft aus. Sie endet, wenn das Boot verloren geht, das Ansehen unter 10 fällt oder die fünfte Mission vorbei ist, und liegt in `~/.u-jagd/boat_campaign.json` neben der Kampagne der Fregatte. - `S` / `L`: Speichern / Laden (Plätze 1-5). Spielstände sind exakt und deterministisch: ein geladenes Spiel läuft identisch weiter. - `F10`: Optionen - Sprache, Vollbild, Audio, große Schrift, Tooltips, Bildrate (30 oder 60 FPS; 30 spart Rechenleistung auf der uConsole und ist voreingestellt), Ereignislog/Telemetrie als Statuszeile (Standard, mehr Platz für die Station) oder feste Leiste, Bedienerassistenz aus (Standard: Rohdaten und manuelle Analyse) oder Training (automatische Linienbeschriftung, Blattfrequenz- und Katalog-/Senderkandidaten). Seite 2 (`Bild ab`/`Tab`): welche Seite der uConsole spielt, Fregatte (Standard) oder feindliches U-Boot; nur im Hauptmenü, nie gespeichert. Ein neues Spiel fragt ohnehin zuerst danach. Auf Seite 2 liegen auch die **geglätteten Kartenlinien** (standardmäßig aus; glättet Peilstriche, Küste und Plot, kostet auf der uConsole etwas Rechenzeit). Dazu die **gesprochenen Crew-Meldungen** (standardmäßig aus): die Crew meldet Torpedo im Wasser, neuen Kontakt mit Peilung, Sinkgeräusche, Torpedo los, Treffer, Gefechtsstationen, Seefernaufklärer auf Station und das Missionsende laut, Peilungen Ziffer für Ziffer. Die uConsole spricht über ein installiertes `espeak-ng` (`sudo apt install espeak-ng`) und bleibt ohne es stumm; Remote-Crew-Browser haben einen eigenen Schalter unter Einstellungen (Sprachausgabe des Browsers, in dessen Sprache). Spielt die uConsole das U-Boot, meldet stattdessen dessen Crew (siehe Kapitel Referenz). - `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). diff --git a/data/manual/00-quickstart.en.md b/data/manual/00-quickstart.en.md index 6b292c0e..e890caae 100644 --- a/data/manual/00-quickstart.en.md +++ b/data/manual/00-quickstart.en.md @@ -82,6 +82,7 @@ The bottom status ticker shows the newest event and key telemetry; `F11` opens t - Menu: `1`-`7` scenario (4 = random with custom difficulty, 5 to 7 = boat missions, see the reference chapter), `W` world mode, `R` new seed, `F` fullscreen, `Enter` start. - **Training** (main menu): six guided lessons, each a short mission with a hint banner that waits for you: 1 listen and take bearings, 2 target motion analysis, 3 torpedo attack, 4 helicopter and sonobuoys; on the submarine (the uConsole plays the boat for these two): 5 listen and hide below the layer (hear the frigate, classify it as a warship, measure the layer with a BT and dive below it), 6 shake off a hunting frigate (read the Threat page, evade with `I`, go quiet and deeper than 100 m until no ping has come for two minutes; the frigate pings every 45 s until you evade, then only while its pings still find you, and never fires). In lessons 1, 2 and 4 the boat is neutral and never attacks; lesson 3 is a real attack that ends when the boat sinks. The other lessons end as won after their last step. `R` at the end runs the lesson again. A saved lesson restarts its hints at step 1 after loading and passes the steps that are already done. After a lesson the uConsole keeps the side it played. - **Campaign** (main menu): six linked missions in the sea area chosen in the menu (world `W` and seed; every mission keeps the same sector). Carried over are the torpedoes left (at least 2, at most 10), compartments still damaged, a lost helicopter and your standing with HQ (0-100, start 50: +15 for a win, -20 for a loss, -10 for a civilian loss, +/-3 per task done or failed). After each mission the ship calls at port: `1` full refit (4 to 8 torpedoes by standing, all repairs, a new helicopter, standing -5) or `2` quick turnaround (half that restock, damage stays aboard, standing +3); `Enter` sails. The campaign ends when the ship is lost, standing falls below 10, or the sixth mission is done. It is kept in `~/.u-jagd/campaign.json`, apart from the save slots: a slot saved during a campaign mission loads as a plain mission; to count, the mission is sailed again from the campaign screen. `N` starts a new campaign (twice while one is running). +- **Boat campaign** (main menu, Campaign, `Tab`): five linked boat missions in the same sea area, played on the boat side: reconnaissance, breakthrough, convoy attack, breakthrough, convoy attack. Carried over are the boat's torpedoes, its hull damage (at most 60 %) and your standing with U-boat command (0-100, start 50: +15 for a mission won, -20 for one lost). After each mission the boat calls at its base: `1` full refit (full torpedo load, hull repaired, standing -5) or `2` quick turnaround (half of 4 to 8 torpedoes by standing added, the hull damage stays, standing +3); `Enter` puts to sea. It ends when the boat is lost, standing falls below 10, or the fifth mission is done, and is kept in `~/.u-jagd/boat_campaign.json` beside the frigate's campaign. - `S` / `L`: save / load (slots 1-5). Saves are exact and deterministic: a loaded game continues identically. - `F10`: options - language, fullscreen, audio, large text, tooltips, frame rate (30 or 60 FPS; 30 saves CPU on the uConsole and is the default), event log / telemetry as status ticker (default, more room for the station) or docked band, operator assistance off (default: raw data and manual analysis) or training (automatic line labels, blade-rate and catalogue/emitter candidates). Page 2 (`PgDn`/`Tab`): which side the uConsole plays, frigate (default) or hostile submarine; only in the main menu, never saved. A new game asks for it first anyway. Page 2 also holds **anti-aliased chart lines** (off by default; smooths bearing lines, coast and plot at some CPU cost on the uConsole). And **spoken crew reports** (off by default): the crew says torpedo in the water, new contact with bearing, breaking-up noises, torpedo away, hit, action stations, patrol aircraft on station and the mission result aloud, bearings digit by digit. The uConsole speaks through an installed `espeak-ng` (`sudo apt install espeak-ng`) and stays silent without it; Remote Crew browsers have their own switch under Settings (the browser's speech synthesis, in the browser's language). With the uConsole on the submarine the boat's crew reports instead (see the reference chapter). - `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). diff --git a/data/manual/10-reference.de.md b/data/manual/10-reference.de.md index bf075647..1e11d2f3 100644 --- a/data/manual/10-reference.de.md +++ b/data/manual/10-reference.de.md @@ -158,7 +158,7 @@ Wenn niemand die Fregatte fährt (die uConsole spielt das Boot oder ein Solo-Bro - Ein ausgefahrener Mast oder Schnorchelkopf erscheint auf dem Fregattenradar nur als bloßer Punkt (siehe Kapitel OPZ). - Das ESM des Boots hört keine Radare anderer U-Boote und keine Flugkörpersucher; es hat keine gewichtete Bibliotheksanalyse, keine Messung der Umlaufzeit und keine Bewegungsanalyse eines Senders (die Kreuzpeilung nimmt einen langsamen Sender an). - Die Bibliothek des Boots zeigt nur die ersten Kandidaten in Katalogreihenfolge; bei einem X-Band-Suchradar mit vielen möglichen Treffern (dem des Hubschraubers) kann der richtige Eintrag außerhalb der Liste liegen. -- Die Kampagne wird nur von der Fregatte aus gespielt; eine Bootskampagne gibt es noch nicht. Außerhalb des Geleitzugangriffs suchen die Torpedos des Boots nur die Fregatte, und die Boote der KI greifen nie Handelsschiffe an. +- Die Bootskampagne kennt im Stützpunkt nur Überholung und schnelles Auslaufen und übernimmt keinen Zustand der Leckwehr (nur den gesamten Rumpfschaden). Außerhalb des Geleitzugangriffs suchen die Torpedos des Boots nur die Fregatte, und die Boote der KI greifen nie Handelsschiffe an. - Die KI steuert ein Boot nicht auf das Ziel einer Bootsmission zu. - Die KI-Jäger ordnen Radarechos, ESM und Meldungen der Führung nicht dem Boot zu und schießen kein ASROC. - Das Sehrohr hat eine Vergrößerung und keine Kamera; Sichtungen tragen keine Identifikation über die grobe Klasse hinaus, und das Stadimeter nimmt eine Klassenlänge statt einer Masthöhe an. diff --git a/data/manual/10-reference.en.md b/data/manual/10-reference.en.md index 1a177047..3d4fe7d0 100644 --- a/data/manual/10-reference.en.md +++ b/data/manual/10-reference.en.md @@ -158,7 +158,7 @@ When nobody sails the frigate (the uConsole plays the boat, or a solo browser pl - A raised mast or snorkel head is seen by the frigate's radar only as a bare blip (see the OPZ chapter). - The boat's ESM hears no other submarine's radar and no missile seeker; it has no scored library analysis, no scan-period measurement and no target motion analysis of an emitter (the cross-fix assumes a slow emitter). - The boat's library shows only the first candidates in catalogue order; for an X-band search radar with many possible matches (the helicopter's) the right entry can fall outside the list. -- The campaign is played from the frigate only; there is no boat campaign yet. Outside the convoy attack the boat's torpedoes home on the frigate only, and the AI's boats never attack merchants. +- The boat campaign has no port choices beyond refit and quick turnaround, and no damage-control state carried over (only the overall hull damage). Outside the convoy attack the boat's torpedoes home on the frigate only, and the AI's boats never attack merchants. - The AI does not steer a boat towards a boat mission's objective. - The AI hunters do not correlate radar blips, ESM or HQ reports with the boat, and they fire no ASROC. - The periscope has one magnification and no camera; sightings carry no identification beyond the coarse class, and the stadimeter assumes a class length rather than a masthead height. diff --git a/docs/manual/handbuch.de.pdf b/docs/manual/handbuch.de.pdf index d065a173..8db713ef 100644 Binary files a/docs/manual/handbuch.de.pdf and b/docs/manual/handbuch.de.pdf differ diff --git a/docs/manual/manual.de.md b/docs/manual/manual.de.md index e1f2cc6d..0f5cf607 100644 --- a/docs/manual/manual.de.md +++ b/docs/manual/manual.de.md @@ -128,6 +128,7 @@ Die Statuszeile unten zeigt das neueste Ereignis und die wichtigste Telemetrie; - Menü: `1`-`7` Szenario (4 = Zufall mit eigener Schwierigkeit, 5 bis 7 = Bootsmissionen, siehe Referenzkapitel), `W` Weltmodus, `R` neuer Seed, `F` Vollbild, `Enter` Start. - **Ausbildung** (Hauptmenü): sechs geführte Lektionen, jede eine kurze Mission mit einem Hinweisbanner, das auf Sie wartet: 1 hören und peilen, 2 Zielbewegungsanalyse, 3 Torpedoangriff, 4 Hubschrauber und Sonarbojen; auf dem U-Boot (für diese beiden spielt die uConsole das Boot): 5 horchen und unter die Schicht (die Fregatte hören, als Kampfschiff klassifizieren, die Schicht per BT messen und darunter tauchen), 6 eine jagende Fregatte abschütteln (Seite Bedrohung lesen, mit `I` ausweichen, leise und tiefer als 100 m gehen, bis zwei Minuten lang kein Ping mehr kommt; die Fregatte pingt alle 45 s, bis Sie ausweichen, danach nur, solange ihre Pings Sie noch finden, und schießt nie). In den Lektionen 1, 2 und 4 ist das Boot neutral und greift nie an; Lektion 3 ist ein echter Angriff, der mit dem Versenken endet. Die übrigen Lektionen enden nach dem letzten Schritt als Sieg. `R` am Ende startet die Lektion neu. Eine gespeicherte Lektion beginnt ihre Hinweise nach dem Laden wieder bei Schritt 1 und überspringt bereits erledigte Schritte. Nach einer Lektion behält die uConsole die gespielte Seite. - **Kampagne** (Hauptmenü): sechs verkettete Einsätze in dem im Menü gewählten Seegebiet (Welt `W` und Seed; jeder Einsatz bleibt im selben Sektor). Übertragen werden die übrigen Torpedos (mindestens 2, höchstens 10), noch beschädigte Abteilungen, ein verlorener Hubschrauber und Ihr Ansehen bei der Führung (0-100, Start 50: +15 für einen Sieg, -20 für eine Niederlage, -10 für einen zivilen Verlust, +/-3 je erledigtem oder gescheitertem Auftrag). Nach jedem Einsatz läuft das Schiff in den Hafen: `1` volle Werftliegezeit (4 bis 8 Torpedos je nach Ansehen, alle Reparaturen, ein neuer Hubschrauber, Ansehen -5) oder `2` schnell wieder auslaufen (halbe Nachlieferung, Schäden bleiben an Bord, Ansehen +3); `Enter` läuft aus. Die Kampagne endet, wenn das Schiff verloren geht, das Ansehen unter 10 fällt oder der sechste Einsatz vorbei ist. Sie liegt in `~/.u-jagd/campaign.json`, getrennt von den Spielständen: ein während eines Kampagneneinsatzes gespeicherter Platz lädt als normale Mission; damit er zählt, wird der Einsatz aus dem Kampagnenbildschirm erneut gefahren. `N` startet eine neue Kampagne (bei laufender Kampagne zweimal). +- **Bootskampagne** (Hauptmenü, Kampagne, `Tab`): fünf verkettete Bootsmissionen im selben Seegebiet, gespielt auf der Bootsseite: Aufklärung, Durchbruch, Geleitzugangriff, Durchbruch, Geleitzugangriff. Übertragen werden die Torpedos des Boots, sein Rumpfschaden (höchstens 60 %) und Ihr Ansehen bei der U-Boot-Führung (0-100, Start 50: +15 für eine gewonnene, -20 für eine verlorene Mission). Nach jeder Mission läuft das Boot in seinen Stützpunkt: `1` volle Überholung (volle Torpedobeladung, Rumpf repariert, Ansehen -5) oder `2` schnell wieder auslaufen (die Hälfte von 4 bis 8 Torpedos je nach Ansehen kommt dazu, der Rumpfschaden bleibt, Ansehen +3); `Enter` läuft aus. Sie endet, wenn das Boot verloren geht, das Ansehen unter 10 fällt oder die fünfte Mission vorbei ist, und liegt in `~/.u-jagd/boat_campaign.json` neben der Kampagne der Fregatte. - `S` / `L`: Speichern / Laden (Plätze 1-5). Spielstände sind exakt und deterministisch: ein geladenes Spiel läuft identisch weiter. - `F10`: Optionen - Sprache, Vollbild, Audio, große Schrift, Tooltips, Bildrate (30 oder 60 FPS; 30 spart Rechenleistung auf der uConsole und ist voreingestellt), Ereignislog/Telemetrie als Statuszeile (Standard, mehr Platz für die Station) oder feste Leiste, Bedienerassistenz aus (Standard: Rohdaten und manuelle Analyse) oder Training (automatische Linienbeschriftung, Blattfrequenz- und Katalog-/Senderkandidaten). Seite 2 (`Bild ab`/`Tab`): welche Seite der uConsole spielt, Fregatte (Standard) oder feindliches U-Boot; nur im Hauptmenü, nie gespeichert. Ein neues Spiel fragt ohnehin zuerst danach. Auf Seite 2 liegen auch die **geglätteten Kartenlinien** (standardmäßig aus; glättet Peilstriche, Küste und Plot, kostet auf der uConsole etwas Rechenzeit). Dazu die **gesprochenen Crew-Meldungen** (standardmäßig aus): die Crew meldet Torpedo im Wasser, neuen Kontakt mit Peilung, Sinkgeräusche, Torpedo los, Treffer, Gefechtsstationen, Seefernaufklärer auf Station und das Missionsende laut, Peilungen Ziffer für Ziffer. Die uConsole spricht über ein installiertes `espeak-ng` (`sudo apt install espeak-ng`) und bleibt ohne es stumm; Remote-Crew-Browser haben einen eigenen Schalter unter Einstellungen (Sprachausgabe des Browsers, in dessen Sprache). Spielt die uConsole das U-Boot, meldet stattdessen dessen Crew (siehe Kapitel Referenz). - `F9`: Commander / Remote Crew - Browser im LAN können Stationen übernehmen. Eine freie Station wird sofort mit allen ihren Rechten übernommen (auch Direktfeuer und Sonar-Liveaudio, wo die Station sie hat); eine Station, die ein Crewmitglied hält, wird angefragt, und der Host kann sie übergeben. Der Host kann jederzeit eine Station oder einzelne Rechte entziehen und bis zu zwei Browser zu reinen Beobachtern machen (Roster-Taste `O`): sie sehen jede Station beider Einheiten, ohne sie zu halten, können nichts befehlen und erhalten das SimLog mit Zeitstrahl zur Nachbesprechung und JSON-Export. Auf einem Windows-PC startet das Programm `U-Jagd-Windows.exe` das Spiel mit bereits eingeschalteter Remote Crew (Besatzungs- oder Solomodus) und zeigt Browser-Adresse, Beitrittscode und QR-Code; `--remote-crew` macht dasselbe über die Kommandozeile (siehe README). @@ -1199,7 +1200,7 @@ Wenn niemand die Fregatte fährt (die uConsole spielt das Boot oder ein Solo-Bro - Ein ausgefahrener Mast oder Schnorchelkopf erscheint auf dem Fregattenradar nur als bloßer Punkt (siehe Kapitel OPZ). - Das ESM des Boots hört keine Radare anderer U-Boote und keine Flugkörpersucher; es hat keine gewichtete Bibliotheksanalyse, keine Messung der Umlaufzeit und keine Bewegungsanalyse eines Senders (die Kreuzpeilung nimmt einen langsamen Sender an). - Die Bibliothek des Boots zeigt nur die ersten Kandidaten in Katalogreihenfolge; bei einem X-Band-Suchradar mit vielen möglichen Treffern (dem des Hubschraubers) kann der richtige Eintrag außerhalb der Liste liegen. -- Die Kampagne wird nur von der Fregatte aus gespielt; eine Bootskampagne gibt es noch nicht. Außerhalb des Geleitzugangriffs suchen die Torpedos des Boots nur die Fregatte, und die Boote der KI greifen nie Handelsschiffe an. +- Die Bootskampagne kennt im Stützpunkt nur Überholung und schnelles Auslaufen und übernimmt keinen Zustand der Leckwehr (nur den gesamten Rumpfschaden). Außerhalb des Geleitzugangriffs suchen die Torpedos des Boots nur die Fregatte, und die Boote der KI greifen nie Handelsschiffe an. - Die KI steuert ein Boot nicht auf das Ziel einer Bootsmission zu. - Die KI-Jäger ordnen Radarechos, ESM und Meldungen der Führung nicht dem Boot zu und schießen kein ASROC. - Das Sehrohr hat eine Vergrößerung und keine Kamera; Sichtungen tragen keine Identifikation über die grobe Klasse hinaus, und das Stadimeter nimmt eine Klassenlänge statt einer Masthöhe an. diff --git a/docs/manual/manual.en.md b/docs/manual/manual.en.md index 27a09665..6bc2bd16 100644 --- a/docs/manual/manual.en.md +++ b/docs/manual/manual.en.md @@ -128,6 +128,7 @@ The bottom status ticker shows the newest event and key telemetry; `F11` opens t - Menu: `1`-`7` scenario (4 = random with custom difficulty, 5 to 7 = boat missions, see the reference chapter), `W` world mode, `R` new seed, `F` fullscreen, `Enter` start. - **Training** (main menu): six guided lessons, each a short mission with a hint banner that waits for you: 1 listen and take bearings, 2 target motion analysis, 3 torpedo attack, 4 helicopter and sonobuoys; on the submarine (the uConsole plays the boat for these two): 5 listen and hide below the layer (hear the frigate, classify it as a warship, measure the layer with a BT and dive below it), 6 shake off a hunting frigate (read the Threat page, evade with `I`, go quiet and deeper than 100 m until no ping has come for two minutes; the frigate pings every 45 s until you evade, then only while its pings still find you, and never fires). In lessons 1, 2 and 4 the boat is neutral and never attacks; lesson 3 is a real attack that ends when the boat sinks. The other lessons end as won after their last step. `R` at the end runs the lesson again. A saved lesson restarts its hints at step 1 after loading and passes the steps that are already done. After a lesson the uConsole keeps the side it played. - **Campaign** (main menu): six linked missions in the sea area chosen in the menu (world `W` and seed; every mission keeps the same sector). Carried over are the torpedoes left (at least 2, at most 10), compartments still damaged, a lost helicopter and your standing with HQ (0-100, start 50: +15 for a win, -20 for a loss, -10 for a civilian loss, +/-3 per task done or failed). After each mission the ship calls at port: `1` full refit (4 to 8 torpedoes by standing, all repairs, a new helicopter, standing -5) or `2` quick turnaround (half that restock, damage stays aboard, standing +3); `Enter` sails. The campaign ends when the ship is lost, standing falls below 10, or the sixth mission is done. It is kept in `~/.u-jagd/campaign.json`, apart from the save slots: a slot saved during a campaign mission loads as a plain mission; to count, the mission is sailed again from the campaign screen. `N` starts a new campaign (twice while one is running). +- **Boat campaign** (main menu, Campaign, `Tab`): five linked boat missions in the same sea area, played on the boat side: reconnaissance, breakthrough, convoy attack, breakthrough, convoy attack. Carried over are the boat's torpedoes, its hull damage (at most 60 %) and your standing with U-boat command (0-100, start 50: +15 for a mission won, -20 for one lost). After each mission the boat calls at its base: `1` full refit (full torpedo load, hull repaired, standing -5) or `2` quick turnaround (half of 4 to 8 torpedoes by standing added, the hull damage stays, standing +3); `Enter` puts to sea. It ends when the boat is lost, standing falls below 10, or the fifth mission is done, and is kept in `~/.u-jagd/boat_campaign.json` beside the frigate's campaign. - `S` / `L`: save / load (slots 1-5). Saves are exact and deterministic: a loaded game continues identically. - `F10`: options - language, fullscreen, audio, large text, tooltips, frame rate (30 or 60 FPS; 30 saves CPU on the uConsole and is the default), event log / telemetry as status ticker (default, more room for the station) or docked band, operator assistance off (default: raw data and manual analysis) or training (automatic line labels, blade-rate and catalogue/emitter candidates). Page 2 (`PgDn`/`Tab`): which side the uConsole plays, frigate (default) or hostile submarine; only in the main menu, never saved. A new game asks for it first anyway. Page 2 also holds **anti-aliased chart lines** (off by default; smooths bearing lines, coast and plot at some CPU cost on the uConsole). And **spoken crew reports** (off by default): the crew says torpedo in the water, new contact with bearing, breaking-up noises, torpedo away, hit, action stations, patrol aircraft on station and the mission result aloud, bearings digit by digit. The uConsole speaks through an installed `espeak-ng` (`sudo apt install espeak-ng`) and stays silent without it; Remote Crew browsers have their own switch under Settings (the browser's speech synthesis, in the browser's language). With the uConsole on the submarine the boat's crew reports instead (see the reference chapter). - `F9`: Commander / Remote Crew - lets browser clients on the LAN take stations. A free station is taken at once with all of its rights (including direct fire and live sonar audio where the station has them); a station a crewmate holds is requested, and the host can hand it over. The host can revoke a station or single rights at any time, and can make up to two browsers read-only observers (roster key `O`): they watch any station of either unit without holding it, cannot command, and get the SimLog with a debrief timeline and JSON export. On a Windows PC the program `U-Jagd-Windows.exe` starts the game with Remote Crew already on (crew or solo mode) and shows the browser address, join code and QR code; `--remote-crew` does the same from the command line (see the README). @@ -1198,7 +1199,7 @@ When nobody sails the frigate (the uConsole plays the boat, or a solo browser pl - A raised mast or snorkel head is seen by the frigate's radar only as a bare blip (see the OPZ chapter). - The boat's ESM hears no other submarine's radar and no missile seeker; it has no scored library analysis, no scan-period measurement and no target motion analysis of an emitter (the cross-fix assumes a slow emitter). - The boat's library shows only the first candidates in catalogue order; for an X-band search radar with many possible matches (the helicopter's) the right entry can fall outside the list. -- The campaign is played from the frigate only; there is no boat campaign yet. Outside the convoy attack the boat's torpedoes home on the frigate only, and the AI's boats never attack merchants. +- The boat campaign has no port choices beyond refit and quick turnaround, and no damage-control state carried over (only the overall hull damage). Outside the convoy attack the boat's torpedoes home on the frigate only, and the AI's boats never attack merchants. - The AI does not steer a boat towards a boat mission's objective. - The AI hunters do not correlate radar blips, ESM or HQ reports with the boat, and they fire no ASROC. - The periscope has one magnification and no camera; sightings carry no identification beyond the coarse class, and the stadimeter assumes a class length rather than a masthead height. diff --git a/docs/manual/manual.en.pdf b/docs/manual/manual.en.pdf index 82524690..40491242 100644 Binary files a/docs/manual/manual.en.pdf and b/docs/manual/manual.en.pdf differ diff --git a/docs/plan-uboot-stations.md b/docs/plan-uboot-stations.md index 8228d1f2..e2a23902 100644 --- a/docs/plan-uboot-stations.md +++ b/docs/plan-uboot-stations.md @@ -132,8 +132,10 @@ plan mit auf und setzte das auch um"): (uConsole auf dem Boot oder Solo-Browser als U-Boot), auf jeder Station, die kein Browser hält. Datum aus Sonar und HF/DF; Radarechos, ESM und Führungsmeldungen werden noch nicht zugeordnet, kein ASROC. -2. **Bootsmissionen und Bootskampagne:** Durchbruch, Angriff auf einen - Geleitzug, Aufklärung; baut auf Punkt 1 auf. +2. ~~**Bootsmissionen und Bootskampagne**~~ erledigt: Durchbruch und + Aufklärung in 1.3.14, Geleitzugangriff in 1.3.15 + (`src/core/boat_missions.py`), Bootskampagne mit fünf Etappen in 1.3.16 + (`src/core/boat_campaign.py`, eigene Datei `boat_campaign.json`). 3. **Angriffsrechner am Sehrohr:** Lösung aus Peilung, Stadimeter und Lage, Vorhaltewinkel für den Torpedo. 4. **Atmosphäre:** Bootsgeräusche, Wasserbomben/Detonationen, diff --git a/docs/resume.md b/docs/resume.md index dc6d5c59..46800d54 100644 --- a/docs/resume.md +++ b/docs/resume.md @@ -1621,4 +1621,4 @@ Notizen Phase 1: - Screenshots neu: `tools/capture_screenshots.py` (jetzt auch die sieben U-Boot-Stationen `uboot-*.png` und `uboot-overview.png`), `tools/capture_commander.py` (Lobby-Prüfung zählt die neun sichtbaren Fregatten-Karten statt aller Stationen). Chromium: im Container `/opt/pw-browsers/chromium-*/chrome-linux/chrome` als `chromium` in den `PATH` verlinken. - DE-README verlinkt jetzt die deutschen Bilder (`de-*.png`). - 1.3.13: `capture_screenshots.py` wärmt drei Simulationsminuten vor (`WARMUP_STEPS` x `WARMUP_STEP_S`), speichert die Editor-Vorlage `data/editor_templates/mission.json` in den temporären Nutzerordner und nimmt zusätzlich `mission-editor-detail.png` (Seed-Vorschau) auf. Die Präsentation unter `docs/presentation/` ist ein Stand von 1.1.0 und wurde nicht neu gebaut. -- 1.3.16: Selbst-Update-Neustart mit `update.clean_environment()` (ohne `_PYI_*`, `PYINSTALLER_RESET_ENVIRONMENT=1`); sonst lädt die getauschte EXE (gleicher Pfad) das gelöschte `_MEI…`-Verzeichnis der alten ("Failed to load Python DLL"). Workflow-Schritt testet den Neustart mit veralteten `_PYI_*`-Variablen. Starter zeigt `launcher.support` (Buy me a coffee, `SUPPORT_URL`). +- 1.3.17: Selbst-Update-Neustart mit `update.clean_environment()` (ohne `_PYI_*`, `PYINSTALLER_RESET_ENVIRONMENT=1`); sonst lädt die getauschte EXE (gleicher Pfad) das gelöschte `_MEI…`-Verzeichnis der alten ("Failed to load Python DLL"). Workflow-Schritt testet den Neustart mit veralteten `_PYI_*`-Variablen. Starter zeigt `launcher.support` (Buy me a coffee, `SUPPORT_URL`). diff --git a/docs/station-shortcuts.de.md b/docs/station-shortcuts.de.md index 95d6cabb..04d68694 100644 --- a/docs/station-shortcuts.de.md +++ b/docs/station-shortcuts.de.md @@ -1,4 +1,4 @@ -# U-Jagd 1.3.16 - Stations- und Tastenkürzel +# U-Jagd 1.3.17 - Stations- und Tastenkürzel Druckfassung: [`station-shortcuts.de.pdf`](station-shortcuts.de.pdf). Maßgeblich ist die implementierte lokale Bedienung. Stationsnummern und diff --git a/docs/station-shortcuts.de.pdf b/docs/station-shortcuts.de.pdf index 8b3eb8e6..9f3c5bd8 100644 Binary files a/docs/station-shortcuts.de.pdf and b/docs/station-shortcuts.de.pdf differ diff --git a/src/core/boat_campaign.py b/src/core/boat_campaign.py new file mode 100644 index 00000000..b188680e --- /dev/null +++ b/src/core/boat_campaign.py @@ -0,0 +1,189 @@ +"""Boat campaign: five linked boat missions with consequences. + +The submarine's counterpart to ``src/core/campaign.py``: its own file +(``boat_campaign.json`` beside the save slots), never inside a game save. +Between missions it carries the boat's torpedoes, its hull damage and the +captain's standing with U-boat command (reputation 0..100). After each +mission the boat calls at its base: a full refit (full torpedo load, hull +repaired) costs standing for the lost time; a quick turnaround sails on at +once with a part load by standing and the damage aboard. + +A leg is an ordinary boat mission (scenarios 5 to 7) with the uConsole on +the boat side; the carried stock and damage are put aboard the crewed boat +when the leg starts. All legs use seeds with the same ``seed % 128`` so the +real-sector world mode keeps the same sea area. +""" + +from __future__ import annotations + +import json +import os + +from src.core import config +from src.core.campaign import (REPUTATION_LOSS, REPUTATION_QUICK, REPUTATION_REFIT, + REPUTATION_RELIEVED, REPUTATION_START, REPUTATION_WIN, + RESULTS, STATUSES, _reject_constant, resupply) + +VERSION = 1 +LEGS = ("s6_aufklaerung", "s5_durchbruch", "s7_geleitzug", "s5_durchbruch", + "s7_geleitzug") +FILE_NAME = "boat_campaign.json" +STATE_FIELDS = frozenset({"version", "base_seed", "leg", "reputation", "torpedoes", + "damage", "status", "port", "history"}) +HISTORY_FIELDS = frozenset({"leg", "result"}) +TORPEDOES_MAX = 40 # above any boat's load; ``None`` is a full load +DAMAGE_CARRY_MAX = 60 # hull damage (%) a boat can sail with +# The boat's side of ``boat_debrief.outcome``: the missions it won. +WINS = ("won", "broke_through", "reported", "convoy_sunk", "escaped", "survived") + + +class BoatCampaignState: + """One boat campaign's progress and carried state.""" + + def __init__(self, base_seed: int): + self.base_seed = int(base_seed) + self.leg = 0 + self.reputation = REPUTATION_START + self.torpedoes: int | None = None # a full load + self.damage = 0 + self.status = "active" + self.port = False + self.history: list[dict] = [] + + @property + def scenario_key(self) -> str: + return LEGS[min(self.leg, len(LEGS) - 1)] + + def mission_seed(self) -> int: + """Same ``seed % 128`` (same real sector) for every leg.""" + seed = self.base_seed + 128 * self.leg + return seed if seed < 1_000_000_000 else self.base_seed + + def can_sail(self) -> bool: + return self.status == "active" and not self.port + + def quick_load(self) -> int | None: + """Torpedoes aboard after a quick turnaround (``None`` stays full).""" + if self.torpedoes is None: + return None + return min(TORPEDOES_MAX, self.torpedoes + resupply(self.reputation) // 2) + + def record(self, *, won: bool, boat_sunk: bool, torpedoes_left: int, + damage: float) -> None: + """A leg ended: standing, carried state, the base next.""" + if not self.can_sail(): + return + result = "sunk" if boat_sunk else ("won" if won else "lost") + self.history.append(dict(leg=self.leg, result=result)) + delta = REPUTATION_WIN if won else REPUTATION_LOSS + self.reputation = int(config.clamp(self.reputation + delta, 0, 100)) + self.torpedoes = int(config.clamp(torpedoes_left, 0, TORPEDOES_MAX)) + self.damage = int(config.clamp(round(damage), 0, DAMAGE_CARRY_MAX)) + if boat_sunk or self.reputation < REPUTATION_RELIEVED: + self.status = "lost" + elif self.leg >= len(LEGS) - 1: + self.status = "won" + else: + self.port = True + + def call_at_port(self, choice: str) -> bool: + """``refit`` or ``quick``; then the next leg is ready.""" + if self.status != "active" or not self.port or choice not in ("refit", "quick"): + return False + if choice == "refit": + self.torpedoes = None + self.damage = 0 + self.reputation = int(config.clamp(self.reputation + REPUTATION_REFIT, 0, 100)) + else: + self.torpedoes = self.quick_load() + self.reputation = int(config.clamp(self.reputation + REPUTATION_QUICK, 0, 100)) + self.port = False + self.leg += 1 + return True + + # --- file ---------------------------------------------------------------------- + + def serialize(self) -> dict: + return dict(version=VERSION, base_seed=self.base_seed, leg=self.leg, + reputation=self.reputation, torpedoes=self.torpedoes, + damage=self.damage, status=self.status, port=self.port, + history=[dict(row) for row in self.history]) + + @staticmethod + def valid_state(state) -> bool: + if not isinstance(state, dict) or set(state) != STATE_FIELDS: + return False + + def integer(key, low, high): + return type(state[key]) is int and low <= state[key] <= high + + if not (integer("version", VERSION, VERSION) + and integer("base_seed", 1, 999_999_999) + and integer("leg", 0, len(LEGS) - 1) + and integer("reputation", 0, 100) + and integer("damage", 0, DAMAGE_CARRY_MAX) + and (state["torpedoes"] is None or integer("torpedoes", 0, TORPEDOES_MAX))): + return False + if type(state["port"]) is not bool: + return False + if state["status"] not in STATUSES or (state["port"] and state["status"] != "active"): + return False + history = state["history"] + if not isinstance(history, list) or len(history) > len(LEGS): + return False + for index, row in enumerate(history): + if (not isinstance(row, dict) or set(row) != HISTORY_FIELDS + or type(row["leg"]) is not int or row["leg"] != index + or row["result"] not in RESULTS): + return False + played = state["leg"] + (1 if state["port"] or state["status"] != "active" else 0) + return len(history) == played + + @classmethod + def restore(cls, state) -> "BoatCampaignState": + if not cls.valid_state(state): + raise ValueError("invalid boat campaign state") + campaign = cls(state["base_seed"]) + for key in ("leg", "reputation", "torpedoes", "damage", "status", "port"): + setattr(campaign, key, state[key]) + campaign.history = [dict(row) for row in state["history"]] + return campaign + + +def campaign_path() -> str: + return os.path.join(config.SAVE_DIR, FILE_NAME) + + +def load_campaign() -> BoatCampaignState | None: + """The saved boat campaign, or ``None`` (missing, symlinked or invalid).""" + path = campaign_path() + try: + if os.path.islink(path) or os.path.islink(config.SAVE_DIR): + return None + with open(path, encoding="utf-8") as stream: + data = json.load(stream, parse_constant=_reject_constant) + return BoatCampaignState.restore(data) + except (OSError, ValueError, TypeError): + return None + + +def save_campaign(state: BoatCampaignState) -> bool: + """Atomic write beside the save slots; False leaves the old file.""" + from src.data.user_content import ContentValidationError, atomic_write_json + try: + atomic_write_json(campaign_path(), state.serialize()) + return True + except (OSError, ValueError, ContentValidationError): + return False + + +def put_aboard(sub, state: BoatCampaignState) -> None: + """The carried torpedo stock and hull damage, on the crewed boat.""" + if state.torpedoes is not None: + battery = sub.weapon_battery + if battery is not None: + battery.limit_to(state.torpedoes) + sub.torpedoes_left = battery.remaining_total + else: + sub.torpedoes_left = min(sub.torpedoes_left, state.torpedoes) + sub.damage = float(state.damage) diff --git a/src/core/game_campaign.py b/src/core/game_campaign.py index e464b1db..7e1fc0e8 100644 --- a/src/core/game_campaign.py +++ b/src/core/game_campaign.py @@ -1,16 +1,18 @@ -"""The campaign in the game: menu, leg start, carried state, port call. +"""The campaigns in the game: menu, leg start, carried state, port call. -``src/core/campaign.py`` holds the campaign and its file; this mixin -starts a leg as an ordinary scenario with the carried torpedo stock, -damage and helicopter, records the result when that mission ends and -offers the port call in the main menu's campaign screen. +``src/core/campaign.py`` holds the frigate's campaign and +``src/core/boat_campaign.py`` the boat's, each in its own file; this mixin +starts a leg as an ordinary scenario with the carried state (the frigate's +torpedo stock, damage and helicopter; the boat's torpedoes and hull +damage), records the result when that mission ends and offers the port +call in the main menu's campaign screen (``Tab`` switches frigate/boat). """ from __future__ import annotations import pygame -from src.core import campaign as campaign_model +from src.core import boat_campaign, campaign as campaign_model from src.core.i18n import message @@ -22,10 +24,41 @@ class CampaignMixin: self.campaign = campaign_model.load_campaign() return self.campaign + def _boat_campaign(self): + if getattr(self, "boat_campaign", None) is None: + self.boat_campaign = boat_campaign.load_campaign() + return self.boat_campaign + + def _menu_campaign(self): + """The campaign the campaign screen shows: the frigate's or the boat's.""" + return (self._boat_campaign() if getattr(self, "campaign_side", "frigate") == "boat" + else self._campaign()) + def new_campaign(self) -> bool: self.campaign = campaign_model.CampaignState(self.seed) return campaign_model.save_campaign(self.campaign) + def new_boat_campaign(self) -> bool: + self.boat_campaign = boat_campaign.BoatCampaignState(self.seed) + return boat_campaign.save_campaign(self.boat_campaign) + + def start_boat_campaign_leg(self) -> bool: + state = self._boat_campaign() + if state is None or not state.can_sail(): + return False + self.local_side = "uboot" + self.scenario_key = state.scenario_key + self.seed = state.mission_seed() + self.in_menu = False + self.main_menu = False + self.reset(self.seed, state.scenario_key) + boat = self.claim_opfor_sub() + if boat is not None: + boat_campaign.put_aboard(boat.sub, state) + self.campaign_mission = True + self.campaign_mission_side = "boat" + return True + def start_campaign_leg(self) -> bool: state = self._campaign() if state is None or not state.can_sail(): @@ -43,6 +76,7 @@ class CampaignMixin: if state.helo_lost: self.helo.state = "VERLOREN" self.campaign_mission = True + self.campaign_mission_side = "frigate" self.hq_msg(message("campaign.leg_brief", leg=str(state.leg + 1), legs=str(len(campaign_model.LEGS)), reputation=str(state.reputation))) @@ -53,10 +87,14 @@ class CampaignMixin: if not getattr(self, "campaign_mission", False): return self.campaign_mission = False + if getattr(self, "campaign_mission_side", "frigate") == "boat": + self._boat_campaign_leg_ended() + return state = self._campaign() if state is None: return self._campaign_leg_shown = True + self._campaign_leg_side = "frigate" board = getattr(self, "tasking", None) counts = board.counts() if board is not None and board.tasks else {} state.record( @@ -69,9 +107,28 @@ class CampaignMixin: if not campaign_model.save_campaign(state): self.flash(message("campaign.save_failed"), 4.0) + def _boat_campaign_leg_ended(self) -> None: + from src.core import boat_debrief, boat_missions + state = self._boat_campaign() + if state is None: + return + self._campaign_leg_shown = True + self._campaign_leg_side = "boat" + boat = self._opfor + sub = boat.sub if boat is not None else boat_missions.target_sub(self) + state.record( + won=boat_debrief.outcome(self, boat) in boat_campaign.WINS, + boat_sunk=sub is None or sub.sunk or sub.state == "SINKING", + torpedoes_left=int(sub.torpedoes_left) if sub is not None else 0, + damage=float(sub.damage) if sub is not None else 100.0) + if not boat_campaign.save_campaign(state): + self.flash(message("campaign.save_failed"), 4.0) + def campaign_end_line(self): """End-panel line for a finished campaign leg, else ``None``.""" - state = getattr(self, "campaign", None) + state = (getattr(self, "boat_campaign", None) + if getattr(self, "_campaign_leg_side", "frigate") == "boat" + else getattr(self, "campaign", None)) if state is None or not getattr(self, "_campaign_leg_shown", False): return None key = {"won": "campaign.end.won", "lost": "campaign.end.lost"}.get( @@ -79,15 +136,20 @@ class CampaignMixin: return message(key, reputation=str(state.reputation)) def _handle_campaign_menu_key(self, key: int) -> None: - state = self._campaign() + boat_side = getattr(self, "campaign_side", "frigate") == "boat" + state = self._menu_campaign() if key in (pygame.K_ESCAPE, pygame.K_q): self.main_menu = True self.main_menu_sel = 2 return + if key == pygame.K_TAB: + self.campaign_side = "frigate" if boat_side else "boat" + self._campaign_confirm_new = False + return confirm = getattr(self, "_campaign_confirm_new", False) if key == pygame.K_n and (state is None or state.status != "active" or confirm): self._campaign_confirm_new = False - if not self.new_campaign(): + if not (self.new_boat_campaign() if boat_side else self.new_campaign()): self.flash(message("campaign.save_failed"), 4.0) return if key == pygame.K_n: @@ -99,21 +161,31 @@ class CampaignMixin: return if state.port and key in (pygame.K_1, pygame.K_2): state.call_at_port("refit" if key == pygame.K_1 else "quick") - if not campaign_model.save_campaign(state): + saved = (boat_campaign.save_campaign(state) if boat_side + else campaign_model.save_campaign(state)) + if not saved: self.flash(message("campaign.save_failed"), 4.0) return if not state.port and key in (pygame.K_RETURN, pygame.K_SPACE): - self.local_side = "frigate" - self.start_campaign_leg() + if boat_side: + self.start_boat_campaign_leg() + else: + self.local_side = "frigate" + self.start_campaign_leg() def _draw_campaign_menu(self, center) -> None: from src.core import config from src.ui import layout - state = self._campaign() - center(self.tr("campaign.title"), 150, color=config.COLOR_WARN) + boat_side = getattr(self, "campaign_side", "frigate") == "boat" + state = self._menu_campaign() + center(self.tr("campaign.boat.title" if boat_side else "campaign.title"), 150, + color=config.COLOR_WARN) lines = [] if state is None: - lines.append(("campaign.none", config.COLOR_TEXT_DIM)) + lines.append(("campaign.boat.none" if boat_side else "campaign.none", + config.COLOR_TEXT_DIM)) + elif boat_side: + lines = self._boat_campaign_lines(state) else: lines.append((message("campaign.progress", leg=str(state.leg + 1), legs=str(len(campaign_model.LEGS)), @@ -150,3 +222,35 @@ class CampaignMixin: hint = ("campaign.confirm_new" if getattr(self, "_campaign_confirm_new", False) else "campaign.menu_hint") center(self.tr(hint), 540, color=config.COLOR_TEXT_DIM) + + def _boat_campaign_lines(self, state) -> list: + from src.core import config + torpedoes = (self.tr("campaign.boat.full_load") if state.torpedoes is None + else str(state.torpedoes)) + lines = [ + (message("campaign.progress", leg=str(state.leg + 1), + legs=str(len(boat_campaign.LEGS)), + scenario=self.tr("scenario." + config.SCENARIO_NAMES[state.scenario_key] + + ".title")), config.COLOR_TEXT), + (message("campaign.boat.standing", reputation=str(state.reputation), + torpedoes=torpedoes), config.COLOR_TEXT), + (message("campaign.boat.condition", damage=str(state.damage)), + config.COLOR_TEXT_DIM), + ] + results = " ".join(self.tr("campaign.result." + row["result"]) + for row in state.history) + if results: + lines.append((message("campaign.history", results=results), config.COLOR_TEXT_DIM)) + if state.status == "won": + lines.append(("campaign.status_won", config.COLOR_OK)) + elif state.status == "lost": + lines.append(("campaign.boat.status_lost", config.COLOR_DANGER)) + elif state.port: + quick = state.quick_load() + lines.append(("campaign.boat.port_refit", config.COLOR_WARN)) + lines.append((message("campaign.boat.port_quick", torpedoes=( + self.tr("campaign.boat.full_load") if quick is None else str(quick)), + damage=str(state.damage)), config.COLOR_WARN)) + else: + lines.append(("campaign.boat.sail_hint", config.COLOR_OK)) + return lines diff --git a/src/core/game_events.py b/src/core/game_events.py index c6cdfc36..02c88528 100644 --- a/src/core/game_events.py +++ b/src/core/game_events.py @@ -1675,6 +1675,7 @@ class EventMixin: self.main_menu = False self.menu_screen = "campaign" self.menu_sel = 0 + self.campaign_side = "boat" if self.local_side == "uboot" else "frigate" elif action == "load": self._open_administration("load") elif action == "mission_editor": diff --git a/src/core/version.py b/src/core/version.py index 31629f78..fe37b498 100644 --- a/src/core/version.py +++ b/src/core/version.py @@ -4,7 +4,7 @@ This module is deliberately dependency-free because setuptools imports the version while building the project. """ -APP_VERSION = "1.3.16" +APP_VERSION = "1.3.17" SAVE_VERSION = 23 SAVE_SCHEMA = "u-jagd-save-v23" SPLASH_TEXT = ( diff --git a/src/ui/uboot_view.py b/src/ui/uboot_view.py index b123f5a4..0567f769 100644 --- a/src/ui/uboot_view.py +++ b/src/ui/uboot_view.py @@ -1147,15 +1147,21 @@ _END_WINS = ("uboot.end.won", "uboot.end.escaped", "uboot.end.survived", def draw_end_panel(game, boat) -> None: s = game.screen - rect = pygame.Rect(340, 250, 600, 150) + campaign = game.campaign_end_line() + extra = 36 if campaign is not None else 0 + rect = pygame.Rect(340, 250, 600, 150 + extra) pygame.draw.rect(s, config.COLOR_OVERLAY_BG, rect) pygame.draw.rect(s, config.COLOR_WARN, rect, 2) key = end_text(game, boat) layout.blit_line(s, key, (rect.x + 16, rect.y + 20, rect.w - 32, 40), config.COLOR_OK if key in _END_WINS else config.COLOR_WARN, size=28, align="center") - layout.blit_block(s, "uboot.end.hint", rect.x + 16, rect.y + 80, rect.w - 32, 56, - config.COLOR_TEXT_DIM, size=16, align="center") + if campaign is not None: + # A boat campaign leg: the standing and what comes next. + layout.blit_line(s, campaign, (rect.x + 16, rect.y + 72, rect.w - 32, 28), + config.COLOR_WARN, size=16, align="center") + layout.blit_block(s, "uboot.end.hint", rect.x + 16, rect.y + 80 + extra, rect.w - 32, + 56, config.COLOR_TEXT_DIM, size=16, align="center") def draw(game) -> None: diff --git a/src/weapons/asw.py b/src/weapons/asw.py index 97d4ff9b..87416334 100644 --- a/src/weapons/asw.py +++ b/src/weapons/asw.py @@ -308,6 +308,28 @@ class WeaponBattery: tube.loading_weapon_key = weapon_key tube.reload_remaining_s = self.reload_s + def limit_to(self, count: int) -> None: + """Keep at most ``count`` weapons aboard (a carried campaign stock): + stowed weapons go first, then tubes still loading, then loaded ones.""" + count = max(0, int(count)) + for magazine in sorted(self.magazines.values(), key=lambda item: item.key, + reverse=True): + excess = self.remaining_total - count + if excess <= 0: + return + taken = min(excess, magazine.stowed) + magazine.stowed -= taken + for tube in reversed(self.tubes): + if self.remaining_total <= count: + return + if tube.loading_weapon_key is not None: + tube.loading_weapon_key = None + tube.reload_remaining_s = 0.0 + for tube in reversed(self.tubes): + if self.remaining_total <= count: + return + tube.loaded_weapon_key = None + def replenish(self) -> None: """Replenishment at sea: every magazine back to its mission load (weapons in the tubes count against their own type).""" diff --git a/tests/test_boat_campaign.py b/tests/test_boat_campaign.py new file mode 100644 index 00000000..ffcb9194 --- /dev/null +++ b/tests/test_boat_campaign.py @@ -0,0 +1,137 @@ +"""The boat campaign: boat missions linked with carried torpedoes, hull and standing.""" + +import copy +from dataclasses import replace +import json +import os + +import pygame + +from src.core import boat_campaign, config +from src.core.boat_campaign import BoatCampaignState +from src.core.game import Game +from src.ui import layout + + +def _menu_game(seed=11, language="en"): + return Game(seed=seed, start_menu=True, audio_enabled=False, language=language) + + +def _key(game, key): + game.handle_event(pygame.event.Event(pygame.KEYDOWN, key=key, mod=0, unicode="")) + + +def test_legs_are_boat_missions_in_one_sea_area(): + assert all(config.SCENARIOS[key].get("boat") for key in boat_campaign.LEGS) + state = BoatCampaignState(1234) + seeds = [] + for leg in range(len(boat_campaign.LEGS)): + state.leg = leg + seeds.append(state.mission_seed()) + assert {seed % 128 for seed in seeds} == {1234 % 128} and len(set(seeds)) == len(seeds) + + +def test_results_standing_and_the_base(): + state = BoatCampaignState(1234) + assert state.torpedoes is None and state.damage == 0 + state.record(won=True, boat_sunk=False, torpedoes_left=3, damage=82.4) + assert state.port and state.reputation == 65 + assert state.torpedoes == 3 and state.damage == boat_campaign.DAMAGE_CARRY_MAX + quick = copy.deepcopy(state) + assert quick.call_at_port("quick") and quick.leg == 1 + assert quick.torpedoes == 3 + boat_campaign.resupply(65) // 2 + assert quick.damage == boat_campaign.DAMAGE_CARRY_MAX and quick.reputation == 68 + assert state.call_at_port("refit") + assert state.torpedoes is None and state.damage == 0 and state.reputation == 60 + assert BoatCampaignState.restore(state.serialize()).serialize() == state.serialize() + for key, value in (("leg", 9), ("reputation", 101), ("damage", 61), ("torpedoes", -1), + ("torpedoes", 2.0), ("status", "draw"), ("history", [])): + assert not BoatCampaignState.valid_state(dict(state.serialize(), **{key: value})) + sunk = BoatCampaignState(5) + sunk.record(won=False, boat_sunk=True, torpedoes_left=0, damage=100.0) + assert sunk.status == "lost" and not sunk.port and sunk.history[0]["result"] == "sunk" + last = BoatCampaignState(5) + last.leg = len(boat_campaign.LEGS) - 1 + last.history = [dict(leg=n, result="won") for n in range(last.leg)] + last.record(won=True, boat_sunk=False, torpedoes_left=1, damage=0.0) + assert last.status == "won" + + +def test_the_file_is_atomic_and_rejects_symlinks(tmp_path, monkeypatch): + monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path)) + assert boat_campaign.load_campaign() is None + state = BoatCampaignState(77) + assert boat_campaign.save_campaign(state) + assert boat_campaign.load_campaign().serialize() == state.serialize() + path = tmp_path / boat_campaign.FILE_NAME + target = tmp_path / "elsewhere.json" + os.replace(path, target) + os.symlink(target, path) + assert boat_campaign.load_campaign() is None + + +def test_a_leg_puts_the_carried_state_aboard_and_records_the_result(tmp_path, monkeypatch): + monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path)) + game = _menu_game(seed=300) + assert game.new_boat_campaign() + state = game.boat_campaign + state.torpedoes, state.damage = 3, 25 + assert game.start_boat_campaign_leg() + assert game.local_side == "uboot" and game.scenario_key == boat_campaign.LEGS[0] + sub = game.opfor.sub + assert sub.torpedoes_left == 3 and sub.weapon_battery.remaining_total == 3 + assert sub.damage == 25.0 and game.campaign_mission + game._update(0.05) + assert game.opfor.sub is sub + # A slot saved on a leg loads as a plain mission. + other = _menu_game() + assert other._load_save_data(json.loads(json.dumps(game.save_state()))) + assert not other.campaign_mission + game._end_mission(False, {"__u_jagd_i18n__": "end.reason.boat_reported"}) + saved = boat_campaign.load_campaign() + assert saved.port and saved.history[0]["result"] == "won" + assert saved.torpedoes == 3 and saved.damage == 25 + # The frigate's campaign is untouched. + assert game._campaign() is None + for language in ("en", "de"): + game.preferences = replace(game.preferences, language=language) + layout.configure_for(game) + game.draw() + + +def test_a_sunk_boat_ends_the_boat_campaign(tmp_path, monkeypatch): + monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path)) + game = _menu_game(seed=301) + assert game.new_boat_campaign() and game.start_boat_campaign_leg() + game.opfor.sub.sunk = True + game._check_mission_end() + assert game.mission_result == "SIEG" + assert boat_campaign.load_campaign().status == "lost" + + +def test_the_campaign_screen_switches_to_the_boat(tmp_path, monkeypatch): + monkeypatch.setattr(config, "SAVE_DIR", str(tmp_path)) + game = _menu_game(seed=400) + game.main_menu_sel = 2 + _key(game, pygame.K_RETURN) + assert game.menu_screen == "campaign" and game.campaign_side == "frigate" + _key(game, pygame.K_TAB) + assert game.campaign_side == "boat" + game.draw() + _key(game, pygame.K_n) + assert game.boat_campaign is not None and game._campaign() is None + game.draw() + _key(game, pygame.K_RETURN) + assert game.campaign_mission and game.local_side == "uboot" + assert game.scenario_key == boat_campaign.LEGS[0] + game._end_mission(True, "test") # the frigate held out + assert game.boat_campaign.port and game.boat_campaign.history[0]["result"] == "lost" + game.draw() + _key(game, pygame.K_m) + game.main_menu_sel = 2 + _key(game, pygame.K_RETURN) + assert game.campaign_side == "boat" + game.draw() + _key(game, pygame.K_1) + assert game.boat_campaign.leg == 1 and game.boat_campaign.torpedoes is None + assert boat_campaign.load_campaign().leg == 1 diff --git a/tests/test_packaging.py b/tests/test_packaging.py index 7d9aebb5..f835ebd5 100644 --- a/tests/test_packaging.py +++ b/tests/test_packaging.py @@ -85,7 +85,7 @@ def test_source_and_wheel_contain_editor_templates(tmp_path): (ROOT / "data/contact_analysis" / name).read_bytes() assert any(name.endswith(".dist-info/licenses/THIRD_PARTY_NOTICES.md") for name in wheel_names) - assert any(name.endswith("-1.3.16.dist-info/METADATA") for name in wheel_names) + assert any(name.endswith("-1.3.17.dist-info/METADATA") for name in wheel_names) source = next(tmp_path.glob("u_jagd-*.tar.gz")) with tarfile.open(source) as archive: @@ -137,7 +137,7 @@ def test_source_and_wheel_contain_editor_templates(tmp_path): [sys.executable, "-c", "from importlib import resources; " "assert resources.files('data.editor_templates').joinpath('mission.json').is_file(); " - "from src.core.version import APP_VERSION; assert APP_VERSION == '1.3.16'; " + "from src.core.version import APP_VERSION; assert APP_VERSION == '1.3.17'; " "from src.commander.server import CommanderServer; " "server=CommanderServer(); server.start('127.0.0.1',0); server.stop(); " "from src.core import manual; page=manual.html_page('de'); assert 'station-sonar' in page; " diff --git a/tests/test_startup.py b/tests/test_startup.py index 17cfb1b9..f10e69d2 100644 --- a/tests/test_startup.py +++ b/tests/test_startup.py @@ -14,9 +14,9 @@ from src.world.real_coast import sector_for_seed def test_release_version_and_exact_splash_text(): - assert APP_VERSION == "1.3.16" + assert APP_VERSION == "1.3.17" assert SPLASH_TEXT == ( - "Anti Sub Marine Warfare on uConsole by Dominik Bornhäußer Version 1.3.16" + "Anti Sub Marine Warfare on uConsole by Dominik Bornhäußer Version 1.3.17" )