#pragma once #include "evo/biology/cellular_step.hpp" #include #include #include #include #include #include namespace evo::biology { inline constexpr std::size_t max_cellular_tick_lives = 256; struct CellularLifeStepInput { std::uint64_t life_id{}; // Stable world identity; arbitrates same-tick patch contention. CellularPosition position; std::uint32_t extent_um{}; CellularStepIntent intent; accounting::Inventory body; // Structural matter; energy must be zero. accounting::Inventory reserve; accounting::Inventory heat; // Energy-only owner; matter channels must be zero. MetabolicBudget budget; auto operator<=>(const CellularLifeStepInput&) const = default; }; struct CellularLifeStepResult { std::uint64_t life_id{}; CellularStepCandidate candidate; auto operator<=>(const CellularLifeStepResult&) const = default; }; struct CellularPatchStockUpdate { CellularPatchAddress address; accounting::Inventory stock; auto operator<=>(const CellularPatchStockUpdate&) const = default; }; struct CellularCorpseCandidate { std::uint64_t life_id{}; CellularPosition position; accounting::Inventory inventory; // Body and reserve; accumulated heat is transferred out. auto operator<=>(const CellularCorpseCandidate&) const = default; }; struct CellularRegionStepCandidate { std::uint64_t begin_tick{}, end_tick{}; // Sorted by stable life_id, independent of connection or input order. std::vector lives; std::vector patches; std::vector starved; accounting::Picojoules heat_released{}; auto operator<=>(const CellularRegionStepCandidate&) const = default; }; enum class CellularRegionStepError : std::uint8_t { invalid_tick, too_many_lives, invalid_life_id, duplicate_life_id, invalid_body, invalid_heat, overflow, life_step, habitat }; // Detached shared-habitat candidate. Same-tick claims resolve by ascending stable life id; // the first valid claimant spends from each patch's remaining per-channel stock. Any refused // life step rejects the complete candidate; the caller publishes nothing. If maintenance // cannot be paid, the life dies in this tick: body and reserve move to one corpse candidate, // and its accumulated heat is reported separately for transfer to the world heat owner. [[nodiscard]] std::expected propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area, std::span lives, const CellularHabitat& habitat); } // namespace evo::biology