#pragma once #include "evo/server/lifecycle/cellular_population.hpp" #include #include #include #include #include #include namespace evo::server { inline constexpr std::uint32_t cellular_census_projection_version = 1; inline constexpr std::uint32_t cellular_plan_census_projection_version = 2; enum class CellularCensusKind : std::uint8_t { individual_wildlife, cohort_wildlife, active_controlled, lingering_controlled, suspended_controlled }; inline constexpr std::size_t cellular_census_kind_count = 5; struct CellularCensusStock { std::uint64_t count{}; accounting::Inventory body{}, reserve{}; bool operator==(const CellularCensusStock&) const = default; }; struct CellularCensusTotals { std::array resident{}; // Historical observations only: no owned inventory/current viability claim. std::uint64_t retained_nonresident_records{}; // Projection 2: references only, never additional organisms or inventory. std::array living_plan_holders{}; std::uint64_t retained_dead_plan_records{}; bool operator==(const CellularCensusTotals&) const = default; }; struct CellularCensusRow { std::uint64_t genome{}; std::uint32_t schema{}, development{}; std::vector parents; CellularCensusTotals totals; bool operator==(const CellularCensusRow&) const = default; }; struct CellularCensusBoundary { std::uint64_t world{}, region{}, frame{}, tick{}; std::uint32_t owner_format{}, rules{}, population_format{}; // Zero: raw owner. std::uint64_t quantum_microseconds{biology::cellular_motion_tick_microseconds}; std::uint32_t projection_version{cellular_census_projection_version}; bool operator==(const CellularCensusBoundary&) const = default; }; enum class CellularCensusScope : std::uint8_t { exact_genome, descendants, invalid = 255 }; enum class CellularCensusError : std::uint8_t { unsupported, history, overflow, unknown_genome, invalid_scope }; // Detached bounded observation, NOT a committed/world-complete evidence record. // It never owns inventory, changes biology or reports terminal extinction. // ADR-0159: rules 8/owner 6 or 7; rules 9/owner 7 (raw or population envelope 2). // Growth observes retained body/reserve, never an unfunded adult forecast. // ADR-0169/0171: rules 10/owner 8, raw or envelope 3, uses projection 2. class CellularCensus { public: [[nodiscard]] static std::expected observe(const CellularLives&); [[nodiscard]] static std::expected observe(const CellularPopulation&); [[nodiscard]] const CellularCensusBoundary& boundary() const noexcept { return boundary_; } // Ascending genome IDs. All retained ancestors remain, even with zero residents. [[nodiscard]] std::span rows() const noexcept { return rows_; } // Descendants includes the anchor. Unknown is an error, never a zero report. [[nodiscard]] std::expected query(std::uint64_t anchor, CellularCensusScope scope) const; private: friend class CellularCensusSet; CellularCensus() = default; [[nodiscard]] static std::expected observe(const CellularLives&, std::span, std::uint32_t population); [[nodiscard]] std::size_t locate(std::uint64_t genome) const; CellularCensusBoundary boundary_; std::vector rows_; std::vector> children_; // Complete immutable identity evidence for cross-region consistency checks. // A short content digest alone cannot establish equality. std::vector genomes_; std::vector residents_; }; } // namespace evo::server