From 5e09a1cbf1aff08c63bd6c371d53ef2fb59fc1ee Mon Sep 17 00:00:00 2001 From: John Cosker Date: Wed, 8 Feb 2023 22:05:08 -0500 Subject: [PATCH] Change autoslab to use slab's "topic" field to compare historical id of slab instead of using str comp --- plugins/autoslab.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/plugins/autoslab.cpp b/plugins/autoslab.cpp index e17ce72c8..7cb67beb3 100644 --- a/plugins/autoslab.cpp +++ b/plugins/autoslab.cpp @@ -19,6 +19,7 @@ #include "df/historical_figure.h" #include "df/item.h" +#include "df/item_slabst.h" #include "df/manager_order.h" #include "df/plotinfost.h" #include "df/unit.h" @@ -168,25 +169,6 @@ static std::string get_last_name(df::unit *unit) return Translation::capitalize(ret); } -// Couldn't figure out any other way to do this besides look for the dwarf name in -// the slab item description. -// Ideally, we could get the historical figure id from the slab but I didn't -// see anything like that in the item struct. This seems to work based on testing. -// Confirmed nicknames don't show up in engraved slab names, so this should probably work okay -bool engravedSlabItemExists(df::unit *unit, std::vector slabs) -{ - for (auto slab : slabs) - { - std::string desc = ""; - slab->getItemDescription(&desc, 0); - auto fullName = get_first_name(unit) + " " + get_last_name(unit); - if (desc.find(fullName) != std::string::npos) - return true; - } - - return false; -} - // Queue up a single order to engrave the slab for the given unit static void createSlabJob(df::unit *unit) { @@ -228,7 +210,14 @@ static void checkslabs(color_ostream &out) for (auto ghost : ghosts) { // Only create a job is the map has no existing jobs for that historical figure or no existing engraved slabs - if (histToJob.count(ghost->hist_figure_id) == 0 && !engravedSlabItemExists(ghost, engravedSlabs)) + if (histToJob.count(ghost->hist_figure_id) == 0 && + !std::any_of(engravedSlabs.begin(), + engravedSlabs.end(), + [&ghost](const auto &slab){ + auto slabst = virtual_cast(slab); + return slabst->topic == ghost->hist_figure_id; + }) + ) { createSlabJob(ghost); auto fullName = get_first_name(ghost) + " " + get_last_name(ghost);