import type { GameRuntimeSnapshot } from "../runtime/snapshot.js"; import type { Aabb } from "./geometry.js"; /** Integer cell coordinates used for ownership on the ground plane. */ export type TerritoryCell = { x: number; z: number; }; /** Cell size, foreign-owner gap, growth price, currency and starter-grant policy. */ export type TerritoryPolicy = { gapCells?: number; cellSize?: number; chunkSize?: number; currency?: string; price?: (ownedCount: number) => number; starterBlock?: number; nowMs?: number; }; /** Atomic claim outcome with the replacement snapshot and total charge. */ export type TerritoryResult = { ok: true; snapshot: GameRuntimeSnapshot; cost: number; } | { ok: false; reason: "territory.blocked" | "territory.unaffordable"; }; /** Read-only footprint quote or a blocked/insufficient-balance rejection. */ export type TerritoryPlan = { ok: true; cells: TerritoryCell[]; cost: number; } | { ok: false; reason: "territory.blocked" | "territory.unaffordable"; }; /** Host-owned snapshot access used by the territory facade. */ export interface TerritoryStorage { get(): GameRuntimeSnapshot; set(snapshot: GameRuntimeSnapshot): void; } /** * Persisted chunk key containing one territory cell. * @capability territory-cell-chunk Map ownership cells to persisted world chunks. */ export declare function territoryChunkKey(cell: TerritoryCell, policy?: TerritoryPolicy): string; /** * Exact chunks needed to validate a footprint and its foreign-owner gap. * @capability territory-read-scope Load the footprint and foreign-owner gap without scanning the world. */ export declare function territoryChunkKeys(cells: readonly TerritoryCell[], policy?: TerritoryPolicy): string[]; /** * Owner of a loaded cell; hosts load the target and gap neighborhood before evaluating claims. * @capability territory-owner-query Read a loaded land cell owner for authoritative placement checks. */ export declare function territoryOwnerOf(snapshot: GameRuntimeSnapshot, cell: TerritoryCell, policy?: TerritoryPolicy): string | null; /** * Cells touched by a placement, excluding cells that only touch its outer edge. * @capability territory-footprint Resolve exactly the ownership cells touched by a placement footprint. */ export declare function territoryFootprintCells(bounds: Aabb, cellSize?: number): TerritoryCell[]; /** Price and validate a footprint without mutating or charging; reuse for placement previews. */ export declare function planFootprintClaims(snapshot: GameRuntimeSnapshot, userId: string, footprint: readonly TerritoryCell[], policy?: TerritoryPolicy): TerritoryPlan; /** Atomically buy every unowned footprint cell, leaving the input untouched on failure. */ export declare function claimTerritory(snapshot: GameRuntimeSnapshot, userId: string, cells: readonly TerritoryCell[], policy?: TerritoryPolicy): TerritoryResult; /** * Placement transaction: rejected object placement also rolls back territory and its charge. * @capability territory-placement Purchase footprint cells atomically with object placement. */ export declare function placeWithTerritory(snapshot: GameRuntimeSnapshot, userId: string, bounds: Aabb, policy: TerritoryPolicy, place: (snapshot: GameRuntimeSnapshot) => { ok: true; snapshot: GameRuntimeSnapshot; } | { ok: false; reason: string; }): { ok: true; snapshot: GameRuntimeSnapshot; cost: number; } | { ok: false; reason: string; }; /** * Snapshot-backed territory facade with host-owned storage and live policy. * @capability territory-ownership Claim, release and query land through host-owned snapshot storage. */ export declare function createTerritory(storage: TerritoryStorage, policy?: () => TerritoryPolicy): { snapshot: () => GameRuntimeSnapshot; restore: (snapshot: GameRuntimeSnapshot) => void; ownerOf: (cell: TerritoryCell) => string | null; canUse: (userId: string, cell: TerritoryCell) => boolean; claim(userId: string, cells: readonly TerritoryCell[]): TerritoryResult; release(userId: string, cell: TerritoryCell): boolean; grantStarter(userId: string, center: TerritoryCell): TerritoryResult; }; /** Snapshot-backed claim, release, owner and starter-grant operations. */ export type Territory = ReturnType;