Change autoslab to use slab's "topic" field to compare historical id of slab instead of using str comp

develop
John Cosker 2023-02-08 22:05:08 -05:00
parent ef81a91181
commit 5e09a1cbf1
1 changed files with 9 additions and 20 deletions

@ -19,6 +19,7 @@
#include "df/historical_figure.h" #include "df/historical_figure.h"
#include "df/item.h" #include "df/item.h"
#include "df/item_slabst.h"
#include "df/manager_order.h" #include "df/manager_order.h"
#include "df/plotinfost.h" #include "df/plotinfost.h"
#include "df/unit.h" #include "df/unit.h"
@ -168,25 +169,6 @@ static std::string get_last_name(df::unit *unit)
return Translation::capitalize(ret); 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<df::item *> 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 // Queue up a single order to engrave the slab for the given unit
static void createSlabJob(df::unit *unit) static void createSlabJob(df::unit *unit)
{ {
@ -228,7 +210,14 @@ static void checkslabs(color_ostream &out)
for (auto ghost : ghosts) for (auto ghost : ghosts)
{ {
// Only create a job is the map has no existing jobs for that historical figure or no existing engraved slabs // 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<df::item_slabst>(slab);
return slabst->topic == ghost->hist_figure_id;
})
)
{ {
createSlabJob(ghost); createSlabJob(ghost);
auto fullName = get_first_name(ghost) + " " + get_last_name(ghost); auto fullName = get_first_name(ghost) + " " + get_last_name(ghost);