Files
aevolution/include/evo/server/lifecycle/cellular_revamp.hpp
T
dingoandClaude Opus 5.5 9f117c9545
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m22s
Foundation / postgres-tools (push) Successful in 22s
Foundation / server-image (push) Successful in 4m21s
Foundation / image (push) Successful in 5m6s
feat(lifecycle): rules 13 mutation splits, stay-or-become and litter
Phase 4 of the cellular revamp build plan (ADR-0179), server half.

- A chosen mutation now splits the cell (Cellular_reproduction_plan.md section
  4): split_cell divides body and reserve per channel by the tuned share, each
  cell develops the largest body its own genome builds from its part, and the
  rest joins its reserve, conserving every channel. Both plans carry the
  mutation; only the offspring expresses it. A split is refused, spending
  nothing and keeping the offer, below the tuned growth, without room beside
  the cell or at the region's organism cap.
- Stay or become: a choice (trace mutation byte 34) or a bud (step intent bit 2
  of byte 13) can hand control to the offspring; the parent becomes wildlife.
  Ownership now follows the account under rules 13, so validation and plan
  history accept a founder that became wildlife (ADR-0163 succession).
- Buds under rules 13: litter replaces the 25% twin (whole hundreds plus a
  chance, up to the tuned maximum, sharing one investment), the tuned bud fee is
  charged once and reclaimed, and births stop at the organism cap.
- New results split_applied and split_refused; owners below rules 13 refuse a
  become.

The revamp tuning file gains the reproduction keys. Tests cover the split's
conservation and refusals, stay and become splits with exact restore, a refused
second split, the cap, become validation and the litter count. Refreshes the DEV
session window.

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

124 lines
6.8 KiB
C++

#pragma once
#include "evo/biology/cellular_catalog.hpp"
#include "evo/biology/cellular_habitat.hpp"
#include "evo/biology/cellular_motion.hpp"
#include "evo/biology/cellular_offers.hpp"
#include "evo/biology/cellular_region_step.hpp"
#include "evo/biology/cellular_revamp_tuning.hpp"
#include "evo/biology/cellular_triggers.hpp"
#include "evo/biology/development.hpp"
#include <array>
#include <compare>
#include <cstdint>
#include <optional>
// 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{};
// Growth per tick in hundredths of a per mille at growth speed 100 (trial 500: 5 per mille).
std::uint32_t growth_per_tick_centi_mille{500};
// Mutation offers: the draw, the catalog's bounds and gates, the cadence in active ticks,
// and every catalog mutation's tunables in catalog order.
biology::CellularOfferRules offers{};
biology::CellularCatalogBounds bounds{};
std::uint32_t offer_interval_ticks{500};
std::array<biology::CellularMutationTuning, biology::cellular_catalog_size> mutations{};
// Reproduction: the offspring's share of a split and the growth a cell needs to split; the
// on-demand bud's fee (amounts times scale, reclaimed); the region's organism cap.
std::uint32_t split_share_per_thousand{500}, split_min_growth{1'000};
accounting::Inventory bud_fee{};
std::uint32_t bud_fee_scale_percent{};
std::uint32_t organism_cap{256};
auto operator<=>(const CellularRevampRules&) const = default;
};
// A rules-13 offer: the drawn mutations (catalog ids) and their chances, in catalog order.
inline constexpr std::size_t max_cellular_offer_options = 10;
struct CellularRevampOffer {
std::uint64_t event_index{}, offer_tick{};
std::uint8_t count{};
std::array<std::uint16_t, max_cellular_offer_options> ids{};
std::array<std::uint32_t, max_cellular_offer_options> chances{};
auto operator<=>(const CellularRevampOffer&) const = default;
};
// A rules-13 life's mutation state: affinity, lineage progress, the cadence counter, the pending
// offer (count 0: none), the previous tick's brake (for presses) and the growth carry.
struct CellularRevampLife {
biology::CellularAffinity affinity{};
biology::CellularLineageProgress progress{};
std::uint32_t active_ticks{};
std::uint8_t last_brake{};
std::uint32_t growth_carry{};
std::uint64_t events{}; // Offers made so far; the next offer's event index is events + 1.
CellularRevampOffer offer{};
auto operator<=>(const CellularRevampLife&) const = default;
};
// The rules' offer settings as the catalog and offer code take them.
[[nodiscard]] bool cellular_revamp_offer_rules_valid(const CellularRevampRules& rules) noexcept;
// Draws an offer from `plan`'s eligible mutations at its affinity, or nothing when fewer
// mutations are eligible than the cap can fill. Seeded by world, region, life and event, so a
// retry draws the same offer.
[[nodiscard]] std::optional<CellularRevampOffer>
cellular_draw_offer(const biology::Genome& plan, const CellularRevampLife& life,
const CellularRevampRules& rules, std::uint64_t world, std::uint64_t region,
std::uint64_t life_id, std::uint64_t tick);
// How many offspring one bud makes from `litter` (hundredths of an extra offspring) and a roll:
// one, plus every whole hundred, plus one more when roll % 100 falls below the remainder; at most
// max_litter / 100 + 1.
[[nodiscard]] constexpr std::uint32_t
cellular_litter_count(std::uint32_t litter, std::uint64_t roll, std::uint32_t max_litter) noexcept {
const auto count = 1 + litter / 100 + (roll % 100 < litter % 100 ? 1U : 0U);
return count < max_litter / 100 + 1 ? count : max_litter / 100 + 1;
}
// What choosing a mutation costs: its amounts times its scale.
[[nodiscard]] accounting::Inventory
cellular_mutation_cost(const biology::CellularMutationTuning& tuning) noexcept;
// Returns `amount` to the region as bubbles at seeded random spots, one per non-empty channel;
// a habitat at its deposit limit merges each into the existing deposit farthest from `from`.
// False only on identity overflow.
[[nodiscard]] bool cellular_reclaim(biology::CellularHabitatConfig& config,
const accounting::Inventory& amount, std::uint64_t seed,
biology::CellularPosition from, std::uint64_t source);
[[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