From 12eb9e48c7d00ef0afb008df015c8f3298f4faca Mon Sep 17 00:00:00 2001 From: myk002 Date: Sat, 2 Oct 2021 12:30:08 -0700 Subject: [PATCH] support multi-type and non-rectangular stockpiles and add integration tests --- .../test/ecosystem/in/allstockpiles-dig.csv | 12 ++++ .../test/ecosystem/in/allstockpiles-place.csv | 12 ++++ .../test/ecosystem/in/allstockpiles-spec.csv | 4 ++ .../library/test/ecosystem/in/basic-place.csv | 2 +- plugins/blueprint.cpp | 61 +++++++++++++------ 5 files changed, 71 insertions(+), 20 deletions(-) create mode 100644 data/blueprints/library/test/ecosystem/in/allstockpiles-dig.csv create mode 100644 data/blueprints/library/test/ecosystem/in/allstockpiles-place.csv create mode 100644 data/blueprints/library/test/ecosystem/in/allstockpiles-spec.csv diff --git a/data/blueprints/library/test/ecosystem/in/allstockpiles-dig.csv b/data/blueprints/library/test/ecosystem/in/allstockpiles-dig.csv new file mode 100644 index 000000000..5f7b0d7e4 --- /dev/null +++ b/data/blueprints/library/test/ecosystem/in/allstockpiles-dig.csv @@ -0,0 +1,12 @@ +#dig label(dig) +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d +d,d,d,d,d,d,d,d,d,d,d,d diff --git a/data/blueprints/library/test/ecosystem/in/allstockpiles-place.csv b/data/blueprints/library/test/ecosystem/in/allstockpiles-place.csv new file mode 100644 index 000000000..4a3a15583 --- /dev/null +++ b/data/blueprints/library/test/ecosystem/in/allstockpiles-place.csv @@ -0,0 +1,12 @@ +#place label(place) +a(2x2),,f(2x2),,u(2x2),,n(2x2),,y(2x2),,r(2x2) + +s(2x2),,w(2x2),,e(2x2),,b(2x2),,h(2x2),,l(2x2) + +z(2x2),,S(2x2),,g(2x2),,p(2x2),,d(2x2),,afunyrswebhlzSgpd(2x2) + +a,a,g,g,a,,,g,l,w,s,a +a,,,g,a,a,g,g,w,w,s,a +u,u,u,,,,,,s,s,s,a +u,z,u,,,,,,a,a,a,a +u,u,u diff --git a/data/blueprints/library/test/ecosystem/in/allstockpiles-spec.csv b/data/blueprints/library/test/ecosystem/in/allstockpiles-spec.csv new file mode 100644 index 000000000..2eb49fb8c --- /dev/null +++ b/data/blueprints/library/test/ecosystem/in/allstockpiles-spec.csv @@ -0,0 +1,4 @@ +#notes +description=all the stockpiles, including multi-type +width=12 +height=11 diff --git a/data/blueprints/library/test/ecosystem/in/basic-place.csv b/data/blueprints/library/test/ecosystem/in/basic-place.csv index 6dae40adc..84f5250ab 100644 --- a/data/blueprints/library/test/ecosystem/in/basic-place.csv +++ b/data/blueprints/library/test/ecosystem/in/basic-place.csv @@ -1,4 +1,4 @@ #place label(place) -,f(1x1),,f(1x1) +,f,,f diff --git a/plugins/blueprint.cpp b/plugins/blueprint.cpp index d1633c2f0..04ecb1b31 100644 --- a/plugins/blueprint.cpp +++ b/plugins/blueprint.cpp @@ -189,6 +189,19 @@ static const char * if_pretty(const tile_context &ctx, const char *c) { return ctx.pretty ? c : NULL; } +static bool is_rectangular(const tile_context &ctx) { + df::building_extents &room = ctx.b->room; + if (!room.extents) + return true; + for (int32_t y = 0; y < room.height; ++y) { + for (int32_t x = 0; x < room.width; ++x) { + if (!room.extents[y * room.width + x]) + return false; + } + } + return true; +} + static const char * do_block_building(const tile_context &ctx, const char *s, bool at_target_pos, bool *add_size = NULL) { @@ -586,26 +599,33 @@ static const char * get_place_keys(const tile_context &ctx) { return NULL; } - switch (sp->settings.flags.whole) { - case df::stockpile_group_set::mask_animals: return "a"; - case df::stockpile_group_set::mask_food: return "f"; - case df::stockpile_group_set::mask_furniture: return "u"; - case df::stockpile_group_set::mask_corpses: return "y"; - case df::stockpile_group_set::mask_refuse: return "r"; - case df::stockpile_group_set::mask_wood: return "w"; - case df::stockpile_group_set::mask_stone: return "s"; - case df::stockpile_group_set::mask_gems: return "e"; - case df::stockpile_group_set::mask_bars_blocks: return "b"; - case df::stockpile_group_set::mask_cloth: return "h"; - case df::stockpile_group_set::mask_leather: return "l"; - case df::stockpile_group_set::mask_ammo: return "z"; - case df::stockpile_group_set::mask_coins: return "n"; - case df::stockpile_group_set::mask_finished_goods: return "g"; - case df::stockpile_group_set::mask_weapons: return "p"; - case df::stockpile_group_set::mask_armor: return "d"; - default: // TODO: handle stockpiles with multiple types + string keys; + df::stockpile_group_set &flags = sp->settings.flags; + if (flags.bits.animals) keys += 'a'; + if (flags.bits.food) keys += 'f'; + if (flags.bits.furniture) keys += 'u'; + if (flags.bits.coins) keys += 'n'; + if (flags.bits.corpses) keys += 'y'; + if (flags.bits.refuse) keys += 'r'; + if (flags.bits.stone) keys += 's'; + if (flags.bits.wood) keys += 'w'; + if (flags.bits.gems) keys += 'e'; + if (flags.bits.bars_blocks) keys += 'b'; + if (flags.bits.cloth) keys += 'h'; + if (flags.bits.leather) keys += 'l'; + if (flags.bits.ammo) keys += 'z'; + if (flags.bits.sheet) keys += 'S'; + if (flags.bits.finished_goods) keys += 'g'; + if (flags.bits.weapons) keys += 'p'; + if (flags.bits.armor) keys += 'd'; + + if (keys.empty()) return NULL; - } + return cache(keys); +} + +static bool is_single_tile(const tile_context &ctx) { + return ctx.b->x1 == ctx.b->x2 && ctx.b->y1 == ctx.b->y2; } static const char * get_tile_place(const df::coord &pos, @@ -613,6 +633,9 @@ static const char * get_tile_place(const df::coord &pos, if (!ctx.b || ctx.b->getType() != building_type::Stockpile) return NULL; + if (!is_rectangular(ctx) || is_single_tile(ctx)) + return get_place_keys(ctx); + if (ctx.b->x1 != static_cast(pos.x) || ctx.b->y1 != static_cast(pos.y)) { return if_pretty(ctx, "`");