feat(ecology): make photosynthesis regions playable on DEV
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s
Foundation / checks (ecs) (push) Successful in 2m19s
Foundation / checks (deploy) (push) Successful in 4m47s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (checks) (push) Canceled after 16m48s
Foundation / checks (network) (push) Canceled after 16m46s
Foundation / checks (postgres) (push) Canceled after 16m47s
Foundation / checks (client) (push) Canceled after 16m53s
Foundation / checks (tsan) (push) Canceled after 14m33s
ADR-0176 and schema 57 admit raw cellular bundle 13 (rules 11 on owner format 9) through parser-local normalization to bundle 12, and a fenced no-tick 12 -> 13 upgrade that declares the region's light; recovery reads the light from the target and re-derives the whole target from the source. The resumable cellular-v8 opening provisions a cellular-v7 genesis, one empty tick and the durable upgrades to bundle 13. Session v12 adds the owner's captured light and the producers it can see to its perception, and lets offers name photosynthesis; older sessions keep their layouts and never receive photosynthesis candidates. The client draws chloroplasts by efficiency, shows sunlight in the HUD and offers photosynthesis cards. DEV now provisions and serves region 9 with the trial light; region 8 stays stored but unserved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -27,6 +27,11 @@ constexpr std::size_t cellular_perception_v9_prefix_bytes =
|
||||
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;
|
||||
// v12 (ADR-0176) appends the captured light, the producer count and 6 reserved bytes.
|
||||
constexpr std::size_t cellular_perception_v12_prefix_bytes =
|
||||
cellular_perception_v10_prefix_bytes + 8 + 2 + 6;
|
||||
// v12: organism, photosynthesis per thousand and 6 reserved bytes.
|
||||
constexpr std::size_t cellular_perceived_producer_bytes = 8 + 2 + 6;
|
||||
constexpr std::size_t cellular_perceived_patch_bytes = 8 + 8 + (4 * 8);
|
||||
// v11: id, centre, radius, shape, drained flag and five 16-bit amount codes.
|
||||
constexpr std::size_t cellular_perceived_deposit_bytes = 4 + 4 + 4 + 2 + 1 + 1 + (5 * 2);
|
||||
@@ -48,15 +53,17 @@ constexpr std::size_t life_receipt_bytes = 17;
|
||||
constexpr std::size_t life_outcome_bytes = 25;
|
||||
constexpr std::size_t life_query_bytes = 8;
|
||||
|
||||
// Seven capabilities and four effects (biology genome/mutation enums, frozen on the wire).
|
||||
bool valid_offer(const CellularMutationOffer& offer) {
|
||||
// Seven capabilities (eight from v12) and four effects (biology genome/mutation enums,
|
||||
// frozen on the wire per version).
|
||||
bool valid_offer(const CellularMutationOffer& offer, std::uint16_t version) {
|
||||
if (offer.tick == 0 || offer.candidates.size() > max_cellular_offered_candidates)
|
||||
return false;
|
||||
if (offer.candidates.empty())
|
||||
return offer.event_index == 0 && offer.offer_tick == 0;
|
||||
std::uint16_t previous = 0;
|
||||
for (const auto& candidate : offer.candidates) {
|
||||
if (candidate.operator_id <= previous || candidate.capability > 6 || candidate.effect > 3)
|
||||
if (candidate.operator_id <= previous ||
|
||||
candidate.capability > cellular_offer_capability_limit(version) || candidate.effect > 3)
|
||||
return false;
|
||||
previous = candidate.operator_id;
|
||||
}
|
||||
@@ -195,7 +202,7 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
if (!cellular_v10_family(version) && std::holds_alternative<CellularMutationAction>(message))
|
||||
return {};
|
||||
if (const auto* offer = std::get_if<CellularMutationOffer>(&message);
|
||||
offer && (!cellular_v10_family(version) || !valid_offer(*offer)))
|
||||
offer && (!cellular_v10_family(version) || !valid_offer(*offer, version)))
|
||||
return {};
|
||||
if (const auto* ended = std::get_if<CellularLifeEnded>(&message);
|
||||
ended && (!cellular_v10_family(version) || ended->tick == 0 || ended->life_identity == 0 ||
|
||||
@@ -220,9 +227,24 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
!cellular_v10_family(version) && std::holds_alternative<CellularPerception>(message))
|
||||
return {};
|
||||
if (const auto* perception = std::get_if<CellularPerception>(&message)) {
|
||||
// v12 alone carries captured light and producers (ADR-0176).
|
||||
const bool producers = version == session_protocol_v12;
|
||||
if ((!producers && (!perception->producers.empty() ||
|
||||
(perception->diagnostics && perception->diagnostics->light_pj))) ||
|
||||
perception->producers.size() > max_cellular_perceived_producers ||
|
||||
(!perception->life_identity && !perception->producers.empty()) ||
|
||||
std::ranges::adjacent_find(perception->producers,
|
||||
[](const auto& a, const auto& b) {
|
||||
return a.organism >= b.organism;
|
||||
}) != perception->producers.end() ||
|
||||
std::ranges::any_of(perception->producers, [](const auto& p) {
|
||||
return p.organism == 0 || p.photosynthesis_per_thousand == 0 ||
|
||||
p.photosynthesis_per_thousand > 1000;
|
||||
}))
|
||||
return {};
|
||||
// v11 (ADR-0136) lists deposits by ascending id, never patches; earlier versions the
|
||||
// reverse.
|
||||
if (version == session_protocol_v11
|
||||
if (cellular_deposit_version(version)
|
||||
? !perception->patches.empty() ||
|
||||
perception->deposits.size() > max_cellular_perceived_deposits ||
|
||||
(!perception->life_identity && !perception->deposits.empty()) ||
|
||||
@@ -364,15 +386,17 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
std::vector<std::uint8_t> operator()(const CellularPerception& m) const {
|
||||
auto out =
|
||||
header(SessionMessageType::cellular_perception,
|
||||
(cellular_v10_family(version) ? cellular_perception_v10_prefix_bytes
|
||||
(version == session_protocol_v12 ? cellular_perception_v12_prefix_bytes
|
||||
: cellular_v10_family(version) ? 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 +
|
||||
m.deposits.size() * cellular_perceived_deposit_bytes,
|
||||
m.deposits.size() * cellular_perceived_deposit_bytes +
|
||||
m.producers.size() * cellular_perceived_producer_bytes,
|
||||
version);
|
||||
put(out, m.tick, 8);
|
||||
put(out, m.life_identity, 8);
|
||||
put(out, version == session_protocol_v11 ? m.deposits.size() : m.patches.size(), 2);
|
||||
put(out, cellular_deposit_version(version) ? m.deposits.size() : m.patches.size(), 2);
|
||||
if (version == session_protocol_v9 || cellular_v10_family(version)) {
|
||||
const auto& d = m.diagnostics;
|
||||
put(out, d ? d->reserve_energy_pj : 0, 8);
|
||||
@@ -393,6 +417,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
for (const auto value :
|
||||
d ? d->bud_cost_matter_fg : std::array<std::uint64_t, 4>{})
|
||||
put(out, value, 8);
|
||||
if (version == session_protocol_v12) {
|
||||
put(out, d ? d->light_pj : 0, 8);
|
||||
put(out, m.producers.size(), 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
} else {
|
||||
put(out, 0, 5);
|
||||
}
|
||||
@@ -414,6 +443,11 @@ std::vector<std::uint8_t> encode_session(const SessionMessage& message, std::uin
|
||||
for (const auto code : deposit.amount_codes)
|
||||
put(out, code, 2);
|
||||
}
|
||||
for (const auto& producer : m.producers) {
|
||||
put(out, producer.organism, 8);
|
||||
put(out, producer.photosynthesis_per_thousand, 2);
|
||||
put(out, 0, 6);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
std::vector<std::uint8_t> operator()(const IntentionReceipt& m) const {
|
||||
@@ -727,7 +761,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
candidate.cost_matter_fg[channel] = get(payload, at + 32 + channel * 8, 8);
|
||||
m.candidates.push_back(candidate);
|
||||
}
|
||||
if (!valid_offer(m))
|
||||
if (!valid_offer(m, wire_version))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
return m;
|
||||
}
|
||||
@@ -744,17 +778,29 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
const bool without_bud_cost = wire_version == session_protocol_v10 &&
|
||||
payload.size() == cellular_perception_v9_prefix_bytes +
|
||||
count * cellular_perceived_patch_bytes;
|
||||
const auto prefix = cellular_v10_family(wire_version) && !without_bud_cost
|
||||
const bool lit = wire_version == session_protocol_v12;
|
||||
const auto prefix = lit ? cellular_perception_v12_prefix_bytes
|
||||
: cellular_v10_family(wire_version) && !without_bud_cost
|
||||
? cellular_perception_v10_prefix_bytes
|
||||
: wire_version == session_protocol_v9 || without_bud_cost
|
||||
? cellular_perception_v9_prefix_bytes
|
||||
: cellular_perception_prefix_bytes;
|
||||
const bool deposits = wire_version == session_protocol_v11;
|
||||
const bool deposits = cellular_deposit_version(wire_version);
|
||||
const auto entry =
|
||||
deposits ? cellular_perceived_deposit_bytes : cellular_perceived_patch_bytes;
|
||||
const auto producer_count = lit && payload.size() >= prefix
|
||||
? static_cast<std::size_t>(get(
|
||||
payload, cellular_perception_v10_prefix_bytes + 8, 2))
|
||||
: 0;
|
||||
if (count > (deposits ? max_cellular_perceived_deposits : max_cellular_perceived_patches) ||
|
||||
payload.size() != prefix + count * entry)
|
||||
producer_count > max_cellular_perceived_producers ||
|
||||
payload.size() !=
|
||||
prefix + count * entry + producer_count * cellular_perceived_producer_bytes)
|
||||
return std::unexpected(SessionCodecError::wrong_length);
|
||||
if (lit &&
|
||||
std::ranges::any_of(payload.subspan(cellular_perception_v10_prefix_bytes + 10, 6),
|
||||
[](std::uint8_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
CellularPerception m;
|
||||
m.tick = get(payload, 0, 8);
|
||||
m.life_identity = get(payload, 8, 8);
|
||||
@@ -785,6 +831,8 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
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);
|
||||
}
|
||||
if (lit)
|
||||
d.light_pj = get(payload, cellular_perception_v10_prefix_bytes, 8);
|
||||
}
|
||||
d.movement = static_cast<CellularMovementResult>(payload[74]);
|
||||
d.intake = static_cast<CellularIntakeResult>(payload[75]);
|
||||
@@ -799,6 +847,7 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
d.intake != CellularIntakeResult::not_reported ||
|
||||
d.engulf != CellularEngulfResult::not_reported ||
|
||||
d.bud != CellularBudOutcome::not_reported || d.bud_cost_energy_pj ||
|
||||
d.light_pj ||
|
||||
std::ranges::any_of(d.bud_cost_matter_fg,
|
||||
[](std::uint64_t value) { return value != 0; }))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
@@ -831,6 +880,23 @@ std::expected<SessionMessage, SessionCodecError> decode_session(std::span<const
|
||||
static_cast<std::uint16_t>(get(payload, offset + 16 + c * 2, 2));
|
||||
m.deposits.push_back(d);
|
||||
}
|
||||
if (!m.life_identity && producer_count)
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.producers.reserve(producer_count);
|
||||
for (std::size_t i = 0; i < producer_count;
|
||||
++i, offset += cellular_perceived_producer_bytes) {
|
||||
CellularPerceivedProducer p;
|
||||
p.organism = get(payload, offset, 8);
|
||||
p.photosynthesis_per_thousand =
|
||||
static_cast<std::uint16_t>(get(payload, offset + 8, 2));
|
||||
if (p.organism == 0 || p.photosynthesis_per_thousand == 0 ||
|
||||
p.photosynthesis_per_thousand > 1000 ||
|
||||
std::ranges::any_of(payload.subspan(offset + 10, 6),
|
||||
[](std::uint8_t value) { return value != 0; }) ||
|
||||
(!m.producers.empty() && m.producers.back().organism >= p.organism))
|
||||
return std::unexpected(SessionCodecError::invalid_value);
|
||||
m.producers.push_back(p);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
m.patches.reserve(count);
|
||||
|
||||
Reference in New Issue
Block a user