From 4d9deb8eca71674c20b534b227cdc5af598870ee Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 16 Feb 2023 14:37:10 -0600 Subject: [PATCH 1/8] tailor: try to squash toad clothing bug this adds a test for an unmapped clothing size which will at least stop the making of toad-sized clothing. a diagnostic is issued when this happens as it is a bug --- plugins/tailor.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 5511e2b5d..49153fd3b 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -405,6 +405,13 @@ public: std::tie(ty, sub, size) = o.first; int count = o.second; + if (sizes.count(size) == 0) + { + WARN(cycle).print("tailor: cannot determine race for clothing of size %d, skipped\n", + size); + continue; + } + if (count > 0) { std::vector v; From 54013b4400a5568527c71e4dfb116237c207be64 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 16 Feb 2023 15:33:55 -0600 Subject: [PATCH 2/8] add support for adamantine cloth off by default because really now also downgraded "weird cloth item" message from WARN to DEBUG --- plugins/tailor.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 49153fd3b..4355c2081 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -56,6 +56,7 @@ enum ConfigValues { CONFIG_CLOTH_IDX = 2, CONFIG_YARN_IDX = 3, CONFIG_LEATHER_IDX = 4, + CONFIG_ADAMANTINE_IDX = 5, }; static int get_config_val(PersistentDataItem &c, int index) { @@ -119,10 +120,11 @@ static const MatType M_SILK = MatType("silk", df::job_material_category::mask_silk, df::armor_general_flags::SOFT), M_CLOTH = MatType("cloth", df::job_material_category::mask_cloth, df::armor_general_flags::SOFT), M_YARN = MatType("yarn", df::job_material_category::mask_yarn, df::armor_general_flags::SOFT), - M_LEATHER = MatType("leather", df::job_material_category::mask_leather, df::armor_general_flags::LEATHER); + M_LEATHER = MatType("leather", df::job_material_category::mask_leather, df::armor_general_flags::LEATHER), + M_ADAMANTINE = MatType("adamantine", df::job_material_category::mask_strand, df::armor_general_flags::SOFT); -static const std::list all_materials = { M_SILK, M_CLOTH, M_YARN, M_LEATHER }; -static std::list material_order = all_materials; +static const std::list all_materials = { M_SILK, M_CLOTH, M_YARN, M_LEATHER, M_ADAMANTINE }; +static std::list material_order = { M_SILK, M_CLOTH, M_YARN, M_LEATHER }; // M_ADAMANTINE is not included by default static struct BadFlags { uint32_t whole; @@ -208,11 +210,13 @@ public: supply[M_CLOTH] += ss; else if (mat.material->flags.is_set(df::material_flags::YARN)) supply[M_YARN] += ss; + else if (mat.material->flags.is_set(df::material_flags::STOCKPILE_THREAD_METAL)) + supply[M_ADAMANTINE] += ss; else { std::string d; i->getItemDescription(&d, 0); - WARN(cycle).print("tailor: weird cloth item found: %s (%d)\n", d.c_str(), i->id); + DEBUG(cycle).print("tailor: weird cloth item found: %s (%d), material_flags = %0x\n", d.c_str(), i->id); } } } @@ -224,7 +228,8 @@ public: supply[M_LEATHER] += i->getStackSize(); } - DEBUG(cycle).print("tailor: available silk %d yarn %d cloth %d leather %d\n", supply[M_SILK], supply[M_YARN], supply[M_CLOTH], supply[M_LEATHER]); + DEBUG(cycle).print("tailor: available silk %d yarn %d cloth %d leather %d adamantine %d\n", + supply[M_SILK], supply[M_YARN], supply[M_CLOTH], supply[M_LEATHER], supply[M_ADAMANTINE]); } void scan_replacements() From f437a83dba1d34890531ebd4e9850fe64a53fb9d Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 16 Feb 2023 15:38:18 -0600 Subject: [PATCH 3/8] add changelog --- docs/changelog.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.txt b/docs/changelog.txt index 85750890c..17db6ce03 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `autodump`: changed behaviour to only change ``dump`` and ``forbid`` flags if an item is successfully dumped. -@ `autochop`: generate default names for burrows with no assigned names - ``Buildings::StockpileIterator``: check for stockpile items on block boundary. +- `tailor`: block making clothing sized for toads, add support for adamantine cloth (off by default), and reduce logging spam ## Misc Improvements - DFHack tool windows that capture mouse clicks (and therefore prevent you from clicking on the "pause" button) now unconditionally pause the game when they open (but you can still unpause with the keyboard if you want to). Examples of this behavior: `gui/quickfort`, `gui/blueprint`, `gui/liquids` From f6df3ff3354880310b35785fec883609828329a5 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Thu, 16 Feb 2023 15:39:10 -0600 Subject: [PATCH 4/8] remove thing i thought i already removed --- plugins/tailor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index 4355c2081..f0f2c0b68 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -216,7 +216,7 @@ public: { std::string d; i->getItemDescription(&d, 0); - DEBUG(cycle).print("tailor: weird cloth item found: %s (%d), material_flags = %0x\n", d.c_str(), i->id); + DEBUG(cycle).print("tailor: weird cloth item found: %s (%d)\n", d.c_str(), i->id); } } } From 7e584df0406d1d5f9074e4ab8a504b221ff66e21 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 17 Feb 2023 12:10:23 -0600 Subject: [PATCH 5/8] misc tailor updates related to adamantine cloth --- docs/plugins/tailor.rst | 15 ++++++++++++++- plugins/lua/tailor.lua | 3 ++- plugins/tailor.cpp | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/plugins/tailor.rst b/docs/plugins/tailor.rst index 0e8980948..7396102f8 100644 --- a/docs/plugins/tailor.rst +++ b/docs/plugins/tailor.rst @@ -30,7 +30,11 @@ By default, ``tailor`` will prefer using materials in this order:: silk cloth yarn leather but you can use the ``tailor materials`` command to restrict which materials -are used, and in what order. +are used, and in what order. ``tailor`` supports adamantine cloth (using the +keyword ``adamantine``) but does not use it by default, as most players find +adamantine too precious to routinely make into cloth. ``tailor`` does not +support modded "cloth" types which utilize custom reactions to making clothing +out of those cloth types. Examples -------- @@ -46,3 +50,12 @@ Examples Restrict the materials used for automatically manufacturing clothing to silk, cloth, and yarn, preferred in that order. This saves leather for other uses, like making armor. + +Note +---- + +The reason for the limitation on modded cloth-like materials is +because custom reactions do not support the in-game mechanic +which allows a manager order to specify a different size for clothing items. +This mechanic only works for reactions that use the default make-clothing or +make-armor reactions, and is a limitation of the game itself. diff --git a/plugins/lua/tailor.lua b/plugins/lua/tailor.lua index bcfd8bc10..e9a88bfe1 100644 --- a/plugins/lua/tailor.lua +++ b/plugins/lua/tailor.lua @@ -28,7 +28,8 @@ function setMaterials(names) idxs.silk or -1, idxs.cloth or -1, idxs.yarn or -1, - idxs.leather or -1) + idxs.leather or -1, + idxs.adamantine or -1) end function parse_commandline(...) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index f0f2c0b68..a50af1939 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -585,6 +585,8 @@ static void set_material_order() { material_order.push_back(M_YARN); else if (i == (size_t)get_config_val(config, CONFIG_LEATHER_IDX)) material_order.push_back(M_LEATHER); + else if (i == (size_t)get_config_val(config, CONFIG_ADAMANTINE_IDX)) + material_order.push_back(M_ADAMANTINE); } if (!material_order.size()) std::copy(all_materials.begin(), all_materials.end(), std::back_inserter(material_order)); @@ -710,6 +712,7 @@ static void tailor_setMaterialPreferences(color_ostream &out, int32_t silkIdx, set_config_val(config, CONFIG_CLOTH_IDX, clothIdx - 1); set_config_val(config, CONFIG_YARN_IDX, yarnIdx - 1); set_config_val(config, CONFIG_LEATHER_IDX, leatherIdx - 1); + set_config_val(config, CONFIG_ADAMANTINE_IDX, leatherIdx - 1); set_material_order(); } From 4eb3ae566d1234c3eb1fc89e475a3a3fc218b718 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 17 Feb 2023 12:58:48 -0600 Subject: [PATCH 6/8] unshadow unit size variable --- plugins/tailor.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index a50af1939..d26559a10 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -258,8 +258,8 @@ public: wearing.insert(inv->item->getType()); } - int size = world->raws.creatures.all[u->race]->adultsize; - sizes[size] = u->race; + int usize = world->raws.creatures.all[u->race]->adultsize; + sizes[usize] = u->race; for (auto ty : std::set{ df::item_type::ARMOR, df::item_type::PANTS, df::item_type::SHOES }) { @@ -267,9 +267,9 @@ public: { TRACE(cycle).print("tailor: one %s of size %d needed to cover %s\n", ENUM_KEY_STR(item_type, ty).c_str(), - size, + usize, Translation::TranslateName(&u->name, false).c_str()); - needed[std::make_pair(ty, size)] += 1; + needed[std::make_pair(ty, usize)] += 1; } } @@ -283,11 +283,11 @@ public: } const df::job_type o = oo->second; - int size = world->raws.creatures.all[w->getMakerRace()]->adultsize; + int isize = world->raws.creatures.all[w->getMakerRace()]->adultsize; std::string description; w->getItemDescription(&description, 0); - if (available[std::make_pair(ty, size)] > 0) + if (available[std::make_pair(ty, usize)] > 0) { if (w->flags.bits.owned) { @@ -303,10 +303,10 @@ public: if (wearing.count(ty) == 0) { - DEBUG(cycle).print("tailor: allocating a %s to %s\n", - ENUM_KEY_STR(item_type, ty).c_str(), + DEBUG(cycle).print("tailor: allocating a %s (size %d) to %s\n", + ENUM_KEY_STR(item_type, ty).c_str(), usize, Translation::TranslateName(&u->name, false).c_str()); - available[std::make_pair(ty, size)] -= 1; + available[std::make_pair(ty, usize)] -= 1; } if (w->getWear() > 1) @@ -314,10 +314,10 @@ public: } else { - DEBUG(cycle).print ("tailor: %s worn by %s needs replacement, but none available\n", - description.c_str(), - Translation::TranslateName(&u->name, false).c_str()); - orders[std::make_tuple(o, w->getSubtype(), size)] += 1; + DEBUG(cycle).print ("tailor: %s (size %d) worn by %s (size %d) needs replacement, but none available\n", + description.c_str(), isize, + Translation::TranslateName(&u->name, false).c_str(), usize); + orders[std::make_tuple(o, w->getSubtype(), usize)] += 1; } } } From 6a0ac8b14244668e783cb7ad88c44ec2f546673f Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 17 Feb 2023 13:08:02 -0600 Subject: [PATCH 7/8] update changelog --- docs/changelog.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.txt b/docs/changelog.txt index 17db6ce03..bf168ac3a 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -42,7 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences: - `autodump`: changed behaviour to only change ``dump`` and ``forbid`` flags if an item is successfully dumped. -@ `autochop`: generate default names for burrows with no assigned names - ``Buildings::StockpileIterator``: check for stockpile items on block boundary. -- `tailor`: block making clothing sized for toads, add support for adamantine cloth (off by default), and reduce logging spam +- `tailor`: block making clothing sized for toads; make replacement clothing orders use the size of the wearer, not the size of the garment; add support for adamantine cloth (off by default); improve logging ## Misc Improvements - DFHack tool windows that capture mouse clicks (and therefore prevent you from clicking on the "pause" button) now unconditionally pause the game when they open (but you can still unpause with the keyboard if you want to). Examples of this behavior: `gui/quickfort`, `gui/blueprint`, `gui/liquids` From f73634d009d5edfb9e690e9a3a078ecbf264abd0 Mon Sep 17 00:00:00 2001 From: Kelly Kinkade Date: Fri, 17 Feb 2023 14:03:42 -0600 Subject: [PATCH 8/8] add missing parameter --- plugins/tailor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/tailor.cpp b/plugins/tailor.cpp index d26559a10..19237429e 100644 --- a/plugins/tailor.cpp +++ b/plugins/tailor.cpp @@ -703,7 +703,8 @@ static void tailor_doCycle(color_ostream &out) { // remember, these are ONE-based indices from Lua static void tailor_setMaterialPreferences(color_ostream &out, int32_t silkIdx, - int32_t clothIdx, int32_t yarnIdx, int32_t leatherIdx) { + int32_t clothIdx, int32_t yarnIdx, int32_t leatherIdx, + int32_t adamantineIdx) { DEBUG(config,out).print("entering tailor_setMaterialPreferences\n"); // it doesn't really matter if these are invalid. set_material_order will do @@ -712,7 +713,7 @@ static void tailor_setMaterialPreferences(color_ostream &out, int32_t silkIdx, set_config_val(config, CONFIG_CLOTH_IDX, clothIdx - 1); set_config_val(config, CONFIG_YARN_IDX, yarnIdx - 1); set_config_val(config, CONFIG_LEATHER_IDX, leatherIdx - 1); - set_config_val(config, CONFIG_ADAMANTINE_IDX, leatherIdx - 1); + set_config_val(config, CONFIG_ADAMANTINE_IDX, adamantineIdx - 1); set_material_order(); }