Add furnished houses, roof views, carpentry, and GCC 16 tests
This commit is contained in:
1 parent
85547b00b9
commit
8bb448cc49
21 files changed
+1256
-331
No files matched your search
+244
-55
@@ -1,6 +1,9 @@
|
||||
#include "testing.hpp"
|
||||
|
||||
#include "settlement/core/deterministic_rng.hpp"
|
||||
#include "settlement/core/world.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@@ -30,7 +33,36 @@ std::unique_ptr<settlement::World> save_roundtrip(const settlement::World& world
|
||||
return restored;
|
||||
}
|
||||
|
||||
void test_parallel_pathfinding_completes_the_jobs() {
|
||||
using Void::Testing::Test;
|
||||
|
||||
struct CoreTests : Void::Testing::Suite<CoreTests> {
|
||||
Test test_parallel_pathfinding_completes_the_jobs();
|
||||
Test test_single_worker_configuration_is_rejected();
|
||||
Test test_rng_repeats_for_same_seed();
|
||||
Test test_work_jobs_complete();
|
||||
Test test_astar_route_uses_opening_in_wall();
|
||||
Test test_residents_gather_and_deliver_resources();
|
||||
[[= Void::Testing::tag("construction")]] Test test_production_reservations_and_construction();
|
||||
[[= Void::Testing::tag("construction")]] Test test_cabin_placement_queues_a_complete_order();
|
||||
Test test_hungry_resident_reserves_and_eats_a_berry();
|
||||
Test test_invalid_save_is_rejected();
|
||||
Test test_two_players_share_the_first_colony();
|
||||
Test test_bed_parts_are_delivered_separately();
|
||||
Test test_resident_uses_assigned_bed_and_sleep_survives_save();
|
||||
Test test_fatigue_slows_work_without_interrupting_it();
|
||||
Test test_ground_rest_never_uses_another_residents_bed();
|
||||
Test test_fields_mines_and_reindexing_active_hauls();
|
||||
Test test_specialists_take_their_own_jobs_and_finish_prior_assignments();
|
||||
Test test_flax_and_loom_supply_a_bed_without_starting_cloth();
|
||||
Test test_field_growth_requires_a_worker();
|
||||
Test test_opening_a_mine_invalidates_unreachable_routes();
|
||||
Test test_object_tools_work_in_an_older_demo_world();
|
||||
[[= 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();
|
||||
};
|
||||
|
||||
Test CoreTests::test_parallel_pathfinding_completes_the_jobs() {
|
||||
settlement::World world(123, 48, 48, 6);
|
||||
for (std::int32_t y = 0; y < 48; ++y) {
|
||||
if (y != 31) world.set_blocked({24, y});
|
||||
@@ -42,26 +74,28 @@ void test_parallel_pathfinding_completes_the_jobs() {
|
||||
}
|
||||
for (int tick = 0; tick < 120; ++tick) world.step();
|
||||
require(world.jobs_completed() == 24, "parallel pathfinding did not finish every job");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_single_worker_configuration_is_rejected() {
|
||||
Test CoreTests::test_single_worker_configuration_is_rejected() {
|
||||
try {
|
||||
settlement::World world(8, 8, 8, 1);
|
||||
} catch (const std::invalid_argument&) {
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
throw std::runtime_error("world accepted a single worker");
|
||||
}
|
||||
|
||||
void test_rng_repeats_for_same_seed() {
|
||||
Test CoreTests::test_rng_repeats_for_same_seed() {
|
||||
settlement::DeterministicRng left(12345);
|
||||
settlement::DeterministicRng right(12345);
|
||||
for (int index = 0; index < 1000; ++index) {
|
||||
require(left.next_u64() == right.next_u64(), "RNG diverged for matching seeds");
|
||||
expect_eq(left.next_u64(), right.next_u64());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_work_jobs_complete() {
|
||||
Test CoreTests::test_work_jobs_complete() {
|
||||
settlement::World world(1, 10, 10);
|
||||
const settlement::AgentId agent_id = world.spawn_agent({1, 1});
|
||||
const settlement::JobId job_id = world.add_job({3, 1}, 2);
|
||||
@@ -81,9 +115,10 @@ void test_work_jobs_complete() {
|
||||
"completed job retained an active state");
|
||||
require(world.agents().front().state == settlement::AgentState::Idle,
|
||||
"worker did not return to idle after completing a job");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_astar_route_uses_opening_in_wall() {
|
||||
Test CoreTests::test_astar_route_uses_opening_in_wall() {
|
||||
settlement::World world(2, 10, 10);
|
||||
for (std::int32_t y = 0; y < 10; ++y) {
|
||||
if (y != 8) {
|
||||
@@ -103,9 +138,10 @@ void test_astar_route_uses_opening_in_wall() {
|
||||
}
|
||||
require(world.path_searches() > 0, "path search counter was not updated");
|
||||
require(world.path_nodes_visited() > 0, "A* did not report expanded nodes");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_residents_gather_and_deliver_resources() {
|
||||
Test CoreTests::test_residents_gather_and_deliver_resources() {
|
||||
settlement::World world(51, 16, 16, 4);
|
||||
static_cast<void>(world.add_storage({1, 1}, 10));
|
||||
static_cast<void>(world.spawn_agent({1, 2}));
|
||||
@@ -126,9 +162,10 @@ void test_residents_gather_and_deliver_resources() {
|
||||
"storage retained reservations after deliveries completed");
|
||||
require(world.resource_nodes()[0].quantity == 0 && world.resource_nodes()[1].quantity == 0,
|
||||
"resource nodes retained units after deliveries completed");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_production_reservations_and_construction() {
|
||||
Test CoreTests::test_production_reservations_and_construction() {
|
||||
using settlement::ItemType;
|
||||
using settlement::JobState;
|
||||
using settlement::RecipeId;
|
||||
@@ -207,9 +244,10 @@ void test_production_reservations_and_construction() {
|
||||
require(world.storages()[0].items.empty() && world.storages()[1].items.empty(),
|
||||
"building did not consume the crafted materials from both stores");
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_cabin_placement_queues_a_complete_order() {
|
||||
Test CoreTests::test_cabin_placement_queues_a_complete_order() {
|
||||
using settlement::RecipeId;
|
||||
settlement::World world(1, 10, 10);
|
||||
world.set_blocked({1, 1});
|
||||
@@ -229,9 +267,10 @@ void test_cabin_placement_queues_a_complete_order() {
|
||||
} catch (const std::invalid_argument&) {
|
||||
require(orders.size() == 6, "invalid placement partially queued new orders");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_hungry_resident_reserves_and_eats_a_berry() {
|
||||
Test CoreTests::test_hungry_resident_reserves_and_eats_a_berry() {
|
||||
using settlement::AgentState;
|
||||
using settlement::ItemType;
|
||||
const settlement::GridPosition pantry{1, 1};
|
||||
@@ -278,9 +317,10 @@ void test_hungry_resident_reserves_and_eats_a_berry() {
|
||||
static_cast<void>(world.add_job(pantry, 1));
|
||||
world.step();
|
||||
require(world.jobs_completed() == 2, "the resident did not resume work after eating");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_invalid_save_is_rejected() {
|
||||
Test CoreTests::test_invalid_save_is_rejected() {
|
||||
const settlement::World world(5, 5, 5);
|
||||
auto bytes = save_contents(world);
|
||||
const auto rejected = [](const std::string& save) {
|
||||
@@ -296,9 +336,10 @@ void test_invalid_save_is_rejected() {
|
||||
require(rejected(bytes + 'x'), "save with trailing data was accepted");
|
||||
bytes[8] = 127;
|
||||
require(rejected(bytes), "unknown save version was accepted");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_two_players_share_the_first_colony() {
|
||||
Test CoreTests::test_two_players_share_the_first_colony() {
|
||||
using settlement::CommandKind;
|
||||
using settlement::CommandStatus;
|
||||
auto world = settlement::make_first_colony(2);
|
||||
@@ -341,9 +382,10 @@ void test_two_players_share_the_first_colony() {
|
||||
"the shared colony could not feed its residents and complete the objective");
|
||||
auto replay = save_roundtrip(*world);
|
||||
require(replay->scenario_progress().completed, "completion was lost after loading");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_bed_parts_are_delivered_separately() {
|
||||
Test CoreTests::test_bed_parts_are_delivered_separately() {
|
||||
using namespace settlement;
|
||||
auto world = make_first_colony(2);
|
||||
const GridPosition wood_bed{16, 18};
|
||||
@@ -373,9 +415,10 @@ void test_bed_parts_are_delivered_separately() {
|
||||
"the beds were not completed through three separate deliveries");
|
||||
require(world->storages().back().item_count(ItemType::Cloth) == 8,
|
||||
"two beds must consume four pieces of cloth");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_resident_uses_assigned_bed_and_sleep_survives_save() {
|
||||
Test CoreTests::test_resident_uses_assigned_bed_and_sleep_survives_save() {
|
||||
using namespace settlement;
|
||||
World world(4, 16, 16, 2);
|
||||
const auto owner = world.spawn_agent({1, 2});
|
||||
@@ -423,9 +466,10 @@ void test_resident_uses_assigned_bed_and_sleep_survives_save() {
|
||||
}
|
||||
require(from_route && woke_rested && rested_on_ground, "sleep and recovery phases were not observed");
|
||||
require(world.jobs_completed() == 2, "residents did not finish their existing work");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_fatigue_slows_work_without_interrupting_it() {
|
||||
Test CoreTests::test_fatigue_slows_work_without_interrupting_it() {
|
||||
using namespace settlement;
|
||||
World world(6, 10, 10);
|
||||
static_cast<void>(world.spawn_agent({2, 2}));
|
||||
@@ -438,9 +482,10 @@ void test_fatigue_slows_work_without_interrupting_it() {
|
||||
const auto before = resident.work_remaining;
|
||||
for (int i = 0; i < 6; ++i) world.step();
|
||||
require(before - resident.work_remaining == 2, "hunger and fatigue did not slow the ongoing work");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_ground_rest_never_uses_another_residents_bed() {
|
||||
Test CoreTests::test_ground_rest_never_uses_another_residents_bed() {
|
||||
using namespace settlement;
|
||||
World world(15, 14, 14);
|
||||
const GridPosition cell{7, 6};
|
||||
@@ -479,9 +524,10 @@ void test_ground_rest_never_uses_another_residents_bed() {
|
||||
require(world.assigned_bed(owner)->position == new_cell, "moving a bed lost its owner");
|
||||
require(world.apply_command({1, 3, CommandKind::DemolishObject, new_cell}).status == CommandStatus::Accepted &&
|
||||
world.assigned_bed(owner) == nullptr, "demolishing a bed left a stale assignment");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_fields_mines_and_reindexing_active_hauls() {
|
||||
Test CoreTests::test_fields_mines_and_reindexing_active_hauls() {
|
||||
using namespace settlement;
|
||||
World world(22, 18, 18, 2);
|
||||
const GridPosition rock{9, 5};
|
||||
@@ -532,9 +578,10 @@ void test_fields_mines_and_reindexing_active_hauls() {
|
||||
"growing, regrowing, or mining did not deliver resources");
|
||||
require(apply(CommandKind::PlaceStorage, {11, 7}) == CommandStatus::Accepted,
|
||||
"a new storage could not be placed");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_specialists_take_their_own_jobs_and_finish_prior_assignments() {
|
||||
Test CoreTests::test_specialists_take_their_own_jobs_and_finish_prior_assignments() {
|
||||
using namespace settlement;
|
||||
World world(54, 14, 14, 2);
|
||||
const auto farmer = world.spawn_agent({2, 2});
|
||||
@@ -588,9 +635,10 @@ void test_specialists_take_their_own_jobs_and_finish_prior_assignments() {
|
||||
}
|
||||
require(delivered_stone && later_cut_wood, "the reassigned miner did not finish mining and then cut wood");
|
||||
require(world.scenario_progress().assigned_beds == 1, "the builder did not complete the bed");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
Test CoreTests::test_flax_and_loom_supply_a_bed_without_starting_cloth() {
|
||||
using namespace settlement;
|
||||
World world(92, 12, 12, 3);
|
||||
const auto farmer = world.spawn_agent({2, 3});
|
||||
@@ -648,9 +696,10 @@ void 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");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_field_growth_requires_a_worker() {
|
||||
Test CoreTests::test_field_growth_requires_a_worker() {
|
||||
using namespace settlement;
|
||||
World world(58, 14, 14);
|
||||
const auto resident = world.spawn_agent({2, 2});
|
||||
@@ -677,9 +726,10 @@ void test_field_growth_requires_a_worker() {
|
||||
require(save_contents(world) == save_contents(*restored), "sowing did not resume after loading");
|
||||
}
|
||||
require(world.resource_nodes().front().quantity > 0, "planting without a storage did not grow flax");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_opening_a_mine_invalidates_unreachable_routes() {
|
||||
Test CoreTests::test_opening_a_mine_invalidates_unreachable_routes() {
|
||||
using namespace settlement;
|
||||
World world(44, 8, 8);
|
||||
const auto resident = world.spawn_agent({1, 4});
|
||||
@@ -698,9 +748,10 @@ void test_opening_a_mine_invalidates_unreachable_routes() {
|
||||
world.step();
|
||||
require(world.agents().front().resource_node_index == 0 &&
|
||||
world.agents().front().state == AgentState::Travelling, "terrain edit left a stale route in the cache");
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_object_tools_work_in_an_older_demo_world() {
|
||||
Test CoreTests::test_object_tools_work_in_an_older_demo_world() {
|
||||
using namespace settlement;
|
||||
World legacy(12, 12, 12);
|
||||
static_cast<void>(legacy.spawn_agent({4, 4}));
|
||||
@@ -719,9 +770,10 @@ void test_object_tools_work_in_an_older_demo_world() {
|
||||
require(edit(CommandKind::DemolishObject, {4, 5}) == CommandStatus::Accepted,
|
||||
"a field in a demonstration could not be demolished");
|
||||
static_cast<void>(save_roundtrip(*world));
|
||||
return {};
|
||||
}
|
||||
|
||||
void test_room_builds_and_saves_as_separate_parts() {
|
||||
Test CoreTests::test_room_builds_and_saves_as_separate_parts() {
|
||||
using namespace settlement;
|
||||
World world(61, 16, 16);
|
||||
static_cast<void>(world.spawn_agent({3, 3}));
|
||||
@@ -761,39 +813,176 @@ void test_room_builds_and_saves_as_separate_parts() {
|
||||
resumed->production_orders().size() == 16 && resumed->can_place_storage(floor),
|
||||
"demolition removed the floor instead of the furniture");
|
||||
static_cast<void>(save_roundtrip(*resumed));
|
||||
return {};
|
||||
}
|
||||
|
||||
Test CoreTests::test_furnished_rooms_queue_and_build_their_contents() {
|
||||
using namespace settlement;
|
||||
using enum RecipeId;
|
||||
const std::pair<RoomTemplate, RecipeId> variants[] = {{RoomTemplate::Doctor, BuildMedicineCabinet},
|
||||
{RoomTemplate::Miner, BuildMiningRack}, {RoomTemplate::Weaver, BuildLoom}};
|
||||
for (const auto& [layout, fixture] : variants) {
|
||||
World world(62, 16, 16);
|
||||
static_cast<void>(world.spawn_agent({3, 3}));
|
||||
const auto carpenter = world.spawn_agent({4, 3});
|
||||
const auto storage = world.add_storage({3, 2}, 48);
|
||||
world.stock_storage(storage, ItemType::Wood, 32);
|
||||
world.stock_storage(storage, ItemType::Stone, 3);
|
||||
world.stock_storage(storage, ItemType::Cloth, 2);
|
||||
world.stock_storage(storage, ItemType::Flax, 1);
|
||||
world.start_scenario({2, 3});
|
||||
require(world.apply_command({1, world.next_command_sequence(1), CommandKind::AssignProfession,
|
||||
{}, static_cast<std::uint8_t>(Profession::Carpenter), {}, carpenter}).status == CommandStatus::Accepted,
|
||||
"could not assign a carpenter for the furnished room");
|
||||
RoomPlan plan{{6, 5}, {9, 8}, RoomSide::East, layout};
|
||||
for (const auto side : {RoomSide::North, RoomSide::East, RoomSide::South, RoomSide::West}) {
|
||||
plan.entrance = side;
|
||||
const auto decoded = RoomPlan::from_placement(plan.first, plan.last, plan.placement_value());
|
||||
const auto parts = decoded.furnishings();
|
||||
require(decoded.entrance == side && decoded.layout == layout && parts.has_value(),
|
||||
"room command lost the direction or furnishings");
|
||||
require((*parts)[0].recipe == BuildBed && (*parts)[1].recipe == fixture &&
|
||||
(*parts)[0].position != (*parts)[1].position &&
|
||||
plan.recipe_at((*parts)[0].position) == BuildFloor &&
|
||||
plan.recipe_at((*parts)[1].position) == BuildFloor,
|
||||
"the furnishings must occupy two distinct interior cells");
|
||||
}
|
||||
const auto parts = *plan.furnishings();
|
||||
const auto place = [&](std::uint8_t player, std::uint8_t value) {
|
||||
return world.apply_command({player, world.next_command_sequence(player), CommandKind::PlaceRoom,
|
||||
plan.first, value, plan.last}).status;
|
||||
};
|
||||
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");
|
||||
require(place(1, plan.placement_value()) == CommandStatus::InvalidTarget &&
|
||||
world.production_orders().size() == 19, "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) {
|
||||
return order.position == cell && order.recipe == BuildFloor && order.state == JobState::Completed;
|
||||
});
|
||||
};
|
||||
world.step();
|
||||
auto resumed = save_roundtrip(world);
|
||||
for (int tick = 0; tick < 850; ++tick) {
|
||||
resumed->step();
|
||||
for (std::size_t i = 0; i < parts.size(); ++i) {
|
||||
const auto& order = resumed->production_orders()[i];
|
||||
if (order.state != JobState::Available || order.recipe == WeaveCloth) {
|
||||
require(floor_is_done(*resumed, parts[i].position), "a furnishing started before its floor");
|
||||
}
|
||||
}
|
||||
}
|
||||
const auto& bed = resumed->production_orders()[0];
|
||||
const auto& furniture = resumed->production_orders()[1];
|
||||
require(bed.recipe == BuildBed && bed.position == parts[0].position && bed.state == JobState::Completed &&
|
||||
bed.bed_owner != 0 && bed.bed_base == (layout == RoomTemplate::Miner ? BedBase::Stone : BedBase::Wood),
|
||||
"the room's bed did not become usable");
|
||||
require(furniture.position == parts[1].position, "the furnishing moved during construction");
|
||||
if (fixture == BuildLoom) {
|
||||
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,
|
||||
"the themed furnishing did not finish");
|
||||
}
|
||||
static_cast<void>(save_roundtrip(*resumed));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Test CoreTests::test_carpenter_delivers_the_door_before_installation() {
|
||||
using namespace settlement;
|
||||
auto world = std::make_unique<World>(63, 16, 16);
|
||||
const auto builder = world->spawn_agent({5, 3});
|
||||
const auto carpenter = world->spawn_agent({3, 3});
|
||||
const auto first_storage = world->add_storage({2, 3}, 9);
|
||||
const auto second_storage = world->add_storage({3, 4}, 20);
|
||||
world->stock_storage(first_storage, ItemType::Wood, 9);
|
||||
world->stock_storage(second_storage, ItemType::Wood, 20);
|
||||
constexpr GridPosition workshop{4, 3};
|
||||
world->start_scenario(workshop);
|
||||
const auto assign = [&](AgentId resident, Profession role) {
|
||||
return world->apply_command({1, world->next_command_sequence(1), CommandKind::AssignProfession,
|
||||
{}, static_cast<std::uint8_t>(role), {}, resident}).status;
|
||||
};
|
||||
const auto place = [&](const RoomPlan& plan) {
|
||||
return world->apply_command({1, world->next_command_sequence(1), CommandKind::PlaceRoom,
|
||||
plan.first, plan.placement_value(), plan.last}).status;
|
||||
};
|
||||
const auto order = [&](RecipeId recipe) -> const ProductionOrder& {
|
||||
const auto& orders = world->production_orders();
|
||||
const auto found = std::find_if(orders.begin(), orders.end(),
|
||||
[recipe](const auto& entry) { return entry.recipe == recipe; });
|
||||
require(found != orders.end(), "expected production order was missing");
|
||||
return *found;
|
||||
};
|
||||
const auto crafted_orders = [&] {
|
||||
return std::count_if(world->production_orders().begin(), world->production_orders().end(),
|
||||
[](const auto& entry) { return entry.recipe == RecipeId::CraftWoodenDoor; });
|
||||
};
|
||||
require(assign(builder, Profession::Builder) == CommandStatus::Accepted &&
|
||||
place({{6, 5}, {8, 7}, RoomSide::South}) == CommandStatus::Accepted,
|
||||
"could not place the room");
|
||||
for (int tick = 0; tick < 400; ++tick) world->step();
|
||||
require(order(RecipeId::CraftWoodenDoor).state == JobState::Available &&
|
||||
order(RecipeId::InstallDoorAlongX).state == JobState::Available &&
|
||||
world->storages()[0].item_count(ItemType::Wood) == 1,
|
||||
"a builder or generalist bypassed the carpenter or failed to build the shell");
|
||||
require(assign(carpenter, Profession::Carpenter) == CommandStatus::Accepted, "could not promote the carpenter");
|
||||
|
||||
bool fetched_wood = false, crafted_at_bench = false, delivered_door = false, installed_from_cargo = false;
|
||||
for (int tick = 0; tick < 400 && order(RecipeId::InstallDoorAlongX).state != JobState::Completed; ++tick) {
|
||||
world->step();
|
||||
const auto& resident = world->agents()[1];
|
||||
if (!fetched_wood && resident.inventory.item_count(ItemType::Wood) == 1) {
|
||||
fetched_wood = true;
|
||||
require(world->storages()[0].reserved_slots == 1, "no space reserved for the product");
|
||||
world = save_roundtrip(*world);
|
||||
continue;
|
||||
}
|
||||
if (!crafted_at_bench && order(RecipeId::CraftWoodenDoor).state == JobState::InProgress &&
|
||||
resident.state == AgentState::Working && resident.position == workshop) {
|
||||
crafted_at_bench = true;
|
||||
world = save_roundtrip(*world);
|
||||
continue;
|
||||
}
|
||||
if (!delivered_door && resident.inventory.item_count(ItemType::WoodenDoor) == 1) {
|
||||
delivered_door = true;
|
||||
require(resident.state == AgentState::Hauling && resident.storage_index == 0 &&
|
||||
world->storages()[0].item_count(ItemType::WoodenDoor) == 0,
|
||||
"the finished door appeared on the store before being delivered");
|
||||
world = save_roundtrip(*world);
|
||||
continue;
|
||||
}
|
||||
if (!installed_from_cargo && world->agents()[0].inventory.item_count(ItemType::WoodenDoor) == 1) {
|
||||
installed_from_cargo = true;
|
||||
world = save_roundtrip(*world);
|
||||
}
|
||||
}
|
||||
require(fetched_wood && crafted_at_bench && delivered_door && installed_from_cargo &&
|
||||
order(RecipeId::InstallDoorAlongX).state == JobState::Completed && crafted_orders() == 1 &&
|
||||
world->storages()[0].reserved_slots == 0 && world->storages()[1].item_count(ItemType::Wood) == 19,
|
||||
"the complete carpenter and builder workflow did not run");
|
||||
|
||||
require(world->apply_command({1, world->next_command_sequence(1), CommandKind::CraftDoor}).status ==
|
||||
CommandStatus::Accepted, "an independent door order was rejected");
|
||||
for (int tick = 0; tick < 300 && world->storages()[1].item_count(ItemType::WoodenDoor) == 0; ++tick) world->step();
|
||||
require(world->storages()[1].item_count(ItemType::WoodenDoor) == 1 && crafted_orders() == 2,
|
||||
"the independent order did not produce a spare door");
|
||||
require(place({{10, 5}, {12, 7}, RoomSide::South}) == CommandStatus::Accepted && crafted_orders() == 2,
|
||||
"a new room did not use the spare door");
|
||||
require(world->apply_command({1, world->next_command_sequence(1), CommandKind::DemolishObject,
|
||||
world->storages()[1].position}).status == CommandStatus::Accepted && crafted_orders() == 3,
|
||||
"losing the stock did not queue a replacement for the waiting room");
|
||||
static_cast<void>(save_roundtrip(*world));
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
try {
|
||||
test_rng_repeats_for_same_seed();
|
||||
test_work_jobs_complete();
|
||||
test_astar_route_uses_opening_in_wall();
|
||||
test_parallel_pathfinding_completes_the_jobs();
|
||||
test_single_worker_configuration_is_rejected();
|
||||
test_residents_gather_and_deliver_resources();
|
||||
test_production_reservations_and_construction();
|
||||
test_cabin_placement_queues_a_complete_order();
|
||||
test_hungry_resident_reserves_and_eats_a_berry();
|
||||
test_invalid_save_is_rejected();
|
||||
test_two_players_share_the_first_colony();
|
||||
test_bed_parts_are_delivered_separately();
|
||||
test_resident_uses_assigned_bed_and_sleep_survives_save();
|
||||
test_fatigue_slows_work_without_interrupting_it();
|
||||
test_ground_rest_never_uses_another_residents_bed();
|
||||
test_fields_mines_and_reindexing_active_hauls();
|
||||
test_specialists_take_their_own_jobs_and_finish_prior_assignments();
|
||||
test_flax_and_loom_supply_a_bed_without_starting_cloth();
|
||||
test_field_growth_requires_a_worker();
|
||||
test_opening_a_mine_invalidates_unreachable_routes();
|
||||
test_object_tools_work_in_an_older_demo_world();
|
||||
test_room_builds_and_saves_as_separate_parts();
|
||||
} catch (const std::exception& error) {
|
||||
std::cerr << "Test failed: " << error.what() << '\n';
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "All core checks passed.\n";
|
||||
return 0;
|
||||
int main(int argc, char** argv) {
|
||||
return CoreTests::run(argc, argv);
|
||||
}
|
||||
Reference in new issue
Block a user