void QuestDb::loadXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc.rootNode(); if (root == nullptr) return; for_each_xml_child_node(varNode, root) { if (xmlNameEqual(varNode, "include")) { const std::string name = XML::getProperty(varNode, "name", ""); if (!name.empty()) loadXmlFile(name, skipError); continue; } else if (xmlNameEqual(varNode, "var")) { const int id = XML::getProperty(varNode, "id", 0); if (id < 0) continue; mVars[id] = QuestVar(); for_each_xml_child_node(questNode, varNode) { if (xmlNameEqual(questNode, "quest")) loadQuest(id, questNode); else if (xmlNameEqual(questNode, "effect")) loadEffect(id, questNode); } } } }
void readXmlIntVector(const std::string &fileName, const std::string &rootName, const std::string §ionName, const std::string &itemName, const std::string &attributeName, std::vector<int> &arr) { arr.clear(); XML::Document doc(fileName, UseResman_true, SkipError_false); const XmlNodePtrConst rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, rootName.c_str())) { logger->log("Error while loading %s!", fileName.c_str()); return; } for_each_xml_child_node(sectionNode, rootNode) { if (!xmlNameEqual(sectionNode, sectionName.c_str())) continue; for_each_xml_child_node(childNode, sectionNode) { if (!xmlNameEqual(childNode, itemName.c_str())) continue; const int val = XML::getProperty(childNode, attributeName.c_str(), -1); if (val == -1) continue; arr.push_back(val); } } }
static EffectDescription *getEffectDescription(int effectId) { if (!effects_initialized) { XML::Document doc(EFFECTS_FILE); XmlNodePtr root = doc.rootNode(); if (!root || !xmlNameEqual(root, "being-effects")) { logger->log1("Error loading being effects file: " EFFECTS_FILE); return nullptr; } for_each_xml_child_node(node, root) { int id; if (xmlNameEqual(node, "effect")) { EffectDescription *EffectDescription = getEffectDescription(node, &id); effects[id] = EffectDescription; } else if (xmlNameEqual(node, "default")) { EffectDescription *effectDescription = getEffectDescription(node, &id); delete default_effect; default_effect = effectDescription; } }
void QuestsWindow::loadXmlFile(const std::string &fileName) { XML::Document doc(fileName); const XmlNodePtrConst root = doc.rootNode(); if (!root) return; for_each_xml_child_node(varNode, root) { if (xmlNameEqual(varNode, "include")) { const std::string name = XML::getProperty(varNode, "name", ""); if (!name.empty()) loadXmlFile(name); continue; } else if (xmlNameEqual(varNode, "var")) { const int id = XML::getProperty(varNode, "id", 0); if (id < 0) continue; for_each_xml_child_node(questNode, varNode) { if (xmlNameEqual(questNode, "quest")) loadQuest(id, questNode); else if (xmlNameEqual(questNode, "effect")) loadEffect(id, questNode); } } } }
void SoundDB::loadXmlFile(const std::string &fileName) { XML::Document *doc = new XML::Document(fileName); const XmlNodePtrConst root = doc->rootNode(); if (!root || !xmlNameEqual(root, "sounds")) { delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadXmlFile(name); continue; } else if (xmlNameEqual(node, "sound")) { const std::string name = XML::getProperty(node, "name", ""); const int id = NotifyManager::getIndexBySound(name); if (id) { const std::string value = XML::getProperty(node, "value", ""); mSounds[id] = value; } } } delete doc; }
void MapDB::loadInfo(const std::string &fileName, const SkipError skipError) { XML::Document *doc = new XML::Document(fileName, UseResman_true, skipError); const XmlNodePtrConst root = doc->rootNode(); if (!root) { delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "map")) { readMap(node); } else if (xmlNameEqual(node, "atlas")) { readAtlas(node); } else if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadInfo(name, skipError); continue; } } delete doc; }
void StatDb::loadXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "stats")) { logger->log("StatDb: Error while loading %s!", fileName.c_str()); if (skipError == SkipError_false) addDefaultStats(); return; } for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadXmlFile(name, skipError); continue; } else if (xmlNameEqual(node, "basic")) { loadBasicStats(node); } else if (xmlNameEqual(node, "extended")) { // TRANSLATORS: stats page name loadStats(node, _("Extended")); } else if (xmlNameEqual(node, "page")) { std::string page = XML::langProperty(node, "name", ""); if (page.empty()) { reportAlways("Page without name in stats.xml"); page = "Unknown"; } loadStats(node, page); } } if (skipError == SkipError_false) { if (mBasicStats.empty() && mStats.empty()) { reportAlways("StatDb: no stats found"); addDefaultStats(); } } }
void readXmlStringMap(const std::string &fileName, const std::string &rootName, const std::string §ionName, const std::string &itemName, const std::string &attributeKeyName, const std::string &attributeValueName, std::map<std::string, std::string> &arr, const SkipError skipError) { XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); if (rootNode == nullptr || !xmlNameEqual(rootNode, rootName.c_str())) { logger->log("Error while loading %s!", fileName.c_str()); return; } for_each_xml_child_node(sectionNode, rootNode) { if (!xmlNameEqual(sectionNode, sectionName.c_str())) continue; for_each_xml_child_node(childNode, sectionNode) { if (xmlNameEqual(childNode, itemName.c_str())) { const std::string key = XML::getProperty(childNode, attributeKeyName.c_str(), ""); if (key.empty()) continue; const std::string val = XML::getProperty(childNode, attributeValueName.c_str(), ""); arr[key] = val; } else if (xmlNameEqual(childNode, "include")) { const std::string name = XML::getProperty( childNode, "name", ""); if (!name.empty()) { readXmlStringMap(name, rootName, sectionName, itemName, attributeKeyName, attributeValueName, arr, skipError); } } } } }
/** * Load the given file into a vector of updateFiles. */ static std::vector<UpdateFile> loadXMLFile(const std::string &fileName, const bool loadMods) { std::vector<UpdateFile> files; XML::Document doc(fileName, false, false); const XmlNodePtrConst rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "updates")) { logger->log("Error loading update file: %s", fileName.c_str()); return files; } for_each_xml_child_node(fileNode, rootNode) { const bool isMod = xmlNameEqual(fileNode, "mod"); if (!xmlNameEqual(fileNode, "update") && !isMod) continue; UpdateFile file; file.name = XML::getProperty(fileNode, "file", ""); file.hash = XML::getProperty(fileNode, "hash", ""); file.type = XML::getProperty(fileNode, "type", "data"); file.desc = XML::getProperty(fileNode, "description", ""); file.group = XML::getProperty(fileNode, "group", ""); if (!file.group.empty() && (!isMod || !loadMods)) continue; const std::string version = XML::getProperty( fileNode, "version", ""); if (!version.empty()) { if (version > CHECK_VERSION) continue; } const std::string notVersion = XML::getProperty( fileNode, "notVersion", ""); if (!notVersion.empty()) { if (notVersion <= CHECK_VERSION) continue; } if (XML::getProperty(fileNode, "required", "yes") == "yes") file.required = true; else file.required = false; if (checkPath(file.name)) files.push_back(file); } return files; }
void readXmlIntVector(const std::string &fileName, const std::string &rootName, const std::string §ionName, const std::string &itemName, const std::string &attributeName, STD_VECTOR<int> &arr, const SkipError skipError) { XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); if (rootNode == nullptr || !xmlNameEqual(rootNode, rootName.c_str())) { logger->log("Error while loading %s!", fileName.c_str()); return; } for_each_xml_child_node(sectionNode, rootNode) { if (!xmlNameEqual(sectionNode, sectionName.c_str())) continue; for_each_xml_child_node(childNode, sectionNode) { if (xmlNameEqual(childNode, itemName.c_str())) { const int val = XML::getProperty(childNode, attributeName.c_str(), -1); if (val == -1) continue; arr.push_back(val); } else if (xmlNameEqual(childNode, "include")) { const std::string name = XML::getProperty( childNode, "name", ""); if (!name.empty()) { readXmlIntVector(name, rootName, sectionName, itemName, attributeName, arr, skipError); } } } } }
void MapDB::readAtlas(XmlNodePtrConst node) { if (!node) return; const std::string atlas = XML::getProperty(node, "name", ""); if (atlas.empty()) return; for_each_xml_child_node(childNode, node) { if (xmlNameEqual(childNode, "file")) { const std::string file = XML::getProperty(childNode, "name", ""); if (file.empty()) continue; mAtlases[atlas].push_back(file); } } if (atlas != "all") { const AtlasCIter &allAtlas = mAtlases.find("all"); if (allAtlas != mAtlases.end()) { FOR_EACH (StringVectCIter, it, (*allAtlas).second) mAtlases[atlas].push_back(*it); } } }
static void loadBasicStats(XmlNodeConstPtr rootNode) { const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE); for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "stat")) { const std::string name = XML::getProperty(node, "name", ""); const std::string attr = XML::getProperty(node, "attr", ""); if (attr.empty() || AttributesEnum::find(attr) == false) { const int id = XML::getProperty(node, "id", 0); if (id <= 0 || id >= maxAttr) { reportAlways("Wrong attr or id for basic " "stat with name %s", name.c_str()); continue; } const std::string tag = XML::getProperty(node, "tag", ""); mBasicStats.push_back(BasicStat(static_cast<AttributesT>(id), tag, name)); } else { const std::string tag = XML::getProperty(node, "tag", ""); mBasicStats.push_back(BasicStat(AttributesEnum::get(attr), tag, name)); } } } }
static void loadStats(XmlNodeConstPtr rootNode, const std::string &page) { const int maxAttr = static_cast<int>(Attributes::MAX_ATTRIBUTE); STD_VECTOR<BasicStat> &stats = mStats[page]; mPages.push_back(page); for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "stat")) { const std::string name = XML::getProperty(node, "name", ""); const std::string attr = XML::getProperty(node, "attr", ""); if (attr.empty() || AttributesEnum::find(attr) == false) { const int id = XML::getProperty(node, "id", 0); if (id <= 0 || id >= maxAttr) { reportAlways("Wrong attr or id for extended " "stat with name %s", name.c_str()); continue; } stats.push_back(BasicStat(static_cast<AttributesT>(id), std::string(), name)); } else { stats.push_back(BasicStat(AttributesEnum::get(attr), std::string(), name)); } } } }
SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) { size_t pos = animationFile.find('|'); std::string palettes; if (pos != std::string::npos) palettes = animationFile.substr(pos + 1); XML::Document doc(animationFile.substr(0, pos)); XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "sprite")) { logger->log("Error, failed to parse %s", animationFile.c_str()); std::string errorFile = paths.getStringValue("sprites") + paths.getStringValue("spriteErrorFile"); if (animationFile != errorFile) return load(errorFile, 0); else return nullptr; } SpriteDef *def = new SpriteDef; def->mProcessedFiles.insert(animationFile); def->loadSprite(rootNode, variant, palettes); def->substituteActions(); if (serverVersion < 1) def->fixDeadAction(); return def; }
void SpriteDef::includeSprite(XmlNodePtr includeNode) { std::string filename = XML::getProperty(includeNode, "file", ""); if (filename.empty()) return; filename = paths.getStringValue("sprites") + filename; if (mProcessedFiles.find(filename) != mProcessedFiles.end()) { logger->log("Error, Tried to include %s which already is included.", filename.c_str()); return; } mProcessedFiles.insert(filename); XML::Document doc(filename); XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "sprite")) { logger->log("Error, no sprite root node in %s", filename.c_str()); return; } loadSprite(rootNode, 0); }
void QuestsWindow::loadQuest(const int var, const XmlNodePtr node) { QuestItem *const quest = new QuestItem(); // TRANSLATORS: quests window quest name quest->name = XML::langProperty(node, "name", _("unknown")); quest->group = XML::getProperty(node, "group", ""); std::string incompleteStr = XML::getProperty(node, "incomplete", ""); std::string completeStr = XML::getProperty(node, "complete", ""); if (incompleteStr.empty() && completeStr.empty()) { logger->log("complete flags incorrect"); delete quest; return; } splitToIntSet(quest->incomplete, incompleteStr, ','); splitToIntSet(quest->complete, completeStr, ','); if (quest->incomplete.empty() && quest->complete.empty()) { logger->log("complete flags incorrect"); delete quest; return; } if (quest->incomplete.empty() || quest->complete.empty()) quest->broken = true; for_each_xml_child_node(dataNode, node) { if (!xmlTypeEqual(dataNode, XML_ELEMENT_NODE)) continue; const char *const data = reinterpret_cast<const char*>( xmlNodeGetContent(dataNode)); if (!data) continue; std::string str = translator->getStr(data); if (xmlNameEqual(dataNode, "text")) quest->texts.push_back(QuestItemText(str, QuestType::TEXT)); else if (xmlNameEqual(dataNode, "name")) quest->texts.push_back(QuestItemText(str, QuestType::NAME)); else if (xmlNameEqual(dataNode, "reward")) quest->texts.push_back(QuestItemText(str, QuestType::REWARD)); } mQuests[var].push_back(quest); }
void ColorDB::loadHair(const std::string &fileName, std::map<ItemColor, ItemColorData> &colors) { XML::Document *doc = new XML::Document(fileName, UseResman_true, SkipError_false); const XmlNodePtrConst root = doc->rootNode(); if (!root || !xmlNameEqual(root, "colors")) { logger->log("ColorDB: Failed to find hair colors file."); if (colors.find(ItemColor_zero) == colors.end()) colors[ItemColor_zero] = ItemColorData(ItemColor_zero, "", ""); delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadHair(name, colors); continue; } else if (xmlNameEqual(node, "color")) { const ItemColor id = fromInt(XML::getProperty( node, "id", 0), ItemColor); if (colors.find(id) != colors.end()) { logger->log("ColorDB: Redefinition of dye ID %d", toInt(id, int)); } colors[id] = ItemColorData(id, XML::langProperty(node, "name", ""), XML::getProperty(node, "value", "#FFFFFF")); } }
void MapDB::loadRemapXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document *const doc = new XML::Document(fileName, UseResman_true, skipError); const XmlNodePtrConst root = doc->rootNode(); if (!root) { delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "map")) { const std::string name = XML::getProperty(node, "name", ""); if (name.empty()) continue; const std::string value = XML::getProperty(node, "value", ""); if (value.empty()) continue; mMaps[name] = value; } else if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadRemapXmlFile(name, skipError); continue; } } delete doc; }
void TextDb::loadXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document *doc = new XML::Document(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst root = doc->rootNode(); if ((root == nullptr) || !xmlNameEqual(root, "texts")) { delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadXmlFile(name, skipError); continue; } else if (xmlNameEqual(node, "text")) { const bool show = XML::getBoolProperty(node, "show", false); if (show == true) { if (!XmlHaveChildContent(node)) continue; std::string text = XmlChildContent(node); mTexts.push_back(text); } } } delete doc; }
void CharDB::load() { if (mLoaded) unload(); XML::Document *doc = new XML::Document( paths.getStringValue("charCreationFile"), true, false); const XmlNodePtrConst root = doc->rootNode(); if (!root || !xmlNameEqual(root, "chars")) { logger->log("CharDB: Failed to parse %s.", paths.getStringValue("charCreationFile").c_str()); delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "haircolor")) { loadMinMax(node, &mMinHairColor, &mMaxHairColor); } else if (xmlNameEqual(node, "hairstyle")) { loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); } else if (xmlNameEqual(node, "look")) { loadMinMax(node, &mMinLook, &mMaxLook); } else if (xmlNameEqual(node, "stat")) { loadMinMax(node, &mMinStat, &mMaxStat); mSumStat = XML::getProperty(node, "sum", 0); } else if (xmlNameEqual(node, "item")) { const int id = XML::getProperty(node, "id", 0); if (id > 0) mDefaultItems.push_back(id); } else if (xmlNameEqual(node, "race")) { loadMinMax(node, &mMinRace, &mMaxRace); } } delete doc; mLoaded = true; }
void SpriteDef::loadSprite(XmlNodePtr spriteNode, int variant, const std::string &palettes) { // Get the variant const int variantCount = XML::getProperty(spriteNode, "variants", 0); int variant_offset = 0; if (variantCount > 0 && variant < variantCount) { variant_offset = variant * XML::getProperty(spriteNode, "variant_offset", 0); } for_each_xml_child_node(node, spriteNode) { if (xmlNameEqual(node, "imageset")) loadImageSet(node, palettes); else if (xmlNameEqual(node, "action")) loadAction(node, variant_offset); else if (xmlNameEqual(node, "include")) includeSprite(node); } }
void MapDB::readMap(XmlNodePtrConst node) { if (!node) return; const std::string map = XML::getProperty(node, "name", ""); if (map.empty()) return; for_each_xml_child_node(childNode, node) { if (xmlNameEqual(childNode, "atlas")) { const std::string atlas = XML::getProperty(childNode, "name", ""); if (atlas.empty()) continue; mInfos[map].atlas = atlas; } } }
void SpriteDef::loadAction(XmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); const unsigned hp = XML::getProperty(node, "hp", 100); ImageSetIterator si = mImageSets.find(imageSetName); if (si == mImageSets.end()) { logger->log("Warning: imageset \"%s\" not defined in %s", imageSetName.c_str(), getIdPath().c_str()); return; } ImageSet *imageSet = si->second; if (actionName == SpriteAction::INVALID) { logger->log("Warning: Unknown action \"%s\" defined in %s", actionName.c_str(), getIdPath().c_str()); return; } Action *action = new Action; action->setNumber(hp); addAction(hp, actionName, action); // dirty hack to fix bad resources in tmw server if (actionName == "attack_stab") addAction(hp, "attack", action); // When first action set it as default direction Actions::const_iterator i = mActions.find(hp); if ((*i).second->size() == 1) addAction(hp, SpriteAction::DEFAULT, action); // Load animations for_each_xml_child_node(animationNode, node) { if (xmlNameEqual(animationNode, "animation")) loadAnimation(animationNode, action, imageSet, variant_offset); } }
void PETDB::load() { if (mLoaded) unload(); logger->log1("Initializing PET database..."); XML::Document doc("pets.xml"); const XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "pets")) { logger->log1("PET Database: Error while loading pets.xml!"); mLoaded = true; return; } // iterate <pet>s for_each_xml_child_node(petNode, rootNode) { if (!xmlNameEqual(petNode, "pet")) continue; const int id = XML::getProperty(petNode, "id", 0); if (id == 0) { logger->log1("PET Database: PET with missing ID in pets.xml!"); continue; } BeingInfo *const currentInfo = new BeingInfo; currentInfo->setTargetSelection(XML::getBoolProperty(petNode, "targetSelection", false)); currentInfo->setTargetCursorSize(XML::getProperty(petNode, "targetCursor", "medium")); currentInfo->setHoverCursor(XML::getProperty(petNode, "hoverCursor", "talk")); currentInfo->setTargetOffsetX(XML::getProperty(petNode, "targetOffsetX", 0)); currentInfo->setTargetOffsetY(XML::getProperty(petNode, "targetOffsetY", 0)); currentInfo->setSortOffsetY(XML::getProperty(petNode, "sortOffsetY", 0)); currentInfo->setDeadSortOffsetY(XML::getProperty(petNode, "deadSortOffsetY", 31)); SpriteDisplay display; for_each_xml_child_node(spriteNode, petNode) { if (!spriteNode->xmlChildrenNode) continue; if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *const currentSprite = new SpriteReference; currentSprite->sprite = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); display.particles.push_back(particlefx); } } currentInfo->setDisplay(display); mPETInfos[id] = currentInfo; } mLoaded = true; }
bool BeingCommon::readObjectNodes(XmlNodePtrConst &spriteNode, SpriteDisplay &display, BeingInfo *const currentInfo, const std::string &dbName) { if (xmlNameEqual(spriteNode, "sprite")) { if (!XmlHaveChildContent(spriteNode)) return true; SpriteReference *const currentSprite = new SpriteReference; currentSprite->sprite = XmlChildContent(spriteNode); currentSprite->variant = XML::getProperty( spriteNode, "variant", 0); display.sprites.push_back(currentSprite); return true; } else if (xmlNameEqual(spriteNode, "sound")) { if (!XmlHaveChildContent(spriteNode)) return true; const std::string event = XML::getProperty( spriteNode, "event", ""); const int delay = XML::getProperty( spriteNode, "delay", 0); const char *const filename = XmlChildContent(spriteNode); if (event == "hit") { currentInfo->addSound(ItemSoundEvent::HIT, filename, delay); } else if (event == "miss") { currentInfo->addSound(ItemSoundEvent::MISS, filename, delay); } else if (event == "hurt") { currentInfo->addSound(ItemSoundEvent::HURT, filename, delay); } else if (event == "die") { currentInfo->addSound(ItemSoundEvent::DIE, filename, delay); } else if (event == "move") { currentInfo->addSound(ItemSoundEvent::MOVE, filename, delay); } else if (event == "sit") { currentInfo->addSound(ItemSoundEvent::SIT, filename, delay); } else if (event == "sittop") { currentInfo->addSound(ItemSoundEvent::SITTOP, filename, delay); } else if (event == "spawn") { currentInfo->addSound(ItemSoundEvent::SPAWN, filename, delay); } else { logger->log((dbName + ": Warning, sound effect %s for " "unknown event %s of monster %s").c_str(), filename, event.c_str(), currentInfo->getName().c_str()); } return true; } else if (xmlNameEqual(spriteNode, "attack")) { const int attackId = XML::getProperty(spriteNode, "id", 0); const int effectId = XML::getProperty(spriteNode, "effect-id", paths.getIntValue("effectId")); const int hitEffectId = XML::getProperty(spriteNode, "hit-effect-id", paths.getIntValue("hitEffectId")); const int criticalHitEffectId = XML::getProperty(spriteNode, "critical-hit-effect-id", paths.getIntValue("criticalHitEffectId")); const int missEffectId = XML::getProperty(spriteNode, "miss-effect-id", paths.getIntValue("missEffectId")); const std::string spriteAction = XML::getProperty(spriteNode, "action", "attack"); const std::string skySpriteAction = XML::getProperty(spriteNode, "skyaction", "skyattack"); const std::string waterSpriteAction = XML::getProperty(spriteNode, "wateraction", "waterattack"); const std::string rideSpriteAction = XML::getProperty(spriteNode, "rideaction", "rideattack"); const std::string missileParticle = XML::getProperty(spriteNode, "missile-particle", ""); const float missileZ = XML::getFloatProperty( spriteNode, "missile-z", 32.0F); const int missileLifeTime = XML::getProperty( spriteNode, "missile-lifetime", 500); const float missileSpeed = XML::getFloatProperty( spriteNode, "missile-speed", 7.0F); const float missileDieDistance = XML::getFloatProperty( spriteNode, "missile-diedistance", 8.0F); currentInfo->addAttack(attackId, spriteAction, skySpriteAction, waterSpriteAction, rideSpriteAction, effectId, hitEffectId, criticalHitEffectId, missEffectId, missileParticle, missileZ, missileSpeed, missileDieDistance, missileLifeTime); return true; } else if (xmlNameEqual(spriteNode, "particlefx")) { if (!XmlHaveChildContent(spriteNode)) return true; display.particles.push_back(XmlChildContent(spriteNode)); return true; } return false; }
void MonsterDB::loadXmlFile(const std::string &fileName) { XML::Document doc(fileName, UseResman_true, SkipError_false); const XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "monsters")) { logger->log("Monster Database: Error while loading %s!", paths.getStringValue("monstersFile").c_str()); mLoaded = true; return; } const int offset = XML::getProperty(rootNode, "offset", OLD_TMWATHENA_OFFSET); // iterate <monster>s for_each_xml_child_node(monsterNode, rootNode) { if (xmlNameEqual(monsterNode, "include")) { const std::string name = XML::getProperty(monsterNode, "name", ""); if (!name.empty()) loadXmlFile(name); continue; } if (!xmlNameEqual(monsterNode, "monster")) continue; const int id = XML::getProperty(monsterNode, "id", 0); BeingInfo *currentInfo = nullptr; if (mMonsterInfos.find(fromInt(id + offset, BeingTypeId)) != mMonsterInfos.end()) { logger->log("MonsterDB: Redefinition of monster ID %d", id); currentInfo = mMonsterInfos[fromInt(id + offset, BeingTypeId)]; } if (!currentInfo) currentInfo = new BeingInfo; currentInfo->setBlockType(BlockType::MONSTER); currentInfo->setName(XML::langProperty( // TRANSLATORS: unknown info name monsterNode, "name", _("unnamed"))); BeingCommon::readBasicAttributes(currentInfo, monsterNode, "attack"); currentInfo->setMaxHP(XML::getProperty(monsterNode, "maxHP", 0)); currentInfo->setDeadSortOffsetY(XML::getProperty( monsterNode, "deadSortOffsetY", 31)); currentInfo->setColorsList(XML::getProperty(monsterNode, "colors", "")); unsigned char block = 0; std::string walkStr = XML::getProperty( monsterNode, "walkType", "walk"); if (walkStr == "walk") block = BlockMask::WATER | BlockMask::AIR; else if (walkStr == "fly") block = 0; else if (walkStr == "swim") block = BlockMask::GROUND | BlockMask::AIR; else if (walkStr == "walkswim" || walkStr == "swimwalk") block = BlockMask::AIR; currentInfo->setBlockWalkMask(static_cast<unsigned char>( BlockMask::WALL | block)); if (currentInfo->getMaxHP()) currentInfo->setStaticMaxHP(true); SpriteDisplay display; // iterate <sprite>s and <sound>s for_each_xml_child_node(spriteNode, monsterNode) { BeingCommon::readObjectNodes(spriteNode, display, currentInfo, "MonsterDB"); } currentInfo->setDisplay(display); mMonsterInfos[fromInt(id + offset, BeingTypeId)] = currentInfo; }
void NPCDB::load() { if (mLoaded) unload(); logger->log1("Initializing NPC database..."); XML::Document doc("npcs.xml"); const XmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "npcs")) { logger->log1("NPC Database: Error while loading npcs.xml!"); mLoaded = true; return; } // iterate <npc>s for_each_xml_child_node(npcNode, rootNode) { if (!xmlNameEqual(npcNode, "npc")) continue; const int id = XML::getProperty(npcNode, "id", 0); if (id == 0) { logger->log1("NPC Database: NPC with missing ID in npcs.xml!"); continue; } BeingInfo *const currentInfo = new BeingInfo; currentInfo->setTargetSelection(XML::getBoolProperty(npcNode, "targetSelection", true)); currentInfo->setTargetCursorSize(XML::getProperty(npcNode, "targetCursor", "medium")); currentInfo->setHoverCursor(XML::getProperty(npcNode, "hoverCursor", "talk")); currentInfo->setTargetOffsetX(XML::getProperty(npcNode, "targetOffsetX", 0)); currentInfo->setTargetOffsetY(XML::getProperty(npcNode, "targetOffsetY", 0)); currentInfo->setSortOffsetY(XML::getProperty(npcNode, "sortOffsetY", 0)); currentInfo->setDeadSortOffsetY(XML::getProperty(npcNode, "deadSortOffsetY", 31)); currentInfo->setAvatarId(static_cast<uint16_t>(XML::getProperty( npcNode, "avatar", 0))); SpriteDisplay display; for_each_xml_child_node(spriteNode, npcNode) { if (!spriteNode->xmlChildrenNode) continue; if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *const currentSprite = new SpriteReference; currentSprite->sprite = reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content); currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlNameEqual(spriteNode, "particlefx")) { display.particles.push_back(reinterpret_cast<const char*>( spriteNode->xmlChildrenNode->content)); } } currentInfo->setDisplay(display); mNPCInfos[id] = currentInfo; } mLoaded = true; }
void StatusEffectDB::loadXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document doc(fileName, UseVirtFs_true, skipError); XmlNodeConstPtrConst rootNode = doc.rootNode(); if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "status-effects")) { logger->log("Error loading status effects file: " + fileName); return; } for_each_xml_child_node(node, rootNode) { if (xmlNameEqual(node, "include")) { const std::string incName = XML::getProperty(node, "name", ""); if (!incName.empty()) loadXmlFile(incName, skipError); continue; } else if (!xmlNameEqual(node, "status-effect")) { continue; } int id = XML::getProperty(node, "id", -1); if (id == -1) { id = fakeId; fakeId ++; } const int option = XML::getProperty(node, "option", 0); const int opt1 = XML::getProperty(node, "opt1", 0); const int opt2 = XML::getProperty(node, "opt2", 0); const int opt3 = XML::getProperty(node, "opt3", 0); if (option != 0) { optionToIdMap[option] = id; } if (opt1 != 0) { opt1ToIdMap[opt1] = id; } if (opt2 != 0) { opt2ToIdMap[opt2] = id; } if (opt3 != 0) { opt3ToIdMap[opt3] = id; } StatusEffect *startEffect = statusEffects[1][id]; StatusEffect *endEffect = statusEffects[0][id]; const std::string name = XML::getProperty(node, "name", ""); const std::string name2 = XML::langProperty(node, "name", ""); if (startEffect == nullptr) startEffect = new StatusEffect; if (endEffect == nullptr) endEffect = new StatusEffect; startEffect->mName = name2; startEffect->mIsPoison = (name == paths.getStringValue("poisonEffectName")); startEffect->mIsCart = (name == paths.getStringValue("cartEffectName")); startEffect->mIsRiding = (name == paths.getStringValue("ridingEffectName")); startEffect->mIsTrickDead = (name == paths.getStringValue("trickDeadEffectName")); startEffect->mIsPostDelay = (name == paths.getStringValue("postDelayName")); startEffect->mMessage = XML::getProperty( node, "start-message", ""); startEffect->mSFXEffect = XML::getProperty( node, "start-audio", ""); startEffect->mStartParticleEffect = XML::getProperty( node, "start-particle", ""); startEffect->mParticleEffect = XML::getProperty( node, "particle", ""); startEffect->mIcon = XML::getProperty(node, "icon", ""); startEffect->mAction = XML::getProperty(node, "action", ""); startEffect->mIsPersistent = (XML::getProperty( node, "persistent-particle-effect", "no")) != "no"; endEffect->mName = startEffect->mName; endEffect->mIsPoison = startEffect->mIsPoison; endEffect->mIsCart = startEffect->mIsCart; endEffect->mIsRiding = startEffect->mIsRiding; endEffect->mIsTrickDead = startEffect->mIsTrickDead; endEffect->mIsPostDelay = startEffect->mIsPostDelay; endEffect->mMessage = XML::getProperty(node, "end-message", ""); endEffect->mSFXEffect = XML::getProperty(node, "end-audio", ""); endEffect->mStartParticleEffect = XML::getProperty( node, "end-particle", ""); statusEffects[1][id] = startEffect; statusEffects[0][id] = endEffect; } }
void Units::loadXmlFile(const std::string &fileName) { XML::Document doc(fileName, UseResman_true, SkipError_false); const XmlNodePtrConst root = doc.rootNode(); if (!root || !xmlNameEqual(root, "units")) { logger->log("Error loading unit definition file: " + paths.getStringValue("unitsFile")); return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "include")) { const std::string name = XML::getProperty(node, "name", ""); if (!name.empty()) loadXmlFile(name); continue; } else if (xmlNameEqual(node, "unit")) { UnitDescription ud; int level = 1; const std::string type = XML::getProperty(node, "type", ""); ud.conversion = XML::getProperty(node, "conversion", 1); ud.mix = XML::getProperty(node, "mix", "no") == "yes"; UnitLevel bu; bu.symbol = XML::getProperty(node, "base", "¤"); bu.count = 1; bu.round = XML::getProperty(node, "round", 2); bu.separator = XML::getProperty(node, "separator", " "); ud.levels.push_back(bu); for_each_xml_child_node(uLevel, node) { if (xmlNameEqual(uLevel, "level")) { const UnitLevel ul = { XML::getProperty(uLevel, "symbol", strprintf("¤%d", level)), XML::getProperty(uLevel, "count", -1), XML::getProperty(uLevel, "round", bu.round), XML::getProperty(uLevel, "separator", bu.separator) }; if (ul.count > 0) { ud.levels.push_back(ul); level++; } else { logger->log("Error bad unit count: %d for %s in %s", ul.count, ul.symbol.c_str(), bu.symbol.c_str()); } } } // Add one more level for saftey const UnitLevel lev = { "", INT_MAX, 0, "" }; ud.levels.push_back(lev); if (type == "weight") units[UNIT_WEIGHT] = ud; else if (type == "currency") units[UNIT_CURRENCY] = ud; else logger->log("Error unknown unit type: %s", type.c_str()); } }
void CharDB::load() { if (mLoaded) unload(); XML::Document *doc = new XML::Document( paths.getStringValue("charCreationFile"), UseResman_true, SkipError_false); const XmlNodePtrConst root = doc->rootNode(); if (!root || !xmlNameEqual(root, "chars")) { logger->log("CharDB: Failed to parse %s.", paths.getStringValue("charCreationFile").c_str()); delete doc; return; } for_each_xml_child_node(node, root) { if (xmlNameEqual(node, "haircolor")) { loadMinMax(node, &mMinHairColor, &mMaxHairColor); } else if (xmlNameEqual(node, "hairstyle")) { loadMinMax(node, &mMinHairStyle, &mMaxHairStyle); } else if (xmlNameEqual(node, "look")) { loadMinMax(node, &mMinLook, &mMaxLook); } else if (xmlNameEqual(node, "stat")) { loadMinMax(node, &mMinStat, &mMaxStat); mSumStat = XML::getProperty(node, "sum", 0); } else if (xmlNameEqual(node, "item")) { const int id = XML::getProperty(node, "id", 0); if (id > 0) { BeingSlot slot; slot.spriteId = id; for (int f = 0; f < maxCards; f ++) { const std::string cardName = strprintf("card%d", f + 1); slot.cardsId.cards[f] = XML::getProperty(node, cardName.c_str(), 0); } mDefaultItems.push_back(slot); } } else if (xmlNameEqual(node, "race")) { loadMinMax(node, &mMinRace, &mMaxRace); } } delete doc; mLoaded = true; }