13 #include <QtConcurrent/QtConcurrent>
68 Q_ASSERT(messageManager != NULL);
69 Q_ASSERT(scriptManager != NULL);
104 if (
item->animation &&
item->animation !=
arch->clone.animation)
116 if (!
item->slaying) {
122 if (strcmp(
item->slaying,
"/!"))
129 start = strstr(
item->msg,
"\nfinal_map ");
130 if (!
start && strncmp(
item->msg,
"final_map", strlen(
"final_map")) == 0)
134 const char *end = strchr(
start+1,
'\n');
136 start += strlen(
"final_map")+2;
145 char exit_path[500], tmppath[
MAX_BUF];
148 if (!QFileInfo(tmppath).exists()) {
149 printf(
" map %s doesn't exist in map %s, at %d, %d.\n", ep,
env->map->path,
env->x,
env->y);
151 QString exit = exit_path;
162 add_map(link, &info->exits_from);
163 add_map(info, &link->exits_to);
168 if (link && link !=
m) {
209 QFileInfo info(tmppath);
217 if (!information->
mapTime().isNull() && information->
mapTime() >= info.lastModified())
219 foreach(QString exit, information->
exitsTo())
235 if (
m->region != NULL)
243 if (
m->background_music)
247 if (
m->shopitems != NULL)
249 for (
int i = 0; i <
m->shopitems[0].index; i++)
251 information->
shopItems().insert(QString(
m->shopitems[i].name == NULL ?
"*" :
m->shopitems[i].name),
m->shopitems[i].strength);
254 if (
m->shoprace != NULL)
258 information->
setResetGroup(
m->reset_group ?
m->reset_group : QString());
262 for (
int x = 0;
x < 4;
x++)
263 if (
m->tile_path[
x] != NULL) {
266 if (!QFileInfo(tmppath).exists()) {
267 printf(
" map %s doesn't exist in map %s, for tile %d.\n", exit_path,
m->path,
x);
270 QString exit = exit_path;
291 QMutexLocker lock(&
myLock);
292 if (
m->region == NULL)
293 qDebug() <<
"map without region" <<
m->name <<
m->path;
320 char path[MAX_BUF], name[MAX_BUF];
321 snprintf(name, sizeof(name),
"%s/%s", first_map_ext_path, arch->name);
322 create_pathname(name, path, sizeof(path));
323 if (QFileInfo(path).exists()) {
324 myToProcess.append(name);
331 recurseStyleDirectory(
"styles");
333 while (myCurrentMap < myToProcess.size())
335 process(myToProcess[myCurrentMap]);
343 for (
auto map : myInformation) {
350 qDebug() <<
"experience repartition:";
351 foreach(QString
region, myExperience.keys())
356 qDebug() << myToProcess.size() <<
"maps processed";
367 QMutexLocker lock(&
myLock);
373 QMutexLocker lock(&
myLock);
379 QMutexLocker lock(&
myLock);
385 QMutexLocker lock(&
myLock);
391 QMutexLocker lock(&
myLock);
400 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
401 file.open(QFile::ReadOnly);
403 QXmlStreamReader reader(&
file);
404 bool hasMaps =
false;
407 while (!reader.atEnd())
411 if (reader.isStartElement() && reader.name() ==
"maps")
413 int version = reader.attributes().value(
"version").toString().toInt();
423 if (reader.isStartElement() && reader.name() ==
"map")
428 if (reader.isStartElement() && reader.name() ==
"path")
430 QString
path = reader.readElementText();
436 if (reader.isStartElement() && reader.name() ==
"name")
438 map->setName(reader.readElementText());
441 if (reader.isStartElement() && reader.name() ==
"lastModified")
443 QString
date = reader.readElementText();
444 map->setMapTime(QDateTime::fromString(
date, Qt::ISODate));
447 if (reader.isStartElement() && reader.name() ==
"difficulty")
449 map->setDifficulty(reader.readElementText().toInt());
451 if (reader.isStartElement() && reader.name() ==
"computedDifficulty")
453 map->setComputedDifficulty(reader.readElementText().toInt());
455 if (reader.isStartElement() && reader.name() ==
"experience")
457 map->setExperience(reader.readElementText().toLongLong());
459 if (reader.isStartElement() && reader.name() ==
"region")
461 map->setRegion(reader.readElementText());
463 if (reader.isStartElement() && reader.name() ==
"arch")
465 QString
arch = reader.readElementText();
470 if (reader.isStartElement() && reader.name() ==
"face")
472 QString face = reader.readElementText();
477 if (reader.isStartElement() && reader.name() ==
"animation")
479 QString
anim = reader.readElementText();
484 if (reader.isStartElement() && reader.name() ==
"exitTo")
486 QString
path = reader.readElementText();
490 if (reader.isStartElement() && reader.name() ==
"accessedFrom")
492 QString
path = reader.readElementText();
496 if (reader.isStartElement() && reader.name() ==
"messageFile")
498 QString
file = reader.readElementText();
505 if (reader.isStartElement() && reader.name() ==
"quest")
507 QString code = reader.readElementText();
512 if (reader.isStartElement() && reader.name() ==
"shopItem")
514 QString
item = reader.attributes().value(
"name").toString();
515 int strength = reader.readElementText().toInt();
516 map->shopItems()[
item] = strength;
518 if (reader.isStartElement() && reader.name() ==
"shopGreed")
520 double greed = reader.readElementText().toDouble();
521 map->setShopGreed(greed);
523 if (reader.isStartElement() && reader.name() ==
"shopRace")
525 map->setShopRace(reader.readElementText());
527 if (reader.isStartElement() && reader.name() ==
"shopMin")
529 quint64 min = reader.readElementText().toULongLong();
530 map->setShopMin(min);
532 if (reader.isStartElement() && reader.name() ==
"shopMax")
534 quint64
max = reader.readElementText().toULongLong();
537 if (reader.isStartElement() && reader.name() ==
"script")
539 int x = reader.attributes().value(
"x").toString().toInt();
540 int y = reader.attributes().value(
"x").toString().toInt();
541 QString
item = reader.attributes().value(
"itemName").toString();
542 QString plugin = reader.attributes().value(
"pluginName").toString();
543 QString
event = reader.attributes().value(
"eventName").toString();
544 QString script = reader.readElementText();
547 if (reader.isStartElement() && reader.name() ==
"random_map")
549 int x = reader.attributes().value(
"x").toString().toInt();
550 int y = reader.attributes().value(
"y").toString().toInt();
551 QString
params = reader.attributes().value(
"params").toString();
554 if (reader.isStartElement() && reader.name() ==
"background_music")
556 map->setBackgroundMusic(reader.readElementText());
559 if (reader.isStartElement() && reader.name() ==
"reset_group")
561 map->setResetGroup(reader.readElementText());
565 if (reader.isEndElement() && reader.name() ==
"map")
578 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
579 file.open(QFile::WriteOnly | QFile::Truncate);
581 QXmlStreamWriter writer(&
file);
583 writer.setAutoFormatting(
true);
584 writer.writeStartDocument();
586 writer.writeStartElement(
"maps");
587 writer.writeAttribute(
"version",
"1");
592 writer.writeStartElement(
"map");
593 writer.writeTextElement(
"path",
map->path());
594 writer.writeTextElement(
"name",
map->name());
595 writer.writeTextElement(
"lastModified",
map->mapTime().toString(Qt::ISODate));
596 writer.writeTextElement(
"difficulty", QString::number(
map->difficulty()));
597 writer.writeTextElement(
"computedDifficulty", QString::number(
map->computedDifficulty()));
598 writer.writeTextElement(
"experience", QString::number(
map->experience()));
599 writer.writeTextElement(
"region",
map->region());
600 foreach(QString
arch,
map->archetypes())
602 writer.writeTextElement(
"arch",
arch);
604 foreach(QString face,
map->faces())
606 writer.writeTextElement(
"face", face);
608 foreach(QString
anim,
map->animations())
610 writer.writeTextElement(
"animation",
anim);
612 foreach(QString
path,
map->exitsTo())
614 writer.writeTextElement(
"exitTo",
path);
616 foreach(QString
path,
map->accessedFrom())
618 writer.writeTextElement(
"accessedFrom",
path);
620 foreach(QString
file,
map->messages())
622 writer.writeTextElement(
"messageFile",
file);
624 foreach(QString code,
map->quests())
626 writer.writeTextElement(
"quest", code);
628 foreach(QString
item,
map->shopItems().keys())
630 writer.writeStartElement(
"shopItem");
631 writer.writeAttribute(
"name",
item);
632 writer.writeCharacters(QString::number(
map->shopItems()[
item]));
633 writer.writeEndElement();
635 if (
map->shopGreed() != 0)
637 writer.writeTextElement(
"shopGreed", QString::number(
map->shopGreed()));
639 if (!
map->shopRace().isEmpty())
641 writer.writeTextElement(
"shopRace",
map->shopRace());
643 if (
map->shopMin() != 0)
645 writer.writeTextElement(
"shopMin", QString::number(
map->shopMin()));
647 if (
map->shopMax() != 0)
649 writer.writeTextElement(
"shopMax", QString::number(
map->shopMax()));
659 writer.writeStartElement(
"script");
660 writer.writeAttribute(
"x", QString::number(hook->
x()));
661 writer.writeAttribute(
"y", QString::number(hook->
y()));
662 writer.writeAttribute(
"itemName", hook->
itemName());
663 writer.writeAttribute(
"pluginName", hook->
pluginName());
664 writer.writeAttribute(
"eventName", hook->
eventName());
665 writer.writeCharacters(script->
path());
666 writer.writeEndElement();
673 writer.writeStartElement(
"random_map");
674 writer.writeAttribute(
"x", QString::number(random->
x()));
675 writer.writeAttribute(
"y", QString::number(random->
y()));
678 writer.writeAttribute(
"params",
params);
680 writer.writeEndElement();
683 if (!
map->backgroundMusic().isEmpty())
685 writer.writeTextElement(
"background_music",
map->backgroundMusic());
687 if (!
map->resetGroup().isEmpty())
689 writer.writeTextElement(
"reset_group",
map->resetGroup());
692 writer.writeEndElement();
695 writer.writeEndElement();
697 writer.writeEndDocument();
712 QMutexLocker lock(&
myLock);
719 QMutexLocker lock(&
myLock);
726 QMutexLocker lock(&
myLock);
732 QMutexLocker lock(&
myLock);
740 const QString slaying =
"/python/dialog/npc_dialog.py";
741 const QString
python =
"Python";
758 if (!
path.startsWith(
'/'))
768 qDebug() <<
"missing message file" <<
path <<
"in" <<
map->path();
771 if (QString(
item->slaying).startsWith(
"/python/quests/"))
774 QStringList
split = QString(
item->name).split(
' ', QString::SkipEmptyParts);
775 if (
split.length() > 1)
786 QList<CREMapInformation*>
list;
801 QFile::remove(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
806 QList<RandomMap*>
maps;
809 maps.append(
map->randomMaps());
820 QFileInfoList items = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::DirsFirst);
821 foreach(QFileInfo info, items)
823 QString relative(from + QDir::separator() + info.baseName());