diff --git a/deploy/kubernetes/region/dev-session-route/listener.yaml b/deploy/kubernetes/region/dev-session-route/listener.yaml index 2b295c0..56d4f09 100644 --- a/deploy/kubernetes/region/dev-session-route/listener.yaml +++ b/deploy/kubernetes/region/dev-session-route/listener.yaml @@ -12,7 +12,7 @@ spec: env: - {name: REGION_SESSION, value: "dev"} - {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"} - - {name: REGION_SESSION_WINDOW, value: "dev-20261026T161949-4606613a:1793045989"} + - {name: REGION_SESSION_WINDOW, value: "dev-20261026T164548-136c52b9:1793047548"} - {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"} ports: # QUIC (ADR-0090): UDP only; nothing listens on TCP 7400. diff --git a/src/server/lifecycle/cellular_lives.cpp b/src/server/lifecycle/cellular_lives.cpp index 9c8d8a0..6a6bffd 100644 --- a/src/server/lifecycle/cellular_lives.cpp +++ b/src/server/lifecycle/cellular_lives.cpp @@ -3242,8 +3242,18 @@ CellularLives::advance_tick_with_mutations(std::span 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, copies); + auto transition = biology::fund_offspring(*expressed, *genome, parent->growth, + parent->reserve, temperature, copies); + // Rules 13: the fee comes on top of the bud, so what the reserve keeps after funding + // it must still pay the fee; otherwise the bud is refused like any unaffordable one. + if (transition && revamp_rules && !twin) { + bool covered = transition->parent_reserve.energy.value >= fee.energy.value; + for (std::size_t c = 0; c < fee.matter.size(); ++c) + covered = covered && + transition->parent_reserve.matter[c].value >= fee.matter[c].value; + if (!covered) + transition = std::unexpected{biology::BuddingError::insufficient_funding}; + } if (revamp_rules && !twin && parent->account != LifeAccount{}) { using S = biology::CellularSignal; auto& a = activity_of(request.life_id); @@ -3290,11 +3300,9 @@ CellularLives::advance_tick_with_mutations(std::span i 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); + // Funding checked that the reserve still covers it. + if (!subtract_inventory(parent->reserve, fee)) + return std::unexpected{CellularLivesError::conservation}; reclaims.emplace_back(fee, parent->position); } CellularOwnedLife bud{}; diff --git a/tests/cellular_revamp_owner_tests.cpp b/tests/cellular_revamp_owner_tests.cpp index 2a30d30..4b9d499 100644 --- a/tests/cellular_revamp_owner_tests.cpp +++ b/tests/cellular_revamp_owner_tests.cpp @@ -178,6 +178,19 @@ void starting_wildlife_is_a_funded_opening() { closed(*seeded); } require(restore(*seeded)->snapshot() == seeded->snapshot(), "running fixture restore"); + // A player is born into the seeded region from the nursery's remainder and plays on. + seeded = checked(seeded->birth_candidate( + {account(9), 1}, {800'000, 800'000, 800'000, 800'000, {seeded->tick()}}), + "player birth after seeding"); + for (int tick = 0; tick < 40; ++tick) { + auto intents = checked(wildlife_intents(*seeded, seeded->tick() + 1), "wildlife intents"); + CellularLifeIntent player{800'000, {}}; + player.intent.movement = {500, 200}; + intents.push_back(player); + std::ranges::sort(intents, {}, &CellularLifeIntent::life_id); + checked(seeded->advance_tick(intents), "tick with the player"); + closed(*seeded); + } auto poor = opening(77, true, 1, false); checked(poor->advance_tick({}), "poor tick"); poor = checked(poor->migration_upgrade_candidate(), "poor boundary"); @@ -533,8 +546,10 @@ void thrust_moves_affinity() { // Rules 13 (reproduction plan sections 6-7): Adhesion turns the cell into a two-member organism // that holds its whole body and reserve; the organism expresses later mutations as a whole, // buds add internal members, and at the threshold it emerges as a recorded export. -Owner adhesion_region() { +Owner adhesion_region(std::uint64_t carbon_fee = 0) { auto rules = revamp(); + rules.bud_fee.matter[0].value = carbon_fee; + rules.bud_fee_scale_percent = carbon_fee == 0 ? 0 : 100; rules.offer_interval_ticks = 40; rules.bounds.buds_for_adhesion = 0; rules.emerge_members = 3; @@ -565,10 +580,13 @@ std::vector forage(const CellularLives& state, std::uint64_t const auto& life = life_of(state, life_id); const biology::CellularPatch* best = nullptr; double nearest{}; + // Short of energy, it heads for energy; otherwise for whatever is richest. + const bool hungry = life.reserve.energy.value < 3'000'000; for (const auto& patch : state.habitat().patches()) { auto richest = patch.stock.energy.value; - for (const auto& channel : patch.stock.matter) - richest = std::max(richest, channel.value); + if (!hungry) + for (const auto& channel : patch.stock.matter) + richest = std::max(richest, channel.value); const auto distance = std::hypot( static_cast(patch.address.x_um) - static_cast(life.position.x_um), static_cast(patch.address.y_um) - static_cast(life.position.y_um)); @@ -585,6 +603,8 @@ std::vector forage(const CellularLives& state, std::uint64_t static_cast(best->address.y_um) - static_cast(life.position.y_um); // Inside the unit circle: scale by the Euclidean length, rounded toward zero. const auto span = std::max(1.0, std::hypot(dx, dy)); + if (hungry && span < 80) + return input; // On the energy: hold still and feed rather than spend on thrust. for (auto& entry : input) if (entry.life_id == life_id) entry.intent.movement = {static_cast(dx * 999.0 / span), @@ -632,6 +652,29 @@ CellularBudExecution bud_until_funded(Owner& state, std::uint64_t life_id, int t } return last; } +// The bud fee comes on top of the bud. Wildlife that can fund a bud but not the fee as well is +// refused, never charged less than the fee the region reclaims (DEV region 14 stalled on that +// conservation error at its first such bud). Seeded wildlife under the DEV fee, run until buds. +void the_bud_fee_is_paid_in_full_or_refused() { + auto rules = revamp(); + rules.bud_fee = {{250'000}, {{{100'000}, {30'000}, {10'000}, {60'000}}}}; + rules.bud_fee_scale_percent = 100; + auto source = opening(77, true, 64, false); + checked(source->advance_tick({}), "opening tick"); + source = checked(source->migration_upgrade_candidate(), "boundary"); + source = checked(source->maturation_upgrade_candidate(), "maturation"); + source = checked(source->inheritance_upgrade_candidate(), "inheritance"); + source = checked(source->photosynthesis_upgrade_candidate({0, 1, {0}}), "light"); + source = checked(source->liquid_upgrade_candidate(liquid()), "liquid"); + auto state = checked(source->revamp_upgrade_candidate(rules, 32, 900'000), "wildlife"); + int tick = 0; + for (; tick < 12'000 && state->next_bud_sequence() < 2; ++tick) { + const auto intents = checked(wildlife_intents(*state, state->tick() + 1), "intents"); + checked(state->advance_tick(intents), "wildlife tick under the bud fee"); + } + require(state->next_bud_sequence() >= 2, "no wildlife budded under the fee"); + closed(*state); +} void an_organism_forms_grows_and_emerges() { auto state = adhesion_region(); const auto adhesion = await_offer(state, 101, 49); @@ -766,6 +809,7 @@ void trace_replays() { int main() try { starting_wildlife_is_a_funded_opening(); shown_bud_charge_includes_the_fee(); + the_bud_fee_is_paid_in_full_or_refused(); upgrade_and_restore(); mixed_generations_tick_and_continue(); the_spent_pool_drips_back();