From 58eaf33b085f11bcc32dc940f061e9debb014178 Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 24 Mar 2023 15:26:17 -0700 Subject: [PATCH 1/2] normalize stairs so they all use the same filter --- docs/changelog.txt | 1 + plugins/buildingplan/buildingplan.cpp | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 88c6eac3b..c550fbc8a 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -37,6 +37,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `prospector`: prospector tool in fort mode is now available. embark prospect is not yet available and is disabled at this time. ## Fixes +- `buildingplan`: filters are now properly applied to planned stairs - `buildingplan`: upright spike traps are now placed extended rather than retracted - `buildingplan`: fixed material filter getting lost for planning buildings on save/reload - `buildingplan`: respect building size limits (e.g. roads and bridges cannot be more than 31 tiles in any dimension) diff --git a/plugins/buildingplan/buildingplan.cpp b/plugins/buildingplan/buildingplan.cpp index 1e2d2c80e..fd77194e5 100644 --- a/plugins/buildingplan/buildingplan.cpp +++ b/plugins/buildingplan/buildingplan.cpp @@ -9,6 +9,7 @@ #include "modules/World.h" +#include "df/construction_type.h" #include "df/item.h" #include "df/job_item.h" #include "df/world.h" @@ -282,6 +283,18 @@ static void clear_state(color_ostream &out) { call_buildingplan_lua(&out, "reload_pens"); } +static int16_t get_subtype(df::building *bld) { + if (!bld) + return -1; + + int16_t subtype = bld->getSubtype(); + if (bld->getType() == df::building_type::Construction && + subtype >= df::construction_type::UpStair && + subtype <= df::construction_type::UpDownStair) + subtype = df::construction_type::UpDownStair; + return subtype; +} + DFhackCExport command_result plugin_load_data (color_ostream &out) { cycle_timestamp = 0; config = World::GetPersistentData(CONFIG_KEY); @@ -315,7 +328,7 @@ DFhackCExport command_result plugin_load_data (color_ostream &out) { pb.remove(out); continue; } - BuildingTypeKey key(bld->getType(), bld->getSubtype(), bld->getCustomType()); + BuildingTypeKey key(bld->getType(), get_subtype(bld), bld->getCustomType()); if (pb.item_filters.size() != get_item_filters(out, key).getItemFilters().size()) { WARN(status).print("loaded state for building %d doesn't match world\n", pb.id); pb.remove(out); @@ -604,11 +617,15 @@ static bool isPlannedBuilding(color_ostream &out, df::building *bld) { static bool addPlannedBuilding(color_ostream &out, df::building *bld) { DEBUG(status,out).print("entering addPlannedBuilding\n"); - if (!bld || planned_buildings.count(bld->id) - || !isPlannableBuilding(out, bld->getType(), bld->getSubtype(), - bld->getCustomType())) + if (!bld || planned_buildings.count(bld->id)) return false; - BuildingTypeKey key(bld->getType(), bld->getSubtype(), bld->getCustomType()); + + int16_t subtype = get_subtype(bld); + + if (!isPlannableBuilding(out, bld->getType(), subtype, bld->getCustomType())) + return false; + + BuildingTypeKey key(bld->getType(), subtype, bld->getCustomType()); PlannedBuilding pb(out, bld, get_heat_safety_filter(key), get_item_filters(out, key)); return registerPlannedBuilding(out, pb); } From a8822bdefa2268c55affe0e0d5e8fe5fc429e48d Mon Sep 17 00:00:00 2001 From: Myk Taylor Date: Fri, 24 Mar 2023 15:43:02 -0700 Subject: [PATCH 2/2] take carved stairs into account when auto building stairs --- docs/changelog.txt | 1 + plugins/lua/buildingplan/planneroverlay.lua | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index c550fbc8a..3e340cf94 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -38,6 +38,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: ## Fixes - `buildingplan`: filters are now properly applied to planned stairs +- `buildingplan`: existing carved up/down stairs are now taken into account when determining which stair shape to construct - `buildingplan`: upright spike traps are now placed extended rather than retracted - `buildingplan`: fixed material filter getting lost for planning buildings on save/reload - `buildingplan`: respect building size limits (e.g. roads and bridges cannot be more than 31 tiles in any dimension) diff --git a/plugins/lua/buildingplan/planneroverlay.lua b/plugins/lua/buildingplan/planneroverlay.lua index e92824f5f..8231a8f46 100644 --- a/plugins/lua/buildingplan/planneroverlay.lua +++ b/plugins/lua/buildingplan/planneroverlay.lua @@ -782,7 +782,7 @@ function PlannerOverlay:get_stairs_subtype(pos, bounds) if opt == 'auto' then local tt = dfhack.maps.getTileType(pos) local shape = df.tiletype.attrs[tt].shape - if shape ~= df.tiletype_shape.STAIR_DOWN then + if shape ~= df.tiletype_shape.STAIR_DOWN and shape ~= df.tiletype_shape.STAIR_UPDOWN then subtype = df.construction_type.UpStair end else @@ -793,7 +793,7 @@ function PlannerOverlay:get_stairs_subtype(pos, bounds) if opt == 'auto' then local tt = dfhack.maps.getTileType(pos) local shape = df.tiletype.attrs[tt].shape - if shape ~= df.tiletype_shape.STAIR_UP then + if shape ~= df.tiletype_shape.STAIR_UP and shape ~= df.tiletype_shape.STAIR_UPDOWN then subtype = df.construction_type.DownStair end else