Preserve production order identities and preflight whole placement batches

This commit is contained in:
faumaray committed 2026-12-02 22:30:07 +03:00
1 parent 4ba64f7e62
commit 2a3ec924de
16 files changed
+661 -88

No files matched your search

+14 -13
View File
@@ -242,7 +242,7 @@ Test CoreTests::test_production_reservations_and_construction() {
world.storages()[1].item_count(ItemType::StoneBlock) == 2,
"materials left a store before the builder reached it");
for (const auto& agent : world.agents()) {
if (agent.production_index != 0) continue;
if (agent.production_id != orders[0].id) continue;
require(agent.inventory.item_count(ItemType::Plank) == 3 &&
agent.inventory.item_count(ItemType::StoneBlock) == 0,
"the builder's bag does not match the first pickup");
@@ -253,14 +253,14 @@ Test CoreTests::test_production_reservations_and_construction() {
require(world.storages()[1].item_count(ItemType::StoneBlock) == 0,
"the builder did not pick up the second shipment");
for (const auto& agent : world.agents()) {
if (agent.production_index != 0) continue;
if (agent.production_id != orders[0].id) continue;
require(agent.inventory.item_count(ItemType::Plank) == 3 &&
agent.inventory.item_count(ItemType::StoneBlock) == 2,
"the builder's bag does not match the complete haul");
}
}
for (const auto& agent : world.agents()) {
if (agent.production_index != 0 || agent.state != settlement::AgentState::Working) continue;
if (agent.production_id != orders[0].id || agent.state != settlement::AgentState::Working) continue;
require(agent.position == orders[0].position && orders[0].delivery_stops.empty(),
"construction started before the builder reached the site with its materials");
require(agent.inventory.empty(), "the builder retained the cargo after unloading");
@@ -483,15 +483,16 @@ Test CoreTests::test_bed_parts_are_delivered_separately() {
for (int tick = 0; tick < 250 && world->scenario_progress().assigned_beds < 2; ++tick) {
world->step();
for (const auto& agent : world->agents()) {
if (agent.production_index == no_entity_index || agent.state != AgentState::Hauling) continue;
const auto& order = world->production_orders()[agent.production_index];
if (agent.production_id == 0 || agent.state != AgentState::Hauling) continue;
const auto& order = *world->find_production(agent.production_id);
const auto order_index = static_cast<std::size_t>(&order - world->production_orders().data());
const auto expected = order.bed_stage == BedStage::Foundation
? (order.position == wood_bed ? ItemType::Wood : ItemType::Stone) : ItemType::Cloth;
require(agent.inventory.item_count(expected) == 1,
"the resident did not carry the raw material required by this stage");
const auto bit = 1U << static_cast<unsigned>(order.bed_stage);
if ((seen[agent.production_index] & bit) == 0) {
seen[agent.production_index] |= bit;
if ((seen[order_index] & bit) == 0) {
seen[order_index] |= bit;
auto copy = save_roundtrip(*world);
copy->step();
}
@@ -696,7 +697,7 @@ Test CoreTests::test_specialists_take_their_own_jobs_and_finish_prior_assignment
for (std::size_t index = 0; index < 3; ++index) {
require(world.agents()[index].resource_node_id == world.resource_nodes()[index].id, "a specialist chose the wrong resource");
}
require(world.agents()[3].production_index == 0 && world.agents()[3].resource_node_id == 0,
require(world.agents()[3].production_id == world.production_orders().front().id && world.agents()[3].resource_node_id == 0,
"the builder did not take the construction job");
require(assign(miner, Profession::Woodcutter) == CommandStatus::Accepted &&
world.agents()[2].resource_node_id == world.resource_nodes()[2].id,
@@ -774,7 +775,7 @@ Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
saved_flax_in_transit = true;
}
if (!saved_active_weaving && loom_order.recipe == RecipeId::WeaveCloth && loom_order.state == JobState::InProgress) {
require(world.agents()[1].production_index == 0 &&
require(world.agents()[1].production_id == world.production_orders().front().id &&
world.object_status(moved_loom, true) == CommandStatus::Busy,
"the loom was assigned to the wrong worker or could move while active");
restored = save_roundtrip(world);
@@ -1126,8 +1127,8 @@ Test CoreTests::test_carpenter_makes_furnishings_for_rooms() {
world->step();
const auto& maker = world->agents()[1];
if (variant.item == ItemType::MiningRack && !saved_stone_stop &&
maker.production_index != no_entity_index &&
world->production_orders()[maker.production_index].recipe == variant.craft &&
maker.production_id != 0 &&
world->find_production(maker.production_id)->recipe == variant.craft &&
maker.inventory.item_count(ItemType::Stone) != 0 && maker.inventory.item_count(ItemType::Wood) == 0) {
require(world->storages()[1].reserved_slots == 0, "output space was reserved before collecting wood");
saved_stone_stop = true;
@@ -1135,8 +1136,8 @@ Test CoreTests::test_carpenter_makes_furnishings_for_rooms() {
continue;
}
if (!saved_workshop && maker.state == AgentState::Working && maker.position == workshop &&
maker.production_index != no_entity_index &&
world->production_orders()[maker.production_index].recipe == variant.craft) {
maker.production_id != 0 &&
world->find_production(maker.production_id)->recipe == variant.craft) {
require(world->storages()[1].reserved_slots == 1, "output space was not reserved while crafting");
saved_workshop = true;
world = save_roundtrip(*world);