Пример #1
0
void ColorDB::load()
{
    if (mLoaded)
        return;

    XML::Document *doc = new XML::Document(HAIR_COLOR_FILE);
    xmlNodePtr root = doc->rootNode();
    bool TMWHair = false;

    if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
    {
        logger->log("Trying TMW's color file, %s.", TMW_COLOR_FILE);

        TMWHair = true;

        delete doc;

        doc = new XML::Document(TMW_COLOR_FILE);
        root = doc->rootNode();
        if (!root || !xmlStrEqual(root->name, BAD_CAST "colors"))
        {
            logger->log("ColorDB: Failed");
            mColors[0] = mFail;
            mLoaded = true;

            delete doc;

            return;
        }
    }
    for_each_xml_child_node(node, root)
    {
        if (xmlStrEqual(node->name, BAD_CAST "color"))
        {
            int id = XML::getProperty(node, "id", 0);

            if (mColors.find(id) != mColors.end())
                logger->log("ColorDB: Redefinition of dye ID %d", id);

            mColors[id] = TMWHair ? XML::getProperty(node, "value", mFail) :
                                    XML::getProperty(node, "dye", mFail);
        }
    }

    delete doc;

    mLoaded = true;
}
Пример #2
0
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;
}
Пример #3
0
void EffectDB::load()
{
    if (!mLoaded)
        return;

    const XML::Document doc("effects.xml");
    const xmlNodePtr root = doc.rootNode();

    if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
    {
        logger->log("Error loading being effects file: effects.xml");
        return;
    }
    else
        logger->log("Effects are now loading");

    for_each_xml_child_node(node, root)
    {
        if (xmlStrEqual(node->name, BAD_CAST "effect"))
        {
            EffectDescription ed;
            ed.id = XML::getProperty(node, "id", -1);
            ed.GFX = XML::getProperty(node, "particle", "");
            ed.SFX = XML::getProperty(node, "audio", "");
            mEffects.push_back(ed);
        }
    }

    mLoaded = true;
}
Пример #4
0
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;
}
Пример #5
0
void EmoteDB::load()
{
    if (mLoaded)
        return;

    mLastEmote = 0;

    logger->log("Initializing emote database...");

    const XML::Document doc("emotes.xml");
    const xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "emotes"))
    {
        logger->log("Emote Database: Error while loading emotes.xml!");
        return;
    }

    //iterate <emote>s
    for_each_xml_child_node(emoteNode, rootNode)
    {
        if (!xmlStrEqual(emoteNode->name, BAD_CAST "emote"))
            continue;

        const int id = XML::getProperty(emoteNode, "id", -1);

        if (id == -1)
        {
            logger->log("Emote Database: Emote with missing ID in emotes.xml!");
            continue;
        }

        EmoteInfo *currentInfo = new EmoteInfo();

        for_each_xml_child_node(spriteNode, emoteNode)
        {
            if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
            {
                EmoteSprite *currentSprite = new EmoteSprite();
                std::string file = "graphics/sprites/" + (std::string)
                            (const char*) spriteNode->xmlChildrenNode->content;
                currentSprite->sprite = AnimatedSprite::load(file,
                                XML::getProperty(spriteNode, "variant", 0));
                currentInfo->sprites.push_back(currentSprite);
            }
            else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
            {
                std::string particlefx = (const char*) spriteNode->xmlChildrenNode->content;
                currentInfo->particles.push_back(particlefx);
            }
        }
        mEmoteInfos[id] = currentInfo;

        if (id > mLastEmote)
            mLastEmote = id;
    }

    mLoaded = true;
}
Пример #6
0
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;
}
Пример #7
0
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"));
        }
    }
Пример #8
0
void EffectDB::load()
{
    if (!mLoaded)
        return;
    
    const XML::Document doc("effects.xml");
    const xmlNodePtr root = doc.rootNode();

    if (!root || !xmlStrEqual(root->name, BAD_CAST "being-effects"))
    {
        logger->log("Error loading being effects file: effects.xml");
        return;
    }
    else
        logger->log("Effects are now loading");

    for_each_xml_child_node(node, root)
    {
        if (xmlStrEqual(node->name, BAD_CAST "effect"))
        {
            EffectDescription ed;
            ed.id = XML::getProperty(node, "id", -1);
            ed.GFX = XML::getProperty(node, "particle", "");
            ed.SFX = XML::getProperty(node, "audio", "");
            ed.ambient.type = ""; // since we test this, ensure it's initialized
                                  // with something
            if (xmlStrEqual(node->name, BAD_CAST "ambient"))
            {
                ed.ambient.type = XML::getProperty(node, "type", "");
                ed.ambient.x = XML::getProperty(node, "x", 0.0f);
                ed.ambient.y = XML::getProperty(node, "y", 0.0f);
                ed.ambient.speedX = XML::getProperty(node, "speedx", 0.95f);
                ed.ambient.speedY = XML::getProperty(node, "speedy", 0.95f);
                ed.ambient.duration = XML::getProperty(node, "duration", 100);
            }
            mEffects.push_back(ed);
        }
    }

    mLoaded = true;
}
Пример #9
0
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;
}
Пример #10
0
void MonsterDB::load()
{
    if (mLoaded)
        return;

    mUnknown.addSprite("error.xml");
    mUnknown.setName(_("unnamed"));

    logger->log("Initializing monster database...");

    const XML::Document doc("monsters.xml");
    const xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "monsters"))
        logger->error("Monster Database: Error while loading monster.xml!");

    //iterate <monster>s
    for_each_xml_child_node(monsterNode, rootNode)
    {
        if (!xmlStrEqual(monsterNode->name, BAD_CAST "monster"))
            continue;

        MonsterInfo *currentInfo = new MonsterInfo();

        currentInfo->setName(XML::getProperty(monsterNode, "name", _("unnamed")));

        std::string targetCursor;
        targetCursor = XML::getProperty(monsterNode, "targetCursor", "medium");
        if (targetCursor == "small")
            currentInfo->setTargetCursorSize(Being::TC_SMALL);
        else if (targetCursor == "medium")
            currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
        else if (targetCursor == "large")
            currentInfo->setTargetCursorSize(Being::TC_LARGE);
        else
        {
            logger->log("MonsterDB: Unknown target cursor type \"%s\" for %s -"
                        "using medium sized one",
                        targetCursor.c_str(), currentInfo->getName().c_str());
            currentInfo->setTargetCursorSize(Being::TC_MEDIUM);
        }

        //iterate <sprite>s and <sound>s
        for_each_xml_child_node(spriteNode, monsterNode)
        {
            if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
                currentInfo->addSprite(
                        (const char*) spriteNode->xmlChildrenNode->content);

            if (xmlStrEqual(spriteNode->name, BAD_CAST "sound"))
            {
                std::string event = XML::getProperty(spriteNode, "event", "");
                const char *filename;
                filename = (const char*) spriteNode->xmlChildrenNode->content;

                if (event == "hit")
                    currentInfo->addSound(MONSTER_EVENT_HIT, filename);
                else if (event == "miss")
                    currentInfo->addSound(MONSTER_EVENT_MISS, filename);
                else if (event == "hurt")
                    currentInfo->addSound(MONSTER_EVENT_HURT, filename);
                else if (event == "die")
                    currentInfo->addSound(MONSTER_EVENT_DIE, filename);
                else
                {
                    logger->log("MonsterDB: Warning, sound effect %s for "
                                "unknown event %s of monster %s",
                                filename, event.c_str(),
                                currentInfo->getName().c_str());
                }
            }

            if (xmlStrEqual(spriteNode->name, BAD_CAST "attack"))
            {
                std::string event = XML::getProperty(
                        spriteNode, "particle-effect", "");
                currentInfo->addAttackParticleEffect(event);
            }

            if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
                currentInfo->addParticleEffect(
                    (const char*) spriteNode->xmlChildrenNode->content);
        }
        mMonsterInfos[XML::getProperty(monsterNode, "id", 0)] = currentInfo;
    }

    mLoaded = true;
}
Пример #11
0
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;
}