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
+149
-19
@@ -69,6 +69,12 @@ const Recipe& recipe_for(RecipeId id) {
|
||||
static constexpr Recipe floor{{ItemStack{ItemType::Wood, 1}, {}}, ItemType::None, 6};
|
||||
static constexpr Recipe wall{{ItemStack{ItemType::Wood, 1}, {}}, ItemType::None, 9};
|
||||
static constexpr Recipe door{{ItemStack{ItemType::Wood, 2}, {}}, ItemType::None, 12};
|
||||
static constexpr Recipe cabinet{{ItemStack{ItemType::Wood, 1}, {}}, ItemType::None, 10};
|
||||
static constexpr Recipe mining_rack{{ItemStack{ItemType::Wood, 1}, ItemStack{ItemType::Stone, 1}},
|
||||
ItemType::None, 10};
|
||||
static constexpr Recipe loom{{ItemStack{ItemType::Wood, 2}, {}}, ItemType::None, 12};
|
||||
static constexpr Recipe install_door{{ItemStack{ItemType::WoodenDoor, 1}, {}}, ItemType::None, 8};
|
||||
static constexpr Recipe craft_door{{ItemStack{ItemType::Wood, 2}, {}}, ItemType::WoodenDoor, 14};
|
||||
switch (id) {
|
||||
case RecipeId::SawPlank: return saw;
|
||||
case RecipeId::CutStoneBlock: return cut;
|
||||
@@ -79,6 +85,12 @@ const Recipe& recipe_for(RecipeId id) {
|
||||
case RecipeId::BuildWall: return wall;
|
||||
case RecipeId::BuildDoorAlongX:
|
||||
case RecipeId::BuildDoorAlongY: return door;
|
||||
case RecipeId::BuildMedicineCabinet: return cabinet;
|
||||
case RecipeId::BuildMiningRack: return mining_rack;
|
||||
case RecipeId::BuildLoom: return loom;
|
||||
case RecipeId::InstallDoorAlongX:
|
||||
case RecipeId::InstallDoorAlongY: return install_door;
|
||||
case RecipeId::CraftWoodenDoor: return craft_door;
|
||||
}
|
||||
throw std::invalid_argument("unknown production recipe");
|
||||
}
|
||||
@@ -143,7 +155,9 @@ RoomPlan make_room_plan(GridPosition first, GridPosition last) noexcept {
|
||||
bool RoomPlan::valid_size() const noexcept {
|
||||
const auto width = static_cast<std::int64_t>(last.x) - first.x + 1;
|
||||
const auto height = static_cast<std::int64_t>(last.y) - first.y + 1;
|
||||
return width >= 3 && width <= 12 && height >= 3 && height <= 12 && entrance <= RoomSide::West;
|
||||
if (entrance > RoomSide::West || layout > RoomTemplate::Weaver) return false;
|
||||
if (layout == RoomTemplate::Empty) return width >= 3 && width <= 12 && height >= 3 && height <= 12;
|
||||
return width == furnished_room_size && height == furnished_room_size;
|
||||
}
|
||||
|
||||
bool RoomPlan::contains(GridPosition cell) const noexcept {
|
||||
@@ -167,6 +181,29 @@ RecipeId RoomPlan::recipe_at(GridPosition cell) const noexcept {
|
||||
return RecipeId::BuildFloor;
|
||||
}
|
||||
|
||||
std::optional<std::array<RoomFurnishing, 2>> RoomPlan::furnishings() const noexcept {
|
||||
if (layout == RoomTemplate::Empty || !valid_size()) return std::nullopt;
|
||||
// Keep the entry aisle clear by placing both pieces against the back wall.
|
||||
const GridPosition bed_offsets[] = {{1, 2}, {1, 1}, {1, 1}, {2, 1}};
|
||||
const GridPosition fixture_offsets[] = {{2, 2}, {1, 2}, {2, 1}, {2, 2}};
|
||||
const RecipeId fixtures[] = {RecipeId::BuildMedicineCabinet, RecipeId::BuildMiningRack, RecipeId::BuildLoom};
|
||||
const auto side = static_cast<std::size_t>(entrance);
|
||||
const auto bed = bed_offsets[side];
|
||||
const auto fixture = fixture_offsets[side];
|
||||
return std::array{RoomFurnishing{{first.x + bed.x, first.y + bed.y}, RecipeId::BuildBed,
|
||||
layout == RoomTemplate::Miner ? BedBase::Stone : BedBase::Wood},
|
||||
RoomFurnishing{{first.x + fixture.x, first.y + fixture.y},
|
||||
fixtures[static_cast<std::size_t>(layout) - 1]}};
|
||||
}
|
||||
|
||||
std::uint8_t RoomPlan::placement_value() const noexcept {
|
||||
return static_cast<std::uint8_t>((static_cast<unsigned>(layout) << 2) | static_cast<unsigned>(entrance));
|
||||
}
|
||||
|
||||
RoomPlan RoomPlan::from_placement(GridPosition first, GridPosition last, std::uint8_t value) noexcept {
|
||||
return {first, last, static_cast<RoomSide>(value & 3U), static_cast<RoomTemplate>(value >> 2)};
|
||||
}
|
||||
|
||||
std::uint32_t Inventory::item_count(ItemType type) const noexcept {
|
||||
const auto index = static_cast<std::size_t>(type);
|
||||
return index != 0 && index <= counts_.size() ? counts_[index - 1] : 0;
|
||||
@@ -263,8 +300,14 @@ void World::set_blocked(GridPosition position, bool blocked) {
|
||||
}
|
||||
}
|
||||
for (const Agent& agent : agents_) {
|
||||
if (agent.production_index != no_entity_index &&
|
||||
production_orders_[agent.production_index].recipe == RecipeId::CraftWoodenDoor &&
|
||||
std::find(agent.haul_route.begin(), agent.haul_route.end(), position) != agent.haul_route.end()) {
|
||||
throw std::logic_error("cannot block the carpenter's delivery route");
|
||||
}
|
||||
if (agent.production_index == no_entity_index &&
|
||||
agent.state != AgentState::GoingToEat && agent.state != AgentState::GoingToSleep) continue;
|
||||
agent.state != AgentState::GoingToEat && agent.state != AgentState::GoingToSleep &&
|
||||
agent.inventory.item_count(ItemType::WoodenDoor) == 0) continue;
|
||||
const auto remaining = agent.route.begin() + static_cast<std::ptrdiff_t>(agent.route_cursor);
|
||||
if (std::find(remaining, agent.route.end(), position) != agent.route.end()) {
|
||||
throw std::logic_error("cannot block an active production, meal, or sleep route");
|
||||
@@ -357,6 +400,9 @@ void World::queue_production(GridPosition position, RecipeId recipe) {
|
||||
if (!is_walkable(position)) {
|
||||
throw std::invalid_argument("production site must be on a walkable cell");
|
||||
}
|
||||
if (recipe == RecipeId::CraftWoodenDoor && carpenter_workshop() != position) {
|
||||
throw std::invalid_argument("wooden doors need the carpenter's workshop");
|
||||
}
|
||||
if (is_production_object(recipe) && !can_place_storage(position)) {
|
||||
throw std::invalid_argument("the production site is occupied");
|
||||
}
|
||||
@@ -382,7 +428,8 @@ bool World::can_place_cabin(GridPosition position) const noexcept {
|
||||
}
|
||||
|
||||
bool World::can_place_room(const RoomPlan& plan) const noexcept {
|
||||
if (!plan.valid_size() || !is_walkable(plan.first) || !is_walkable(plan.last)) return false;
|
||||
if (!plan.valid_size() || (plan.layout != RoomTemplate::Empty && !scenario_active_) ||
|
||||
!is_walkable(plan.first) || !is_walkable(plan.last)) return false;
|
||||
const int middle_x = std::midpoint(plan.first.x, plan.last.x);
|
||||
const int middle_y = std::midpoint(plan.first.y, plan.last.y);
|
||||
const GridPosition exits[] = {{middle_x, plan.first.y - 1}, {plan.last.x + 1, middle_y},
|
||||
@@ -413,6 +460,35 @@ std::array<ItemStack, 2> World::construction_materials(RecipeId recipe, BedBase
|
||||
return is_construction(recipe) ? recipe_for(recipe).ingredients : std::array<ItemStack, 2>{};
|
||||
}
|
||||
|
||||
RecipeId World::room_construction_recipe(RecipeId part) const noexcept {
|
||||
if (scenario_active_) {
|
||||
if (part == RecipeId::BuildDoorAlongX) return RecipeId::InstallDoorAlongX;
|
||||
if (part == RecipeId::BuildDoorAlongY) return RecipeId::InstallDoorAlongY;
|
||||
}
|
||||
return part;
|
||||
}
|
||||
|
||||
std::size_t World::missing_door_orders(std::size_t new_installations) const {
|
||||
std::uint64_t waiting_installations = new_installations, supply = 0;
|
||||
for (const auto& order : production_orders_) {
|
||||
if (order.recipe == RecipeId::CraftWoodenDoor && order.state != JobState::Completed) ++supply;
|
||||
if (order.state == JobState::Available &&
|
||||
(order.recipe == RecipeId::InstallDoorAlongX || order.recipe == RecipeId::InstallDoorAlongY)) {
|
||||
++waiting_installations;
|
||||
}
|
||||
}
|
||||
for (const auto& agent : agents_) {
|
||||
if (agent.state == AgentState::Hauling && agent.production_index == no_entity_index) {
|
||||
supply += agent.inventory.item_count(ItemType::WoodenDoor);
|
||||
}
|
||||
}
|
||||
for (const auto& storage : storages_) {
|
||||
const auto available = storage.available_item_count(ItemType::WoodenDoor);
|
||||
if (available != 0 && find_path(scenario_sawmill_, storage.position).reachable) supply += available;
|
||||
}
|
||||
return waiting_installations > supply ? static_cast<std::size_t>(waiting_installations - supply) : 0;
|
||||
}
|
||||
|
||||
void World::queue_cabin(GridPosition position, GridPosition sawmill, GridPosition stonecutter) {
|
||||
if (!can_place_cabin(position) || position == sawmill || position == stonecutter ||
|
||||
(scenario_active_ && position == scenario_sawmill_)) {
|
||||
@@ -485,7 +561,7 @@ CommandStatus World::object_status(GridPosition position, bool moving) const noe
|
||||
for (const auto& order : production_orders_) {
|
||||
if (order.position != position || !is_production_object(order.recipe)) continue;
|
||||
if (is_finished_floor(order)) continue;
|
||||
if (moving && order.recipe >= RecipeId::BuildFloor) return CommandStatus::InvalidTarget;
|
||||
if (moving && is_room_part(order.recipe)) return CommandStatus::InvalidTarget;
|
||||
return order.state == JobState::InProgress || resting_at(position) ? busy : ready;
|
||||
}
|
||||
for (std::size_t i = 0; i < storages_.size(); ++i) {
|
||||
@@ -537,6 +613,7 @@ CommandStatus World::edit_object(GridPosition position, const GridPosition* dest
|
||||
if (storage != storages_.end()) {
|
||||
if (destination) storage->position = *destination;
|
||||
else {
|
||||
const bool loses_doors = storage->item_count(ItemType::WoodenDoor) != 0;
|
||||
const auto removed = static_cast<std::size_t>(storage - storages_.begin());
|
||||
storages_.erase(storage);
|
||||
for (auto& agent : agents_) shift_index(agent.storage_index, removed);
|
||||
@@ -544,6 +621,10 @@ CommandStatus World::edit_object(GridPosition position, const GridPosition* dest
|
||||
for (auto& material : entry.materials) shift_index(material.storage_index, removed);
|
||||
for (auto& stop : entry.delivery_stops) shift_index(stop.storage_index, removed);
|
||||
}
|
||||
if (scenario_active_ && loses_doors) {
|
||||
const auto missing = missing_door_orders();
|
||||
for (std::size_t i = 0; i < missing; ++i) queue_production(scenario_sawmill_, RecipeId::CraftWoodenDoor);
|
||||
}
|
||||
}
|
||||
return CommandStatus::Accepted;
|
||||
}
|
||||
@@ -661,23 +742,42 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
|
||||
}
|
||||
queue_production(command.cell, RecipeId::WeaveCloth);
|
||||
break;
|
||||
case CommandKind::CraftDoor:
|
||||
queue_production(scenario_sawmill_, RecipeId::CraftWoodenDoor);
|
||||
break;
|
||||
case CommandKind::PlaceRoom: {
|
||||
const RoomPlan plan{command.cell, command.destination, static_cast<RoomSide>(command.value)};
|
||||
const auto plan = RoomPlan::from_placement(command.cell, command.destination, command.value);
|
||||
if (!can_place_room(plan) || !can_reach_object_cell(plan.first)) {
|
||||
return receipt(CommandStatus::InvalidTarget);
|
||||
}
|
||||
const auto width = static_cast<std::size_t>(plan.last.x - plan.first.x + 1);
|
||||
const auto height = static_cast<std::size_t>(plan.last.y - plan.first.y + 1);
|
||||
production_orders_.reserve(production_orders_.size() + width * height);
|
||||
const auto furnishings = plan.furnishings();
|
||||
const bool legacy_bed = furnishings.has_value() && !staged_beds_;
|
||||
const auto door_orders = scenario_active_ ? missing_door_orders(1) : 0;
|
||||
production_orders_.reserve(production_orders_.size() + width * height +
|
||||
(furnishings ? furnishings->size() : 0) + (legacy_bed ? 1U : 0U) + door_orders);
|
||||
if (legacy_bed) queue_production(scenario_sawmill_, RecipeId::SawPlank);
|
||||
if (furnishings) {
|
||||
for (const auto& part : *furnishings) {
|
||||
ProductionOrder order{};
|
||||
order.position = part.position;
|
||||
order.recipe = part.recipe;
|
||||
order.bed_base = part.bed_base;
|
||||
if (order.recipe == RecipeId::BuildBed && staged_beds_) order.bed_stage = BedStage::Foundation;
|
||||
production_orders_.push_back(std::move(order));
|
||||
}
|
||||
}
|
||||
for (int y = plan.first.y; y <= plan.last.y; ++y) {
|
||||
for (int x = plan.first.x; x <= plan.last.x; ++x) {
|
||||
const GridPosition cell{x, y};
|
||||
ProductionOrder order{};
|
||||
order.position = cell;
|
||||
order.recipe = plan.recipe_at(cell);
|
||||
order.recipe = room_construction_recipe(plan.recipe_at(cell));
|
||||
production_orders_.push_back(std::move(order));
|
||||
}
|
||||
}
|
||||
for (std::size_t i = 0; i < door_orders; ++i) queue_production(scenario_sawmill_, RecipeId::CraftWoodenDoor);
|
||||
break;
|
||||
}
|
||||
case CommandKind::PlaceStorage:
|
||||
@@ -695,7 +795,7 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
|
||||
break;
|
||||
}
|
||||
case CommandKind::AssignProfession: {
|
||||
if (command.value > static_cast<std::uint8_t>(Profession::Builder) || command.resident == 0) {
|
||||
if (command.value > static_cast<std::uint8_t>(Profession::Carpenter) || command.resident == 0) {
|
||||
return receipt(CommandStatus::InvalidTarget);
|
||||
}
|
||||
const auto resident = std::lower_bound(agents_.begin(), agents_.end(), command.resident,
|
||||
@@ -1004,10 +1104,11 @@ void World::assign_resource_tasks(ResourceFocus focus) {
|
||||
}
|
||||
for (Agent& agent : agents_) {
|
||||
if (open_pantry_count == 0 && open_material_store_count == 0 && untended_sites == 0) break;
|
||||
if (agent.profession == Profession::Builder || agent.state != AgentState::Idle || agent.current_job != 0 ||
|
||||
const auto profession = static_cast<std::size_t>(agent.profession);
|
||||
if (profession >= available.size() || agent.state != AgentState::Idle || agent.current_job != 0 ||
|
||||
!agent.inventory.empty()) continue;
|
||||
|
||||
const auto& candidates = available[static_cast<std::size_t>(agent.profession)];
|
||||
const auto& candidates = available[profession];
|
||||
if (candidates.empty()) continue;
|
||||
std::vector<std::uint8_t> tried_nodes(candidates.size(), 0);
|
||||
for (;;) {
|
||||
@@ -1099,7 +1200,8 @@ void World::assign_production_tasks(bool weaving) {
|
||||
if (production_orders_.empty() || storages_.empty() ||
|
||||
std::none_of(agents_.begin(), agents_.end(),
|
||||
[](const Agent& agent) {
|
||||
return agent.state == AgentState::Idle && can_take_work(agent, Profession::Builder);
|
||||
return agent.state == AgentState::Idle &&
|
||||
(can_take_work(agent, Profession::Builder) || agent.profession == Profession::Carpenter);
|
||||
})) return;
|
||||
for (std::size_t index = 0; index < production_orders_.size(); ++index) {
|
||||
ProductionOrder& order = production_orders_[index];
|
||||
@@ -1107,15 +1209,18 @@ void World::assign_production_tasks(bool weaving) {
|
||||
|
||||
const bool site_busy = std::any_of(production_orders_.begin(), production_orders_.end(),
|
||||
[&order](const ProductionOrder& other) {
|
||||
return other.state == JobState::InProgress &&
|
||||
other.position.x == order.position.x && other.position.y == order.position.y;
|
||||
return other.position == order.position &&
|
||||
(other.state == JobState::InProgress ||
|
||||
(order.recipe != RecipeId::BuildFloor && other.recipe == RecipeId::BuildFloor &&
|
||||
other.state != JobState::Completed));
|
||||
});
|
||||
if (site_busy) continue;
|
||||
|
||||
const Recipe recipe = recipe_for(order);
|
||||
const bool construction = is_construction(order.recipe);
|
||||
const bool door_craft = order.recipe == RecipeId::CraftWoodenDoor;
|
||||
const bool deliver_ingredients = delivers_materials(order.recipe);
|
||||
enum class Access { Unknown, Reachable, Unreachable };
|
||||
std::vector<Access> storage_access(construction || weaving ? storages_.size() : 0, Access::Unknown);
|
||||
std::vector<Access> storage_access(deliver_ingredients || weaving ? storages_.size() : 0, Access::Unknown);
|
||||
std::vector<MaterialReservation> materials;
|
||||
bool supplied = true;
|
||||
for (const ItemStack& ingredient : recipe.ingredients) {
|
||||
@@ -1146,7 +1251,7 @@ void World::assign_production_tasks(bool weaving) {
|
||||
if (!supplied) continue;
|
||||
|
||||
std::vector<ConstructionStop> stops;
|
||||
if (construction) {
|
||||
if (deliver_ingredients) {
|
||||
for (std::size_t s = 0; s < storage_access.size(); ++s) {
|
||||
if (storage_access[s] == Access::Reachable) stops.push_back({s, {}});
|
||||
}
|
||||
@@ -1160,12 +1265,18 @@ void World::assign_production_tasks(bool weaving) {
|
||||
stops[i].route_to_next = std::move(path.positions);
|
||||
}
|
||||
}
|
||||
const GridPosition destination = construction
|
||||
const GridPosition destination = deliver_ingredients
|
||||
? storages_[stops.front().storage_index].position : order.position;
|
||||
for (Agent& agent : agents_) {
|
||||
if (agent.state != AgentState::Idle || !can_take_work(agent, Profession::Builder)) continue;
|
||||
const bool can_craft = agent.profession == Profession::Carpenter;
|
||||
const bool eligible = door_craft ? can_craft :
|
||||
can_take_work(agent, Profession::Builder) || (can_craft && order.recipe == RecipeId::SawPlank);
|
||||
if (agent.state != AgentState::Idle || !eligible) continue;
|
||||
auto path = assignment_path(agent.position, destination);
|
||||
if (!path.reachable) continue;
|
||||
if (door_craft) {
|
||||
agent.haul_route = assignment_path(order.position, storages_[materials.front().storage_index].position).positions;
|
||||
}
|
||||
|
||||
for (const auto& material : materials) {
|
||||
stack_position(storages_[material.storage_index], material.type)->reserved += material.count;
|
||||
@@ -1177,7 +1288,7 @@ void World::assign_production_tasks(bool weaving) {
|
||||
agent.route = std::move(path.positions);
|
||||
agent.route_cursor = 0;
|
||||
agent.work_remaining = recipe.ticks;
|
||||
agent.state = construction ? AgentState::FetchingMaterials :
|
||||
agent.state = deliver_ingredients ? AgentState::FetchingMaterials :
|
||||
(agent.route.empty() ? AgentState::Working : AgentState::Travelling);
|
||||
break;
|
||||
}
|
||||
@@ -1326,6 +1437,10 @@ void World::advance_construction_delivery(Agent& agent) {
|
||||
agent.inventory.add(material.type, material.count);
|
||||
}
|
||||
}
|
||||
if (order.recipe == RecipeId::CraftWoodenDoor && stop.storage_index == order.materials.front().storage_index) {
|
||||
// The wood just collected frees a slot for the completed door.
|
||||
++storages_[stop.storage_index].reserved_slots;
|
||||
}
|
||||
++order.collected_stops;
|
||||
agent.route = std::move(stop.route_to_next);
|
||||
agent.route_cursor = 0;
|
||||
@@ -1336,6 +1451,18 @@ void World::finish_production(Agent& agent) {
|
||||
ProductionOrder& order = production_orders_[agent.production_index];
|
||||
const Recipe recipe = recipe_for(order);
|
||||
assert(!order.materials.empty());
|
||||
if (order.recipe == RecipeId::CraftWoodenDoor) {
|
||||
agent.inventory.add(recipe.output);
|
||||
agent.storage_index = order.materials.front().storage_index;
|
||||
agent.route = std::move(agent.haul_route);
|
||||
agent.haul_route.clear();
|
||||
agent.route_cursor = 0;
|
||||
agent.production_index = no_entity_index;
|
||||
agent.state = AgentState::Hauling;
|
||||
order.materials.clear();
|
||||
order.state = JobState::Completed;
|
||||
return;
|
||||
}
|
||||
if (recipe.output != ItemType::None) {
|
||||
for (const auto& material : order.materials) {
|
||||
take_reserved_material(storages_[material.storage_index], material);
|
||||
@@ -1348,6 +1475,9 @@ void World::finish_production(Agent& agent) {
|
||||
(order.bed_stage == BedStage::Foundation || order.bed_stage == BedStage::Bedding)) {
|
||||
order.bed_stage = order.bed_stage == BedStage::Foundation ? BedStage::Bedding : BedStage::Pillow;
|
||||
order.state = JobState::Available;
|
||||
} else if (order.recipe == RecipeId::BuildLoom) {
|
||||
order.recipe = RecipeId::WeaveCloth;
|
||||
order.state = JobState::Available;
|
||||
} else if (order.recipe == RecipeId::WeaveCloth) {
|
||||
order.state = JobState::Available;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user