diff options
author | Andrei Karas <akaras@inbox.ru> | 2018-02-11 01:50:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2018-02-11 04:28:43 +0300 |
commit | e27ab1c594b8ab927708a769c8ee3d58f51a89a3 (patch) | |
tree | ba038da1c40a368aad9f3d77d4554b99efa918cf /src/resources | |
parent | ce34b402281f75cb1e9d214c925382fdc522455b (diff) | |
download | plus-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.gz plus-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.bz2 plus-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.tar.xz plus-e27ab1c594b8ab927708a769c8ee3d58f51a89a3.zip |
Add clandb support.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/claninfo.h | 41 | ||||
-rw-r--r-- | src/resources/db/clandb.cpp | 135 | ||||
-rw-r--r-- | src/resources/db/clandb.h | 49 | ||||
-rw-r--r-- | src/resources/dbmanager.cpp | 3 |
4 files changed, 228 insertions, 0 deletions
diff --git a/src/resources/claninfo.h b/src/resources/claninfo.h new file mode 100644 index 000000000..3e510dcbf --- /dev/null +++ b/src/resources/claninfo.h @@ -0,0 +1,41 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_CLANINFO_H +#define RESOURCES_CLANINFO_H + +#include <string> + +#include "localconsts.h" + +struct ClanInfo final +{ + ClanInfo() : + stats(), + id(0) + { } + + A_DELETE_COPY(ClanInfo) + + std::string stats; + int id; +}; + +#endif // RESOURCES_CLANINFO_H diff --git a/src/resources/db/clandb.cpp b/src/resources/db/clandb.cpp new file mode 100644 index 000000000..ac32b4ea7 --- /dev/null +++ b/src/resources/db/clandb.cpp @@ -0,0 +1,135 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "resources/db/clandb.h" + +#include "configuration.h" + +#include "resources/beingcommon.h" +#include "resources/claninfo.h" + +#include "resources/db/itemfielddb.h" + +#include "utils/checkutils.h" +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/itemxmlutils.h" + +#include "debug.h" + +namespace +{ + std::map<int, ClanInfo *> mClansInfos; + bool mLoaded = false; +} // namespace + +void ClanDb::load() +{ + if (mLoaded) + unload(); + + logger->log1("Initializing clans database..."); + loadXmlFile(paths.getStringValue("clansFile"), SkipError_false); + loadXmlFile(paths.getStringValue("clansPatchFile"), SkipError_true); + loadXmlDir("clansPatchDir", loadXmlFile); + + mLoaded = true; +} + +void ClanDb::loadXmlFile(const std::string &fileName, + const SkipError skipError) +{ + XML::Document doc(fileName, UseVirtFs_true, skipError); + XmlNodeConstPtr rootNode = doc.rootNode(); + + if ((rootNode == nullptr) || !xmlNameEqual(rootNode, "clans")) + { + logger->log("Clans database: Error while loading %s!", + paths.getStringValue("clansFile").c_str()); + mLoaded = true; + return; + } + + const ItemFieldInfos &addFields = + ItemFieldDb::getAddFields(); + + // iterate <clan>s + for_each_xml_child_node(clanNode, rootNode) + { + if (xmlNameEqual(clanNode, "include")) + { + const std::string name = XML::getProperty( + clanNode, "name", ""); + if (!name.empty()) + loadXmlFile(name, skipError); + continue; + } + if (!xmlNameEqual(clanNode, "clan")) + continue; + + const int id = XML::getProperty(clanNode, "id", 0); + ClanInfo *clanInfo = nullptr; + if (mClansInfos.find(id) != mClansInfos.end()) + { + reportAlways("ClanDb: Redefinition of clan ID %d", id); + clanInfo = mClansInfos[id]; + } + if (clanInfo == nullptr) + clanInfo = new ClanInfo; + + clanInfo->id = id; + + readItemStatsString(clanInfo->stats, + clanNode, + addFields); + + mClansInfos[id] = clanInfo; + } +} + +void ClanDb::unload() +{ + logger->log1("Unloading clans database..."); + delete_all(mClansInfos); + mClansInfos.clear(); + + mLoaded = false; +} + +const ClanInfo *ClanDb::get(const int clanId) +{ + std::map<int, ClanInfo *>::const_iterator i = + mClansInfos.find(clanId); + + if (i == mClansInfos.end()) + { + i = mClansInfos.find(clanId); + if (i == mClansInfos.end()) + { + reportAlways("ClanDb: Warning, unknown clan ID " + "%d requested", + clanId); + return nullptr; + } + } + return i->second; +} diff --git a/src/resources/db/clandb.h b/src/resources/db/clandb.h new file mode 100644 index 000000000..ea20d5e46 --- /dev/null +++ b/src/resources/db/clandb.h @@ -0,0 +1,49 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2018 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_DB_CLANDB_H +#define RESOURCES_DB_CLANDB_H + +#include "enums/simpletypes/skiperror.h" + +#include "localconsts.h" + +#include <string> + +struct ClanInfo; + +/** + * Clan information database. + */ +namespace ClanDb +{ + void load(); + + void unload(); + + void loadXmlFile(const std::string &fileName, + const SkipError skipError); + + const ClanInfo *get(const int clanId) A_WARN_UNUSED; +} // namespace ClanDb + +#endif // RESOURCES_DB_CLANDB_H diff --git a/src/resources/dbmanager.cpp b/src/resources/dbmanager.cpp index b7997130f..350ea5fa3 100644 --- a/src/resources/dbmanager.cpp +++ b/src/resources/dbmanager.cpp @@ -28,6 +28,7 @@ #include "resources/db/avatardb.h" #include "resources/db/badgesdb.h" #include "resources/db/chardb.h" +#include "resources/db/clandb.h" #include "resources/db/colordb.h" #include "resources/db/deaddb.h" #include "resources/db/elementaldb.h" @@ -86,6 +87,7 @@ void DbManager::loadDb() ElementalDb::load(); SkillUnitDb::load(); HorseDB::load(); + ClanDb::load(); } MonsterDB::load(); AvatarDB::load(); @@ -120,6 +122,7 @@ void DbManager::unloadDb() { MercenaryDB::unload(); HomunculusDB::unload(); + ClanDb::unload(); ElementalDb::unload(); SkillUnitDb::unload(); HorseDB::unload(); |