feat(lifecycle): rules 13 mutation splits, stay-or-become and litter
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
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
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>
This commit is contained in:
@@ -62,9 +62,11 @@ constexpr std::size_t cellular_life_motion_bytes = 20;
|
||||
// reserved zero, 32), the catalog bounds (five 4-byte fields, a reserved zero and the carbon
|
||||
// gate, 32), the offer interval and a reserved zero (8), and 49 mutation tunables of 80 bytes.
|
||||
constexpr std::size_t cellular_revamp_mutation_bytes = 80;
|
||||
// Then the reproduction tunables: split share, split growth, organism cap, fee scale (16) and
|
||||
// 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;
|
||||
biology::cellular_catalog_size * cellular_revamp_mutation_bytes + 56;
|
||||
// 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).
|
||||
@@ -243,6 +245,10 @@ void write_revamp_offers(Writer& out, const CellularRevampRules& r) {
|
||||
out.put(value, 4);
|
||||
out.inventory(m.cost);
|
||||
}
|
||||
for (const auto value :
|
||||
{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);
|
||||
}
|
||||
bool read_revamp_offers(Reader& in, CellularRevampRules& r) {
|
||||
const auto u32 = [&in] { return static_cast<std::uint32_t>(in.get(4)); };
|
||||
@@ -286,6 +292,11 @@ bool read_revamp_offers(Reader& in, CellularRevampRules& r) {
|
||||
m.cost_scale_percent = u32();
|
||||
m.cost = in.inventory();
|
||||
}
|
||||
r.split_share_per_thousand = u32();
|
||||
r.split_min_growth = u32();
|
||||
r.organism_cap = u32();
|
||||
r.bud_fee_scale_percent = u32();
|
||||
r.bud_fee = in.inventory();
|
||||
return zero;
|
||||
}
|
||||
void write_revamp_life(Writer& out, const CellularRevampLife& life) {
|
||||
@@ -505,7 +516,8 @@ sum_state(accounting::Inventory nursery, accounting::Inventory heat,
|
||||
bool validate_plans(std::span<const CellularOwnedLife> lives,
|
||||
std::span<const CellularOwnedCorpse> corpses,
|
||||
const biology::LineageArchive& archive,
|
||||
std::span<const CellularOffspringRevision> history, std::uint64_t tick) {
|
||||
std::span<const CellularOffspringRevision> history, std::uint64_t tick,
|
||||
bool transfers = false) {
|
||||
if (history.size() > biology::max_archived_genomes)
|
||||
return false;
|
||||
struct Plan {
|
||||
@@ -528,7 +540,7 @@ bool validate_plans(std::span<const CellularOwnedLife> lives,
|
||||
plans.push_back(
|
||||
{life.identity.life, life.identity.genome, life.identity.genome, life.offspring_genome,
|
||||
std::max(life.identity.born.value, last_expression[life.identity.organism]), 0,
|
||||
life.account != LifeAccount{}});
|
||||
transfers || life.account != LifeAccount{}});
|
||||
observe(life.identity.genome, life.identity.born.value);
|
||||
}
|
||||
for (const auto& corpse : corpses) {
|
||||
@@ -538,7 +550,7 @@ bool validate_plans(std::span<const CellularOwnedLife> lives,
|
||||
return false;
|
||||
plans.push_back({corpse.life_id, *expressed, *expressed, corpse.offspring_genome,
|
||||
std::max(record->born.value, last_expression[corpse.organism]),
|
||||
corpse.died_tick, corpse.parent_life == 0});
|
||||
corpse.died_tick, transfers || corpse.parent_life == 0});
|
||||
observe(record->genome, record->born.value);
|
||||
observe(*expressed, record->born.value);
|
||||
}
|
||||
@@ -590,7 +602,7 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
bool bud_rules = false, std::uint64_t next_bud_sequence = 1,
|
||||
bool presence_rules = false, const CellularBoundaryLedger* boundary = nullptr,
|
||||
const std::vector<CellularOffspringRevision>* plans = nullptr,
|
||||
const accounting::Inventory& spent = {}) {
|
||||
const accounting::Inventory& spent = {}, bool transfers = false) {
|
||||
// A bud's identity lies in this region's namespace below the next sequence; anything
|
||||
// else is an allocated identity, below the namespace (ADR-0125).
|
||||
const auto bud_identity = [&](std::uint64_t identity) noexcept {
|
||||
@@ -658,30 +670,34 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
const auto& life = lives[i];
|
||||
if (!plans && life.offspring_genome != 0)
|
||||
return std::unexpected{CellularLivesError::version};
|
||||
// Founders are owned; buds are unowned wildlife (rules 4) and never earn offers.
|
||||
// Founders are owned; buds are unowned wildlife (rules 4) and never earn offers. Rules 13
|
||||
// (ADR-0163 succession) moves control between parent and offspring, so ownership is the
|
||||
// account's alone; bud identities still follow parentage.
|
||||
const bool wildlife = life.parent_life != 0;
|
||||
const bool owned = transfers ? life.account != LifeAccount{} : !wildlife;
|
||||
// ADR-0128: only owned lives leave; a lingering life is within its linger time.
|
||||
const bool presence_valid =
|
||||
life.presence == CellularPresence::active
|
||||
? life.frozen_since == 0
|
||||
: presence_rules && !wildlife && life.frozen_since != 0 &&
|
||||
: presence_rules && owned && life.frozen_since != 0 &&
|
||||
life.frozen_since <= config.tick &&
|
||||
(life.presence == CellularPresence::suspended ||
|
||||
(life.presence == CellularPresence::lingering &&
|
||||
config.tick - life.frozen_since < cellular_linger_ticks));
|
||||
if (!presence_valid)
|
||||
return std::unexpected{CellularLivesError::invalid_life};
|
||||
if ((life.account == LifeAccount{}) != wildlife || life.identity.life == 0 ||
|
||||
life.identity.organism == 0 || life.identity.genome == 0 || life.identity.event == 0 ||
|
||||
life.identity.born.value == 0 || life.identity.born.value > config.tick ||
|
||||
life.source == 0 || (i != 0 && lives[i - 1].identity.life >= life.identity.life) ||
|
||||
if ((!transfers && (life.account == LifeAccount{}) != wildlife) ||
|
||||
life.identity.life == 0 || life.identity.organism == 0 || life.identity.genome == 0 ||
|
||||
life.identity.event == 0 || life.identity.born.value == 0 ||
|
||||
life.identity.born.value > config.tick || life.source == 0 ||
|
||||
(i != 0 && lives[i - 1].identity.life >= life.identity.life) ||
|
||||
!lineage_valid(life.identity.life, life.parent_life) ||
|
||||
(wildlife && (life.identity.organism != life.identity.life ||
|
||||
life.identity.event != life.identity.life ||
|
||||
life.mutation != CellularMutationProgress{})))
|
||||
return std::unexpected{CellularLivesError::invalid_life};
|
||||
for (std::size_t j = 0; j < i; ++j)
|
||||
if ((!wildlife && lives[j].account == life.account) ||
|
||||
if ((owned && lives[j].account == life.account) ||
|
||||
lives[j].identity.organism == life.identity.organism)
|
||||
return std::unexpected{CellularLivesError::duplicate_life};
|
||||
const auto record = archive.organism(life.identity.organism);
|
||||
@@ -761,7 +777,7 @@ validate_state(std::uint64_t world, std::uint64_t region, std::uint64_t frame,
|
||||
if (std::ranges::adjacent_find(life_ids) != life_ids.end())
|
||||
return std::unexpected{CellularLivesError::duplicate_life};
|
||||
|
||||
if (plans && !validate_plans(lives, corpses, archive, *plans, config.tick))
|
||||
if (plans && !validate_plans(lives, corpses, archive, *plans, config.tick, transfers))
|
||||
return std::unexpected{CellularLivesError::invalid_life};
|
||||
auto current = sum_state(nursery, heat, habitat, lives, corpses);
|
||||
if (!current)
|
||||
@@ -1011,11 +1027,11 @@ CellularLives::migration_replacement(std::vector<CellularOwnedLife> living,
|
||||
state_->region, state_->frame);
|
||||
if (!habitat)
|
||||
return std::unexpected(CellularLivesError::habitat);
|
||||
const auto total =
|
||||
validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, **habitat, living, state_->corpses, archive,
|
||||
state_->nursery, state_->heat, state_->opening_total, true, true,
|
||||
state_->next_bud_sequence, true, &boundary, nullptr, state_->spent);
|
||||
const auto total = validate_state(
|
||||
state_->world, state_->region, state_->frame, state_->config, state_->nursery_config,
|
||||
**habitat, living, state_->corpses, archive, state_->nursery, state_->heat,
|
||||
state_->opening_total, true, true, state_->next_bud_sequence, true, &boundary, nullptr,
|
||||
state_->spent, state_->rules_version >= cellular_lives_revamp_rules);
|
||||
if (!total)
|
||||
return std::unexpected(total.error());
|
||||
auto replacement = std::unique_ptr<CellularLives>{new CellularLives{std::make_unique<State>(
|
||||
@@ -1077,13 +1093,14 @@ CellularLives::exchange_boundary(std::span<const biology::CellularPatch> deposit
|
||||
habitat = std::move(*created);
|
||||
}
|
||||
const auto rules = state_->rules_version;
|
||||
const auto total = validate_state(
|
||||
state_->world, state_->region, state_->frame, state_->config, state_->nursery_config,
|
||||
*habitat, state_->lives, state_->corpses, state_->archive, state_->nursery, heat,
|
||||
state_->opening_total, rules >= cellular_lives_engulf_rules,
|
||||
rules >= cellular_lives_bud_rules, state_->next_bud_sequence,
|
||||
rules >= cellular_lives_presence_rules, &boundary,
|
||||
cellular_retained_plans(rules) ? &state_->offspring_revisions : nullptr, state_->spent);
|
||||
const auto total =
|
||||
validate_state(state_->world, state_->region, state_->frame, state_->config,
|
||||
state_->nursery_config, *habitat, state_->lives, state_->corpses,
|
||||
state_->archive, state_->nursery, heat, state_->opening_total,
|
||||
rules >= cellular_lives_engulf_rules, rules >= cellular_lives_bud_rules,
|
||||
state_->next_bud_sequence, rules >= cellular_lives_presence_rules, &boundary,
|
||||
cellular_retained_plans(rules) ? &state_->offspring_revisions : nullptr,
|
||||
state_->spent, state_->rules_version >= cellular_lives_revamp_rules);
|
||||
if (!total)
|
||||
return std::unexpected(total.error());
|
||||
BoundarySavepoint savepoint{std::move(state_->habitat), state_->heat, state_->current_total,
|
||||
@@ -1687,7 +1704,7 @@ CellularLives::birth_candidate(LifeRequest request, LifeAllocation allocation) c
|
||||
state_->format_version >= cellular_lives_migration_format ? &state_->boundary : nullptr,
|
||||
state_->format_version >= cellular_lives_inheritance_format ? &state_->offspring_revisions
|
||||
: nullptr,
|
||||
state_->spent);
|
||||
state_->spent, state_->rules_version >= cellular_lives_revamp_rules);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
|
||||
@@ -2128,7 +2145,7 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
|
||||
saved_world, saved_region, saved_frame, config, nursery_config, **habitat, lives, corpses,
|
||||
*archive, nursery, heat, opening_total, engulf_version, bud_version, next_bud_sequence,
|
||||
presence_version, migration_version ? &boundary : nullptr,
|
||||
inheritance_version ? &plan_history : nullptr, spent);
|
||||
inheritance_version ? &plan_history : nullptr, spent, revamp_version);
|
||||
if (!current)
|
||||
return std::unexpected{current.error()};
|
||||
|
||||
@@ -2197,6 +2214,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
if (intent.brake && !liquid_rules)
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
if (intent.become &&
|
||||
(!revamp_rules || !intent.bud || state_->lives[i].account == LifeAccount{}))
|
||||
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 ||
|
||||
state_->lives[i].account == LifeAccount{}))
|
||||
@@ -2205,7 +2225,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
for (std::size_t i = 0; i < selections.size(); ++i) {
|
||||
const auto& selection = selections[i];
|
||||
if (selection.life_id == 0 || selection.event_index == 0 || selection.offer_tick == 0 ||
|
||||
selection.successor_id == 0 || // Operator 0 declines (ADR-0120 amendment).
|
||||
selection.successor_id == 0 || // Operator 0 declines (ADR-0120 amendment).
|
||||
(selection.become && !revamp_rules) || // Rules 13 only (ADR-0179).
|
||||
(i != 0 && selections[i - 1].life_id >= selection.life_id))
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
const auto life = std::ranges::lower_bound(
|
||||
@@ -2501,6 +2522,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
next_lives.erase(found);
|
||||
}
|
||||
std::vector<CellularMutationExecution> mutation_results;
|
||||
// Bud identities: rules-13 splits draw from the same sequence as buds.
|
||||
auto next_bud_sequence = state_->next_bud_sequence;
|
||||
mutation_results.reserve(selections.size());
|
||||
for (const auto& selection : selections) {
|
||||
const auto found = std::ranges::lower_bound(
|
||||
@@ -2560,21 +2583,81 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
continue;
|
||||
}
|
||||
const auto successor = biology::Genome::create(*draft);
|
||||
if (!successor || next_offspring_revisions.size() >= biology::max_archived_genomes ||
|
||||
!next_archive.admit(*successor))
|
||||
if (!successor)
|
||||
return std::unexpected{CellularLivesError::mutation};
|
||||
// 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.
|
||||
const auto temperature = state_->config.ambient_temperature_millikelvin;
|
||||
const auto split =
|
||||
biology::split_cell(*expressed, *successor, found->growth, found->body, reserve,
|
||||
temperature, state_->revamp.split_share_per_thousand,
|
||||
state_->revamp.split_min_growth, state_->revamp.body);
|
||||
if (!split && split.error() == biology::BuddingError::development)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto identity = cellular_bud_identity(state_->region, next_bud_sequence);
|
||||
std::optional<biology::CellularPosition> spot;
|
||||
if (split) {
|
||||
const auto shrunk = biology::metabolic_budget(
|
||||
*expressed, split->parent_growth, {temperature, {}}, 1000, state_->revamp.body);
|
||||
const auto born = biology::metabolic_budget(
|
||||
*successor, split->child_growth, {temperature, {}}, 1000, state_->revamp.body);
|
||||
if (!shrunk || !born)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto position =
|
||||
bud_position(*found, shrunk->phenotype.extent, born->phenotype.extent,
|
||||
next_lives, next_archive, state_->config);
|
||||
if (!position)
|
||||
return std::unexpected{position.error()};
|
||||
spot = *position;
|
||||
}
|
||||
if (!split || !spot || identity == 0 ||
|
||||
next_lives.size() >= state_->revamp.organism_cap ||
|
||||
next_archive.organism(identity)) {
|
||||
mutation_results.push_back({selection.life_id, selection.successor_id,
|
||||
CellularMutationResult::split_refused});
|
||||
continue;
|
||||
}
|
||||
if (next_offspring_revisions.size() >= biology::max_archived_genomes ||
|
||||
!next_archive.admit(*successor) ||
|
||||
!next_archive.record_birth(identity, successor->id(), {proposal->end_tick}))
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
next_offspring_revisions.push_back({selection.life_id, found->offspring_genome,
|
||||
selection.successor_id, proposal->end_tick});
|
||||
found->offspring_genome = selection.successor_id;
|
||||
found->reserve = reserve;
|
||||
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 child{};
|
||||
child.identity = {identity, identity, successor->id(), identity, {proposal->end_tick}};
|
||||
child.source = found->source;
|
||||
child.growth = split->child_growth;
|
||||
child.position = *spot;
|
||||
child.body = split->child_body;
|
||||
child.reserve = split->child_reserve;
|
||||
child.parent_life = found->identity.life;
|
||||
child.offspring_genome = successor->id();
|
||||
child.revamp.affinity.score = found->revamp.affinity.score;
|
||||
child.revamp.progress = found->revamp.progress;
|
||||
found->growth = split->parent_growth;
|
||||
found->body = split->parent_body;
|
||||
found->reserve = split->parent_reserve;
|
||||
found->offspring_genome = successor->id();
|
||||
pending = {};
|
||||
mutation_results.push_back({selection.life_id, selection.successor_id,
|
||||
CellularMutationResult::offspring_plan_applied});
|
||||
if (selection.become) {
|
||||
// One-way: the player continues as the offspring; the founder is wildlife.
|
||||
child.account = found->account;
|
||||
found->account = {};
|
||||
found->revamp.active_ticks = 0;
|
||||
}
|
||||
++next_bud_sequence;
|
||||
next_lives.insert(std::ranges::lower_bound(
|
||||
next_lives, identity, {},
|
||||
[](const CellularOwnedLife& life) { return life.identity.life; }),
|
||||
child);
|
||||
mutation_results.push_back(
|
||||
{selection.life_id, selection.successor_id, CellularMutationResult::split_applied});
|
||||
continue;
|
||||
}
|
||||
const auto parent = next_archive.find(cellular_offspring_genome(*found));
|
||||
@@ -2639,7 +2722,6 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
// Rules 4 budding (ADR-0125), after mutations and in parent life order: a parent that
|
||||
// died this tick cannot bud, and a bud born this tick asked for nothing.
|
||||
std::vector<CellularBudExecution> bud_results;
|
||||
auto next_bud_sequence = state_->next_bud_sequence;
|
||||
for (const auto& request : ordered) {
|
||||
if (!bud_rules || !request.intent.bud)
|
||||
continue;
|
||||
@@ -2657,8 +2739,35 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
// 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.
|
||||
// Rules 13 (mutation plan section 9): litter gives extra offspring sharing one investment,
|
||||
// whole hundreds guaranteed and the rest a chance, up to the declared maximum.
|
||||
std::uint32_t litter_count = 1;
|
||||
accounting::Inventory fee{};
|
||||
if (revamp_rules) {
|
||||
const auto expressed_genome = next_archive.find(parent->identity.genome);
|
||||
const auto& traits =
|
||||
expressed_genome ? expressed_genome->cellular_traits() : std::nullopt;
|
||||
const auto litter = traits ? std::uint32_t{traits->litter} : 0U;
|
||||
Random roll{state_->world * 0x9e3779b97f4a7c15ULL ^ request.life_id ^
|
||||
proposal->end_tick * 0xbf58476d1ce4e5b9ULL};
|
||||
litter_count =
|
||||
cellular_litter_count(litter, roll.next(), state_->revamp.bounds.max_litter);
|
||||
fee = cellular_mutation_cost(
|
||||
{.cost = state_->revamp.bud_fee,
|
||||
.cost_scale_percent = state_->revamp.bud_fee_scale_percent});
|
||||
bool affordable = parent->reserve.energy.value >= fee.energy.value;
|
||||
for (std::size_t c = 0; c < fee.matter.size(); ++c)
|
||||
affordable = affordable && parent->reserve.matter[c].value >= fee.matter[c].value;
|
||||
if (!affordable) {
|
||||
bud_results.push_back(
|
||||
{request.life_id, 0, CellularBudResult::insufficient_funding});
|
||||
if (parent->account != LifeAccount{})
|
||||
activity_of(request.life_id)[biology::CellularSignal::bud_refused] += 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const bool twins = [&] {
|
||||
if (state_->rules_version < cellular_lives_reproduction_rules)
|
||||
if (state_->rules_version < cellular_lives_reproduction_rules || revamp_rules)
|
||||
return false;
|
||||
const auto parent_genome = next_archive.find(parent->identity.genome);
|
||||
const auto offspring_genome = next_archive.find(cellular_offspring_genome(*parent));
|
||||
@@ -2674,7 +2783,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
state_->config.ambient_temperature_millikelvin)
|
||||
.has_value();
|
||||
}();
|
||||
for (int copy = 0; copy < (twins ? 2 : 1); ++copy) {
|
||||
const auto copies = revamp_rules ? litter_count : (twins ? 2U : 1U);
|
||||
for (std::uint32_t copy = 0; copy < copies; ++copy) {
|
||||
if (copy == 1)
|
||||
// Inserting the first bud may have moved the parent; find it again.
|
||||
parent = std::ranges::lower_bound(
|
||||
@@ -2697,8 +2807,8 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
for (std::size_t c = 0; surplus && c < cost->matter.size(); ++c)
|
||||
surplus = parent->reserve.matter[c].value / 2 >= cost->matter[c].value;
|
||||
}
|
||||
const auto transition = biology::fund_offspring(
|
||||
*expressed, *genome, parent->growth, parent->reserve, temperature, twins ? 2U : 1U);
|
||||
const auto transition = biology::fund_offspring(*expressed, *genome, parent->growth,
|
||||
parent->reserve, temperature, copies);
|
||||
if (revamp_rules && !twin && parent->account != LifeAccount{}) {
|
||||
using S = biology::CellularSignal;
|
||||
auto& a = activity_of(request.life_id);
|
||||
@@ -2733,6 +2843,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
return std::unexpected{position.error()};
|
||||
if (identity == 0 || !*position ||
|
||||
next_lives.size() >= biology::max_cellular_tick_lives ||
|
||||
(revamp_rules && next_lives.size() >= state_->revamp.organism_cap) ||
|
||||
next_archive.organism(identity)) {
|
||||
if (!twin)
|
||||
bud_results.push_back({request.life_id, 0, CellularBudResult::no_placement});
|
||||
@@ -2742,6 +2853,15 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
!next_archive.record_birth(identity, genome->id(), {proposal->end_tick}))
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
parent->reserve = transition->parent_reserve;
|
||||
if (revamp_rules && !twin) {
|
||||
// The fee, once per bud action, returns to the region; then control, if asked.
|
||||
for (std::size_t c = 0; c < fee.matter.size(); ++c)
|
||||
parent->reserve.matter[c].value -=
|
||||
std::min(parent->reserve.matter[c].value, fee.matter[c].value);
|
||||
parent->reserve.energy.value -=
|
||||
std::min(parent->reserve.energy.value, fee.energy.value);
|
||||
reclaims.emplace_back(fee, parent->position);
|
||||
}
|
||||
CellularOwnedLife bud{};
|
||||
bud.identity = {identity, identity, genome->id(), identity, {proposal->end_tick}};
|
||||
bud.source = parent->source;
|
||||
@@ -2756,6 +2876,16 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
// Offspring start with the parent's scores and lineage progress.
|
||||
bud.revamp.affinity.score = parent->revamp.affinity.score;
|
||||
bud.revamp.progress = parent->revamp.progress;
|
||||
const auto asked = std::ranges::lower_bound(ordered, request.life_id, {},
|
||||
&CellularLifeIntent::life_id);
|
||||
if (!twin && asked != ordered.end() && asked->life_id == request.life_id &&
|
||||
asked->intent.become) {
|
||||
// One-way: the player continues as the first bud; the parent is wildlife.
|
||||
bud.account = parent->account;
|
||||
parent->account = {};
|
||||
parent->revamp.offer = {};
|
||||
parent->revamp.active_ticks = 0;
|
||||
}
|
||||
}
|
||||
// Foreign residents can have a higher origin-region namespace. Keep
|
||||
// the sequence sorted even before the next parent's lookup/twin.
|
||||
@@ -3024,7 +3154,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
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,
|
||||
inheritance_rules ? &next_offspring_revisions : nullptr, next_spent);
|
||||
inheritance_rules ? &next_offspring_revisions : nullptr, next_spent, revamp_rules);
|
||||
if (!total)
|
||||
return std::unexpected{total.error()};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user