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); }
static void loadQuest(const int var, XmlNodeConstPtr node) { if (node == nullptr) return; 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; XmlChar *const data = reinterpret_cast<XmlChar*>( XmlNodeGetContent(dataNode)); if (data == nullptr) continue; std::string str = translator->getStr(data); XmlFree(data); for (int f = 1; f < 100; f ++) { const std::string key = strprintf("text%d", f); const std::string val = XML::getProperty(dataNode, key.c_str(), ""); if (val.empty()) break; const std::string param = strprintf("{@@%d}", f); replaceAll(str, param, val); } replaceItemLinks(str); if (xmlNameEqual(dataNode, "text")) { quest->texts.push_back(QuestItemText(str, QuestType::TEXT, std::string(), std::string())); } else if (xmlNameEqual(dataNode, "name")) { quest->texts.push_back(QuestItemText(str, QuestType::NAME, std::string(), std::string())); } else if (xmlNameEqual(dataNode, "reward")) { quest->texts.push_back(QuestItemText(str, QuestType::REWARD, std::string(), std::string())); } else if (xmlNameEqual(dataNode, "questgiver") || xmlNameEqual(dataNode, "giver")) { quest->texts.push_back(QuestItemText(str, QuestType::GIVER, std::string(), std::string())); } else if (xmlNameEqual(dataNode, "coordinates")) { const std::string str1 = toString(XML::getIntProperty( dataNode, "x", 0, 1, 1000)); const std::string str2 = toString(XML::getIntProperty( dataNode, "y", 0, 1, 1000)); quest->texts.push_back(QuestItemText(str, QuestType::COORDINATES, str1, str2)); } else if (xmlNameEqual(dataNode, "npc")) { quest->texts.push_back(QuestItemText(str, QuestType::NPC, std::string(), std::string())); } } quest->var = var; mQuests[var].push_back(quest); }
for_each_xml_child_node(childNode, node) { if (!xmlTypeEqual(childNode, XML_ELEMENT_NODE)) continue; if (xmlNameEqual(childNode, "button")) { const std::string name = XML::getProperty(childNode, "name", ""); const std::string value = XML::getProperty(childNode, "value", ""); if (value.empty()) continue; NpcButtonInfo *const button = new NpcButtonInfo; button->x = XML::getIntProperty( childNode, "x", 0, 0, 10000); button->y = XML::getIntProperty( childNode, "y", 0, 0, 10000); button->name = name; button->value = value; button->image = XML::getProperty(childNode, "image", ""); if (button->name.empty() && button->image.empty()) { reportAlways("Error: npc button without name or image"); delete button; continue; } button->imageWidth = XML::getIntProperty( childNode, "imageWidth", 16, 1, 1000); button->imageHeight = XML::getIntProperty( childNode, "imageHeight", 16, 1, 1000); dialog->menu.buttons.push_back(button); } else if (xmlNameEqual(childNode, "image")) { const std::string image = XML::getProperty(childNode, "image", ""); if (image.empty()) { reportAlways("Error: no image attribute found in image tag."); continue; } NpcImageInfo *const imageInfo = new NpcImageInfo; imageInfo->name = image; imageInfo->x = XML::getIntProperty( childNode, "x", 0, 0, 10000); imageInfo->y = XML::getIntProperty( childNode, "y", 0, 0, 10000); dialog->menu.images.push_back(imageInfo); } else if (xmlNameEqual(childNode, "text")) { const std::string text = XML::getProperty(childNode, "text", ""); if (text.empty()) { reportAlways("Error: no text attribute found in text tag."); continue; } NpcTextInfo *const textInfo = new NpcTextInfo; textInfo->text = text; textInfo->x = XML::getIntProperty( childNode, "x", 0, 0, 10000); textInfo->y = XML::getIntProperty( childNode, "y", 0, 0, 10000); textInfo->width = XML::getIntProperty( childNode, "width", 20, 10, 10000); textInfo->height = XML::getIntProperty( childNode, "height", 20, 10, 10000); dialog->menu.texts.push_back(textInfo); } }