From 35481061f62111f916a39ce3cac6a314579418f9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 31 Jan 2017 21:27:52 +0300 Subject: Load currency names for each npc from npcs.xml. --- src/client.cpp | 2 +- src/resources/beinginfo.cpp | 1 + src/resources/beinginfo.h | 7 +++++++ src/resources/db/npcdb.cpp | 12 ++++++++++++ src/resources/db/unitsdb.cpp | 12 ++++++++++++ src/resources/db/unitsdb.h | 2 ++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/client.cpp b/src/client.cpp index 1739b8468..d45353c7b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1374,13 +1374,13 @@ int Client::gameExec() AvatarDB::load(); BadgesDB::load(); WeaponsDB::load(); + UnitsDb::loadUnits(); NPCDB::load(); NpcDialogDB::load(); PETDB::load(); EmoteDB::load(); // ModDB::load(); StatusEffectDB::load(); - UnitsDb::loadUnits(); EquipmentWindow::prepareSlotNames(); ActorSprite::load(); diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index e4be68fce..466a5832d 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -59,6 +59,7 @@ BeingInfo::BeingInfo() : mAttacks(), mMenu(), mStrings(), + mCurrency(), mBlockWalkMask(BlockMask::WALL | BlockMask::AIR | BlockMask::WATER | diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 2e7bc1743..a68e7ca7b 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -339,6 +339,12 @@ class BeingInfo final std::string getString(const int idx) const A_WARN_UNUSED; + std::string getCurrency() const A_WARN_UNUSED + { return mCurrency; } + + void setCurrency(const std::string &name) + { mCurrency = name; } + static void init(); static void clear(); @@ -352,6 +358,7 @@ class BeingInfo final Attacks mAttacks; std::vector mMenu; std::map mStrings; + std::string mCurrency; unsigned char mBlockWalkMask; BlockTypeT mBlockType; const std::map *mColors; diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp index 55ca39c99..4e5fd35fe 100644 --- a/src/resources/db/npcdb.cpp +++ b/src/resources/db/npcdb.cpp @@ -27,6 +27,8 @@ #include "resources/beingcommon.h" #include "resources/beinginfo.h" +#include "resources/db/unitsdb.h" + #include "resources/sprite/spritereference.h" #include "utils/checkutils.h" @@ -115,6 +117,16 @@ void NPCDB::loadXmlFile(const std::string &fileName, currentInfo->setAllowDelete(XML::getBoolProperty(npcNode, "allowDelete", true)); + const std::string currency = XML::getProperty(npcNode, + "currency", "default"); + if (UnitsDb::existsCurrency(currency) == false) + { + reportAlways("Not found currency '%s' for npc %d", + currency.c_str(), + CAST_S32(id)); + } + currentInfo->setCurrency(currency); + SpriteDisplay display; for_each_xml_child_node(spriteNode, npcNode) { diff --git a/src/resources/db/unitsdb.cpp b/src/resources/db/unitsdb.cpp index 3001ccb7b..94d055ffd 100644 --- a/src/resources/db/unitsdb.cpp +++ b/src/resources/db/unitsdb.cpp @@ -214,11 +214,18 @@ void UnitsDb::loadXmlFile(const std::string &fileName, const std::string type = XML::getProperty(node, "type", ""); UnitDescription ud = loadUnit(node); if (type == "weight") + { defaultWeight = ud; + } else if (type == "currency") + { defaultCurrency = ud; + mCurrencies["default"] = ud; + } else + { logger->log("Error unknown unit type: %s", type.c_str()); + } } else if (xmlNameEqual(node, "currency")) { @@ -318,6 +325,11 @@ std::string UnitsDb::formatWeight(const int value) return formatUnit(value, defaultWeight); } +bool UnitsDb::existsCurrency(const std::string &name) +{ + return mCurrencies.find(name) != mCurrencies.end(); +} + static std::string splitNumber(std::string str, const std::string &separator) { diff --git a/src/resources/db/unitsdb.h b/src/resources/db/unitsdb.h index b8c81cfc3..7a913cc16 100644 --- a/src/resources/db/unitsdb.h +++ b/src/resources/db/unitsdb.h @@ -51,6 +51,8 @@ class UnitsDb final * Formats the given number in the correct weight/mass format. */ static std::string formatWeight(const int value) A_WARN_UNUSED; + + static bool existsCurrency(const std::string &name) A_WARN_UNUSED; }; #endif // RESOURCES_DB_UNITSDB_H -- cgit v1.2.3-60-g2f50