#pragma once #include "evo/accounting/ledger.hpp" #include "evo/biology/genome.hpp" #include #include #include #include #include #include #include // The named mutation catalog of rules 13 (ADR-0179; Cellular_mutation_plan.md sections 5-9). // Each entry edits a genome's plan within bounds; what triggers raise or lower its chance and // how offers are drawn live in cellular_triggers.hpp and cellular_offers.hpp. IDs are stable. namespace evo::biology { // What a mutation edits. Point-based traits move in fixed reference points: one point is a // hundredth of the founder's value, whatever the trait's unit. enum class CellularTrait : std::uint8_t { none, move_output, move_efficiency, move_steering, move_streamlining, move_braking, move_coasting, collect_energy, collect_carbon, collect_nitrogen, collect_phosphorus, collect_other, intake, // Ingestion capability, femtograms per second. energy_kept, // Energy conversion capability, per thousand. burn_carbon, burn_nitrogen, burn_phosphorus, burn_other, light, // Photosynthesis capability, per thousand. membrane, // Nanometres. engulf_capacity, kill_absorption, size, // Target size, femtograms. recipe_carbon, recipe_nitrogen, recipe_phosphorus, recipe_other, upkeep_efficiency, growth_speed, density, bud_share, // Reproduction capability, per thousand. litter, // Hundredths of an extra offspring; moves in its own units, not points. }; enum class CellularEffect : std::uint8_t { adjust, // Primary by the primary step, paired by the paired step, spread. recipe, // Recipe: primary loses the recipe step, the other three share it. acquire_light, // Photosynthesis at the founder reference, with the paired edit. shed_light, // Photosynthesis removed. acquire_adhesion, // Adhesion set. }; // A spread lowers each other channel of the primary's group by the spread step. enum class CellularSpread : std::uint8_t { none, collect_matter, burn }; // Extra eligibility beyond staying within bounds. enum class CellularAvailability : std::uint8_t { always, light_absent_after_carbon, // No photosynthesis, and enough carbon burned. light_present, adhesion_absent_after_buds, // No adhesion, and enough on-demand buds. }; // What a cell does that a trigger counts. Flags are 0 or 1 per tick; amounts are pJ or fg. enum class CellularSignal : std::uint8_t { thrust, // Thrust applied this tick. drifting, // No thrust this tick. brake_press, // Brake pressed this tick and not the last. fed, // Anything collected. intake_limited, // Matter collection held by a limit. energy_limited, // Energy collection held by its limit. energy_collected, // Amount of energy collected. collected_carbon, // Amounts of matter collected, by channel, and in total. collected_nitrogen, collected_phosphorus, collected_other, collected_matter, burned_carbon, // Amounts of matter burned for energy, by channel, and in total. burned_nitrogen, burned_phosphorus, burned_other, burned_matter, burned_not_carbon, energy_upkeep, // Energy spent on upkeep, on movement, and in total. energy_movement, energy_spent, larger_contact, // Touching a cell over 1.5 times this cell's mass. engulf_attempt, // An engulf was asked for. engulf_success, engulf_too_large, // Failed: prey too large. engulf_too_large_or_membrane, // Failed: prey too large or membrane too thick. reserve_over_body, // More matter in the reserve than in the body. regrowing, // Growing toward full size. fully_grown, blocked_carbon, // Growth or a bud held back by this channel. blocked_nitrogen, blocked_phosphorus, blocked_other, bud_done, // An on-demand bud was made. bud_refused, // An on-demand bud was refused for lack of resources. bud_lost_early, // One of this cell's buds was engulfed within 2 minutes of birth. bud_with_surplus, // A bud made with the reserve covering twice its cost. }; inline constexpr std::size_t cellular_signal_count = 37; enum class CellularTriggerKind : std::uint8_t { accumulate, // Fires each time the signal has been present for `ticks` ticks in total. absence, // Fires when the signal has been absent for `ticks` ticks running. count, // Fires when the signal happened `count` times within `ticks` (0: any time). event, // Fires each time the signal happens. share, // Every `ticks` ticks: fires if signal / denominator >= per_thousand. regular, // Fires when the signal recurred with gaps of at most `gap` for `ticks`. straight, // Fires after `ticks` thrust ticks within `angle` of one heading. turns, // Fires after `count` turns of more than `angle` within `ticks`. }; struct CellularTriggerSpec { CellularTriggerKind kind{}; CellularSignal signal{}; std::uint32_t ticks{}; std::uint32_t count{}; CellularSignal denominator{}; // share only. std::uint32_t per_thousand{}; // share only. std::uint32_t gap{}; // regular only. std::uint16_t angle{}; // straight and turns: heading units (65,536 per turn). auto operator<=>(const CellularTriggerSpec&) const = default; }; struct CellularMutationSpec { std::uint16_t id{}; std::string_view key, name, pro, con; CellularEffect effect{}; CellularTrait primary{}, paired{}; std::int8_t primary_sign{}, paired_sign{}; CellularSpread spread{}; CellularAvailability available{}; CellularTriggerSpec increase{}, decrease{}; std::uint32_t base_weight{100}; std::uint32_t primary_step{5}; // Default primary step in its units (points; recipe 20). }; inline constexpr std::size_t cellular_catalog_size = 49; [[nodiscard]] std::span cellular_catalog() noexcept; [[nodiscard]] const CellularMutationSpec* cellular_mutation(std::uint16_t id) noexcept; // One mutation's tunables (Cellular_mutation_plan.md sections 3-4); defaults from its spec. struct CellularMutationTuning { bool enabled{true}; std::uint32_t base_weight{100}; std::int32_t increase_points{100}, decrease_points{100}; std::uint32_t primary_step{5}, paired_step{2}, spread_step{1}; accounting::Inventory cost{}; std::uint32_t cost_scale_percent{}; std::uint32_t increase_ticks{}, decrease_ticks{}; // 0: the spec's threshold. auto operator<=>(const CellularMutationTuning&) const = default; }; // Bounds and gates shared by every mutation. struct CellularCatalogBounds { std::uint32_t min_points{25}, max_points{1'000}; std::uint32_t recipe_min_share{20}; // Per thousand; the founder's phosphorus is 50. std::uint32_t max_litter{900}; // 10 offspring per bud. std::uint64_t carbon_for_light{}; // Femtograms of carbon burned before photosynthesis. std::uint32_t buds_for_adhesion{5}; auto operator<=>(const CellularCatalogBounds&) const = default; }; // Lineage progress the gates read. struct CellularLineageProgress { std::uint64_t carbon_burned{}; std::uint32_t buds{}; auto operator<=>(const CellularLineageProgress&) const = default; }; [[nodiscard]] CellularMutationTuning cellular_default_tuning(const CellularMutationSpec& spec) noexcept; // The successor plan the mutation makes from `plan` (a schema-7 genome), or nothing when it is // not available: a gate is closed, the trait is absent, or an edit would leave its bounds. The // successor has one parent, `plan`, and identity `successor_id` from `origin_event`. [[nodiscard]] std::optional apply_cellular_mutation(const Genome& plan, const CellularMutationSpec& spec, const CellularMutationTuning& tuning, const CellularCatalogBounds& bounds, const CellularLineageProgress& progress, std::uint64_t successor_id, std::uint64_t origin_event); } // namespace evo::biology