feat(lifecycle): rules 13 multicellular organisms and Emerge
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m32s
Foundation / postgres-tools (push) Successful in 21s
Foundation / server-image (push) Successful in 4m12s
Foundation / image (push) Successful in 4m52s

Adhesion turns a cell into a two-member organism: one life with a member
count, one genome and one reserve, developed as its genome with the target
size times its members. The single cell ends as an empty merged corpse.
An organism expresses accepted mutations as a whole, paid from its reserve;
its buds add internal members (wildlife stops one short of the threshold);
the extra members' mass loads its thrust. At the emergence threshold the
Emerge intent exports the body and reserve through the boundary ledger and
ends the life as emerged.

Records the maintainer's 2026-10-23 decisions in ADR-0179 and the project
vision (whole-organism mutations; the playtest form of Emerge).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-23 06:50:19 -04:00
co-authored by Claude Opus 5.5
parent 9f117c9545
commit f454e038a1
21 changed files with 664 additions and 50 deletions
+7 -5
View File
@@ -58,7 +58,8 @@ bool valid_intent(const CellularLifeIntent& life) {
!(step.bud && (step.intake_target || step.engulf)) &&
!(step.frozen && (step.movement != biology::CellularIntent{} || step.intake_target ||
step.engulf || step.bud || step.brake || step.exclude != 0)) &&
step.exclude <= 0x0F && !(step.become && !step.bud);
step.exclude <= 0x0F && !(step.become && !step.bud) &&
!(step.emerge && (step.frozen || step.bud || step.engulf || step.intake_target));
}
bool valid_ticks(std::span<const CellularTickIntents> ticks) {
std::set<std::uint64_t> identities;
@@ -167,9 +168,9 @@ void put_intent(std::vector<std::uint8_t>& out, const CellularLifeIntent& life)
// Flags: bit 0 frozen (ADR-0128), bit 1 brake (rules 12). SQL never parses this byte, and
// player action records keep it zero: the trace alone carries a brake.
// Bit 2 (rules 13): continue as the bud.
out.push_back(static_cast<std::uint8_t>((life.intent.frozen ? 1U : 0U) |
(life.intent.brake ? 2U : 0U) |
(life.intent.become ? 4U : 0U)));
out.push_back(
static_cast<std::uint8_t>((life.intent.frozen ? 1U : 0U) | (life.intent.brake ? 2U : 0U) |
(life.intent.become ? 4U : 0U) | (life.intent.emerge ? 8U : 0U)));
// Byte 14 (rules 13): kept matter channels, bits 0-3; byte 15 stays zero.
out.push_back(life.intent.exclude);
out.push_back(0);
@@ -311,7 +312,7 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
step.lives.reserve(static_cast<std::size_t>(count));
for (std::uint64_t i = 0; i < count; ++i) {
const auto record = bytes.subspan(offset, cellular_batch_intent_bytes);
if (record[12] > 3 || record[13] > 7 || record[14] > 0x0F || record[15] != 0)
if (record[12] > 3 || record[13] > 15 || record[14] > 0x0F || record[15] != 0)
return std::unexpected{CellularBatchError::format};
CellularLifeIntent life;
life.life_id = get(record, 0, 8);
@@ -332,6 +333,7 @@ decode_cellular_batch(std::span<const std::uint8_t> bytes) {
life.intent.brake = (record[13] & 2U) != 0; // Rules 12; owners below refuse it.
life.intent.exclude = record[14]; // Rules 13; owners below refuse it.
life.intent.become = (record[13] & 4U) != 0; // Rules 13; owners below refuse it.
life.intent.emerge = (record[13] & 8U) != 0; // Rules 13; owners below refuse it.
if (!valid_intent(life) ||
(!step.lives.empty() && step.lives.back().life_id >= life.life_id))
return std::unexpected{CellularBatchError::format};
+330 -13
View File
@@ -66,7 +66,7 @@ constexpr std::size_t cellular_revamp_mutation_bytes = 80;
// the bud fee (40).
constexpr std::size_t cellular_lives_v11_header_bytes =
cellular_lives_v10_header_bytes + 120 + 8 + 32 + 32 + 8 +
biology::cellular_catalog_size * cellular_revamp_mutation_bytes + 56;
biology::cellular_catalog_size * cellular_revamp_mutation_bytes + 56 + 24;
// Each format-11 life adds its mutation state: 49 scores and a reserved zero (100), 98 trigger
// states of 24 bytes (2,352), lineage progress and the cadence counter (16), the last brake,
// three zeros and the growth carry (8), the offers made (8), and the pending offer (88).
@@ -249,6 +249,10 @@ void write_revamp_offers(Writer& out, const CellularRevampRules& r) {
{r.split_share_per_thousand, r.split_min_growth, r.organism_cap, r.bud_fee_scale_percent})
out.put(value, 4);
out.inventory(r.bud_fee);
out.put(r.organism_load_per_thousand, 4);
out.put(r.emerge_members, 4);
out.put(r.emerge_mass_fg);
out.put(r.emerge_reserve_pj);
}
bool read_revamp_offers(Reader& in, CellularRevampRules& r) {
const auto u32 = [&in] { return static_cast<std::uint32_t>(in.get(4)); };
@@ -297,6 +301,10 @@ bool read_revamp_offers(Reader& in, CellularRevampRules& r) {
r.organism_cap = u32();
r.bud_fee_scale_percent = u32();
r.bud_fee = in.inventory();
r.organism_load_per_thousand = u32();
r.emerge_members = u32();
r.emerge_mass_fg = in.get();
r.emerge_reserve_pj = in.get();
return zero;
}
void write_revamp_life(Writer& out, const CellularRevampLife& life) {
@@ -311,7 +319,8 @@ void write_revamp_life(Writer& out, const CellularRevampLife& life) {
out.put(life.progress.buds, 4);
out.put(life.active_ticks, 4);
out.put(life.last_brake, 1);
out.zeros(3);
out.zeros(1);
out.put(life.members, 2);
out.put(life.growth_carry, 4);
out.put(life.events);
const auto& offer = life.offer;
@@ -346,8 +355,10 @@ std::optional<CellularRevampLife> read_revamp_life(Reader& in) {
life.progress.buds = static_cast<std::uint32_t>(in.get(4));
life.active_ticks = static_cast<std::uint32_t>(in.get(4));
const auto brake = in.get(1);
zero = zero && brake <= 1 && in.get(3) == 0;
zero = zero && brake <= 1 && in.get(1) == 0;
life.last_brake = static_cast<std::uint8_t>(brake);
life.members = static_cast<std::uint16_t>(in.get(2));
zero = zero && life.members >= 1;
life.growth_carry = static_cast<std::uint32_t>(in.get(4));
life.events = in.get();
auto& offer = life.offer;
@@ -381,13 +392,75 @@ std::optional<CellularRevampLife> read_revamp_life(Reader& in) {
return life;
}
// Rules 13 (reproduction plan section 6): a multicellular organism develops as its genome with
// the target size times its members, so mass, footprint, upkeep and growth follow from it.
std::expected<biology::Genome, CellularLivesError> organism_genome(const biology::Genome& genome,
std::uint32_t members) {
if (members <= 1)
return genome;
biology::GenomeDraft draft;
draft.schema_version = genome.schema_version();
draft.id = genome.id();
draft.origin_event = genome.origin_event();
draft.development_version = genome.development_version();
draft.parents.assign(genome.parents().begin(), genome.parents().end());
draft.capabilities.assign(genome.capabilities().begin(), genome.capabilities().end());
draft.movement_arrangement = genome.movement_arrangement();
draft.cellular_traits = genome.cellular_traits();
for (auto& record : draft.capabilities)
if (record.kind == biology::Capability::target_size) {
if (record.parameter > std::numeric_limits<std::uint32_t>::max() / members)
return std::unexpected{CellularLivesError::biology};
record.parameter *= members;
}
const auto made = biology::Genome::create(draft);
if (!made)
return std::unexpected{CellularLivesError::biology};
return *made;
}
std::expected<biology::Genome, CellularLivesError>
life_genome(const biology::LineageArchive& archive, const CellularOwnedLife& life) {
const auto genome = archive.find(life.identity.genome);
if (!genome)
return std::unexpected{CellularLivesError::archive};
return organism_genome(*genome, life.revamp.members);
}
// Moves `body` to `target`: added matter from `reserve` per channel with construction energy
// (to `heat`) at `price` pJ per 1,000 fg added, freed matter back to the reserve. Changes nothing
// and returns false when the reserve cannot pay.
bool rebody(accounting::Inventory& body, accounting::Inventory& reserve,
accounting::Inventory& heat, const accounting::Inventory& target, std::uint64_t price) {
auto next_reserve = reserve;
std::uint64_t added{};
for (std::size_t c = 0; c < body.matter.size(); ++c) {
const auto have = body.matter[c].value, want = target.matter[c].value;
if (want > have) {
if (next_reserve.matter[c].value < want - have)
return false;
next_reserve.matter[c].value -= want - have;
added += want - have;
} else {
next_reserve.matter[c].value += have - want;
}
}
const auto energy = added / 1'000 * price + added % 1'000 * price / 1'000;
if (next_reserve.energy.value < energy)
return false;
next_reserve.energy.value -= energy;
reserve = next_reserve;
heat.energy.value += energy;
body = target;
body.energy = {};
return true;
}
std::expected<biology::MetabolicBudget, CellularLivesError>
budget_for(const biology::LineageArchive& archive, const CellularOwnedLife& life,
std::uint32_t temperature,
const biology::BodyTuning& body = biology::default_body_tuning) {
const auto genome = archive.find(life.identity.genome);
const auto genome = life_genome(archive, life);
if (!genome)
return std::unexpected{CellularLivesError::archive};
return std::unexpected{genome.error()};
const auto budget =
biology::metabolic_budget(*genome, life.growth, {temperature, {}}, 1000, body);
if (!budget)
@@ -950,6 +1023,14 @@ CellularLives::create(const PrimitiveLives& opening,
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
}
bool cellular_can_emerge(const CellularOwnedLife& life, const CellularRevampRules& rules) noexcept {
std::uint64_t mass{};
for (std::size_t c = 0; c < life.body.matter.size(); ++c)
mass += life.body.matter[c].value + life.reserve.matter[c].value;
return life.account != LifeAccount{} && life.revamp.members >= rules.emerge_members &&
mass >= rules.emerge_mass_fg && life.reserve.energy.value >= rules.emerge_reserve_pj;
}
bool cellular_twin_bud(std::uint64_t world, std::uint64_t region, std::uint64_t parent_life,
std::uint64_t tick, std::uint32_t reproduction) noexcept {
// Its own stream: the parent and tick hashed with a twin-only salt ("twin").
@@ -2065,8 +2146,12 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
corpse.predator_life = in.get();
corpse.cause = static_cast<biology::CellularDeathCause>(cause);
const bool engulfed = corpse.cause == biology::CellularDeathCause::engulfed;
const bool revamp_cause =
revamp_version && (corpse.cause == biology::CellularDeathCause::merged ||
corpse.cause == biology::CellularDeathCause::emerged);
if (padding != 0 ||
(corpse.cause != biology::CellularDeathCause::starved && !engulfed) ||
(corpse.cause != biology::CellularDeathCause::starved && !engulfed &&
!revamp_cause) ||
engulfed != (corpse.predator_life != 0) || corpse.predator_life == corpse.life_id ||
corpse.inventory != accounting::Inventory{})
return std::unexpected{CellularLivesError::noncanonical};
@@ -2215,7 +2300,11 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
if (intent.brake && !liquid_rules)
return std::unexpected{CellularLivesError::invalid_intents};
if (intent.become &&
(!revamp_rules || !intent.bud || state_->lives[i].account == LifeAccount{}))
(!revamp_rules || !intent.bud || state_->lives[i].account == LifeAccount{} ||
state_->lives[i].revamp.members > 1))
return std::unexpected{CellularLivesError::invalid_intents};
if (intent.emerge && (!revamp_rules || state_->lives[i].account == LifeAccount{} ||
intent.frozen || intent.bud || intent.engulf || intent.intake_target))
return std::unexpected{CellularLivesError::invalid_intents};
// Rules 13: exclusions are an owned life's setting, never wildlife's or a frozen cell's.
if (intent.exclude != 0 && (!revamp_rules || intent.exclude > 0x0F || intent.frozen ||
@@ -2310,8 +2399,11 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
std::uint64_t carried{};
for (const auto& channel : life.reserve.matter)
carried += channel.value;
const auto members = std::uint64_t{life.revamp.members};
const auto extra = budget->phenotype.total_mass / members * (members - 1) / 1'000 *
state_->revamp.organism_load_per_thousand;
*handling = cellular_loaded_handling(*handling, budget->phenotype.total_mass,
carried, state_->revamp);
carried, state_->revamp, extra);
}
inputs.back().liquid = biology::CellularLiquidInput{
life.motion, *handling,
@@ -2505,8 +2597,10 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
if (found == next_lives.end() || found->identity.life != dead.life_id ||
!next_archive.record_death(found->identity.organism, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive};
auto single = *found;
single.revamp.members = 1; // A corpse records the single-cell extent.
const auto corpse_budget =
budget_for(next_archive, *found, state_->config.ambient_temperature_millikelvin,
budget_for(next_archive, single, state_->config.ambient_temperature_millikelvin,
state_->revamp.body);
if (!corpse_budget)
return std::unexpected{corpse_budget.error()};
@@ -2585,6 +2679,129 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
const auto successor = biology::Genome::create(*draft);
if (!successor)
return std::unexpected{CellularLivesError::mutation};
const auto price = [&]() -> std::uint64_t {
const auto rules = biology::rules_for(successor->development_version());
return rules ? rules->construction_per_kilogram : 0;
}();
if (found->revamp.members > 1) {
// A multicellular organism expresses the mutation as a whole (ADR-0179), its
// changed tissue funded from the shared reserve; "not now" when it cannot be.
const auto scaled = organism_genome(*successor, found->revamp.members);
const auto target = scaled
? biology::metabolic_budget(
*scaled, found->growth,
{state_->config.ambient_temperature_millikelvin, {}},
1000, state_->revamp.body)
: std::unexpected{biology::DevelopmentError::overflow};
auto body = found->body;
auto heat = accounting::Inventory{};
if (!target)
return std::unexpected{CellularLivesError::biology};
if (!rebody(body, reserve, heat, target->body, price)) {
// The offer stays, as for any unaffordable cost.
mutation_results.push_back({selection.life_id, selection.successor_id,
CellularMutationResult::insufficient_funding});
continue;
}
if (!next_archive.record_mutation(found->identity.organism, *successor,
{proposal->end_tick}) ||
!add_inventory(next_heat, heat) || !add_inventory(next_spent, payment->spent))
return std::unexpected{CellularLivesError::archive};
auto returned = cost;
returned.energy.value = payment->energy;
reclaims.emplace_back(returned, found->position);
found->identity.genome = successor->id();
found->offspring_genome = successor->id();
found->body = body;
found->reserve = reserve;
pending = {};
mutation_results.push_back(
{selection.life_id, selection.successor_id, CellularMutationResult::applied});
continue;
}
if (spec->effect == biology::CellularEffect::acquire_adhesion) {
// Adhesion: the split's offspring attaches at once, so the cell becomes a
// two-member organism holding its whole body and reserve under the new plan. The
// single cell's life ends as merged; the player continues as the organism.
const auto temperature = state_->config.ambient_temperature_millikelvin;
const auto organism = organism_genome(*successor, 2);
if (!organism)
return std::unexpected{organism.error()};
const auto fit = biology::largest_growth_within(*organism, found->body, temperature,
state_->revamp.body);
if (!fit)
return std::unexpected{CellularLivesError::biology};
const auto identity = cellular_bud_identity(state_->region, next_bud_sequence);
const auto& formed = *fit;
if (!formed || identity == 0 || next_archive.organism(identity)) {
mutation_results.push_back({selection.life_id, selection.successor_id,
CellularMutationResult::split_refused});
continue;
}
const auto grown = biology::metabolic_budget(
*organism, formed->first, {temperature, {}}, 1000, state_->revamp.body);
if (!grown)
return std::unexpected{CellularLivesError::biology};
const auto single_budget =
budget_for(next_archive, *found, temperature, state_->revamp.body);
if (!single_budget)
return std::unexpected{single_budget.error()};
if (!next_archive.admit(*successor) ||
!next_archive.record_birth(identity, successor->id(), {proposal->end_tick}) ||
!next_archive.record_death(found->identity.organism, {proposal->end_tick}))
return std::unexpected{CellularLivesError::archive};
if (!add_inventory(next_spent, payment->spent))
return std::unexpected{CellularLivesError::overflow};
auto returned = cost;
returned.energy.value = payment->energy;
reclaims.emplace_back(returned, found->position);
CellularOwnedLife whole{};
whole.account = found->account;
whole.identity = {
identity, identity, successor->id(), identity, {proposal->end_tick}};
whole.source = found->source;
whole.growth = formed->first;
whole.body = formed->second;
whole.reserve = reserve;
for (std::size_t c = 0; c < whole.body.matter.size(); ++c)
whole.reserve.matter[c].value +=
found->body.matter[c].value - formed->second.matter[c].value;
// Keep the larger body inside the region.
const auto extent = grown->phenotype.extent;
whole.position = found->position;
whole.position.x_um = std::min<std::uint64_t>(
whole.position.x_um, state_->config.area.width_um - extent);
whole.position.y_um = std::min<std::uint64_t>(
whole.position.y_um, state_->config.area.height_um - extent);
whole.motion = found->motion;
whole.parent_life = found->identity.life;
whole.offspring_genome = successor->id();
whole.revamp.affinity.score = found->revamp.affinity.score;
whole.revamp.progress = found->revamp.progress;
whole.revamp.members = 2;
next_corpses.push_back({found->identity.life,
found->identity.organism,
found->source,
proposal->end_tick,
found->position,
found->growth,
single_budget->phenotype.extent,
{},
biology::CellularDeathCause::merged,
0,
found->parent_life,
found->offspring_genome});
next_lives.erase(found);
++next_bud_sequence;
next_lives.insert(std::ranges::lower_bound(next_lives, identity, {},
[](const CellularOwnedLife& life) {
return life.identity.life;
}),
whole);
mutation_results.push_back({selection.life_id, selection.successor_id,
CellularMutationResult::split_applied});
continue;
}
// The split (Cellular_reproduction_plan.md section 4): body and reserve divide, the
// offspring expresses the mutation, both plans carry it. Refused, spending nothing,
// when the cell is too small, has no room beside it, or the region is full.
@@ -2736,6 +2953,68 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
bud_results.push_back({request.life_id, 0, CellularBudResult::not_able});
continue; // Out of the world (ADR-0128).
}
if (revamp_rules && parent->revamp.members > 1) {
// An organism's bud is an internal cell (reproduction plan section 6): litter adds
// members, funded from the shared reserve. Wildlife organisms stop one short of
// the emergence threshold.
const auto expressed_genome = next_archive.find(parent->identity.genome);
if (!expressed_genome)
return std::unexpected{CellularLivesError::archive};
const auto& traits = expressed_genome->cellular_traits();
Random roll{state_->world * 0x9e3779b97f4a7c15ULL ^ request.life_id ^
proposal->end_tick * 0xbf58476d1ce4e5b9ULL};
const auto added = cellular_litter_count(traits ? traits->litter : 0U, roll.next(),
state_->revamp.bounds.max_litter);
auto members = std::uint32_t{parent->revamp.members} + added;
if (parent->account == LifeAccount{})
members = std::min(members, state_->revamp.emerge_members - 1);
const auto grown = members > parent->revamp.members
? organism_genome(*expressed_genome, members)
: std::unexpected{CellularLivesError::biology};
const auto target = grown ? biology::metabolic_budget(
*grown, parent->growth,
{state_->config.ambient_temperature_millikelvin, {}},
1000, state_->revamp.body)
: std::unexpected{biology::DevelopmentError::overflow};
const auto rules = biology::rules_for(expressed_genome->development_version());
// The same fee per bud action as a single cell's, then the new tissue.
const auto fee = cellular_mutation_cost(
{.cost = state_->revamp.bud_fee,
.cost_scale_percent = state_->revamp.bud_fee_scale_percent});
auto body = parent->body;
auto reserve = parent->reserve;
bool funded = reserve.energy.value >= fee.energy.value;
for (std::size_t c = 0; c < fee.matter.size(); ++c)
funded = funded && reserve.matter[c].value >= fee.matter[c].value;
if (funded) {
reserve.energy.value -= fee.energy.value;
for (std::size_t c = 0; c < fee.matter.size(); ++c)
reserve.matter[c].value -= fee.matter[c].value;
}
auto heat = accounting::Inventory{};
if (!target || !rules || !funded ||
!rebody(body, reserve, heat, target->body, rules->construction_per_kilogram)) {
bud_results.push_back({request.life_id, 0,
target ? CellularBudResult::insufficient_funding
: CellularBudResult::not_able});
if (target && parent->account != LifeAccount{})
activity_of(request.life_id)[biology::CellularSignal::bud_refused] += 1;
continue;
}
if (!add_inventory(next_heat, heat))
return std::unexpected{CellularLivesError::overflow};
reclaims.emplace_back(fee, parent->position);
parent->body = body;
parent->reserve = reserve;
parent->revamp.members = static_cast<std::uint16_t>(members);
if (parent->account != LifeAccount{}) {
activity_of(request.life_id)[biology::CellularSignal::bud_done] += 1;
parent->revamp.progress.buds += 1;
}
// The bud is internal: the organism reports itself as the bud.
bud_results.push_back({request.life_id, request.life_id, CellularBudResult::budded});
continue;
}
// ADR-0137 (rules 7): on a twin roll the bud investment is split between two buds
// (each a quarter of the parent's body). The parent's reported result is the
// first bud's; a twin that finds no room is simply not made.
@@ -2900,6 +3179,44 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
}
std::ranges::sort(next_lives, {},
[](const CellularOwnedLife& life) { return life.identity.life; });
// Rules 13 (reproduction plan section 7): an owned organism at the emergence threshold that
// asks leaves for the world. Its matter is a recorded export; its life ends as emerged.
auto next_boundary = state_->boundary;
if (revamp_rules) {
for (const auto& request : ordered) {
if (!request.intent.emerge)
continue;
const auto life = std::ranges::lower_bound(
next_lives, request.life_id, {},
[](const CellularOwnedLife& value) { return value.identity.life; });
if (life == next_lives.end() || life->identity.life != request.life_id ||
!cellular_can_emerge(*life, state_->revamp))
continue;
auto single = *life;
single.revamp.members = 1;
const auto budget =
budget_for(next_archive, single, state_->config.ambient_temperature_millikelvin,
state_->revamp.body);
if (!budget ||
!next_archive.record_death(life->identity.organism, {proposal->end_tick}) ||
!add_inventory(next_boundary.outgoing, life->body) ||
!add_inventory(next_boundary.outgoing, life->reserve))
return std::unexpected{CellularLivesError::archive};
next_corpses.push_back({life->identity.life,
life->identity.organism,
life->source,
proposal->end_tick,
life->position,
life->growth,
budget->phenotype.extent,
{},
biology::CellularDeathCause::emerged,
0,
life->parent_life,
life->offspring_genome});
next_lives.erase(life);
}
}
// Rules 5 presence (ADR-0128), after deaths, mutations and buds: a death in this tick
// is final before any presence change.
std::vector<std::uint64_t> resume_blocked;
@@ -2956,9 +3273,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
previous->presence == CellularPresence::suspended ||
life.growth.realized_per_thousand == 1000)
continue;
const auto genome = next_archive.find(life.identity.genome);
const auto genome = life_genome(next_archive, life);
if (!genome)
return std::unexpected(CellularLivesError::archive);
return std::unexpected(genome.error());
// Rules 13: growth speed scales the per-tick step; the fraction carries over.
auto step = cellular_growth_per_tick;
const auto& traits = genome->cellular_traits();
@@ -3153,7 +3470,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
state_->nursery_config, **next_habitat, next_lives, next_corpses, next_archive,
state_->nursery, next_heat, state_->opening_total, engulf_rules, bud_rules,
next_bud_sequence, presence_rules,
state_->format_version >= cellular_lives_migration_format ? &state_->boundary : nullptr,
state_->format_version >= cellular_lives_migration_format ? &next_boundary : nullptr,
inheritance_rules ? &next_offspring_revisions : nullptr, next_spent, revamp_rules);
if (!total)
return std::unexpected{total.error()};
@@ -3164,7 +3481,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
state_->config.ambient_temperature_millikelvin},
state_->nursery_config, std::move(*next_habitat), std::move(next_lives),
std::move(next_corpses), next_archive, state_->nursery, next_heat, state_->opening_total,
*total, state_->format_version, state_->rules_version, state_->boundary);
*total, state_->format_version, state_->rules_version, next_boundary);
next->next_bud_sequence = next_bud_sequence;
next->offspring_revisions = std::move(next_offspring_revisions);
next->light = state_->light;
@@ -41,6 +41,12 @@ summarize_cellular_play(const CellularLives& state) {
case biology::CellularDeathCause::unrecorded:
++summary.unrecorded;
break;
case biology::CellularDeathCause::merged:
++summary.merged;
break;
case biology::CellularDeathCause::emerged:
++summary.emerged;
break;
}
(corpse.parent_life == 0 ? summary.owned_deaths : summary.wildlife_deaths) += 1;
const auto record = archive.organism(corpse.organism);
+11 -4
View File
@@ -55,15 +55,18 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
rules.bud_fee.matter,
[](const accounting::Femtograms& f) { return f.value <= most; }) &&
rules.organism_cap != 0 && rules.organism_cap <= biology::max_cellular_tick_lives &&
cellular_revamp_offer_rules_valid(rules);
rules.organism_load_per_thousand <= 10'000 && rules.emerge_members >= 2 &&
rules.emerge_members <= 10'000 && rules.emerge_mass_fg <= most &&
rules.emerge_reserve_pj <= most && cellular_revamp_offer_rules_valid(rules);
}
biology::CellularHandling cellular_loaded_handling(const biology::CellularHandling& handling,
std::uint64_t body_mass, std::uint64_t carried,
const CellularRevampRules& rules) noexcept {
const CellularRevampRules& rules,
std::uint64_t extra_load) noexcept {
// Masses stay far below 2^40 fg, so these products fit in 64 bits.
const auto load = carried / 1'000 * rules.reserve_load_per_thousand +
carried % 1'000 * rules.reserve_load_per_thousand / 1'000;
carried % 1'000 * rules.reserve_load_per_thousand / 1'000 + extra_load;
if (load == 0 || body_mass == 0 || body_mass > (1ULL << 40U) || load > (1ULL << 40U))
return handling;
const auto total = body_mass + load;
@@ -275,6 +278,10 @@ CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t
accounting::Femtograms{u64(t.reproduction_bud_fee_p_fg)},
accounting::Femtograms{u64(t.reproduction_bud_fee_o_fg)}}},
.bud_fee_scale_percent = u32(t.reproduction_bud_fee_scale_percent),
.organism_cap = u32(t.reproduction_organism_cap)};
.organism_cap = u32(t.reproduction_organism_cap),
.organism_load_per_thousand = u32(t.organism_load_per_mille),
.emerge_members = u32(t.organism_emerge_members),
.emerge_mass_fg = u64(t.organism_emerge_mass_fg),
.emerge_reserve_pj = u64(t.organism_emerge_reserve_pj)};
}
} // namespace evo::server