feat(cellular): seed dev wildlife and tune budding playtests
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m27s
Foundation / postgres-tools (push) Successful in 30s
Foundation / server-image (push) Successful in 4m16s
Foundation / image (push) Successful in 4m54s

This commit is contained in:
dingo
2026-10-26 12:01:57 -04:00
parent 18a64a29cd
commit ff121c3ed1
32 changed files with 738 additions and 78 deletions
+150 -2
View File
@@ -1281,7 +1281,8 @@ const CellularLiquidRules& CellularLives::liquid_rules() const noexcept {
return state_->liquid;
}
std::expected<std::unique_ptr<CellularLives>, CellularLivesError>
CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules) const {
CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules, std::uint32_t count,
std::uint64_t first) const {
if (state_->format_version != cellular_lives_liquid_format ||
state_->rules_version != cellular_lives_liquid_rules)
return std::unexpected{CellularLivesError::version};
@@ -1294,7 +1295,154 @@ CellularLives::revamp_upgrade_candidate(const CellularRevampRules& rules) const
next.format_version = cellular_lives_revamp_format;
next.rules_version = cellular_lives_revamp_rules;
next.revamp = rules;
return candidate;
if (count == 0)
return first == 0 ? std::move(candidate) : std::unexpected{CellularLivesError::identity};
// ADR-0180: only an explicit, empty opening may contain fixture roots.
if (tick() != 1 || !next.lives.empty() || !next.corpses.empty() ||
next.archive.archived() != 0 || count >= rules.organism_cap || count > 255 || first == 0 ||
first > cellular_bud_namespace - count)
return std::unexpected{CellularLivesError::invalid_config};
for (std::uint32_t index = 0; index < count; ++index) {
const auto id = first + index;
const auto founder = biology::primitive_founder(id, id, biology::primitive_founder_v6);
if (!founder)
return std::unexpected{CellularLivesError::biology};
biology::GenomeDraft draft{
.id = id,
.origin_event = id,
.development_version = 7,
.parents = {},
.capabilities = {founder->capabilities().begin(), founder->capabilities().end()},
.schema_version = biology::genome_schema_v7,
.movement_arrangement = biology::founder_movement_arrangement,
.cellular_traits = biology::founder_cellular_traits};
Random random{mutation_seed(world(), region(), id, 0x57494C44U)};
const auto points = [&] { return static_cast<std::uint16_t>(75 + random.next() % 51); };
auto& traits = *draft.cellular_traits;
traits.density = points();
traits.upkeep_efficiency = points();
traits.growth_speed = points();
for (auto& channel : traits.collection)
channel = points();
for (auto& channel : traits.burn)
channel = points();
traits.engulf_capacity = points();
traits.kill_absorption = points();
auto& movement = *draft.movement_arrangement;
movement.output = points();
movement.efficiency = points();
movement.steering = points();
movement.streamlining = points();
movement.braking = points();
movement.coasting = points();
const auto genome = biology::Genome::create(draft);
const auto budget =
genome ? biology::metabolic_budget(*genome, {1000, 0},
{next.config.ambient_temperature_millikelvin, {}},
1000, rules.body)
: std::unexpected{biology::DevelopmentError::overflow};
if (!budget)
return std::unexpected{CellularLivesError::biology};
// A normal founder's starting provision, evaluated for its randomized genome.
const accounting::Inventory reserve{
{budget->demand.value * biology::founder_reserve_seconds}, {}};
auto empty_body = accounting::Inventory{};
auto nursery = next.nursery;
auto heat = next.heat;
const auto development = biology::rules_for(genome->development_version());
if (!development || !subtract_inventory(nursery, reserve) ||
!rebody(empty_body, nursery, heat, budget->body,
development->construction_per_kilogram))
return std::unexpected{CellularLivesError::insufficient_funding};
const auto extent = budget->phenotype.extent;
if (next.config.area.width_um <= extent + 2000 ||
next.config.area.height_um <= extent + 2000)
return std::unexpected{CellularLivesError::no_placement};
std::optional<biology::CellularPosition> position;
for (int attempt = 0; attempt < 1024 && !position; ++attempt) {
const biology::CellularPosition spot{
1000 + random.next() % (next.config.area.width_um - extent - 2000),
1000 + random.next() % (next.config.area.height_um - extent - 2000)};
bool occupied = false;
for (const auto& other : next.lives) {
const auto body = budget_for(
next.archive, other, next.config.ambient_temperature_millikelvin, rules.body);
if (!body)
return std::unexpected{CellularLivesError::biology};
const auto side = body->phenotype.extent;
occupied = occupied || (spot.x_um < other.position.x_um + side &&
other.position.x_um < spot.x_um + extent &&
spot.y_um < other.position.y_um + side &&
other.position.y_um < spot.y_um + extent);
}
if (!occupied)
position = spot;
}
if (!position)
return std::unexpected{CellularLivesError::no_placement};
if (!next.archive.admit(*genome) || !next.archive.record_birth(id, id, {tick()}))
return std::unexpected{CellularLivesError::archive};
CellularOwnedLife life{};
life.identity = {id, id, id, id, {tick()}};
life.source = next.nursery_config.source;
life.growth = {1000, 0};
life.position = *position;
life.body = budget->body;
life.reserve = reserve;
life.offspring_genome = id;
next.lives.push_back(life);
next.nursery = nursery;
next.nursery_config.funding = nursery;
next.heat = heat;
}
// Restore validates bodies, identities, history and channel-by-channel closure.
return restore((*candidate)->snapshot(), world(), region(), frame(), tick());
}
std::optional<accounting::Inventory> CellularLives::budding_cost(std::uint64_t id) const {
const auto life =
std::ranges::find(state_->lives, id, [](const auto& value) { return value.identity.life; });
if (life == state_->lives.end())
return std::nullopt;
const auto parent = state_->archive.find(life->identity.genome);
const auto child = state_->archive.find(cellular_offspring_genome(*life));
if (!parent || !child)
return std::nullopt;
if (state_->rules_version < cellular_lives_revamp_rules)
return biology::offspring_cost(*parent, *child, ambient_temperature_millikelvin());
auto cost =
cellular_mutation_cost({.cost = state_->revamp.bud_fee,
.cost_scale_percent = state_->revamp.bud_fee_scale_percent});
if (life->revamp.members == 1) {
const auto investment =
biology::offspring_cost(*parent, *child, ambient_temperature_millikelvin());
if (!investment || !add_inventory(cost, *investment))
return std::nullopt;
} else {
const auto traits = parent->cellular_traits().value_or(biology::founder_cellular_traits);
const auto added = std::min<std::uint32_t>(1 + (traits.litter + 99U) / 100U,
1 + state_->revamp.bounds.max_litter / 100U);
const auto grown = organism_genome(*parent, life->revamp.members + added);
const auto target = grown
? biology::metabolic_budget(*grown, life->growth,
{ambient_temperature_millikelvin(), {}},
1000, state_->revamp.body)
: std::unexpected{biology::DevelopmentError::overflow};
const auto development = biology::rules_for(parent->development_version());
if (!target || !development)
return std::nullopt;
std::uint64_t mass{};
for (std::size_t c = 0; c < cost.matter.size(); ++c) {
const auto difference = target->body.matter[c].value > life->body.matter[c].value
? target->body.matter[c].value - life->body.matter[c].value
: 0;
cost.matter[c].value += difference;
mass += difference;
}
const auto price = development->construction_per_kilogram;
cost.energy.value += mass / 1000 * price + mass % 1000 * price / 1000;
}
return cost;
}
const CellularRevampRules& CellularLives::revamp_rules() const noexcept {
return state_->revamp;