Files
aevolution/include/evo/server/lifecycle/cellular_revamp.hpp
T
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.9 KiB
C++

#pragma once
#include "evo/biology/cellular_habitat.hpp"
#include "evo/biology/cellular_region_step.hpp"
#include "evo/biology/cellular_revamp_tuning.hpp"
#include "evo/biology/development.hpp"
#include <array>
#include <compare>
#include <cstdint>
// Rules 13 (ADR-0179, Cellular_Revamp_Build_Plan.md): what a cellular owner declares when it
// upgrades to owner format 11. Taken from the Git tuning file when the region opens and
// persisted with the owner, so replay and restore never read the file. Later build phases add
// the feeding, mutation and reproduction tunables here.
namespace evo::server {
struct CellularRevampRules {
biology::BodyTuning body{};
// Picojoules 1,000 fg of C, N, P and other matter stand in for at burn efficiency 100.
std::array<std::uint64_t, 4> burn_pj_per_kfg{};
biology::CellularRevampStepRules step{};
// The spent pool drips back as bubbles every `drip_interval_ticks` ticks (0: never), one
// bubble per non-empty channel of at most these amounts, at seeded random spots.
std::uint32_t drip_interval_ticks{};
std::uint64_t drip_bubble_pj{}, drip_bubble_fg{};
// Share of reserve matter carried as load, per mille: it slows thrust and turning and makes
// thrust costlier, in proportion to the body's mass. Upkeep stays on the body.
std::uint32_t reserve_load_per_thousand{};
auto operator<=>(const CellularRevampRules&) const = default;
};
[[nodiscard]] bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept;
// The spent pool's drip for the tick ending at `tick`: on every `drip_interval_ticks`-th tick,
// one bubble per non-empty channel of at most the declared size, taken from `spent`, at a
// seeded random spot (nudged east past taken addresses) with the next deposit id and `source`.
// A habitat at its deposit limit keeps the rest waiting. False only on identity overflow, with
// `config` and `spent` then unusable.
[[nodiscard]] bool cellular_drip_spent(biology::CellularHabitatConfig& config,
accounting::Inventory& spent,
const CellularRevampRules& rules, std::uint64_t world,
std::uint64_t region, std::uint64_t tick,
std::uint64_t source);
// A body's handling carrying reserve matter: thrust, reverse thrust and turning scale by
// body / (body + load), full-output costs by (body + load) / body, where load is the declared
// share of `carried` matter. Drag is unchanged. No load leaves the handling as it is.
[[nodiscard]] biology::CellularHandling
cellular_loaded_handling(const biology::CellularHandling& handling, std::uint64_t body_mass,
std::uint64_t carried, const CellularRevampRules& rules) noexcept;
// Rules from the revamp tuning file.
[[nodiscard]] CellularRevampRules
cellular_revamp_rules(const biology::CellularRevampTuning& tuning);
} // namespace evo::server