Transfer reserved meal and construction pickups as one checked operation

This commit is contained in:
faumaray committed 2026-12-02 22:45:22 +03:00
1 parent a8cd7bb415
commit 3c997ed236
7 files changed
+595 -11

No files matched your search

+12 -11
View File
@@ -1,4 +1,5 @@
#include "settlement/core/world.hpp"
#include "settlement/core/inventory_transaction.hpp"
#include <Void/Core/Scope.hpp>
#include <Void/Math/Numeric.hpp>
@@ -1511,8 +1512,10 @@ void World::assign_meals() {
void World::finish_meal_step(Agent& agent) {
if (agent.state == AgentState::GoingToEat) {
if (agent.route_cursor != agent.route.size()) return;
take_reserved_material(storage_by_id(agent.storage_id), {agent.storage_id, ItemType::Berries, 1});
agent.inventory.add(ItemType::Berries);
const std::array meal{MaterialReservation{agent.storage_id, ItemType::Berries, 1}};
if (!withdraw_reserved_materials(storage_by_id(agent.storage_id), agent.inventory, meal)) {
throw std::logic_error("invalid reserved meal pickup");
}
agent.storage_id = 0;
agent.route.clear();
agent.route_cursor = 0;
@@ -1593,16 +1596,14 @@ void World::advance_construction_delivery(Agent& agent) {
return;
}
auto& stop = order.delivery_stops[order.collected_stops];
for (const auto& material : order.materials) {
if (material.storage_id == stop.storage_id) {
take_reserved_material(storage_by_id(stop.storage_id), material);
agent.inventory.add(material.type, material.count);
}
if (order.collected_stops > order.delivery_stops.size() || order.materials.empty()) {
throw std::logic_error("invalid construction pickup stop");
}
if (is_carpentry_recipe(order.recipe) && stop.storage_id == order.materials.front().storage_id) {
// Collecting the first ingredient frees a slot for the finished item.
++storage_by_id(stop.storage_id).reserved_slots;
auto& stop = order.delivery_stops[order.collected_stops];
const bool reserve_output = is_carpentry_recipe(order.recipe) &&
stop.storage_id == order.materials.front().storage_id;
if (!withdraw_reserved_materials(storage_by_id(stop.storage_id), agent.inventory, order.materials, reserve_output)) {
throw std::logic_error("invalid reserved construction pickup");
}
++order.collected_stops;
agent.route = std::move(stop.route_to_next);