Show what a bud costs (ADR-0129 amendment)
Foundation / checks (ecs) (push) Successful in 2m20s
Foundation / checks (deploy) (push) Successful in 4m4s
Foundation / checks (tsan) (push) Successful in 9m59s
Foundation / checks (client) (push) Successful in 19m19s
Foundation / checks (network) (push) Successful in 19m24s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 32m13s
Foundation / checks (checks) (push) Canceled after 32m19s

The v10 cellular perception carries the bud cost after the diagnostics block: the
energy (construction plus the bud's provision) and matter per channel one bud takes
from a fully grown cell's reserve. biology::bud_cost reads it from fund_bud itself,
so the shown cost is exactly the charge; the server caches it per genome. The
client shows it and names the channels the reserve is short on. v10 clients must
be rebuilt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-15 19:11:28 -04:00
co-authored by Claude Opus 5.5
parent a97f0c3fea
commit d98d71e7c0
13 changed files with 225 additions and 13 deletions
+30 -12
View File
@@ -23,6 +23,10 @@ constexpr std::size_t cellular_perception_prefix_bytes = 8 + 8 + 2;
constexpr std::size_t cellular_diagnostics_bytes = 64;
constexpr std::size_t cellular_perception_v9_prefix_bytes =
cellular_perception_prefix_bytes + cellular_diagnostics_bytes;
// v10 appends the bud cost (energy and four matter channels, ADR-0129 amendment).
constexpr std::size_t cellular_bud_cost_bytes = std::size_t{5} * 8;
constexpr std::size_t cellular_perception_v10_prefix_bytes =
cellular_perception_v9_prefix_bytes + cellular_bud_cost_bytes;
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
constexpr std::size_t intention_receipt_bytes = 8 + 1 + 8;
constexpr std::size_t simulated_bytes = std::size_t{3} * 8;
@@ -195,11 +199,15 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
ended && (version != session_protocol_v10 || ended->tick == 0 ||
ended->life_identity == 0 || ended->cause > CellularDeathReason::engulfed))
return {};
// v9 has no room for engulf and bud effects; only v10 reports them (ADR-0129).
// v9 has no room for engulf and bud effects or the bud cost; only v10 reports them
// (ADR-0129).
if (const auto* perception = std::get_if<CellularPerception>(&message);
perception && version != session_protocol_v10 && perception->diagnostics &&
(perception->diagnostics->engulf != CellularEngulfResult::not_reported ||
perception->diagnostics->bud != CellularBudOutcome::not_reported))
perception->diagnostics->bud != CellularBudOutcome::not_reported ||
perception->diagnostics->bud_cost_energy_pj != 0 ||
std::ranges::any_of(perception->diagnostics->bud_cost_matter_fg,
[](std::uint64_t value) { return value != 0; })))
return {};
if (const auto* action = std::get_if<CellularAction>(&message);
action && (action->engulf || action->bud) &&
@@ -334,12 +342,13 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
return out;
}
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
auto out = header(SessionMessageType::cellular_perception,
(version == session_protocol_v9 || version == session_protocol_v10
? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
m.patches.size() * cellular_perceived_patch_bytes,
version);
auto out =
header(SessionMessageType::cellular_perception,
(version == session_protocol_v10 ? cellular_perception_v10_prefix_bytes
: version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes) +
m.patches.size() * cellular_perceived_patch_bytes,
version);
put(out, m.tick, 8);
put(out, m.life_identity, 8);
put(out, m.patches.size(), 2);
@@ -359,6 +368,10 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
out.push_back(d ? static_cast<std::uint8_t>(d->engulf) : 0);
out.push_back(d ? static_cast<std::uint8_t>(d->bud) : 0);
put(out, 0, 3);
put(out, d ? d->bud_cost_energy_pj : 0, 8);
for (const auto value :
d ? d->bud_cost_matter_fg : std::array<std::uint64_t, 4>{})
put(out, value, 8);
} else {
put(out, 0, 5);
}
@@ -692,9 +705,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
wire_version != session_protocol_v10)
return std::unexpected(SessionCodecError::unsupported_version);
const auto prefix =
wire_version == session_protocol_v9 || wire_version == session_protocol_v10
? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes;
wire_version == session_protocol_v10 ? cellular_perception_v10_prefix_bytes
: wire_version == session_protocol_v9 ? cellular_perception_v9_prefix_bytes
: cellular_perception_prefix_bytes;
if (payload.size() < prefix)
return std::unexpected(SessionCodecError::wrong_length);
const auto count = static_cast<std::size_t>(get(payload, 16, 2));
@@ -726,6 +739,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
if (wire_version == session_protocol_v10) {
d.engulf = static_cast<CellularEngulfResult>(payload[77]);
d.bud = static_cast<CellularBudOutcome>(payload[78]);
d.bud_cost_energy_pj = get(payload, 82, 8);
for (std::size_t channel = 0; channel < d.bud_cost_matter_fg.size(); ++channel)
d.bud_cost_matter_fg[channel] = get(payload, 90 + channel * 8, 8);
}
d.movement = static_cast<CellularMovementResult>(payload[74]);
d.intake = static_cast<CellularIntakeResult>(payload[75]);
@@ -739,7 +755,9 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
d.movement != CellularMovementResult::not_reported ||
d.intake != CellularIntakeResult::not_reported ||
d.engulf != CellularEngulfResult::not_reported ||
d.bud != CellularBudOutcome::not_reported)
d.bud != CellularBudOutcome::not_reported || d.bud_cost_energy_pj ||
std::ranges::any_of(d.bud_cost_matter_fg,
[](std::uint64_t value) { return value != 0; }))
return std::unexpected(SessionCodecError::invalid_value);
}
if ((wire_version == session_protocol_v9 || wire_version == session_protocol_v10) &&