diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-05-29 14:30:20 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-05-29 14:30:20 +0300 |
commit | 0f9ec2061c4ad6157c3186f1cab9c4d8558980b5 (patch) | |
tree | 6259593b8436178ad8d981a96a8fd71eab9e04cc /src/resources | |
parent | 01773c71a4698c6f01fe70d864f922bda65506cb (diff) | |
download | mv-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.gz mv-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.bz2 mv-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.tar.xz mv-0f9ec2061c4ad6157c3186f1cab9c4d8558980b5.zip |
Add strong typed int type BeingId.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/beinginfo.cpp | 2 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 10 | ||||
-rw-r--r-- | src/resources/chatobject.cpp | 2 | ||||
-rw-r--r-- | src/resources/chatobject.h | 4 | ||||
-rw-r--r-- | src/resources/db/avatardb.cpp | 5 | ||||
-rw-r--r-- | src/resources/db/avatardb.h | 4 | ||||
-rw-r--r-- | src/resources/db/homunculusdb.cpp | 11 | ||||
-rw-r--r-- | src/resources/db/homunculusdb.h | 4 | ||||
-rw-r--r-- | src/resources/db/mercenarydb.cpp | 11 | ||||
-rw-r--r-- | src/resources/db/mercenarydb.h | 4 | ||||
-rw-r--r-- | src/resources/db/monsterdb.cpp | 14 | ||||
-rw-r--r-- | src/resources/db/monsterdb.h | 4 | ||||
-rw-r--r-- | src/resources/db/npcdb.cpp | 20 | ||||
-rw-r--r-- | src/resources/db/npcdb.h | 6 | ||||
-rw-r--r-- | src/resources/db/petdb.cpp | 10 | ||||
-rw-r--r-- | src/resources/db/petdb.h | 4 |
16 files changed, 70 insertions, 45 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index 552b2a434..87bb4e33e 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -69,7 +69,7 @@ BeingInfo::BeingInfo() : mMaxHP(0), mSortOffsetY(0), mDeadSortOffsetY(31), - mAvatarId(0), + mAvatarId(BeingId_zero), mWidth(0), mHeight(0), mStartFollowDist(3), diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 43c711524..a30c150af 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -25,6 +25,8 @@ #include "enums/being/targetcursorsize.h" +#include "enums/simpletypes/beingid.h" + #include "resources/beingmenuitem.h" #include "resources/cursor.h" #include "resources/soundinfo.h" @@ -189,10 +191,10 @@ class BeingInfo final void setDeadSortOffsetY(const int n) { mDeadSortOffsetY = n; } - uint16_t getAvatarId() const A_WARN_UNUSED + BeingId getAvatarId() const A_WARN_UNUSED { return mAvatarId; } - void setAvatarId(const uint16_t id) + void setAvatarId(const BeingId id) { mAvatarId = id; } int getWidth() const A_WARN_UNUSED @@ -341,7 +343,7 @@ class BeingInfo final int mMaxHP; int mSortOffsetY; int mDeadSortOffsetY; - uint16_t mAvatarId; + BeingId mAvatarId; int mWidth; int mHeight; int mStartFollowDist; @@ -365,7 +367,7 @@ class BeingInfo final bool mTargetSelection; }; -typedef std::map<int, BeingInfo*> BeingInfos; +typedef std::map<BeingId, BeingInfo*> BeingInfos; typedef BeingInfos::iterator BeingInfoIterator; #endif // RESOURCES_BEINGINFO_H diff --git a/src/resources/chatobject.cpp b/src/resources/chatobject.cpp index 0c617f6dc..669452d27 100644 --- a/src/resources/chatobject.cpp +++ b/src/resources/chatobject.cpp @@ -26,7 +26,7 @@ std::map<std::string, ChatObject*> ChatObject::chatNameMap; std::map<int, ChatObject*> ChatObject::chatIdMap; ChatObject::ChatObject() : - ownerId(0), + ownerId(BeingId_zero), chatId(0), maxUsers(0), currentUsers(0), diff --git a/src/resources/chatobject.h b/src/resources/chatobject.h index 8ee55c930..a5ce98be9 100644 --- a/src/resources/chatobject.h +++ b/src/resources/chatobject.h @@ -21,6 +21,8 @@ #ifndef RESOURCES_CHATOBJECT_H #define RESOURCES_CHATOBJECT_H +#include "enums/simpletypes/beingid.h" + #include <map> #include <string> @@ -40,7 +42,7 @@ struct ChatObject final static ChatObject *findById(const int id); - int ownerId; + BeingId ownerId; int chatId; uint16_t maxUsers; uint16_t currentUsers; diff --git a/src/resources/db/avatardb.cpp b/src/resources/db/avatardb.cpp index 7e58db364..5f1ac6da7 100644 --- a/src/resources/db/avatardb.cpp +++ b/src/resources/db/avatardb.cpp @@ -76,7 +76,8 @@ void AvatarDB::loadXmlFile(const std::string &fileName) if (!xmlNameEqual(avatarNode, "avatar")) continue; - const int id = XML::getProperty(avatarNode, "id", 0); + const BeingId id = fromInt(XML::getProperty( + avatarNode, "id", 0), BeingId); BeingInfo *currentInfo = nullptr; if (mAvatarInfos.find(id) != mAvatarInfos.end()) currentInfo = mAvatarInfos[id]; @@ -131,7 +132,7 @@ void AvatarDB::unload() mLoaded = false; } -BeingInfo *AvatarDB::get(const int id) +BeingInfo *AvatarDB::get(const BeingId id) { BeingInfoIterator i = mAvatarInfos.find(id); if (i == mAvatarInfos.end()) diff --git a/src/resources/db/avatardb.h b/src/resources/db/avatardb.h index 252804f9c..9e8cecd07 100644 --- a/src/resources/db/avatardb.h +++ b/src/resources/db/avatardb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_AVATARDB_H #define RESOURCES_DB_AVATARDB_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -35,7 +37,7 @@ namespace AvatarDB void unload(); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; void loadXmlFile(const std::string &fileName); } // namespace AvatarDB diff --git a/src/resources/db/homunculusdb.cpp b/src/resources/db/homunculusdb.cpp index 173b37e65..41c863a6f 100644 --- a/src/resources/db/homunculusdb.cpp +++ b/src/resources/db/homunculusdb.cpp @@ -85,10 +85,11 @@ void HomunculusDB::loadXmlFile(const std::string &fileName) const int id = XML::getProperty(homunculusNode, "id", 0); BeingInfo *currentInfo = nullptr; - if (mHomunculusInfos.find(id + offset) != mHomunculusInfos.end()) + if (mHomunculusInfos.find(fromInt(id + offset, BeingId)) + != mHomunculusInfos.end()) { logger->log("HomunculusDB: Redefinition of homunculus ID %d", id); - currentInfo = mHomunculusInfos[id + offset]; + currentInfo = mHomunculusInfos[fromInt(id + offset, BeingId)]; } if (!currentInfo) currentInfo = new BeingInfo; @@ -133,7 +134,7 @@ void HomunculusDB::loadXmlFile(const std::string &fileName) } currentInfo->setDisplay(display); - mHomunculusInfos[id + offset] = currentInfo; + mHomunculusInfos[fromInt(id + offset, BeingId)] = currentInfo; } } @@ -146,7 +147,7 @@ void HomunculusDB::unload() } -BeingInfo *HomunculusDB::get(const int id) +BeingInfo *HomunculusDB::get(const BeingId id) { BeingInfoIterator i = mHomunculusInfos.find(id); @@ -157,7 +158,7 @@ BeingInfo *HomunculusDB::get(const int id) { logger->log("HomunculusDB: Warning, unknown homunculus ID " "%d requested", - id); + toInt(id, int)); return BeingInfo::unknown; } else diff --git a/src/resources/db/homunculusdb.h b/src/resources/db/homunculusdb.h index c6ab6972a..1d879cf9f 100644 --- a/src/resources/db/homunculusdb.h +++ b/src/resources/db/homunculusdb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_HOMUNCULUSDB_H #define RESOURCES_DB_HOMUNCULUSDB_H +#include "enums/simpletypes/beingid.h" + #include "localconsts.h" #include <string> @@ -40,7 +42,7 @@ namespace HomunculusDB void loadXmlFile(const std::string &fileName); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; } // namespace HomunculusDB #endif // RESOURCES_DB_HOMUNCULUSDB_H diff --git a/src/resources/db/mercenarydb.cpp b/src/resources/db/mercenarydb.cpp index a101bc891..13dfbbd45 100644 --- a/src/resources/db/mercenarydb.cpp +++ b/src/resources/db/mercenarydb.cpp @@ -85,10 +85,11 @@ void MercenaryDB::loadXmlFile(const std::string &fileName) const int id = XML::getProperty(mercenaryNode, "id", 0); BeingInfo *currentInfo = nullptr; - if (mMercenaryInfos.find(id + offset) != mMercenaryInfos.end()) + if (mMercenaryInfos.find(fromInt(id + offset, BeingId)) + != mMercenaryInfos.end()) { logger->log("MercenaryDB: Redefinition of mercenary ID %d", id); - currentInfo = mMercenaryInfos[id + offset]; + currentInfo = mMercenaryInfos[fromInt(id + offset, BeingId)]; } if (!currentInfo) currentInfo = new BeingInfo; @@ -132,7 +133,7 @@ void MercenaryDB::loadXmlFile(const std::string &fileName) } currentInfo->setDisplay(display); - mMercenaryInfos[id + offset] = currentInfo; + mMercenaryInfos[fromInt(id + offset, BeingId)] = currentInfo; } } @@ -145,7 +146,7 @@ void MercenaryDB::unload() } -BeingInfo *MercenaryDB::get(const int id) +BeingInfo *MercenaryDB::get(const BeingId id) { BeingInfoIterator i = mMercenaryInfos.find(id); @@ -156,7 +157,7 @@ BeingInfo *MercenaryDB::get(const int id) { logger->log("MercenaryDB: Warning, unknown mercenary ID " "%d requested", - id); + toInt(id, int)); return BeingInfo::unknown; } else diff --git a/src/resources/db/mercenarydb.h b/src/resources/db/mercenarydb.h index e3aee4b56..a642b1a7c 100644 --- a/src/resources/db/mercenarydb.h +++ b/src/resources/db/mercenarydb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_MERCENARYDB_H #define RESOURCES_DB_MERCENARYDB_H +#include "enums/simpletypes/beingid.h" + #include "localconsts.h" #include <string> @@ -40,7 +42,7 @@ namespace MercenaryDB void loadXmlFile(const std::string &fileName); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; } // namespace MercenaryDB #endif // RESOURCES_DB_MERCENARYDB_H diff --git a/src/resources/db/monsterdb.cpp b/src/resources/db/monsterdb.cpp index cfb7f4e92..de72f487f 100644 --- a/src/resources/db/monsterdb.cpp +++ b/src/resources/db/monsterdb.cpp @@ -88,10 +88,11 @@ void MonsterDB::loadXmlFile(const std::string &fileName) const int id = XML::getProperty(monsterNode, "id", 0); BeingInfo *currentInfo = nullptr; - if (mMonsterInfos.find(id + offset) != mMonsterInfos.end()) + if (mMonsterInfos.find(fromInt(id + offset, BeingId)) + != mMonsterInfos.end()) { logger->log("MonsterDB: Redefinition of monster ID %d", id); - currentInfo = mMonsterInfos[id + offset]; + currentInfo = mMonsterInfos[fromInt(id + offset, BeingId)]; } if (!currentInfo) currentInfo = new BeingInfo; @@ -139,7 +140,7 @@ void MonsterDB::loadXmlFile(const std::string &fileName) } currentInfo->setDisplay(display); - mMonsterInfos[id + offset] = currentInfo; + mMonsterInfos[fromInt(id + offset, BeingId)] = currentInfo; } } @@ -152,17 +153,18 @@ void MonsterDB::unload() } -BeingInfo *MonsterDB::get(const int id) +BeingInfo *MonsterDB::get(const BeingId id) { BeingInfoIterator i = mMonsterInfos.find(id); if (i == mMonsterInfos.end()) { - i = mMonsterInfos.find(id + OLD_TMWATHENA_OFFSET); + i = mMonsterInfos.find(fromInt(toInt( + id, int) + OLD_TMWATHENA_OFFSET, BeingId)); if (i == mMonsterInfos.end()) { logger->log("MonsterDB: Warning, unknown monster ID %d requested", - id); + toInt(id, int)); return BeingInfo::unknown; } else diff --git a/src/resources/db/monsterdb.h b/src/resources/db/monsterdb.h index 241c8f168..c8ef85a5a 100644 --- a/src/resources/db/monsterdb.h +++ b/src/resources/db/monsterdb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_MONSTERDB_H #define RESOURCES_DB_MONSTERDB_H +#include "enums/simpletypes/beingid.h" + #include "localconsts.h" #include <string> @@ -40,7 +42,7 @@ namespace MonsterDB void loadXmlFile(const std::string &fileName); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; } // namespace MonsterDB #endif // RESOURCES_DB_MONSTERDB_H diff --git a/src/resources/db/npcdb.cpp b/src/resources/db/npcdb.cpp index bb006e75a..8be92f186 100644 --- a/src/resources/db/npcdb.cpp +++ b/src/resources/db/npcdb.cpp @@ -81,9 +81,10 @@ void NPCDB::loadXmlFile(const std::string &fileName) if (!xmlNameEqual(npcNode, "npc")) continue; - const int id = XML::getProperty(npcNode, "id", 0); + const BeingId id = fromInt(XML::getProperty( + npcNode, "id", 0), BeingId); BeingInfo *currentInfo = nullptr; - if (id == 0) + if (id == BeingId_zero) { logger->log("NPC Database: NPC with missing ID in %s!", paths.getStringValue("npcsFile").c_str()); @@ -91,7 +92,7 @@ void NPCDB::loadXmlFile(const std::string &fileName) } else if (mNPCInfos.find(id) != mNPCInfos.end()) { - logger->log("NpcDB: Redefinition of npc ID %d", id); + logger->log("NpcDB: Redefinition of npc ID %d", toInt(id, int)); currentInfo = mNPCInfos[id]; } if (!currentInfo) @@ -105,8 +106,8 @@ void NPCDB::loadXmlFile(const std::string &fileName) currentInfo->setDeadSortOffsetY(XML::getProperty(npcNode, "deadSortOffsetY", 31)); - currentInfo->setAvatarId(static_cast<uint16_t>(XML::getProperty( - npcNode, "avatar", 0))); + currentInfo->setAvatarId(fromInt(XML::getProperty( + npcNode, "avatar", 0), BeingId)); SpriteDisplay display; for_each_xml_child_node(spriteNode, npcNode) @@ -159,13 +160,14 @@ void NPCDB::unload() mLoaded = false; } -BeingInfo *NPCDB::get(const int id) +BeingInfo *NPCDB::get(const BeingId id) { const BeingInfoIterator i = mNPCInfos.find(id); if (i == mNPCInfos.end()) { - logger->log("NPCDB: Warning, unknown NPC ID %d requested", id); + logger->log("NPCDB: Warning, unknown NPC ID %d requested", + toInt(id, int)); return BeingInfo::unknown; } else @@ -174,10 +176,10 @@ BeingInfo *NPCDB::get(const int id) } } -uint16_t NPCDB::getAvatarFor(const int id) +BeingId NPCDB::getAvatarFor(const BeingId id) { const BeingInfo *const info = get(id); if (!info) - return 0; + return BeingId_zero; return info->getAvatarId(); } diff --git a/src/resources/db/npcdb.h b/src/resources/db/npcdb.h index e8adb744e..283671fba 100644 --- a/src/resources/db/npcdb.h +++ b/src/resources/db/npcdb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_NPCDB_H #define RESOURCES_DB_NPCDB_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -38,9 +40,9 @@ namespace NPCDB void unload(); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; - uint16_t getAvatarFor(const int id); + BeingId getAvatarFor(const BeingId id); void loadXmlFile(const std::string &fileName); } // namespace NPCDB diff --git a/src/resources/db/petdb.cpp b/src/resources/db/petdb.cpp index 31893403f..242313d14 100644 --- a/src/resources/db/petdb.cpp +++ b/src/resources/db/petdb.cpp @@ -79,8 +79,9 @@ void PETDB::loadXmlFile(const std::string &fileName) continue; } - const int id = XML::getProperty(petNode, "id", -1); - if (id == -1) + const BeingId id = fromInt(XML::getProperty( + petNode, "id", -1), BeingId); + if (id == BeingId_negOne) { logger->log("PET Database: PET with missing ID in %s!", paths.getStringValue("petsFile").c_str()); @@ -185,13 +186,14 @@ void PETDB::unload() mLoaded = false; } -BeingInfo *PETDB::get(const int id) +BeingInfo *PETDB::get(const BeingId id) { const BeingInfoIterator i = mPETInfos.find(id); if (i == mPETInfos.end()) { - logger->log("PETDB: Warning, unknown PET ID %d requested", id); + logger->log("PETDB: Warning, unknown PET ID %d requested", + toInt(id, int)); return BeingInfo::unknown; } else diff --git a/src/resources/db/petdb.h b/src/resources/db/petdb.h index bb3d9f329..893a9dcde 100644 --- a/src/resources/db/petdb.h +++ b/src/resources/db/petdb.h @@ -23,6 +23,8 @@ #ifndef RESOURCES_DB_PETDB_H #define RESOURCES_DB_PETDB_H +#include "enums/simpletypes/beingid.h" + #include <string> #include "localconsts.h" @@ -37,7 +39,7 @@ namespace PETDB void unload(); - BeingInfo *get(const int id) A_WARN_UNUSED; + BeingInfo *get(const BeingId id) A_WARN_UNUSED; } // namespace PETDB #endif // RESOURCES_DB_PETDB_H |