feat(admin): take reserve, cull wildlife, wildlife cap, fresh bud costs (schema 67)
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m34s
Foundation / postgres-tools (push) Successful in 26s
Foundation / server-image (push) Successful in 4m30s
Foundation / image (push) Successful in 5m46s

ADR-0182 section 16, from playtesting region 16 at its 256-life cap.

- Bud costs: the region host's cache of each genome's bud cost was keyed
  by genome only, so after a tuning adoption the client kept the old cost
  (or "cannot bud"). It now clears when the rules' encoding changes.
- Wildlife cap: reproduction.wildlife_cap (optional, 0..organism cap,
  0 = the organism cap) refuses buds of parents without an account at that
  many lives, keeping the slots above it for players. Bits 17-31 of the
  energy-cycle word, so older rules keep their bytes. DEV file: 200.
- Schema 67: admin command kinds take_reserve (8: up to the amounts from a
  life's reserve to the spent pool) and remove_wildlife (9: every life
  without an account, as remove_cell).
- Region view: caps; the portal shows lives against the cap.
- Portal: Take reserve in the inspector, Remove all wildlife, and marking
  cells on the map (shift+click, shift+drag) for bulk removal; the guided
  editor lists optional keys the base revision lacks.
- Client: a refused bud says the region may be full.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-28 16:06:56 -04:00
co-authored by Claude Opus 5.5
parent 51aa08446d
commit 757304437e
24 changed files with 485 additions and 70 deletions
+5
View File
@@ -87,6 +87,7 @@ constexpr std::array fields{
Field{"reproduction.bud_fee_scale_percent",
&CellularRevampTuning::reproduction_bud_fee_scale_percent, 0, 100},
Field{"reproduction.organism_cap", &CellularRevampTuning::reproduction_organism_cap, 1, 256},
Field{"reproduction.wildlife_cap", &CellularRevampTuning::reproduction_wildlife_cap, 0, 256},
Field{"organism.load_per_mille", &CellularRevampTuning::organism_load_per_mille, 0, 10'000},
Field{"organism.emerge_members", &CellularRevampTuning::organism_emerge_members, 2, 10'000},
Field{"organism.emerge_mass_fg", &CellularRevampTuning::organism_emerge_mass_fg, 0,
@@ -262,6 +263,7 @@ parse_cellular_revamp_tuning(std::string_view text) {
fields.at(index).key != "feeding.split_evenly" &&
fields.at(index).key != "spent.heat_recycle_per_mille" &&
fields.at(index).key != "spent.drip_absorb" &&
fields.at(index).key != "reproduction.wildlife_cap" &&
fields.at(index).key != "reproduction.safety_version" &&
fields.at(index).key != "body.growth_reserve_seconds" &&
fields.at(index).key != "reproduction.split_launch_um_per_s")
@@ -270,6 +272,9 @@ parse_cellular_revamp_tuning(std::string_view text) {
if (tuning.version != cellular_revamp_tuning_version)
return std::unexpected{
error(CellularTuningErrorKind::unsupported_version, 0, "tuning.version")};
if (tuning.reproduction_wildlife_cap > tuning.reproduction_organism_cap)
return std::unexpected{
error(CellularTuningErrorKind::inconsistent, 0, "reproduction.wildlife_cap")};
if (tuning.playtest_starting_wildlife_cells >= tuning.reproduction_organism_cap)
return std::unexpected{
error(CellularTuningErrorKind::inconsistent, 0, "playtest.starting_wildlife_cells")};
+14 -7
View File
@@ -578,11 +578,18 @@ OpsResponse AdminApi::set_window(std::uint64_t region, std::string_view query_te
}
namespace {
// Kinds 1-6 are queued by name; adopt_tuning (7) only through a tuning revision.
constexpr std::array<std::string_view, 8> command_kinds{
"", "remove_cell", "grant_reserve", "add_bubbles",
"add_pool", "release_pool", "spawn_wildlife", "adopt_tuning"};
constexpr std::size_t queued_kinds = 7;
// Every kind is queued by name but adopt_tuning (7), which comes only through a tuning revision.
constexpr std::array<std::string_view, 10> command_kinds{"",
"remove_cell",
"grant_reserve",
"add_bubbles",
"add_pool",
"release_pool",
"spawn_wildlife",
"adopt_tuning",
"take_reserve",
"remove_wildlife"};
constexpr std::size_t tuning_kind = 7;
std::string hex(std::span<const std::uint8_t> bytes) {
constexpr std::string_view digits = "0123456789abcdef";
@@ -1023,7 +1030,7 @@ OpsResponse AdminApi::enqueue(std::uint64_t region, std::string_view query_text,
kind_text ? std::ranges::find(command_kinds, *kind_text) : command_kinds.end();
if (!kind_text || kind_text->empty() || kind == command_kinds.end())
return error(400, "bad_kind");
if (static_cast<std::size_t>(kind - command_kinds.begin()) >= queued_kinds)
if (static_cast<std::size_t>(kind - command_kinds.begin()) == tuning_kind)
return error(400, "bad_kind");
// Absent numbers are zero; present ones must be plain u64 decimals.
const auto value = [&](std::string_view name) -> std::optional<std::uint64_t> {
@@ -1107,7 +1114,7 @@ OpsResponse AdminApi::set_schedule(std::uint64_t region, std::string_view query_
kind_text ? std::ranges::find(command_kinds, *kind_text) : command_kinds.end();
if (!kind_text || kind_text->empty() || kind == command_kinds.end())
return error(400, "bad_kind");
if (static_cast<std::size_t>(kind - command_kinds.begin()) >= queued_kinds)
if (static_cast<std::size_t>(kind - command_kinds.begin()) == tuning_kind)
return error(400, "bad_kind");
const auto value = [&](std::string_view name,
std::uint64_t absent) -> std::optional<std::uint64_t> {
@@ -93,6 +93,12 @@ std::string render_cellular_admin_view(const CellularLives& state,
out.push_back(',');
append(out, rules.heat_recycle_per_thousand);
out += rules.drip_absorb ? ",1]" : ",0]";
// The organism cap and the wildlife cap (0: the organism cap).
out += ",\"caps\":[";
append(out, rules.organism_cap);
out.push_back(',');
append(out, rules.wildlife_cap);
out.push_back(']');
}
out += ",\"cells_total\":";
append(out, lives.size());
+70 -29
View File
@@ -237,8 +237,10 @@ void write_revamp_offers(Writer& out, const CellularRevampRules& r) {
out.put(r.split_launch_um_per_s, 4);
out.put(b.carbon_for_light);
out.put(r.offer_interval_ticks, 4);
// The offer interval's reserved word: the heat recycle share and the absorbing drip.
out.put(r.heat_recycle_per_thousand | (r.drip_absorb ? 0x10000U : 0U), 4);
// The offer interval's reserved word: the heat recycle share (bits 0-15), the absorbing
// drip (bit 16) and the wildlife cap (bits 17-31).
out.put(r.heat_recycle_per_thousand | (r.drip_absorb ? 0x10000U : 0U) | (r.wildlife_cap << 17U),
4);
for (const auto& m : r.mutations) {
out.put(m.enabled ? 1 : 0, 1);
out.zeros(3);
@@ -288,7 +290,8 @@ bool read_revamp_offers(Reader& in, CellularRevampRules& r) {
const auto cycle = in.get(4);
r.heat_recycle_per_thousand = static_cast<std::uint32_t>(cycle & 0xFFFFU);
r.drip_absorb = (cycle & 0x10000U) != 0;
zero = zero && (cycle & ~0x1FFFFULL) == 0;
r.wildlife_cap = static_cast<std::uint32_t>(cycle >> 17U);
zero = zero && (cycle >> 32U) == 0;
for (auto& m : r.mutations) {
const auto enabled = in.get(1);
zero = zero && enabled <= 1 && in.get(3) == 0;
@@ -1537,6 +1540,10 @@ bool cellular_admin_command_valid(const CellularAdminCommand& c) noexcept {
c.target <= cellular_bud_namespace - c.count;
case CellularAdminKind::adopt_tuning:
return c.id != 0 && c.count == 0 && c.target != 0 && some && c.amount.matter[3].value == 0;
case CellularAdminKind::take_reserve:
return c.id != 0 && c.target != 0 && c.count == 0 && some;
case CellularAdminKind::remove_wildlife:
return c.id != 0 && c.target == 0 && c.count == 0 && !some;
}
return false;
}
@@ -1556,6 +1563,35 @@ CellularLives::admin_candidate(std::span<const CellularAdminCommand> commands,
if (!candidate)
return std::unexpected(candidate.error());
std::vector<CellularAdminResult> report;
// A removed life's body and reserve go to the spent pool, and it leaves a corpse.
const auto remove_life = [&](State& next, std::vector<CellularOwnedLife>::iterator life) {
if (!next.archive.record_death(life->identity.organism, {tick()}))
return false;
auto single = *life;
single.revamp.members = 1; // A corpse records the single-cell extent.
const auto extent = budget_for(
next.archive, single, next.config.ambient_temperature_millikelvin, next.revamp.body);
if (!extent || !add_inventory(next.spent, life->body) ||
!add_inventory(next.spent, life->reserve))
return false;
CellularOwnedCorpse corpse{life->identity.life,
life->identity.organism,
life->source,
tick(),
life->position,
life->growth,
extent->phenotype.extent,
{},
biology::CellularDeathCause::removed,
0,
life->parent_life,
life->offspring_genome};
const auto at = std::ranges::lower_bound(next.corpses, corpse.organism, {},
&CellularOwnedCorpse::organism);
next.corpses.insert(at, corpse);
next.lives.erase(life);
return true;
};
for (const auto& command : commands) {
// Each command works on a copy, kept only when it applies and still closes.
auto attempt = restore((*candidate)->snapshot(), world(), region(), frame(), tick());
@@ -1568,34 +1604,36 @@ CellularLives::admin_candidate(std::span<const CellularAdminCommand> commands,
const bool found = life != next.lives.end() && life->identity.life == command.target;
switch (command.kind) {
case CellularAdminKind::remove_cell:
if (found && next.archive.record_death(life->identity.organism, {tick()})) {
auto single = *life;
single.revamp.members = 1; // A corpse records the single-cell extent.
const auto extent =
budget_for(next.archive, single, next.config.ambient_temperature_millikelvin,
next.revamp.body);
if (extent && add_inventory(next.spent, life->body) &&
add_inventory(next.spent, life->reserve)) {
CellularOwnedCorpse corpse{life->identity.life,
life->identity.organism,
life->source,
tick(),
life->position,
life->growth,
extent->phenotype.extent,
{},
biology::CellularDeathCause::removed,
0,
life->parent_life,
life->offspring_genome};
const auto at = std::ranges::lower_bound(next.corpses, corpse.organism, {},
&CellularOwnedCorpse::organism);
next.corpses.insert(at, corpse);
next.lives.erase(life);
applied = true;
}
applied = found && remove_life(next, life);
break;
case CellularAdminKind::remove_wildlife: {
std::vector<std::uint64_t> wild;
for (const auto& each : next.lives)
if (each.account == LifeAccount{})
wild.push_back(each.identity.life);
applied = !wild.empty();
for (const auto id : wild) {
const auto at = std::ranges::lower_bound(
next.lives, id, {}, [](const auto& v) { return v.identity.life; });
applied = applied && remove_life(next, at);
}
break;
}
case CellularAdminKind::take_reserve: {
if (!found)
break;
auto amount = command.amount; // Never more than the reserve holds.
for (std::size_t c = 0; c < 5; ++c) {
auto& want = c == 0 ? amount.energy.value : amount.matter[c - 1].value;
const auto have =
c == 0 ? life->reserve.energy.value : life->reserve.matter[c - 1].value;
want = std::min(want, have);
}
applied = amount != accounting::Inventory{} &&
subtract_inventory(life->reserve, amount) &&
add_inventory(next.spent, amount);
break;
}
case CellularAdminKind::grant_reserve:
applied = found && add_inventory(life->reserve, command.amount) &&
add_inventory(next.boundary.incoming, command.amount);
@@ -3604,6 +3642,9 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
if (identity == 0 || !*position ||
next_lives.size() >= biology::max_cellular_tick_lives ||
(revamp_rules && next_lives.size() >= state_->revamp.organism_cap) ||
(revamp_rules && parent->account == LifeAccount{} &&
state_->revamp.wildlife_cap != 0 &&
next_lives.size() >= state_->revamp.wildlife_cap) ||
next_archive.organism(identity)) {
if (!twin)
bud_results.push_back({request.life_id, 0, CellularBudResult::no_placement});
+5 -3
View File
@@ -63,9 +63,10 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
std::ranges::all_of(rules.bud_fee.matter,
[](const accounting::Femtograms& f) { return f.value <= most; }) &&
rules.organism_cap != 0 && rules.organism_cap <= biology::max_cellular_tick_lives &&
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);
rules.wildlife_cap <= rules.organism_cap && 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,
@@ -353,6 +354,7 @@ CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t
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),
.wildlife_cap = u32(t.reproduction_wildlife_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),