Files
aevolution/include/evo/server/lifecycle/cellular_revamp.hpp
T
dingoandClaude Opus 5.5 757304437e
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m34s
Foundation / postgres-tools (push) Successful in 26s
Foundation / server-image (push) Successful in 4m30s
Foundation / image (push) Successful in 5m46s
feat(admin): take reserve, cull wildlife, wildlife cap, fresh bud costs (schema 67)
ADR-0182 section 16, from playtesting region 16 at its 256-life cap.

- Bud costs: the region host's cache of each genome's bud cost was keyed
  by genome only, so after a tuning adoption the client kept the old cost
  (or "cannot bud"). It now clears when the rules' encoding changes.
- Wildlife cap: reproduction.wildlife_cap (optional, 0..organism cap,
  0 = the organism cap) refuses buds of parents without an account at that
  many lives, keeping the slots above it for players. Bits 17-31 of the
  energy-cycle word, so older rules keep their bytes. DEV file: 200.
- Schema 67: admin command kinds take_reserve (8: up to the amounts from a
  life's reserve to the spent pool) and remove_wildlife (9: every life
  without an account, as remove_cell).
- Region view: caps; the portal shows lives against the cap.
- Portal: Take reserve in the inspector, Remove all wildlife, and marking
  cells on the map (shift+click, shift+drag) for bulk removal; the guided
  editor lists optional keys the base revision lacks.
- Client: a refused bud says the region may be full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 16:06:56 -04:00

152 lines
8.9 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{};
// ADR-0182 section 14 (0 and false keep the historical law): the share of the region's
// heat, per mille, moved to the spent pool at the end of every tick before the drip, so
// energy cycles back like matter; and a drip at the deposit limit joins an existing bubble
// (the first at or after its spot) instead of waiting.
std::uint32_t heat_recycle_per_thousand{};
bool drip_absorb{};
// 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};
// Wildlife buds are refused at this many lives (0: the organism cap), leaving the slots
// above it to players; spawning still answers to the organism cap. Below 32,768.
std::uint32_t wildlife_cap{};
// Multicellular organisms (reproduction plan section 6): the share of the extra members'
// mass carried as load on one cell's thrust, and the emergence threshold.
std::uint32_t organism_load_per_thousand{500};
std::uint32_t emerge_members{8};
std::uint64_t emerge_mass_fg{}, emerge_reserve_pj{};
// ADR-0181: 0 preserves historical behavior. Revision 1 makes split_share
// the controlled cell's share, returns bud fees to that cell, launches mutation
// offspring, and protects a growth fuel buffer for every organism.
std::uint32_t safety_version{}, growth_reserve_seconds{}, split_launch_um_per_s{};
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::uint16_t members{1}; // Cells in the organism: 1 for a single cell.
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, or with `drip_absorb` adds it to the
// first bubble at or after that spot in address order (wrapping). 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);
// ADR-0182 admin bubbles: `amount` as `count` bubbles, each channel split evenly (the remainder
// in the last), at seeded random spots nudged east past taken addresses, with the next deposit
// ids and `source`. False, with `config` unchanged, when the habitat cannot take them all.
[[nodiscard]] bool cellular_scatter_bubbles(biology::CellularHabitatConfig& config,
const accounting::Inventory& amount,
std::uint16_t count, std::uint64_t seed,
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,
std::uint64_t extra_load = 0) noexcept;
// Rules from the revamp tuning file.
[[nodiscard]] CellularRevampRules
cellular_revamp_rules(const biology::CellularRevampTuning& tuning);
} // namespace evo::server