Apply furniture and standalone loom crafting to the Windows game

This commit is contained in:
Codex committed 2026-12-01 11:54:01 +03:00
1 parent 1ef2977081
commit 803433bc94
9 files changed
+345 -74

No files matched your search

+87 -25
View File
@@ -75,6 +75,12 @@ const Recipe& recipe_for(RecipeId id) {
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};
static constexpr Recipe craft_cabinet{cabinet.ingredients, ItemType::MedicineCabinet, 14};
static constexpr Recipe craft_rack{mining_rack.ingredients, ItemType::MiningRack, 14};
static constexpr Recipe craft_loom{loom.ingredients, ItemType::Loom, 16};
static constexpr Recipe install_cabinet{{ItemStack{ItemType::MedicineCabinet, 1}, {}}, ItemType::None, 8};
static constexpr Recipe install_rack{{ItemStack{ItemType::MiningRack, 1}, {}}, ItemType::None, 8};
static constexpr Recipe install_loom{{ItemStack{ItemType::Loom, 1}, {}}, ItemType::None, 8};
switch (id) {
case RecipeId::SawPlank: return saw;
case RecipeId::CutStoneBlock: return cut;
@@ -91,10 +97,30 @@ const Recipe& recipe_for(RecipeId id) {
case RecipeId::InstallDoorAlongX:
case RecipeId::InstallDoorAlongY: return install_door;
case RecipeId::CraftWoodenDoor: return craft_door;
case RecipeId::CraftMedicineCabinet: return craft_cabinet;
case RecipeId::CraftMiningRack: return craft_rack;
case RecipeId::CraftLoom: return craft_loom;
case RecipeId::InstallMedicineCabinet: return install_cabinet;
case RecipeId::InstallMiningRack: return install_rack;
case RecipeId::InstallLoom: return install_loom;
}
throw std::invalid_argument("unknown production recipe");
}
constexpr ItemType carpentry_products[] = {
ItemType::WoodenDoor, ItemType::MedicineCabinet, ItemType::MiningRack, ItemType::Loom,
};
RecipeId recipe_for_carpentry_item(ItemType item) {
switch (item) {
case ItemType::WoodenDoor: return RecipeId::CraftWoodenDoor;
case ItemType::MedicineCabinet: return RecipeId::CraftMedicineCabinet;
case ItemType::MiningRack: return RecipeId::CraftMiningRack;
case ItemType::Loom: return RecipeId::CraftLoom;
default: throw std::invalid_argument("unknown carpentry item");
}
}
Recipe recipe_for(const ProductionOrder& order) {
Recipe recipe = recipe_for(order.recipe);
if (order.recipe == RecipeId::BuildBed) recipe.ingredients[0].type = order.bed_material();
@@ -301,13 +327,13 @@ 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 &&
is_carpentry_recipe(production_orders_[agent.production_index].recipe) &&
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 &&
agent.inventory.item_count(ItemType::WoodenDoor) == 0) continue;
!is_carpentry_item(agent.inventory.first_item())) 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");
@@ -400,8 +426,8 @@ 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_carpentry_recipe(recipe) && carpenter_workshop() != position) {
throw std::invalid_argument("carpentry orders need the carpenter's workshop");
}
if (is_production_object(recipe) && !can_place_storage(position)) {
throw std::invalid_argument("the production site is occupied");
@@ -464,26 +490,34 @@ 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;
if (part == RecipeId::BuildMedicineCabinet) return RecipeId::InstallMedicineCabinet;
if (part == RecipeId::BuildMiningRack) return RecipeId::InstallMiningRack;
if (part == RecipeId::BuildLoom) return RecipeId::InstallLoom;
}
return part;
}
std::size_t World::missing_door_orders(std::size_t new_installations) const {
std::array<ItemStack, 2> World::carpentry_materials(RecipeId recipe) const {
return is_carpentry_recipe(recipe) ? recipe_for(recipe).ingredients : std::array<ItemStack, 2>{};
}
std::size_t World::missing_carpentry_orders(ItemType product, std::size_t new_installations) const {
const auto craft = recipe_for_carpentry_item(product);
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)) {
if (order.recipe == craft && order.state != JobState::Completed) ++supply;
if (order.state == JobState::Available && is_construction(order.recipe) &&
recipe_for(order).ingredients.front().type == product) {
++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);
supply += agent.inventory.item_count(product);
}
}
for (const auto& storage : storages_) {
const auto available = storage.available_item_count(ItemType::WoodenDoor);
const auto available = storage.available_item_count(product);
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;
@@ -613,7 +647,10 @@ 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;
std::array<std::uint8_t, std::size(carpentry_products)> lost_products{};
for (std::size_t i = 0; i < std::size(carpentry_products); ++i) {
lost_products[i] = storage->item_count(carpentry_products[i]) != 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);
@@ -621,9 +658,15 @@ 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);
if (scenario_active_) {
for (std::size_t i = 0; i < std::size(carpentry_products); ++i) {
if (!lost_products[i]) continue;
const auto product = carpentry_products[i];
const auto missing = missing_carpentry_orders(product);
for (std::size_t j = 0; j < missing; ++j) {
queue_production(scenario_sawmill_, recipe_for_carpentry_item(product));
}
}
}
}
return CommandStatus::Accepted;
@@ -740,11 +783,24 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
if (!can_place_storage(command.cell) || !can_reach_object_cell(command.cell)) {
return receipt(CommandStatus::InvalidTarget);
}
queue_production(command.cell, RecipeId::WeaveCloth);
if (scenario_active_) {
const auto missing = missing_carpentry_orders(ItemType::Loom, 1);
production_orders_.reserve(production_orders_.size() + 1 + missing);
queue_production(command.cell, RecipeId::InstallLoom);
for (std::size_t i = 0; i < missing; ++i) queue_production(scenario_sawmill_, RecipeId::CraftLoom);
} else {
queue_production(command.cell, RecipeId::WeaveCloth);
}
break;
case CommandKind::CraftDoor:
queue_production(scenario_sawmill_, RecipeId::CraftWoodenDoor);
break;
case CommandKind::CraftFurniture: {
const auto product = static_cast<ItemType>(command.value);
if (!is_carpentry_item(product) || product == ItemType::WoodenDoor) return receipt(CommandStatus::InvalidTarget);
queue_production(scenario_sawmill_, recipe_for_carpentry_item(product));
break;
}
case CommandKind::PlaceRoom: {
const auto plan = RoomPlan::from_placement(command.cell, command.destination, command.value);
if (!can_place_room(plan) || !can_reach_object_cell(plan.first)) {
@@ -754,15 +810,18 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
const auto height = static_cast<std::size_t>(plan.last.y - plan.first.y + 1);
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;
const auto door_orders = scenario_active_ ? missing_carpentry_orders(ItemType::WoodenDoor, 1) : 0;
const auto fixture = furnishings ? room_construction_recipe(furnishings->back().recipe) : RecipeId::BuildFloor;
const auto fixture_item = furnishings ? recipe_for(fixture).ingredients.front().type : ItemType::None;
const auto fixture_orders = furnishings ? missing_carpentry_orders(fixture_item, 1) : 0;
production_orders_.reserve(production_orders_.size() + width * height +
(furnishings ? furnishings->size() : 0) + (legacy_bed ? 1U : 0U) + door_orders);
(furnishings ? furnishings->size() : 0) + (legacy_bed ? 1U : 0U) + door_orders + fixture_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.recipe = room_construction_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));
@@ -778,6 +837,9 @@ CommandReceipt World::apply_command(const PlayerCommand& command) {
}
}
for (std::size_t i = 0; i < door_orders; ++i) queue_production(scenario_sawmill_, RecipeId::CraftWoodenDoor);
for (std::size_t i = 0; i < fixture_orders; ++i) {
queue_production(scenario_sawmill_, recipe_for_carpentry_item(fixture_item));
}
break;
}
case CommandKind::PlaceStorage:
@@ -1217,7 +1279,7 @@ void World::assign_production_tasks(bool weaving) {
if (site_busy) continue;
const Recipe recipe = recipe_for(order);
const bool door_craft = order.recipe == RecipeId::CraftWoodenDoor;
const bool carpentry = is_carpentry_recipe(order.recipe);
const bool deliver_ingredients = delivers_materials(order.recipe);
enum class Access { Unknown, Reachable, Unreachable };
std::vector<Access> storage_access(deliver_ingredients || weaving ? storages_.size() : 0, Access::Unknown);
@@ -1269,12 +1331,12 @@ void World::assign_production_tasks(bool weaving) {
? storages_[stops.front().storage_index].position : order.position;
for (Agent& agent : agents_) {
const bool can_craft = agent.profession == Profession::Carpenter;
const bool eligible = door_craft ? can_craft :
const bool eligible = carpentry ? 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) {
if (carpentry) {
agent.haul_route = assignment_path(order.position, storages_[materials.front().storage_index].position).positions;
}
@@ -1437,8 +1499,8 @@ 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.
if (is_carpentry_recipe(order.recipe) && stop.storage_index == order.materials.front().storage_index) {
// Collecting the first ingredient frees a slot for the finished item.
++storages_[stop.storage_index].reserved_slots;
}
++order.collected_stops;
@@ -1451,7 +1513,7 @@ 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) {
if (is_carpentry_recipe(order.recipe)) {
agent.inventory.add(recipe.output);
agent.storage_index = order.materials.front().storage_index;
agent.route = std::move(agent.haul_route);
@@ -1475,7 +1537,7 @@ 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) {
} else if (furnishing_shape(order.recipe) == RecipeId::BuildLoom) {
order.recipe = RecipeId::WeaveCloth;
order.state = JobState::Available;
} else if (order.recipe == RecipeId::WeaveCloth) {