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

+28 -11
View File
@@ -13,7 +13,7 @@ namespace settlement {
namespace {
constexpr std::string_view signature = "SETTLERS";
constexpr std::uint32_t save_version = 12;
constexpr std::uint32_t save_version = 13;
constexpr std::uint32_t last_legacy_footer_version = 8;
constexpr std::size_t max_records = 1'000'000;
constexpr std::size_t max_save_bytes = 128 * 1024 * 1024;
@@ -174,7 +174,8 @@ void flag(Archive& archive, Flag& value) {
struct WorldSaveCodec {
template<class Archive, class State>
static void body(Archive& archive, State& world, std::uint32_t version) {
const auto max_item = version >= 12 ? ItemType::WoodenDoor : (version >= 7 ? ItemType::Flax : ItemType::Cloth);
const auto max_item = version >= 13 ? ItemType::Loom :
version >= 12 ? ItemType::WoodenDoor : (version >= 7 ? ItemType::Flax : ItemType::Cloth);
const auto max_item_count = static_cast<std::size_t>(max_item);
archive.field(world.tick_);
archive.field(world.path_searches_);
@@ -259,6 +260,7 @@ struct WorldSaveCodec {
require_save(version >= 10 || order.recipe <= RecipeId::WeaveCloth, "Unknown recipe for save version.");
require_save(version >= 11 || order.recipe <= RecipeId::BuildDoorAlongY, "Unknown recipe for save version.");
require_save(version >= 12 || order.recipe <= RecipeId::BuildLoom, "Unknown recipe for save version.");
require_save(version >= 13 || order.recipe <= RecipeId::CraftWoodenDoor, "Unknown recipe for save version.");
archive.field(order.state);
sequence(archive, order.materials, item_types, [&](auto& material) {
index(archive, material.storage_index);
@@ -365,10 +367,10 @@ void WorldSaveCodec::validate(const World& world) {
std::vector<AgentId> bed_owners;
for (std::size_t i = 0; i < world.production_orders_.size(); ++i) {
const auto& order = world.production_orders_[i];
invalid(order.recipe <= RecipeId::CraftWoodenDoor && order.state <= JobState::Completed &&
invalid(order.recipe <= RecipeId::CraftLoom && order.state <= JobState::Completed &&
world.is_walkable(order.position) &&
(order.recipe != RecipeId::WeaveCloth || order.state != JobState::Completed));
invalid(order.recipe != RecipeId::CraftWoodenDoor || world.carpenter_workshop() == order.position);
invalid(!is_carpentry_recipe(order.recipe) || world.carpenter_workshop() == order.position);
invalid(order.bed_base <= BedBase::Stone && order.bed_stage <= BedStage::Pillow &&
(order.bed_stage == BedStage::Legacy ||
(world.staged_beds_ && order.recipe == RecipeId::BuildBed)) &&
@@ -429,7 +431,14 @@ void WorldSaveCodec::validate(const World& world) {
break;
case RecipeId::BuildBed: required[item_index(order.bed_material())] = 1; break;
case RecipeId::WeaveCloth: required[item_index(ItemType::Flax)] = 1; break;
case RecipeId::CraftWoodenDoor: required[item_index(ItemType::Wood)] = 2; break;
case RecipeId::CraftWoodenDoor:
case RecipeId::CraftMedicineCabinet:
case RecipeId::CraftMiningRack:
case RecipeId::CraftLoom:
for (const auto& item : world.carpentry_materials(order.recipe)) {
if (item.count) required[item_index(item.type)] = item.count;
}
break;
case RecipeId::BuildFloor:
case RecipeId::BuildWall:
case RecipeId::BuildDoorAlongX:
@@ -439,6 +448,9 @@ void WorldSaveCodec::validate(const World& world) {
case RecipeId::BuildLoom:
case RecipeId::InstallDoorAlongX:
case RecipeId::InstallDoorAlongY:
case RecipeId::InstallMedicineCabinet:
case RecipeId::InstallMiningRack:
case RecipeId::InstallLoom:
for (const auto& item : world.construction_materials(order.recipe, order.bed_base)) {
if (item.count) required[item_index(item.type)] = item.count;
}
@@ -468,9 +480,9 @@ void WorldSaveCodec::validate(const World& world) {
const bool has_source = agent.resource_node_index != no_entity_index;
const bool has_storage = agent.storage_index != no_entity_index;
invalid(!has_storage || agent.storage_index < world.storages_.size());
const bool door_craft = has_order && agent.production_index < world.production_orders_.size() &&
world.production_orders_[agent.production_index].recipe == RecipeId::CraftWoodenDoor;
invalid(agent.haul_route.empty() || has_source || door_craft);
const bool carpentry = has_order && agent.production_index < world.production_orders_.size() &&
is_carpentry_recipe(world.production_orders_[agent.production_index].recipe);
invalid(agent.haul_route.empty() || has_source || carpentry);
if (has_job) {
invalid(!has_order && !has_storage && !has_source && agent.inventory.empty() &&
(agent.state == Travelling || agent.state == Working) && agent.work_remaining > 0);
@@ -491,11 +503,16 @@ void WorldSaveCodec::validate(const World& world) {
} else {
invalid(agent.state == Working || (agent.state == Travelling && !delivers_materials(order.recipe)));
}
if (door_craft) {
if (carpentry) {
const auto storage = order.materials.front().storage_index;
const auto destination = world.storages_[storage].position;
invalid(agent.haul_route.empty() ? destination == order.position : agent.haul_route.back() == destination);
if (order.delivery_stops.empty() || order.collected_stops > 0) ++reserved_slots[storage];
const auto& stops = order.delivery_stops;
const auto output_stop = std::find_if(stops.begin(), stops.end(),
[storage](const auto& stop) { return stop.storage_index == storage; });
const bool collected = stops.empty() ||
static_cast<std::size_t>(output_stop - stops.begin()) < order.collected_stops;
if (collected) ++reserved_slots[storage];
}
for (std::size_t i = 0; i < item_types; ++i) {
invalid(agent.inventory.item_count(static_cast<ItemType>(i + 1)) == expected_cargo[agent.production_index][i]);
@@ -515,7 +532,7 @@ void WorldSaveCodec::validate(const World& world) {
} else if (agent.state == Hauling) {
const auto cargo = agent.inventory.first_item();
invalid(has_storage && (cargo == ItemType::Wood || cargo == ItemType::Stone ||
cargo == ItemType::Berries || cargo == ItemType::Flax || cargo == ItemType::WoodenDoor) &&
cargo == ItemType::Berries || cargo == ItemType::Flax || is_carpentry_item(cargo)) &&
agent.inventory.item_count(cargo) == 1 && agent.work_remaining == 0 &&
world.storages_[agent.storage_index].accepts(cargo));
for (std::size_t i = 1; i <= item_types; ++i) {