From d6bcce3a76e0f243ffcb2c455b9c419f24a50d99 Mon Sep 17 00:00:00 2001 From: Richard Zink Date: Wed, 4 Nov 2026 08:34:55 +0100 Subject: [PATCH] Multiplayer plan: deterministic lockstep, steps A-F Co-Authored-By: Claude Opus 5.5 --- docs/MULTIPLAYER.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 docs/MULTIPLAYER.md diff --git a/docs/MULTIPLAYER.md b/docs/MULTIPLAYER.md new file mode 100644 index 0000000..4263ebe --- /dev/null +++ b/docs/MULTIPLAYER.md @@ -0,0 +1,41 @@ +# Multiplayer - plan and status + +Multiplayer is only available for users of a server (not in the standalone file). + +## Decisions + +- Modes: **versus** (every player a master with an own heart), **coop** (every player an own master, + together against AI masters and/or the humans) and a **coop campaign of 20 missions**. +- 2 to 4 players per match; free slots can be AI masters. +- The match **pauses while a player is missing** (connection lost); a player who **leaves** is replaced by an AI. +- The humans (hero waves of the Order) as a third party (can be switched off), chat, alliances/teams. +- Coop is "separate but helpful": own heart, gold, mana, research and creatures; allies never fight each + other, their creatures help each other, gold can be sent, allied ground can be walked; a fallen heart only + knocks out that player (who may keep watching); the allies win when all enemies have fallen. +- Lobby: an open list of matches under *Multiplayer* in the title menu; the host chooses mode, map, AI slots, + humans on/off and teams; logged-in users join; the match starts when everybody is ready. + +## Architecture: deterministic lockstep + +Every client runs the same simulation (the same WASM module, so floating point results are identical). +The server does not simulate; it relays: + +1. Clients send their **commands** (dig, build, cast, hand, orders, ...) to the server. +2. Every 100 ms the server sends **turn N**: the commands of all players for that turn. +3. Each client applies turn N and simulates two fixed steps of 50 ms. Turns arrive in order; a client waits + for the next turn, so a missing player stalls everybody - exactly the "pause while missing" rule. +4. Clients send a **checksum** of the game state every few seconds; a mismatch (desync) is reported. + +Only the commands travel over the network, so bandwidth is tiny and no game state has to be serialised +per turn. Fog of war, particles and the camera are local and not part of the shared state. + +## Steps + +| # | Step | Status | +|---|---|---| +| A | Simulation per master: gold, mana, research, rooms, hand, flag, traps, payday... per side; up to four masters (red, green, blue, yellow) | planned | +| B | All player actions as commands (`Command` + `Game::apply`), single player uses the same path; fixed time step | planned | +| C | Server: lobby and match relay over WebSocket (axum), turns, pause on disconnect, AI takeover on leave, chat | planned | +| D | Client: *Multiplayer* menu (lobby, create, join, ready, teams), WebSocket bridge in `dc_plugin.js`, chat, gold sending | planned | +| E | Alliances and coop rules, AI masters for free and abandoned slots | planned | +| F | Coop campaign: 20 missions with story (EN/DE) | planned |