Ejemplo n.º 1
0
void AttributeManager::readAttributeNode(xmlNodePtr attributeNode)
{
    int id = XML::getProperty(attributeNode, "id", 0);

    if (id <= 0)
    {
        LOG_WARN("Attribute manager: attribute '" << id
                 << "' has an invalid id and will be ignored.");
        return;
    }

    mAttributeMap[id] =
            AttributeInfoMap(false, std::vector<struct AttributeInfoType>());

    for_each_xml_child_node(subNode, attributeNode)
    {
        if (xmlStrEqual(subNode->name, BAD_CAST "modifier"))
        {
            readModifierNode(subNode, id);
        }
    }

    const std::string scope = utils::toUpper(
                XML::getProperty(attributeNode, "scope", std::string()));

    if (scope.empty())
    {
        // Give a warning unless scope has been explicitly set to "NONE"
        LOG_WARN("Attribute manager: attribute '" << id
                 << "' has no default scope.");
    }
    else if (scope == "CHARACTER")
    {
        mAttributeScopes[CharacterScope][id] = &mAttributeMap.at(id).second;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default character scope.");
    }
    else if (scope == "MONSTER")
    {
        mAttributeScopes[MonsterScope][id] = &mAttributeMap.at(id).second;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default monster scope.");
    }
    else if (scope == "BEING")
    {
        mAttributeScopes[BeingScope][id] = &mAttributeMap.at(id).second;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default being scope.");
    }
    else if (scope == "NONE")
    {
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' set to have no default scope.");
    }
}
Ejemplo n.º 2
0
/**
 * Read a <attribute> element from settings.
 * Used by SettingsManager.
 */
void AttributeManager::readAttributeNode(xmlNodePtr attributeNode)
{
    int id = XML::getProperty(attributeNode, "id", 0);

    if (id <= 0)
    {
        LOG_WARN("Attribute manager: attribute '" << id
                 << "' has an invalid id and will be ignored.");
        return;
    }

    AttributeInfo &attribute = mAttributeMap[id];

    attribute.modifiers = std::vector<AttributeModifier>();
    attribute.minimum = XML::getFloatProperty(attributeNode, "minimum",
                                           std::numeric_limits<double>::min());
    attribute.maximum = XML::getFloatProperty(attributeNode, "maximum",
                                           std::numeric_limits<double>::max());
    attribute.modifiable = XML::getBoolProperty(attributeNode, "modifiable",
                                                false);

    for_each_xml_child_node(subNode, attributeNode)
    {
        if (xmlStrEqual(subNode->name, BAD_CAST "modifier"))
        {
            readModifierNode(subNode, id);
        }
    }

    const std::string scope = utils::toUpper(
                XML::getProperty(attributeNode, "scope", std::string()));

    if (scope.empty())
    {
        // Give a warning unless scope has been explicitly set to "NONE"
        LOG_WARN("Attribute manager: attribute '" << id
                 << "' has no default scope.");
    }
    else if (scope == "CHARACTER")
    {
        mAttributeScopes[CharacterScope][id] = &attribute;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default character scope.");
    }
    else if (scope == "MONSTER")
    {
        mAttributeScopes[MonsterScope][id] = &attribute;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default monster scope.");
    }
    else if (scope == "BEING")
    {
        mAttributeScopes[BeingScope][id] = &attribute;
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' added to default being scope.");
    }
    else if (scope == "NONE")
    {
        LOG_DEBUG("Attribute manager: attribute '" << id
                  << "' set to have no default scope.");
    }
}