Renamed to getBookTitle, cut down on virtual_cast

develop
PatrikLundell 2020-01-25 21:46:10 +01:00
parent c6bbf39c6c
commit 876ac6c056
3 changed files with 34 additions and 28 deletions

@ -162,7 +162,7 @@ DFHACK_EXPORT df::coord getPosition(df::item *item);
/// Returns the title of a codex or "tool", either as the codex title or as the title of the
/// first page or writing it has that has a non blank title. An empty string is returned if
/// no title is found (which is the casee for everything that isn't a "book").
DFHACK_EXPORT std::string getTitle(df::item *item);
DFHACK_EXPORT std::string getBookTitle(df::item *item);
/// Returns the description string of the item.
DFHACK_EXPORT std::string getDescription(df::item *item, int type = 0, bool decorate = false);

@ -688,7 +688,7 @@ static void addQuality(std::string &tmp, int quality)
}
// It's not impossible the functionality of this operation is provided by one of the unmapped item functions.
std::string Items::getTitle(df::item *item)
std::string Items::getBookTitle(df::item *item)
{
CHECK_NULL_POINTER(item);
@ -696,30 +696,32 @@ std::string Items::getTitle(df::item *item)
if (item->getType() == df::item_type::BOOK)
{
if (virtual_cast<df::item_bookst>(item)->title != "")
auto book = virtual_cast<df::item_bookst>(item);
if (book->title != "")
{
return virtual_cast<df::item_bookst>(item)->title;
return book->title;
}
else
{
for (size_t i = 0; i < virtual_cast<df::item_bookst>(item)->improvements.size(); i++)
for (size_t i = 0; i < book->improvements.size(); i++)
{
if (virtual_cast<df::item_bookst>(item)->improvements[i]->getType() == df::improvement_type::PAGES)
if (auto page = virtual_cast<df::itemimprovement_pagesst>(book->improvements[i]))
{
for (size_t k = 0; k < virtual_cast<df::itemimprovement_pagesst>(virtual_cast<df::item_bookst>(item)->improvements[i])->contents.size(); k++)
for (size_t k = 0; k < page->contents.size(); k++)
{
df::written_content *contents = world->written_contents.all[virtual_cast<df::itemimprovement_pagesst>(virtual_cast<df::item_bookst>(item)->improvements[i])->contents[k]];
df::written_content *contents = world->written_contents.all[page->contents[k]];
if (contents->title != "")
{
return contents->title;
}
}
}
else if (virtual_cast<df::item_bookst>(item)->improvements[i]->getType() == df::improvement_type::WRITING)
else if (auto writing = virtual_cast<df::itemimprovement_writingst>(book->improvements[i]))
{
for (size_t k = 0; k < virtual_cast<df::itemimprovement_writingst>(virtual_cast<df::item_bookst>(item)->improvements[i])->contents.size(); k++)
for (size_t k = 0; k < writing->contents.size(); k++)
{
df::written_content *contents = world->written_contents.all[virtual_cast<df::itemimprovement_writingst>(virtual_cast<df::item_bookst>(item)->improvements[i])->contents[k]];
df::written_content *contents = world->written_contents.all[writing->contents[k]];
if (contents->title != "")
{
return contents->title;
@ -729,30 +731,34 @@ std::string Items::getTitle(df::item *item)
}
}
}
else if (item->getType() == df::item_type::TOOL &&
virtual_cast<df::item_toolst>(item)->hasToolUse(df::tool_uses::CONTAIN_WRITING))
else if (item->getType() == df::item_type::TOOL)
{
for (size_t i = 0; i < virtual_cast<df::item_toolst>(item)->improvements.size(); i++)
auto book = virtual_cast<df::item_toolst>(item);
if (book->hasToolUse(df::tool_uses::CONTAIN_WRITING))
{
if (virtual_cast<df::item_toolst>(item)->improvements[i]->getType() == df::improvement_type::PAGES)
for (size_t i = 0; i < book->improvements.size(); i++)
{
for (size_t k = 0; k < virtual_cast<df::itemimprovement_pagesst>(virtual_cast<df::item_toolst>(item)->improvements[i])->contents.size(); k++)
if (auto page = virtual_cast<df::itemimprovement_pagesst>(book->improvements[i]))
{
df::written_content *contents = world->written_contents.all[virtual_cast<df::itemimprovement_pagesst>(virtual_cast<df::item_toolst>(item)->improvements[i])->contents[k]];
if (contents->title != "")
for (size_t k = 0; k < page->contents.size(); k++)
{
return contents->title;
df::written_content *contents = world->written_contents.all[page->contents[k]];
if (contents->title != "")
{
return contents->title;
}
}
}
}
else if (virtual_cast<df::item_toolst>(item)->improvements[i]->getType() == df::improvement_type::WRITING)
{
for (size_t k = 0; k < virtual_cast<df::itemimprovement_writingst>(virtual_cast<df::item_toolst>(item)->improvements[i])->contents.size(); k++)
else if (auto writing = virtual_cast<df::itemimprovement_writingst>(book->improvements[i]))
{
df::written_content *contents = world->written_contents.all[virtual_cast<df::itemimprovement_writingst>(virtual_cast<df::item_toolst>(item)->improvements[i])->contents[k]];
if (contents->title != "")
for (size_t k = 0; k < writing->contents.size(); k++)
{
return contents->title;
df::written_content *contents = world->written_contents.all[writing->contents[k]];
if (contents->title != "")
{
return contents->title;
}
}
}
}

@ -248,7 +248,7 @@ static string get_keywords(df::item *item)
static string get_item_label(df::item *item, bool trim = false)
{
auto label = Items::getTitle(item);
auto label = Items::getBookTitle(item);
if (label == "")
{
label = Items::getDescription(item, 0, false);
@ -566,7 +566,7 @@ class StockListColumn : public ListColumn<T>
if (!ListColumn<T>::showEntry(entry, search_tokens))
return false;
string item_name = toLower(Items::getTitle(entry->elem->entries[0]));
string item_name = toLower(Items::getBookTitle(entry->elem->entries[0]));
if (item_name == "")
{
item_name = toLower(Items::getDescription(entry->elem->entries[0], 0, false));