Validate work phases and retain exact refusal and consumption receipts

This commit is contained in:
faumaray committed 2026-12-02 23:19:05 +03:00
1 parent 539cea0608
commit 9e20f99a66
3 files changed
+203 -15

No files matched your search

+23 -6
View File
@@ -1544,9 +1544,13 @@ void World::finish_meal_step(Agent& agent) {
auto& sink = item_balances_[static_cast<std::size_t>(ItemType::Berries) - 1].meal;
const auto amount = Void::Numeric::checked_add(sink, std::uint64_t{1});
const auto meals = Void::Numeric::checked_add(meals_eaten_, std::uint64_t{1});
auto receipt = prepare_custody(agent, CustodyOperation::Eat,
amount && meals ? CustodyStatus::Accepted : CustodyStatus::Overflow);
auto receipt = std::const_pointer_cast<CustodyReceipt>(prepare_custody(agent, CustodyOperation::Eat,
amount && meals ? CustodyStatus::Accepted : CustodyStatus::Overflow));
if (!receipt) return;
receipt->result.terminal = amount && meals;
receipt->result.effects[0] = {{OwnerKind::Resident, agent.id}, agent.inventory.stack_id(ItemType::Berries), ItemType::Berries,
amount && meals ? 0U : 1U};
receipt->result.effect_count = 1;
commit_custody(agent, receipt);
if (!amount || !meals) return;
sink = *amount;
@@ -1690,11 +1694,23 @@ void World::finish_production(Agent& agent) {
if (!receipt) return;
if (status == CustodyStatus::Accepted) {
receipt->result.terminal = !carpentry;
for (const auto& material : order.materials) {
const auto& original_store = storage_by_id(material.storage_id);
StackId consumed_id = 0;
std::uint32_t remaining = 0;
StockOwner owner{OwnerKind::Production, order.id};
if (delivered) { consumed_id = order.input.stack_id(material.type); remaining = input.item_count(material.type); }
else {
owner = {OwnerKind::Storage, material.storage_id};
for (const auto& stack : original_store.items) if (stack.type == material.type) consumed_id = stack.id;
for (const auto& store : stores) if (store.id == material.storage_id) remaining = store.item_count(material.type);
}
receipt->result.effects[receipt->result.effect_count++] = {owner, consumed_id, material.type, remaining};
}
if (output_id) {
receipt->result.effects[0] = {carpentry ? StockOwner{OwnerKind::Resident, agent.id} :
receipt->result.effects[receipt->result.effect_count++] = {carpentry ? StockOwner{OwnerKind::Resident, agent.id} :
StockOwner{OwnerKind::Storage, stores.front().id}, output_id, recipe.output,
carpentry ? inventory.item_count(recipe.output) : stores.front().item_count(recipe.output)};
receipt->result.effect_count = 1;
}
}
commit_custody(agent, receipt);
@@ -1867,8 +1883,9 @@ void World::step(TickProfile* profile) {
ResourceNode& node = resource_node_by_id(agent.resource_node_id);
if (agent.storage_id == 0) {
const auto growth = Void::Numeric::checked_add(tick_, growing_time(node.site));
auto receipt = prepare_custody(agent, CustodyOperation::Tend, growth ? CustodyStatus::Accepted : CustodyStatus::Overflow);
auto receipt = std::const_pointer_cast<CustodyReceipt>(prepare_custody(agent, CustodyOperation::Tend, growth ? CustodyStatus::Accepted : CustodyStatus::Overflow, node.id));
if (!receipt) continue;
receipt->result.terminal = growth.has_value();
commit_custody(agent, receipt);
if (!growth) continue;
node.growth_at = *growth;
@@ -1884,7 +1901,7 @@ void World::step(TickProfile* profile) {
const auto amount = Void::Numeric::checked_add(balance, std::uint64_t{1});
const auto next = Void::Numeric::checked_add(next_stack_id_, std::uint64_t{1});
auto receipt = std::const_pointer_cast<CustodyReceipt>(prepare_custody(agent, CustodyOperation::Harvest,
!next ? CustodyStatus::Exhausted : !amount ? CustodyStatus::Overflow : CustodyStatus::Accepted));
!next ? CustodyStatus::Exhausted : !amount ? CustodyStatus::Overflow : CustodyStatus::Accepted, node.id));
if (!receipt) continue;
if (next && amount) {
receipt->result.effects[0] = {{OwnerKind::Resident, agent.id}, next_stack_id_, node.type, 1};