Annual general meeting and change of club

At the end of a season three groups of members vote on a human manager.
Below half of the votes he has to take over one of up to seven interested
clubs; the same list lets a manager leave on his own from the manager page.
The meeting is shown as a needle that swings between red and green and
comes to rest on the result.

Engine: assembly_vote, club_offers, change_club; read "assembly", command
manager.clubChange, field assembly of session.advance; saved in
state/modern.json. Dismissals are always on until the options offer them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
MichaelandClaude Fable 5.2 committed 2026-11-17 12:58:36 +01:00
1 parent 811edfa900
commit a2b9770d81
24 files changed
+1016 -7

No files matched your search

+3
View File
@@ -1230,6 +1230,9 @@ add_test(NAME quit_confirmation_unit_tests COMMAND quit_confirmation_unit_tests)
add_executable(modern_camp_tests tests/modern_camp_tests.cpp)
target_link_libraries(modern_camp_tests PRIVATE bmh_season_modern)
add_test(NAME modern_camp_tests COMMAND modern_camp_tests)
add_executable(modern_assembly_tests tests/modern_assembly_tests.cpp)
target_link_libraries(modern_assembly_tests PRIVATE bmh_season_modern)
add_test(NAME modern_assembly_tests COMMAND modern_assembly_tests)
add_executable(modern_almanac_tests tests/modern_almanac_tests.cpp)
target_link_libraries(modern_almanac_tests PRIVATE bmh_modern_content)
add_test(NAME modern_almanac_tests COMMAND modern_almanac_tests)
+16
View File
@@ -1066,3 +1066,19 @@ body.midnight .cp-map-name,body.matchday .cp-map-name {color:#f0ece2;font-effect
.lp-shape-pitch {display:block;flex:none;width:60dp;height:80dp;}
.lp-shape-name {display:block;font-family:Display;font-weight:normal;font-size:48dp;line-height:54dp;}
.lp-shape-card[disabled] {opacity:0.45;}
.as-vote {display:block;margin:0 0 27dp;}
.as-row {display:flex;align-items:center;gap:22dp;padding:12dp 0;}
.as-name {display:block;flex:none;width:300dp;font-size:31dp;color:var(--p-text);}
.as-track {display:block;flex:1;height:22dp;border-radius:11dp;background-color:var(--p-div);overflow:hidden;}
.as-fill {display:block;height:22dp;border-radius:11dp;background-color:var(--p-s6);}
.as-fill.low {background-color:var(--p-a5);}
.as-value {display:block;flex:none;width:110dp;text-align:right;font-size:31dp;color:var(--p-text);}
.as-result {display:flex;align-items:baseline;justify-content:center;gap:27dp;margin:22dp 0 0;padding:22dp 0 0;border-top:2dp var(--p-div);}
.as-result strong {font-family:Display;font-weight:normal;font-size:58dp;color:var(--p-s6);}
.as-result.low strong {color:var(--p-a5);}
.as-result span {font-size:31dp;color:var(--p-n7);}
body .popup-box p.as-verdict {margin:14dp 0 0;text-align:center;font-size:31dp;}
.as-gauge {display:block;position:relative;width:640dp;height:358dp;margin:0 auto;}
.as-needle {display:block;position:absolute;left:314dp;top:76dp;width:12dp;height:244dp;border-radius:6dp;background-color:var(--p-text);transform-origin:50% 100%;transform:rotate(0deg);}
.as-ends {display:flex;justify-content:space-between;width:640dp;margin:6dp auto 18dp;font-size:27dp;color:var(--p-n7);}
.as-ends span {display:block;}
+3
View File
@@ -32,8 +32,11 @@ describe deliberate changes; they are not a list of every known compatibility li
- [src/modern/app/modern_session.cpp](../src/modern/app/modern_session.cpp): supports designated set-piece record initialization and validation.
- [src/modern/app/modern_session.cpp](../src/modern/app/modern_session.cpp): native saves do not consume gameplay randomness for encryption.
- [src/modern/content/world_expand.cpp](../src/modern/content/world_expand.cpp): Modern worlds have league sizes, clubs and players of their own; players whose nation has no single-byte nationality code carry a substitute foreign code.
- [src/modern/game/assembly.cpp](../src/modern/game/assembly.cpp): Modern holds an annual general meeting at the end of a season; three groups of members vote on a human manager, and below half of the votes he has to take over another club.
- [src/modern/game/assembly.cpp](../src/modern/game/assembly.cpp): in Modern up to seven German clubs with a clearly weaker eleven are interested in a human manager; the list is drawn by a generator of its own and stays for a fortnight.
- [src/modern/game/career.cpp](../src/modern/game/career.cpp): in a Modern world a club's place in the strength band of its league follows the data set's ranking of the squads instead of the table place, and its players keep their relative values (balance.md).
- [src/modern/game/career.cpp](../src/modern/game/career.cpp): skips reserved calendar positions when assigning a joining manager to a club.
- [src/modern/game/career.cpp](../src/modern/game/career.cpp): in Modern a human manager can change to an interested club; he starts there as a manager who joins a running game, with the cash the club offers and without his funds, shares and loans.
- [src/modern/app/modern_session.cpp](../src/modern/app/modern_session.cpp): in Modern a new manager's assistant adapts the attitude to the score (as the computer clubs do) until the manager sets it himself; Classic starts at the most defensive attitude for whole matches.
- [src/modern/game/career.cpp](../src/modern/game/career.cpp): retains an existing Modern club's league slot when a human joins, preserving its played results.
- [src/modern/game/career.hpp](../src/modern/game/career.hpp): uses the supported player-generation ranges and excludes reserved calendar positions when assigning managers.
+1
View File
@@ -11,6 +11,7 @@ Grundlage ist der [Engine-Split](../ENGINE_SPLIT.md); die Oberfläche ist in
| [Phasen](phasen.md) | Arbeitsschritte M0–M7 mit Abnahmekriterien |
| [Befund](befund.md) | Feste Classic-Größen im Code, die Modern auflösen muss |
| [Trainingslager](trainingslager.md) | Katalog, Preis, Wirkung und die neue 6-Sterne-Stufe |
| [Jahreshauptversammlung](hauptversammlung.md) | Abstimmung am Saisonende, interessierte Vereine, Vereinswechsel |
| [Datenformat](datenformat.md) | **Formatänderungen für Engine und Editor** (F1–F8) |
| [Agentenregeln](AGENTS.md) | Arbeitsregeln für diesen Bereich |
+143
View File
@@ -0,0 +1,143 @@
# Jahreshauptversammlung und Vereinswechsel · Modern-Engine
Stand: 17. November 2026. Zwei zusammengehörige Modern-Regeln, die Classic nicht hat. Vorbild
ist ein späterer Teil der Reihe; übernommen sind die Regeln, nicht dessen Texte, Bilder oder
Code. Wo das Vorbild unklar ist oder Größen nutzt, die es hier nicht gibt, steht unten, was
stattdessen gilt.
## Jahreshauptversammlung
Am Saisonende (Schreibtisch „Saisonende“, vor dem Saisonwechsel) stimmen drei Gruppen der
Mitglieder über jeden menschlichen Manager eines Ligavereins ab. Der Bundestrainer am
Schreibtisch der Nationalmannschaft wird nicht befragt.
| Gruppe | Zustimmung in Prozent |
|---|---|
| Sportliche Leitung | `(2 × Kreditwürdigkeit + 4 × p + Liga-Bewertung / 55) / 7`, mit `p = 3 × (Platz zuvor − Platz jetzt) + 50 + 30 × Pokal`, auf 0–100 begrenzt |
| Kassenprüfer | `(Vermögen − Vermögen zuvor) / 30 000 + 50`, auf 0–100 begrenzt; bei mehr als 1 Mio. € auf dem Konto nur 85 % davon |
| Fans | `(letzte Bewertung / 55 + 2 × Ansehen) / 3` |
- Jede Gruppe erhält danach 10 Punkte dazu (höchstens 100). Das Ergebnis ist der Mittelwert
der drei als Ja-Anteil. Ab 50 % ist der Manager bestätigt, darunter abgewählt.
- **Platz** zählt über alle Ligen: erster Platz der ersten Liga zuerst. **Pokal**: 2 für einen
gewonnenen Pokal der Saison, 1 für ein verlorenes Finale, sonst 0; Hallenturniere zählen nicht.
- **Vermögen**: Konto bis höchstens 1 Mio. €, dazu Festgeld, Fonds und Aktien zum Tageskurs,
abzüglich der Kredite; zusammen höchstens 2 Mio. €.
- Kreditwürdigkeit ist Satz +0x26f, Ansehen +0x211, die Bewertungen sind die Worte +0x8b2
und +0x8b4 der sechs Managerbewertungen.
- Verglichen wird mit dem Stand der letzten Abstimmung. Wer noch keine hinter sich hat, wird
mit dem Stand beim ersten Anstoß verglichen: sein Vermögen von da und ein Platz im
Mittelfeld seiner Liga (Platz 10). Dasselbe gilt nach einem Vereinswechsel.
- Ein Manager mit lauter mittleren Werten kommt auf 54 / 60 / 46 und 53 % Ja. Die Abwahl
braucht also deutlich schlechte Werte.
**Abwahl.** Ist der Manager abgewählt und sind Rauswürfe eingeschaltet
(`ModernState::dismissals`, derzeit immer an; ein Schalter in den Optionen folgt), muss er vor
dem Saisonwechsel einen der interessierten Vereine übernehmen. Sind sie ausgeschaltet, bleibt
die Abwahl ohne Folgen.
### Abweichungen vom Vorbild
- **Richtung des Platzvergleichs:** Im Vorbild ist offen, wie der Platz eingeht. Hier hebt
eine Verbesserung die Zustimmung.
- **Pokal:** eigene Einteilung (siehe oben), weil die Stufen des Vorbilds nicht belegt sind.
- **Zuschläge** für Prämien, Halbzeitansprache, zweites Trainingslager und Topzuschlag
entfallen; diese Größen gibt es hier nicht.
- **Gleichstand:** Bei genau 50 % ist der Manager bestätigt. Das Vorbild würfelt.
- **Kein Zufall:** Die Abstimmung zieht keine Zahl aus den Generatoren des Spiels. Die
Auszählung als Animation ist Sache der Oberfläche.
- Das Ansehen wird vor der Abstimmung nicht neu berechnet; es gilt der gespeicherte Wert.
## Interessierte Vereine
Bis zu sieben deutsche Ligavereine, die kein Mensch führt, wollen den Manager verpflichten.
```
eigen = Schnitt(eigene Elf) + Ansehen / 20 + Kreditwürdigkeit / 10 − 35
erster Kandidat: einer der letzten zehn deutschen Vereine
bis zu 10 Durchgänge:
wert = Schnitt(Elf des Kandidaten) + Zufall(0–10) + 5
selten ein Abschlag von 10 (Kreditwürdigkeit über 80) oder 30 (über 90)
kasse = 20 000 × Zufall(0–300) − 3 000 000
ist kasse über 100 000: dazu 100 000 × Zufall(0–10) + 1000 × Zufall(0–500)
auf der leichtesten Stufe: kasse = 50 000 000
eigen > wert oder Liste leer: Kandidat mit dieser Kasse aufnehmen
Liste voll (7): Ende
nächster Kandidat: ein beliebiger deutscher Verein, der noch nicht auf der Liste steht
mit Wahrscheinlichkeit 1/5: Ende
```
- `Schnitt` ist `team_average` über Kondition, Technik, Form und Moral der aufgestellten Elf.
- Der erste Kandidat wird immer aufgenommen; die Liste ist nie leer. Alle weiteren haben
eine deutlich schwächere Elf. Der Vereinswechsel ist ein Neuanfang weiter unten, kein
Aufstieg zu einem größeren Verein.
- Die Liste hat einen eigenen Zufallsgenerator, dessen Startwert aus Karriere, Manager und
dem Zwei-Wochen-Abschnitt des Datums folgt. Sie bleibt zwei Wochen gleich, und das Ansehen
der Liste verändert den Spielverlauf nicht. Es braucht kein Feld im Spielstand.
### Abweichungen vom Vorbild
- Der Vergleich `eigen > wert` ist vorzeichenbehaftet. Im Vorbild gilt bei sehr schwacher
eigener Elf durch einen vorzeichenlosen Vergleich jeder Verein als interessiert.
- Wertpapiere und Aktien, die ein Verein des Vorbilds mitbringt, werden hier bar ausgezahlt.
- Der Startwert der Liste stammt nicht aus dem Spielgenerator, sondern aus dem Datum.
## Vereinswechsel
`modern::change_club` (`src/modern/game/career.cpp`). Der Manager übernimmt einen Verein der
Liste, freiwillig oder nach der Abwahl:
1. Sein Privatvermögen bleibt zurück: Fonds, Aktien und alle fünf Kredite verfallen. Was ihm
ein Mitspieler geliehen hat, erhält dieser in Höhe des noch nicht getilgten Darlehens zurück.
2. Der alte Verein wird wieder ein Computerverein; seine Verkäufe, Gebote und Leihen als
Menschenverein enden wie beim Beitritt eines Managers.
3. Der Managersatz wird geleert. Es bleiben Name, Porträt und das Kennzeichen des
Bundestrainers. Toto-Schein und ein wartendes Sponsorenangebot verfallen.
4. Der Satz wird für den neuen Verein eingerichtet wie für einen Manager, der einem laufenden
Spiel beitritt (`equip_manager`, die zweite Hälfte von `career_add_manager`): Stadion nach
Liga, Eintrittspreis, Trainingsplan, Bewertungen, Kreditrahmen, Verträge für den ganzen
Kader, automatische Aufstellung.
5. Kontostand und Saisonanfangsstand sind die Kasse des Angebots.
Die Vereine tauschen keine Plätze, und die Spieler behalten ihre Werte. Der Wechsel zieht nur
aus dem Watcom-Generator (Stadion, Verträge).
### Abweichungen vom Vorbild
- Alle Kredite verfallen. Im Vorbild bleibt ein Teil stehen, vermutlich ein Versehen.
- Kreditwürdigkeit und Bewertungen beginnen wie bei einem neuen Manager (50, Mitte), nicht bei 0.
- Der Wechsel ist jederzeit am Schreibtisch möglich, nicht nur in einem Spielmodus.
- Es gibt eine Rückfrage statt dreier.
## Speichern
`state/modern.json` erhält zwei optionale Felder; ältere Stände laden ohne sie:
- `assembly`: je Managerplatz `{assets, place, voted_season}`,
- `dismissals`: ob eine Abwahl zum Wechsel zwingt.
Das OBW-Format des Datensatzes ändert sich nicht.
## Anbindung
Siehe [UI-Anbindung](ui-anbindung.md): Read `assembly`, Befehl `manager.clubChange` und das
Feld `assembly` von `session.advance`.
## Prüfung
- `modern_assembly_tests` (ohne Spieldaten): die drei Wertungen am mittleren Manager, Abwahl,
Abzug für gehortetes Geld, Deckel des Vermögens, Ausgangswerte, und die Liste: ein bis sieben
Vereine, der erste aus den letzten zehn, keine Wiederholung, gleich beim erneuten Lesen,
wechselnd über die Wochen, nur der eine sichere Verein bei schwacher Elf, 50 Mio. auf Stufe 0.
- `modern_ui_contract_tests` (mit Spieldaten): Read, Ablehnung ohne Bestätigung und für einen
Verein außerhalb der Liste, Wechsel, Kasse, Aufstellung und drei Anstöße beim neuen Verein.
## Offen
- Schalter für Rauswürfe in den Optionen.
- Nachrichten zum Wechsel und zur Abstimmung im Posteingang.
- Aufgeben bei mehreren Menschen ist weiter nicht unterstützt; der Wechsel braucht es nicht,
weil der Manager seinen Platz behält.
- Wechselt ein Manager an einem Spieltag, spielt der alte Verein die schon angesetzte Partie
ohne ihn; die Kopfzeile nennt bis zum Anstoß noch den alten Gegner.
- Kein Langlauf über mehrere Saisons mit Abwahl gemessen.
+3
View File
@@ -46,6 +46,7 @@ Revision kommt vom Aufrufer (Konsole bzw. AppController), der Read ändert nicht
| `sponsor` | das Exklusiv-Sponsor-Angebot aus einem Trainingslager und ein vorgemerkter Vertrag (`monthly` als `Money`; `asset: null`, siehe [Trainingslager](trainingslager.md)) |
| `bank` | Konto, Festgeld, Kreditrahmen, Anlagen (alles `Money`), die 12 Aktien (Kurs, Vorkurs, Bestand, bezahlt, Höchstkauf, 30 Kurse Verlauf) und die angebotenen Fonds; `credit` verweist auf den Read `credit`, der Aktientipp zieht Zufall und kommt als `quote.request` |
| `credit` | der Kreditdialog (`lenderId` `bank` oder die Manager-ID eines anderen Menschen): `saved` (Darlehen, Gesamtbetrag, Rate, Laufzeit, vergangene Monate, Zahlungen), `fields` (acht Felder mit `field`, `label`, `value`, `editable`, `min`, `max`; Werte in ganzen Euro bzw. Monaten), `fees`, `refund`, `principalPaid` (`Money`). Optional `edits` [{field, value}] als Vorschau, nichts wird gebucht; Fehler `unknown_lender`, `credit_unavailable`, `invalid_credit_edit` |
| `assembly` | die [Jahreshauptversammlung](hauptversammlung.md) und die interessierten Vereine: `available` (false am Schreibtisch des Bundestrainers), `due` (am Schreibtisch „Saisonende“, solange in dieser Saison nicht abgestimmt ist), `dismissals`, `vote {sport, finance, supporters, yes, confirmed}` (Prozent), `club` und `offers[]` je mit `teamId`, `name`, `league`, `leagueIndex`, `strength` (Schnitt der Elf), `position`; Angebote zusätzlich `cash` (`Money`). Rein lesend, zieht keine Zufallszahl |
| `postmatch` | das Nachspiel des letzten `session.advance` (auch am Bundestrainer-Schreibtisch): `steps` (`results`, `report`, `team_of_the_day`, `overview`, `table` je mit `available`), `matches` (alle Spiele des Anstoßes im Almanach-Format), `reportMatchIds` (Spiele menschlicher Manager), `teamOfTheDay` (die Sportschau-Elf der Engine je Wettbewerb mit Spieler, Verein, Wertung; nur mit der Sportschau-Option der EXE, sonst leer und `team_of_the_day` nicht verfügbar), `tables` (die aktuellen Tabellen der Ligen des Spieltags). Rückblick und Abspielen ändern nichts; weiter geht es mit `session.advance` |
Fehler: `unknown_read`, `manager_not_active`, `no_active_manager`, `unknown_team`.
@@ -91,6 +92,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| `fixture.reschedule` | `matchId`, `date`; oder `action: undo`, `date` | verlegt eine eigene Ligapartie bzw. nimmt die Verlegung zurück; Fehler `invalid_day`, `day_full`, `team_clash`, `no_free_slot`, `no_moved_match` |
| `environment.commit` | `itemId`, `level` 0–6 | setzt ein Monatsbudget des Umfelds (keine Sofortbuchung, kein Zufall); unverändert: `outcome: no_change`; Fehler `environment_refused` |
| `manager.resign.commit` | `confirmed: true` | Aufgeben (neu in Modern, das Original kennt kein Aussteigen). Spielt nur ein Mensch (oder ist er der letzte), endet das Spiel wie mit dem Ablauf der festgelegten Dauer: die Highscore-Tabelle wird fortgeschrieben und angezeigt (der Hook der Saisonwende, erst Aktualisierung, dann Anzeige), `outcome: career_ended`, `ownershipChange` mit `archivedIdentity` (Manager `control: archived`, `status: resigned`, Amtszeiten mit `until` und `endReason: resigned`), `terminationReason: last_human_resigned`; danach antwortet jeder Befehl `career_ended`. Beim Ablauf der Dauer sind die Manager `retired`, die Amtszeiten enden mit `career_end`. Mit weiteren Menschen soll der Computer den Verein übernehmen; das braucht das Nachrücken aller Managertabellen und folgt (`resign_not_supported_yet`). Fehler `confirmation_required` |
| `manager.clubChange` | `teamId`, `confirmed: true` | der Manager wechselt zu einem der interessierten Vereine des Reads `assembly` und beginnt dort mit dessen Kasse ([Regeln](hauptversammlung.md)). Fehler: `confirmation_required`, `not_at_desk`, `no_club` (Bundestrainer), `club_change_refused` (Verein nicht auf der Liste) |
| `toto.submit` | `stake` (`Money` je Spalte), `columns` (bis 6 Spalten mit 11 Tipps: 1 Heim, 0 Unentschieden, 2 Auswärts) | gibt den Tippschein ab; Fehler `toto_refused` (z. B. kein offener Schein, Einsatzgrenzen, doppelte Spalte) |
| `sponsor.answer` | `accept` | Antwort auf das Exklusiv-Sponsor-Angebot: beginnt sofort, wird vorgemerkt oder abgelehnt |
| `quote.request` (Stadion) | `kind: periphery`, `objectId`; oder `kind: facility`, `facilityId`, `increment` 1–3; oder `kind: block`, `blockId` (`block:a`–`block:h`), `places` (Ziel insgesamt), optional `seats`, `roof` | öffnet den Stadion-Dialog und holt das Angebot der Baufirma bzw. wählt Anlage und Stufen bzw. stellt den Tribünenausbau zusammen (Plätze, Sitzplätze, Dach; vorhandene Ausstattung bleibt; Angebot mit Aufschlüsselung Plätze/Sitze/Dach); `offer_pending`. Der Dialog bleibt offen (andere Schreibtisch-Einstellungen sind bis dahin gesperrt, `quote_open` für ein zweites Angebot) |
@@ -106,6 +108,7 @@ Die UI ruft diese über `DataSource::read_almanac` und `read_statistics` direkt
| `news.update` | `messageId`, `action` `read`/`unread`/`archive`/`trash`/`restore` | eine Nachricht des eigenen Postfachs: gelesen und Papierkorb sind Markierungen der Oberfläche (im Spielstand, `news_marks` je Manager; die Nachricht bleibt im Postfach des Originals, `restore` holt sie zurück), `archive` ist das „Behalten“ des Originals (eine behaltene Nachricht wird bei vollem Postfach nicht verdrängt), `restore` gibt sie wieder frei. Endgültiges Löschen bietet die Schnittstelle nicht an. Unverändert: `no_change`; Fehler `unknown_message` |
| `lineup.commit` | `order`: Spieler-IDs in der gewünschten Reihenfolge | öffnet die Aufstellung wie am Schreibtisch und tauscht die Zeilen; Fehler `unknown_player`, `lineup_refused` (z. B. Verletzte, Ausländerregel) |
| `session.advance` (Zusatz) | `transferOffers {playerId: {accept: 0–3} \| {action: "decline"}}` | die Antwort des Verkäufers auf die Gebote für einen Spieler, den er auf die Transferliste gesetzt hat (Stichtag der Woche). Gefragt wird nur, wer das Feld sendet (auch leer); ohne das Feld läuft der Anstoß wie bisher und alle Gebote an menschliche Verkäufer verfallen. Ohne Antwort wird der Lauf zurückgenommen und `decision_pending` mit `args {decision: "transfer_offers", playerId, name, sellerManagerId, askingFee, offers [{index, teamId, fee, monthlySalary, months, loan, eligible}]}` gemeldet; die Oberfläche fragt und sendet den Anstoß erneut |
| `session.advance` (Zusatz) | `assembly {} \| {seen: true} \| {seen: true, teamId}` | die [Jahreshauptversammlung](hauptversammlung.md) am Schreibtisch „Saisonende“. Gefragt wird nur, wer das Feld sendet: mit `{}` wird der Lauf zurückgenommen und `decision_pending` mit `args {decision: "assembly", …}` gemeldet (Inhalt wie der Read `assembly`); mit `seen: true` gilt die Abstimmung als gezeigt. Ist der Manager abgewählt und sind Rauswürfe an, braucht es zusätzlich `teamId` eines interessierten Vereins, sonst erneut `decision_pending`; ein anderer Verein gibt `club_change_refused`. Ohne das Feld wird still abgestimmt und niemand muss gehen |
| `transfer.submit` (Abwerben) | `action: "poach"`, `playerId` · `action: "poachOffer"`, `fee`, `monthlySalary`, `years` 1–4 · `action: "poachCancel"` | zweistufig wie im Original: `poach` prüft, fragt den Verein und zählt den Versuch (fünf je Saison); kann geboten werden, bleibt der Angebotseditor offen und die Antwort trägt `outcome: "poach_open"` und `poach {playerId, name, sellerId, askingFee, askingMonthlySalary, fee, monthlySalary, feeRange {min, max}, salaryRange {min, max}, years, attemptsLeft}`, sonst `poach_refused` mit der Begründung. `poachOffer` wird sofort entschieden (`poach_accepted`, `poach_rejected`; ein zu niedriges Gebot lässt den Editor offen: `poach_open`), `poachCancel` schließt ohne Gebot. Solange der Editor offen ist, verweigern andere Befehle; Fehler `poach_open`, `no_poach`, `unknown_player`, `transfer_refused` |
| `lineup.setFormation` | `formation` 1–8, optional `save: true` (nur 5–8) | ohne `save` wird die Formation übernommen und der Co-Trainer stellt die Elf darauf (`apply_pitch_formation_source`); mit `save` werden die jetzigen Plätze der Elf als eigene Formation gespeichert und benutzt. Der Read `lineup` trägt dazu `formations [{formation, own, available, positions [{depth, lane} × 11]}]` und `formation` (0 = freie Aufstellung). Fehler `lineup_refused` |
| `lineup.setOrder` | `playerId`, `aspect` 0–3, `value` 2–40 | eine der vier Anweisungen eines aufgestellten Spielers (die vier Pfeile der Originalansicht; der Read `lineup` nennt sie je Feldspieler unter `positions[].orders`); Fehler `invalid_payload`, `unknown_player`, `lineup_refused` |
+125 -1
View File
@@ -11,6 +11,7 @@
#include "ui/achievements.hpp"
#include "ui/indoor_standings.hpp"
#include "modern/content/world_save.hpp"
#include "modern/game/assembly.hpp"
#include "modern/game/balance_plan.hpp"
#include "modern/game/bank_credit.hpp"
#include "modern/game/career.hpp"
@@ -8921,6 +8922,40 @@ cli::Json ModernSession::read_statistics_screen(const cli::Json& request) const
#include "modern/app/ui_managers.inc"
namespace {
// The annual general meeting and the interested clubs for the interface (read "assembly", and the
// args of the advance's question): the vote of the three groups, whether it is due at this desk,
// and the clubs with the cash they offer and the strength of their eleven.
cli::Json assembly_data(const modern::ModernState& g, int manager, bool season_end) {
using O = cli::Json::Object;
using A = cli::Json::Array;
const int team = manager >= 0 && size_t(manager) < g.manager_teams.size() ? g.manager_teams[size_t(manager)] : -1;
if (team < 0 || team >= league_clubs()) return O{{"kind", "assembly"}, {"available", false}};
const auto vote = modern::assembly_vote(g, manager);
const int voted = size_t(manager) < g.assembly.size() ? g.assembly[size_t(manager)].voted_season : -1;
const uint16_t eleven = avg::CONDITION | avg::TECHNIQUE | avg::FORM | avg::MORALE | avg::ALL_POSITIONS | avg::LINEUP_ONLY;
const auto club = [&](int t) {
const int league = team_league(t);
return O{{"teamId", modern::ui_team_id(g, t)},
{"name", size_t(t) < g.world_club_name.size() ? g.world_club_name[size_t(t)] : std::string()},
{"league", league >= 0 && size_t(league) < g.world_league_name.size() ? g.world_league_name[size_t(league)] : std::string()},
{"leagueIndex", league}, {"strength", team_average(g, t, eleven).value},
{"position", modern::table_position(g, t) < 0 ? cli::Json(nullptr) : cli::Json(modern::table_position(g, t) + 1)}};
};
A offers;
for (const auto& offer : modern::club_offers(g, manager)) {
O row = club(offer.team);
row["cash"] = modern::ui_money(int64_t(offer.cash));
offers.push_back(std::move(row));
}
return O{{"kind", "assembly"}, {"available", true}, {"due", season_end && voted != g.season},
{"dismissals", g.dismissals}, {"season", g.season},
{"vote", O{{"sport", vote.sport}, {"finance", vote.finance}, {"supporters", vote.supporters},
{"yes", vote.yes}, {"confirmed", vote.confirmed}}},
{"club", club(team)}, {"offers", std::move(offers)}};
}
} // namespace
cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) const {
using O = cli::Json::Object;
using A = cli::Json::Array;
@@ -9055,7 +9090,7 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
}
if (manager < 0 || size_t(manager) >= g_.manager_teams.size() ||
(kind != "balance" && kind != "achievements" && kind != "statistics" && kind != "analysis" && kind != "opening" && kind != "lineup" && kind != "tactics" && kind != "training" && kind != "bank" && kind != "contracts" &&
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" &&
kind != "advertising" && kind != "stadium" && kind != "transfer" && kind != "postmatch" && kind != "credit" && kind != "assembly" &&
!(kind == "friendly" && g_.manager_teams[size_t(manager)] == no_team())))
return modern::ui_read(g_, context, request);
if (const std::string wanted = ui_text(request, "managerId"); !wanted.empty() && wanted != modern::ui_manager_id(g_, manager))
@@ -9480,6 +9515,15 @@ cli::Json ModernSession::ui_read(const cli::Json& request, uint64_t revision) co
return modern::ui_snapshot(g_, context, request_id,
O{{"kind", "contracts"}, {"teamId", modern::ui_team_id(g_, team)}, {"players", std::move(players)}, {"quote", std::move(quote)}});
}
if (kind == "assembly") {
// the annual general meeting and the clubs that want the manager (hauptversammlung.md). Pure.
try {
return modern::ui_snapshot(g_, context, request_id,
assembly_data(g_, manager, turn_driver_.stage == TurnDriver::Stage::SeasonEndDesk));
} catch (const std::exception&) {
return modern::ui_error(request_id, "assembly_unavailable", "Die Hauptversammlung ist hier nicht verfügbar.", revision, false);
}
}
if (kind == "credit") {
// the credit dialog (bank or another human manager as lender): the saved loan, the draft after
// the request's edits [{field, value}] with labels, bounds per field, fees and refund. Pure:
@@ -9818,6 +9862,64 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
};
cli::Json answer;
std::string error;
// A manager takes over one of the clubs interested in him (manager.clubChange, and the advance
// of a manager the annual general meeting voted out). False with `error`, and nothing changed,
// when the club is not on his list.
const auto move_manager = [&](const std::string& team_id) -> bool {
std::vector<modern::ClubOffer> offers;
try { offers = modern::club_offers(g_, manager); } catch (const std::exception&) { offers.clear(); }
const auto offer = std::find_if(offers.begin(), offers.end(), [&](const modern::ClubOffer& o) { return modern::ui_team_id(g_, o.team) == team_id; });
if (offer == offers.end()) { error = "Dieser Verein gehört nicht zu den interessierten Vereinen."; return false; }
MinuteReport report;
if (!modern::change_club(g_, exe_, manager, offer->team, offer->cash, rand_, report)) {
error = report.reason.empty() ? "Vereinswechsel nicht möglich." : report.reason;
return false;
}
modern::assembly_baseline(g_, manager);
int master = -1;
for (size_t m = 0; m * 2 + 1 < db_.raw_club_name_offsets.size() && master < 0; ++m)
if (uint16_t(db_.raw_club_name_offsets[m * 2] | db_.raw_club_name_offsets[m * 2 + 1] << 8) == g_.club_ids.at(size_t(offer->team))) master = int(m);
for (auto& entry : managers_)
if (entry.slot == manager) entry.runtime_club = offer->team, entry.master_club = master >= 0 ? master : entry.master_club;
return true;
};
// The annual general meeting (hauptversammlung.md). Whoever has no base yet gets it at his
// first kickoff. At the season's last desk the members vote; only an interface that sends
// `assembly` is asked: {} first, then {seen: true}, and for a manager who is voted out
// {seen: true, teamId} with one of the interested clubs. Without the field the vote is held
// unheard and nobody has to leave.
const auto assembly_step = [&]() -> std::optional<cli::Json> {
const auto managers_before = managers_;
if (const int team = g_.manager_teams[size_t(manager)]; team >= 0 && team < league_clubs()) {
if (size_t(manager) >= g_.assembly.size() || g_.assembly[size_t(manager)].place < 0) modern::assembly_baseline(g_, manager);
if (turn_driver_.stage == TurnDriver::Stage::SeasonEndDesk && g_.assembly[size_t(manager)].voted_season != g_.season) {
const auto vote = modern::assembly_vote(g_, manager);
const bool must_leave = !vote.confirmed && g_.dismissals;
const cli::Json* asked = ui_field(*payload, "assembly");
const auto ask = [&](const char* text) {
cli::Json data = assembly_data(g_, manager, true);
restore(); managers_ = managers_before;
cli::Json pending = refuse("decision_pending", text);
auto& message = std::get<cli::Json::Object>(std::get<cli::Json::Object>(pending.value)["message"].value);
auto args = std::get<cli::Json::Object>(data.value);
args["decision"] = "assembly";
message["args"] = std::move(args);
return pending;
};
std::string new_club;
if (asked && asked->object()) {
const cli::Json* seen = ui_field(*asked, "seen");
if (!seen || !std::holds_alternative<bool>(seen->value) || !std::get<bool>(seen->value))
return ask("Die Jahreshauptversammlung stimmt über den Manager ab.");
if (must_leave && (new_club = ui_text(*asked, "teamId")).empty())
return ask("Die Mitglieder haben den Manager abgewählt: Er muss den Verein wechseln.");
}
modern::assembly_remember(g_, manager, vote);
if (!new_club.empty() && !move_manager(new_club)) { restore(); managers_ = managers_before; return refuse("club_change_refused", error); }
}
}
return std::nullopt;
};
if (kind == "camp.book") {
// payload {campId, focus?: {condition, technique, play}}: focus first (recovery follows), then the booking
const std::string camp = ui_text(*payload, "campId");
@@ -9967,6 +10069,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
} else if (kind == "session.advance" && ui_field(*payload, "live") && std::holds_alternative<bool>(ui_field(*payload, "live")->value) &&
std::get<bool>(ui_field(*payload, "live")->value)) {
// the kickoff on its own thread, stopping after the first match minute of a human match
if (auto stop = assembly_step()) return *stop;
auto run = std::make_shared<LiveRun>();
if (const cli::Json* e = ui_field(*payload, "contractExpiry"); e && e->object())
for (const auto& [id, value] : *e->object()) {
@@ -10126,6 +10229,7 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
restore();
turn_driver_ = saved_driver, managers_ = saved_managers, source_desk_callargs_ = saved_desk_callargs;
};
if (auto stop = assembly_step()) return *stop;
auto previous_hook = g_.contract_screen;
const bool previous_installed = contract_expiry_presenter_installed_;
set_contract_expiry_presenter([&](modern::ModernState& state, WatcomRandom& random, int m, int row) -> int {
@@ -10872,6 +10976,26 @@ cli::Json ModernSession::ui_command(const cli::Json& request, uint64_t& revision
} else if (kind == "manager.join.commit") {
answer = ui_join_managers(*payload,request_id,revision);
if (ui_text(answer,"messageType")=="error") return answer;
} else if (kind == "manager.clubChange") {
// payload {teamId, confirmed: true}. A Modern rule (hauptversammlung.md): the manager leaves
// for one of the clubs of the read "assembly" and starts there with the cash it offers.
const cli::Json* confirmed = ui_field(*payload, "confirmed");
if (!confirmed || !std::holds_alternative<bool>(confirmed->value) || !std::get<bool>(confirmed->value))
return refuse("confirmation_required", "Der Vereinswechsel muss bestätigt werden (confirmed: true).");
if (career_complete()) return refuse("career_ended", "Die Karriere ist beendet.");
if (balance_draft_ || balance_dispatch_active_ || strengths_owner_ || strengths_dispatch_active_ || top_scorers_owner_ ||
top_scorers_dispatch_active_ || stadium_.block_expansion || other_games_owner_ || other_games_dispatch_active_ || transfer_offer_editor_ ||
(turn_driver_.stage != TurnDriver::Stage::Empty && turn_driver_.stage != TurnDriver::Stage::MatchdayDesks &&
turn_driver_.stage != TurnDriver::Stage::SeasonEndDesk))
return refuse("not_at_desk", "Der Verein lässt sich nur am Schreibtisch wechseln, wenn nichts anderes offen ist.");
if (const int team = g_.manager_teams[size_t(manager)]; team < 0 || team >= league_clubs())
return refuse("no_club", "Am Schreibtisch des Bundestrainers gibt es keinen Vereinswechsel.");
if (!move_manager(ui_text(*payload, "teamId"))) { restore(); return refuse("club_change_refused", error); }
modern::ensure_ui_identities(g_);
revision = previous + 1;
answer = modern::ui_command_result(request_id, previous, revision,
{"session", "manager_menu", "desktop", "squad", "lineup", "tactics", "training", "camps", "bank",
"stadium", "advertising", "contracts", "statistics"}, "Vereinswechsel vollzogen.");
} else if (kind == "manager.resign.commit") {
// payload {confirmed: true}. A Modern feature (the original has no resigning): when the last
// human manager resigns the career ends (outcome career_ended, sessionState "ended"). With
+1 -1
View File
@@ -151,7 +151,7 @@ A allowed_commands(const ModernState& g, const UiContext& c) {
const int team = team_of(g, c.manager);
const bool national = team == no_team();
static constexpr const char* kAll[] = {
"session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "lineup.setFormation", "tactics.commit", "friendly.book", "manager.resign.commit",
"session.advance", "lineup.commit", "lineup.setPiece", "lineup.setOrder", "lineup.setFormation", "tactics.commit", "friendly.book", "manager.resign.commit", "manager.clubChange",
"training.commit", "camp.book", "bank.commit", "toto.submit", "quote.request", "contract.offer",
"stadium.commit", "advertising.accept", "budget.commit", "ticket.commit", "transfer.submit",
"sponsor.answer", "environment.commit", "fixture.reschedule", "contract.cancel", "news.update", "balance.commit", "settings.commit", "manager.join.commit"};
+15 -1
View File
@@ -186,7 +186,14 @@ void save_world_career(const std::filesystem::path& path, const World& world, co
{"press_month", int64_t(state.press_month)},
{"press_month_cash", [&] { A a; for (int64_t v : state.press_month_cash) a.push_back(v); return J(std::move(a)); }()},
{"career_end_reason", state.career_end_reason},
{"career_end_date", int64_t(state.career_end_date)}});
{"career_end_date", int64_t(state.career_end_date)},
{"assembly", [&] {
A rows;
for (const auto& m : state.assembly)
rows.push_back(O{{"assets", m.assets}, {"place", int64_t(m.place)}, {"voted_season", int64_t(m.voted_season)}});
return J(std::move(rows));
}()},
{"dismissals", state.dismissals}});
// The almanac: finished seasons unchanged, the running one encoded now.
for (const auto& [name, bytes] : state.almanac.finished) docs[name] = bytes;
if (state.almanac.current.season >= 0) docs["history/current.bin"] = encode_almanac_season(state.almanac.current);
@@ -256,6 +263,13 @@ SavedWorldCareer load_world_career(const std::filesystem::path& path, const Worl
out.state.press_month = uint32_t(num(get(modern, "press_month")));
for (const J& v : arr(get(modern, "press_month_cash"))) out.state.press_month_cash.push_back(int64_t(num(v)));
}
// the annual general meeting (since 17 November 2026); older saves start without a base
if (o->count("assembly")) {
for (const J& row : arr(get(modern, "assembly")))
out.state.assembly.push_back({int64_t(num(get(row, "assets"))), int32_t(num(get(row, "place"))), int32_t(num(get(row, "voted_season")))});
if (const auto it = o->find("dismissals"); it != o->end() && std::holds_alternative<bool>(it->second.value))
out.state.dismissals = std::get<bool>(it->second.value);
}
if (o->count("career_end_reason")) {
out.state.career_end_reason = str(get(modern, "career_end_reason"));
out.state.career_end_date = uint32_t(num(get(modern, "career_end_date")));
+187
View File
@@ -0,0 +1,187 @@
// SPDX-License-Identifier: GPL-3.0-only
#include "modern/game/assembly.hpp"
#include <algorithm>
#include <stdexcept>
#include <string>
#include "formats/executable_layout.hpp"
#include "game/random.hpp"
#include "game/schedule.hpp"
#include "modern/game/matchday.hpp"
namespace bmh::modern {
namespace {
constexpr size_t kRecord = 0xb0c;
constexpr size_t kCash = 0x314, kSavings = 0x318, kPrestige = 0x211, kStanding = 0x26f, kRatings = 0x8aa;
uint16_t rec16(const ModernState& g, int m, size_t offset) {
const size_t at = size_t(m) * kRecord + offset;
return uint16_t(g.manager_records.at(at) | g.manager_records.at(at + 1) << 8);
}
int32_t rec32(const ModernState& g, int m, size_t offset) {
return int32_t(uint32_t(rec16(g, m, offset)) | uint32_t(rec16(g, m, offset + 2)) << 16);
}
int rec8(const ModernState& g, int m, size_t offset) { return g.manager_records.at(size_t(m) * kRecord + offset); }
// A manager who runs a league club (not the national coach's desk, not an empty slot).
int league_club(const ModernState& g, int manager) {
if (manager < 0 || size_t(manager) >= g.manager_teams.size() || g.manager_records.size() < size_t(manager + 1) * kRecord)
return -1;
const int team = g.manager_teams[size_t(manager)];
return team >= 0 && team < league_clubs() ? team : -1;
}
// Savings, funds and shares at today's prices, less the loans (the highscore's count without cash).
int64_t holdings(const ModernState& g, int m) {
int64_t sum = rec32(g, m, kSavings);
const StaticMemory& mem = g.memory;
for (uint32_t k = 0; k < 6; ++k) {
const uint32_t held = ::bmh::layout::Advertising_OriginalShareAdjustment_RuntimeField + uint32_t(m) * 2 + k * 0x1c;
const uint32_t price = ::bmh::layout::FundBlock + k * 0x1c;
if (mem.has(held + 1) && mem.has(price + 3)) sum += int64_t(mem.u16(held)) * int64_t(mem.u32(price));
}
for (size_t k = 0; k < 12 && (k + 1) * 0x5c <= g.stocks.size(); ++k) {
const size_t at = k * 0x5c;
const int64_t held = uint16_t(g.stocks[at + 0x50 + size_t(m) * 2] | g.stocks[at + 0x51 + size_t(m) * 2] << 8);
const int64_t price = uint16_t(g.stocks[at + 0x4e] | g.stocks[at + 0x4f] << 8);
sum += held * price;
}
for (uint32_t k = 0; k < 5; ++k) {
const uint32_t at = ::bmh::layout::Analytics_SourceAssetMaskE_RuntimeField + uint32_t(m) * 0x78 + k * 0x18;
if (mem.has(at + 3)) sum -= int64_t(mem.u32(at));
}
return sum;
}
// What the club did in the cups of the running season: 2 a cup won, 1 a final lost, 0 otherwise.
// The indoor tournaments do not count.
int cup_merit(const ModernState& g, int team) {
if (size_t(team) >= g.world_club_id.size() || g.world_club_id[size_t(team)].empty()) return 0;
const std::string& id = g.world_club_id[size_t(team)];
const AlmanacSeason& season = g.almanac.current;
int merit = 0;
for (const AlmanacWinner& w : season.winners) {
if (w.type == 0 || w.detail != 0) continue;
if (w.winner < season.clubs.size() && season.clubs[w.winner].id == id) merit = 2;
else if (w.runner_up < season.clubs.size() && season.clubs[w.runner_up].id == id) merit = std::max(merit, 1);
}
return merit;
}
int clamp100(int v) { return std::clamp(v, 0, 100); }
} // namespace
int64_t assembly_assets(const ModernState& g, int manager) {
if (league_club(g, manager) < 0) throw std::invalid_argument("assembly: no manager of a league club");
const int64_t cash = std::min<int64_t>(rec32(g, manager, kCash), 1000000);
return std::min<int64_t>(cash + holdings(g, manager), 2000000);
}
int assembly_place(const ModernState& g, int manager) {
const int team = league_club(g, manager);
if (team < 0) return -1;
const int position = modern::table_position(g, team);
return position < 0 ? -1 : league_first_team(team_league(team)) + position;
}
// OpenBMH deviates from the original: Modern holds an annual general meeting at the end of a season; three groups of members vote on a human manager, and below half of the votes he has to take over another club.
AssemblyVote assembly_vote(const ModernState& g, int manager) {
const int team = league_club(g, manager);
if (team < 0) throw std::invalid_argument("assembly: no manager of a league club");
ModernState::AssemblyMemory before = size_t(manager) < g.assembly.size() ? g.assembly[size_t(manager)] : ModernState::AssemblyMemory{};
AssemblyVote vote;
vote.assets = assembly_assets(g, manager);
vote.place = assembly_place(g, manager);
if (vote.place < 0) vote.place = league_first_team(team_league(team)) + 9;
if (before.place < 0) before.place = vote.place, before.assets = vote.assets; // nothing to compare with: neutral
const int standing = rec8(g, manager, kStanding), prestige = rec8(g, manager, kPrestige);
// sport: places gained since the last meeting (three points each), the cups, the bank's
// opinion of him and his rating in the league
const int progress = clamp100(3 * (before.place - vote.place) + 50 + 30 * cup_merit(g, team));
vote.sport = (2 * standing + 4 * progress + rec16(g, manager, kRatings + 8) / 55) / 7;
// finance: what his assets gained, 30 000 a point; hoarded cash costs approval
vote.finance = clamp100(int((vote.assets - before.assets) / 30000) + 50);
if (rec32(g, manager, kCash) > 1000000) vote.finance = 85 * vote.finance / 100;
// supporters: his prestige and his last rating
vote.supporters = (rec16(g, manager, kRatings + 10) / 55 + 2 * prestige) / 3;
vote.sport = clamp100(vote.sport + 10), vote.finance = clamp100(vote.finance + 10), vote.supporters = clamp100(vote.supporters + 10);
vote.yes = (vote.sport + vote.finance + vote.supporters) / 3;
vote.confirmed = vote.yes >= 50;
return vote;
}
void assembly_remember(ModernState& g, int manager, const AssemblyVote& vote) {
if (manager < 0) return;
if (g.assembly.size() <= size_t(manager)) g.assembly.resize(size_t(manager) + 1);
g.assembly[size_t(manager)] = {vote.assets, vote.place, g.season};
}
void assembly_baseline(ModernState& g, int manager) {
const int team = league_club(g, manager);
if (team < 0) return;
if (g.assembly.size() <= size_t(manager)) g.assembly.resize(size_t(manager) + 1);
const int32_t voted = g.assembly[size_t(manager)].voted_season;
g.assembly[size_t(manager)] = {assembly_assets(g, manager), league_first_team(team_league(team)) + 9, voted};
}
// OpenBMH deviates from the original: in Modern up to seven German clubs with a clearly weaker eleven are interested in a human manager; the list is drawn by a generator of its own and stays for a fortnight.
std::vector<ClubOffer> club_offers(const ModernState& g, int manager) {
const int own_team = league_club(g, manager);
if (own_team < 0) throw std::invalid_argument("assembly: no manager of a league club");
const int clubs = german_clubs();
const auto human = [&](int team) {
for (const int t : g.manager_teams) if (t == team) return true;
// the club of a manager who is away coaching the national team
return g.manager_records.size() >= 5 * kRecord && g.manager_teams.at(0) == no_team() && rec16(g, 4, 0x290) == uint16_t(team);
};
int free_last = 0, free_all = 0;
for (int team = 0; team < clubs; ++team) {
if (human(team)) continue;
++free_all;
if (team >= clubs - 10) ++free_last;
}
if (clubs < 11 || free_last == 0) return {};
// a generator of its own: the same list for a fortnight, and no draw of the game is used
uint32_t salt = 2166136261u;
for (const unsigned char c : g.career_id) salt = (salt ^ c) * 16777619u;
GameRandom draw(int32_t((uint64_t(salt) + uint64_t(g.date / 14) * 7919u + uint64_t(manager) * 104729u) % 4000000u));
const uint16_t eleven = avg::CONDITION | avg::TECHNIQUE | avg::FORM | avg::MORALE | avg::ALL_POSITIONS | avg::LINEUP_ONLY;
const int standing = rec8(g, manager, kStanding);
const int own = team_average(g, own_team, eleven).value + rec8(g, manager, kPrestige) / 20 + standing / 10 - 35;
const int level = g.memory.has(::bmh::layout::Difficulty) ? g.memory.u8(::bmh::layout::Difficulty) : g.level;
std::vector<ClubOffer> offers;
const auto listed = [&](int team) {
return std::any_of(offers.begin(), offers.end(), [&](const ClubOffer& o) { return o.team == team; });
};
draw.range(clubs - 10, clubs - 1);
int candidate;
do candidate = draw.range(clubs - 10, clubs - 1);
while (human(candidate));
for (int pass = 0; pass < 10; ++pass) {
int value = team_average(g, candidate, eleven).value + draw.range(0, 10) + 5;
if (draw.range(0, 40) == 0 && standing > 80) value -= 10;
else if (draw.range(0, 10) == 0 && standing > 90) value -= 30;
int32_t cash = 20000 * draw.range(0, 300) - 3000000;
// the papers and shares a club of the model brings along are paid out in cash here
if (cash > 100000) {
const int32_t papers = 100000 * draw.range(0, 10);
cash += papers + 1000 * draw.range(0, 500);
}
if (level == 0) cash = 50000000;
if (own > value || offers.empty()) offers.push_back({candidate, cash});
if (offers.size() == 7 || int(offers.size()) >= free_all) break;
do candidate = draw.range(0, clubs - 1);
while (listed(candidate) || human(candidate));
if (draw.range(0, 4) == 0) break;
}
return offers;
}
} // namespace bmh::modern
+55
View File
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The annual general meeting and the clubs that want a manager
// (docs/new_engine/hauptversammlung.md). Both are Modern rules; Classic has neither.
//
// At the end of a season three groups of members vote on the manager: the sporting side, the
// treasurers and the supporters. Below half of the votes he is voted out and, while dismissals
// are on, has to take over one of the clubs that are interested in him. The same list of clubs
// serves a manager who wants to leave on his own.
//
// Nothing here draws from the game's generators: the vote is a function of the state, and the
// list of clubs uses a generator of its own, seeded from the career, the manager and the
// fortnight, so looking at it never changes the course of the game.
#include <cstdint>
#include <vector>
#include "modern/game/modern_state.hpp"
namespace bmh::modern {
struct AssemblyVote {
int sport = 0, finance = 0, supporters = 0; // approval of each group, 0-100
int yes = 0; // share of all votes for the manager, 0-100
bool confirmed = true; // at least half of the votes
int64_t assets = 0; // what the next meeting compares with
int place = 0;
};
// The manager's assets as the treasurers count them: his cash up to a million, his savings,
// funds and shares at today's prices, less his loans - two million at most.
int64_t assembly_assets(const ModernState& g, int manager);
// His club's place counted over all leagues (first league first), -1 without a league club or
// before the first round.
int assembly_place(const ModernState& g, int manager);
// The vote on a manager of a league club. Throws std::invalid_argument for another manager.
AssemblyVote assembly_vote(const ModernState& g, int manager);
// Notes what the vote found as the base of the next one, and the season it was held in.
void assembly_remember(ModernState& g, int manager, const AssemblyVote& vote);
// The base for a manager who has no meeting behind him at this club: his assets now and a
// place in the middle of his league.
void assembly_baseline(ModernState& g, int manager);
// A club that wants the manager, and the cash it gives him to start with.
struct ClubOffer {
int team = -1;
int32_t cash = 0;
};
// Up to seven German league clubs no human manages. The first is always one of the last ten
// clubs; the others are clubs whose eleven is clearly weaker than his own. The list stays the
// same for a fortnight.
std::vector<ClubOffer> club_offers(const ModernState& g, int manager);
} // namespace bmh::modern
+80
View File
@@ -5,6 +5,7 @@
#include "modern/game/career.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <utility>
#include <vector>
@@ -579,6 +580,13 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
modern::clubs_change_places(g, int16_t(team_of(g, m)), place);
}
set_club_strength(g, int16_t(team_of(g, m)), choice.strength + 1, rand);
return modern::equip_manager(g, exe, m, league, adding, rand, report);
}
bool equip_manager(ModernState& g, const LeImage& exe, int m, int league, bool adding, WatcomRandom& rand, MinuteReport& report) {
StaticMemory& mem = g.memory;
const size_t rec = size_t(m) * kRecord;
std::vector<uint8_t>& r = g.manager_records;
const int club = int16_t(team_of(g, m));
if (adding && !remove_join_loans(g, club, report)) return false;
@@ -643,6 +651,78 @@ bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerM
return !report.unsupported;
}
// OpenBMH deviates from the original: in Modern a human manager can change to an interested club; he starts there as a manager who joins a running game, with the cash the club offers and without his funds, shares and loans.
bool change_club(ModernState& g, const LeImage& exe, int m, int team, int32_t cash, WatcomRandom& rand, MinuteReport& report) {
// Reject before anything changes or a number is drawn.
if (!g.memory.has(::bmh::layout::ManagerCount) || m < 0 || m >= 4 || m >= g.memory.u8(::bmh::layout::ManagerCount) ||
size_t(m) >= g.manager_teams.size() || g.manager_records.size() < 5 * kRecord ||
team < 0 || team >= german_clubs() || size_t(team) >= g.club_ids.size() || size_t(team) >= g.team_morale.size() ||
g.tactics.size() < size_t(m + 1) * 0x840 || g.stocks.size() < 12 * 0x5c) {
report.fail("invalid club change");
return false;
}
const int old_team = g.manager_teams[size_t(m)];
if (old_team < 0 || old_team >= league_clubs() || old_team == team || human_club(g, team)) {
report.fail("club change needs a league club and a club no human manages");
return false;
}
StaticMemory& mem = g.memory;
const size_t rec = size_t(m) * kRecord;
std::vector<uint8_t>& r = g.manager_records;
// What belongs to the man stays in his record: name, portrait, the national coach's flag.
std::array<uint8_t, 0x19> name{};
std::copy_n(r.begin() + ptrdiff_t(rec + 0xa8), name.size(), name.begin());
const uint8_t portrait = r[rec + 0x221], coach = r[rec + 0x21c];
// His private assets stay behind with everything else: funds, shares, loans.
for (uint32_t k = 0; k < 6; ++k)
if (const uint32_t at = ::bmh::layout::Advertising_OriginalShareAdjustment_RuntimeField + uint32_t(m) * 2 + k * 0x1c; mem.has(at + 1)) mem.set16(at, 0);
for (size_t k = 0; k < 12; ++k) {
const size_t at = k * 0x5c;
g.stocks[at + 0x50 + size_t(m) * 2] = g.stocks[at + 0x51 + size_t(m) * 2] = 0;
for (size_t i = 0; i < 4; ++i) g.stocks[at + 4 + size_t(m) * 4 + i] = 0;
}
// His loans end. What a fellow manager lent him (rows 1-4 of his five loans) the lender gets
// back: the part of the principal that is not yet repaid.
const uint32_t loans = ::bmh::layout::Loans + uint32_t(m) * 0x78;
if (mem.has(loans + 0x77)) {
for (uint32_t row = 1; row < 5; ++row) {
const int64_t principal = int32_t(mem.u32(loans + row * 0x18)), term = int32_t(mem.u32(loans + row * 0x18 + 12)),
elapsed = int32_t(mem.u32(loans + row * 0x18 + 16));
const int lender = int(row) - 1;
if (principal <= 0 || term <= 0 || lender == m || size_t(lender) >= g.manager_teams.size()) continue;
const int64_t open = std::clamp<int64_t>(principal - principal / term * elapsed, 0, principal);
modern::book_money(g, lender, int32_t(-open), true);
}
for (uint32_t i = 0; i < 0x78; ++i) mem.set8(loans + i, 0);
}
if (size_t(m) < g.pools.size()) g.pools[size_t(m)] = {};
if (size_t(m) < g.exclusive_sponsors.size()) g.exclusive_sponsors[size_t(m)] = {};
// The club he leaves is a computer club again: its sales, bids and loans as a human club end.
remove_join_transfers(g, old_team);
if (!remove_join_loans(g, old_team, report)) return false;
g.team_morale[size_t(old_team)] &= 0x7f;
std::fill_n(r.begin() + ptrdiff_t(rec), kRecord, uint8_t(0));
std::fill_n(g.tactics.begin() + ptrdiff_t(size_t(m) * 0x840), 0x840, uint8_t(0));
std::copy(name.begin(), name.end(), r.begin() + ptrdiff_t(rec + 0xa8));
r[rec + 0x221] = portrait, r[rec + 0x21c] = coach;
for (size_t i = 0; i < 0x12; i++) r[rec + 0x1f6 + i] = 1;
for (size_t i = 0; i < 10; i++) r[rec + 0x8b6 + i] = 0xff;
r[rec + 0x1f6] = 0x40;
r[rec + 0x290] = uint8_t(team), r[rec + 0x291] = uint8_t(team >> 8);
const int league = team_league(team);
r[rec + 0x210] = uint8_t(league);
g.manager_teams[size_t(m)] = int16_t(team);
remove_join_transfers(g, team);
if (!modern::equip_manager(g, exe, m, league, true, rand, report)) return false;
put32(r, rec + 0x314, uint32_t(cash));
put32(r, rec + 0x324, uint32_t(cash));
return !report.unsupported;
}
void career_managers_end(ModernState& g, bool adding) {
g.memory.add_block(::bmh::layout::CareerSession_FormatError_RuntimeField6, 1);
g.memory.set8(::bmh::layout::CareerSession_FormatError_RuntimeField6, 0);
+14
View File
@@ -142,6 +142,20 @@ void starting_sponsors(ModernState& g, int manager);
bool career_add_manager(ModernState& g, const LeImage& exe, int m, const CareerManager& choice, bool adding,
GameRandom& game, WatcomRandom& rand, MinuteReport& report);
// The second half of career_add_manager, from the club's players on: what a manager's record,
// board and stadium need for the club his record names (league = his record's start league).
// Draws from the Watcom generator only.
bool equip_manager(ModernState& g, const LeImage& exe, int m, int league, bool adding, WatcomRandom& rand, MinuteReport& report);
// A Modern rule (docs/new_engine/hauptversammlung.md): manager m leaves his club for the German
// league club `team`, which no human manages, and starts there with `cash`. His record is
// built anew as for a manager who joins a running game (equip_manager); only his name, portrait
// and the national coach's flag stay. His funds, shares, loans, toto coupon and a waiting
// sponsor offer are gone, and the club he leaves is a computer club again. The clubs keep their
// places and their players keep their values. Returns false, with nothing changed, for a
// request that is not possible.
bool change_club(ModernState& g, const LeImage& exe, int m, int team, int32_t cash, WatcomRandom& rand, MinuteReport& report);
// ConfirmManager after the loop: clear CareerSession_FormatError_RuntimeField6; only a new career empties the twelve
// human loan entries Career_CareerManagersEnd_RuntimeField. Joining preserves unrelated entries.
void career_managers_end(ModernState& g, bool adding);
+12
View File
@@ -128,6 +128,18 @@ struct ModernState : GameState {
// The scale of the traffic access bytes (traffic.hpp): 0 the original's (steps of 0x55), 64 the
// four stages of a Modern world. Older Modern saves are converted when loaded.
uint8_t traffic_scale = 0;
// The annual general meeting (docs/new_engine/hauptversammlung.md), per manager slot: what the
// members compare the season with - his assets and his club's place over all leagues when
// they last voted (or when he took the club) - and the season they last voted in.
struct AssemblyMemory {
int64_t assets = 0;
int32_t place = -1; // -1: not yet set (an older save, a manager who has just joined)
int32_t voted_season = -1;
bool operator==(const AssemblyMemory&) const = default;
};
std::vector<AssemblyMemory> assembly;
// Whether a manager the meeting votes out has to leave his club. On until the options offer it.
bool dismissals = true;
// Players whose age the data set gives (birth date); the others carry a placeholder the
// career start replaces as in the original. Needed only while a career starts (not saved).
std::vector<bool> world_age_known;
+2 -2
View File
@@ -5,7 +5,7 @@ namespace {
struct CareerScene { const char *action, *title, *text; double left, top, width, height; };
constexpr std::array<CareerScene, 3> career_scenes{{
{"career-resign", "Aufhören", "Dein Amt abgeben. Der Verein wird danach vom Computer geführt.", 0, 0, 49.3, 52.3},
{"career-search", "Vereinssuche", "Bei einem anderen Verein anheuern – noch nicht verfügbar.", 50.1, 0, 49.9, 52.3},
{"career-search", "Vereinssuche", "Bei einem anderen Verein anheuern: Wer interessiert ist und was er bietet.", 50.1, 0, 49.9, 52.3},
{"career-add", "Neuer Spieler", "Einen weiteren menschlichen Mitspieler einrichten: Name, Land, Liga und Verein.", 0, 53.2, 100, 46.8}}};
std::string career_hint_markup(const std::string &action) {
for (const auto &scene : career_scenes)
@@ -22,7 +22,7 @@ std::string App::render_career() {
page_title_ = ended ? "Karriere beendet" : "Manager";
page_hint_ = m.value("name", "") + " · " + c.at("current_team").value("name", "") + " · " + (c.at("role") == "national" ? "Nationalmannschaft" : "Vereinsmanager");
const auto off = [&](const std::string &action) {
if (action == "career-search") return true;
if (action == "career-search") return ended || !engine_mode_ || c.at("role") == "national";
if (action == "career-resign") return ended || (engine_mode_ && engine_manager_value_.at("can_resign") != true);
return ended || (engine_mode_ && engine_manager_value_.at("can_join") != true);
};
+127
View File
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-3.0-only
// The annual general meeting and the clubs interested in a manager
// (docs/new_engine/hauptversammlung.md), as notes over the notebook.
namespace {
// One group of members: its name, a bar and its approval in percent.
std::string assembly_group(const char *name, int value) {
value = std::clamp(value, 0, 100);
return "<div class=\"as-row\"><span class=\"as-name\">" + esc(name) + "</span><div class=\"as-track\"><div class=\"as-fill" + std::string(value < 50 ? " low" : "") + "\" style=\"width:" + std::to_string(value) +
"%;\"></div></div><span class=\"as-value\">" + std::to_string(value) + " %</span></div>";
}
} // namespace
// The kickoff at the end of a season stopped for the meeting: first its result, then - for a
// manager who was voted out - the clubs he can go to.
void App::engine_assembly_ask(const Json &args) {
engine_assembly_ = args;
const Json vote = args.value("vote", Json::object());
const bool confirmed = vote.value("confirmed", true), leave = !confirmed && args.value("dismissals", true);
const Json sent = engine_advance_payload_.value("assembly", Json::object());
if (sent.is_object() && sent.value("seen", false)) {
if (leave) engine_assembly_clubs(true);
return;
}
const int yes = std::clamp(vote.value("yes", 0), 0, 100);
const std::string verdict = confirmed ? "Die Mitglieder bestätigen dich im Amt."
: leave ? "Die Mitglieder haben dich abgewählt. Du musst den Verein verlassen."
: "Die Mehrheit stimmt gegen dich. Diesmal bleibt das ohne Folgen.";
const std::string club = args.value("club", Json::object()).value("name", std::string());
confirmation("Zum Saisonende stimmen die Mitglieder" + (club.empty() ? std::string() : " von " + club) + " über ihren Manager ab.", [this, leave] {
engine_advance_payload_["assembly"]["seen"] = true;
if (leave) engine_assembly_clubs(true);
else engine_kickoff();
});
popup_title_ = "Jahreshauptversammlung";
popup_accept_ = leave ? "Interessierte Vereine" : "Weiter";
popup_close_ = "Zum Schreibtisch";
// the dial: red on the left, green on the right, the line of the vote in the middle
std::string dial = "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 112'>";
constexpr int parts = 48;
for (int i = 0; i < parts; ++i) {
const double from = 3.14159265358979 * (1.0 - double(i) / parts), to = 3.14159265358979 * (1.0 - double(i + 1) / parts + 0.002);
const double at = (i + 0.5) / parts;
const std::array<int, 3> red{196, 62, 46}, amber{226, 170, 52}, green{84, 140, 66};
const auto &lo = at < 0.5 ? red : amber, &hi = at < 0.5 ? amber : green;
const double k = std::pow(at < 0.5 ? at * 2 : (at - 0.5) * 2, at < 0.5 ? 2.2 : 0.45); // the colour turns close to the middle
char colour[8];
std::snprintf(colour, sizeof colour, "#%02x%02x%02x", int(lo[0] + (hi[0] - lo[0]) * k), int(lo[1] + (hi[1] - lo[1]) * k), int(lo[2] + (hi[2] - lo[2]) * k));
dial += "<path d='M" + scalar(100 + 80 * std::cos(from)) + " " + scalar(100 - 80 * std::sin(from)) + " A80 80 0 0 1 " + scalar(100 + 80 * std::cos(to)) + " " + scalar(100 - 80 * std::sin(to)) +
"' fill='none' stroke='" + colour + "' stroke-width='22'/>";
}
const std::string ink = theme_ != "silver" && theme_ != "matchday" ? "#f0ece2" : "#2a211a";
dial += "<path d='M100 6v28' stroke='" + ink + "' stroke-width='2.4'/><circle cx='100' cy='100' r='9' fill='" + ink + "'/></svg>";
engine_assembly_target_ = yes;
engine_assembly_started_ = std::max<uint64_t>(SDL_GetTicks64(), 1);
popup_body_ = "<div class=\"as-vote\"><div class=\"as-gauge\">" + picture(renderer_.diagram("assembly-dial-" + theme_, dial, 1280), 640, 358) +
"<div id=\"assembly-needle\" class=\"as-needle\"></div></div><div class=\"as-ends\"><span>Abwahl</span><span>Bestätigung</span></div>" +
"<div id=\"assembly-result\" style=\"visibility:hidden;\">" + assembly_group("Sportliche Leitung", vote.value("sport", 0)) + assembly_group("Kassenprüfer", vote.value("finance", 0)) +
assembly_group("Fans", vote.value("supporters", 0)) + "<div class=\"as-result" + std::string(confirmed ? "" : " low") + "\"><strong>" + std::to_string(yes) + " % Ja</strong><span>" +
std::to_string(100 - yes) + " % Nein</span></div><p class=\"as-verdict\">" + esc(verdict) + "</p></div></div>";
}
// The needle swings while the votes are counted and comes to rest on the result. It moves from
// the middle towards the result within a second and a half; the swing around it starts at a
// good fifth of the dial and dies away, so a clear result never looks like its opposite.
void App::engine_assembly_tick() {
if (!engine_assembly_started_) return;
if (popup_.empty()) { engine_assembly_started_ = 0; return; }
auto *needle = element("assembly-needle");
if (!needle) return; // the note is drawn with this frame
constexpr double duration = 7.5;
const double t = double(SDL_GetTicks64() - engine_assembly_started_) / 1000.0;
const double target = std::clamp(engine_assembly_target_, 0, 100);
double shown = target;
if (t < duration) {
const double x = std::min(t / 1.5, 1.0), approach = x * x * (3 - 2 * x);
const double swing = 22.0 * std::pow(1.0 - t / duration, 1.4);
const double phase = double(engine_assembly_started_ % 6283) / 1000.0;
const double wave = 0.55 * std::sin(t * 4.3 + phase) + 0.3 * std::sin(t * 7.9 + phase * 2.1) + 0.25 * std::sin(t * 2.1 + phase * 0.7);
shown = std::clamp(50 + (target - 50) * approach + swing * wave, 0.0, 100.0);
}
needle->SetProperty("transform", "rotate(" + scalar((shown - 50) * 1.8) + "deg)");
if (t >= duration) {
if (auto *result = element("assembly-result")) result->SetProperty("visibility", "visible");
engine_assembly_started_ = 0;
}
}
// The clubs that want the manager: crest, league, the strength of their eleven beside his own,
// and the cash they give him to start with.
void App::engine_assembly_clubs(bool forced) {
engine_assembly_forced_ = forced;
const Json offers = engine_assembly_.value("offers", Json::array());
const Json own = engine_assembly_.value("club", Json::object());
std::string body = "<div class=\"po-offers\">";
for (const auto &offer : offers) {
const std::string id = offer.value("teamId", std::string());
const auto *club = world_->find("clubs", id);
const std::string name = club ? world_->name(*club) : offer.value("name", std::string("Ein Verein"));
body += "<div class=\"po-offer\"><span class=\"po-crest\">" + (club ? crest(club, 72) : std::string()) + "</span><div class=\"po-text\"><strong>" + esc(name) + "</strong><span>" + esc(offer.value("league", std::string())) +
(offer.contains("position") && offer.at("position").is_number_integer() ? " · Platz " + std::to_string(offer.at("position").get<int>()) : std::string()) + " · Stärke " + std::to_string(offer.value("strength", 0)) +
" · Startkapital " + esc(offer.contains("cash") ? engine_price(offer.at("cash")) : std::string("—")) + "</span></div>" +
pg_button("assembly-club", "Übernehmen", "primary", "id=\"assembly-club-" + esc(id) + "\" data-id=\"" + esc(id) + "\"") + "</div>";
}
body += "</div>";
const std::string strength = own.contains("strength") ? " Deine Elf hat die Stärke " + std::to_string(own.value("strength", 0)) + "." : std::string();
message(offers.empty() ? "Zurzeit interessiert sich kein Verein für dich."
: forced ? "Diese Vereine wollen dich verpflichten. Einen davon musst du übernehmen, bevor die neue Saison beginnt." + strength
: "Diese Vereine wollen dich verpflichten. Die Liste wechselt alle zwei Wochen." + strength);
popup_title_ = "Interessierte Vereine";
popup_close_ = forced ? "Zum Schreibtisch" : "Abbrechen";
popup_body_ = body;
}
// A club of the list was chosen: asked once more, because nothing of the old club comes along.
void App::engine_assembly_choose(const std::string &team) {
const auto *club = world_->find("clubs", team);
const std::string name = club ? world_->name(*club) : std::string("diesem Verein");
const bool forced = engine_assembly_forced_;
confirmation("Wirklich zu " + name + " wechseln? Dein Konto, deine Aktien, Fonds und Kredite bleiben zurück; beim neuen Verein beginnst du mit dessen Startkapital und einem neuen Vertragswerk.", [this, team, forced] {
if (forced) {
engine_advance_payload_["assembly"] = {{"seen", true}, {"teamId", team}};
engine_kickoff();
return;
}
try {
engine_finance_submit(engine_club_change_command(engine_data_, team, editor::new_id("request:ui-")));
} catch (const std::exception &e) { message(e.what()); }
});
popup_title_ = "Vereinswechsel";
popup_accept_ = "Wechseln";
}
+2
View File
@@ -32,6 +32,8 @@ Json engine_ticket_command(const Json &bundle, int euros, const std::string &req
Json engine_environment_projection(const Json &bundle);
Json engine_environment_command(const Json &bundle, const std::string &item, int level, const std::string &request_id);
// The manager leaves for one of the clubs interested in him (read "assembly").
Json engine_club_change_command(const Json &bundle, const std::string &team, const std::string &request_id);
Json engine_advertising_projection(const Json &bundle);
Json engine_advertising_quote(const Json &bundle, int slot, int choice);
Json engine_advertising_command(const Json &bundle, const std::string &offer, const std::string &request_id);
+17
View File
@@ -14,6 +14,8 @@ void App::engine_kickoff() {
// kickoff, never after a match the manager has watched and steered.
// this interface answers the bids for listed players: the field says so even while it is empty
if (!engine_advance_payload_.contains("transferOffers")) engine_advance_payload_["transferOffers"] = Json::object();
// ... and shows the annual general meeting at the end of a season
if (!engine_advance_payload_.contains("assembly")) engine_advance_payload_["assembly"] = Json::object();
Json rehearsal = engine_advance_payload_, live = engine_advance_payload_;
rehearsal["dryRun"] = true; live["live"] = true;
const auto probe = engine_advance_command(engine_data_, editor::new_id("request:ui-"), rehearsal);
@@ -163,6 +165,8 @@ void App::engine_accept(EngineReply result) {
engine_expiry_ask(args);
else if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "transfer_offers")
engine_offers_ask(args);
else if (engine_response_.value("code", "") == "decision_pending" && args.is_object() && args.value("decision", "") == "assembly")
engine_assembly_ask(args);
}
if (engine_response_.contains("seasonOpening")) {
// a new season began: its draw is shown once the ticker is closed
@@ -213,6 +217,13 @@ void App::engine_poll() {
}
refresh(); return;
}
if (result.response.value("messageType", "") == "assembly_read") {
// the clubs interested in a manager who thinks of leaving
const auto &read = result.response.at("read");
if (read.value("messageType", "") == "error" || !read.contains("data") || !read.at("data").value("available", false)) engine_notice_ = "Hier gibt es keinen Vereinswechsel.";
else { engine_assembly_ = read.at("data"); engine_assembly_clubs(false); }
refresh(); return;
}
if (result.response.value("messageType", "") == "poach_squad") {
// the squad of the club a manager wants to poach from
const auto &read = result.response.at("read");
@@ -466,6 +477,12 @@ void App::engine_event(Rml::Event &event) {
const auto action = node->GetAttribute<Rml::String>("data-action", ""), id = node->GetAttribute<Rml::String>("data-id", "");
if (!popup_.empty()) {
if(action=="balance-discard"){engine_balance_action(action,node);return;}
if (action == "assembly-club") {
const std::string team = id;
popup_.clear(); reset_popup(); confirm_ = {}; dirty_ = true;
engine_assembly_choose(team);
return;
}
if (action == "engine-offer-accept") {
const auto player = engine_offer_player_;
const int index = node->GetAttribute<int>("data-id", -1);
+3
View File
@@ -513,6 +513,9 @@ Json engine_environment_projection(const Json &bundle) {
}
return {{"ok", true}, {"rows", rows}};
}
Json engine_club_change_command(const Json &bundle, const std::string &team, const std::string &request_id) {
return sports_command(bundle, "manager.clubChange", {{"teamId", team}, {"confirmed", true}}, request_id);
}
Json engine_environment_command(const Json &bundle, const std::string &id, int level, const std::string &request_id) {
const auto view = engine_environment_projection(bundle);
const Json *item = nullptr;
+5
View File
@@ -50,6 +50,11 @@ void App::engine_manager_main() {
bool App::engine_manager_action(const std::string &action,Rml::Element *) {
if(engine_busy_)return true;
if(action=="career-game-end"){engine_manager_main();return true;}
if(action=="career-search"&&engine_fresh_&&!engine_busy_&&engine_link_) {
auto link=engine_link_;
engine_start("Interessierte Vereine …",[link]{auto response=link->read({{"kind","assembly"}});return EngineReply{link,link->snapshot(),{{"messageType","assembly_read"},{"read",response}},nullptr};});
return true;
}
if(action=="career-resign-cancel"){career_resign_open_=false;focus_after_render_="career-resign";refresh();return true;}
if(action=="career-resign"&&engine_fresh_&&engine_manager_value_.at("can_resign")==true){engine_manager_context_=engine_data_.at("desktop").at("meta");career_resign_open_=true;career_resign_portrait_=engine_manager_value_.at("active").at("portrait");focus_after_render_="career-resign-owner";refresh();return true;}
if(action=="career-resign-confirm") {
+11
View File
@@ -46,6 +46,17 @@
std::string engine_expiry_player_;
std::string engine_offer_player_; // the listed player whose bids are being decided
void engine_offers_ask(const Json &args);
// The annual general meeting: what the engine reported (vote, interested clubs) and whether
// the list of clubs is shown to a manager who was voted out.
Json engine_assembly_;
bool engine_assembly_forced_ = false;
void engine_assembly_ask(const Json &args);
void engine_assembly_clubs(bool forced);
void engine_assembly_choose(const std::string &team);
// The needle of the meeting: when it started to swing (0 = at rest) and where it comes to rest.
uint64_t engine_assembly_started_ = 0;
int engine_assembly_target_ = 50;
void engine_assembly_tick();
void engine_kickoff();
// A kickoff of the engine that is played minute by minute while the ticker is open.
bool engine_live_running_ = false, engine_live_busy_ = false, engine_live_at_end_ = false;
+7 -2
View File
@@ -565,6 +565,7 @@ class App final : public Rml::EventListener {
bool rendered_confirm_ = false;
std::string popup_input_, popup_extra_, popup_accept_ = "Bestätigen";
std::string popup_body_; // markup under the question, for a question that lists things
std::string popup_title_, popup_close_; // another heading and another word on the closing button
bool popup_has_input_ = false, quit_after_save_ = false;
std::function<void(const std::string &)> text_accept_;
bool context_open_ = false, context_dirty_ = false;
@@ -744,6 +745,8 @@ class App final : public Rml::EventListener {
popup_input_.clear();
popup_extra_.clear();
popup_body_.clear();
popup_title_.clear();
popup_close_.clear();
popup_accept_ = "Bestätigen";
text_accept_ = {};
rendered_popup_.clear();
@@ -1323,7 +1326,7 @@ class App final : public Rml::EventListener {
return;
element("popup")->SetInnerRML(
"<div class=\"fill popup-backdrop\"></div><div "
"class=\"popup-box\"><h2>" + std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis") + "</h2><p>" +
"class=\"popup-box\"><h2>" + (!popup_title_.empty() ? esc(popup_title_) : std::string(confirm_ || text_accept_ ? "Rückfrage" : "Hinweis")) + "</h2><p>" +
esc(popup_) + "</p>" + popup_body_ +
(popup_has_input_
? "<input id=\"popup-text\" value=\"" + esc(popup_input_) +
@@ -1331,7 +1334,7 @@ class App final : public Rml::EventListener {
: "") +
"<footer>" +
btn("popup-close",
confirm_ || text_accept_ ? "Abbrechen" : "Verstanden") +
!popup_close_.empty() ? popup_close_ : confirm_ || text_accept_ ? "Abbrechen" : "Verstanden") +
popup_extra_ +
((confirm_ || text_accept_)
? btn("popup-confirm", popup_accept_, "primary")
@@ -1373,6 +1376,7 @@ class App final : public Rml::EventListener {
engine_create_poll();
engine_files_poll();
stadium_flight_tick();
engine_assembly_tick();
if (engine_mode_) { engine_frame(); return; }
front_poll();
flush_selects();
@@ -1847,6 +1851,7 @@ public:
#include "modern/ui/engine_statistics.inc"
#include "modern/ui/engine_toto.inc"
#include "modern/ui/engine_stadium.inc"
#include "modern/ui/engine_assembly.inc"
#include "modern/ui/engine_transfer.inc"
#include "modern/ui/engine_achievements.inc"
#include "modern/ui/engine_news.inc"
+145
View File
@@ -0,0 +1,145 @@
// SPDX-License-Identifier: GPL-3.0-only
// The annual general meeting and the interested clubs (docs/new_engine/hauptversammlung.md) on a
// synthetic world: the three groups' approval, the dismissal, and the list of clubs.
#include <cstdio>
#include <set>
#include "game/schedule.hpp"
#include "modern/game/assembly.hpp"
using namespace bmh;
using namespace bmh::modern;
namespace {
int failures = 0;
void check(bool ok, const char* what) {
if (!ok) {
std::fprintf(stderr, "FAIL: %s\n", what);
++failures;
}
}
void put16(std::vector<uint8_t>& v, size_t at, uint16_t x) { v[at] = uint8_t(x), v[at + 1] = uint8_t(x >> 8); }
void put32(std::vector<uint8_t>& v, size_t at, uint32_t x) {
for (int i = 0; i < 4; ++i) v[at + size_t(i)] = uint8_t(x >> (8 * i));
}
// Manager 0 runs club 0. Every German club fields eleven players of one strength: `own` for his
// club, 30 for the others.
ModernState world(int own) {
ModernState g;
g.career_id = "career:test";
g.level = 2;
g.manager_teams = {0};
g.manager_records.assign(5 * 0xb0c, 0);
g.manager_records[0x211] = 50, g.manager_records[0x26f] = 50; // prestige, standing with the bank
for (size_t i = 0; i < 6; ++i) put16(g.manager_records, 0x8aa + 2 * i, 550);
put32(g.manager_records, 0x314, 500000);
put16(g.manager_records, 4 * 0xb0c + 0x290, 0xffff);
g.team_morale.assign(419, 50);
g.stocks.assign(12 * 0x5c, 0);
g.squad_slots.assign(3150, kEmptySlot);
for (int team = 0; team < german_clubs(); ++team) {
const SquadRange range = squad_range(team);
const uint32_t skill = uint32_t(team == 0 ? own : 30);
for (int i = 0; i < 11; ++i) {
Player p;
p.w35c = 50u | skill << 7 | skill << 14; // form, technique, condition
p.w364 = uint32_t(i == 0 ? 0 : 1 + (i - 1) % 3); // position
g.squad_slots[range.first + size_t(i)] = uint16_t(g.players.size()) | kSlotInLineup;
g.players.push_back(p);
}
}
return g;
}
} // namespace
int main() {
// a manager with everything in the middle and nothing to compare with
{
const ModernState g = world(60);
const AssemblyVote v = assembly_vote(g, 0);
check(v.sport == 54 && v.finance == 60 && v.supporters == 46, "the neutral manager: 54 / 60 / 46");
check(v.yes == 53 && v.confirmed, "the neutral manager is confirmed");
check(v.assets == 500000 && v.place == league_first_team(0) + 9, "what the next meeting compares with");
}
// nine places lost and a million and a half gone: voted out
{
ModernState g = world(60);
g.assembly = {{2000000, league_first_team(0), 0}};
const AssemblyVote v = assembly_vote(g, 0);
check(v.sport == 38, "nine places lost cost the sporting side 16 points");
check(v.finance == 10, "assets lost: the treasurers' approval is at its floor");
check(v.yes == 31 && !v.confirmed, "voted out");
assembly_remember(g, 0, v);
check(g.assembly[0].assets == v.assets && g.assembly[0].place == v.place && g.assembly[0].voted_season == g.season,
"the vote becomes the base of the next");
}
// hoarded cash costs approval, assets are capped at two million
{
ModernState g = world(60);
put32(g.manager_records, 0x314, 9000000);
put32(g.manager_records, 0x318, 5000000);
g.assembly = {{0, league_first_team(0) + 9, 0}};
const AssemblyVote v = assembly_vote(g, 0);
check(v.assets == 2000000, "assets count up to two million");
check(v.finance == 95, "hoarded cash: 85 % of the approval, then the ten points of every group");
}
// the baseline of a manager who has just taken the club
{
ModernState g = world(60);
assembly_baseline(g, 0);
check(g.assembly.size() == 1 && g.assembly[0].assets == 500000 && g.assembly[0].place == league_first_team(0) + 9 &&
g.assembly[0].voted_season == -1,
"baseline: his assets now, the middle of the league, no vote yet");
}
// the interested clubs
{
const ModernState g = world(80);
const auto offers = club_offers(g, 0);
check(!offers.empty() && offers.size() <= 7, "one to seven clubs");
check(offers.front().team >= german_clubs() - 10 && offers.front().team < german_clubs(), "the first is one of the last ten clubs");
std::set<int> teams;
bool sound = true;
for (const ClubOffer& o : offers) {
sound = sound && o.team > 0 && o.team < german_clubs() && teams.insert(o.team).second && o.cash >= -3000000 && o.cash <= 4500000;
}
check(sound, "German clubs no human manages, each once, with a start cash in range");
const auto again = club_offers(g, 0);
bool same = again.size() == offers.size();
for (size_t i = 0; same && i < offers.size(); ++i) same = again[i].team == offers[i].team && again[i].cash == offers[i].cash;
check(same, "looking at the list does not change it");
// over many fortnights a strong eleven gets more than the one certain offer
ModernState later = g;
size_t most = 0;
std::set<int> firsts;
for (uint32_t fortnight = 0; fortnight < 40; ++fortnight) {
later.date = fortnight * 14;
const auto list = club_offers(later, 0);
most = std::max(most, list.size());
firsts.insert(list.front().team);
}
check(most > 1 && firsts.size() > 1, "the list changes with the fortnight and can hold several clubs");
}
// a weak eleven: only the one certain offer
{
ModernState g = world(30);
bool only_one = true;
for (uint32_t fortnight = 0; fortnight < 40; ++fortnight) {
g.date = fortnight * 14;
only_one = only_one && club_offers(g, 0).size() == 1;
}
check(only_one, "no club is interested in a manager whose eleven is no stronger than theirs, except the certain one");
}
// the easiest level: every club brings fifty million
{
ModernState g = world(80);
g.level = 0;
const auto offers = club_offers(g, 0);
bool rich = !offers.empty();
for (const ClubOffer& o : offers) rich = rich && o.cash == 50000000;
check(rich, "level 0: fifty million");
}
if (failures) return 1;
std::puts("modern_assembly_tests: ok");
return 0;
}
+39
View File
@@ -948,6 +948,45 @@ int main(int argc, char** argv) {
const J curves = session.read_statistics_screen(O{{"section", 2}});
check(!club_desk || (at(curves, "series").array() && at(curves, "series").array()->size() == 6), "the six curves of the original");
}
// the annual general meeting and the interested clubs: the read, then a change of club
{
const J meeting = at(session.ui_read(O{{"kind", "assembly"}}, rev), "data");
if (truth(at(meeting, "available"))) {
const J& vote = at(meeting, "vote");
check(vote.object() && at(vote, "yes").integer() && *at(vote, "yes").integer() >= 0 && *at(vote, "yes").integer() <= 100 &&
!truth(at(meeting, "due")) && truth(at(meeting, "dismissals")),
"assembly: a vote, not due in the season, dismissals on");
const auto* offers = at(meeting, "offers").array();
check(offers && !offers->empty() && offers->size() <= 7, "assembly: one to seven interested clubs");
const std::string own = s(at(at(meeting, "club"), "teamId"));
check(cli::dump_json(at(session.ui_read(O{{"kind", "assembly"}}, rev), "data")) == cli::dump_json(meeting), "assembly: reading changes nothing");
const auto change = [&](const std::string& id, J payload) {
return session.ui_command(cmd(id, "manager.clubChange", std::move(payload)), rev);
};
const uint64_t before = rev;
check(s(at(change("request:cc1", O{{"teamId", own}}), "code")) == "confirmation_required", "club change needs the confirmation");
check(s(at(change("request:cc2", O{{"teamId", own}, {"confirmed", true}}), "code")) == "club_change_refused" && rev == before,
"a club that is not interested is refused, nothing changes");
if (offers && !offers->empty()) {
const std::string to = s(at(offers->front(), "teamId"));
const std::string cash = cli::dump_json(at(offers->front(), "cash"));
const J done = change("request:cc3", O{{"teamId", to}, {"confirmed", true}});
if (s(at(done, "messageType")) != "command_result") std::fprintf(stderr, "club change: %s\n",cli::dump_json(done).c_str());
check(s(at(done, "messageType")) == "command_result" && rev == before + 1, "club change accepted");
const J after = at(session.ui_read(O{{"kind", "assembly"}}, rev), "data");
check(s(at(at(after, "club"), "teamId")) == to, "the manager runs the new club");
const J bank = at(session.ui_read(O{{"kind", "bank"}}, rev), "data");
check(cli::dump_json(bank).find(cash) != std::string::npos, "he starts with the cash the club offered");
const J lineup = at(session.ui_read(O{{"kind", "lineup"}}, rev), "data");
check(lineup.object() != nullptr, "the new club has a line-up to read");
for (int k = 0; k < 3; ++k) {
const J next = session.ui_command(cmd("request:cc-go" + std::to_string(k), "session.advance", O{}), rev);
if (s(at(next, "messageType")) != "command_result") std::fprintf(stderr, "advance after change: %s\n",cli::dump_json(next).c_str());
check(s(at(next, "messageType")) == "command_result", "the game goes on at the new club");
}
}
}
}
// resigning: needs the confirmation; the last human manager ends the career
{
const auto resign = [&](const std::string& id, J payload) {