- Rust 99.1%
- Shell 0.6%
- Python 0.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .cargo | ||
| .claude | ||
| .forgejo/workflows | ||
| content | ||
| crates | ||
| docs | ||
| scripts | ||
| web | ||
| .dockerignore | ||
| .env.example | ||
| .env.postgres.example | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CHANGELOG.de.md | ||
| CHANGELOG.md | ||
| CLAUDE.md | ||
| docker-compose.yml | ||
| Dockerfile | ||
| IDEAS.md | ||
| README.md | ||
| start.sh | ||
Tirakan: A Thousand Wars
Tirakan: Tausend Kriege in German (formerly Battle for Tirakan / Schlacht um Tirakan, before that Tirakans Thron).
Async fantasy autobattler in Rust, inspired by 9 Kings, set in the world of
Tirakans Reiche. Two rulers build a small
realm on their half of a war table, then watch tiny pixel armies clash, year
after year, until one throne falls. Full design: docs/SPEC.md.
Quick start
./start.sh # builds, server in a herdr workspace (inside herdr: in this pane), opens the browser
./start.sh --fast --bot # short duel timers + a duel bot in a second pane
./start.sh --web # rebuild the browser client first (built anyway if missing)
./start.sh --instances 2 # two server instances (7878, 7879) sharing Redis + Postgres
./start.sh --memory # in-memory store, no Postgres/Redis
./start.sh --no-debug # without the local debug mode (by default every player is a developer)
start.sh uses Postgres postgres:///trbattler (created if missing) and
Redis redis://127.0.0.1/ when it answers; DATABASE_URL/REDIS_URL
override. The servers listen on all interfaces (0.0.0.0:7878; TT_BIND
overrides). One server process serves both the game connection (/ws) and
the browser client (/). To play from another device, leave
TT_PUBLIC_URL empty (or set it to this machine's LAN address) before
building the browser client.
Game server address: TT_PUBLIC_URL in .env (copy .env.example;
development: http://127.0.0.1:7878). It is baked into the client at build
time (crates/tt_client/build.rs; an environment variable of the same name
wins), the server logs it and start.sh opens it. Without it the browser
client talks to the address it was loaded from, the native client to
http://127.0.0.1:7878. There is no server field in the client.
Development loop: the servers run under scripts/dev-server.sh, which
restarts them when target/release/tt_server changes (gracefully: matches
are saved and resume at once). So after cargo build --release -p tt_server
or web/build.sh, a browser reload shows the new version. The native client
(cargo run --release -p tt_client) still works against the same server.
Manual start:
createdb trbattler
DATABASE_URL=postgres:///trbattler cargo run --release -p tt_server # without: in-memory store
cargo run --release -p tt_client # second terminal
Useful flags: tt_server --fast (short Sync Duel timers),
tt_server --debug / TT_DEBUG=1 (local debug mode: every player is a
developer; refused with a non-local TT_PUBLIC_URL, never in production),
tt_server --bind 0.0.0.0:7878, --web-dir DIR / --no-web,
tt_client --server http://host:7878 (overrides the built-in address).
Scaling out
tt_server --database-url … --redis-url redis://… (or REDIS_URL) runs one
of any number of interchangeable instances behind a load balancer (it must
pass WebSockets; no sticky sessions needed):
- Postgres stays the durable store: players, ratings, pool, battles, match checkpoints (every year boundary and match end).
- Redis holds what is shared and hot: per-player and per-match pub/sub channels (a connection on one instance talks to a match actor on another), a lease per match (exactly one instance runs it), the match state after every action (written only by the lease holder), the Sync Duel queue and the matchmaker leader lease.
- If an instance dies, its matches resume on another instance as soon as a player sends something and the lease (10 s) has expired; on SIGTERM an instance saves and releases its matches first, so they resume at once.
TT_REDIS_PREFIXseparates deployments sharing one Redis.
Play a Sync Duel alone by letting a bot join the queue:
cargo run --release -p tt_tools -- bot-client --mode duel --watch
Client
cargo run --release -p tt_client # talks to the TT_PUBLIC_URL it was built with
Flags: --name, --lang de|en, --size WxH, --fresh (ignore the saved
login in $XDG_CONFIG_HOME/tirakans-thron/profile.ron), --mute,
--mock (built-in fake server, no backend needed; F9 simulates a
disconnect). Screenshot autopilot for testing:
--screenshot out.png --after-frames N --mock-screen build|battle|achievements|… [--gauntlet] [--mock-boss <id>] [--mock-yearly] [--mock-reich <id>] [--mock-year N] [--mock-unlock <id>] [--live]
(--live drives the real server; TT_PILOT_YEAR, TT_PILOT_TICK choose
the moment; --mock-unlock fires an achievement unlock toast).
Controls: click an offer card to take it, click a hand card and then a highlighted plot to place/level it (Edikte: plot, or anywhere for those marked "Überall"), click a priced locked plot to buy it, hover plots for stat sheets with every buff source; "Alle Karten" (build phase, Reich draft) lists every card of a Reich; game terms in tooltips (Zauberkraft, Zinsobergrenze, …) are highlighted and explained under the tooltip, and "?" (menu bar, match bar) opens the glossary of all terms. Mouse wheel zooms; right/middle-drag or WASD/arrow keys pan, Home resets the view; keys 1–6 select hand cards; right-click or Esc cancels a selection.
Browser client
The same client also runs in the browser (WebAssembly, WebGL2), served by the game server itself:
web/build.sh # → web/dist (release, wasm-opt, .br/.gz)
cargo run --release -p tt_server # serves web/dist at / by itself
# open http://127.0.0.1:7878/
or ./start.sh --web. web/dist is a symlink swapped atomically per build
and read per request, so a running server needs no restart. Needs the wasm32-unknown-unknown target (Arch:
rust-wasm), the wasm-bindgen CLI in exactly the version of the
wasm-bindgen crate in Cargo.lock (cargo install wasm-bindgen-cli --version <v> --locked; the script checks), and optionally wasm-opt
(binaryen) and brotli. web/build.sh --dev skips optimisation.
Flags become URL query parameters: ?name=…&lang=en&fresh&mute&mock&server=…;
the server defaults to the built-in TT_PUBLIC_URL, else the page's origin. The login is kept in
localStorage. Audio starts on the first click or key press (browser autoplay
rules). The download is about 7 MB (brotli).
Modes
- Async Gauntlet – solo run against stored boards of real players (snapshot pool, bot boards as fallback), no timer, resume any time, year 20 boss. Ranked runs go to the weekly leaderboard; casual runs enable Reich perks; the daily run uses the same seed for everyone.
- Sync Duel – two live players, shared build timer (90 s + 3 s per year,
max 150 s), Glicko-2 rating, disconnect grace, year-30 boss decides survivors.
Gegen Bot (vs bot) starts a Sync Duel at once against a server-side bot
(Reich and name from content, builds with
tt_rules::bot, seals at the start of each year); casual: perks active, no rating change.
Achievements
Achievements for a Duel win and a Gauntlet boss kill with every Reich, for
every boss, for all of these together, and for feats (tower HP, single hit,
ruler damage, kills in one battle, flawless and comeback wins, Gauntlet
depth, Reich level, win counters). The catalogue is content
(content/achievements.ron: texts, icon key and a condition from a closed
vocabulary); the server evaluates the conditions after each battle and at
the end of a match, stores progress per player and pushes unlocks, which
the client shows as a toast on any screen. The menu's trophy button opens
the list (unlocked with date, locked with progress, hidden ones as "???").
Only real players earn them, Sync Duels against the bot count, wins by
forfeit and past matches do not.
Accounts
Anyone can play straight away as a guest: the name entry creates a player
and a token the client keeps (profile.ron natively, localStorage in the
browser). An account is that same player with an email address and a
password: registering (email + password, 8–128 characters, no
confirmation mail) upgrades the current guest in place, keeping name,
rating and Reich levels. Logging in on another device with email and
password returns the player's existing token; logging out makes the client
forget it. The account panel opens from the ruler's dropdown or the
profile in the menu, and "Mit Konto anmelden" on the name entry logs in an
existing account. Passwords are stored as salted Argon2id hashes. A
forgotten password is reset by email: "Passwort vergessen?" in the log-in
form mails a link (valid for one hour, single use) that opens the game with
a new-password form; the reset logs the other devices out. The server
sends mail over SMTP with the EMAIL_* settings in .env (see
.env.example); without EMAIL_HOST it logs the link instead.
In build and battle a small game ref (match:year:phase) opens "report
game": the text goes to ADMIN_EMAIL with the ref, so the game can be
looked up later (docs/OPERATIONS.md).
Guests play casual: Gauntlet runs (the daily one too), Sync Duels against other players and against the bot, and gain Reich XP and perks. Ranked play, the leaderboard and achievements need an account; the server enforces this, and the client shows those controls dimmed with an "account required" tooltip. Matches played as a guest give no achievements later.
Friends
Every player has a friend tag Name#1234: the name plus a random 4-digit
number (5 digits once a name has used up all 4-digit ones), assigned when
the player is created; POST /auth, /login and /reset return it as
tag in their JSON. Accounts send a friend request by pasting a tag; the
other player accepts or declines it, the sender can cancel it, and a
request to someone who already asked you makes you friends at once.
Friends can be removed. The friend list shows each friend as online, in a
match or offline; the "invisible" option shows you as offline to everyone.
Requests and answers reach the other player at once. Limits: 200 friends
plus pending requests, 20 requests per 10 minutes. Guests see their tag
but cannot use friends, and their tags are never found.
In the client, the friends button in the main menu's top bar (with a badge
for open requests) opens the friends panel: the own tag with a copy button,
the online/invisible toggle, a field to paste a tag, and the lists of
requests, friends and sent requests. The profile panel shows the tag too.
Workspace
| Crate | Role |
|---|---|
tt_core |
IDs, Q24.8 fixed point, enums, board geometry, deterministic RNG, hashing |
tt_proto |
Wire protocol (postcard envelopes), views, replay events, client content |
tt_content |
RON content schema, loader, validator, client export (content/) |
tt_sim |
Deterministic battle simulation (server only, no floats) |
tt_rules |
Build phase: economy, offers, levelling, research, sealing, bot |
tt_server |
axum gateway, match actors, replay streaming, Postgres/memory store |
tt_client |
Bevy client: war table, procedural pixel art, build UI, replays |
tt_tools |
Content lint/export, battles, balance matrix, win/loss stats, determinism, bot client |
The client links only tt_core and tt_proto; every outcome (offers, gold,
stats, combat) is decided on the server.
Design deviations from the spec
- Battle: march and siege. Troops start on their plot and march out
through the front or a side gate (whichever path is shorter; never the
back gate), with no formation phase (spec: spawn at the gate, walk to a
Vorfeld slot). Inside their own walls units pass through each other and
their own structures, so the gates never jam. Flyers wait over their
Vorfeld until the armies meet (or 12 s), siege units march with the army
until then, Frontline holds until an enemy is near, tick 600 or the
enemy army is gone. When one army is wiped the survivors besiege the
enemy city (only towers and the Thron can be attacked). A side wins
only by destroying the enemy Thron; the battle ends at once. No Thron
fallen after 90 s (sudden death from 75 s), or both armies gone, is a
draw (spec: the side with units left wins, 60 s, sudden death from 45 s).
Thron and tower battle HP scale with the year: 35 % of their stats in
year 15, ±5 % per year, at least 10 % for the Thron and 50 % for towers
(boss boards: 100 %), because armies grow over a match and structures
barely do; towers only fight near the walls, so they keep enough HP to
defend the Thron.
throne_dmgis a bonus against the Thron: +10 % of each hit on it per point. - The Thron attacks only when armed (spec: the Thron is a fixed defensive building): a Reich's Thron has no attack of its own, only what Thron cards (an Edikt or a crown enchantment per Reich, +15 each), its Thron research node (+30) and perks give it; Hadewald's Thron gains attack from banked Gulden instead. Reich towers hit half as hard as their first design. Without this most draws were an army that won the field and then died at the enemy's walls (a quarter of all battles). Boss Throne and towers keep their attack.
- Ruler life (the spec's "Thron HP"): 175 in the Sync Duel and 250 in
the Gauntlet (spec: 30 / 50) unless a Reich sets its own (
lifein its RON file; duel overrides from 110 to 225). After every battle each ruler loses the summedplayer_dmg(a unit stat, 1–5, from the unit's strength) of the opponent's surviving units, uncapped, whatever the outcome (Mechabellum-style), plus2 + year/5if the own Thron fell (spec: loser takesthrone_dmgsum +2·year/5). A draw gives 4 Gulden instead of loot. In bot duels the median match ends in year 15 (p10 10, p90 25), about 5% reach the boss, and about a sixth of the battles are draws. - Boss score: a boss is beaten when its Thron falls, which ends the
battle early, so the boss damage counts as
damage × 90 s / twhen the boss Thron fell aftertseconds (tt_rules::boss_score). In the Sync Duel a player who felled the boss Thron beats one who did not, then the higher counted damage wins (spec: higher boss damage wins); the Gauntlet score uses the counted damage. - Herald battles and boss relics (spec: the boss appears only in the final year): the match boss sends its vanguard ahead, a smaller board of its own units on a lesser herald Thron. In the Gauntlet it is the opponent of years 7 and 14; in 1 of 4 Sync Duels both players fight its second stage in year 12 instead of each other (the same board for both, so ranked stays fair). Beating it lets the player choose one of the stage's two relics of that boss (one-off Edikte or enchantments for any Reich, mostly strongest against their own boss, never offered or looted). The codex shows each boss's heralds and relics.
- Heroes (Helden; not in the spec): every player gets one hero per match. In the hero call (Sync Duel year 5, Gauntlet year 3) they pick one of the Reich's two heroes or a wanderer drawn for them; the call is compulsory and stays open until picked. A hero is a single unique unit that is never offered, looted or discarded; destroyed it returns to the hand, and placed on an occupied plot it swaps the card there back into the hand. It levels only by Ruhm (+2 per battle won, +1 otherwise, +2 for a won Gauntlet herald battle, levels 1–6), at levels 3 and 5 the player picks one of two deeds that add effects, and the hero unit itself deals +25 % damage against the boss and the heralds (not its summons, charmed units or its spell damage). To keep the boss and heralds a challenge, their boards are hardened: boss units +16 %, herald units +27 % HP and attack (summons included, the Thron not). The 12 Reiche have 24 heroes from their lore plus 4 wanderers from the Akademie von Jaar and the circle of Kingsley und das Artefakt.
- Loot for both: after every battle won or lost both players pick a loot card, the loser from 3, the winner from 2 (a draw gives Gulden instead); the first card comes from the opponent's Reich, the others from both Reiche (so a Reich with few lootable cards does not starve its opponents). Spec: only the winner, 1 of 3, which snowballed: the year's winner won the next battle 96 % of the time in bot duels, now ≈ 80 %. Picks are simultaneous; the pools are per player. In the Gauntlet the stored opponent's Reich stands in for the opponent. Passing the loot ("Verzichten", also a herald's relic choice) gives at random 1 Wissen or 2 Gulden.
- Economy: interest is 1 Gulden per 5 banked, cap 3 (spec: per 10, cap 5), so saving is a real alternative to paid picks. A streak of 2+ wins or 2+ losses pays +1 Gulden per year, 4+ pays +2 (a draw resets it), on top of the loser's +3 catch-up in Sync Duel. Discarding (burning) a hand card gives 1 Gulden (spec: no refund), so a free pick or loot card nobody wants is still worth something.
- Build timer: the Sync Duel's shared timer is 90 s + 3 s per year, max 150 s (spec: 45 s + 3 s, max 90 s), room for the bigger offers, research and enchantments.
- Kriegsrat (War Council): once a Reich's whole research tree is done, spare Wissen buys Kriegsrat stacks, 3 Wissen each, +4 % attack and HP for every plot in this year's battle only (applied with the research buffs; the stacks clear at the end of the year). Spec: research is a finite tree, which left the Wissen-rich Reiche with nothing to spend it on.
- Recovery persists the whole match actor state (postcard + zstd) after every change instead of an event-sourced action log (to Redis when configured, with Postgres checkpoints); a crash mid-battle re-simulates the sealed year (deterministic).
- Perks are meta progression: Reich XP from finished matches unlocks perk n at Reich level n; perks are active only in casual matches.
- Picks: players start the match with a hand of 3 cards from their
offer pool (at least one troop) instead of a free pick in year 1. From
year 2 on the first offer card each year is free; further cards from the
same offer (and all of them in year 1) cost their
costin Gulden (gives Gulden a purpose). - No selling: the spec's "sell a plot (50 % refund)" action is removed. The destroy Edikte below clear a plot instead, for a bonus rather than a refund.
- Offer: 3 cards in years 1–5, one more every 5 years up to 6 from year 16 (spec: always 3). The offer can be frozen for free (Hearthstone-style): the cards left in it carry over into next year's offer, which is filled up to size; the freeze lasts one year, a reroll clears it.
- Each Reich has 9 deck cards plus 4 extra Reich Edikte in its offer pool
(spec: 3). The 4th is a destroy Edikt (Opfer): dragged onto an own plot
other than the Thron, it removes the card there for good (no refund, the
plot becomes free) for a bonus that can scale with the victim's level.
Hadewald, Toran and the Minotauren have a 10th deck card: a wall (a
tower with
atk: 0and theWalltag, drawn as a wall segment). It is placed like a tower and attacked like one, before the Thron, but never attacks; lots of HP and a small aura for neighbouring troops. - Twelve Reiche (spec: nine, mirroring the nine kings): Al'Bah'Jira, the desert realm of the sun and the city of the dead, joins as the tenth. It fights with sunfire under the Day Moon, mummies, ghosts and scarabs under the Night Moon, and plays enchantments in place of most Edikte. The Doldagor (Gargoyles), the Titans' stone wardens, are the eleventh: very hard stone troops that sink into stone sleep, broken by magic. The Duigoshz, gnome artificers without a king or towns, are the twelfth: clockwork constructs that burst when they fall, workshop towers that build tin imps, telescope marksmen and an alchemist; strong until about year 20, weak late. They have no Building cards (the lore knows only their tower homes), their economy is a tower.
- Hadewald fights with guilds, not mercenaries (spec: "mercenaries bought with Gulden"): the lore has no mercenaries, only the craft guilds of the Rat der Meister, timber and woodcraft. Banked Gulden still arm the Thron and strengthen the guild troops; the craft guilds level towers and buildings, and Holz cards pay off next to each other.
- Thron position: the Thron sits in the middle of the back row, plot (2,4) next to the back wall (spec: grid centre (2,2)). The match starts with the full inner 3×3 free to build on plus the Thron plot; plots bought later are adjacent to an unlocked one, as before, and still cost 12 Gulden +1 per plot bought.
- Enchantments (Verzauberungen) are a sixth card kind beside the spec's Thron, Truppe, Turm, Gebäude and Edikt: played onto an occupied plot whose card fits, they stay there, stack (up to 2–3×, at most 2 different per plot) and carry stat buffs and battle triggers such as lifesteal for that plot's units. Silkanda and Flügler are the pilots (3 each, replacing Chosen-buff Edikte and other spells 1:1).
- Gauntlet length: the Async Gauntlet runs 20 years (boss in year 20) with the same ruler life as the Sync Duel (spec: 30 years, 50 HP). In bot runs against same-year bot boards about two thirds reach the boss. The boss's surviving units hit the ruler like any battle, but falling in the boss year still counts that year for the score. The Sync Duel keeps year 30; the boss content is tuned for year-20 boards and gains a level per 5 years beyond, so the Duel's year-30 boss is unchanged.
- Resolution: the table is scaled to fit any window (fractional scale, sharp-bilinear upscaling, floor fills the rest) instead of a fixed internal resolution with integer scaling and letterboxing; portrait works too.
- Music is MP3 tracks in
crates/tt_client/assets/music/(menu, build phase, battle), not a full theme per Reich: build phase and battle can play the own Reich's songs, set in the tableFACTION_MUSICincrates/tt_client/src/audio.rs(Reiche without an entry use the default tracks). Sound effects are synthesised. - Plain
ws:///http://only (no TLS) for now; put a TLS proxy in front for a public browser client (it then useswss://automatically).
Deployment
One container image runs everything: the game server, which also serves the
browser client and the content (Dockerfile; multi-stage, plain docker build). Configure it with DATABASE_URL and REDIS_URL; it listens on
port 7878 and has a /health endpoint. GET /stats returns
{"online": n, "queued": n} (players connected and waiting in the Sync Duel
queue, across all instances); the main menu shows the same numbers.
docker build -t trbattler .
docker run --rm -p 7878:7878 trbattler # in-memory store, single instance
docker-compose.yml is a Docker Swarm stack behind Traefik (app replicas,
Postgres, Redis with an append-only file):
cp .env.example .env && cp .env.postgres.example .env.postgres # set TT_PUBLIC_URL, DATABASE_URL/REDIS_URL and a password
mkdir -p /home/sven/deployments/tirakan-autobattler/{database,redis}
TT_DOMAIN=thron.example.org docker stack deploy -c docker-compose.yml trbattler
Forgejo Actions (.forgejo/workflows/publish-image.yml) builds the image
only for release tags vX.Y.Z (made with scripts/release.sh patch|minor|major) and pushes latest and X.Y.Z to the Forgejo registry
(needs the REGISTRY_TOKEN secret; the optional repository variable
TT_PUBLIC_URL is baked into the browser client, unset it uses the domain it
is served from; docker build --build-arg TT_PUBLIC_URL=… locally). There
are no tests in CI: scripts/check.sh runs clippy (native and wasm), the
content lint and all tests locally before a push and on every release.
Tools
cargo run -p tt_tools -- lint # validate content
cargo run -p tt_tools -- battle --a fraxut --b echsen --year 15 --verbose
cargo run --release -p tt_tools -- balance --games 20
cargo run --release -p tt_tools -- stats # Reich + card win/loss, battle ends (draw causes), ruler life by year, tower damage shares, from 10k bot Duels + Gauntlet runs → target/stats/ (--compare DIR: deltas, paired per game with standard errors)
cargo run --release -p tt_tools -- stats --reich minotauren # only the games of one Reich (or --pair a,b for one cell); same games as a full run
cargo run --release -p tt_tools -- boss --games 10 # every boss (or --boss <id>)
cargo run -p tt_tools -- battle --a toran --boss finsternis --year 20
cargo run -p tt_tools -- towers # tower cards: stats, DPS, range reach per plot row, same-cost troops
cargo run --release -p tt_tools -- determinism --n 10000
cargo run -p tt_tools -- export-content --out client_content.bin
cargo run -p tt_tools -- game 1234:7 --database-url postgres:///trbattler_inspect --replay # inspect one stored match
Production database access and investigating a game ref: docs/OPERATIONS.md.
Tests
scripts/check.sh # clippy (native + wasm), content lint, all tests
cargo test --workspace
cargo test -p tt_sim --release -- --ignored --nocapture # performance
# Postgres store + multi-instance tests (skipped without these variables):
createdb trbattler_test
REDIS_URL=redis://127.0.0.1/ DATABASE_URL=postgres:///trbattler_test cargo test -p tt_server
Licence
Code GPL-3.0-or-later. Names, lore and texts derived from Tirakans Reiche
are used under CC-BY-NC-SA; this project is non-commercial and credits
https://tirakans-reiche.de/. Derived lore in content/ is shared under the
same licence.

