Apply furniture and standalone loom crafting to the Windows game
This commit is contained in:
1 parent
1ef2977081
commit
803433bc94
9 files changed
+345
-74
No files matched your search
+135
-6
@@ -60,6 +60,7 @@ struct CoreTests : Void::Testing::Suite<CoreTests> {
|
||||
[[= Void::Testing::tag("construction")]] Test test_room_builds_and_saves_as_separate_parts();
|
||||
[[= Void::Testing::tag("construction")]] Test test_furnished_rooms_queue_and_build_their_contents();
|
||||
[[= Void::Testing::tag("construction")]] Test test_carpenter_delivers_the_door_before_installation();
|
||||
[[= Void::Testing::tag("construction")]] Test test_carpenter_makes_furnishings_for_rooms();
|
||||
};
|
||||
|
||||
Test CoreTests::test_parallel_pathfinding_completes_the_jobs() {
|
||||
@@ -643,10 +644,12 @@ Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
World world(92, 12, 12, 3);
|
||||
const auto farmer = world.spawn_agent({2, 3});
|
||||
const auto builder = world.spawn_agent({4, 4});
|
||||
const auto carpenter = world.spawn_agent({5, 2});
|
||||
const auto materials = world.add_storage({3, 3}, 30);
|
||||
const auto pantry = world.add_storage({3, 4}, 12, StorageKind::Pantry);
|
||||
world.stock_storage(pantry, ItemType::Berries, 12);
|
||||
world.stock_storage(materials, ItemType::Stone, 1);
|
||||
world.stock_storage(materials, ItemType::Wood, 2);
|
||||
world.start_scenario({4, 2});
|
||||
const auto send = [&](CommandKind kind, GridPosition cell = {}, std::uint8_t value = 0,
|
||||
GridPosition destination = {}, AgentId resident = 0) {
|
||||
@@ -665,13 +668,24 @@ Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
send(CommandKind::MoveObject, loom, 0, moved_loom) == CommandStatus::Accepted &&
|
||||
send(CommandKind::PlaceBed, {5, 4}, static_cast<std::uint8_t>(BedBase::Stone)) == CommandStatus::Accepted,
|
||||
"a textile object collided with a field or could not be placed or moved");
|
||||
require(world.production_orders().front().recipe == RecipeId::InstallLoom &&
|
||||
world.production_orders().front().position == moved_loom &&
|
||||
world.production_orders()[1].recipe == RecipeId::CraftLoom,
|
||||
"placing or moving the loom bypassed or duplicated its craft order");
|
||||
require(world.resource_nodes().front().needs_tending(), "flax started growing before being planted");
|
||||
for (int i = 0; i < 24; ++i) world.step();
|
||||
require(world.production_orders().front().state == JobState::Available &&
|
||||
world.production_orders()[1].state == JobState::Available &&
|
||||
world.storages().front().available_item_count(ItemType::Wood) == 2,
|
||||
"the loom was installed or crafted without a carpenter");
|
||||
require(send(CommandKind::AssignProfession, {}, static_cast<std::uint8_t>(Profession::Carpenter), {}, carpenter) ==
|
||||
CommandStatus::Accepted, "could not assign a carpenter for the loom");
|
||||
auto restored = save_roundtrip(world);
|
||||
bool saved_flax_in_transit = false;
|
||||
bool saved_active_weaving = false;
|
||||
int sowings = 0;
|
||||
std::uint64_t last_growth = 0;
|
||||
for (int i = 0; i < 360; ++i) {
|
||||
for (int i = 0; i < 500; ++i) {
|
||||
world.step();
|
||||
restored->step();
|
||||
require(save_contents(world) == save_contents(*restored), "textile work diverged after loading");
|
||||
@@ -680,8 +694,8 @@ Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
restored = save_roundtrip(world);
|
||||
saved_flax_in_transit = true;
|
||||
}
|
||||
if (!saved_active_weaving && loom_order.state == JobState::InProgress) {
|
||||
require(world.agents().back().production_index == 0 &&
|
||||
if (!saved_active_weaving && loom_order.recipe == RecipeId::WeaveCloth && loom_order.state == JobState::InProgress) {
|
||||
require(world.agents()[1].production_index == 0 &&
|
||||
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);
|
||||
@@ -696,6 +710,9 @@ Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
require(world.scenario_progress().assigned_beds == 1 &&
|
||||
world.storages().front().item_count(ItemType::Cloth) > 0,
|
||||
"the loom did not make enough cloth to finish and replenish a bed order");
|
||||
require(world.storages().front().item_count(ItemType::Wood) == 0 &&
|
||||
world.storages().front().item_count(ItemType::Loom) == 0,
|
||||
"the installed loom did not consume the materials and finished item exactly once");
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -855,9 +872,9 @@ Test CoreTests::test_furnished_rooms_queue_and_build_their_contents() {
|
||||
require(place(2, 255) == CommandStatus::InvalidTarget && world.production_orders().empty(),
|
||||
"an unknown layout partially queued a room");
|
||||
require(place(2, plan.placement_value()) == CommandStatus::Accepted &&
|
||||
world.production_orders().size() == 19, "the furnished room did not queue construction and the door");
|
||||
world.production_orders().size() == 20, "the furnished room did not queue construction and carpentry");
|
||||
require(place(1, plan.placement_value()) == CommandStatus::InvalidTarget &&
|
||||
world.production_orders().size() == 19, "an overlapping furnished room left duplicate orders");
|
||||
world.production_orders().size() == 20, "an overlapping furnished room left duplicate orders");
|
||||
const auto floor_is_done = [&](const World& state, GridPosition cell) {
|
||||
return std::any_of(state.production_orders().begin(), state.production_orders().end(),
|
||||
[cell](const auto& order) {
|
||||
@@ -885,7 +902,7 @@ Test CoreTests::test_furnished_rooms_queue_and_build_their_contents() {
|
||||
require(furniture.recipe == WeaveCloth && resumed->storages().front().item_count(ItemType::Cloth) == 1,
|
||||
"the built loom did not process flax");
|
||||
} else {
|
||||
require(furniture.recipe == fixture && furniture.state == JobState::Completed,
|
||||
require(furnishing_shape(furniture.recipe) == fixture && furniture.state == JobState::Completed,
|
||||
"the themed furnishing did not finish");
|
||||
}
|
||||
static_cast<void>(save_roundtrip(*resumed));
|
||||
@@ -981,6 +998,118 @@ Test CoreTests::test_carpenter_delivers_the_door_before_installation() {
|
||||
return {};
|
||||
}
|
||||
|
||||
Test CoreTests::test_carpenter_makes_furnishings_for_rooms() {
|
||||
using namespace settlement;
|
||||
struct Variant {
|
||||
RoomTemplate layout;
|
||||
ItemType item;
|
||||
RecipeId craft;
|
||||
RecipeId installation;
|
||||
};
|
||||
const Variant variants[] = {
|
||||
{RoomTemplate::Doctor, ItemType::MedicineCabinet, RecipeId::CraftMedicineCabinet, RecipeId::InstallMedicineCabinet},
|
||||
{RoomTemplate::Miner, ItemType::MiningRack, RecipeId::CraftMiningRack, RecipeId::InstallMiningRack},
|
||||
{RoomTemplate::Weaver, ItemType::Loom, RecipeId::CraftLoom, RecipeId::InstallLoom},
|
||||
};
|
||||
for (const auto& variant : variants) {
|
||||
auto world = std::make_unique<World>(64, 20, 18);
|
||||
const auto builder = world->spawn_agent({5, 3});
|
||||
const auto carpenter = world->spawn_agent({3, 3});
|
||||
// Stone is at the first delivery stop, but the product returns to the wood store.
|
||||
const auto stone = world->add_storage({2, 3}, 6);
|
||||
const auto wood = world->add_storage({3, 4}, 48);
|
||||
world->stock_storage(stone, ItemType::Stone, 4);
|
||||
world->stock_storage(wood, ItemType::Wood, 38);
|
||||
world->stock_storage(wood, ItemType::Cloth, 2);
|
||||
world->stock_storage(wood, ItemType::Flax, 1);
|
||||
const GridPosition workshop{4, 3};
|
||||
world->start_scenario(workshop);
|
||||
auto send = [&](CommandKind kind, GridPosition cell = {}, std::uint8_t value = 0,
|
||||
GridPosition target = {}, AgentId resident = 0) {
|
||||
return world->apply_command({1, world->next_command_sequence(1), kind, cell, value, target, resident}).status;
|
||||
};
|
||||
const RoomPlan plan{{6, 5}, {9, 8}, RoomSide::East, variant.layout};
|
||||
require(send(CommandKind::AssignProfession, {}, static_cast<std::uint8_t>(Profession::Builder), {}, builder) ==
|
||||
CommandStatus::Accepted &&
|
||||
send(CommandKind::PlaceRoom, plan.first, plan.placement_value(), plan.last) == CommandStatus::Accepted,
|
||||
"could not place the furnished room");
|
||||
const auto count_orders = [&](RecipeId recipe) {
|
||||
return std::count_if(world->production_orders().begin(), world->production_orders().end(),
|
||||
[recipe](const auto& order) { return order.recipe == recipe; });
|
||||
};
|
||||
require(count_orders(variant.craft) == 1 && count_orders(variant.installation) == 1,
|
||||
"the blueprint did not request its furnishing");
|
||||
for (int tick = 0; tick < 180; ++tick) world->step();
|
||||
require(std::all_of(world->production_orders().begin(), world->production_orders().end(),
|
||||
[&](const auto& order) {
|
||||
return (order.recipe != variant.craft && order.recipe != variant.installation) ||
|
||||
order.state == JobState::Available;
|
||||
}), "a generalist or builder bypassed the carpenter");
|
||||
require(send(CommandKind::AssignProfession, {}, static_cast<std::uint8_t>(Profession::Carpenter), {}, carpenter) ==
|
||||
CommandStatus::Accepted, "could not assign the carpenter");
|
||||
|
||||
bool saved_stone_stop = false, saved_workshop = false, saved_delivery = false, saved_installation = false;
|
||||
const auto fixture = plan.furnishings()->back().position;
|
||||
for (int tick = 0; tick < 900; ++tick) {
|
||||
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.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;
|
||||
world = save_roundtrip(*world);
|
||||
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) {
|
||||
require(world->storages()[1].reserved_slots == 1, "output space was not reserved while crafting");
|
||||
saved_workshop = true;
|
||||
world = save_roundtrip(*world);
|
||||
continue;
|
||||
}
|
||||
if (!saved_delivery && maker.inventory.item_count(variant.item) != 0) {
|
||||
require(maker.state == AgentState::Hauling && world->storages()[1].item_count(variant.item) == 0,
|
||||
"the furnishing appeared in stock before delivery");
|
||||
saved_delivery = true;
|
||||
world = save_roundtrip(*world);
|
||||
continue;
|
||||
}
|
||||
if (!saved_installation && world->agents()[0].inventory.item_count(variant.item) != 0) {
|
||||
saved_installation = true;
|
||||
world = save_roundtrip(*world);
|
||||
}
|
||||
}
|
||||
require(saved_workshop && saved_delivery && saved_installation &&
|
||||
(variant.item != ItemType::MiningRack || saved_stone_stop),
|
||||
"the furnishing did not survive every stage of crafting and delivery");
|
||||
const auto active_recipe = variant.item == ItemType::Loom ? RecipeId::WeaveCloth : variant.installation;
|
||||
require(std::any_of(world->production_orders().begin(), world->production_orders().end(),
|
||||
[&](const auto& order) {
|
||||
return order.position == fixture && order.recipe == active_recipe &&
|
||||
(active_recipe == RecipeId::WeaveCloth || order.state == JobState::Completed);
|
||||
}), "the stored furnishing was not installed");
|
||||
if (variant.item == ItemType::Loom) {
|
||||
require(world->storages()[1].item_count(ItemType::Cloth) == 1, "the installed loom did not weave");
|
||||
}
|
||||
|
||||
const auto existing_work = world->production_orders().size();
|
||||
require(send(CommandKind::CraftFurniture, {}, static_cast<std::uint8_t>(ItemType::Wood)) == CommandStatus::InvalidTarget &&
|
||||
world->production_orders().size() == existing_work, "an invalid craft queued an order");
|
||||
require(send(CommandKind::CraftFurniture, {}, static_cast<std::uint8_t>(variant.item)) == CommandStatus::Accepted,
|
||||
"could not order a spare furnishing");
|
||||
for (int tick = 0; tick < 450 && world->storages()[1].available_item_count(variant.item) == 0; ++tick) world->step();
|
||||
require(world->storages()[1].available_item_count(variant.item) == 1, "the manual order yielded no spare");
|
||||
const RoomPlan second{{11, 5}, {14, 8}, RoomSide::East, variant.layout};
|
||||
require(send(CommandKind::PlaceRoom, second.first, second.placement_value(), second.last) == CommandStatus::Accepted &&
|
||||
count_orders(variant.craft) == 2, "a room ignored the matching furnishing already in stock");
|
||||
static_cast<void>(save_roundtrip(*world));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Reference in new issue
Block a user