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; }
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 PETDB::loadXmlFile(const std::string &fileName, const SkipError skipError) { XML::Document doc(fileName, UseResman_true, skipError); const XmlNodePtrConst rootNode = doc.rootNode(); if (!rootNode || !xmlNameEqual(rootNode, "pets")) { logger->log("PET Database: Error while loading %s!", fileName.c_str()); return; } // iterate <pet>s for_each_xml_child_node(petNode, rootNode) { if (xmlNameEqual(petNode, "include")) { const std::string name = XML::getProperty(petNode, "name", ""); if (!name.empty()) loadXmlFile(name, skipError); continue; } else if (!xmlNameEqual(petNode, "pet")) { continue; } const BeingTypeId id = fromInt(XML::getProperty( petNode, "id", -1), BeingTypeId); if (id == BeingTypeId_negOne) { reportAlways("PET Database: PET with missing ID in %s!", paths.getStringValue("petsFile").c_str()); continue; } BeingInfo *currentInfo = nullptr; if (mPETInfos.find(id) != mPETInfos.end()) currentInfo = mPETInfos[id]; if (!currentInfo) currentInfo = new BeingInfo; currentInfo->setName(XML::langProperty(petNode, // TRANSLATORS: unknown info name "name", _("pet"))); currentInfo->setTargetSelection(XML::getBoolProperty(petNode, "targetSelection", true)); BeingCommon::readBasicAttributes(currentInfo, petNode, "talk"); BeingCommon::readWalkingAttributes(currentInfo, petNode, 0); currentInfo->setDeadSortOffsetY(XML::getProperty(petNode, "deadSortOffsetY", 31)); const std::string returnMessage = XML::langProperty(petNode, // TRANSLATORS: popup menu item // TRANSLATORS: pet return to egg "removeMessage", _("Return to egg")); currentInfo->setString(0, returnMessage); SpriteDisplay display; for_each_xml_child_node(spriteNode, petNode) { if (!XmlHaveChildContent(spriteNode)) continue; if (xmlNameEqual(spriteNode, "sprite")) { SpriteReference *const currentSprite = new SpriteReference; currentSprite->sprite = XmlChildContent(spriteNode); currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); display.sprites.push_back(currentSprite); } else if (xmlNameEqual(spriteNode, "particlefx")) { std::string particlefx = XmlChildContent(spriteNode); display.particles.push_back(particlefx); } } currentInfo->setDisplay(display); mPETInfos[id] = currentInfo; } }