13 #include <QtConcurrent/QtConcurrent>
70 Q_ASSERT(messageManager != NULL);
71 Q_ASSERT(scriptManager != NULL);
106 if (
item->animation &&
item->animation !=
arch->clone.animation)
118 if (!
item->slaying) {
124 if (strcmp(
item->slaying,
"/!"))
131 start = strstr(
item->msg,
"\nfinal_map ");
132 if (!
start && strncmp(
item->msg,
"final_map", strlen(
"final_map")) == 0)
136 const char *end = strchr(
start+1,
'\n');
138 start += strlen(
"final_map")+2;
147 char exit_path[500], tmppath[
MAX_BUF];
150 if (!QFileInfo(tmppath).exists()) {
151 printf(
" map %s doesn't exist in map %s, at %d, %d.\n", ep,
env->map->path,
env->x,
env->y);
153 QString exit = exit_path;
164 add_map(link, &info->exits_from);
165 add_map(info, &link->exits_to);
170 if (link && link !=
m) {
211 QFileInfo info(tmppath);
219 if (!information->
mapTime().isNull() && information->
mapTime() >= info.lastModified())
221 foreach(QString exit, information->
exitsTo())
237 if (
m->region != NULL)
245 if (
m->background_music)
249 if (
m->shopitems != NULL)
251 for (
int i = 0; i <
m->shopitems[0].index; i++)
253 information->
shopItems().insert(QString(
m->shopitems[i].name == NULL ?
"*" :
m->shopitems[i].name),
m->shopitems[i].strength);
256 if (
m->shoprace != NULL)
263 for (
int x = 0;
x < 4;
x++)
264 if (
m->tile_path[
x] != NULL) {
267 if (!QFileInfo(tmppath).exists()) {
268 printf(
" map %s doesn't exist in map %s, for tile %d.\n", exit_path,
m->path,
x);
271 QString exit = exit_path;
292 QMutexLocker lock(&
myLock);
293 if (
m->region == NULL)
294 qDebug() <<
"map without region" <<
m->name <<
m->path;
321 char path[MAX_BUF], name[MAX_BUF];
322 snprintf(name, sizeof(name),
"%s/%s", first_map_ext_path, arch->name);
323 create_pathname(name, path, sizeof(path));
324 if (QFileInfo(path).exists()) {
325 myToProcess.append(name);
332 recurseStyleDirectory(
"styles");
334 while (myCurrentMap < myToProcess.size())
336 process(myToProcess[myCurrentMap]);
344 for (
auto map : myInformation) {
351 qDebug() <<
"experience repartition:";
352 foreach(QString
region, myExperience.keys())
357 qDebug() << myToProcess.size() <<
"maps processed";
368 QMutexLocker lock(&
myLock);
374 QMutexLocker lock(&
myLock);
380 QMutexLocker lock(&
myLock);
386 QMutexLocker lock(&
myLock);
392 QMutexLocker lock(&
myLock);
401 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
402 file.open(QFile::ReadOnly);
404 QXmlStreamReader reader(&
file);
405 bool hasMaps =
false;
408 while (!reader.atEnd())
412 if (reader.isStartElement() && reader.name() ==
"maps")
414 int version = reader.attributes().value(
"version").toString().toInt();
424 if (reader.isStartElement() && reader.name() ==
"map")
429 if (reader.isStartElement() && reader.name() ==
"path")
431 QString
path = reader.readElementText();
437 if (reader.isStartElement() && reader.name() ==
"name")
439 map->setName(reader.readElementText());
442 if (reader.isStartElement() && reader.name() ==
"lastModified")
444 QString
date = reader.readElementText();
445 map->setMapTime(QDateTime::fromString(
date, Qt::ISODate));
448 if (reader.isStartElement() && reader.name() ==
"difficulty")
450 map->setDifficulty(reader.readElementText().toInt());
452 if (reader.isStartElement() && reader.name() ==
"computedDifficulty")
454 map->setComputedDifficulty(reader.readElementText().toInt());
456 if (reader.isStartElement() && reader.name() ==
"experience")
458 map->setExperience(reader.readElementText().toLongLong());
460 if (reader.isStartElement() && reader.name() ==
"region")
462 map->setRegion(reader.readElementText());
464 if (reader.isStartElement() && reader.name() ==
"arch")
466 QString
arch = reader.readElementText();
471 if (reader.isStartElement() && reader.name() ==
"face")
473 QString face = reader.readElementText();
478 if (reader.isStartElement() && reader.name() ==
"animation")
480 QString
anim = reader.readElementText();
485 if (reader.isStartElement() && reader.name() ==
"exitTo")
487 QString
path = reader.readElementText();
491 if (reader.isStartElement() && reader.name() ==
"accessedFrom")
493 QString
path = reader.readElementText();
497 if (reader.isStartElement() && reader.name() ==
"messageFile")
499 QString
file = reader.readElementText();
506 if (reader.isStartElement() && reader.name() ==
"quest")
508 QString code = reader.readElementText();
513 if (reader.isStartElement() && reader.name() ==
"shopItem")
515 QString
item = reader.attributes().value(
"name").toString();
516 int strength = reader.readElementText().toInt();
517 map->shopItems()[
item] = strength;
519 if (reader.isStartElement() && reader.name() ==
"shopGreed")
521 double greed = reader.readElementText().toDouble();
522 map->setShopGreed(greed);
524 if (reader.isStartElement() && reader.name() ==
"shopRace")
526 map->setShopRace(reader.readElementText());
528 if (reader.isStartElement() && reader.name() ==
"shopMin")
530 quint64 min = reader.readElementText().toULongLong();
531 map->setShopMin(min);
533 if (reader.isStartElement() && reader.name() ==
"shopMax")
535 quint64
max = reader.readElementText().toULongLong();
538 if (reader.isStartElement() && reader.name() ==
"script")
540 int x = reader.attributes().value(
"x").toString().toInt();
541 int y = reader.attributes().value(
"x").toString().toInt();
542 QString
item = reader.attributes().value(
"itemName").toString();
543 QString plugin = reader.attributes().value(
"pluginName").toString();
544 QString
event = reader.attributes().value(
"eventName").toString();
545 QString script = reader.readElementText();
548 if (reader.isStartElement() && reader.name() ==
"random_map")
550 int x = reader.attributes().value(
"x").toString().toInt();
551 int y = reader.attributes().value(
"y").toString().toInt();
552 QString
params = reader.attributes().value(
"params").toString();
555 if (reader.isStartElement() && reader.name() ==
"background_music")
557 map->setBackgroundMusic(reader.readElementText());
561 if (reader.isEndElement() && reader.name() ==
"map")
574 QFile
file(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
575 file.open(QFile::WriteOnly | QFile::Truncate);
577 QXmlStreamWriter writer(&
file);
579 writer.setAutoFormatting(
true);
580 writer.writeStartDocument();
582 writer.writeStartElement(
"maps");
583 writer.writeAttribute(
"version",
"1");
588 writer.writeStartElement(
"map");
589 writer.writeTextElement(
"path",
map->path());
590 writer.writeTextElement(
"name",
map->name());
591 writer.writeTextElement(
"lastModified",
map->mapTime().toString(Qt::ISODate));
592 writer.writeTextElement(
"difficulty", QString::number(
map->difficulty()));
593 writer.writeTextElement(
"computedDifficulty", QString::number(
map->computedDifficulty()));
594 writer.writeTextElement(
"experience", QString::number(
map->experience()));
595 writer.writeTextElement(
"region",
map->region());
596 foreach(QString
arch,
map->archetypes())
598 writer.writeTextElement(
"arch",
arch);
600 foreach(QString face,
map->faces())
602 writer.writeTextElement(
"face", face);
604 foreach(QString
anim,
map->animations())
606 writer.writeTextElement(
"animation",
anim);
608 foreach(QString
path,
map->exitsTo())
610 writer.writeTextElement(
"exitTo",
path);
612 foreach(QString
path,
map->accessedFrom())
614 writer.writeTextElement(
"accessedFrom",
path);
616 foreach(QString
file,
map->messages())
618 writer.writeTextElement(
"messageFile",
file);
620 foreach(QString code,
map->quests())
622 writer.writeTextElement(
"quest", code);
624 foreach(QString
item,
map->shopItems().keys())
626 writer.writeStartElement(
"shopItem");
627 writer.writeAttribute(
"name",
item);
628 writer.writeCharacters(QString::number(
map->shopItems()[
item]));
629 writer.writeEndElement();
631 if (
map->shopGreed() != 0)
633 writer.writeTextElement(
"shopGreed", QString::number(
map->shopGreed()));
635 if (!
map->shopRace().isEmpty())
637 writer.writeTextElement(
"shopRace",
map->shopRace());
639 if (
map->shopMin() != 0)
641 writer.writeTextElement(
"shopMin", QString::number(
map->shopMin()));
643 if (
map->shopMax() != 0)
645 writer.writeTextElement(
"shopMax", QString::number(
map->shopMax()));
655 writer.writeStartElement(
"script");
656 writer.writeAttribute(
"x", QString::number(hook->
x()));
657 writer.writeAttribute(
"y", QString::number(hook->
y()));
658 writer.writeAttribute(
"itemName", hook->
itemName());
659 writer.writeAttribute(
"pluginName", hook->
pluginName());
660 writer.writeAttribute(
"eventName", hook->
eventName());
661 writer.writeCharacters(script->
path());
662 writer.writeEndElement();
669 writer.writeStartElement(
"random_map");
670 writer.writeAttribute(
"x", QString::number(random->
x()));
671 writer.writeAttribute(
"y", QString::number(random->
y()));
674 writer.writeAttribute(
"params",
params);
676 writer.writeEndElement();
679 if (!
map->backgroundMusic().isEmpty())
681 writer.writeTextElement(
"background_music",
map->backgroundMusic());
684 writer.writeEndElement();
687 writer.writeEndElement();
689 writer.writeEndDocument();
704 QMutexLocker lock(&
myLock);
711 QMutexLocker lock(&
myLock);
718 QMutexLocker lock(&
myLock);
724 QMutexLocker lock(&
myLock);
732 const QString slaying =
"/python/dialog/npc_dialog.py";
733 const QString
python =
"Python";
750 if (!
path.startsWith(
'/'))
760 qDebug() <<
"missing message file" <<
path <<
"in" <<
map->path();
763 if (QString(
item->slaying).startsWith(
"/python/quests/"))
766 QStringList
split = QString(
item->name).split(
' ', QString::SkipEmptyParts);
767 if (
split.length() > 1)
778 QList<CREMapInformation*>
list;
793 QFile::remove(
settings.mapCacheDirectory() + QDir::separator() +
"maps_cache.xml");
798 QList<RandomMap*>
maps;
801 maps.append(
map->randomMaps());
812 QFileInfoList items = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot, QDir::DirsFirst);
813 foreach(QFileInfo info, items)
815 QString relative(from + QDir::separator() + info.baseName());