feat(cellular): split collection evenly across a source's nutrients
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 4s
Foundation / checks (deploy) (push) Successful in 4m31s
Foundation / postgres-tools (push) Successful in 21s
Foundation / server-image (push) Successful in 4m21s
Foundation / image (push) Successful in 5m3s

Playtest: phosphorus held growth back everywhere. Per-nutrient collection
limits followed the body recipe (5% phosphorus), but the membrane is 10%
phosphorus, so no cell could collect phosphorus as fast as it builds with it.

Two optional revamp tuning keys, stored in a formerly reserved rules word so
regions opened without them keep their exact meaning:
- feeding.split_evenly: matter from one food source is split equally between
  the nutrients it holds (a carbon-only bubble gives the whole matter limit to
  carbon, carbon and phosphorus half each, all four a quarter each), each share
  scaled by the cell's collection trait;
- feeding.collection_percent: every collection limit per cent (100 default).

The DEV tuning file takes these keys with the image that reads them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-26 15:56:00 -04:00
co-authored by Claude Opus 5.5
parent 054e48579c
commit 51f979a664
9 changed files with 125 additions and 12 deletions
@@ -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-20261026T191917-ee4c5e16:1793056757"}
- {name: REGION_SESSION_WINDOW, value: "dev-20261026T195548-24751cee:1793058948"}
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
ports:
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
@@ -31,6 +31,13 @@ struct CellularRevampStepRules {
std::uint32_t engulf_reserve_percent{100};
// Share of a kill's remainder left as bubbles at the prey; the rest goes to the spent pool.
std::uint32_t kill_bubble_per_thousand{500};
// Every collection limit, per cent of the body's own (100: unchanged).
std::uint32_t collection_percent{100};
// Matter from one food source is split evenly between the nutrients it holds: all of the
// shared matter limit to a carbon-only bubble, half each to carbon and phosphorus, and so
// on (each share then scaled by the cell's collection trait). Off: per-nutrient limits in
// the body's proportions.
bool split_evenly{};
auto operator<=>(const CellularRevampStepRules&) const = default;
};
// Rules 13: engulf mass is the body plus the declared share of reserve matter.
@@ -23,6 +23,8 @@ struct CellularRevampTuning {
std::int64_t version{};
// Optional DEV opening fixture; zero preserves unseeded, player-origin worlds.
std::int64_t playtest_starting_wildlife_cells{};
// Optional feeding keys: every collection limit per cent, and the even split.
std::int64_t feeding_collection_percent{100}, feeding_split_evenly{};
// Body: the share of upkeep no upkeep-efficiency trait reduces.
std::int64_t body_essential_upkeep_per_mille{};
// Body: share of reserve matter carried as load on handling and thrust costs.
+24 -4
View File
@@ -85,10 +85,12 @@ std::optional<Limits> revamp_limits(const CellularLifeStepInput& life,
for (std::size_t channel = 0; channel < limits.channel.size(); ++channel) {
const auto per_second = channel == 0 ? life.budget.intake_limit.energy.value
: life.budget.intake_limit.matter[channel - 1].value;
const auto base = accounting::per_tick(per_second, cellular_motion_tick_microseconds,
accounting::Rounding::down);
auto base = accounting::per_tick(per_second, cellular_motion_tick_microseconds,
accounting::Rounding::down);
if (!base || *base > u64_max / 2'000)
return std::nullopt;
*base =
*base / 100 * rules.collection_percent + *base % 100 * rules.collection_percent / 100;
limits.channel.at(channel) = *base / 100 * own.collection.at(channel) +
*base % 100 * own.collection.at(channel) / 100;
if (limits.channel.at(channel) > u64_max / 2'000)
@@ -266,10 +268,26 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
deposit))
continue;
bool took = false;
// Even split: the matter limit left this tick, shared equally by the nutrients
// this source holds.
const bool even = rules.revamp->split_evenly;
std::uint64_t share{};
if (even) {
std::uint64_t present{};
for (std::size_t channel = 1; channel < limits->channel.size(); ++channel)
present += channel_of(patch_stock[index], channel) != 0 ? 1 : 0;
const auto matter = matter_of(drained);
const auto left = limits->shared > matter ? limits->shared - matter : 0;
share = present == 0 ? 0 : left / present;
}
for (std::size_t channel = 0; channel < limits->channel.size(); ++channel) {
auto& stock = channel_of(patch_stock[index], channel);
auto& taken = channel_of(drained, channel);
auto allowance = limits->channel.at(channel) - taken;
if (even && channel != 0) {
const auto trait = std::uint64_t{life->revamp->collection.at(channel)};
allowance = share / 100 * trait + share % 100 * trait / 100;
}
if (channel != 0) {
const auto matter = matter_of(drained);
allowance = std::min(allowance,
@@ -277,8 +295,10 @@ propose_cellular_region_step(std::uint64_t begin_tick, CellularArea area,
}
if (deposit.kind == CellularDepositKind::pool)
allowance =
std::min(allowance, limits->channel.at(channel) *
cellular_pool_yield_per_thousand / 1000);
even && channel != 0
? allowance * cellular_pool_yield_per_thousand / 1000
: std::min(allowance, limits->channel.at(channel) *
cellular_pool_yield_per_thousand / 1000);
auto& reserve = channel_of(result.reserve_after, channel);
const auto take = std::min({stock, allowance, u64_max - reserve});
if (stock > take) {
+6 -1
View File
@@ -36,6 +36,9 @@ constexpr std::array fields{
rate_limit},
Field{"feeding.membrane_collection_per_mille_per_point",
&CellularRevampTuning::feeding_membrane_collection_per_mille_per_point, 0, 1'000},
Field{"feeding.collection_percent", &CellularRevampTuning::feeding_collection_percent, 1,
1'000},
Field{"feeding.split_evenly", &CellularRevampTuning::feeding_split_evenly, 0, 1},
Field{"predation.engulf_ratio_milli", &CellularRevampTuning::predation_engulf_ratio_milli, 1,
1'000'000},
Field{"predation.engulf_reserve_percent",
@@ -246,7 +249,9 @@ parse_cellular_revamp_tuning(std::string_view text) {
tuning.*field.member = *value;
}
for (std::size_t index = 0; index < fields.size(); ++index)
if (!seen.at(index) && fields.at(index).key != "playtest.starting_wildlife_cells")
if (!seen.at(index) && fields.at(index).key != "playtest.starting_wildlife_cells" &&
fields.at(index).key != "feeding.collection_percent" &&
fields.at(index).key != "feeding.split_evenly")
return std::unexpected{
error(CellularTuningErrorKind::missing_key, 0, fields.at(index).key)};
if (tuning.version != cellular_revamp_tuning_version)
+11 -3
View File
@@ -1630,7 +1630,11 @@ std::vector<std::uint8_t> CellularLives::snapshot() const {
if (revamp) {
const auto& r = state_->revamp;
out.put(r.body.essential_upkeep_per_thousand, 4);
out.put(0, 4);
// Formerly reserved: collection per cent (0 for the original 100) and the even split
// in bit 16. Regions opened before these keys hold zero and keep their meaning.
out.put((r.step.collection_percent == 100 ? 0U : r.step.collection_percent) |
(r.step.split_evenly ? 0x10000U : 0U),
4);
for (const auto rate : r.burn_pj_per_kfg)
out.put(rate);
out.put(r.step.membrane_collection_per_mille_per_point, 4);
@@ -2157,7 +2161,10 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
if (revamp_version) {
const auto u32 = [&in] { return static_cast<std::uint32_t>(in.get(4)); };
revamp.body.essential_upkeep_per_thousand = u32();
const auto reserved = in.get(4);
const auto feeding = in.get(4);
revamp.step.collection_percent =
(feeding & 0xFFFFU) == 0 ? 100U : static_cast<std::uint32_t>(feeding & 0xFFFFU);
revamp.step.split_evenly = (feeding & 0x10000U) != 0;
for (auto& rate : revamp.burn_pj_per_kfg)
rate = in.get();
revamp.step.membrane_collection_per_mille_per_point = u32();
@@ -2169,7 +2176,8 @@ CellularLives::restore(std::span<const std::uint8_t> bytes, std::uint64_t world,
revamp.drip_bubble_pj = in.get();
revamp.drip_bubble_fg = in.get();
spent = in.inventory();
if (!read_revamp_offers(in, revamp) || reserved != 0 || !cellular_revamp_valid(revamp))
if (!read_revamp_offers(in, revamp) || (feeding & ~0x1FFFFULL) != 0 ||
(feeding & 0xFFFFU) == 100 || !cellular_revamp_valid(revamp))
return std::unexpected{CellularLivesError::format};
}
const auto life_bytes =
+7 -3
View File
@@ -41,6 +41,7 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
return false;
return rules.body.essential_upkeep_per_thousand <= 1'000 &&
step.membrane_collection_per_mille_per_point <= 1'000 && step.engulf_ratio_milli >= 1 &&
step.collection_percent >= 1 && step.collection_percent <= 1'000 &&
step.engulf_ratio_milli <= 1'000'000 && step.engulf_reserve_percent <= 100 &&
step.kill_bubble_per_thousand <= 1'000 && rules.drip_interval_ticks <= 72'000 &&
rules.drip_bubble_pj <= most && rules.drip_bubble_fg <= most &&
@@ -51,8 +52,9 @@ bool cellular_revamp_valid(const CellularRevampRules& rules) noexcept {
rules.split_share_per_thousand < 1'000 && rules.split_min_growth != 0 &&
rules.split_min_growth <= 1'000 && rules.bud_fee_scale_percent <= 100 &&
rules.bud_fee.energy.value <= most &&
std::ranges::all_of(rules.bud_fee.matter,
[](const accounting::Femtograms& f) { return f.value <= most; }) &&
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 &&
@@ -248,7 +250,9 @@ CellularRevampRules cellular_revamp_rules(const biology::CellularRevampTuning& t
u32(t.feeding_membrane_collection_per_mille_per_point),
.engulf_ratio_milli = u32(t.predation_engulf_ratio_milli),
.engulf_reserve_percent = u32(t.predation_engulf_reserve_percent),
.kill_bubble_per_thousand = u32(t.predation_kill_bubble_per_mille)},
.kill_bubble_per_thousand = u32(t.predation_kill_bubble_per_mille),
.collection_percent = u32(t.feeding_collection_percent),
.split_evenly = t.feeding_split_evenly != 0},
.drip_interval_ticks = u32(t.spent_drip_interval_ticks),
.drip_bubble_pj = u64(t.spent_drip_bubble_pj),
.drip_bubble_fg = u64(t.spent_drip_bubble_fg),
+27
View File
@@ -237,6 +237,32 @@ void upgrade_and_restore() {
"a format 11 checkpoint restored as format 10");
}
// The feeding settings live in a formerly reserved word: zero there is the original 100%
// per-nutrient collection, so earlier regions restore unchanged; new values round-trip.
void feeding_settings_restore() {
auto rules = revamp();
rules.step.collection_percent = 130;
rules.step.split_evenly = true;
auto state = opening(7, true, 2, false);
checked(state->advance_tick({}), "genesis tick");
state = checked(state->migration_upgrade_candidate(), "boundary upgrade");
state = checked(state->maturation_upgrade_candidate(), "maturation upgrade");
state = checked(state->inheritance_upgrade_candidate(), "inheritance upgrade");
state = checked(state->photosynthesis_upgrade_candidate({0, 1, {0}}), "light upgrade");
state = checked(state->liquid_upgrade_candidate(liquid()), "liquid upgrade");
const auto plain = checked(state->revamp_upgrade_candidate(revamp()), "plain upgrade");
state = checked(state->revamp_upgrade_candidate(rules), "feeding upgrade");
const auto copy = restore(*state);
require(copy->revamp_rules() == rules && copy->snapshot() == state->snapshot(),
"feeding settings did not restore");
require(restore(*plain)->revamp_rules().step.collection_percent == 100 &&
!restore(*plain)->revamp_rules().step.split_evenly,
"an original region changed its feeding");
auto too_much = revamp();
too_much.step.collection_percent = 1'001;
require(!state->revamp_upgrade_candidate(too_much), "collection above 1000% accepted");
}
// Both generations live and pay their way in one region, and restore continues exactly.
void mixed_generations_tick_and_continue() {
auto continuous = revamp_region();
@@ -815,6 +841,7 @@ int main() try {
shown_bud_charge_includes_the_fee();
the_bud_fee_is_paid_in_full_or_refused();
upgrade_and_restore();
feeding_settings_restore();
mixed_generations_tick_and_continue();
the_spent_pool_drips_back();
carried_matter_is_load();
+40
View File
@@ -142,6 +142,45 @@ void collection_per_channel_with_a_shared_limit() {
CHECK(total(*result, *map, lives) == before(*map, lives));
}
// The even split: a source's matter limit (here 200 a tick) is shared equally by the
// nutrients it holds, each share scaled by the cell's collection trait; a collection
// percentage scales every limit.
void collection_split_evenly_between_what_a_source_holds() {
CellularRevampStepRules even{};
even.split_evenly = true;
const CellularRegionRules rules{true, true, even};
const auto collected = [&](const Inventory& stock, const CellularRegionRules& with,
CellularRevampLifeInput input = founder_input()) {
const auto map = liquid_map(stock);
const std::array lives{cell(1, {95, 95}, 1'000, {}, false, input)};
const auto result = propose_cellular_region_step(4, area, lives, *map, with);
CHECK(result && total(*result, *map, lives) == before(*map, lives));
return result->lives[0].candidate.reserve_after.matter;
};
const auto only_carbon = collected(inv(0, 1'000, 0, 0, 0), rules);
CHECK(only_carbon[0].value == 200 && only_carbon[2].value == 0);
const auto carbon_and_phosphorus = collected(inv(0, 1'000, 0, 1'000, 0), rules);
CHECK(carbon_and_phosphorus[0].value == 100 && carbon_and_phosphorus[2].value == 100);
const auto all_four = collected(inv(0, 1'000, 1'000, 1'000, 1'000), rules);
CHECK(all_four[0].value == 50 && all_four[1].value == 50 && all_four[2].value == 50 &&
all_four[3].value == 50);
// A share is capped by what the source holds; the trait scales its own share only.
const auto scarce = collected(inv(0, 1'000, 0, 30, 0), rules);
CHECK(scarce[0].value == 100 && scarce[2].value == 30);
auto poor = founder_input();
poor.collection = {100, 50, 100, 100, 100}; // Carbon collection halved.
const auto poor_take = collected(inv(0, 1'000, 0, 1'000, 0), rules, poor);
CHECK(poor_take[0].value == 50 && poor_take[2].value == 100);
// 130%: every limit 65 a tick, the shared matter limit 260.
auto more = even;
more.collection_percent = 130;
const auto boosted = collected(inv(0, 1'000, 0, 0, 0), {true, true, more});
CHECK(boosted[0].value == 260);
// Off, as before: per-nutrient limits (50 a tick each).
const auto per_nutrient = collected(inv(0, 1'000, 0, 0, 0), plain);
CHECK(per_nutrient[0].value == 50);
}
void a_thicker_membrane_collects_slower() {
const auto map = liquid_map(inv(1'000, 1'000, 1'000, 1'000, 1'000));
auto input = founder_input();
@@ -259,6 +298,7 @@ void every_life_needs_a_revamp_input() {
int main() {
try {
collection_per_channel_with_a_shared_limit();
collection_split_evenly_between_what_a_source_holds();
a_thicker_membrane_collects_slower();
matter_pays_upkeep_and_nothing_left_starves();
reserve_mass_and_capacity_decide_engulfment();