feat(cellular): session v14, bundle 15 and rules-13 wildlife
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s
Foundation / checks (checks) (push) Successful in 5s
Foundation / checks (client) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 4s
Foundation / checks (postgres) (push) Successful in 5s
Foundation / checks (network) (push) Successful in 5s
Foundation / checks (tsan) (push) Successful in 5s
Foundation / checks (deploy) (push) Successful in 4m29s
Foundation / postgres-tools (push) Successful in 24s
Foundation / server-image (push) Successful in 4m33s
Foundation / image (push) Successful in 4m59s
Session v14 carries the rules-13 revamp: a body block in the owner's view (members, emergence threshold, exclusions, Emerge open, payable energy, mass and the 20 traits), become, emerge and channel exclusions on actions, become on mutation choices, catalog offers (id, chance, cost) and the emerged ending. Older sessions never see a v14 field. The client shows Stay / Become offspring offers named from the shared catalog, continuing as a bud, the organism and its Emerge button, kept channels, the body and the emerged end screen. Bundle 15 (rules 13 on owner format 11) is durable: schema 60 admits it raw-only, stores become as bit 15 of the choice's operator, widens the action input and mutation results, and publishes the 14 -> 15 revamp profile migration. evo-world-clone opens cellular-v10 (cellular-v9 plus the revamp upgrade from --revamp-tuning), resumable and recoverable. Wildlife counts reserve matter as energy, waits for the bud fee, grows organisms one short of emerging, and hunts by the region step's rules-13 engulf test. The play summary adds organisms, offers and the spent pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -128,6 +128,28 @@ network::ActionOutcome action_outcome(const FinalCellularMutation& mutation) noe
|
||||
network::CellularMutationOffer offer_view(const CellularLives& state, const CellularOwnedLife& life,
|
||||
std::uint64_t tick) {
|
||||
network::CellularMutationOffer view{tick, life.identity.life, 0, 0, {}};
|
||||
if (state.rules_version() >= cellular_lives_revamp_rules) {
|
||||
// Rules 13 (v14): catalog mutations with their chance and tuned cost; the client names
|
||||
// them from the same catalog.
|
||||
const auto& pending = life.revamp.offer;
|
||||
if (pending.count == 0)
|
||||
return view;
|
||||
view.event_index = pending.event_index;
|
||||
view.offer_tick = pending.offer_tick;
|
||||
for (std::size_t k = 0; k < pending.count; ++k) {
|
||||
const auto id = pending.ids.at(k);
|
||||
if (id == 0 || id > biology::cellular_catalog_size)
|
||||
continue;
|
||||
const auto cost = cellular_mutation_cost(state.revamp_rules().mutations.at(id - 1u));
|
||||
network::CellularOfferedCandidate shown{
|
||||
id, 0, 0, pending.chances.at(k), 0, 0, cost.energy.value, {}};
|
||||
for (std::size_t channel = 0; channel < shown.cost_matter_fg.size(); ++channel)
|
||||
shown.cost_matter_fg.at(channel) = cost.matter.at(channel).value;
|
||||
view.candidates.push_back(shown);
|
||||
}
|
||||
std::ranges::sort(view.candidates, {}, &network::CellularOfferedCandidate::operator_id);
|
||||
return view;
|
||||
}
|
||||
const auto& offer = life.mutation.offer;
|
||||
if (!offer)
|
||||
return view;
|
||||
@@ -842,17 +864,29 @@ CellularRegionHost::select_mutation(const persistence::Uuid& account, std::uint6
|
||||
// The choice must name this account's living cell and its exact outstanding offer.
|
||||
const auto life = std::ranges::find(state_->lives(), account, &CellularOwnedLife::account);
|
||||
if (life == state_->lives().end() || life->identity.life != input.life_id ||
|
||||
input.event_index == 0 || life->mutation.event_index != input.event_index ||
|
||||
life->mutation.offer_tick != input.offer_tick || input.offer_tick >= tick ||
|
||||
input.event_index == 0 || input.offer_tick >= tick ||
|
||||
life->presence != CellularPresence::active) // ADR-0128: only an active life chooses.
|
||||
return {invalid, 0, {}};
|
||||
const auto& offer = life->mutation.offer;
|
||||
// Operator 0 declines the exact offer (ADR-0120 amendment); otherwise it must be offered.
|
||||
if (!offer || (input.operator_id != 0 &&
|
||||
!std::ranges::any_of(offer->candidates, [&](const auto& candidate) {
|
||||
return candidate.operator_id == input.operator_id;
|
||||
})))
|
||||
return {invalid, 0, {}};
|
||||
if (state_->rules_version() >= cellular_lives_revamp_rules) {
|
||||
// Rules 13: the catalog offer; operator 0 declines, and become needs a choice.
|
||||
const auto& offer = life->revamp.offer;
|
||||
const auto end = offer.ids.begin() + offer.count;
|
||||
if (offer.count == 0 || offer.event_index != input.event_index ||
|
||||
offer.offer_tick != input.offer_tick || (input.become && input.operator_id == 0) ||
|
||||
(input.operator_id != 0 &&
|
||||
std::ranges::find(offer.ids.begin(), end, input.operator_id) == end))
|
||||
return {invalid, 0, {}};
|
||||
} else {
|
||||
const auto& offer = life->mutation.offer;
|
||||
// Operator 0 declines the exact offer (ADR-0120 amendment); otherwise it must be offered.
|
||||
if (input.become || life->mutation.event_index != input.event_index ||
|
||||
life->mutation.offer_tick != input.offer_tick || !offer ||
|
||||
(input.operator_id != 0 &&
|
||||
!std::ranges::any_of(offer->candidates, [&](const auto& candidate) {
|
||||
return candidate.operator_id == input.operator_id;
|
||||
})))
|
||||
return {invalid, 0, {}};
|
||||
}
|
||||
const auto grant = authority_.grant();
|
||||
if (!grant)
|
||||
return {not_ready, 0, {}};
|
||||
|
||||
@@ -107,7 +107,9 @@ bool valid_action_input(const CellularActionRecord& action, std::uint64_t begin_
|
||||
return !all_zero(action.account) && action.action_id != 0 && tick > begin_tick &&
|
||||
tick <= end_tick && move_x >= -movement_limit && move_x <= movement_limit &&
|
||||
move_y >= -movement_limit && move_y <= movement_limit && input[12] <= 3 &&
|
||||
input[13] <= 1 && all_zero(input.subspan(14, 2)) &&
|
||||
// Flags: brake, become (with a bud) and emerge (no target); then exclusions.
|
||||
input[13] <= 7 && ((input[13] & 2U) == 0 || input[12] == 3) &&
|
||||
((input[13] & 4U) == 0 || input[12] == 0) && input[14] <= 0x0F && input[15] == 0 &&
|
||||
(input[12] == 1 || all_zero(input.subspan(16, 8)));
|
||||
}
|
||||
bool action_less(const CellularActionRecord& a, const CellularActionRecord& b) {
|
||||
@@ -400,7 +402,7 @@ encode_cellular_mutation_input(const CellularMutationActionRecord& action) {
|
||||
put(bytes, action.input.life_id, 8);
|
||||
put(bytes, action.input.event_index, 8);
|
||||
put(bytes, action.input.offer_tick, 8);
|
||||
put(bytes, action.input.operator_id, 2);
|
||||
put(bytes, action.input.operator_id | (action.input.become ? 0x8000U : 0U), 2);
|
||||
std::array<std::uint8_t, cellular_mutation_input_bytes> out{};
|
||||
std::ranges::copy(bytes, out.begin());
|
||||
return out;
|
||||
@@ -418,10 +420,12 @@ decode_cellular_mutation_input(const std::array<std::uint8_t, 16>& account, std:
|
||||
action.input.life_id = get(input, 8, 8);
|
||||
action.input.event_index = get(input, 16, 8);
|
||||
action.input.offer_tick = get(input, 24, 8);
|
||||
action.input.operator_id = static_cast<std::uint16_t>(get(input, 32, 2));
|
||||
const auto stored = static_cast<std::uint16_t>(get(input, 32, 2));
|
||||
action.input.operator_id = static_cast<std::uint16_t>(stored & 0x7FFFU);
|
||||
action.input.become = (stored & 0x8000U) != 0;
|
||||
if (action_id == 0 || action.tick == 0 || action.input.life_id == 0 ||
|
||||
action.input.event_index == 0 || action.input.offer_tick == 0 ||
|
||||
action.input.offer_tick >= action.tick)
|
||||
(action.input.become && action.input.operator_id == 0) || action.input.event_index == 0 ||
|
||||
action.input.offer_tick == 0 || action.input.offer_tick >= action.tick)
|
||||
return std::nullopt;
|
||||
return action;
|
||||
}
|
||||
@@ -517,7 +521,8 @@ encode_cellular_mutation_action_block(std::span<const CellularMutationActionReco
|
||||
put(out, action.input.life_id, 8);
|
||||
put(out, action.input.event_index, 8);
|
||||
put(out, action.input.offer_tick, 8);
|
||||
put(out, action.input.operator_id, 2);
|
||||
// Rules 13: become is bit 15 of the stored operator, as in the reservation input.
|
||||
put(out, action.input.operator_id | (action.input.become ? 0x8000U : 0U), 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
return out;
|
||||
@@ -541,8 +546,11 @@ decode_cellular_mutation_action_block(std::span<const std::uint8_t> bytes, std::
|
||||
action.input.life_id = get(record, 32, 8);
|
||||
action.input.event_index = get(record, 40, 8);
|
||||
action.input.offer_tick = get(record, 48, 8);
|
||||
action.input.operator_id = static_cast<std::uint16_t>(get(record, 56, 2));
|
||||
if (!all_zero(record.subspan(58, 6)))
|
||||
const auto stored = static_cast<std::uint16_t>(get(record, 56, 2));
|
||||
action.input.operator_id = static_cast<std::uint16_t>(stored & 0x7FFFU);
|
||||
action.input.become = (stored & 0x8000U) != 0;
|
||||
if (!all_zero(record.subspan(58, 6)) ||
|
||||
(action.input.become && action.input.operator_id == 0))
|
||||
return std::unexpected{CellularActionBlockError::format};
|
||||
out.push_back(action);
|
||||
offset += cellular_mutation_action_record_bytes;
|
||||
@@ -587,7 +595,10 @@ match_cellular_actions_to_trace(const CellularLives& predecessor, const Cellular
|
||||
intent->intent.movement.y !=
|
||||
std::bit_cast<std::int16_t>(static_cast<std::uint16_t>(get(input, 10, 2))) ||
|
||||
intent->intent.intake_target != target || intent->intent.engulf != (input[12] == 2) ||
|
||||
intent->intent.bud != (input[12] == 3) || intent->intent.brake != (input[13] == 1))
|
||||
intent->intent.bud != (input[12] == 3) ||
|
||||
intent->intent.brake != ((input[13] & 1U) != 0) ||
|
||||
intent->intent.become != ((input[13] & 2U) != 0) ||
|
||||
intent->intent.emerge != ((input[13] & 4U) != 0) || intent->intent.exclude != input[14])
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
}
|
||||
return {};
|
||||
@@ -623,7 +634,8 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
action.tick == tick && action.input.life_id == selection.life_id &&
|
||||
action.input.event_index == selection.event_index &&
|
||||
action.input.offer_tick == selection.offer_tick &&
|
||||
action.input.operator_id == selection.operator_id;
|
||||
action.input.operator_id == selection.operator_id &&
|
||||
action.input.become == selection.become;
|
||||
});
|
||||
if (matches != 1)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
@@ -645,7 +657,8 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
if (departed == mutations.end() || departed->life_id != action.input.life_id ||
|
||||
departed->event_index != action.input.event_index ||
|
||||
departed->offer_tick != action.input.offer_tick ||
|
||||
departed->operator_id != action.input.operator_id)
|
||||
departed->operator_id != action.input.operator_id ||
|
||||
departed->become != action.input.become)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
continue;
|
||||
}
|
||||
@@ -655,7 +668,24 @@ match_cellular_mutation_actions_to_trace(const CellularLives& predecessor,
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto selection = std::ranges::lower_bound(mutations, life->identity.life, {},
|
||||
&CellularMutationSelection::life_id);
|
||||
if (!life->mutation.offer)
|
||||
if (predecessor.rules_version() >= cellular_lives_revamp_rules) {
|
||||
// Rules 13: the catalog offer the life held; operator 0 declines it.
|
||||
const auto& offer = life->revamp.offer;
|
||||
const auto end = offer.ids.begin() + offer.count;
|
||||
if (selection == mutations.end() || selection->life_id != life->identity.life ||
|
||||
selection->event_index != action.input.event_index ||
|
||||
selection->offer_tick != action.input.offer_tick ||
|
||||
selection->operator_id != action.input.operator_id ||
|
||||
selection->become != action.input.become || offer.count == 0 ||
|
||||
offer.event_index != action.input.event_index ||
|
||||
offer.offer_tick != action.input.offer_tick ||
|
||||
life->identity.life != action.input.life_id ||
|
||||
(action.input.operator_id != 0 &&
|
||||
std::ranges::find(offer.ids.begin(), end, action.input.operator_id) == end))
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
continue;
|
||||
}
|
||||
if (!life->mutation.offer || action.input.become)
|
||||
return std::unexpected{CellularActionBlockError::mismatch};
|
||||
const auto offer = life->mutation.offer.value_or(biology::MutationOffer{});
|
||||
if (selection == mutations.end() || selection->life_id != life->identity.life ||
|
||||
|
||||
@@ -1023,6 +1023,11 @@ CellularLives::create(const PrimitiveLives& opening,
|
||||
return std::unique_ptr<CellularLives>{new CellularLives{std::move(state)}};
|
||||
}
|
||||
|
||||
std::expected<biology::Genome, CellularLivesError>
|
||||
cellular_organism_genome(const biology::Genome& genome, std::uint32_t members) {
|
||||
return organism_genome(genome, members);
|
||||
}
|
||||
|
||||
bool cellular_can_emerge(const CellularOwnedLife& life, const CellularRevampRules& rules) noexcept {
|
||||
std::uint64_t mass{};
|
||||
for (std::size_t c = 0; c < life.body.matter.size(); ++c)
|
||||
@@ -1084,6 +1089,9 @@ accounting::Inventory CellularLives::nursery() const noexcept {
|
||||
accounting::Inventory CellularLives::heat() const noexcept {
|
||||
return state_->heat;
|
||||
}
|
||||
accounting::Inventory CellularLives::spent() const noexcept {
|
||||
return state_->spent;
|
||||
}
|
||||
accounting::Inventory CellularLives::opening_total() const noexcept {
|
||||
return state_->opening_total;
|
||||
}
|
||||
@@ -3555,6 +3563,7 @@ CellularLives::advance_tick_with_mutations(std::span<const CellularLifeIntent> i
|
||||
}
|
||||
if (input == ordered.end() || input->life_id != result.life_id)
|
||||
return std::unexpected{CellularLivesError::invalid_intents};
|
||||
feedback.back().exclude = input->intent.exclude;
|
||||
}
|
||||
// ADR-0128: each surviving life reports its presence after the tick; a suspended life,
|
||||
// which took no step, reports its unchanged reserve and any blocked resume.
|
||||
|
||||
@@ -15,7 +15,16 @@ summarize_cellular_play(const CellularLives& state) {
|
||||
summary.lingering += life.presence == CellularPresence::lingering ? 1 : 0;
|
||||
summary.suspended += life.presence == CellularPresence::suspended ? 1 : 0;
|
||||
genomes.push_back(life.identity.genome);
|
||||
if (life.revamp.members > 1) {
|
||||
++summary.organisms;
|
||||
summary.largest_organism =
|
||||
std::max<std::uint64_t>(summary.largest_organism, life.revamp.members);
|
||||
}
|
||||
summary.offers_pending += life.revamp.offer.count != 0 ? 1 : 0;
|
||||
summary.offers_earned += life.revamp.events;
|
||||
}
|
||||
for (const auto& channel : state.spent().matter)
|
||||
summary.spent_matter_fg += channel.value;
|
||||
std::ranges::sort(genomes);
|
||||
const auto distinct = std::ranges::unique(genomes);
|
||||
genomes.erase(distinct.begin(), distinct.end());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "evo/server/lifecycle/wildlife_controller.hpp"
|
||||
|
||||
#include "evo/biology/budding.hpp"
|
||||
#include "evo/biology/cellular_burn.hpp"
|
||||
#include "evo/biology/cellular_motion.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -98,6 +99,22 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
{0, -1'000},
|
||||
{707, -707}}};
|
||||
const auto temperature = state.ambient_temperature_millikelvin();
|
||||
// Rules 13 (ADR-0179): organisms develop as their scaled genome, engulf masses carry
|
||||
// reserve matter, membranes are in nanometres, and reserve matter stands in for energy.
|
||||
const bool revamp = state.rules_version() >= cellular_lives_revamp_rules;
|
||||
const auto& revamp_rules = state.revamp_rules();
|
||||
const auto body_genome =
|
||||
[&](const CellularOwnedLife& life) -> std::expected<biology::Genome, CellularLivesError> {
|
||||
const auto genome = state.archive().find(life.identity.genome);
|
||||
if (!genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
return revamp ? cellular_organism_genome(*genome, life.revamp.members)
|
||||
: std::expected<biology::Genome, CellularLivesError>{*genome};
|
||||
};
|
||||
// A life from before the upgrade keeps its membrane in micrometres.
|
||||
const auto membrane_nm = [](const biology::Genome& genome, std::uint32_t membrane) {
|
||||
return genome.cellular_traits() ? membrane : membrane * 1'000;
|
||||
};
|
||||
std::vector<CellularLifeIntent> intents;
|
||||
// Rules 7 prey facts for every cell in the world, derived once per tick: a per-hunter
|
||||
// derivation made the step quadratic in metabolic budgets.
|
||||
@@ -107,6 +124,7 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
std::uint32_t extent{}, membrane{};
|
||||
std::uint64_t mass{};
|
||||
};
|
||||
std::vector<std::uint64_t> engulf_masses; // Rules 13, beside prey_facts.
|
||||
std::vector<Prey> prey_facts;
|
||||
const bool hunting = state.rules_version() >= cellular_lives_reproduction_rules &&
|
||||
std::ranges::any_of(state.lives(), [](const CellularOwnedLife& life) {
|
||||
@@ -117,35 +135,56 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
for (const auto& other : state.lives()) {
|
||||
if (other.presence == CellularPresence::suspended)
|
||||
continue;
|
||||
const auto other_genome = state.archive().find(other.identity.genome);
|
||||
const auto other_genome = body_genome(other);
|
||||
if (!other_genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
return std::unexpected{other_genome.error()};
|
||||
const auto other_budget = biology::metabolic_budget(
|
||||
*other_genome, other.growth, {temperature, {}}, 1000, state.revamp_rules().body);
|
||||
const auto membrane = other_genome->parameter(biology::Capability::membrane);
|
||||
if (!other_budget || !membrane)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
prey_facts.push_back({other.identity.life, other.position,
|
||||
other_budget->phenotype.extent, *membrane,
|
||||
other_budget->phenotype.extent,
|
||||
revamp ? membrane_nm(*other_genome, *membrane) : *membrane,
|
||||
other_budget->phenotype.total_mass});
|
||||
engulf_masses.push_back(biology::cellular_engulf_mass(
|
||||
other_budget->phenotype.total_mass, other.reserve, revamp_rules.step));
|
||||
}
|
||||
}
|
||||
for (const auto& life : state.lives()) {
|
||||
if (life.account != LifeAccount{})
|
||||
continue;
|
||||
const auto genome = state.archive().find(life.identity.genome);
|
||||
if (!genome)
|
||||
const auto expressed = state.archive().find(life.identity.genome);
|
||||
const auto genome = body_genome(life);
|
||||
if (!expressed || !genome)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
const auto budget = biology::metabolic_budget(*genome, life.growth, {temperature, {}}, 1000,
|
||||
state.revamp_rules().body);
|
||||
if (!budget)
|
||||
return std::unexpected{CellularLivesError::biology};
|
||||
const auto& traits = expressed->cellular_traits();
|
||||
biology::CellularStepIntent intent{};
|
||||
const auto offspring = state.archive().find(cellular_offspring_genome(life));
|
||||
if (!offspring)
|
||||
return std::unexpected{CellularLivesError::archive};
|
||||
if ((tick + life.identity.life) % wildlife_bud_interval_ticks == 0 &&
|
||||
biology::fund_offspring(*genome, *offspring, life.growth, life.reserve, temperature)) {
|
||||
// Rules 13: a single cell buds when it can pay the bud and its fee; an organism adds a
|
||||
// member when it can, and stops one short of the emergence threshold (the owner refuses
|
||||
// what it cannot fund).
|
||||
const auto fee =
|
||||
revamp
|
||||
? cellular_mutation_cost({.cost = revamp_rules.bud_fee,
|
||||
.cost_scale_percent = revamp_rules.bud_fee_scale_percent})
|
||||
: accounting::Inventory{};
|
||||
bool fee_paid = life.reserve.energy.value >= fee.energy.value;
|
||||
for (std::size_t c = 0; c < fee.matter.size(); ++c)
|
||||
fee_paid = fee_paid && life.reserve.matter[c].value >= fee.matter[c].value;
|
||||
const bool organism = revamp && life.revamp.members > 1;
|
||||
const bool may_bud =
|
||||
organism ? fee_paid && life.revamp.members + 1U < revamp_rules.emerge_members
|
||||
: fee_paid && biology::fund_offspring(*expressed, *offspring, life.growth,
|
||||
life.reserve, temperature)
|
||||
.has_value();
|
||||
if ((tick + life.identity.life) % wildlife_bud_interval_ticks == 0 && may_bud) {
|
||||
intent.bud = true;
|
||||
intents.push_back({life.identity.life, intent});
|
||||
continue;
|
||||
@@ -156,12 +195,18 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
// players' cells included; otherwise feed.
|
||||
if (hunting) {
|
||||
bool prey = false;
|
||||
for (const auto& other : prey_facts) {
|
||||
const auto hunter_mass = biology::cellular_engulf_mass(budget->phenotype.total_mass,
|
||||
life.reserve, revamp_rules.step);
|
||||
const auto capacity = traits ? traits->engulf_capacity : std::uint16_t{100};
|
||||
for (std::size_t k = 0; k < prey_facts.size(); ++k) {
|
||||
const auto& other = prey_facts[k];
|
||||
if (other.life == life.identity.life ||
|
||||
!biology::cellular_footprints_contact(life.position, extent, other.position,
|
||||
other.extent))
|
||||
continue;
|
||||
if (can_engulf(budget->phenotype.total_mass, other.mass, other.membrane)) {
|
||||
if (revamp ? biology::cellular_engulfable(hunter_mass, capacity, engulf_masses[k],
|
||||
other.membrane, revamp_rules.step)
|
||||
: can_engulf(budget->phenotype.total_mass, other.mass, other.membrane)) {
|
||||
prey = true;
|
||||
break;
|
||||
}
|
||||
@@ -190,9 +235,21 @@ wildlife_intents(const CellularLives& state, std::uint64_t tick) {
|
||||
// Rules 11: a cell short of energy forages for energy (wildlife_food).
|
||||
const auto demand_period = budget->rate_microseconds / 50'000;
|
||||
const auto demand_per_tick = demand_period == 0 ? 0 : budget->demand.value / demand_period;
|
||||
const bool hungry =
|
||||
state.rules_version() >= cellular_lives_photosynthesis_rules && demand_per_tick != 0 &&
|
||||
life.reserve.energy.value / demand_per_tick < wildlife_energy_hunger_ticks;
|
||||
// Rules 13: burnable reserve matter stands in for energy, so a cell rich in matter is
|
||||
// not hungry.
|
||||
const auto payable =
|
||||
revamp
|
||||
? biology::cellular_payable_energy(
|
||||
life.reserve,
|
||||
biology::cellular_burn(
|
||||
revamp_rules.burn_pj_per_kfg,
|
||||
traits ? traits->burn : std::array<std::uint16_t, 4>{100, 100, 100, 100},
|
||||
0),
|
||||
false)
|
||||
: life.reserve.energy.value;
|
||||
const bool hungry = state.rules_version() >= cellular_lives_photosynthesis_rules &&
|
||||
demand_per_tick != 0 &&
|
||||
payable / demand_per_tick < wildlife_energy_hunger_ticks;
|
||||
const auto chosen = wildlife_food(*perceived, centre_x, centre_y, deposits, hungry);
|
||||
const auto nearest = chosen ? std::optional{chosen->address} : std::nullopt;
|
||||
if (nearest && deposits && chosen) {
|
||||
|
||||
@@ -78,6 +78,10 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
owned_intent->intent.bud = input->bud;
|
||||
// Rules 12: below them the owner refuses a brake, so only v13 sessions send one.
|
||||
owned_intent->intent.brake = input->brake;
|
||||
// Rules 13 (v14): below them the owner refuses each of these.
|
||||
owned_intent->intent.become = input->become;
|
||||
owned_intent->intent.emerge = input->emerge;
|
||||
owned_intent->intent.exclude = input->exclude;
|
||||
CellularActionRecord record;
|
||||
record.account = action.account.bytes;
|
||||
record.action_id = action.action_id;
|
||||
@@ -101,7 +105,10 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
const auto life_id = little_endian(bytes, 8, 8);
|
||||
const auto event_index = little_endian(bytes, 16, 8);
|
||||
const auto offer_tick = little_endian(bytes, 24, 8);
|
||||
const auto operator_id = static_cast<std::uint16_t>(little_endian(bytes, 32, 2));
|
||||
const auto stored_operator = static_cast<std::uint16_t>(little_endian(bytes, 32, 2));
|
||||
const auto operator_id = static_cast<std::uint16_t>(stored_operator & 0x7FFFU);
|
||||
const bool become = (stored_operator & 0x8000U) != 0;
|
||||
const bool revamp = state.rules_version() >= cellular_lives_revamp_rules;
|
||||
// ADR-0121 amendment (schema 59): the reservation's tick is the earliest the choice
|
||||
// may bind at; the queue binds it at the first tick simulated after admission.
|
||||
if (reservation.account == persistence::Uuid{} || reservation.action_id == 0 ||
|
||||
@@ -114,7 +121,17 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
const auto life =
|
||||
std::ranges::find(state.lives(), life_id,
|
||||
[](const CellularOwnedLife& value) { return value.identity.life; });
|
||||
if (life != state.lives().end()) {
|
||||
if ((become && (!revamp || operator_id == 0)))
|
||||
return std::unexpected{CellularSessionBatchError::mutation};
|
||||
if (life != state.lives().end() && revamp) {
|
||||
// Rules 13: the catalog offer the life holds; operator 0 declines it.
|
||||
const auto& offer = life->revamp.offer;
|
||||
const auto end = offer.ids.begin() + offer.count;
|
||||
if (life->account != reservation.account || offer.count == 0 ||
|
||||
offer.event_index != event_index || offer.offer_tick != offer_tick ||
|
||||
(operator_id != 0 && std::ranges::find(offer.ids.begin(), end, operator_id) == end))
|
||||
return std::unexpected{CellularSessionBatchError::mutation};
|
||||
} else if (life != state.lives().end()) {
|
||||
if (life->account != reservation.account || life->mutation.event_index != event_index ||
|
||||
life->mutation.offer_tick != offer_tick)
|
||||
return std::unexpected{CellularSessionBatchError::mutation};
|
||||
@@ -136,12 +153,13 @@ prepare_cellular_session_tick(const CellularLives& state, std::uint64_t tick,
|
||||
previous.action_id == reservation.action_id;
|
||||
}))
|
||||
return std::unexpected{CellularSessionBatchError::duplicate_mutation};
|
||||
prepared.intents.mutations.push_back(
|
||||
{life_id, event_index, offer_tick, reservation.successor_identity, operator_id});
|
||||
prepared.mutation_actions.push_back({reservation.account,
|
||||
reservation.action_id,
|
||||
tick,
|
||||
{life_id, event_index, offer_tick, operator_id}});
|
||||
prepared.intents.mutations.push_back({life_id, event_index, offer_tick,
|
||||
reservation.successor_identity, operator_id, become});
|
||||
prepared.mutation_actions.push_back(
|
||||
{reservation.account,
|
||||
reservation.action_id,
|
||||
tick,
|
||||
{life_id, event_index, offer_tick, operator_id, become}});
|
||||
}
|
||||
std::ranges::sort(prepared.intents.mutations, {}, &CellularMutationSelection::life_id);
|
||||
std::ranges::sort(prepared.mutation_actions, [](const auto& left, const auto& right) {
|
||||
|
||||
@@ -152,12 +152,21 @@ struct RegionSessions::Impl {
|
||||
}
|
||||
// Reliable owner-only v10 messages, to the account's established v10 session.
|
||||
bool send_to_v10_owner(const network::AccountId& account,
|
||||
const network::SessionMessage& message) {
|
||||
const network::SessionMessage& message, bool named_offer = false) {
|
||||
for (const auto& c : connections) {
|
||||
if (c.state != State::established ||
|
||||
!network::cellular_v10_family(c.protocol_version) || c.account_id != account)
|
||||
continue;
|
||||
// Rules 13 offers name catalog mutations (v14); operator offers are v10-v13's.
|
||||
if (std::holds_alternative<network::CellularMutationOffer>(message) &&
|
||||
named_offer != (c.protocol_version == network::session_protocol_v14))
|
||||
return false;
|
||||
auto delivered = message;
|
||||
// An emerged ending reads as unrecorded before v14.
|
||||
if (auto* ended = std::get_if<network::CellularLifeEnded>(&delivered);
|
||||
ended && ended->cause == network::CellularDeathReason::emerged &&
|
||||
c.protocol_version != network::session_protocol_v14)
|
||||
ended->cause = network::CellularDeathReason::unrecorded;
|
||||
// ADR-0176: before v12 an offer cannot name photosynthesis; its other choices
|
||||
// stay valid, so those candidates alone are withheld.
|
||||
if (auto* offer = std::get_if<network::CellularMutationOffer>(&delivered))
|
||||
@@ -628,7 +637,7 @@ struct RegionSessions::Impl {
|
||||
wire_version == network::session_protocol_v9 ||
|
||||
network::cellular_v10_family(wire_version)) &&
|
||||
!cellular_actions) ||
|
||||
wire_version > network::session_protocol_v13)
|
||||
wire_version > network::session_protocol_v14)
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
} else if (wire_version != c.protocol_version) {
|
||||
return close(c, SessionCloseReason::unsupported_version, now);
|
||||
@@ -960,8 +969,17 @@ bool RegionSessions::send_cellular_perception(const network::AccountId& account,
|
||||
if (delivered.diagnostics)
|
||||
delivered.diagnostics->light_pj = 0;
|
||||
}
|
||||
// Only v13 carries liquid motion (rules 12).
|
||||
if (c.protocol_version != network::session_protocol_v13) {
|
||||
// Only v14 carries the rules-13 body block.
|
||||
if (c.protocol_version != network::session_protocol_v14 && delivered.diagnostics) {
|
||||
auto& d = *delivered.diagnostics;
|
||||
d.members = d.emerge_members = 0;
|
||||
d.exclude = 0;
|
||||
d.can_emerge = false;
|
||||
d.payable_energy_pj = d.total_mass_fg = 0;
|
||||
d.traits = {};
|
||||
}
|
||||
// Only v13 and v14 carry liquid motion (rules 12).
|
||||
if (!network::cellular_liquid_version(c.protocol_version)) {
|
||||
delivered.currents.reset();
|
||||
if (delivered.diagnostics) {
|
||||
delivered.diagnostics->velocity_x_q10 = 0;
|
||||
@@ -995,8 +1013,8 @@ bool RegionSessions::send_life_ended(const network::AccountId& account,
|
||||
}
|
||||
|
||||
bool RegionSessions::send_mutation_offer(const network::AccountId& account,
|
||||
const network::CellularMutationOffer& offer) {
|
||||
return impl_->send_to_v10_owner(account, offer);
|
||||
const network::CellularMutationOffer& offer, bool named) {
|
||||
return impl_->send_to_v10_owner(account, offer, named);
|
||||
}
|
||||
|
||||
void RegionSessions::clear_cellular_perceptions(std::uint64_t tick) {
|
||||
|
||||
Reference in New Issue
Block a user