16 #include <QStringList>
17 #include <QMessageBox>
28 #include "AssetsManager.h"
32 #include "ArchetypeWriter.h"
33 #include "QuestWriter.h"
34 #include "MessageWriter.h"
35 #include "TreasureWriter.h"
36 #include "ArtifactWriter.h"
45 myGeneralMessages(new MessageWriter()), myArtifacts(new ArtifactWriter()), myFaces(nullptr), myAnimations(nullptr)
54 QMessageBox::critical(
nullptr,
"Fatal error",
"Error while initializing Crossfire data, make sure you have maps and archetypes correctly installed.");
59 setlocale(LC_NUMERIC,
"C");
61 settings.assets_tracker =
this;
62 add_server_collect_hooks();
63 assets_add_collector_hook(
".LICENSE", [
this] (BufferReader *reader,
const char *filename) {
myLicenseManager.
readLicense(reader, filename); });
64 assets_add_collector_hook(
"", [] (BufferReader *,
const char *) { QCoreApplication::processEvents(); });
66 settings.ignore_assets_errors = 1;
69 bool hasWarningOrError =
false;
70 auto log_callback = [&] (LogLevel logLevel,
const char *format, va_list va) {
71 if (logLevel > llevInfo) {
75 vsnprintf(buf,
sizeof(buf), format, va);
76 QString l(tr(
"%1%2").arg(loglevel_names[logLevel], buf));
78 if (logLevel == llevError) {
79 hasWarningOrError =
true;
82 settings.log_callback = log_callback;
86 settings.fatal_hook =
nullptr;
89 settings.log_callback =
nullptr;
91 if (hasWarningOrError) {
92 QString msg(tr(
"The following errors occurred during asset collection:\n") + log.join(
""));
93 QMessageBox::warning(
nullptr, tr(
"Errors during asset collection!"), msg);
98 for (
int ing = 1; ; ing++)
100 recipelist* list = get_formulalist(ing);
104 QHash<QString, recipe*>
recipes;
105 for (recipe* rec = list->items; rec; rec = rec->next)
107 key = QString(
"%1_%2").arg(rec->arch_name[0], rec->title);
121 if (count < 1 || count >
myRecipes.size())
122 return QStringList();
124 QStringList keys =
myRecipes[count - 1].keys();
131 if (ingredients < 1 || ingredients >
myRecipes.size())
140 getManager()->archetypes()->each([&item, &callback, &goOn] (archetype *arch) {
144 if (arch->clone.other_arch == item)
146 goOn = callback(OTHER_ARCH, arch, nullptr, nullptr, nullptr);
149 sstring death_anim = NULL;
150 if (goOn && (death_anim = object_get_value(&arch->clone,
"death_animation")) && strcmp(death_anim, item->name) == 0)
152 goOn = callback(DEATH_ANIM, arch, nullptr, nullptr, nullptr);
156 getManager()->treasures()->each([&item, callback, &goOn] (treasurelist *list) {
159 for (
auto t = list->items; t; t = t->next)
163 goOn = callback(TREASURE_USE, nullptr, list, nullptr, nullptr);
168 QList<CREMapInformation*> mapuse = store->getArchetypeUse(item);
173 goOn = callback(
MAP_USE,
nullptr,
nullptr, information,
nullptr);
175 auto allMaps = store->allMaps();
182 if (strcmp(item->name, rm->
parameters()->final_exit_archetype) == 0)
193 while ((list = get_formulalist(count++)))
197 recipe* rec = list->items;
200 for (
size_t ing = 0; ing < rec->arch_names; ing++)
202 if (strcmp(rec->arch_name[ing], item->name) == 0)
235 while (!no.empty()) {
236 auto list = no.back();
240 origins, std::vector<std::string>());
241 if (dlg.exec() == QDialog::Accepted) {
245 if (QMessageBox::question(
nullptr, tr(
"Lose changes to treasure list %1?").arg(list->name),
246 tr(
"Really discard changes to treasure list %1?").arg(list->name)) == QMessageBox::Yes) {