1 #include <QtConcurrent/QtConcurrent>
58 Q_ASSERT(messageManager != NULL);
59 Q_ASSERT(scriptManager != NULL);
94 if (
item->animation &&
item->animation !=
arch->clone.animation)
106 if (!
item->slaying) {
112 if (strcmp(
item->slaying,
"/!"))
119 start = strstr(
item->msg,
"\nfinal_map ");
120 if (!
start && strncmp(
item->msg,
"final_map", strlen(
"final_map")) == 0)
124 const char *end = strchr(
start+1,
'\n');
126 start += strlen(
"final_map")+2;
135 char exit_path[500], tmppath[
MAX_BUF];
138 if (!QFileInfo(tmppath).exists()) {
139 printf(
" map %s doesn't exist in map %s, at %d, %d.\n", ep,
env->map->path,
env->x,
env->y);
141 QString exit = exit_path;
152 add_map(link, &info->exits_from);
153 add_map(info, &link->exits_to);
158 if (link && link !=
m) {
199 QFileInfo info(tmppath);
207 if (!information->
mapTime().isNull() && information->
mapTime() >= info.lastModified())
209 foreach(QString exit, information->
exitsTo())
225 if (
m->region != NULL)
233 if (
m->background_music)
237 if (
m->shopitems != NULL)
239 for (
int i = 0; i <
m->shopitems[0].index; i++)
241 information->
shopItems().insert(QString(
m->shopitems[i].name == NULL ?
"*" :
m->shopitems[i].name),
m->shopitems[i].strength);
244 if (
m->shoprace != NULL)
251 for (
int x = 0;
x < 4;
x++)
252 if (
m->tile_path[
x] != NULL) {
255 if (!QFileInfo(tmppath).exists()) {
256 printf(
" map %s doesn't exist in map %s, for tile %d.\n", exit_path,
m->path,
x);
259 QString exit = exit_path;
280 QMutexLocker lock(&
myLock);
281 if (
m->region == NULL)
282 qDebug() <<
"map without region" <<
m->name <<
m->path;
309 char path[MAX_BUF], name[MAX_BUF];
310 snprintf(name, sizeof(name),
"%s/%s", first_map_ext_path, arch->name);
311 create_pathname(name, path, sizeof(path));
312 if (QFileInfo(path).exists()) {
313 myToProcess.append(name);
320 recurseStyleDirectory(
"styles");
322 while (myCurrentMap < myToProcess.size())
324 process(myToProcess[myCurrentMap]);
332 for (
auto map : myInformation) {
339 qDebug() <<
"experience repartition:";
340 foreach(QString
region, myExperience.keys())
345 qDebug() << myToProcess.size() <<
"maps processed";
356 QMutexLocker lock(&
myLock);
362 QMutexLocker lock(&
myLock);
368 QMutexLocker lock(&
myLock);
374 QMutexLocker lock(&
myLock);
380 QMutexLocker lock(&
myLock);
389 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
390 file.open(QFile::ReadOnly);
392 QXmlStreamReader reader(&
file);
393 bool hasMaps =
false;
396 while (!reader.atEnd())
400 if (reader.isStartElement() && reader.name() ==
"maps")
402 int version = reader.attributes().value(
"version").toString().toInt();
412 if (reader.isStartElement() && reader.name() ==
"map")
417 if (reader.isStartElement() && reader.name() ==
"path")
419 QString
path = reader.readElementText();
425 if (reader.isStartElement() && reader.name() ==
"name")
427 map->setName(reader.readElementText());
430 if (reader.isStartElement() && reader.name() ==
"lastModified")
432 QString
date = reader.readElementText();
433 map->setMapTime(QDateTime::fromString(
date, Qt::ISODate));
436 if (reader.isStartElement() && reader.name() ==
"difficulty")
438 map->setDifficulty(reader.readElementText().toInt());
440 if (reader.isStartElement() && reader.name() ==
"computedDifficulty")
442 map->setComputedDifficulty(reader.readElementText().toInt());
444 if (reader.isStartElement() && reader.name() ==
"experience")
446 map->setExperience(reader.readElementText().toLongLong());
448 if (reader.isStartElement() && reader.name() ==
"region")
450 map->setRegion(reader.readElementText());
452 if (reader.isStartElement() && reader.name() ==
"arch")
454 QString
arch = reader.readElementText();
459 if (reader.isStartElement() && reader.name() ==
"face")
461 QString face = reader.readElementText();
466 if (reader.isStartElement() && reader.name() ==
"animation")
468 QString
anim = reader.readElementText();
473 if (reader.isStartElement() && reader.name() ==
"exitTo")
475 QString
path = reader.readElementText();
479 if (reader.isStartElement() && reader.name() ==
"accessedFrom")
481 QString
path = reader.readElementText();
485 if (reader.isStartElement() && reader.name() ==
"messageFile")
487 QString
file = reader.readElementText();
494 if (reader.isStartElement() && reader.name() ==
"quest")
496 QString code = reader.readElementText();
501 if (reader.isStartElement() && reader.name() ==
"shopItem")
503 QString
item = reader.attributes().value(
"name").toString();
504 int strength = reader.readElementText().toInt();
505 map->shopItems()[
item] = strength;
507 if (reader.isStartElement() && reader.name() ==
"shopGreed")
509 double greed = reader.readElementText().toDouble();
510 map->setShopGreed(greed);
512 if (reader.isStartElement() && reader.name() ==
"shopRace")
514 map->setShopRace(reader.readElementText());
516 if (reader.isStartElement() && reader.name() ==
"shopMin")
518 quint64 min = reader.readElementText().toULongLong();
519 map->setShopMin(min);
521 if (reader.isStartElement() && reader.name() ==
"shopMax")
523 quint64
max = reader.readElementText().toULongLong();
526 if (reader.isStartElement() && reader.name() ==
"script")
528 int x = reader.attributes().value(
"x").toString().toInt();
529 int y = reader.attributes().value(
"x").toString().toInt();
530 QString
item = reader.attributes().value(
"itemName").toString();
531 QString plugin = reader.attributes().value(
"pluginName").toString();
532 QString
event = reader.attributes().value(
"eventName").toString();
533 QString script = reader.readElementText();
536 if (reader.isStartElement() && reader.name() ==
"random_map")
538 int x = reader.attributes().value(
"x").toString().toInt();
539 int y = reader.attributes().value(
"y").toString().toInt();
540 QString
params = reader.attributes().value(
"params").toString();
543 if (reader.isStartElement() && reader.name() ==
"background_music")
545 map->setBackgroundMusic(reader.readElementText());
549 if (reader.isEndElement() && reader.name() ==
"map")
562 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
563 file.open(QFile::WriteOnly | QFile::Truncate);
565 QXmlStreamWriter writer(&
file);
567 writer.setAutoFormatting(
true);
568 writer.writeStartDocument();
570 writer.writeStartElement(
"maps");
571 writer.writeAttribute(
"version",
"1");
576 writer.writeStartElement(
"map");
577 writer.writeTextElement(
"path",
map->path());
578 writer.writeTextElement(
"name",
map->name());
579 writer.writeTextElement(
"lastModified",
map->mapTime().toString(Qt::ISODate));
580 writer.writeTextElement(
"difficulty", QString::number(
map->difficulty()));
581 writer.writeTextElement(
"computedDifficulty", QString::number(
map->computedDifficulty()));
582 writer.writeTextElement(
"experience", QString::number(
map->experience()));
583 writer.writeTextElement(
"region",
map->region());
584 foreach(QString
arch,
map->archetypes())
586 writer.writeTextElement(
"arch",
arch);
588 foreach(QString face,
map->faces())
590 writer.writeTextElement(
"face", face);
592 foreach(QString
anim,
map->animations())
594 writer.writeTextElement(
"animation",
anim);
596 foreach(QString
path,
map->exitsTo())
598 writer.writeTextElement(
"exitTo",
path);
600 foreach(QString
path,
map->accessedFrom())
602 writer.writeTextElement(
"accessedFrom",
path);
604 foreach(QString
file,
map->messages())
606 writer.writeTextElement(
"messageFile",
file);
608 foreach(QString code,
map->quests())
610 writer.writeTextElement(
"quest", code);
612 foreach(QString
item,
map->shopItems().keys())
614 writer.writeStartElement(
"shopItem");
615 writer.writeAttribute(
"name",
item);
616 writer.writeCharacters(QString::number(
map->shopItems()[
item]));
617 writer.writeEndElement();
619 if (
map->shopGreed() != 0)
621 writer.writeTextElement(
"shopGreed", QString::number(
map->shopGreed()));
623 if (!
map->shopRace().isEmpty())
625 writer.writeTextElement(
"shopRace",
map->shopRace());
627 if (
map->shopMin() != 0)
629 writer.writeTextElement(
"shopMin", QString::number(
map->shopMin()));
631 if (
map->shopMax() != 0)
633 writer.writeTextElement(
"shopMax", QString::number(
map->shopMax()));
643 writer.writeStartElement(
"script");
644 writer.writeAttribute(
"x", QString::number(hook->
x()));
645 writer.writeAttribute(
"y", QString::number(hook->
y()));
646 writer.writeAttribute(
"itemName", hook->
itemName());
647 writer.writeAttribute(
"pluginName", hook->
pluginName());
648 writer.writeAttribute(
"eventName", hook->
eventName());
649 writer.writeCharacters(script->
path());
650 writer.writeEndElement();
657 writer.writeStartElement(
"random_map");
658 writer.writeAttribute(
"x", QString::number(random->
x()));
659 writer.writeAttribute(
"y", QString::number(random->
y()));
662 writer.writeAttribute(
"params",
params);
664 writer.writeEndElement();
667 if (!
map->backgroundMusic().isEmpty())
669 writer.writeTextElement(
"background_music",
map->backgroundMusic());
672 writer.writeEndElement();
675 writer.writeEndElement();
677 writer.writeEndDocument();
692 QMutexLocker lock(&
myLock);
699 QMutexLocker lock(&
myLock);
706 QMutexLocker lock(&
myLock);
712 QMutexLocker lock(&
myLock);
720 const QString slaying =
"/python/dialog/npc_dialog.py";
721 const QString
python =
"Python";
738 if (!
path.startsWith(
'/'))
748 qDebug() <<
"missing message file" <<
path <<
"in" <<
map->path();
751 if (QString(
item->slaying).startsWith(
"/python/quests/"))
754 QStringList
split = QString(
item->name).split(
' ', QString::SkipEmptyParts);
755 if (
split.length() > 1)
766 QList<CREMapInformation*>
list;
781 QFile::remove(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
786 QList<RandomMap*>
maps;
789 maps.append(
map->randomMaps());
800 QFileInfoList items = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::DirsFirst);
801 foreach(QFileInfo info, items)
803 QString relative(from + QDir::separator() + info.baseName());