Files
dingoandClaude Opus 5.5 76d21b4815
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 31s
Foundation / server-image (push) Successful in 4m24s
Foundation / image (push) Successful in 5m3s
feat(cellular): rules 13 feeding, matter as energy, spent pool and predation
Phase 2 of the cellular revamp build plan (ADR-0179), server half.

- Matter as energy: when an energy cost exceeds the reserve's energy, reserve
  matter stands in for the rest at each channel's burn rate (pJ per 1,000 fg,
  scaled by the genome's burn efficiency), largest channel first. Upkeep may
  burn any channel; thrust only channels the player has not excluded. Burned
  matter adds no heat; it goes to the region's spent pool. A cell dies only when
  nothing can pay its upkeep.
- Collection: per-channel limits scaled by the genome's collection indices, a
  shared limit on all matter, a tunable cost per membrane point, and only the
  genome's kept share (energy conversion) of bubble energy reaching the reserve.
- Predation: engulf mass carries a tunable share of reserve matter, the
  predator's engulf capacity scales its side and the prey's membrane (now in
  nanometres) its own; kill absorption scales the predator's intake; the kill's
  remainder is split between bubbles at the prey and the spent pool, and a full
  habitat sends overflow to the pool.
- The spent pool is owner format 11 state, counted in conservation, and drips
  back as seeded random bubbles every interval tick.
- Reserve matter is carried as load: slower thrust and turning, costlier thrust.
- Channel exclusions are a 4-bit step intent field, trace byte 14; only owned
  lives under rules 13 may send them.

All values come from the revamp tuning file. Rules up to 12 are unchanged. Tests
cover payments and their conservation over 400 seeds, the rules-13 region step
(collection, membrane, kept energy, burning, engulfment and kill splits with
closure), the drip, load, exclusions, a 700-tick run with closure and exact
restore, and trace replay with exclusions. Session v14 and the client follow
the server phases (build plan). Refreshes the DEV session window.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 18:35:31 -04:00

53 lines
2.6 KiB
C++

#pragma once
#include "evo/accounting/ledger.hpp"
#include <array>
#include <compare>
#include <cstdint>
#include <optional>
// 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<std::uint64_t, cellular_matter_channels> 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<std::uint64_t, cellular_matter_channels>& base_pj_per_kfg,
const std::array<std::uint16_t, cellular_matter_channels>& 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<CellularPayment> cellular_pay(accounting::Inventory& reserve,
std::uint64_t cost,
const CellularBurn& burn,
bool override_exclusions) noexcept;
} // namespace evo::biology