#pragma once #include "evo/accounting/ledger.hpp" #include #include #include #include // Matter as energy (rules 13, ADR-0179; Cellular_feeding_energy_plan.md section 3). When an // energy cost is larger than the reserve's energy, reserve matter stands in for the rest at // each channel's burn rate. The matter is not converted: it leaves the cell as spent matter, // which the region owner keeps in its spent pool. No energy is created, so a cost paid with // matter adds no heat. namespace evo::biology { inline constexpr std::size_t cellular_matter_channels = 4; // C, N, P, other. struct CellularBurn { // Picojoules 1,000 fg of each matter channel stands in for, after the cell's burn // efficiency. Zero means the channel cannot be burned. std::array pj_per_kfg{}; // Bit c set: the player keeps channel c (C = bit 0). Upkeep may override it. std::uint8_t excluded{}; auto operator<=>(const CellularBurn&) const = default; }; // The burn rates of a cell: each base rate times its burn efficiency index over 100. [[nodiscard]] CellularBurn cellular_burn(const std::array& base_pj_per_kfg, const std::array& efficiency, std::uint8_t excluded) noexcept; // Energy the reserve could pay: its energy plus what its burnable matter stands in for. // `override_exclusions` also counts excluded channels (upkeep). [[nodiscard]] std::uint64_t cellular_payable_energy(const accounting::Inventory& reserve, const CellularBurn& burn, bool override_exclusions) noexcept; // Pays `cost` from `reserve`: its energy first, then matter from the largest burnable channel // (ties C, N, P, O), the next largest when that runs out. Returns the energy paid and the // matter spent, and leaves `reserve` debited; nothing changes when the whole cost cannot be // paid. A channel pays whole femtograms, so matter may cover slightly more than the cost. struct CellularPayment { std::uint64_t energy{}; accounting::Inventory spent{}; // Matter only. auto operator<=>(const CellularPayment&) const = default; }; [[nodiscard]] std::optional cellular_pay(accounting::Inventory& reserve, std::uint64_t cost, const CellularBurn& burn, bool override_exclusions) noexcept; } // namespace evo::biology