3. Rust server — modules & the Game core API

Crate layout (server/):

Cargo.toml
src/
  main.rs        # tokio runtime, axum router: static files + /ws, room manager task
  protocol.rs    # server-shell protocol adapter shim; serde DTOs live in crates/protocol
  config.rs      # server-shell balance shim; authoritative values live in crates/rules
  lab_scenarios.rs # bundled lab checkpoint setup manifest loader and restore validator
  lobby/         # Lobby API plus room task, connection writers, snapshots, dev replay, crash replay
crates/
  contract/      # semantic DTOs shared below protocol/sim/server
  protocol/      # semantic wire DTOs and compact snapshot transport encoding
  rules/         # pure domain, balance, terrain, economy, and combat rules
  ai/            # live AI controllers, shared AI strategy core, and self-play harnesses
  sim/           # reusable simulation crate; no Tokio/Axum/server transport/AI dependency
    src/game/
    mod.rs       # Game struct + public API (the seam below)
    command.rs   # SimCommand domain commands + protocol translation helpers
    map.rs       # Map model: terrain queries, materialized identity, passability
    map/catalog.rs # Bundled map discovery, loading, metadata, and catalog validation
    entity/      # Entity, EntityKind, Order state machines, grouped state, and EntityStore
    pathfinding.rs # A* over the tile grid, with optional turn-cost route shaping for tanks
    fog.rs       # per-player live visibility grids; snapshots union living teammate grids
    building_memory.rs # server-only per-player last-seen enemy building records
    anti_tank_gun_memory.rs # server-only per-player last-seen deployed enemy AT-gun arcs
    systems.rs   # orchestrator: runs services in order each tick
    services/    # per-tick services: commands, order_planner, move_coordinator, movement (incl. unit collision), combat, economy, production, construction/deconstruction, death, entrenchment, occupancy, supply, pathing, geometry, standability, line_of_sight
    replay.rs    # tick-stamped command log replay harness for determinism checks
    src/rules/projection.rs # fog-gated entity/event projection seam

Dependency policy is part of the development contract:

scripts/check-crate-boundaries.mjs checks these edges in cargo metadata and scans lower crates for server-only imports. server/src/protocol.rs, server/src/config.rs, server/crates/sim/src/protocol.rs, server/crates/sim/src/config.rs, and server/crates/sim/src/rules/mod.rs remain intentional adapters while call sites are migrated; new code should prefer the owning crate directly when that does not make local code less clear.

3.1 game::Game public API (seam between game and lobby/main)

The lobby/networking layer interacts with the simulation ONLY through this surface. Game::critical_event_state() -> Vec<PlayerCriticalEventState> exposes read-only per-seat supply used/cap, completed living building kinds, and deduplicated blocked auto-production (unit, prerequisite) pairs. The room tracks which building kinds each seat previously completed and owns chat routing and 30-second simulation-time warning cooldowns. Notification state belongs to the live session and stays outside checkpoints. Completed living buildings satisfy prerequisites; destroyed or unfinished buildings do not. game-core implementer: provide exactly these. server-shell implementer: call only these. The server shell may also serve non-simulation HTTP routes such as /wiki, /wiki/, and /wiki/{*path}. /wiki redirects to /wiki/, the player wiki: pages generated once per process by rts-wiki (server/crates/wiki) from the compiled rules plus the fixed docs/wiki data files, served as no-cache HTML by file name (/wiki/unit-tank.html). Developer docs live under /wiki/dev/: the index is generated from the allowlisted packaged Markdown docs roots (docs/context and docs/design), canonical /wiki/dev/docs/... doc pages keep the short /wiki/dev/context/... aliases, allowlisted relative Markdown doc links are rewritten under /wiki/dev with anchors preserved, and the pre-move /wiki/docs|context|design/... links redirect (308) to /wiki/dev/.... None of these routes call into Game.

pub struct Game { /* private */ }

impl Game {
    /// Create a match for the given players (ids + colors + names already assigned by lobby).
    /// Loads the hardcoded handcrafted map and assigns ordered players to fixed authored start
    /// locations. A map owns flat `startLocations`, `baseSites`, movement- and sight-affecting
    /// `elevation`, presentation-only `sun`, and static `doodads`: start locations determine its
    /// capacity, while every base site receives its authored 0–36 Steel and 0–9 Oil patches.
    /// Maps with `teamGroup` constrain each team to its own authored group and reject rosters that do
    /// not fit. Ungrouped singleton-team matches shuffle fixed start locations by `seed`;
    /// ungrouped team matches choose ordered starts from the
    /// same fixed set, preferring lower teammate spread, higher nearest enemy-team distance, lower
    /// exposure imbalance, and finally a deterministic seed-influenced tie break. No player-count
    /// layouts or player-owned natural groups exist in authored maps. Generated oil clusters place each oil patch on a unique passable tile
    /// center near the intended layout, keep one tile between oil patches, and reject sites whose
    /// Pump Jack footprint would collide with non-oil resources while preserving Resource Depot
    /// resource-distance bounds. Schema-v5 doodads are catalog-validated and id-canonicalized.
    /// Tree species share a 4.5px authoritative circular trunk. Vehicles use exact trunk
    /// standability; infantry use finite tree path cost with pass-through, without tree-avoidance steering.
    /// Wildflowers remain presentation-only. Lab-restored oil nodes are normalized to passable tile centers and
    /// keep one free tile between oil patches.
    /// AI players are spawned as normal match participants; external AI orchestration owns any
    /// controller/profile selection.
    pub fn new(players: &[PlayerInit], seed: u32) -> Game;

    /// Create a live lobby match where each AI chooses one strategy from the live profile pool.
    pub fn new_with_random_ai_profiles(players: &[PlayerInit], seed: u32) -> Game;

    /// Compatibility helper for tests that still need explicit starting Steel/Oil. Production
    /// replay/lifecycle reconstruction should use per-player `PlayerStartingLoadout` records
    /// instead.
    pub fn new_with_starting_resources(players: &[PlayerInit], steel: u32, oil: u32, seed: u32) -> Game;

    /// Compatibility helper for callers that still name AI profile setup plus explicit starting
    /// resources. AI controllers are owned by the caller, not by `Game`.
    pub fn new_with_starting_resources_and_random_ai_profiles(players: &[PlayerInit], steel: u32, oil: u32, seed: u32) -> Game;

    /// Rebuild replay playback with recorded per-player faction loadouts, map, and map metadata.
    /// Commands are injected by the replay runtime rather than live AI controllers.
    pub fn new_for_replay_with_map_metadata(
        players: &[PlayerInit],
        seed: u32,
        starting_loadouts: &[PlayerStartingLoadout],
        map: Map,
        map_metadata: MapMetadata,
    ) -> Game;

    /// Create a lab match around an already validated map/player setup. Lab rooms still use the
    /// normal `Game` simulation; the lab constructor only names the mode-specific setup seam.
    pub fn new_lab(players: &[PlayerInit], seed: u32, map: Map, map_metadata: MapMetadata) -> Game;

    /// Apply one typed, validated lab mutation and repair derived sim state before returning.
    /// Plural LabOp variants validate and commit atomically through this same seam.
    pub fn apply_lab_op(&mut self, op: lab::LabOp) -> Result<lab::LabOpOutcome, lab::LabError>;

    /// Export map-only Lab state for the dedicated editor boundary; excludes all simulation state.
    pub fn export_lab_map(&self) -> protocol::LabMapDraft;

    /// Export authoritative lab setup data as a checkpoint-backed setup container. The JSON-friendly
    /// transport name is still `LabScenarioPayload`, but the payload is `LabCheckpointScenarioV1`.
    pub fn export_lab_checkpoint_scenario(
        &self,
        name: String,
        server_build_sha: &str,
    ) -> Result<lab::LabCheckpointScenarioV1, lab::LabError>;

    /// Restore a checkpoint-backed setup into a fresh lab `Game` after validating map binding,
    /// checkpoint shape, player metadata, lab metadata, and entity-id remap metadata.
    pub fn restore_lab_checkpoint_scenario(
        scenario: lab::LabCheckpointScenarioV1,
    ) -> Result<Game, lab::LabError>;

    /// Static info for the `start` message (terrain + player start tiles). Call once.
    pub fn start_payload(&self) -> StartPayload;

    /// Queue a validated-on-apply domain command from `player`. Cheap; real work happens in tick().
    pub fn enqueue(&mut self, player: u32, cmd: SimCommand);

    /// Queue a trusted server-authored command that uses lab/dev admission limits.
    pub fn enqueue_server_authored_command_ignoring_limits(&mut self, player: u32, cmd: SimCommand);

    /// Arm one authored dev-scenario infantry source with a bounded Panzerfaust windup. Returns
    /// false for stale ids, missing combat state, or a zero-duration windup.
    pub fn start_dev_scenario_panzerfaust_windup(
        &mut self,
        attacker: u32,
        target: u32,
        windup_ticks: u16,
    ) -> bool;

    /// Ordinary retreat commands for AI-owned workers hit on the previous tick.
    pub fn worker_retreat_commands_for(&self, player: u32) -> Vec<SimCommand>;

    /// Advance the simulation by one tick. Returns per-player transient events.
    pub fn tick(&mut self) -> Vec<(u32 /*player*/, Vec<Event>)>;

    /// Build the fog-filtered snapshot for one player at the current tick. Entity visibility and
    /// visibleTiles use living-team current fog and exploredTiles use server-owned team history;
    /// resources/upgrades stay local.
    pub fn snapshot_for(&self, player: u32) -> Snapshot;

    /// Same projection as `snapshot_for`, with explicit room-projection diagnostic options such as
    /// owner-only movement paths. The default `snapshot_for` includes no movement diagnostics.
    pub fn snapshot_for_with_options(&self, player: u32, options: SnapshotOptions) -> Snapshot;

    /// Request fog-safe durable ground marks learned by one player after a prior cursor.
    pub fn ground_decals_for_player(&self, player: u32, after_revision: u32) -> (u32, Vec<GroundDecalView>, Vec<TankTrailView>);

    /// Request durable marks for an accepted selected-player union or omniscient observer view.
    pub fn ground_decals_for_observer(&self, view: &ObserverView, after_revision: u32) -> (u32, Vec<GroundDecalView>, Vec<TankTrailView>);

    /// Build a read-only privileged observer projection. `Omniscient` exposes the complete
    /// world/all-owner private detail; `Players` combines selected real-player perspectives.
    /// This value never conveys command authority.
    pub fn snapshot_for_observer(&self, view: &ObserverView) -> Snapshot;
    pub fn snapshot_for_observer_with_options(&self, view: &ObserverView, options: SnapshotOptions) -> Snapshot;

    /// Build a spectator snapshot from the union of the selected players' current fog, stale
    /// building memory, and resource rows.
    pub fn snapshot_for_spectator(&self, visible_players: &[u32]) -> Snapshot;

    /// Same projection as `snapshot_for_spectator`, with explicit room-projection diagnostic options.
    pub fn snapshot_for_spectator_with_options(&self, visible_players: &[u32], options: SnapshotOptions) -> Snapshot;

    /// Build a full-world snapshot for a room projection that intentionally exposes all state,
    /// including per-entity planning details through each entity's real owner. Normal gameplay
    /// must not use this.
    pub fn snapshot_full_for(&self, player: u32) -> Snapshot;

    /// Same full-world projection, with explicit room-projection diagnostic options.
    pub fn snapshot_full_for_with_options(&self, player: u32, options: SnapshotOptions) -> Snapshot;

    /// Player ids still alive. Humans need at least one building; AI players also need a unit.
    pub fn alive_players(&self) -> Vec<u32>;

    /// Player ids whose starting main base is still alive. AI-only live outcome checks use this
    /// objective query instead of the normal elimination rule.
    pub fn primary_base_alive_players(&self) -> Vec<u32>;

    /// Team ids with at least one alive member, in stable start/lobby order.
    pub fn alive_team_ids(&self) -> Vec<TeamId>;

    /// First alive player on a team in stable start/lobby order.
    pub fn first_alive_player_on_team(&self, team_id: TeamId) -> Option<u32>;

    /// Whether this player's team still has at least one alive member.
    pub fn team_has_alive_player(&self, player_id: u32) -> bool;

    /// Frozen score-screen rows for every match participant, in start/lobby order.
    pub fn scores(&self) -> Vec<PlayerScore>;
    /// Own losses plus witnessed enemy deaths, keyed by owner then kind; no hidden totals.
    pub fn known_losses_for(&self, player_id: u32) -> BTreeMap<u32, BTreeMap<EntityKind, u32>>;

    /// Lifetime collection for the requested player; excludes initial funds/refunds, invalid ids return zero.
    pub fn lifetime_mined_for(&self, player_id: u32) -> ObserverAnalysisResourceTotals;

    /// Authoritative observer analysis state for configured spectator-only or all-recipient audiences.
    pub fn observer_analysis(&self) -> ObserverAnalysisPayload;

    /// Remove all of a player's entities (e.g. on give-up or disconnect) so the match can resolve,
    /// without treating administrative cleanup as simulated deaths in score totals.
    pub fn eliminate(&mut self, player: u32);

    pub fn tick_count(&self) -> u32;

    /// Versioned committed-state fingerprint for final replay verification (not a per-tick API).
    pub fn replay_end_state_hash(&self) -> Result<String, String>;

    /// Authoritative commands applied so far, stamped with the tick that applied them.
    pub fn command_log(&self) -> &[CommandLogEntry];

    /// Reconstruct the player specs used to create this match for replay/crash artifacts.
    pub fn player_inits(&self) -> Vec<PlayerInit>;
}

pub type TeamId = u32;
pub struct PlayerInit { pub id: u32, pub team_id: TeamId, pub faction_id: String, pub name: String, pub color: String, pub is_ai: bool }
pub struct CommandLogEntry { pub tick: u32, pub player_id: u32, pub command: Command }
pub struct SnapshotOptions {
    pub include_movement_paths: bool,
    pub movement_paths_for_all_projected: bool
}

SimCommand is the internal command enum from game::command; live ClientMessage::Command envelopes and replay artifacts are translated into it at the boundary. Live transport metadata such as clientSeq stays in the room/connection layer and is not part of the sim command or replay command-log contract. rts-rules::faction::UpgradeKind is re-exported through game::upgrade because SimCommand::Research carries it and external AI controllers construct ordinary SimCommands. CommandLogEntry.command remains the serde Command from rts-protocol so replay JSON stays wire-compatible. StartPayload, Snapshot, Event, and PlayerScore are also serde types from rts-protocol.

PlayerInit.is_ai marks a computer-controlled player. AI players are full players in every respect (they get a start position, Resource Depot, workers, economy, and count toward win/elimination); the only difference is they have no socket. Game does not own AI controllers; the room task or tool harness asks rts-ai controllers for ordinary SimCommands and enqueues them through this API before ticking — see §8.

Lab mutation types live under game::lab. LabOp is intentionally narrow rather than a debug backdoor: entity mutations validate known unit/building kinds, real players, finite in-map positions, placement/collision legality, and stale ids before changing the world. Plural spawn, update, and delete requests accept 1–400 items, run against a cloned scratch Game, preserve input ordering, and replace live state only after the whole request succeeds. Non-move updates apply to scratch state in order; every moved entity is then removed from scratch occupancy before destinations are validated, so swaps and translations are simultaneous while destination conflicts remain illegal. Accepted batches clear stale orders and reservations where needed and repair supply, derived state, fog, and building memory once. Placement errors carry the attempted point, typed entity/feature/terrain/boundary blockers, and up to eight deterministic suggestions produced by the same standability predicate against the transactional prefix. Lab setup import/export uses checkpoint-backed LabCheckpointScenarioV1 containers: materialized map data and binding live beside an embedded GameCheckpointV1 payload, and small lab metadata carries setup name, exported tick, selected vision, god-mode players, and optional source entity-id remap rows. Restore validates map binding, checkpoint payload, player and lab metadata, repairs derived state, and returns the id remap for callers that need to reconcile UI selection. Snapshot-only projections, transient events, projectile runtime state, active commands, production queues, rally plans, cooldowns, and command logs are not part of the setup format. Legacy kind:"labScenario" setup JSON is rejected before it can mutate a lab room.

Replay end-state verification uses optional endStateHash: { algorithm, digest } and an ordered eliminations: [{ tick, playerId }] list in schema-3 artifacts. ReplayStartComposition records room-authored administrative removals on give-up/disconnect; playback applies them after that tick’s systems (or at the start boundary for tick-zero removals), before keyframes and verification. The final hash is captured after the same removal, so a surrender does not create a false divergence. ReplayArtifactV1::verify_end_state requires the exact final tick and returns verified/mismatched, absent (older artifacts are unverified), or an unsupported-algorithm/error result. Replay sessions check once on reaching the end through playback or seeking, log status and cost, and show a warning on mismatches or unavailable algorithms. Seeking backward re-arms verification. A mismatch signals divergence; it does not distinguish nondeterminism from build/rules/platform drift or corruption.

The algorithm rts-end-state-json-sha256-v5 hashes its ASCII identifier followed immediately by compact serde_json serialization of the explicit ordered projection in game/checkpoint/fingerprint.rs. SHA-256 is streamed through a 64 KiB buffer. Struct fields have fixed serialization order; entity ids and unordered fog/memory collections are sorted by their checkpoint adapters. Numbers use serde_json’s locale-independent decimal representation, not native-endian memory, pointer addresses, Rust Hash, or debug text. Valid simulation floats are finite and their exact round-trip values participate without rounding/tolerance. Arrays retain semantic order. Changes to projection/serialization semantics require a new algorithm identifier. Version 5 adds Cosmic Energy balances and pending insight credits. Version 4 includes committed pivot-vehicle forward/reverse choices. Version 3 removes the redundant mutable Dao field; simulation schema 7 records Adept identity in kind. The map uses its existing canonical materialized binding; map content is immutable during live play. The projection includes all committed authoritative owners (players/private economy/scores/upgrades, entities/orders, fog/memories, active abilities/projectiles, decals/trails, world combat signals, construction state, RNG seed/draw count and an eight-draw non-consuming future-output probe). Command history, unapplied pending commands, build SHA, room/session state and rebuildable derived caches are excluded. Pending input has not affected the final committed state and is not replayed. When adding a GameState field, update this projection alongside the ownership/checkpoint registry. This is a fingerprint, not a saved final checkpoint; playback must reconstruct the state to compare.

Hashing runs once at artifact finalization and once per completed playback traversal, never every minute or tick. It borrows large entity/projectile/decal stores, copies only ordered fog/memory adapters and a sorted entity-reference index, and does not clone/serialize the command history or validate/rebuild an entire checkpoint. Cost depends on final-state size, not duration. The ignored release test end_state_hash_cost measures 2,000 total entities on the four-player 166×166 map plus a 200,000-command history. A local release run (100 hashes, four players, 2,000 entities, 200,000 historical commands) measured 8.5 ms median, 11.0 ms p95, and 18.0 ms maximum. This is a finalization-only synchronous cost below one 33.3 ms tick on that machine, not a production-hardware latency guarantee; unusually large decal/projectile state can cost more. Runtime logs expose hash_us for capture and verification. The simulation now pins its RNG stream across native and WASM (see §3.1.3); the future-output probe additionally detects accidental generator drift even when seed/draw counters agree. Hash portability still does not promise that every floating-point simulation path will remain identical across builds/platforms: exact differences must be reported, not rounded away. A fixed three-tick full-state fingerprint runs natively and under WASM alongside the RNG known answers.

3.1.1 Game State Ownership Registry

Game is a private ownership tree with only two top-level state roots: GameState (server/crates/sim/src/game/state.rs) for durable authoritative state and setup/replay compatibility metadata, and DerivedState (server/crates/sim/src/game/derived_state.rs) for rebuildable cache/search state. Both owners are private to crate::game; public Game methods remain the only seam for lobby, replay, lab, AI, server, and snapshot callers.

This registry is the source of truth for classifying fields currently owned by GameState or DerivedState. Any change that adds, removes, or changes the semantics of a GameState or DerivedState field must update this table in the same change. The categories are:

No current state field is classified as transient; room/session transient state remains outside Game in server/src/lobby/. Field names in this table must match current GameState or DerivedState fields exactly; rts-archcheck treats missing, stale, or wrongly categorized rows as architecture failures.

FieldCategoryCheckpoint policyEvidence and notes
mapauthoritative/serializedInternal cold checkpoints serialize the full live Map value. Public GameCheckpointV1 payloads do not embed a map body; they carry mapBinding facts and import only with the exact container-supplied Map. See §3.1.3.Game::new_inner_with_map stores the generated or supplied map; systems::run_tick, pathing, fog, placement, resource setup, and start_payload all read it. Runtime ownership and external artifact composition are intentionally separate contracts.
entitiesauthoritative/serializedSerialize the full EntityStore, including shared disciple entry targets, Proving Grounds training plans/active trainee production, tournament entrants and pre-rolled winners in movement/production groups, stable entity ids, allocator/high-water state, HP, orders, queues, movement state, selected waypoints, path goals, committed pivot-recovery goals/facing/timeouts, waypoint-bound normal forward/reverse choices (both directions persist through hull turns and checkpoint restore; new orders, route changes, waypoint consumption, or committed recovery clear them), weapon cooldowns, Methamphetamines Rifleman post-shot lock timestamps, ability charges and charge-recharge timers, episode-keyed firing-reveal reaction gates, combat state (including the materialized tank_plus owner-research flag, refreshed before movement and after production each tick so new and existing Tanks share modifiers), per-unit kill totals and last-damaging entity attribution, Novice Charge duration and cooldown, Disciple insight, its exact fractional remainder, pending non-passive Cosmic Energy credits (settled to the owner before death removal), a derived nonserialized Breakthrough aura flag (rebuilt before each movement pass), permanent Dao and replaceable chosen Dao intent, production/build progress, worker repair target and work timer, repair-target-owned fractional repair credits, rally plans and each producer’s next line-rally sequence ordinal, Scout Plane source-car/orbit/remaining-lifetime state, resource reservations, extractor fractional unsupported-decay damage (serialized with extractor harvest progress), body/weapon/setup facing, Tank commander MG facing and secondary target id, and entity flags.systems::run_tick mutates the store every tick; snapshots, score, survival, command validation, replay determinism tests, and the Phase 0.5 comparator all treat entity state as semantic authority. Chosen movement paths and aerial orbit state live on entities, not in pathing. Scout Plane entities are excluded from standard fog sight stamping and contribute independent team aerial vision through the dedicated smoke-only pass.
fogauthoritative/serializedSerialize the latest 15 Hz actionable visibility sample and its bounded per-viewer firing-reveal provenance map.recompute_live_fog separately records whether each sampled entity needs its firing reveal for targeting and whether the stamped terrain tile lacked ordinary sight. Combat consumes the first fact; snapshot visibleTiles removes only terrain-reveal-only stamps. Phase 0.5 compares per-player actionable tiles as semantic state.
building_memoryauthoritative/serializedSerialize remembered building entries and cleared-observation ticks per player.BuildingMemory::refresh records last-seen enemy building state, while match setup seeds entity-backed neutral buildings authored into the map for every player. Hidden destroyed entries are removed only after the footprint is scouted again; that clear tick prevents older positive memory from another selected player from resurrecting the building in union observer projections. Spectator/player snapshots project remembered buildings while fogged.
resource_memoryauthoritative/serializedSerialize static resource identities, initial quantities, and per-player last-observed remaining quantities and ticks, retaining explicit depletion records.Tick/setup/Lab fog-memory refresh observes only living-team visible tiles; player and selected observer projections resolve this state without mutating it. Checkpoints and replay keyframes restore resource knowledge alongside building memory. Legacy launch checkpoints without the field seed at tick zero; nonzero checkpoints missing it are rejected because historical knowledge cannot be recovered from the current world.
anti_tank_gun_memoryauthoritative/serializedSerialize last-observed deployed enemy Anti-Tank Gun position, facing, owner, and observation tick per player.AntiTankGunMemory::refresh records ordinary team sight and actionable firing reveals, retains stale records through hidden movement/teardown/destruction, and clears them only when that player’s team observes the gun changed or the remembered position empty; observer snapshots select the requested players’ stores.
playersauthoritative/serializedSerialize all PlayerState rows, including id/team/faction/name/color/start tile, current Steel/Oil/Cosmic Energy, supply, AI flag, score counters, unit/building loss counts by kind, per-recipient witnessed enemy loss counts by owner/kind, mined-resource lifetime totals, rolling mined-resource income history, completed upgrades (including the temporary AntiTankGunUnlock Engineering Complex ownership-history hack; TODO: remove when tech rules are revisited), and the paused/Steel-floor/Oil-floor Auto-Build policy.Economy, command authority, team relations, alive checks, scores, observer-analysis resource income and losses, faction-specific tech, automatic-production spending, and snapshot resource/settings rows are all read from players.
pendingauthoritative/serializedSerialize unapplied pending commands unless a future checkpoint caller explicitly proves it captures only immediately after command drain with pending empty.Game::enqueue appends commands between ticks; tick_inner drains pending, records them in command_log, and applies them. Dropping a non-empty queue would skip authoritative player/AI intent.
command_logcompatibility metadataSerialize command history for replay/crash/API continuity; do not replay it during normal checkpoint import unless building a replay artifact.Game::command_log is public, schema 3 replay artifacts finalize the stored launch-time ReplayStartComposition with this log, and tick logic only appends/applies new pending commands instead of reading old log entries.
tickauthoritative/serializedSerialize the exact tick count.tick_inner increments it before systems, logs commands with it, drives expirations/cooldowns, passes it to projection/runtime stores, and advances PathingService to the same tick.
last_world_combat_tickauthoritative/serializedSerialize the most recent hostile-weapon activity tick.Records exact observation time without exposing it to clients. Snapshot projection uses the separate published deadline below.
last_world_combat_positionauthoritative/serializedSerialize the latest authoritative combat-area centroid before publication.The point is held between 15-tick publication boundaries so direction changes do not expose live weapon cadence.
world_combat_active_through_tickauthoritative/serializedSerialize the last published 15-tick boundary through which the global signal is active.Keeping published state separate from exact observation prevents new activity inside a quantization bucket from suppressing an already-active signal while preserving boundary-only changes.
world_combat_positionauthoritative/serializedSerialize the published coarse combat point used while the global signal is active.The point is snapped to a 32-tile grid and shared identically with all projections for direction-only background audio.
lingering_sightauthoritative/serializedSerialize all active death-vision sources and their expiry ticks.retain_active_visibility_sources prunes by tick; the next 15 Hz fog sample stamps active sources into team fog, affecting command legality, combat visibility, and snapshots.
firing_revealsauthoritative/serializedSerialize active firing-reveal sources with stable episode-start and expiry ticks.Anti-Tank Gun and artillery/mortar reveal logic records temporary actionable sight. Repeated shots extend one continuous episode without changing its start; the next 15 Hz fog sample stamps active sources into viewer fog until a later sample observes expiry.
smokesauthoritative/serializedSerialize the full SmokeCloudStore, including next id, active clouds, pending clouds, locations, radii, spawn/due/expiry ticks.Smoke blocks line of sight, combat projection, and the next authoritative fog sample; tick_inner retains active smoke and systems may resolve pending smoke.
trenchesauthoritative/serializedSerialize the full TrenchStore, including deterministic trench ids, terrain positions, discovery/memory data, and any store allocator state.Trenches are persistent neutral terrain outside EntityStore; entrenchment services create/discover/update them and snapshots project current plus remembered trench terrain.
ground_decalsauthoritative/serializedSerialize compact typed append-only mark rows, checkpointed active tank trails, immutable finalized trail chunks, stable id allocators, the shared global revision and creation/discovery log, and per-player first-discovery revisions; rebuild derived tile indexes after restore. Historical tank trails are explicitly approximate and capped at 4,096 finalized chunks so cosmetic evidence cannot grow server memory without bound.Death and delayed mortar/artillery impacts create ordinary records. Visible tanks paint precise client-local tracks from fog-filtered entity snapshots. The server separately samples approximate historical poses at 4-world-pixel/8-bit-heading precision after material travel or rotation, finalizes spatially bounded chunks, and clients reconstruct their swept left/right tread footprint after refresh or later discovery. A trail becomes discoverable when current team fog first intersects a tile in its swept-footprint bounds. Historical tread geometry is an explicit best-effort-cosmetic exception to positional fog secrecy: disclosing that bounded immutable chunk may reveal nearby hidden tread geometry, but no live entity or command state, while client rendering clips permanent rasterization to individual currently visible map tiles. Snapshots carry only the current tick’s bounded, fog-scoped revisions through the existing ground-decal delta; reliable requests repair older accepted player/observer ranges.
ability_runtimeauthoritative/serializedSerialize active ability runtime state, object ids, world objects, projectiles, cooldown-linked runtime payloads, and expiry/return data.AbilityRuntime owns deterministic active instances and non-entity world objects; systems and snapshots read it for Ekat return markers, line projectiles, anchors, and owner/enemy projection.
mortar_shellsauthoritative/serializedSerialize all scheduled mortar impacts with owner, attacker, impact point, and impact tick.MortarShellStore::schedule records delayed impacts; later ticks resolve area damage/events even if the firing mortar dies before impact.
artillery_shellsauthoritative/serializedSerialize all scheduled artillery impacts with their owners, source data (including fixed launch coordinates used for shield crossing), impact points, and impact ticks.The artillery store mirrors the delayed-shell contract used by the tick pipeline; dropping it would cancel future area damage and reveal/event output.
disciple_shotsauthoritative/serializedSerialize detached magic-orb target, owner, source/endpoint, damage, launch-rank penetration, and impact tick; restore and fingerprint pending impacts.shot::resolve_orbs applies the locked hit after the 100 ms release plus flight at 650 px/s (minimum 60 ms), rounded up to a simulation tick. Caster death does not cancel a launched orb; dead/missing/untargetable victims are ignored. Protection and shields apply at impact.
panzerfaust_shotsauthoritative/serializedSerialize all launched Panzerfaust loaded shots with owner/source facts, locked target id, launch-safe impact point, and impact tick.PanzerfaustShotStore::schedule records detached loaded-shot impacts; later ticks resolve the direct damage/event even if the firing Panzerfaust dies before impact.
seedcompatibility metadataSerialize the original match seed as setup/replay metadata. Do not use it as a substitute for rng.Constructors and replay artifacts expose seed; the current map is stored separately and the current random stream lives in rng.
starting_loadoutscompatibility metadataSerialize per-player starting loadout records for replay/setup compatibility.Replay constructors and artifacts persist these records so mixed faction/resource starts can be reconstructed without a global resource pair.
map_metadatacompatibility metadataSerialize stable authored map identity/version metadata alongside the map.Replay/lab setup paths expose map metadata; it identifies the authored map but is not the live terrain grid used by systems.
active_construction_sitesauthoritative/serializedSerialize the set when checkpointing a post-tick state that may immediately produce snapshots; otherwise it should normally be empty at the next tick start.tick_inner clears it before systems; construction_system inserts sites that received progress this tick; snapshot passes it to projection so same-tick construction progress is visible.
lab_god_mode_playersauthoritative/serializedSerialize the canonical enabled-player set and resync mirrored entity invulnerability flags after import.Lab ops mutate the set; sync_lab_god_mode_flags mirrors it onto unit/building invulnerability, and damage checks consume those entity flags.
starting_loadoutcompatibility metadataSerialize until legacy/global-starting-resource compatibility constructors are retired. Checkpoint import should prefer starting_loadouts for per-player setup facts.The field is set by setup constructors and dev scenarios but does not feed the per-tick systems after match creation.
rngauthoritative/serializedSerialize the exact current generator state or an equivalent deterministic draw-stream state. Re-seeding from seed is not valid after any random draw.systems::run_tick passes &mut self.state.rng into combat damage/miss logic; Phase 0.5 probes cloned RNG output as semantic state.
final_spatialderived/rebuildableDo not serialize. Rebuild with SpatialIndex::build(&entities, map.width, map.height) after import, after lab mutations that change entity positions/existence, and after any derived-state wipe.DerivedState owns the final post-tick spatial index used by snapshots. tick_inner stores the final systems::run_tick spatial result, and Phase 0.5/2/4 checkpoint proofs compare snapshots after clearing and rebuilding it.
pathingderived/rebuildableDo not serialize reusable pathing cache/search entries or precomputed graph tables. Recreate PathingService with the live map content key, default budget, cache capacity, and current tick alignment during import, map replacement, or a full derived-state rebuild.PathingService owns cache/search bookkeeping plus PathGraph: immutable authored-map/profile edges, page-COW dynamic edge tables, the exact ordered building topology key (id, kind, pos_x_bits, pos_y_bits), and a monotonic table generation. Chosen unit paths, movement phases, waypoints, path goals, and throttling remain serialized on entities. Entity-only Lab repair retains graph pages but clears route-cache/search residency at the legacy boundary; map replacement clears the graph. Phase 0.5/2/4 tests prove clearing this derived owner does not change semantic state or fog-filtered snapshots.

The Phase 0.5 and Phase 2 derived-state wipe harnesses confirm the current derived boundary: only final_spatial and pathing are cleared and rebuilt. Every current GameState field is treated as authoritative or compatibility metadata until a later phase adds a deterministic rebuild proof and updates this registry. No current field has an unresolved ownership category or checkpoint-policy blocker.

3.1.2 Ownership guardrails and checkpoint-readiness audit

server/crates/archcheck turns the registry above into an executable guardrail. The check-sim-architecture command fails if:

Durable state owners belong under GameState; rebuildable cache/index/search owners belong under DerivedState. Services may own invariants and narrow mutation/query APIs, but long-lived state that changes future authoritative behavior must be stored in the explicit tree. Room/session exceptions stay documented in §3.2 and server/src/lobby/: sockets, room identity/lifecycle, replay session cursors/keyframes, replay branch seeds, lab timeline keyframes and durable replay baselines/operation entries, selected vision, participant capabilities, AI controller memory, persisted match-history writes, and test fixtures are outside the cold checkpoint contract unless a future plan promotes them into authoritative recorded actions.

Private checkpoint export/import remains internal test machinery. GameCheckpointV1 payload helpers under rts-sim::game are used by the semantic comparator and validation tests; they do not define a public route, command, replay artifact format, lab setup format, UI affordance, or lobby/server call path by themselves. Lab entity mutations rebuild final spatial state and clear pathing cache and dense-search residency at the existing repair boundary, while retaining the map-keyed graph so building changes can patch its dynamic pages locally. Lab map replacement and checkpoint restore replace the full DerivedState shell, including all graph tables.

Phase 7 release audit for the ownership sequence:

Remaining follow-up product decisions are deliberately outside this checkpoint plan: whether to replace in-process replay/lab keyframes with checkpoint keyframes, and whether a separate product plan should expose any public checkpoint save/load surface with rollout observability.

PlayerInit.team_id is canonical team identity. Phase 1 preserves FFA gameplay by assigning each seated player a unique nonzero team by default; deserialized or hand-built fixtures with team_id == 0 are normalized to team_id = id when constructing a Game. Relationship helpers on Game are available for future team-aware systems: team_of_player, same_team_player, same_team_owner, is_enemy_player, is_enemy_owner, and allied_player_ids. Neutral owner 0 is never allied with a player.

PlayerInit.faction_id is canonical faction identity. The default current faction is kriegsia, and the server/lobby layer validates requested or recorded faction ids before match assembly. That policy is separate from rules::faction catalog existence: normal lobby, AI, self-play, and dev starts default missing requests to Kriegsia, explicit kriegsia and ekat requests are accepted as playable factions, replay paths require explicit recorded faction ids, and phase2_empty_fixture is accepted only by test-fixture contexts. The lower rules/sim layer also fails closed: empty faction ids may default only at the narrow compatibility boundary, while unknown non-empty ids get no faction catalog loadout, no starting entities/resources, no supply credit for faction units/buildings, and no legal build/train/research/gather/ability surface.

Command validation, queued attack promotion, combat target acquisition, direct damage attribution, shot interception, support-weapon splash attribution, worker-retreat metadata, and under-attack notice routing use TeamRelations snapshots derived from PlayerState. Hostile target checks must call is_enemy_owner through that relationship surface rather than relying on raw owner != player; this covers explicit attack commands, ordered attack retention, attack-move and idle auto-acquisition, shoot-while-moving target retention, Anti-Tank Gun tank preference, hostile building target acquisition, direct-fire damage attribution, and direct-shot victims. Raw owner == player checks remain correct for strict authority and economy surfaces such as selected-unit ownership, production/research/cancel authority, build/gather ownership, rally control, supply, upgrades, and resource spending. Snapshot entity visibility and visibleTiles use the union of current fog from living teammates on the recipient’s team. A defeated or disconnected teammate has no live entities and no longer contributes current sight; a defeated player whose team still has a living member still receives that surviving team vision. exploredTiles is accumulated authoritatively from the effective team fog after all ordinary, Scout Plane, lingering-death, and firing-reveal stamps, then persisted in checkpoints. Allied visible entities project full read-only inspection details, but command authority, economy, resources/supply/upgrades, rally/order plans, ability controls, and debug path overlays remain exact-owner-only. Combat target ids and weapon facing for allied entities are projected only when the target is team-visible, so allied inspection does not reveal hidden enemy ids or directions. Attack events may carry a closed weaponKind feedback hint, but it is added only to attack events that were already projected and must not change event recipients or reveal hidden target facts. Missed direct shots emit a separate miss event to that same projected attack-recipient set and carry only the target id, so the client can anchor text to an already visible unit without receiving a hidden position. Victory resolution is team-aware: the room task ends 2+ player matches only when at most one nonzero team still has an alive member, and a defeated player does not receive an individual loss screen while any teammate keeps that team alive.

3.1.3 GameCheckpointV1 Embeddable Payload Contract

GameCheckpointV1 is the first public checkpoint payload contract. It is a versioned UTF-8 JSON text payload that can be embedded inside a replay artifact, lab setup container, match-start artifact, or debug document. It is not a standalone product file format, network command, route, UI option, replay schema change, or lab schema change by itself. Schema 3 replay artifacts may embed a checkpoint at a nonzero start tick; replay start capture rejects games with pending commands so playback cannot duplicate pending intent. Their top-level command log retains only commands after that tick, and their top-level seed, player, and starting-loadout metadata must agree with the checkpoint start state or artifact validation rejects them. The internal implementation exports Game + supplied map binding through explicit DTOs to JSON text bytes, imports only with the exact container-supplied Map, and rebuilds derived state before returning a live Game. Export sorts entity DTOs by id so normalized payload text does not depend on entity-store iteration order, and rejects payloads above the same v1 byte limit enforced by import.

The payload schema is named rts.gameCheckpoint; the current emitted version is 2. Field names are camelCase. DTOs must be explicit Rust types with serde support; do not serialize private GameState, Entity, store, service, or snapshot internals directly as the stable persisted contract. Persisted DTOs should use strict deserialization (deny_unknown_fields or an equivalent manual check) except for explicitly versioned compatibility metadata. Unknown required features must fail closed; unknown optional features may be ignored only when the schema says the field is non-authoritative.

Top-level shape:

{
  "schema": "rts.gameCheckpoint",
  "version": 2,
  "compatibility": {
    "createdBy": "server|replay|lab|debug",
    "serverBuildSha": "...",
    "simSchemaVersion": 9,
    "rulesVersion": 1,
    "protocolVersion": 1,
    "requiredFeatures": [],
    "optionalFeatures": []
  },
  "mapBinding": {
    "name": "Chokes",
    "schemaVersion": 2,
    "contentHash": "...",
    "materializedMapHash": "...",
    "width": 96,
    "height": 64,
    "playerCount": 2
  },
  "seed": 1234,
  "tick": 900,
  "rng": {
    "algorithm": "rts-xoshiro256pp-pcg32-rand086-draws-v1",
    "seed": 1234,
    "drawsConsumed": 0
  },
  "players": [],
  "startingLoadouts": [],
  "startingLoadout": {},
  "entities": {},
  "pendingCommands": [],
  "commandLog": [],
  "commandLogMetadata": {},
  "fog": {},
  "buildingMemory": {},
  "lingeringSight": [],
  "firingReveals": [],
  "smokes": {},
  "trenches": {},
  "abilityRuntime": {},
  "mortarShells": [],
  "artilleryShells": [],
  "discipleShots": { "shots": [] },
  "panzerfaustShots": [],
  "activeConstructionSites": [],
  "labGodModePlayers": []
}

The rng field is a deterministic draw-stream descriptor. The portable algorithm is Xoshiro256PlusPlus from exactly rand_xoshiro 0.6.0 on all targets, including wasm32. PortableRng expands the u64 seed with eight PCG32 words (multiply by 6364136223846793005, add 11634580027462260723, then XSH-RR output after advancing), writes them little-endian, and interprets the resulting bytes as four little-endian u64 Xoshiro state words. This preserves the former 64-bit SmallRng initialization, rather than Xoshiro’s different SplitMix64 initializer. Each u32 draw advances Xoshiro once and takes its upper 32 bits.

TrackedRng counts these u32 transitions in drawsConsumed. Its u64 draws consume two u32 transitions, low word first; byte fills consume little-endian u32 words and discard unused tail bytes. Import reseeds and advances exactly that many transitions. Re-seeding alone is invalid after any draw. Combat call order is unchanged: conditional miss checks and MG spread draws consume the same stream in system/entity iteration order. Sampling is pinned to rand =0.8.6: f32 standard draws use the upper 24 bits of a u32, MG spread uses its inclusive f32 uniform sampler, and start-location Fisher-Yates shuffle uses its u32 index sampler (map sizes fit u32). Seeded AI/profile selection and tools also use PortableRng; random live-profile indexing uses a fixed u64 sampler, preserving historical 64-bit selections and draw consumption on all targets. Changes to expansion, sampling, or draw order require a new algorithm identifier and compatibility review. Fixed answer tests run natively and under WASM.

The former rts-small-rng-0.8-draws-v1 descriptor is rejected by the existing incompatible-algorithm error, because its stream was target-dependent. The checkpoint JSON shape/version is unchanged; algorithm compatibility is checked separately. Bundled setup checkpoints are relabeled because their 64-bit stream is preserved. Old external checkpoints/replays carrying the old descriptor must be regenerated; command-only legacy replays use the portable stream from now on.

commandLog carries replay/API/crash continuity history. Normal checkpoint import installs the log as metadata and must not replay it to reconstruct state. commandLogMetadata records the command DTO/protocol version, first and last command ticks, whether the log is complete from tick zero, and any replay-base tick used by a containing artifact. Replay containers may choose to store a separate authoritative command stream, but they must not infer live state by replaying commandLog during checkpoint import.

Map policy:

Concealment applies to units, not buildings or doodads. Sight rays traverse at most four concealment tiles, excluding the origin and including the target. Direct-fire rays use the same four-tile total depth into cover, excluding the origin tile. A shot may leave the forest it starts in and enter another forest, but cannot leave any forest it enters from open ground. Thus firing out of cover or into visible cover is allowed, while firing through an intervening forest at units or buildings beyond it is blocked, even with a plane, ally, or side spotter revealing them. Mortars retain indirect fire and do not require a clear direct-fire ray. This lets a unit at a forest edge retain normal outward vision while limiting vision through a forest interior. Owners and allies always receive their units. Enemy projection, auto-acquisition, explicit attack validation, and retained targets reject a concealed unit unless a hostile unit is within two tiles measured between body edges, or that unit has fired. Close detection is shared with the spotter’s team, remains active for one second after separation, and projects the target normally; smoke suppresses it. Firing creates the existing entity-scoped reveal, outline-only presentation, and half-second counterfire reaction delay. The terrain remains normally lit when ordinary sight already covers it; only a tile lacking ordinary sight stays presentation-dark. Concealed deaths do not publish positional death events or global death decals. No-vehicle tiles seed vehicle-body occupancy only, so vehicles path around them while infantry can traverse the same tile. Damage-reduction tiles reduce incoming direct, area, loaded-shot, and ability-projectile damage by 25% after existing weapon/armor/facing and entrenchment policy, rounding a non-zero fractional result up. Slow-movement tiles apply a 0.75x movement-budget multiplier from the unit-centre tile and multiply normally with road, upgrade, breakthrough, and ability movement modifiers. All five sparse layers are independent and may overlap at one coordinate.

Field map for Phase 2 DTO conversion:

Runtime fieldGameCheckpointV1 strategy
mapExcluded as a body; represented by mapBinding. Import writes the exact container-supplied Map into GameState.map only after binding validation succeeds.
entitiesEntityStoreV1 with allocator/high-water state and explicit entity DTOs. Entity DTOs must cover stable ids, owners, kind, HP, flags, carried Escape Treasure source and autocast-disabled flag, per-unit kill totals, last-damaging owner/entity attribution, construction/production/resource state (including whether an unfinished scaffold’s construction cost was paid and the optional Resource Depot producer id for a queue-owned extractor scaffold), combat cooldowns, targets, bounded reveal-reaction gates, body/weapon/setup facing, entity-local active orders, queued order intents, selected movement paths, selected waypoints, path goals, bounded committed pivot-recovery state, waypoint-bound pivot forward/reverse choices, rally plans and each producer’s next line-rally sequence ordinal, Scout Plane source-car/orbit/remaining-lifetime state, reservations, occupants/transport-like references if added later, and all entity-local timers.
fogFogStateV1 latest sampled visibility grids plus bounded per-viewer firing-reveal provenance and close-detection expiry ticks. The sampled provenance may lead or trail the current source list by one simulation tick, and ids remain bounded by the entity allocator high-water mark.
building_memoryBuildingMemoryV1 remembered enemy-building entries and cleared-observation ticks per player, including the last-seen state and footprint facts needed for projection after restore.
anti_tank_gun_memoryAntiTankGunMemoryV1 remembered deployed enemy Anti-Tank Gun position/facing entries per player, preserving fog knowledge across replay and Lab keyframe restore.
playersPlayerStateV1 rows with id, team id, faction id, name, color, start tile, resources, supply, AI slot flag, score counters, unit/building loss counts by kind, per-recipient witnessed enemy loss counts by owner/kind, mined-resource lifetime totals, rolling mined-resource income history, completed upgrades, and Auto-Build pause/resource-floor settings.
pendingpendingCommands entries with issuer, command DTO, admission/lab context, and original order. Import preserves them so the first post-restore tick drains them exactly once.
command_logcommandLog plus commandLogMetadata. It is compatibility metadata, installed but not replayed by normal import.
tickTop-level tick, serialized exactly. Timers and expiry ticks remain absolute tick values.
last_world_combat_tick, last_world_combat_position, world_combat_active_through_tick, world_combat_positionOptional top-level activity tick, pre-publication point, bounded 15-tick publication deadline, and published coarse point. Points must be finite and inside the bound map.
lingering_sightLingeringSightSourceV1 entries with owner/team visibility, position/radius, and expiry tick.
firing_revealsFiringRevealSourceV1 entries with revealer, viewer/team policy, stable episode-start tick, position or source facts, and expiry tick.
smokesSmokeCloudStoreV1 with next id, active clouds, pending clouds, locations, radii, spawn/due/expiry ticks, and owner/source facts.
trenchesTrenchStoreV1 with deterministic trench ids, geometry, occupation/discovery/memory state, and allocator state.
ability_runtimeAbilityRuntimeV1 with active ability instance ids, cooldown-linked runtime payloads, world objects, projectiles, return/expiry data, owner facts, and any visibility-relevant projection state.
mortar_shellsMortarShellStoreV1 scheduled impacts with owner, attacker/source, impact point, damage/reveal facts, and impact tick.
artillery_shellsArtilleryShellStoreV1 scheduled impacts with owner/source, scatter/impact point, damage/reveal facts, and impact tick.
disciple_shotsDetached magic-orb impacts, capped at 4,096 on import; player/allocated entity references, in-map coordinates, damage, and future impact ticks are validated.
panzerfaust_shotsPanzerfaustShotStoreV1 scheduled loaded-shot impacts with owner/source facts, locked target id, launch-safe impact point, and impact tick.
seedTop-level seed compatibility value. It is retained for setup/replay metadata and for rng.seed, but it is never enough to restore current RNG state by itself.
starting_loadoutsstartingLoadouts compatibility records, preserving per-player faction/loadout/resource start facts.
map_metadataFolded into mapBinding.name, schemaVersion, and contentHash; not duplicated as an independent state body.
active_construction_sitesactiveConstructionSites entity-id set. Import validates ids against entities; normally empty at tick boundaries but preserved for same-tick snapshot parity.
lab_god_mode_playerslabGodModePlayers player-id set. Import validates players and resyncs mirrored entity invulnerability flags after restore.
starting_loadoutstartingLoadout legacy compatibility object until global-start constructors are retired. Import prefers startingLoadouts when both are present and rejects contradictory values.
rngTop-level rng draw-stream descriptor with algorithm, seed, and consumed draw count.
final_spatialOmitted. Rebuild with SpatialIndex::build(&entities, map.width, map.height) after import and after any import repair.
pathingOmitted. Recreate PathingService with the live map content key, default budget, cache capacity, and current tick alignment; selected unit paths and goals are serialized on entities.

Snapshots, compact snapshots, fog-filtered events, observer projections, selected debug-path projections, pathing caches/search queues, room sockets, connection buffers, replay playback cursors/keyframes, replay branch runtime, lab timeline history, match-history write tasks, AI controller memory, and test fixtures are outside GameCheckpointV1 unless a later phase promotes one of them into explicit authoritative DTO state.

Validation model and bounds:

Errors returned to artifact-loading surfaces use stable codes and short user-facing messages for malformed JSON, unsupported version, unsupported required feature, payload/container too large, map not found, map schema/hash/materialized binding mismatch, count cap exceeded, invalid player/faction or unit kind, and incompatible RNG algorithm. Developer-only detail, including the exact duplicate id, dangling reference, field path, or invariant that failed, is logged or exposed only in debug tooling. The importer must validate all of this before constructing a live Game; partially constructed state is not allowed to escape.

Compatibility policy is strict. Same-version readers may add optional compatibility metadata only when old readers can ignore it without changing authoritative state. Adding, removing, renaming, or changing the meaning of authoritative fields requires a new checkpoint version and either an explicit migrator or a stable rejection reason. Existing replay and lab assets remain on their current schemas until their phases introduce containers around this payload. Simulation schema 2 adds the authoritative construction-cost payment receipt; schema 4 adds compact, owner-attributed approximate tank-trail history. Checkpoint version 1 and simulation schemas before 4 are rejected rather than guessing at missing authoritative trail ownership or converting old rows.

The canonical Hellhole server benchmark is a direct Game-API harness, not a live room. Running scripts/hellhole-perf-harness.sh restores fixed-roster-hellhole, issues its deterministic Lab movement commands through the public Lab command seam, replenishes missing central units through a single replayable SpawnEntities batch before the next tick, calls tick(), and produces one full-world snapshot through the normal compaction and MessagePack encoding path for every tick. It starts no HTTP listener, WebSocket, or browser and does not pace itself from wall time, so a slow renderer cannot become its bottleneck. The scenario is one coherent 2v2 match: Players 1 and 3 share a team, as do Players 2 and 4. The separate checked-in snapshot stream is the client-only lane and records Player 1’s normal fog-filtered body and recipient events, including shared team visibility. A live Lab server and Pixi client may be run together only through the explicit --integrated mode for visual/end-to-end inspection; that mode is not server-isolation evidence.

The churn driver runs before every tick. Players 1 and 2 are mortal; the driver tracks their authoritative unit ids and original kinds, preserves spent Panzerfaust kinds, and restores each owner’s canonical 77-unit roster. A replacement that dies during its first tick is recovered by the owner-count backstop even though the driver never observed its id. Placement considers at most 504 nearest-center candidates, builds body occupancy once per missing request, accounts for earlier planned spawns, and emits at most one spawn batch. Unresolved requests are reported and retried. Game::lab_owned_units and Game::lab_plan_unit_spawns are the typed Lab queries at this seam; callers do not inspect simulation stores.

Players 3 and 4 remain invulnerable. At every 30-tick boundary the driver statelessly ranks their 77 ids from scenario seed, player, epoch, and id, selects exactly 43, and sends one unqueued move to a deterministically selected passable integer tile in the active diagonal endpoint corridor. The endpoint leg still changes every 900 ticks. Request ids, selection, jitter, and replay operations are deterministic across fresh runs and Lab seek reconstruction.

The former static Hellhole’s 8.0x target is not comparable to this churn workload: that fixture sent two full-army commands in 900 ticks and could not exercise death or path-request admission. Treat the new counters and serial timings as a measured regression baseline until repeated reference-machine runs establish a replacement headroom gate. Keep simulation, projection, compaction, encoding, and driver work on the same serial lane, and do not hide driver cost outside the measured round trip.

3.1.4 Deterministic arithmetic and physical positions

Simulation schema 6 breaks numerical compatibility with schema 5 and earlier. Entity centers, ability projectile centers, world ability objects, smoke, trenches, mortar/artillery shell launch and impact points, and Panzerfaust shot positions use rts_rules::math::Coord: a signed i32 Q19.12 (4096 substeps per world unit, 131072 per 32-unit tile). Its world range is −524288 through 524287.999755859375, providing 32× positive headroom beyond a future 512 × 512 map’s 16384-unit extent. Storage width is independent of intermediate width: conversion scales in f64 before rounding; circular area-effect distances widen differences to i64 and products/sums to i128 so even opposite full-i32 endpoints cannot overflow. No position is stored as an i64.

Physical position writes round to nearest substep, ties away from zero, on spawn, movement, collision, pulls, teleports, projectile steps, and effect creation. Entity setters reject nonfinite or unrepresentable coordinates atomically; optional entity constructors reject them. Trusted geometry conversion saturates at i32 bounds (NaN maps to zero) rather than wrapping; command/map admission still validates finite world bounds. Static landing probes quantize their candidates before checking body legality, and movement deltas describe the stored result. Circular smoke and trench inclusion uses grid-rounded query points/radii and widened integer squared distances.

Transient steering, oriented-shape geometry, speed/radius rules, and angles retain strict IEEE-754 f32 arithmetic to preserve existing gameplay formulas. Immutable command intent, paths, remembered observations, and presentation metadata may retain world-coordinate floats; they are not accumulated physical centers. Conversion back to transient/wire f32 rounds nearest-even; at the future map edge the f32 ULP is 1/512 world unit, so not every stored substep is expressible through that projection. Ordinary arithmetic must use Rust’s strict default without fast-math, implicit FMA contraction, or flush-to-zero settings. rts_rules::math::GameplayMath supplies explicit det_* operations for trigonometry, angles, roots, hypot, powers, and explicit FMA through exact-pinned libm 0.2.16 with force-soft-floats; this disables target-specific/intrinsic implementations even if Cargo feature unification enables arch. Integer powers have a specified multiplication order. Angles remain radians with the existing wrap conventions, including deterministic atan2 quadrants and signed zero. Changing these algorithms, precision, or operation ordering requires a simulation-version bump. scripts/check-crate-boundaries.mjs rejects platform math calls in rules/sim/AI and direct libm calls outside the facade. Numerical vectors cover rounding, axes/quadrants, roots, planned map bounds, projection error, and full-domain widened distance arithmetic.

Checkpoint coordinates above are raw signed substep integers. Imports validate the numerical compatibility header before decoding positions, so old checkpoints/replays fail closed even when the caller supplies the same build label. Schema 3 replay containers continue to embed this versioned checkpoint; strict build matching remains in force. Old recordings, including replay 495, require their original simulation executable: the new math does not promise historical trajectories or final scores. Current checked-in Lab setups and diagnostic start fixtures are explicitly reauthored on the new grid; this is not a general old-replay migration. Wire snapshots still send fractional world coordinates, and the client’s existing interpolation remains smooth. RNG replacement, replay checksums, and platform replay parity tests are outside this change.

3.2 Concurrency model

Lobby-owned runtime boundaries stay in server/src/lobby/; none of these helpers move transport, AI controllers, or Tokio coordination into rts-sim. RoomTask remains the single Tokio owner of room membership, phase state, room-owned control state, and the active Game; the implementation is split into focused room-local modules:

Empty private dev, replay, replay-artifact, and lab rooms are disposable; empty private replay-branch rooms reset their live/staging state but keep RoomMode::ReplayBranch, so reserved __replay_branch__ names never decay into public normal lobbies while preserving the in-memory branch seed.

/dev/scenario remains mode-local for scripted setup and driver selection: each scenario still chooses a dedicated Game::new_*_scenario constructor and optional tick driver before joining the shared clock, projection, and launch helpers. A driver that needs one delayed authoritative combat transition uses a narrow Game seam such as start_dev_scenario_panzerfaust_windup; it does not reach into entity state from the lobby. Moving those constructors into a generic launch path would either widen this behavior-preserving refactor or add scenario registration machinery, so future lab work should consume the extracted primitives first and migrate scenario setup only with a separate product-approved design. scripts/check-lobby-architecture.mjs guards the now-stable fanout boundary by failing new production lobby calls to Game::snapshot_for* outside projection.rs, except for the existing AI think context in live_tick.rs. The same guardrail keeps accepted lab mutation and issue-as calls centralized in room_task/lab.rs, where role-based operator authorization, result routing, dirty state, and the append-only operation log live. The checker also ratchets the post-split room-task shape: room_task.rs, each production child module, and the production room-task total all have explicit line budgets, and any new child module must add its own budget instead of silently becoming another hotspot.

3.3 Rules layer (rules/)

server/crates/rules/src/ contains classification, formula, terrain, and economy functions with no simulation state dependency. server/crates/sim/src/rules/projection.rs is the explicit state-reading exception: it reads Entity, Fog, and smoke state so snapshot and event visibility policy is centralized instead of scattered through services.

Production buildings may carry an ordered server-authoritative repeat_units list. The production system silently retries the current list entry only while the unit queue is empty, using the same economy, supply, tech, and producer predicates as direct training. Entries whose building or upgrade prerequisite is incomplete stay enabled but are skipped when choosing work, so they cannot starve a currently trainable entry and become eligible automatically when their prerequisite completes. Resource, supply, pause, and reserve failures remain temporary waits on the selected eligible entry. The cursor advances after a repeated unit is admitted, so two eligible active units produce in stable A/B/A/B order. Once admitted, a repeated unit is an ordinary FIFO entry, so later manual train commands append behind it. Enabling a unit appends it to the list if absent, disabling it removes only that unit, and any production cancel clears the whole list before removing the latest queued item. The list and its next-unit cursor are durable entity state, so checkpoints, replay branches, and Lab rewinds preserve them without recording synthetic train commands on every retry. Rally plans and repeat-production choices may be assigned while a production building is still under construction; both remain inert until completion, then govern its first produced unit.

Explicit manual train and research commands use bounded eight-entry FIFO queues. The front entry pays immediately when the queue is empty and its cost (plus unit supply) is available; otherwise it is stored unpaid at zero progress and retries each production tick. Entries appended behind existing work never prepay. An unpaid unit reserves neither resources nor supply, cancellation and producer death refund only paid entries, and owner/team projections expose prodWaiting so clients do not extrapolate false progress. Manual front entries for every player seat attempt payment in stable entity-id order before any standing repeat admission, still before construction payment. Dao research selects a player-wide tier at payment from completed plus paid active Dao researches, including other pavilions. Its committed total duration identifies the paid tier for cancellation/death refunds; unpaid entries reprice at activation. See balance for tier costs and times.

Auto-Build for human and AI seats protects the combined Steel/Oil cost of remaining unpaid manual front entries on living, completed producers and active worker build purchases already in interaction range at a currently valid site. Construction is checked after movement, including first arrival; travelling workers, queued build intents, blocked/invalid placements, and resuming existing scaffolds protect nothing. Friendly unit blockers that a Pump Jack can eject do not prevent its purchase being ready. Only fronts ready at the production phase boundary participate; items behind existing work and research on unfinished buildings do not. The budget is transient, derived from live orders every tick, and disappears when commitments are paid, cancelled, invalidated, or their issuers die. For each resource an automatic item spends, its post-purchase stockpile must remain at or above the greater of this pending budget and the configured menu floor. A zero-cost resource never gates that item. Manual purchases may spend normally, and supply reservation rules are unchanged. Already-paid automatic items continue normal progress. No additional client UI or wire state is introduced.

Research queue state is allocated from the union of faction research catalogs, so faction-specific research buildings support the same queue lifecycle. Command admission still checks the owner’s faction catalog. Research may be queued on an unfinished valid research building; those entries remain unpaid and inert until the building completes, then enter the same front-entry payment and progress path. Standing repeat production deliberately does not use unpaid entries: it continues retrying while the ordinary queue is empty and inserts a normal paid item only after cost and supply succeed. Dependent research is admissible when its prerequisite is complete or already earlier in the same building’s FIFO. Owner/team projections expose the ordered prodUpgradeQueue, allowing the command card to enable Artillery Fire Control behind queued Artillery research. The FIFO completion path remains the authority for when each prerequisite actually takes effect.

3.4 Ability system (game/ability.rs, game/services/ability_orders.rs)

rules::faction owns AbilityKind, UpgradeKind, AbilityTargetMode, their stable ids, and the faction-aware ability/upgrade catalog rows. Each AbilityCatalogEntry records its typed kind, label/icon/hotkey/title, legal carriers, target mode, optional min/max range, cooldown, optional charges and sequential charge-recharge interval, Steel/Oil cost, tech requirement, queue policy, autocast support, command-card visibility, and compact protocol/order-stage codes. game/ability.rs thinly re-exports the rules-owned types and converts total typed catalog lookups into the sim-facing AbilityDefinition; it is not a second identity or metadata source. Its planner codes and effect hooks remain simulation-only details. Raw command, replay/Lab, and checkpoint strings still parse fallibly at their trust boundaries. Adding a registry-backed ability means adding the rules-owned typed kind/catalog row and dependency-required protocol wire mirror, extending their parity coverage, updating the client mirror, and then adding only effect-specific code the registry cannot express.

AbilityDefinition also carries a sim-local AbilityEffectHook discriminator for the reusable effect shapes that actually exist today: legacy no-op (charge compatibility), reserved no-op (blanketFire), owned area status (breakthrough), delayed world effects (smoke, mortarFire), Scout Plane dispatch, dash return, line projectile, Magic Anchor placement, Golem consumption, and the intentionally one-off artillery point-fire path. Panzerfaust damage resolves against the locked live vehicle when it is enemy-owned or owned by the firing player; allied teammate and neutral targets remain non-damageable. Deliberate same-owner hits do not emit under-attack notices or receive enemy kill attribution. Impact feedback uses the stored launch endpoint when a damageable target has moved outside the firing team’s current visibility; enemy victim under-attack notices use the victim’s actual position. Dead loaded Panzerfausts do not advance pending windup state, so they cannot launch before normal death cleanup. The reserved Blanket Fire hook returns before command planning, so commands do not spend resources, start cooldowns, or replace artillery orders. The hook receives the owning player’s faction id at execution time through the normal command/order helpers, so wrong-faction ability use fails before effects, resource spending, cooldowns, or events are applied. Artillery point fire preserves an in-map raw clicked center. A gun already inside its valid 10-to-35 tile range band owns any needed in-place setup or redeploy before the first shot; a gun outside that band packs up, paths to a legal staging point inside the band, sets up facing the stored center, and then enters the same repeating fire order. It records temporary live-fog firing reveal sources for enemy players when a shell launches, using the firing-cycle-plus-half-second lifetime and smoke suppression used by other actionable firing reveals. Non-targetable Scout Planes are excluded from splash damage, projectile impacts, and Magic Anchor effects. The hook is deliberately not a generic script engine. Phase 11 signature abilities should first use one of the existing shapes; if they cannot, add either a narrow explicit hook or a named one-off path with faction validation, cost validation, and fog-safe event tests rather than widening the hook into generic scripting.

services::ability_orders owns the tick-path execution helpers:

Active Order::Ability movement orders run through services::order_queue::promote_ready_orders: when the caster arrives (phase Arrived), launch_world_ability is called; when pathing fails (phase PathFailed), the order is cleared silently. Stale queued ability intents (caster dead, tech gone, target point off-map, or cooldown active for a skip-if-not-ready ability) are skipped at promotion time via ability_intent_valid. Wait-until-ready world abilities instead promote into an active ability order and hold there while cooldown or weapon readiness catches up.

Services in server/crates/sim/src/game/services/ orchestrate tick logic and call into rules::* for classification. Rules functions have no imports from services/; classification and formula rules read kind-specific data from rules::defs. config.rs holds scalar constants and compatibility wrappers such as unit_stats(kind) / building_stats(kind), which return the stats embedded in defs.

Snapshot ability affordances are projected from the owning player’s faction catalog, so fixture or future factions do not inherit Kriegsia command-card buttons merely because they reuse a global entity kind.

Complex ability runtime state lives in game::ability_runtime. Its AbilityRuntime owns deterministic active instances and lightweight ability world objects that are not normal entities: they do not participate in supply, pathing, production, selection, scoring, or combat target queries unless a later phase explicitly adds such behavior. Game::snapshot_for, snapshot_for_observer, and snapshot_full_for project active world objects through Snapshot.abilityObjects, filtered by the same current-team fog / selected-player / omniscient mode used by other snapshot data. Enemy-visible objects expose only public render fields; owner-only payload state and safe caster ids are withheld from enemies.

Neutral trench terrain lives in game::trench::TrenchStore, owned by Game rather than the entity store. Trenches have deterministic ids, stable world-pixel centers, and a radius from the Entrenchment rules, but they do not consume supply, block construction/pathing, take damage, count for scoring, or participate in entity death cleanup. Snapshot projection sends currently visible trench terrain through the same active-player, selected-player, and full-world policies as other world objects, and records per-player discovered terrain so a scouted trench remains visible after it becomes fogged. That remembered trench record is terrain-only; it does not expose creator, owner, current occupants, or hidden unit state.

services::entrenchment updates unit-facing trench state after normal collision cleanup and before final snapshot indexing. Riflemen and Machine Gunners owned by a player with completed Entrenchment research create a neutral trench after holding ground on untrenched terrain for 90 consecutive simulation ticks. Engineers/Workers are not eligible: they neither dig new trenches nor occupy existing trenches. Holding ground means the unit has no movement path, no path movement delta for the tick, no collision displacement after pre-collision derived-state rebuild, and an order that is effectively stationary: Idle, Hold Position, an in-range Attack order, or an arrived Attack Move. Firing, target changes, body/weapon facing, and Machine Gunner setup/teardown do not reset that timer; Move, Attack Move while still travelling, Gather, Build, Deconstruct, ability movement, artillery point-fire, path movement, and non-slotting forced movement reset it.

Existing trenches are neutral. Any eligible Rifleman or Machine Gunner can occupy an empty one without owning Entrenchment research when it is stopped in the trench footprint. Each trench can actively hold only one infantry unit; once occupied, it is skipped as an occupation candidate for other units. A stopped eligible unit within one tile of an empty trench may be slotted by at most one tile into a legal position inside the trench footprint; slotting validates static standability, the swept static segment, and unit-body overlap against the current live entity positions. Slotting does not issue a move order or path, so the unit can still fire normally. Move and attack-move formation assignment also prefers a nearby known, unoccupied trench for eligible infantry when the trench footprint is within two tiles of the unit’s normal formation goal. This uses only current team-visible trench terrain plus the issuing player’s remembered trench terrain; hidden server-only trenches never influence movement goals. Non-eligible units, occupied trenches, blocked trench points, and farther trenches fall back to ordinary formation spreading. entity::active_trench_occupation(entity) is the simulation predicate for active occupation; digging progress, failed slotting, and merely standing near trench terrain do not set it. Visible occupied units project occupiedTrenchId; remembered trench terrain never exposes hidden occupants.

Entrenched combat benefits consume only active occupation through entrenchment_combat::is_actively_entrenched. Active entrenched Riflemen, Panzerfausts, and Machine Gunners gain one tile of weapon range through entrenchment_combat::attack_range_tiles, including the loaded Panzerfaust launcher shot. Combat target acquisition treats actively entrenched units, including units retaining an arrived Attack Move stance, and Machine Gunners that are setting up or deployed like Hold Position: they can acquire and fire at legal targets inside current weapon range but do not request enemy-directed paths or tear down the weapon to pursue. A fresh ground Attack Move for an MG that is setting up or deployed preserves setup progress and existing trench occupation when normal acquisition finds a visible, legal target within its current weapon range before movement. The new destination remains active and resumes after combat’s no-target grace. This continuation preserves an occupied trench without authorizing mid-route digging. If no legal target exists, the new order starts teardown normally. Plain Move always leaves occupation and packs the weapon, including explicit retreats. Direct Attack retains occupation until combat decides whether its target requires pursuit.

Incoming direct-fire accuracy is weapon-specific: Anti-Tank Guns may deliberately target infantry-sized units, and those intended hits have no intrinsic miss roll but deal only 30% damage. Tank cannon shots have no intrinsic miss chance and entrenchment adds no miss chance. Direct shots normally damage only their resolved victim. Enemy tanks and blocking building footprints may intercept the shot before the intended target. Tank HE adds an exception when a cannon both targets and hits infantry: the primary takes its unchanged direct hit, and other eligible entities within 1.4 tiles take 30 base damage with mortar armor scaling, friendly fire, and direct (50%) trench protection. The blast is immediate, has no inner circle, and emits the existing mortar impact effect only to teams that can see its location. Vehicle-targeted and intercepted non-infantry hits do not produce this blast. After a direct hit’s normal weapon, armor, and facing calculations, entrenchment_combat::reduce_direct_damage reduces damage by 50% for actively entrenched eligible infantry. Area effects call entrenchment_combat::reduce_area_damage after their normal falloff and armor calculations, so Mortar and Artillery splash deal 75% of their current post-formula damage to actively entrenched eligible infantry.

The entrenchment_inspection dev-watch scenario seeds a two-player inspection map with researched Entrenchment for player 1, a dig-capable Rifleman, friendly and enemy eligible reuse units, a Machine Gunner for crowded slotting checks, and several neutral trenches including a nearby connected pair. Its script driver does not issue movement commands after setup, so humans can pause, step, and manually inspect trench rendering, reuse, fog-memory behavior, and occupied-unit projection from the initial state.

Per-caster recast state is exposed to the owner through EntityView.abilities: active return marker id, availability tick, and remaining lifetime are projected only for the owning player’s command card. Ekat’s ekatTeleport world-point activation is a dash: it selects the nearest unoccupied, statically legal landing within cast range, moves the caster, and creates a four-second return marker at the original position. One dash command applies independently to every selected eligible Ekat for both immediate and queued casts. Each caster keeps its own range clamp, cooldown, and return marker; unavailable or invalid casters do not block the others. Wind uses the separate windDash ability, displayed as Blink, with a twelve-tile clamp and no return marker or recast. Adepts hold one charge and Masters two, recharging sequentially every eighteen seconds. Promotion adds one ready charge without resetting recharge progress. Wind Blink also applies independently to every selected eligible caster. Both outgoing dashes first try the exact range-clamped request, then search a one-world-pixel lattice anchored there across the full cast disk, ordered by squared distance with deterministic ties. Branch-and-bound prunes regions outside range, inside occupied bodies, or inside an impassable tile. Every landing checks the current bodies of all other living units, including allies and working workers; each accepted caster immediately occupies its spot before the next caster is processed. There is no additional snap-distance cap. Return markers retain their exact destination and reject occupied landings without consuming the marker. recastAbility commands are explicit and validate a live owned caster plus matching active runtime state; missing state, same-tick/too-early return, stale caster ids, and invalid return destinations are ignored rather than overloading world-point useAbility commands. A valid recast returns Ekat to the marker and consumes it.

Ekat’s ekatLineShot world-point activation clamps the endpoint to ability range, spawns an ability-runtime line projectile at Ekat’s current position, and starts cooldown when the projectile is accepted. The projectile travels outbound to the clamped endpoint, then returns toward Ekat’s current server position each tick, so moving or dashing after firing can bend the return path. Enemies intersecting the swept line are damaged once per leg; stale or dead casters remove the projectile without resolving further hits.

Ekat’s ekatMagicAnchor world-point activation places one replacement-style, non-blocking, non-attackable runtime object at the target point. It naturally expires after 10 seconds. While active, it creates a 3-tile pull field affecting only enemy ground units (owned, allied, neutral, and Scout Plane units are unaffected). After normal movement, one inward displacement vector applies to every eligible unit regardless of its path or movement direction. Its magnitude is movement_speed × EKAT_MAGIC_ANCHOR_PULL_SPEED_MULTIPLIER (2.4), scaled by linear radial falloff and divided by the square root of collision footing resistance (at least 1.0, so pass-through worker orders receive normal infantry pull). The strongest overlapping field applies. Pull is clamped to the center and checked against terrain and unit blockers; orders and paths are preserved, and the reported movement delta includes both displacements. There are no Anchor directional speed multipliers or separate stationary movement rules. If an active anchor exists when ekatLineShot is accepted, the runtime spawns one projectile from Ekat and one from the anchor toward the same cursor point; both return toward Ekat’s current server position.

Ekat’s ekatConsumeGolem self activation has no cooldown or resource cost. It finds the nearest owned, living Golem within the ability range, releases any active mining slot held by that Golem, removes the Golem permanently, restores Ekat to max HP, and emits an owner-visible positioned notice. If no Golem is in range, the command is a no-op. Ekat has no passive regeneration.

Mortar shells are delayed AOE effects resolved by game::mortar after their flight timer expires. They damage owned, allied, and enemy units/buildings with the same falloff and armor rules; resource nodes are ignored. Same-team mortar damage is intentionally real friendly fire, but it is unattributed: it does not update last_damage_owner/position/tick, does not trigger AI worker retreat, does not emit enemy under-attack notices, and does not award kill credit or combat score. Mortar Teams do not participate in ordinary combat acquisition: Idle, Hold Position, Attack Move, and even direct Attack orders cannot launch a shell. Every shot requires an explicit mortarFire ability command, lands exactly on the selected point, and remains intentionally allowed onto same-team positions so players can take risky shots deliberately. Manual commands still obey the five-to-17-tile range band, setup/repositioning rules, weapon reload, and queued-command semantics.

Artillery point-fire shells follow the same support-weapon friendly-fire contract: blast damage can hit owned and allied entities in the radius, but same-team damage is unattributed and cannot award enemy kill credit. Direct-fire weapons are the opposite rule: normal target selection, ordered attacks and shot interception only damage enemies. Allied entities may block a direct line of fire through the friendly-blocker safety rule, but they are not legal direct-fire victims.

server/crates/archcheck classifies each top-level service module before accepting service-to-service imports. The roles are intentionally coarse and are part of the command/order boundary:

Every service import must be present in the exact import allowlist and must also be legal under the role matrix. A role failure explains why the edge is forbidden, usually because orchestration should stay in systems.rs or because command-family growth should use command input -> issue-time facts -> pure plan -> narrow executor. Residual services::commands and services::order_queue imports into tick-system helpers are named one by one in the role allowlist; there is no blanket broad adapter exception. New command/order service edges therefore need both an exact import allowlist entry and a role-matrix justification.

services::repair is a tick system called directly by systems.rs after construction. It owns worker repair work and resource spending and uses the existing entity HP restoration and player spending helpers; command adapters do not import this tick system.

services::scout_plane is a mutation helper for the Scout Plane aerial unit. Command admission calls it from the scoutPlane ability after validating a selected owned Resource Depot or Command Car, that carrier’s sortie price, and that carrier’s cooldown. The helper spawns the plane at the carrier, records Command Car provenance when applicable, flies it to the clicked point, starts a 30-second total lifetime at launch, and despawns it when that timer expires whether or not it reached the orbit. Scout Plane sorties have no return leg. Live fog recompute stamps Scout Plane sight as team aerial vision that ignores terrain and building line-of-sight blockers while still using active smoke clouds as blockers.

game::systems::run_tick owns the tick pipeline and the lifecycle of tick-scoped derived state. It rebuilds named phase state at explicit boundaries: pre-command state for command validation, pathing, and movement; post-movement state for combat and economy queries; pre-collision state after production/construction/death mutations; collision-displacement snapshots for entrenchment; and final state for snapshot interest filtering. The three phase occupancy snapshots compare the exact ordered (id, kind, pos_x_bits, pos_y_bits) vector for every building and share immutable blocker/clearance data within the tick when that topology is unchanged. Construction placement, building removal, or relocation rebuilds occupancy at the next boundary; owner/completion and unit movement do not affect owner-independent topology. Spatial indexes continue to rebuild at every boundary. This preserves the named phase semantics without repeating the two full-map clearance-field builds after unit-only movement.

PathGraph is the longer-lived pathing projection inside DerivedState.pathing. Its authored-map content key is computed when the room/map owner is created and covers dimensions, row-major terrain/roads, elevation, doodads/trees, no-vehicle tiles, slow-movement tiles, and the remaining materialized map overlays. Immutable and current directed edges are stored by proven routing profile: infantry-like normal, vehicle-body normal, and oriented vehicle-clearance/pinch (with radius as a profile parameter). Each tile has one passability byte and eight u32 extra-cost entries in legacy direction order; u32::MAX is the illegal-edge sentinel. Base-step and turn costs remain outside the table so A* keeps the legacy saturating-add order, heap/tie order, heuristic, cap, and fallback behavior.

Dynamic tables use 256-tile copy-on-write pages so transactional Lab clones share unchanged graph memory. A movement-body fingerprint first rejects unchanged occupancy in O(1); on change, the graph diffs the old/current blocker bitsets and recomputes only edge origins in a square around changed tiles. The exact bound is max(radius + 2, 4 for vehicle-clearance else 2) tiles: it covers the destination radius, diagonal orthogonal guards, oriented pinch corners, tree/current slow costs, vehicle corner grazes, and the three-tile preferred-clearance threshold plus the source-to- destination edge. Overlapping footprints are resolved from the complete current occupancy, so removing one blocker cannot reopen an edge held closed by another. The content-derived occupancy fingerprint remains the cache key and the monotonic graph generation decides only table refresh; generation never changes cache scheduling, validation, or request-resolution ticks. Systems should consume the derived-state object for their phase instead of carrying occupancy or spatial indexes across later mutations.

3.5 Command planning and queued order semantics

Building and vehicle repairs use a dedicated Repair command/order and queued target intent. Engineers and Serfs (the Worker kind) may repair their own living, completed, damaged buildings and their own damaged Tanks, Scout Cars, Rocket Trucks, Mortar Teams, and AT Guns; legality is checked at issue, queue promotion, and every work tick. All eligible selected workers repair concurrently, routing to the normal outside footprint staging ring for buildings. For mobile targets workers follow the current target position using normal throttled, budgeted path requests; repair only progresses within the existing 48-world-pixel non-building interaction range. Other mobile kinds remain ineligible. Each repairs 1 HP every 15 ticks (2 HP/s); leaving range resets work progress, unaffordable work waits, and full health or an invalid/dead target ends the order. Existing construction and Tank Trap dismantling remain separate. Repair target markers use ordinary fog-safe target projection. Repair orders and work timers and target-owned fractional resource credits are entity-owned serialized state and resume through checkpoints/replays.

Tank Point (SimCommand::PointTanks) filters to living owned tanks after ordinary command admission, then calculates a shared heading from their centroid to the clicked world point. Immediate issue replaces active and queued orders with checkpoint-serialized Order::Point { facing }. Shift issue appends checkpoint-serialized OrderIntent::Point { facing } within the ordinary queue limit, preserving the active order and earlier intents. The shared heading is resolved at issue time. Movement pivots in place at the ordinary tank hull turn rate, checking static standability at every step; blocked hulls wait for clearance. The stance holds ground, allows automatic turret fire, and suppresses automatic armor-reaction hull turns until another order replaces it. Following queued orders wait until the hull reaches the requested heading; Point holds indefinitely when no follow-up exists. A target at the centroid leaves existing orders unchanged.

Rocket Truck barrage orders require the target to be within the existing 10–44 tile range and within ±10° of the hull facing. Range approach uses the ordinary ability path; terminal positioning samples collision-checked forward/reverse driving arcs until both conditions hold. The truck stops before launching and remains committed through its unload. The rack does not turn the hull in place. This reuses the ability order and movement state; there is no new wire order or checkpoint field. Terminal positioning is a local search, so crowded or blocked firing positions can still require a manual move.

Entrenchment research takes 20 seconds.

Deployed anti-tank guns acquire and retain only targets inside their fixed setup cone. Their body and barrel turn together to track an in-cone target before firing, while the setup cone itself remains fixed. Targets outside the cone do not cause rotation and require teardown and redeployment before the gun can engage them.

Automatic acquisition defaults to legal enemy candidates inside the attacker’s current weapon range, then applies the existing target-priority ranking. Range to buildings is measured from the attacker’s center to the closest point on the authoritative building footprint; melee attacks (Worker tools, Golem fists, and Disciple swords) measure range to the authoritative oriented vehicle body, including clearance, for vehicle targets. Other unit-target range remains center-to-center. Melee pursuit uses the same closest hull point so an attacker stops outside collision instead of repeatedly pushing toward a vehicle center. Building acquisition broadphase queries include the maximum building half-extent so a footprint inside range is discoverable even when its indexed center is not. Explicit Attack orders may target the issuing player’s own units or buildings, but not allied teammate entities, and retain their commanded target while it remains legal and visible. A direct attack pursues that target to the current weapon range band, using the closest footprint-boundary point for buildings and the closest hull point for melee attacks on vehicles, stops to fire, and repaths if the same target moves out of range. Tanks instead hold position when the commanded target is within their maximum stationary cannon range (including the usual attacker radius and range slack), allowing the range ramp to reach it; they still fire only inside the current range and pursue if the target leaves the maximum stationary range. A direct attack never switches targets while the commanded target remains valid. For a retreating unit, an established final foot-pursuit segment of at most one tile may update its endpoint each combat tick without another tile search. The endpoint uses the unchanged current hull/footprint range calculation, must remain outside the target body, and requires a radius-aware clear static segment. Stationary/approaching targets, vehicle attackers, minimum-range retreats, original Attack Move travel routes, longer detours, and large endpoint shifts retain normal throttled pathfinding. This local tracking does not change hit legality, weapon setup, visibility checks, or the path-search budget. Opportunistic moving-fire acquisition for a plain Move uses the same in-range boundary. Wind Disciples use the base Disciple’s 0.75-tile sword profile while retaining a plain Move destination and striking in melee range. They also retain an explicit Attack or automatic pursuit approach path while striking, rather than clearing it on each in-range combat tick. The approach still ends at melee reach; moving targets can cause brief stops and renewed pursuit when they leave range; speed, Dash, and the 61-tick cooldown remain unchanged. Magic uses a five-tile orb profile, ordinary stop-to-fire behavior, no sword secondary, and engagement range equal to attack range. Base/War/Wind keep sword reach and five-tile automatic approach. Attack Move may pause for an in-range engagement and resumes only its original player-issued destination afterward. While retaining a building target, Attack Move rechecks for visible enemy combat units in weapon range each tick and switches to a legal shot on one when available, even during weapon cooldown. This does not change the movement destination or override explicit Attack orders. Disciples are the sole automatic-pursuit exception: aggressive Idle/Attack Move uses a five-tile engagement range, approaches to sword reach, and can switch from a building to a visible combat defender within that engagement range. Other kinds remain weapon-range-only.

After the 50 Steel / 100 Oil, 20-second Scout Plane research completes at the Engineering Complex, Resource Depots and Command Cars activate Scout Plane on the C grid slot. A Resource Depot sortie costs 38 Steel / 56 Oil; a Command Car sortie costs 63 Steel / 94 Oil. Activation launches immediately from a selected ready carrier and starts that carrier’s 30-second cooldown. Sorties are independent: any number may coexist and each contributes its own team aerial vision. Activation does not replace or clear a selected Command Car’s active or queued orders. The plane has a 30-second total lifetime from launch: transit consumes that lifetime, it orbits only for any time remaining after arrival, and it despawns when the timer expires even if it never reaches the target. Scout Planes have no fuel reserve, Oil upkeep, selected-plane retargeting, return leg, or dismissal commands.

Group move formation assignment chooses one bounded, locally connected landing patch before issuing per-unit goals, avoiding command-time A* probes outside the move coordinator pathing budget. The patch uses the passability intersection of every movement kind in the selection, so a mixed group cannot split across water, rock, or vehicle-blocking forest. A passable click anchors the patch on the clicked side of an obstacle; an impassable click deterministically prefers a sufficiently large nearby patch on the selection’s approach side. Blocked compact slots are smudged independently only within that patch and must also pass the existing cached global-reachability check. If no reachable local alternative exists, the unit keeps its current position instead of receiving a free but unreachable fallback goal.

FormationMove accepts a bounded, sanitized world-space polyline and assigns deterministic slots by arc length. A stroke with enough length uses a single rank across the complete stroke; a shorter stroke grows parallel ranks at body-aware spacing. Stable entity-id and nearest-slot tie-breaking reduce crossing. Requested slots then pass through the same standability, uniqueness, known-trench, and cached-reachability goal search as ordinary formations. Immediate commands replace active orders as a group. Queued commands resolve the slots at issue time and store one ordinary point move intent per accepted unit, keeping each unit’s bounded queue independent of stroke complexity.

The authoritative command model is: clients compose intent; the server validates and plans it. Keyboard latching, double-tap quick-cast, Shift lifetime, cursor previews, and rejecting pointer-captured touch releases outside their originating controls are client UX. The simulation contract begins when a SimCommand reaches services::commands: the command service dedupes and caps unit-id lists, rejects over-budget human unit-list commands, builds issue-time facts for the referenced units/targets, and must produce unit-local actions that match the policy below. The budget scalars live in the sim-owned command_budget helper so parity checks can dump them without moving ownership into rules. Human command budget is supply-based: 25 base command supply. Command Cars have zero command weight and add no capacity (COMMAND_CAR_SUPPLY_CAP_BONUS = 0); other units use mirrored supply as command weight. AI-owned players are exempt from this budget because live AI still issues ordinary SimCommands through Game::enqueue. Lab issueCommandAs and authored dev replay drivers can also opt into a server-owned admission mode that bypasses the command-supply budget and uses a larger bounded unit-id window for scenario-scale commands. Lab scenario export and restore preserve stable active and queued order intent, including artillery point-fire and blanket-fire commands. Restore also hydrates the runtime state required for active movement, build, deconstruct, and artillery point-fire orders to resume execution. While a worker is actively constructing a scaffold, ordinary non-Shift orders replace its future queue with one follow-up intent and leave construction running. Repeated ordinary orders replace that follow-up; Shift orders append using the usual bounded queue. This applies to move (including formation move), attack move, attack, gather, hold, build, and deconstruct orders that the worker can legally receive. Stop remains the explicit immediate construction interruption. Workers travelling to a build site or waiting there remain interruptible. When choosing one worker for a build/deconstruct command, prefer an interruptible selected worker before an active constructor. When construction completes, its single active builder clears the active Build order, preserving follow-ups for normal queue promotion and authoritative order-plan feedback. Build intents may be appended when the same worker’s active and earlier queued Build orders, together with the player’s completed buildings, satisfy the new building’s tech requirements. The admission check is worker-local and respects queue replacement; another worker’s plan cannot unlock a build. The owner-private order plan projects each Build stage’s building kind so the client build card can expose this chain. Promotion and build arrival still require completed live prerequisites, so a destroyed or interrupted prerequisite causes dependent stages to be skipped. services::order_planner is the pure reference implementation of this planning policy. The planner has no EntityStore, fog, pathing, economy, or cooldown mutation dependency; it accepts plain facts and emits one of four effects:

services::order_execution is the shared narrow mutation helper for order-state transitions that are needed by both issue-time command application and queued promotion, such as support-weapon setup, artillery point-fire targeting, and artillery teardown before movement. Queued artillery Point Fire remains accepted while a deployed gun is tearing down for an active move, preserving the locked future target for move-then-fire execution. It should not grow new validation policy or tick orchestration; those responsibilities remain with command admission, queued promotion, or the owning tick system.

AI SDK Tank routes prefer three-tile static-obstacle clearance and emit checked intermediate waypoints through ordinary queued movement commands (see ai.md, Eco policy). This planning preference does not change native Tank collision radii, body-width path legality, waypoint consumption, or human-issued movement orders. Native movement retains its existing acceptance radius; the SDK pads its planned waypoint clearance for that steering tolerance.

Live pathfinding and dev scenarios share a 32,768-node expansion budget per path miss. Requests that exhaust the budget return a best-effort path. Cache entries include the effective search budget, so an identical bounded request can reuse its deterministic best-effort result while a larger-budget request still searches afresh. The movement coordinator services at most eight search-backed tile-path requests per tick; cache hits consume the same scheduling allowance as misses so clearing the rebuildable cache cannot change simulation timing. Same-tile, zero-search, and proven-clear direct routes remain free. A cached result retains its original search-work classification; after any result representing at least 4,096 expanded nodes, the coordinator preserves that result but defers all later tile-path requests to the next tick. Deferred movement orders remain AwaitingPath; build and deconstruction orders retain their interaction intent for a later routing pass. Their serialized execution state advances a staging-candidate cursor after bounded failures and resets it when the static blocker fingerprint or worker start tile changes, so retry progress does not depend on rebuildable cache residency. This tick-level scheduling does not lower the per-route search allowance. Ordinary non-vehicle move formations bypass A* only when the existing body standability check proves the exact world-space segment clear and its sampled centerline crosses no authored slow-movement tile; interaction routes, blocked direct segments, and slow-terrain crossings retain the full tile-guided search. Infantry-like A* routes add a cardinal/diagonal slow-tile surcharge derived from the same authoritative 0.75x movement ratio used during ticks, so they may choose a shorter-time open-ground detour while still crossing slow terrain when going around costs more. Direct results are not stored in the tile-keyed cache. PathingService reuses cleared A* working containers between sequential room requests; that scratch state remains derived and is never serialized. Pivot-vehicle queries include the hull’s quantized eight-way initial heading in the cache key and charge the initial direction change in 45-degree steps using the existing vehicle turn penalty. Subsequent bends retain their existing cost. When a diagonal first step is expanded to an L, equally costly legal elbows prefer the heading-aligned first leg. Heading remains a soft preference; required backward routes are legal, and heading-free authoring/non-pivot queries retain their old scoring. Tree-trunk waypoint refinement is best-effort: if its bounded local detour graph cannot refine a successful tile route, the movement coordinator retains the original route instead of converting the active order to PathFailed. Static movement legality still prevents a vehicle from entering blocked terrain, and retaining the path keeps normal blocked-route recovery active. Pump Jack standability permits a Pump Jack to coexist with its oil node, and simulation invariant checks use that same Pump Jack policy.

Point move and attack-move commands translate selections into one compact destination layout regardless of command distance. The destination footprint is the nearest compact rectangle: for example, ten units use four-by-three or three-by-four slots rather than inheriting a one-deep line. Wide selections fold into ordered columns and tall selections fold into ordered rows, preserving position most strongly along the selection’s long axis while preventing repeated moves from feeding an extreme aspect ratio back into the next formation. It does not preserve original world-space separation. Infantry-like selections use adjacent destination tiles. A selection containing an oriented vehicle body uses a two-tile pitch, leaving one open tile between destination slots so mixed selections also keep clear of vehicle bodies. Vehicle groups of six or more use one additional slot along the footprint’s long side, reducing deep same-lane traffic queues while remaining at least two slots deep. In partially filled rectangles, the deeper cells are centered so central units lead and outside units trail through constrained routes; when folding a one-deep line, that leading edge follows the move direction. Blocked-slot search stays inside the command’s cohesive landing patch and keeps vehicle spacing strict. Player-drawn formation lines remain an explicitly authored layout with their separate line-and-rank assignment policy.

Eligible infantry move and attack-move formation slots bias toward nearby known, unoccupied trench terrain within a two-tile footprint band around the normal formation goal. A trench occupant counts as occupied only when visible to the issuing player through the fog and smoke projection used for snapshots; selected units still free their own occupied trenches for group moves. The visibility check uses contributors derived from Game::alive_players(), matching the living-team visibility boundary used for snapshots; leftover units owned by defeated teammates do not reveal trench candidates. Hidden trenches, blocked trench points, occupied trenches outside the command, far trenches, and non-eligible units use ordinary formation spreading. Trench preference cannot place infantry inside the one-tile clearance reserved around an already assigned vehicle goal.

Tank weapon range is dynamic in the simulation: tanks keep their base 5-tile range while moving, then linearly ramp to 14 tiles after three stationary seconds. Path-driven translation or hull rotation resets the ramp to base range; turret aiming and external pushes do not.

Team-current visibility, including an ally’s lingering death vision, permits explicit immediate and queued attack targeting, but death-vision-only targets remain ineligible for general combat auto-acquisition. A consumed direct Panzerfaust attack spends the unit’s launcher immediately at launch, allowing queued movement to promote while the detached projectile continues travelling.

Combat weapon cooldowns and firing-reveal reaction gates are independently keyed by rules::combat::WeaponKind inside CombatState. A reaction gate is additionally keyed by target and the stable reveal source/episode, so transient target clears and switching back within one episode do not restart it. Its absolute readiness deadline includes any reload remaining when the gate begins, preserving the prior additive timing without mixing reaction time into reload state. Ordinary sight bypasses the gate immediately while leaving the real reload unchanged; explicit ordered fire and auto-acquisition use the same team-current ordinary-sight scope as their target-legality checks. Each weapon retains at most 64 active reaction gates and deterministically evicts the oldest if that defensive bound is reached. The legacy Entity::attack_cd(), set_attack_cd(), and tick_attack_cd() shims operate only on an entity kind’s default weapon; new multi-weapon code should use weapon_cooldown, set_weapon_cooldown, tick_weapon_cooldowns, and weapon_firing_reveal_reaction_ready. Ability cooldowns, lockouts, and uses remain separate from weapon cooldown state. Tanks use this keyed state to keep the tank_cannon and tank_coax reloads independent.

Auto-acquisition prefers unit targets before building cleanup targets by default. Building fallback targets still use weapon-fit ranking among eligible cleanup targets.

Entrenchment auto-occupation chooses the nearest trench that has a legal occupation slot for the unit. A closer trench with no legal slot does not block searching for a farther usable trench. For dig-in progress, explicit attack orders count as holding ground only after combat advances them to the Firing phase; waiting attack orders do not create trench progress. Lab move operations clear trench occupation and dig-in state when repositioning an entity so snapshots do not retain stale occupiedTrenchId values before the next tick.

Construction build-site checks classify the current site state before deciding whether work can start or continue. The status distinguishes invalid terrain, existing buildings or scaffolds, resource nodes, and relevant unit bodies, while preserving Tank Trap placement rules. Pump Jack placement is the resource-node exception: it is only valid when the Pump Jack footprint center is associated with non-depleted oil without another extractor on that same patch, and completed Pump Jacks, not workers, extract oil. When a Pump Jack builder arrives at an otherwise-valid site, owned and allied unit bodies overlapping the footprint are deterministically moved to the nearest static-standable, non-overlapping positions before placement is revalidated; enemy bodies remain ordinary temporary blockers. Pump Jacks are treated like field infrastructure rather than survival buildings for defeat checks, so a player with only Pump Jacks remaining is eliminated. Build orders can enter a WaitingAtSite phase and track unit-blocked ticks with a grace period derived from TICK_HZ. Otherwise-valid build orders may be issued and promoted while the player is short on resources; once the worker arrives, construction waits and retries until resources are available. Workers also wait through temporary unit blockers for that grace period, but cancel if permanent blockers claim the footprint. Existing owned scaffolds with no active builder can be resumed without charging again; occupied scaffolds reject another builder.

General rules:

Allocation rules:

Examples:

Promotion is centralized in services::order_queue: idle units, arrived/path-failed move orders, completed or invalid explicit attacks, and completed ability movement orders pop the next valid intent. Move and attack-move promotions are batched by owner/destination through deterministic BTreeMap ordering, while attack, gather, build, setup, and ability promotions are issued per unit. Active gather and build orders remain terminal until their own systems mark them complete or clear them.

Production buildings keep an owner-only rally plan capped at four stages. Non-queued setRally replaces the whole plan; queued setRally appends a move or attackMove stage if space remains, or establishes the first stage when the plan is empty. Newly produced units receive the first rally stage as their active order and any later stages as queued unit-local intents, so every trained unit follows the same accepted building rally chain. The first stage also drives spawn-exit and vehicle facing preference. A stage may also carry a bounded polyline of 2–128 vertices. At successful production each line stage resolves to the next point of one shared binary-subdivision sequence (0, 1/2, 1/4, 3/4, 1/8, …), shifted by (building entity id % 10) / 10 and wrapped into [0,1). Fractions measure arc length, not vertex index. Every power-of-two prefix is evenly spaced along the normalized line; other prefixes progressively subdivide those intervals. Phase rotation uses 24-bit integer fractions before conversion to deterministic f32 geometry. Each producer owns a serialized u64 line_rally_sequence ordinal; successful line-rally spawns advance it once, shared by all queued line stages. Failed or blocked spawns do not advance it. Replacing/clearing the first rally or clearing Lab production resets it; appending a stage retains it. The 24-bit pattern repeats after 2^24 line-rally units; the u64 counter also wraps safely. Zero is the omitted/default value, preserving fingerprints when no line rally has advanced; checkpoint restore and fingerprints preserve every nonzero next ordinal. Sampling reads no existing units or pending destinations and bypasses point-rally occupancy reservation; normal movement handles terrain and collisions. Only resolved points reach unit orders; the original line remains in production state and private selected-building markers.

game::smoke::SmokeCloudStore owns active neutral smoke clouds as world effects, not entities: clouds have stable ids, center points, radius, spawn tick, and expiry tick, and they do not participate in pathing, collision, scoring, supply, or target queries. Scout-car smoke launch schedules a pending cloud rather than spawning it immediately: impact is delayed by up to 3 ticks (100 ms) at max range and scales down with launch distance. The server emits a transient owner-visible smokeLaunch event with caster and target positions for the client canister visual, but the projectile itself is not simulated as an entity. services::line_of_sight owns terrain raycasts used by fog and combat and can be constructed with the active smoke store or a fog-only building-footprint blocker mask as dynamic blocker input. Stone/rock tiles block vision and ranged attacks. Non-Tank-Trap building footprints block authoritative fog for every player, so units do not see through friendly or enemy structures; the visible edge of a building footprint can still reveal that building’s footprint for projection. Blocking buildings stamp their own footprint as visible but do not project sight through themselves. Fog may reveal the blocking stone tile itself and the visible edge of a smoke cloud, but not tiles behind blockers. Units inside smoke do not stamp their normal sight radius; friendly units inside smoke remain owner-visible through projection, while enemies remain concealed at range. Two living units both inside smoke gain mutual actionable close-quarters visibility when their body-edge gap is at most one tile. Fog stamps only the other unit’s occupied tile for that exception, and command validation, auto-acquisition, snapshot projection, and direct fire share the same range predicate. Combat auto-acquisition and firing otherwise use the smoke-aware LOS query; explicit attack orders remain stationary behind terrain, smoke, or entity blockers and cannot fire until the shot is clear. Direct-fire shot projection also checks hard entity blockers: tanks and non-Tank-Trap building footprints intercept shots, while Tank Traps do not. Forest direct-fire blocking also applies to secondary weapons, Panzerfaust launch checks, and machine-gun burst endpoints through the shared LOS service.

Game samples raw live fog per player every second simulation tick (15 Hz). Command validation, combat targeting, event visibility, building-memory refreshes, and snapshots all consume the same held sample between refreshes. Normal player snapshots build a temporary team-current fog by unioning the sampled raw grids of living teammates only. Hostile unit shots from outside a victim player’s current live fog add temporary firing-reveal sources to live fog for players on the victim’s team, not for third-party observers who merely see the combat event. These sources reveal only the firing unit’s current tile, are actionable for command validation and combat targeting, and expire at fired_at_tick + 13 * TICK_HZ / 2, a fixed 6.5 seconds (195 ticks) regardless of the weapon’s firing cycle. Each later shot extends the expiry to 6.5 seconds after that shot. The fog rebuild records each source’s stamped tile, whether targeting needs the reveal, and whether the terrain lacked ordinary sight before any firing reveals were stamped, keeping provenance attached to the authoritative fog result rather than inferred later. This tile-level record also covers colocated entities and does not follow a source that moves to a different tile during the next tick. Combatants that first engage a target through reveal-only sight spend a half-second response delay before their first counter-shot, so firing-reveal counterfire plays out as shot/counter-shot rather than an instant simultaneous chain. An actionable tile lacking ordinary sight is removed from snapshot visibleTiles and explored-history accumulation; a concealment reveal on ordinarily visible ground does not darken that terrain. The firing unit remains in entities; the client recognizes a projected enemy unit whose tile is presentation-dark and renders it on the explicit above-fog reveal layer. Thus firing reveals expose the unit for counterfire without clearing or exploring the terrain beneath it. An active reveal does not delay a combatant that has ordinary sight, and gaining ordinary sight bypasses an in-progress reaction gate without changing the weapon’s reload. Explicit attacks and autonomous target acquisition both count ordinary allied sight because firing legality and reaction provenance share the same team-current scope. Lingering death sight is stamped into live fog as ordinary temporary team sight for five seconds. The invisible source stays at the dead unit/building’s final position, uses that entity’s base sight radius plus the elevation bonus at its final tile, respects smoke and line-of-sight blockers, and is stamped into every tracked teammate fog grid. Because it is normal fog, snapshots project current enemy positions without visionOnly, direct and queued attacks validate through it, remembered buildings/trenches refresh from it, and idle/attack-move auto-acquisition can choose targets it reveals. Unit live fog stamps a center-origin sight circle. The observer’s absolute authored elevation adds one sight tile per two levels, capped at four tiles, without any low-ground penalty or elevation-based occlusion; Scout Plane aerial sight remains independent of elevation. Building live fog stamps the whole building footprint plus sight_tiles outward from each footprint edge, so a building with 1-tile sight sees itself and the one-tile perimeter around its edges. Neutral resource nodes never stamp vision. Match setup marks the exact footprints of entity-backed neutral buildings authored into the map as explored for every player, without adding current visibility or a sight radius.

game::building_memory::BuildingMemory is server-only stale intel owned by Game. After live, smoke-aware fog is recomputed, the store records one latest-seen entry per (viewer_player_id, enemy_building_entity_id) for non-neutral enemy buildings and completed neutral obstacles currently projectable to that viewer through team-current actionable fog. Records copy id, owner, kind, center position, footprint tiles, hp/max hp, construction progress/completion state, and the tick observed. At match setup it also seeds each player’s memory with entity-backed neutral buildings authored into the map. This exposes their initial position below fog; player-built Tank Traps enter the same memory only after they are actually observed. Five-second lingering death vision is normal temporary fog, so it refreshes remembered building intel while the source remains active. If a remembered building no longer exists, the record remains while its footprint is hidden from the viewer’s team and is removed once that team scouts any remembered footprint tile. The store retains that per-player clear tick so a selected observer union compares its newest positive sighting with its newest clear; a clear at the same or a later tick wins and keeps the destroyed building absent after current vision leaves. Clears are discarded once no positive memory of that building remains. Individual player views retain their independent knowledge, and no clear record is sent on the wire. A selected owner also suppresses other selected players’ stale memories of its buildings that no longer exist, regardless of current footprint visibility; opponent-only views retain their own memory. Tank Traps are excluded from owner-based inference because they become neutral on completion and require observed-empty clears. This keeps hidden destruction stale until the location is checked without adding wire-protocol fields.

game::anti_tank_gun_memory::AntiTankGunMemory is the corresponding server-authoritative per-player knowledge store for deployed enemy Anti-Tank Gun firing arcs. It refreshes from ordinary team sight and actionable firing-reveal fog, freezes last-observed position/facing while hidden, and does not react to authoritative movement, teardown, or destruction that the viewer cannot see. Observing the same gun packed or moved updates or removes the record, and scouting the remembered position empty removes stale intel. Selected-player observer snapshots project that player’s store, so Lab and replay vision switches restore perspective-specific knowledge instead of depending on which views one browser previously rendered.

services::geometry owns shared body primitives: infantry unit bodies are circles centered on (x, y) with the configured unit radius, tanks use an oriented vehicle hull derived from their body facing, configured length/width, and a small clearance margin, building bodies are axis-aligned rectangles derived from footprint tiles, and resource node bodies are circles for build-site blocking. services::occupancy separates terrain, all-ground static blockers, and physical vehicle-body-only blockers. Pump Jacks remain buildings for placement, targeting, economy, and fog memory, but they do not populate static occupancy layers, so units and vehicles can stand on and path through their footprints. Tank Trap pairs exactly two tiles apart close the single tile between them for physical vehicle body legality while remaining infantry-passable and shot-transparent. Vehicle path planning uses that same blocker layer for every Tank Trap regardless of owner, team, visibility, or prior scouting, so vehicles route around enemy walls even when their player has never seen the traps. Path-cache fingerprints include the vehicle-only blocker layer. Movement, collision, and standability use the same physical legality. services::standability owns reusable legality predicates for unit bodies and building sites. Its tick-local UnitBlockers index tracks current living unit bodies, updating after each accepted move or push. Units belonging to different teams block one another: ordinary motion, hull turns, recovery motion, body growth, and friendly collision pushes cannot create or deepen an enemy intersection. Swept motion includes translation and rotation, with conservative expanded samples to cover between-sample poses and stored-coordinate rounding. Existing authored overlaps may separate without moving the opponent. Opposing collision pairs never exchange separation pushes. Same-owner and same-team traffic retains footing-weighted separation; workers on work orders keep friendly pass-through, but still respect enemy blockers. Friendly pushes rejected by enemy bodies can leave compressed friendly overlap; the debug overlap invariant therefore applies to opponents, with the existing tolerance retained for authored/legacy overlap. Global paths remain static; enemy congestion can require local steering or waiting rather than a new global pathfinder.

Production spawn exits, construction/build intent, movement landing, steering candidates, collision push targets, and formation goal selection all use this shared standability layer for static/body legality. Oriented-body queries derive the perpendicular axis from the already computed forward axis, reusing identical deterministic trig results within the query. Swept segment checks sample the same body shape along a straight segment, and broad-phase queries use each body’s conservative bounding radius. Movement separates oriented vehicle body legality from drive behavior: tanks and anti-tank guns use pivot-drive locomotion that can rotate in place before advancing, while scout cars use car-drive path following where hull facing changes through translation/curvature. Pivot vehicles can reverse to a final steering point within three tiles when it is more than 90 degrees behind. They can also back up at most one tile to a nearby intermediate point when its following segment is not behind the hull, so a short route-entry correction does not become reverse driving through every bend. The normal forward/reverse choice is committed for the effective target waypoint after any accepted prefix, using that target’s following segment. Both forward and reverse choices persist while the hull turns: reevaluating intermediate-reverse eligibility from that changing angle can otherwise alternate the desired heading by 180 degrees every tick (replay 573, Tank 324). The choice lives in serialized entity movement state and is cleared by new orders, path replacement, waypoint consumption, or committed hull-axis recovery. Traffic adjustments and the existing armor-reaction facing preference remain applied over the normal choice; body legality and translation admission remain unchanged. Older checkpoints without a choice initialize it on the next movement tick. Pivot intent also returns the already accepted waypoint-prefix count. The movement pass reuses that count while consuming the same prefix, after reverse-intent and traffic calculations and before translation. Accepted pops preserve the queried pose/facing and static occupancy, so this avoids duplicate hull sweeps without changing collision samples, path choice, or pop order. The count is local to that unit’s movement pass and is never retained across ticks. If the old hull fits but its proposed turn is blocked and the immediate unjam fails, a vehicle stalled for at least 15 ticks and not yielding to forward traffic may begin bounded longitudinal recovery. It searches up to two tiles forward/backward for a position with room to complete the intended turn. It validates the swept old-angle hull over the complete escape, then commits to moving at normal movement speed without turning until that position is reached (at most three seconds). The complete escape corridor must also be clear of nearby units. Every recovery step rechecks static legality and nearby traffic; replacement orders/paths cancel the maneuver. Recovery retains the original route and queued orders, permits no sideways translation or obstacle crossing, and serializes its goal, held facing, and remaining ticks in entity movement state. Water, trees, and buildings use the same static legality checks. Shared geometry/standability queries remain pure; the wire protocol and client contract do not change.


Immediate weapon firing and machine-gun rays

services/combat/shot.rs::try_fire is the common immediate-fire entry point for primary weapons and Tank coax after their respective acquisition, alignment, and setup checks. It owns per-weapon cooldown readiness, firing-reveal reaction gates, victim-team firing reveals, and reload commitment, including missed cycles. New shot-wide effects belong here. services/combat/damage.rs::apply_direct_hit owns shared armor/facing, entrenchment, authored damage-reduction tiles, attribution, armor reaction, and under-attack notices; new direct-hit effects belong there. Single-target shots retain blocker redirection, movement miss rolls, and Tank HE splash. Detached mortar and Panzerfaust projectiles retain their launch/impact lifecycles.

services/combat/machine_gun.rs specializes trajectory resolution and fog-safe ray events, returning victim outcomes to the shared lifecycle rather than owning reveal or reload effects. It resolves three first-hit rays for each Machine Gunner, Scout Car, and Tank coax firing cycle. It reuses the tick spatial grid, body geometry, and terrain/smoke LOS. Burst-local hit totals and rays are temporary derived values; there is no new durable projectile state or Game API. Damage is aggregated per victim and multiplied by the rules-owned 0.6 ray damage scalar (20% above the original 0.5), then rounded once to the nearest whole point before existing protection rounding, with a minimum of 1 damage per hit victim. Building aim uses the nearest footprint surface, matching acquisition and stopping distance. See the balance prototype section and compact version-57 attack ray contract for tuning and per-viewer projection.

Barbed Wire entry effects live inside the movement service. Phase-local tile positions cover waypoint/anchor motion and collision displacement without new durable state. Collision entries that exhaust wire or kill infantry run death cleanup again before final snapshots. Tank tile entry exhausts the entire wire segment immediately, without damage or slowdown to the tank.

Disciple insight and Dao specializations

See Dao evolution playtest. Entity-owned insight and authoritative unit kind persist through checkpoints. Evolution changes Novice warrior (29) to wind_adept (35), war_adept (36), or magic_adept (37), preserving the entity id and orders. Permanent Dao identity is derived from kind; the engine stores no separate mutable dao. Visible Disciple snapshots append insight (compact slot 45) and dao (slot 46: wind/war/magic). Evolution buttons set replaceable, entity-owned chosenDao intent (team-private compact slot 49), independent of orders. Codes 14–16 and order stages 22–24 retain their positions. Evolution automatically occurs once 60 insight is ready, without research or a Pavilion. Evolution clears all insight and raises the cap to 200. Evolved Disciples continue earning insight from actual hostile unit HP damage at one insight per HP or quarter-rate building HP damage, carrying exact fractional remainders through checkpoints. War Adepts earn two insight per actual Tank HP removed. Both legs of Throw Sword count toward insight. Reaching 200 automatically advances a living Adept to its matching Master, resets insight and fully heals. Public daoMaster (compact slot 52) persists alongside the authoritative Adept kind. Research ids are dao_wind, dao_of_heaviness (War), dao_of_magic (Magic).

Dao body growth: Novice evolution and Adept-to-Master advancement share services/movement/body_growth.rs after the post-production/death occupancy rebuild. The existing bounded local clearance search validates the finished body against terrain, buildings and hostile units before committing rank, healing and position. Blocked Novices retain their chosen Dao (including an automatic RNG choice), insight and HP and retry without rerolling. Training exits separately validate their queued Adept’s body before spawning/evolving it.

Dao presentation and support Shield follow Disciple insight and Dao evolution.

Tournament Grounds

The tournament service admits own base Disciples at the arena perimeter before movement. Entry targets live in MovementState; entrant counts and RNG-selected winners live in ProductionState and checkpoint with the entity store. Ordinary paid production items hold 150 ticks for the winner, reserving three supply. Production emits all available winners together using existing legal exit and rally logic; blocked exits retain the queue. Cancellation is rejected; death releases supply without refunding the free winners. No public Game API or room state changes. See Tournament Grounds.

Portal first-stage rallies to the exact owned completed Grounds center automatically issue entry movement to newly trained base Disciples. Busy grounds retain waiting entry intents.

Portal Adept production

A completed Cultivator Portal trains Novices and, after matching Pavilion research, Wind, War and Magic Adepts. Each Adept costs 150 steel, 45 oil, three supply and takes 300 ticks (ten seconds), without a Novice input. Use normal train/repeat commands, queue payment/refunds, legal spawn exits and rally behavior. An unresearched Dao cannot be trained. Combat-earned evolution and Tournament Grounds are unchanged.

Proving Grounds

Retired from the playable Cultivator catalog: Serfs cannot construct it, it is not a production anchor, and the build menu no longer offers it. Its gate artwork is reused by the Portal’s Jade Silk Gate effect. Direct researched Adept production remains at Portals. The internal kind and training machinery below remain for authored fixtures; they are not an available progression path in normal matches.

The retained proven_grounds fixture has the former construction baseline: 100 steel, zero oil, 200-tick construction, 3×3 tiles, 120 HP, armored, one-tile sight, no weapon or supply. Select the building to queue a mix of researched Dao training plans (maximum 64). Right-click base Disciples inside or rally a Portal there. Each admission consumes one base Disciple and 100 oil, reserving three supply for its Adept replacement. One full-health chosen Dao specialist emerges after 300 ticks (10 seconds), using legal exits and the full rally plan. Blocked exits retry; destruction loses the trainee and oil. Unpaid plans can be canceled; active training cannot. Combat-earned 60-insight evolution requires no research. See Proving Grounds brief and rules for details and deferred audio/AI work.

Empty Proving Grounds training-plan vectors are omitted from checkpoint serialization, preserving existing replay fingerprints for games that never use this building; nonempty plans remain semantic authority and survive checkpoint restore. Native/WASM RNG portability tests pin this boundary.

Lab unit spawning accepts an optional dao (wind, war, or magic) on spawnEntity and each spawnEntities entry. Only the Novice (warrior) kind accepts it; other kinds are rejected before mutation. The authoritative spawn uses normal Dao evolution to initialize specialization stats, with its entrance animation already complete. Omission spawns a base unit. Lab timeline and replay operations retain this field, and setup checkpoints retain the resulting entity specialization.

LabSpawnEntity.faction_id optionally sets the owner’s catalog identity on successful spawn. It is validated against the unit/building catalog before mutation and retained by timeline/replay operations. Public snapshot playerFactions rows include every seat independently of private resource projection, so rendering, HUD and command admission share authoritative faction identity even when observing another team.

Shop goods

Shop item purchases use generic unit-targeted abilities and durable simulation state. Deliveries and applied escape protection are checkpointed for deterministic replay and Lab continuation. The R Buy menu sends a source Shop and selected fighters through generic useAbility without a target id. shop_items::purchase chooses one eligible recipient from authoritative rank, Insight, inventory and in-flight reservations; no client inventory prediction or new durable state is required. See Shop for costs, delivery, targeting, and lethal-damage behavior.

services::shop_items is a mutation helper: command admission invokes its atomic purchase executor, while the death phase invokes its escape executor before death attribution/removal. Its standability and occupancy queries select legal rescue exits; it does not import command adapters or invoke another tick phase. Entity-owned protection and runtime projectiles use the existing checkpoint policies for entities and ability runtime.

Carried Shop attack/defense items (Regen, Haste, Double Damage, Armor, and Vitality) persist permanently under entity ability_uses_remaining; their effects apply immediately on delivery without cooldowns or activation. Armor is resolved with native/Dao armor before penetration at hit production, rather than inside raw Entity::apply_damage; shared rules combine and cap additive bonuses before other defenses. Escape’s global 60-second purchase timer uses existing durable player ability_cooldowns. These existing owners checkpoint and fingerprint the state without a new state-tree owner. See categorized Shop items.

Vitality Treasure shares the existing carried owner and checkpoints its permanent bonus in the existing hp/max_hp pair. It has no expiry. Dao promotion excludes this flat bonus before scaling base health. See Vitality rules.

Regen uses the existing permanent carried state; shop_items::heal_regen restores one HP every ten ticks to living carriers, capped at max HP. It consumes a slot and rejects duplicates.

Cosmic Energy settlement and Breakthrough aura

PlayerState.cosmic_energy is authoritative serialized player state under GameState.players, covered by its existing checkpoint policy and fingerprint. Insight helpers record only whole insight actually gained in serialized entity cosmic_energy_pending. The death service settles and clears pending credits after field rewards and before entity removal, including credits from attackers dying in the same tick. Cultivators earn no passive insight. Training and tournament promotion use the same non-passive helper. Cosmic Energy has no spender. Before movement, Shop item policy rebuilds each entity’s skipped/derived breakthrough_aura from living friendly carriers at pre-movement positions. Movement speed multiplies by 1.25 once when covered. See Shop rules.